1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
/*
* Copyright (c) 2003 Boudewijn Rempt
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tqwidget.h>
#include <tqrect.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqwhatsthis.h>
#include <tqcheckbox.h>
#include <kdebug.h>
#include <klocale.h>
#include <knuminput.h>
#include <kiconloader.h>
#include "kis_button_release_event.h"
#include "kis_canvas_subject.h"
#include "kis_cmb_composite.h"
#include "kis_colorspace.h"
#include "kis_config.h"
#include "kis_cursor.h"
#include "kis_global.h"
#include "kis_image.h"
#include "kis_int_spinbox.h"
#include "kis_paint_device.h"
#include "kis_tool_controller.h"
#include "kis_tool_paint.h"
KisToolPaint::KisToolPaint(const TQString& UIName)
: super(UIName)
{
m_subject = 0;
m_UIName = UIName;
m_optionWidget = 0;
m_optionWidgetLayout = 0;
m_lbOpacity = 0;
m_slOpacity = 0;
m_lbComposite= 0;
m_cmbComposite = 0;
m_opacity = OPACITY_OPAQUE;
m_compositeOp = COMPOSITE_OVER;
}
KisToolPaint::~KisToolPaint()
{
}
void KisToolPaint::update(KisCanvasSubject *subject)
{
m_subject = subject;
updateCompositeOpComboBox();
}
void KisToolPaint::paint(KisCanvasPainter&)
{
}
void KisToolPaint::paint(KisCanvasPainter&, const TQRect&)
{
}
void KisToolPaint::deactivate()
{
}
void KisToolPaint::buttonPress(KisButtonPressEvent *)
{
}
void KisToolPaint::move(KisMoveEvent *)
{
}
void KisToolPaint::buttonRelease(KisButtonReleaseEvent * e)
{
kdDebug() << "buttonRelease" << endl;
if(e->button() == Qt::MidButton)
{
kdDebug() << "switch" << endl;
KisColor bg = m_subject->bgColor();
m_subject->setBGColor(m_subject->fgColor());
m_subject->setFGColor(bg);
}
}
void KisToolPaint::doubleClick(KisDoubleClickEvent *)
{
}
void KisToolPaint::keyPress(TQKeyEvent *)
{
}
void KisToolPaint::keyRelease(TQKeyEvent *)
{
}
TQWidget* KisToolPaint::createOptionWidget(TQWidget* parent)
{
m_optionWidget = new TQWidget(parent);
m_optionWidget->setCaption(m_UIName);
m_lbOpacity = new TQLabel(i18n("Opacity:"), m_optionWidget);
m_slOpacity = new KisIntSpinbox( m_optionWidget, "int_m_optionwidget");
m_slOpacity->setRange( 0, 100);
m_slOpacity->setValue(m_opacity / OPACITY_OPAQUE * 100);
connect(m_slOpacity, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetOpacity(int)));
m_lbComposite = new TQLabel(i18n("Mode:"), m_optionWidget);
m_cmbComposite = new KisCmbComposite(m_optionWidget);
connect(m_cmbComposite, TQT_SIGNAL(activated(const KisCompositeOp&)), this, TQT_SLOT(slotSetCompositeMode(const KisCompositeOp&)));
TQVBoxLayout* verticalLayout = new TQVBoxLayout(m_optionWidget);
verticalLayout->setMargin(0);
verticalLayout->setSpacing(3);
m_optionWidgetLayout = new TQGridLayout(verticalLayout, 2, 3, 6);
m_optionWidgetLayout->addWidget(m_lbOpacity, 0, 0);
m_optionWidgetLayout->addWidget(m_slOpacity, 0, 1);
m_optionWidgetLayout->addWidget(m_lbComposite, 1, 0);
m_optionWidgetLayout->addWidget(m_cmbComposite, 1, 1);
verticalLayout->addItem(new TQSpacerItem(0,0,TQSizePolicy::Fixed,TQSizePolicy::Expanding));
if (!quickHelp().isEmpty()) {
TQPushButton* push = new TQPushButton(SmallIconSet( "help" ), "", m_optionWidget);
connect(push, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotPopupQuickHelp()));
TQHBoxLayout* hLayout = new TQHBoxLayout(m_optionWidget);
hLayout->addWidget(push);
hLayout->addItem(new TQSpacerItem(0,0,TQSizePolicy::Expanding,TQSizePolicy::Fixed));
verticalLayout->addLayout(hLayout);
}
return m_optionWidget;
}
TQWidget* KisToolPaint::optionWidget()
{
return m_optionWidget;
}
void KisToolPaint::addOptionWidgetLayout(TQLayout *layout)
{
Q_ASSERT(m_optionWidget != 0);
Q_ASSERT(m_optionWidgetLayout != 0);
int rowCount = m_optionWidgetLayout->numRows();
m_optionWidgetLayout->addMultiCellLayout(layout, rowCount, rowCount, 0, 1);
}
void KisToolPaint::addOptionWidgetOption(TQWidget *control, TQWidget *label)
{
Q_ASSERT(m_optionWidget != 0);
Q_ASSERT(m_optionWidgetLayout != 0);
if(label)
{
m_optionWidgetLayout->addWidget(label, m_optionWidgetLayout->numRows(), 0);
m_optionWidgetLayout->addWidget(control, m_optionWidgetLayout->numRows()-1, 1);
}
else
m_optionWidgetLayout->addMultiCellWidget(control, m_optionWidgetLayout->numRows(), m_optionWidgetLayout->numRows(), 0, 1);
}
void KisToolPaint::slotSetOpacity(int opacityPerCent)
{
m_opacity = opacityPerCent * OPACITY_OPAQUE / 100;
}
void KisToolPaint::slotSetCompositeMode(const KisCompositeOp& compositeOp)
{
m_compositeOp = compositeOp;
}
TQCursor KisToolPaint::cursor()
{
return m_cursor;
}
void KisToolPaint::setCursor(const TQCursor& cursor)
{
m_cursor = cursor;
if (m_subject) {
KisToolControllerInterface *controller = m_subject->toolController();
if (controller && controller->currentTool() == this) {
m_subject->canvasController()->setCanvasCursor(m_cursor);
}
}
}
void KisToolPaint::activate()
{
if (m_subject) {
KisToolControllerInterface *controller = m_subject->toolController();
if (controller)
controller->setCurrentTool(this);
updateCompositeOpComboBox();
KisConfig cfg;
m_paintOutline = (cfg.cursorStyle() == CURSOR_STYLE_OUTLINE);
}
}
void KisToolPaint::notifyModified() const
{
if (m_subject && m_subject->currentImg()) {
m_subject->currentImg()->setModified();
}
}
void KisToolPaint::updateCompositeOpComboBox()
{
if (m_optionWidget && m_subject) {
KisImageSP img = m_subject->currentImg();
if (img) {
KisPaintDeviceSP device = img->activeDevice();
if (device) {
KisCompositeOpList compositeOps = device->colorSpace()->userVisiblecompositeOps();
m_cmbComposite->setCompositeOpList(compositeOps);
if (compositeOps.find(m_compositeOp) == compositeOps.end()) {
m_compositeOp = COMPOSITE_OVER;
}
m_cmbComposite->setCurrentItem(m_compositeOp);
}
}
}
}
void KisToolPaint::slotPopupQuickHelp() {
TQWhatsThis::display(quickHelp());
}
#include "kis_tool_paint.moc"
|