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 
26 #ifdef Q_OS_MAC
27 extern "C" {
28  void detectWhichOSX();
29  void disableCoalescing();
30  void enableCoalescing();
31 }
32 #else
33 extern "C" {
34  void detectWhichOSX() {}
35  void disableCoalescing() {}
36  void enableCoalescing() {}
37 }
38 #endif
39 
40 StrokeTool::StrokeTool(QObject* parent) : BaseTool(parent)
41 {
42  detectWhichOSX();
43 }
44 
45 void StrokeTool::startStroke(PointerEvent::InputType inputType)
46 {
48  {
49  mScribbleArea->handleDrawingOnEmptyFrame();
50  }
51 
52  mFirstDraw = true;
53  mLastPixel = getCurrentPixel();
54 
55  mStrokePoints.clear();
56 
57  //Experimental
58  QPointF startStrokes = strokeManager()->interpolateStart(mLastPixel);
59  mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
60 
61  mStrokePressures.clear();
62  mStrokePressures << strokeManager()->getPressure();
63 
64  mCurrentInputType = inputType;
65 
66  disableCoalescing();
67 }
68 
69 bool StrokeTool::keyPressEvent(QKeyEvent *event)
70 {
71  switch (event->key()) {
72  case Qt::Key_Alt:
73  mScribbleArea->setTemporaryTool(EYEDROPPER);
74  return true;
75  case Qt::Key_Space:
76  mScribbleArea->setTemporaryTool(HAND); // just call "setTemporaryTool()" to activate temporarily any tool
77  return true;
78  }
79  return false;
80 }
81 
82 bool StrokeTool::keyReleaseEvent(QKeyEvent *event)
83 {
84  Q_UNUSED(event);
85  return true;
86 }
87 
89 {
90  return true;
91 }
92 
93 void StrokeTool::endStroke()
94 {
95  strokeManager()->interpolateEnd();
96  mStrokePressures << strokeManager()->getPressure();
97  mStrokePoints.clear();
98  mStrokePressures.clear();
99 
100  enableCoalescing();
101 }
102 
103 void StrokeTool::drawStroke()
104 {
105  QPointF pixel = getCurrentPixel();
106  if (pixel != mLastPixel || !mFirstDraw)
107  {
108  // get last pixel before interpolation initializes
109  QPointF startStrokes = strokeManager()->interpolateStart(getLastPixel());
110  mStrokePoints << mEditor->view()->mapScreenToCanvas(startStrokes);
111  mStrokePressures << strokeManager()->getPressure();
112  }
113  else
114  {
115  mFirstDraw = false;
116  }
117 }
void clear()
virtual bool emptyFrameActionEnabled()
Whether to enable the "drawing on empty frame" preference.
Definition: stroketool.cpp:88
void handleDrawingOnEmptyFrame()
Call this when starting to use a paint tool.
int key() const const