chalk

kis_dlg_new_layer.cpp
1/*
2 * Copyright (c) 2000 Michael Koch <koch@kde.org>
3 * Copyright (c) 2000 Patrick Julien <freak@codepimps.org>
4 * Copyright (c) 2004 Boudewijn Remot <boud@valdyas.org>
5 * Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21#include <tqgroupbox.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24
25#include <klineedit.h>
26#include <tdelocale.h>
27#include <knuminput.h>
28#include <kpushbutton.h>
29
30#include "kis_factory.h"
31#include "kis_global.h"
32#include "kis_cmb_composite.h"
33#include "kis_cmb_idlist.h"
34#include "squeezedcombobox.h"
35#include "kis_dlg_new_layer.h"
36#include <kis_meta_registry.h>
37#include "kis_colorspace_factory_registry.h"
38#include "kis_profile.h"
39#include "kis_colorspace.h"
40#include "wdglayerproperties.h"
41#include "kis_int_spinbox.h"
42
43NewLayerDialog::NewLayerDialog(const KisID colorSpaceID,
44 const TQString & profilename,
45 const TQString & deviceName,
46 TQWidget *parent,
47 const char *name)
48 : super(parent, name, true, "", Ok | Cancel)
49{
50 m_page = new WdgLayerProperties(this);
51 m_page->layout()->setMargin(0);
52
53 setCaption(i18n("New Layer"));
54
55 setMainWidget(m_page);
56
57 // Name
58 m_page->editName->setText(deviceName);
59
60 // Opacity
61 m_page->intOpacity->setRange(0, 100, 13);
62 m_page->intOpacity->setValue(100);
63
64 // ColorSpace
65 m_page->cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
66 m_page->cmbColorSpaces->setCurrentText(colorSpaceID.id());
67 connect(m_page->cmbColorSpaces, TQ_SIGNAL(activated(const KisID &)),
68 this, TQ_SLOT(fillCmbProfiles(const KisID &)));
69 connect(m_page->cmbColorSpaces, TQ_SIGNAL(activated(const KisID &)),
70 this, TQ_SLOT(fillCmbComposite(const KisID &)));
71
72 // Init profiles
73 fillCmbProfiles(m_page->cmbColorSpaces->currentItem());
74 m_page->cmbProfile->setCurrentText(profilename);
75
76 // Init composite op
77 fillCmbComposite(m_page->cmbColorSpaces->currentItem());
78
79/*
80 connect( m_page->editName, TQ_SIGNAL( textChanged ( const TQString & ) ), this, TQ_SLOT( slotNameChanged( const TQString & ) ) );
81
82 slotNameChanged( m_page->editName->text() );
83*/
84}
85
86void NewLayerDialog::setColorSpaceEnabled(bool enabled)
87{
88 m_page->cmbProfile->setEnabled(enabled);
89 m_page->cmbColorSpaces->setEnabled(enabled);
90}
91
92void NewLayerDialog::fillCmbProfiles(const KisID & s)
93{
94 m_page->cmbProfile->clear();
95
96 if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
97 return;
98 }
99
100 KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
101 if (csf == 0) return;
102
103 TQValueVector<KisProfile *> profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
104 TQValueVector<KisProfile *> ::iterator it;
105 for ( it = profileList.begin(); it != profileList.end(); ++it ) {
106 m_page->cmbProfile->insertItem((*it)->productName());
107 }
108 m_page->cmbProfile->setCurrentText(csf->defaultProfile());
109}
110
111void NewLayerDialog::fillCmbComposite(const KisID & s)
112{
113 m_page->cmbComposite->clear();
114
115 if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
116 return;
117 }
118
119 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(s,"");
120 if (cs) {
121 m_page->cmbComposite->setCompositeOpList(cs->userVisiblecompositeOps());
122 }
123}
124
125int NewLayerDialog::opacity() const
126{
127 TQ_INT32 opacity = m_page->intOpacity->value();
128
129 if (!opacity)
130 return 0;
131
132 opacity = int((opacity * 255.0) / 100 + 0.5);
133 if(opacity>255)
134 opacity=255;
135 return opacity;
136}
137
138KisCompositeOp NewLayerDialog::compositeOp() const
139{
140 return m_page->cmbComposite->currentItem();
141}
142
143KisID NewLayerDialog::colorSpaceID() const
144{
145 return m_page->cmbColorSpaces->currentItem();
146}
147
148TQString NewLayerDialog::layerName() const
149{
150 return m_page->editName->text();
151}
152
153TQString NewLayerDialog::profileName() const
154{
155 return m_page->cmbProfile-> currentText();
156}
157
158#include "kis_dlg_new_layer.moc"
159
TQValueVector< KisProfile * > profilesFor(KisColorSpaceFactory *cs)
Return the vector of profiles for this colorspacefactory.
KisColorSpace * getColorSpace(const KisID &csID, const TQString &profileName)
Return the colorspace + profile as named, or NULL if impossible combination.
virtual KisCompositeOpList userVisiblecompositeOps() const =0
Returns the list of user-visible composite ops supported by this colourspace.
_T get(const KisID &name) const
This function allow to get an object from its KisID.
Chalk has a large number of extensible resources.
Definition kis_id.h:57