-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathQtPanel.h
100 lines (75 loc) · 2.62 KB
/
QtPanel.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
90
91
92
93
94
95
96
97
98
99
100
/**
Livewire Qt Demo - Demo for running the Livewire algorithm
Copyright (C) 2011 Jeffrey Bush jeff@coderforlife.com
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
#ifndef LIVEWIREQTPANEL_H
#define LIVEWIREQTPANEL_H
#include "LivewireCalculator.h"
#include <QWidget>
#include <QImage>
#include <QPoint>
#include <QVector>
namespace Livewire
{
class QtPanel : public QWidget
{
Q_OBJECT
private:
/// <summary>The pen used to draw the active livewire</summary>
static const QPen LivewirePen;
/// <summary>The pen used to draw the static previous wires</summary>
static const QPen PrevwirePen;
/// <summary>The pen used to draw the wrapping livewire</summary>
static const QPen WrapwirePen;
static const QBrush MouseBrush;
static const QBrush PointBrush;
static const QBrush NotCalculatedBrush;
static const QBrush CalculatingBrush;
private:
QImage image;
uint w, h;
QPoint mouse;
QVector<QPoint> points;
LivewireCalculator *livewire;
LivewireCalculator *wrapwire;
QImage prevwires;
bool showCalculationBlocks;
uint availSize;
void Cleanup();
public:
QtPanel(QWidget *parent = NULL);
~QtPanel();
void SetImage(QImage &img);
/// <summary>Reset the current state of the livewires</summary>
void Reset();
protected:
void paintEvent(QPaintEvent *evnt);
void mouseMoveEvent(QMouseEvent *evnt);
void mousePressEvent(QMouseEvent *evnt);
void mouseDoubleClickEvent(QMouseEvent *evnt);
private:
/// <summary>Handles mouse clicking and double clicking. </summary>
/// <param name="evnt">The mouse event arguments</param>
/// <param name="dbl">True if the mouse double clicked</param>
void MouseClicked(QMouseEvent *evnt, bool dbl);
void AddEventsToThreaded(const Threaded *t) const;
/// <summary>Moves the point to be within the bounds of the image</summary>
/// <param name="p">The point to move</param>
/// <returns>The adjusted point</returns>
void getPointInBounds(QPoint &p);
private slots:
void ShowContextMenu(const QPoint &p);
};
}
#endif