All Classes Namespaces Functions Variables Enumerations Properties Pages
stroketool.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
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.
15 
16 */
17 
18 #include "stroketool.h"
19 
20 #include <QKeyEvent>
21 #include "scribblearea.h"
22 #include "strokemanager.h"
23 #include "viewmanager.h"
24 #include "editor.h"
25 #include "toolmanager.h"
26 
27 #ifdef Q_OS_MAC
28 extern "C" {
29  void detectWhichOSX();
30  void disableCoalescing();
31  void enableCoalescing();
32 }
33 #else
34 extern "C" {
35  void detectWhichOSX() {}
36  void disableCoalescing() {}
37  void enableCoalescing() {}
38 }
39 #endif
40 
41 StrokeTool::StrokeTool(QObject* parent) : BaseTool(parent)
42 {
43  detectWhichOSX();
44 }
45 
46 void StrokeTool::startStroke(PointerEvent::InputType inputType)
47 {
49  {
50  mScribbleArea->handleDrawingOnEmptyFrame();
51  }
52 
53  mFirstDraw = true;
54  mLastPixel = getCurrentPixel();
55 
56  mStrokePoints.clear();
57 
58  //Experimental
59  QPointF startStrokes = strokeManager()->interpolateStart(mLastPixel);
60  mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
61 
62  mStrokePressures.clear();
63  mStrokePressures << strokeManager()->getPressure();
64 
65  mCurrentInputType = inputType;
66 
67  disableCoalescing();
68 }
69 
70 bool StrokeTool::keyPressEvent(QKeyEvent *event)
71 {
72  switch (event->key()) {
73  case Qt::Key_Alt:
74  if (mEditor->tools()->setTemporaryTool(EYEDROPPER, {}, Qt::AltModifier))
75  {
76  return true;
77  }
78  break;
79  case Qt::Key_Space:
80  if (mEditor->tools()->setTemporaryTool(HAND, Qt::Key_Space, Qt::NoModifier))
81  {
82  return true;
83  }
84  break;
85  }
86  return BaseTool::keyPressEvent(event);
87 }
88 
90 {
91  return true;
92 }
93 
94 void StrokeTool::endStroke()
95 {
96  strokeManager()->interpolateEnd();
97  mStrokePressures << strokeManager()->getPressure();
98  mStrokePoints.clear();
99  mStrokePressures.clear();
100 
101  enableCoalescing();
102 
103  mScribbleArea->setModified(mEditor->currentLayerIndex(), mEditor->currentFrame());
104 }
105 
106 void StrokeTool::drawStroke()
107 {
108  QPointF pixel = getCurrentPixel();
109  if (pixel != mLastPixel || !mFirstDraw)
110  {
111  // get last pixel before interpolation initializes
112  QPointF startStrokes = strokeManager()->interpolateStart(getLastPixel());
113  mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
114  mStrokePressures << strokeManager()->getPressure();
115  }
116  else
117  {
118  mFirstDraw = false;
119  }
120 }
void clear()
AltModifier
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:89
void setModified(int layerNumber, int frameNumber)
Set frame on layer to modified and invalidate current frame cache.
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
int key() const const