krita

kis_dlg_new_layer.cc

00001 /*
00002  *  Copyright (c) 2000 Michael Koch <koch@kde.org>
00003  *  Copyright (c) 2000 Patrick Julien <freak@codepimps.org>
00004  *  Copyright (c) 2004 Boudewijn Remot <boud@valdyas.org>
00005  *  Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  */
00021 #include <qgroupbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 
00025 #include <klineedit.h>
00026 #include <klocale.h>
00027 #include <knuminput.h>
00028 #include <kpushbutton.h>
00029 
00030 #include "kis_factory.h"
00031 #include "kis_global.h"
00032 #include "kis_cmb_composite.h"
00033 #include "kis_cmb_idlist.h"
00034 #include "squeezedcombobox.h"
00035 #include "kis_dlg_new_layer.h"
00036 #include <kis_meta_registry.h>
00037 #include "kis_colorspace_factory_registry.h"
00038 #include "kis_profile.h"
00039 #include "kis_colorspace.h"
00040 #include "wdglayerproperties.h"
00041 #include "kis_int_spinbox.h"
00042 
00043 NewLayerDialog::NewLayerDialog(const KisID colorSpaceID,
00044                    const QString & profilename,
00045                    const QString & deviceName,
00046                    QWidget *parent,
00047                    const char *name)
00048     : super(parent, name, true, "", Ok | Cancel)
00049 {
00050     m_page = new WdgLayerProperties(this);
00051     m_page->layout()->setMargin(0);
00052 
00053     setCaption(i18n("New Layer"));
00054 
00055     setMainWidget(m_page);
00056 
00057     // Name
00058     m_page->editName->setText(deviceName);
00059 
00060     // Opacity
00061     m_page->intOpacity->setRange(0, 100, 13);
00062     m_page->intOpacity->setValue(100);
00063 
00064     // ColorSpace
00065     m_page->cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
00066     m_page->cmbColorSpaces->setCurrentText(colorSpaceID.id());
00067     connect(m_page->cmbColorSpaces, SIGNAL(activated(const KisID &)),
00068         this, SLOT(fillCmbProfiles(const KisID &)));
00069     connect(m_page->cmbColorSpaces, SIGNAL(activated(const KisID &)),
00070         this, SLOT(fillCmbComposite(const KisID &)));
00071 
00072     // Init profiles
00073     fillCmbProfiles(m_page->cmbColorSpaces->currentItem());
00074     m_page->cmbProfile->setCurrentText(profilename);
00075 
00076     // Init composite op
00077     fillCmbComposite(m_page->cmbColorSpaces->currentItem());
00078 
00079 /*
00080     connect( m_page->editName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) );
00081 
00082     slotNameChanged( m_page->editName->text() );
00083 */
00084 }
00085 
00086 void NewLayerDialog::setColorSpaceEnabled(bool enabled)
00087 {
00088     m_page->cmbProfile->setEnabled(enabled);
00089     m_page->cmbColorSpaces->setEnabled(enabled);
00090 }
00091 
00092 void NewLayerDialog::fillCmbProfiles(const KisID & s)
00093 {
00094     m_page->cmbProfile->clear();
00095 
00096     if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
00097         return;
00098     }
00099 
00100     KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
00101     if (csf == 0) return;
00102 
00103     QValueVector<KisProfile *>  profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
00104         QValueVector<KisProfile *> ::iterator it;
00105         for ( it = profileList.begin(); it != profileList.end(); ++it ) {
00106             m_page->cmbProfile->insertItem((*it)->productName());
00107     }
00108     m_page->cmbProfile->setCurrentText(csf->defaultProfile());
00109 }
00110 
00111 void NewLayerDialog::fillCmbComposite(const KisID & s)
00112 {
00113     m_page->cmbComposite->clear();
00114 
00115     if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
00116         return;
00117     }
00118 
00119     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(s,"");
00120     if (cs) {
00121         m_page->cmbComposite->setCompositeOpList(cs->userVisiblecompositeOps());
00122     }
00123 }
00124 
00125 int NewLayerDialog::opacity() const
00126 {
00127     Q_INT32 opacity = m_page->intOpacity->value();
00128 
00129     if (!opacity)
00130         return 0;
00131 
00132     opacity = int((opacity * 255.0) / 100 + 0.5);
00133     if(opacity>255)
00134         opacity=255;
00135     return opacity;
00136 }
00137 
00138 KisCompositeOp NewLayerDialog::compositeOp() const
00139 {
00140     return m_page->cmbComposite->currentItem();
00141 }
00142 
00143 KisID NewLayerDialog::colorSpaceID() const
00144 {
00145     return m_page->cmbColorSpaces->currentItem();
00146 }
00147 
00148 QString NewLayerDialog::layerName() const
00149 {
00150     return m_page->editName->text();
00151 }
00152 
00153 QString NewLayerDialog::profileName() const
00154 {
00155     return m_page->cmbProfile-> currentText();
00156 }
00157 
00158 #include "kis_dlg_new_layer.moc"
00159 
KDE Home | KDE Accessibility Home | Description of Access Keys