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 <kcolorcombo.h>
00031 
00032 #include <kdebug.h>
00033 #include <qpushbutton.h>
00034 #include <qslider.h>
00035 #include <qtextedit.h>
00036 #include <KoUnitWidgets.h>
00037 
00038 KisCustomImageWidget::KisCustomImageWidget(QWidget *parent, KisDoc *doc, Q_INT32 defWidth, Q_INT32 defHeight, double resolution, QString defColorSpaceName, QString imageName)
00039     : WdgNewImage(parent) {
00040     m_doc = doc;
00041 
00042     txtName->setText(imageName);
00043 
00044     intWidth->setValue(defWidth);
00045     intHeight->setValue(defHeight);
00046     doubleResolution->setValue(resolution);
00047 
00048     cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys());
00049     cmbColorSpaces->setCurrentText(defColorSpaceName);
00050 
00051     connect(cmbColorSpaces, SIGNAL(activated(const KisID &)),
00052         this, SLOT(fillCmbProfiles(const KisID &)));
00053     connect (m_createButton, SIGNAL( clicked() ), this, SLOT (buttonClicked()) );
00054 
00055     fillCmbProfiles(cmbColorSpaces->currentItem());
00056 
00057 }
00058 
00059 void KisCustomImageWidget::buttonClicked() {
00060     KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cmbColorSpaces->currentItem(), cmbProfile->currentText());
00061 
00062     QColor qc(cmbColor->color());
00063 
00064     m_doc->newImage(txtName->text(), (Q_INT32)intWidth->value(), (Q_INT32)intHeight->value(), cs, KisColor(qc, cs), txtDescription->text(), doubleResolution->value());
00065     emit documentSelected();
00066 }
00067 
00068 Q_UINT8 KisCustomImageWidget::backgroundOpacity() const
00069 {
00070     Q_INT32 opacity = sliderOpacity->value();
00071 
00072     if (!opacity)
00073         return 0;
00074 
00075     return (opacity * 255) / 100;
00076 }
00077 
00078 void KisCustomImageWidget::fillCmbProfiles(const KisID & s)
00079 {
00080     cmbProfile->clear();
00081 
00082     if (!KisMetaRegistry::instance()->csRegistry()->exists(s)) {
00083         return;
00084     }
00085 
00086     KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
00087     if (csf == 0) return;
00088 
00089     QValueVector<KisProfile *>  profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
00090         QValueVector<KisProfile *> ::iterator it;
00091         for ( it = profileList.begin(); it != profileList.end(); ++it ) {
00092             cmbProfile->insertItem((*it)->productName());
00093     }
00094     cmbProfile->setCurrentText(csf->defaultProfile());
00095 }
00096 
00097 #include "kis_custom_image_widget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys