krita

kis_custom_image_widget.cc

00001 /* This file is part of the KOffice project
00002  * Copyright (C) 2005 Thomas Zander <zander@kde.org>
00003  * Copyright (C) 2005 Casper Boemann <cbr@boemann.dk>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; version 2.
00008 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include <kis_custom_image_widget.h>
00021 #include <kis_doc.h>
00022 #include <kis_meta_registry.h>
00023 #include "kis_colorspace_factory_registry.h"
00024 #include "kis_profile.h"
00025 #include "kis_colorspace.h"
00026 #include "kis_id.h"
00027 #include "kis_cmb_idlist.h"
00028 #include "squeezedcombobox.h"
00029 #include "kis_color.h"
00030 #include "kis_image.h"
00031 #include "kis_layer.h"
00032 
00033 #include <kcolorcombo.h>
00034 
00035 #include <kdebug.h>
00036 #include <qpushbutton.h>
00037 #include <qslider.h>
00038 #include <qtextedit.h>
00039 #include <KoUnitWidgets.h>
00040 #include <qlabel.h>
00041 
00042 KisCustomImageWidget::KisCustomImageWidget(QWidget *parent, KisDoc *doc, Q_INT32 defWidth, Q_INT32 defHeight, double resolution, QString defColorSpaceName, QString imageName)
00043     : WdgNewImage(parent) {
00044     m_doc = doc;
00045 
00046     txtName->setText(imageName);
00047 
00048     intWidth->setValue(defWidth);
00049     intHeight->setValue(defHeight);
00050     doubleResolution->setValue(resolution);
00051 
00052     cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
00053     cmbColorSpaces->setCurrentText(defColorSpaceName);
00054 
00055     connect(cmbColorSpaces, SIGNAL(activated(const KisID &)),
00056         this, SLOT(fillCmbProfiles(const KisID &)));
00057     connect (m_createButton, SIGNAL( clicked() ), this, SLOT (buttonClicked()) );
00058     m_createButton -> setDefault(true);
00059 
00060     fillCmbProfiles(cmbColorSpaces->currentItem());
00061     lblResolution->hide();
00062     doubleResolution->hide();
00063 }
00064 
00065 void KisCustomImageWidget::buttonClicked() {
00066     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cmbColorSpaces->currentItem(), cmbProfile->currentText());
00067 
00068     QColor qc(cmbColor->color());
00069 
00070     m_doc->newImage(txtName->text(), (Q_INT32)intWidth->value(), (Q_INT32)intHeight->value(), cs, KisColor(qc, cs), txtDescription->text(), doubleResolution->value());
00071     KisImageSP img = m_doc->currentImage();
00072     if (img) {
00073         KisLayerSP layer = img->activeLayer();
00074         if (layer) {
00075             layer->setOpacity(backgroundOpacity());
00076         }
00077     }
00078     emit documentSelected();
00079 }
00080 
00081 Q_UINT8 KisCustomImageWidget::backgroundOpacity() const
00082 {
00083     Q_INT32 opacity = sliderOpacity->value();
00084 
00085     if (!opacity)
00086         return 0;
00087 
00088     return (opacity * 255) / 100;
00089 }
00090 
00091 void KisCustomImageWidget::fillCmbProfiles(const KisID & s)
00092 {
00093     cmbProfile->clear();
00094 
00095     if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
00096         return;
00097     }
00098 
00099     KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
00100     if (csf == 0) return;
00101 
00102     QValueVector<KisProfile *>  profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
00103         QValueVector<KisProfile *> ::iterator it;
00104         for ( it = profileList.begin(); it != profileList.end(); ++it ) {
00105             cmbProfile->insertItem((*it)->productName());
00106     }
00107     cmbProfile->setCurrentText(csf->defaultProfile());
00108 }
00109 
00110 #include "kis_custom_image_widget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys