Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
stroketool.cpp
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 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 "scribblearea.h"
21 #include "strokemanager.h"
22 #include "editor.h"
23 
24 #ifdef Q_OS_MAC
25 extern "C" {
26  void detectWhichOSX();
27  void disableCoalescing();
28  void enableCoalescing();
29 }
30 #else
31 extern "C" {
32  void detectWhichOSX() {}
33  void disableCoalescing() {}
34  void enableCoalescing() {}
35 }
36 #endif
37 
38 StrokeTool::StrokeTool( QObject *parent ) :
39 BaseTool( parent )
40 {
41  detectWhichOSX();
42 }
43 
44 void StrokeTool::startStroke()
45 {
46  mFirstDraw = true;
47  mLastPixel = getCurrentPixel();
48 
49  mStrokePoints.clear();
50 
51  //Experimental
52  QPointF startStrokes = m_pStrokeManager->interpolateStart(mLastPixel);
53  mStrokePoints << mEditor->view()->mapScreenToCanvas( startStrokes );
54 
55  mStrokePressures.clear();
56  mStrokePressures << m_pStrokeManager->getPressure();
57 
58  disableCoalescing();
59 }
60 
61 bool StrokeTool::keyPressEvent(QKeyEvent *event)
62 {
63  switch ( event->key() ) {
64  case Qt::Key_Alt:
65  mScribbleArea->setTemporaryTool( EYEDROPPER );
66  return true;
67  case Qt::Key_Space:
68  mScribbleArea->setTemporaryTool( HAND ); // just call "setTemporaryTool()" to activate temporarily any tool
69  return true;
70  }
71  return false;
72 }
73 
74 bool StrokeTool::keyReleaseEvent(QKeyEvent *event)
75 {
76  Q_UNUSED(event);
77  return true;
78 }
79 
80 void StrokeTool::endStroke()
81 {
82  m_pStrokeManager->interpolateEnd();
83  mStrokePressures << m_pStrokeManager->getPressure();
84  mStrokePoints.clear();
85  mStrokePressures.clear();
86 
87  enableCoalescing();
88 }
89 
90 void StrokeTool::drawStroke()
91 {
92  QPointF pixel = getCurrentPixel();
93  if ( pixel != mLastPixel || !mFirstDraw )
94  {
95 
96  // get last pixel before interpolation initializes
97  QPointF startStrokes = m_pStrokeManager->interpolateStart(getLastPixel());
98  mStrokePoints << mEditor->view()->mapScreenToCanvas( startStrokes );
99  mStrokePressures << m_pStrokeManager->getPressure();
100 
101  }
102  else
103  {
104  mFirstDraw = false;
105  }
106 }