2
* kis_paintop_box.cc - part of KImageShop/Krayon/Krita
4
* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <qvaluelist.h>
27
#include <kactioncollection.h>
31
#include <kglobalsettings.h>
32
#include <kaccelmanager.h>
34
#include <kstandarddirs.h>
36
#include <kis_paintop_registry.h>
38
#include <kis_painter.h>
39
#include <kis_paintop.h>
40
#include <kis_layer.h>
41
#include <kis_factory.h>
43
#include "kis_paintop_box.h"
45
KisPaintopBox::KisPaintopBox (KisView * view, QWidget *parent, const char * name)
46
: super (parent, name),
47
m_canvasController(view->getCanvasController())
49
#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,90)
50
KAcceleratorManager::setNoAccel(this);
53
Q_ASSERT(m_canvasController != 0);
55
setCaption(i18n("Painter's Toolchest"));
57
m_paintops = new QValueList<KisID>();
58
m_displayedOps = new QValueList<KisID>();
60
m_cmbPaintops = new QComboBox(this, "KisPaintopBox::m_cmbPaintops");
61
m_cmbPaintops->setMinimumWidth(150);
62
m_layout = new QHBoxLayout(this, 1, 1);
63
m_layout->addWidget(m_cmbPaintops);
65
connect(this, SIGNAL(selected(const KisID &, const KisPaintOpSettings *)), view, SLOT(paintopActivated(const KisID &, const KisPaintOpSettings *)));
66
connect(m_cmbPaintops, SIGNAL(activated(int)), this, SLOT(slotItemSelected(int)));
68
// XXX: Let's see... Are all paintops loaded and ready?
69
KisIDList keys = KisPaintOpRegistry::instance()->listKeys();
70
for ( KisIDList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
71
// add all paintops, and show/hide them afterwards
75
connect(view, SIGNAL(currentColorSpaceChanged(KisColorSpace*)),
76
this, SLOT(colorSpaceChanged(KisColorSpace*)));
77
connect(view, SIGNAL(sigInputDeviceChanged(const KisInputDevice&)),
78
this, SLOT(slotInputDeviceChanged(const KisInputDevice&)));
80
setCurrentPaintop(defaultPaintop(m_canvasController->currentInputDevice()));
83
KisPaintopBox::~KisPaintopBox()
86
delete m_displayedOps;
89
void KisPaintopBox::addItem(const KisID & paintop, const QString & /*category*/)
91
m_paintops->append(paintop);
94
void KisPaintopBox::slotItemSelected(int index)
96
if ((uint)index > m_displayedOps->count()) {
100
KisID paintop = *m_displayedOps->at(index);
102
setCurrentPaintop(paintop);
105
void KisPaintopBox::colorSpaceChanged(KisColorSpace *cs)
107
QValueList<KisID>::iterator it = m_paintops->begin();
108
QValueList<KisID>::iterator end = m_paintops->end();
109
m_displayedOps->clear();
110
m_cmbPaintops->clear();
112
for ( ; it != end; ++it ) {
113
if (KisPaintOpRegistry::instance()->userVisible(*it, cs)) {
114
QPixmap pm = paintopPixmap(*it);
116
QPixmap p = QPixmap( 16, 16 );
118
m_cmbPaintops->insertItem(p, (*it).name());
121
m_cmbPaintops->insertItem(pm, (*it).name());
123
m_displayedOps->append(*it);
127
int index = m_displayedOps->findIndex(currentPaintop());
130
// Must change the paintop as the current one is not supported
131
// by the new colourspace.
135
m_cmbPaintops->setCurrentItem( index );
136
slotItemSelected( index );
139
QPixmap KisPaintopBox::paintopPixmap(const KisID & paintop)
141
QString pixmapName = KisPaintOpRegistry::instance()->pixmap(paintop);
143
if (pixmapName.isEmpty()) {
147
QString fname = KisFactory::instance()->dirs()->findResource("kis_images", pixmapName);
149
return QPixmap(fname);
152
void KisPaintopBox::slotInputDeviceChanged(const KisInputDevice & inputDevice)
155
InputDevicePaintopMap::iterator it = m_currentID.find(inputDevice);
157
if (it == m_currentID.end()) {
158
paintop = defaultPaintop(inputDevice);
160
paintop = (*it).second;
163
int index = m_displayedOps->findIndex(paintop);
166
// Must change the paintop as the current one is not supported
167
// by the new colourspace.
169
paintop = *m_displayedOps->at(index);
172
m_cmbPaintops->setCurrentItem(index);
173
setCurrentPaintop(paintop);
176
void KisPaintopBox::updateOptionWidget()
178
if (m_optionWidget != 0) {
179
m_layout->remove(m_optionWidget);
180
m_optionWidget->hide();
181
m_layout->invalidate();
184
const KisPaintOpSettings *settings = paintopSettings(currentPaintop(), m_canvasController->currentInputDevice());
187
m_optionWidget = settings->widget();
188
Q_ASSERT(m_optionWidget != 0);
190
m_layout->addWidget(m_optionWidget);
192
m_optionWidget->show();
196
const KisID& KisPaintopBox::currentPaintop()
198
return m_currentID[m_canvasController->currentInputDevice()];
201
void KisPaintopBox::setCurrentPaintop(const KisID & paintop)
203
m_currentID[m_canvasController->currentInputDevice()] = paintop;
205
updateOptionWidget();
207
emit selected(paintop, paintopSettings(paintop, m_canvasController->currentInputDevice()));
210
KisID KisPaintopBox::defaultPaintop(const KisInputDevice& inputDevice)
212
if (inputDevice == KisInputDevice::eraser()) {
213
return KisID("eraser","");
215
return KisID("paintbrush","");
219
const KisPaintOpSettings *KisPaintopBox::paintopSettings(const KisID & paintop, const KisInputDevice & inputDevice)
221
QValueVector<KisPaintOpSettings *> settingsArray;
222
InputDevicePaintopSettingsMap::iterator it = m_inputDevicePaintopSettings.find(inputDevice);
224
if (it == m_inputDevicePaintopSettings.end()) {
225
// Create settings for each paintop.
227
for (QValueList<KisID>::const_iterator pit = m_paintops->begin(); pit != m_paintops->end(); ++pit) {
228
KisPaintOpSettings *settings = KisPaintOpRegistry::instance()->settings(*pit, this, inputDevice);
229
settingsArray.append(settings);
230
if (settings && settings->widget()) {
231
settings->widget()->hide();
234
m_inputDevicePaintopSettings[inputDevice] = settingsArray;
236
settingsArray = (*it).second;
239
const int index = m_paintops->findIndex(paintop);
240
if (index >= 0 && index < (int)settingsArray.count())
241
return settingsArray[index];
246
#include "kis_paintop_box.moc"