~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to krita/ui/tool/kis_tool_paint.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
#include "widgets/kis_slider_spin_box.h"
66
66
#include "kis_canvas_resource_provider.h"
67
67
#include <recorder/kis_recorded_paint_action.h>
 
68
#include <kis_cubic_curve.h>
 
69
#include "kis_color_picker_utils.h"
68
70
 
69
71
 
70
72
KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)
71
 
        : KisTool(canvas, cursor), m_previousNode(0)
 
73
        : KisTool(canvas, cursor)
72
74
{
73
75
    m_optionWidgetLayout = 0;
74
76
 
75
77
    m_lbOpacity = 0;
76
78
    m_slOpacity = 0;
77
 
    m_lbComposite = 0;
78
 
    m_cmbComposite = 0;
79
79
 
80
80
    m_opacity = OPACITY_OPAQUE_U8;
81
81
    m_compositeOp = 0;
82
82
 
 
83
    updateTabletPressureSamples();
 
84
 
83
85
    m_supportOutline = false;
 
86
 
 
87
    KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas);
 
88
 
 
89
 
 
90
    connect(kiscanvas->view()->resourceProvider(), SIGNAL(sigCompositeOpChanged(QString)), this, SLOT(slotSetCompositeMode(QString))); 
 
91
    connect(this, SIGNAL(sigFavoritePaletteCalled(const QPoint&)), kiscanvas, SIGNAL(favoritePaletteCalled(const QPoint&)));
 
92
    connect(this, SIGNAL(sigPaintingFinished()), kiscanvas->view()->resourceProvider(), SLOT(slotPainting()));
84
93
}
85
94
 
86
95
 
92
101
{
93
102
    KisTool::resourceChanged(key, v);
94
103
 
95
 
    switch (key) {
96
 
    case(KisCanvasResourceProvider::CurrentKritaNode):
97
 
        updateCompositeOpComboBox();
98
 
        // Deconnect colorspace change of previous node
99
 
        if (m_previousNode) {
100
 
            if (m_previousNode->paintDevice()) {
101
 
                disconnect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), this, SLOT(updateCompositeOpComboBox()));
102
 
            }
103
 
        }
104
 
        // Reconnect colorspace change of node
105
 
        m_previousNode = currentNode();
106
 
        if (m_previousNode && m_previousNode->paintDevice()) {
107
 
            connect(m_previousNode->paintDevice().data(), SIGNAL(colorSpaceChanged(const KoColorSpace*)), SLOT(updateCompositeOpComboBox()));
108
 
        }
109
 
        break;
110
 
    default:
111
 
        ; // Do nothing
 
104
    switch(key){
 
105
        case(KisCanvasResourceProvider::CurrentKritaNode):
 
106
            slotSetCompositeMode(canvas()->resourceManager()->resource(KisCanvasResourceProvider::CurrentCompositeOp).toString());
 
107
            break;
 
108
        default: //nothing
 
109
            break;
112
110
    }
113
111
 
114
112
    connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(resetCursorStyle()));
 
113
    connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(updateTabletPressureSamples()));
115
114
 
116
115
}
117
116
 
119
118
void KisToolPaint::activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes)
120
119
{
121
120
    KisTool::activate(toolActivation, shapes);
 
121
    KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
 
122
    slotSetCompositeMode(kiscanvas->view()->resourceProvider()->currentCompositeOp());
122
123
    resetCursorStyle();
123
124
}
124
125
 
127
128
{
128
129
}
129
130
 
130
 
 
131
 
void KisToolPaint::mouseReleaseEvent(KoPointerEvent *e)
132
 
{
133
 
    if (e->button() == Qt::RightButton) {
134
 
        //CALLING POP UP PALETTE
135
 
        emit sigFavoritePaletteCalled(e->pos());
136
 
 
137
 
//        KoResourceManager * resourceProvider = 0;
138
 
//        if (canvas() && (resourceProvider = canvas()->resourceProvider())) {
139
 
//            QVariant fg = resourceProvider->resource(KoCanvasResource::ForegroundColor);
140
 
//            if (!fg.isValid()) return;
141
 
//            QVariant bg = resourceProvider->resource(KoCanvasResource::BackgroundColor);
142
 
//            if (!bg.isValid()) return;
143
 
//            resourceProvider->setResource(KoCanvasResource::ForegroundColor, bg);
144
 
//            resourceProvider->setResource(KoCanvasResource::BackgroundColor, fg);
145
 
//        }
146
 
    }
147
 
}
148
 
 
 
131
void KisToolPaint::setMode(ToolMode mode)
 
132
{
 
133
    if(this->mode() == KisTool::PAINT_MODE &&
 
134
       mode != KisTool::PAINT_MODE) {
 
135
 
 
136
        // Let's add history information about recently used colors
 
137
        emit sigPaintingFinished();
 
138
    }
 
139
 
 
140
    KisTool::setMode(mode);
 
141
}
 
142
 
 
143
void KisToolPaint::mousePressEvent(KoPointerEvent *event)
 
144
{
 
145
    if(mode() == KisTool::HOVER_MODE &&
 
146
       (event->button() == Qt::LeftButton || event->button() == Qt::RightButton) &&
 
147
       event->modifiers() & Qt::ControlModifier &&
 
148
       !specialModifierActive()) {
 
149
 
 
150
        setMode(SECONDARY_PAINT_MODE);
 
151
        useCursor(KisCursor::pickerCursor());
 
152
 
 
153
        m_toForegroundColor = event->button() == Qt::LeftButton;
 
154
        pickColor(event->point, event->modifiers() & Qt::AltModifier,
 
155
                  m_toForegroundColor);
 
156
        event->accept();
 
157
    }
 
158
    else if(mode() == KisTool::HOVER_MODE &&
 
159
            event->button() == Qt::RightButton &&
 
160
            event->modifiers() == Qt::NoModifier &&
 
161
            !specialModifierActive()) {
 
162
 
 
163
        emit sigFavoritePaletteCalled(event->pos());
 
164
        event->accept();
 
165
    }
 
166
    else {
 
167
        KisTool::mousePressEvent(event);
 
168
    }
 
169
}
 
170
 
 
171
void KisToolPaint::mouseMoveEvent(KoPointerEvent *event)
 
172
{
 
173
    if(mode() == KisTool::SECONDARY_PAINT_MODE) {
 
174
        pickColor(event->point, event->modifiers() & Qt::AltModifier,
 
175
                  m_toForegroundColor);
 
176
        event->accept();
 
177
    }
 
178
    else {
 
179
        KisTool::mouseMoveEvent(event);
 
180
    }
 
181
}
 
182
 
 
183
void KisToolPaint::mouseReleaseEvent(KoPointerEvent *event)
 
184
{
 
185
    if(mode() == KisTool::SECONDARY_PAINT_MODE) {
 
186
        setMode(KisTool::HOVER_MODE);
 
187
        resetCursorStyle();
 
188
        event->accept();
 
189
    }
 
190
    else {
 
191
        KisTool::mouseReleaseEvent(event);
 
192
    }
 
193
}
 
194
 
 
195
void KisToolPaint::keyPressEvent(QKeyEvent *event)
 
196
{
 
197
    KisTool::keyPressEvent(event);
 
198
}
 
199
 
 
200
void KisToolPaint::keyReleaseEvent(QKeyEvent* event)
 
201
{
 
202
    KisTool::keyReleaseEvent(event);
 
203
}
 
204
 
 
205
void KisToolPaint::pickColor(const QPointF &documentPixel,
 
206
                             bool fromCurrentNode,
 
207
                             bool toForegroundColor)
 
208
{
 
209
    if(m_colorPickerDelayTimer.isActive()) {
 
210
        return;
 
211
    }
 
212
    else {
 
213
        m_colorPickerDelayTimer.setSingleShot(true);
 
214
        m_colorPickerDelayTimer.start(100);
 
215
    }
 
216
 
 
217
    int resource = toForegroundColor ?
 
218
        KoCanvasResource::ForegroundColor : KoCanvasResource::BackgroundColor;
 
219
 
 
220
    KisPaintDeviceSP device = fromCurrentNode ?
 
221
        currentNode()->paintDevice() : image()->projection();
 
222
 
 
223
    QPoint imagePoint = image()->documentToIntPixel(documentPixel);
 
224
 
 
225
    canvas()->resourceManager()->
 
226
        setResource(resource, KisToolUtils::pick(device, imagePoint));
 
227
}
149
228
 
150
229
QWidget * KisToolPaint::createOptionWidget()
151
230
{
153
232
    QWidget * optionWidget = new QWidget();
154
233
    optionWidget->setObjectName(toolId());
155
234
 
156
 
    m_lbComposite = new QLabel(i18n("Mode: "), optionWidget);
157
 
    m_lbComposite->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
158
 
    m_cmbComposite = new KisCmbComposite(optionWidget);
159
 
    updateCompositeOpComboBox();
160
 
    connect(m_cmbComposite, SIGNAL(activated(const QString&)), this, SLOT(slotSetCompositeMode(const QString&)));
161
 
 
162
235
    m_lbOpacity = new QLabel(i18n("Opacity: "), optionWidget);
163
236
    m_lbOpacity->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
164
237
    m_slOpacity = new KisSliderSpinBox(optionWidget);
176
249
    m_optionWidgetLayout->setSpacing(1);
177
250
    m_optionWidgetLayout->setMargin(0);
178
251
 
179
 
    m_optionWidgetLayout->addWidget(m_lbComposite, 0, 0);
180
 
    m_optionWidgetLayout->addWidget(m_cmbComposite, 0, 1);
181
 
 
182
252
    m_optionWidgetLayout->addWidget(m_lbOpacity, 1, 0);
183
253
    m_optionWidgetLayout->addWidget(m_slOpacity, 1, 1);
184
254
 
229
299
 
230
300
void KisToolPaint::slotSetCompositeMode(const QString& compositeOp)
231
301
{
 
302
    Q_ASSERT(!compositeOp.isEmpty());
232
303
    if (currentNode()) {
233
304
        KisPaintDeviceSP device = currentNode()->paintDevice();
234
305
 
238
309
    }
239
310
}
240
311
 
241
 
 
242
 
void KisToolPaint::updateCompositeOpComboBox()
243
 
{
244
 
    if (m_cmbComposite && currentNode()) {
245
 
        KisPaintDeviceSP device = currentNode()->paintDevice();
246
 
 
247
 
        if (device) {
248
 
            QList<KoCompositeOp*> compositeOps = device->colorSpace()->compositeOps();
249
 
            m_cmbComposite->setCompositeOpList(compositeOps);
250
 
 
251
 
            if (m_compositeOp == 0 || compositeOps.indexOf(const_cast<KoCompositeOp*>(m_compositeOp)) < 0) {
252
 
                m_compositeOp = device->colorSpace()->compositeOp(COMPOSITE_OVER);
253
 
            }
254
 
            m_cmbComposite->setCurrent(m_compositeOp);
255
 
            m_cmbComposite->setEnabled(true);
256
 
        } else {
257
 
            m_cmbComposite->setEnabled(false);
258
 
        }
259
 
    }
260
 
}
261
 
 
262
312
void KisToolPaint::slotPopupQuickHelp()
263
313
{
264
314
    QWhatsThis::showText(QCursor::pos(), quickHelp());
282
332
#if defined(HAVE_OPENGL)
283
333
    // TODO: maybe m_support 3D outline would be cooler. So far just freehand tool support 3D_MODEL cursor style
284
334
    if (cfg.cursorStyle() == CURSOR_STYLE_3D_MODEL) {
285
 
        if (m_supportOutline) {
286
 
            useCursor(KisCursor::blankCursor());
 
335
        if(isCanvasOpenGL()) {
 
336
            if (m_supportOutline) {
 
337
                useCursor(KisCursor::blankCursor());
 
338
            } else {
 
339
                useCursor(cursor());
 
340
            }
287
341
        } else {
288
 
            useCursor(cursor());
 
342
            useCursor(KisCursor::arrowCursor());
289
343
        }
290
344
    }
291
345
#endif
293
347
 
294
348
}
295
349
 
 
350
void KisToolPaint::updateTabletPressureSamples()
 
351
{
 
352
    KisConfig cfg;
 
353
    KisCubicCurve curve;
 
354
    curve.fromString(cfg.pressureTabletCurve());
 
355
    m_pressureSamples = curve.floatTransfer(LEVEL_OF_PRESSURE_RESOLUTION + 1);
 
356
}
 
357
 
 
358
void KisToolPaint::setupPainter(KisPainter* painter)
 
359
{
 
360
    KisTool::setupPainter(painter);
 
361
    painter->setOpacity(m_opacity);
 
362
    painter->setCompositeOp(m_compositeOp);
 
363
}
 
364
 
296
365
void KisToolPaint::setupPaintAction(KisRecordedPaintAction* action)
297
366
{
298
367
    KisTool::setupPaintAction(action);
299
 
    action->setOpacity(m_opacity / (qreal) 255.0);
 
368
    action->setOpacity(m_opacity / qreal(255.0));
300
369
    if (m_compositeOp) {
301
370
        action->setCompositeOp(m_compositeOp->id());
302
371
    }
303
372
}
304
373
 
 
374
KisToolPaint::NodePaintAbility KisToolPaint::nodePaintAbility()
 
375
{
 
376
    KisNodeSP node = currentNode();
 
377
    if (!node || node->systemLocked() || node->inherits("KisSelectionMask")) {
 
378
        return NONE;
 
379
    }
 
380
    if (node->inherits("KisShapeLayer")) {
 
381
        return VECTOR;
 
382
    }
 
383
    if (node->paintDevice()) {
 
384
        return PAINT;
 
385
    }
 
386
    return NONE;
 
387
}
 
388
 
 
389
 
305
390
#include "kis_tool_paint.moc"