krita

kis_dlg_image_properties.cc

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program 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
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include <qbuttongroup.h>
00019 #include <qpushbutton.h>
00020 #include <qradiobutton.h>
00021 #include <qgroupbox.h>
00022 #include <qlayout.h>
00023 #include <qlabel.h>
00024 #include <qspinbox.h>
00025 #include <qslider.h>
00026 #include <qtextedit.h>
00027 #include <qcheckbox.h>
00028 
00029 #include <klocale.h>
00030 #include <kcolorcombo.h>
00031 
00032 #include <KoUnitWidgets.h>
00033 
00034 #include "kis_factory.h"
00035 #include "kis_meta_registry.h"
00036 #include "kis_colorspace_factory_registry.h"
00037 #include "kis_dlg_image_properties.h"
00038 #include "kis_profile.h"
00039 #include "kis_types.h"
00040 #include "kis_image.h"
00041 #include "kis_config.h"
00042 #include "kis_id.h"
00043 #include "kis_cmb_idlist.h"
00044 #include "squeezedcombobox.h"
00045 #include "wdgnewimage.h"
00046 
00047 KisDlgImageProperties::KisDlgImageProperties(KisImageSP image, QWidget *parent, const char *name)
00048     : super(parent, name, true, "", Ok | Cancel)
00049 {
00050 
00051     setCaption(i18n("Image Properties"));
00052     m_page = new WdgNewImage(this);
00053 
00054     m_image = image;
00055 
00056     setMainWidget(m_page);
00057     resize(m_page->sizeHint());
00058 
00059     m_page->txtName->setText(image->name());
00060     m_page->m_createButton->hide();
00061     KisConfig cfg;
00062 
00063     m_page->intWidth->setValue(image->width());
00064     m_page->intHeight->setValue(image->height());
00065 
00066     m_page->doubleResolution->setValue(image->xRes()); // XXX: separate values for x & y?
00067 
00068     //m_page->cmbColorSpaces->hide();
00069     //m_page->lblColorSpaces->setText(image->colorSpace()->id().name());
00070     KisIDList colorSpaces = KisMetaRegistry::instance()->csRegistry()->listKeys();
00071     KisIDList::iterator i = colorSpaces.find(KisID("WET",""));
00072     if (i != colorSpaces.end()) {
00073         colorSpaces.remove(i);
00074     }
00075     m_page->cmbColorSpaces->setIDList(colorSpaces);
00076     m_page->cmbColorSpaces->setCurrent(image->colorSpace()->id());
00077             
00078     fillCmbProfiles(image->colorSpace()->id());
00079 
00080     if (image->getProfile()) {
00081         m_page->cmbProfile->setCurrentText(image->getProfile()->productName());
00082     }
00083     else {
00084         m_page->cmbProfile->setCurrentItem(0);
00085     }
00086 
00087     m_page->sliderOpacity->setEnabled(false); // XXX re-enable when figured out a way to do this
00088     m_page->opacityPanel->hide();
00089     m_page->lblOpacity->hide();
00090 
00091     m_page->cmbColor->setEnabled(false); // XXX re-enable when figured out a way to do this
00092     m_page->cmbColor->hide();
00093     m_page->lblColor->hide();
00094 
00095     connect(m_page->cmbColorSpaces, SIGNAL(activated(const KisID &)),
00096         this, SLOT(fillCmbProfiles(const KisID &)));
00097 
00098 
00099 }
00100 
00101 KisDlgImageProperties::~KisDlgImageProperties()
00102 {
00103     delete m_page;
00104 }
00105 
00106 int KisDlgImageProperties::imageWidth()
00107 {
00108     return m_page->intWidth->value();
00109 }
00110 
00111 int KisDlgImageProperties::imageHeight()
00112 {
00113     return m_page->intHeight->value();
00114 }
00115 
00116 int KisDlgImageProperties::opacity()
00117 {
00118     return m_page->sliderOpacity->value();
00119 }
00120 
00121 QString KisDlgImageProperties::imageName()
00122 {
00123     return m_page->txtName->text();
00124 }
00125 
00126 double KisDlgImageProperties::resolution()
00127 {
00128     return m_page->doubleResolution->value();
00129 }
00130 
00131 QString KisDlgImageProperties::description()
00132 {
00133     return m_page->txtDescription->text();
00134 }
00135 
00136 KisColorSpace * KisDlgImageProperties::colorSpace()
00137 {
00138     return KisMetaRegistry::instance()->csRegistry()->getColorSpace(m_page->cmbColorSpaces->currentItem(), m_page->cmbProfile->currentText());
00139 }
00140 
00141 KisProfile * KisDlgImageProperties::profile()
00142 {
00143     QValueVector<KisProfile *>  profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( m_image->colorSpace()->id() );
00144     Q_UINT32 index = m_page->cmbProfile->currentItem();
00145 
00146     if (index < profileList.count()) {
00147         return profileList.at(index);
00148     } else {
00149         return 0;
00150     }
00151 }
00152 
00153 // XXX: Copy & paste from kis_dlg_create_img -- refactor to separate class
00154 void KisDlgImageProperties::fillCmbProfiles(const KisID & s)
00155 {
00156 
00157     KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s);
00158     m_page->cmbProfile->clear();
00159     QValueVector<KisProfile *>  profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf );
00160         QValueVector<KisProfile *> ::iterator it;
00161         for ( it = profileList.begin(); it != profileList.end(); ++it ) {
00162         m_page->cmbProfile->insertItem((*it)->productName());
00163     }
00164 
00165 
00166 }
00167 
00168 #include "kis_dlg_image_properties.moc"
00169 
KDE Home | KDE Accessibility Home | Description of Access Keys