-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDockingToolButton.cpp
114 lines (90 loc) · 3.18 KB
/
DockingToolButton.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* This file is part of DockingPanes. (https://github.com/KestrelRadarSensors/dockingpanes)
*
* (C) 2020 Kestrel Radar Sensors (https://www.kestrelradarsensors.com)
*
* DockingPanes 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.
*
* DockingPanes 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 DockingPanes. If not, see <https://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QImage>
#include <QPainter>
#include <QPaintEvent>
#include "DockingToolButton.h"
DockingToolButton::DockingToolButton(DockingToolButton::ButtonType type, QWidget *parent) :
QPushButton(parent)
{
setMouseTracking(true);
m_buttonType = type;
m_highlight = false;
}
void DockingToolButton::enterEvent(QEvent* event)
{
m_highlight = true;
QPushButton::enterEvent(event);
}
void DockingToolButton::leaveEvent(QEvent* event)
{
m_highlight = false;
QPushButton::leaveEvent(event);
}
void DockingToolButton::paintEvent(QPaintEvent*)
{
QImage buttonImage;
QPainter p(this);
int centreX = width()/2;
int centreY = height()/2;
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHint(QPainter::HighQualityAntialiasing, true);
switch(m_buttonType) {
case closeButtonInactive: {
buttonImage.load(":/img/tool_button_bitmaps/close_inactive.png");
break;
}
case closeButtonActive: {
buttonImage.load(":/img/tool_button_bitmaps/close_active.png");
break;
}
case pinButtonInactive: {
buttonImage.load(":/img/tool_button_bitmaps/pin_inactive.png");
break;
}
case pinButtonActive: {
buttonImage.load(":/img/tool_button_bitmaps/pin_active.png");
break;
}
case unpinButtonInactive: {
buttonImage.load(":/img/tool_button_bitmaps/pin_inactive.png");
buttonImage = buttonImage.transformed(QTransform().rotate(90));
break;
}
case unpinButtonActive: {
buttonImage.load(":/img/tool_button_bitmaps/pin_active.png");
buttonImage = buttonImage.transformed(QTransform().rotate(90));
break;
}
}
p.drawImage(centreX-(buttonImage.width()/2), centreY-(buttonImage.height()/2), buttonImage);
QRect rcHighlight;
rcHighlight.setLeft(centreX-(buttonImage.width()/2)-2);
rcHighlight.setRight(centreX+(buttonImage.width()/2)+2);
rcHighlight.setTop(centreY-(buttonImage.height()/2)-2);
rcHighlight.setBottom(centreY+(buttonImage.height()/2)+2);
if (m_highlight) {
p.fillRect(rcHighlight, QColor(0xFF, 0xFF, 0xFF, 0xAA));
}
}
void DockingToolButton::setButton(DockingToolButton::ButtonType type)
{
m_buttonType = type;
update();
}