-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscribblearea.h
89 lines (70 loc) · 2.54 KB
/
scribblearea.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* scribble: Scribbling Application for Onyx Boox M92
*
* Copyright (C) 2012 peter-x
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SCRIBBLEAREA_H
#define SCRIBBLEAREA_H
#include <QWidget>
#include <QPainter>
#include <QTimer>
#include "scribble_document.h"
class ScribbleGraphicsContext
{
public:
/* draw to QWidget */
ScribbleGraphicsContext(QPainter *painter, bool undraw) : widget(0), painter(painter), undraw(undraw) {}
/* directly draw to screen */
ScribbleGraphicsContext(QWidget *widget, bool undraw) : widget(widget), painter(0), undraw(undraw) {}
void drawPage(const ScribblePage &page, int maxLayer);
void drawStroke(const ScribbleStroke &stroke);
void drawStrokeSegment(const ScribbleStroke &stroke, int i);
private:
void drawLinePainter(const QPoint &p1, const QPoint &p2, unsigned char color, int width);
void drawLineDirect(const QPoint &p1, const QPoint &p2, unsigned char color, int width);
QWidget *widget;
QPainter *painter;
bool undraw;
};
class ScribbleArea : public QWidget
{
Q_OBJECT
public:
explicit ScribbleArea(QWidget *parent, const ScribbleDocument *document);
signals:
void resized(const QSize &size);
public slots:
void redrawPage(const ScribblePage &page, int layer);
void drawLastStrokeSegment(const ScribbleStroke &);
void drawCompletedStroke(const ScribbleStroke &);
void updateStrokes(const ScribblePage &page, int layer, const QList<ScribbleStroke> &removedStrokes);
protected:
void resizeEvent(QResizeEvent *);
private slots:
void updateIfNeeded();
private:
void paintEvent(QPaintEvent *);
/* uses painter on x86 */
void drawStroke(const ScribbleStroke &s, bool unpaint = false);
/* uses painter on x86 */
void drawStrokeSegment(const ScribbleStroke &s, int i, bool unpaint = false);
const ScribbleDocument *document;
QImage buffer;
QRegion regionToUpdate;
QTimer updateTimer;
};
#endif // SCRIBBLEAREA_H