Engauge Digitizer 2
Loading...
Searching...
No Matches
CursorFactory.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CursorFactory.h"
8#include "CursorSize.h"
10#include <QBitmap>
11#include <QPainter>
12#include <QPixmap>
13
17
18QCursor CursorFactory::generate (const DocumentModelDigitizeCurve &modelDigitizeCurve) const
19{
20 // To prevent hideous drawing errors when the line is thicker, we
21 // leave a padding region around the outside equal in size to the line width
22 int innerRadius = modelDigitizeCurve.cursorInnerRadius();
23 int size = CursorSizeToPixels (modelDigitizeCurve.cursorSize());
24 int halfSize = size / 2;
25 int lineWidth = modelDigitizeCurve.cursorLineWidth();
26 int halfLineWidth = lineWidth / 2;
27
28 if (modelDigitizeCurve.cursorStandardCross()) {
29
30 // Standard cursor
31 return QCursor (Qt::CrossCursor);
32
33 } else {
34
35 // Custom cursor
36 const int BACKGROUND_COLOR = Qt::white, FOREGROUND_COLOR = Qt::black;
37
38 // Cursor is created with pic image (which has nontrivial pen) masked by picMask image
39 // (which has single color pen)
40 QPixmap picMask (size,
41 size);
42 QPainter picMaskPaint (&picMask);
43 picMask.fill (QColor (BACKGROUND_COLOR));
44
45 QPen pen (QBrush (FOREGROUND_COLOR),
46 modelDigitizeCurve.cursorLineWidth());
47 picMaskPaint.setPen (pen);
48
49 picMaskPaint.drawLine (QPointF (halfSize,
50 halfSize - innerRadius - halfLineWidth),
51 QPointF (halfSize,
52 lineWidth)); // Up
53 picMaskPaint.drawLine (QPointF (halfSize - innerRadius - halfLineWidth,
54 halfSize),
55 QPointF (lineWidth,
56 halfSize)); // Left
57 picMaskPaint.drawLine (QPointF (halfSize,
58 halfSize + innerRadius + halfLineWidth),
59 QPointF (halfSize,
60 size - 1 - lineWidth)); // Down
61 picMaskPaint.drawLine (QPointF (halfSize + innerRadius + halfLineWidth,
62 halfSize),
63 QPointF (size - 1 - lineWidth,
64 halfSize)); // Right
65
66 QPixmap pic (size,
67 size);
68 pic.fill (QColor (FOREGROUND_COLOR));
69
70 return QCursor (pic.createMaskFromColor(QColor (BACKGROUND_COLOR)),
71 picMask.createMaskFromColor(QColor (BACKGROUND_COLOR)));
72 }
73}
int CursorSizeToPixels(CursorSize cursorSize)
CursorFactory()
Single constructor.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
CursorSize cursorSize() const
Get method for cursor size.
int cursorInnerRadius() const
Get method for cursor inner radius.
bool cursorStandardCross() const
Get method for cursor type.
int cursorLineWidth() const
Get method for cursor line width.