chalk

kis_custom_image_widget.cpp
1/* This file is part of the KOffice project
2 * Copyright (C) 2005 Thomas Zander <zander@kde.org>
3 * Copyright (C) 2005 Casper Boemann <cbr@boemann.dk>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; version 2.
8
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include <kis_custom_image_widget.h>
21#include <kis_doc.h>
22#include <kis_meta_registry.h>
23#include "kis_colorspace_factory_registry.h"
24#include "kis_profile.h"
25#include "kis_colorspace.h"
26#include "kis_id.h"
27#include "kis_cmb_idlist.h"
28#include "squeezedcombobox.h"
29#include "kis_color.h"
30#include "kis_image.h"
31#include "kis_layer.h"
32
33#include <kcolorcombo.h>
34
35#include <kdebug.h>
36#include <tqpushbutton.h>
37#include <tqslider.h>
38#include <tqtextedit.h>
39#include <KoUnitWidgets.h>
40#include <tqlabel.h>
41
42KisCustomImageWidget::KisCustomImageWidget(TQWidget *parent, KisDoc *doc, TQ_INT32 defWidth, TQ_INT32 defHeight, double resolution, TQString defColorSpaceName, TQString imageName)
43 : WdgNewImage(parent) {
44 m_doc = doc;
45
46 txtName->setText(imageName);
47
48 intWidth->setValue(defWidth);
49 intHeight->setValue(defHeight);
50 doubleResolution->setValue(resolution);
51
52 cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
53 cmbColorSpaces->setCurrentText(defColorSpaceName);
54
55 connect(cmbColorSpaces, TQ_SIGNAL(activated(const KisID &)),
56 this, TQ_SLOT(fillCmbProfiles(const KisID &)));
57 connect (m_createButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT (buttonClicked()) );
58 m_createButton -> setDefault(true);
59
60 fillCmbProfiles(cmbColorSpaces->currentItem());
61 lblResolution->hide();
62 doubleResolution->hide();
63}
64
65void KisCustomImageWidget::buttonClicked() {
66 KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cmbColorSpaces->currentItem(), cmbProfile->currentText());
67
68 TQColor qc(cmbColor->color());
69
70 m_doc->newImage(txtName->text(), (TQ_INT32)intWidth->value(), (TQ_INT32)intHeight->value(), cs, KisColor(qc, cs), txtDescription->text(), doubleResolution->value());
71 KisImageSP img = m_doc->currentImage();
72 if (img) {
73 KisLayerSP layer = img->activeLayer();
74 if (layer) {
75 layer->setOpacity(backgroundOpacity());
76 }
77 }
78 emit documentSelected();
79}
80
81TQ_UINT8 KisCustomImageWidget::backgroundOpacity() const
82{
83 TQ_INT32 opacity = sliderOpacity->value();
84
85 if (!opacity)
86 return 0;
87
88 return (opacity * 255) / 100;
89}
90
91void KisCustomImageWidget::fillCmbProfiles(const KisID & s)
92{
93 cmbProfile->clear();
94
95 if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
96 return;
97 }
98
99 KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
100 if (csf == 0) return;
101
102 TQValueVector<KisProfile *> profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
103 TQValueVector<KisProfile *> ::iterator it;
104 for ( it = profileList.begin(); it != profileList.end(); ++it ) {
105 cmbProfile->insertItem((*it)->productName());
106 }
107 cmbProfile->setCurrentText(csf->defaultProfile());
108}
109
110#include "kis_custom_image_widget.moc"
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.
A colorspace is the definition of a certain color model in Chalk.
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
KisCustomImageWidget(TQWidget *parent, KisDoc *doc, TQ_INT32 defWidth, TQ_INT32 defHeight, double resolution, TQString defColorSpaceName, TQString imageName)
Constructor.
void documentSelected()
this signal is emitted (as defined by KoDocument) the moment the document is 'ready'
_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