-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconButton.cpp
More file actions
64 lines (50 loc) · 1.52 KB
/
Copy pathIconButton.cpp
File metadata and controls
64 lines (50 loc) · 1.52 KB
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
#include "iconbutton.h"
#include "delegates/fadableitemcomposite.h"
#include "delegates/fadableitem.h"
#include "widgetsettings.h"
#include "delegates/mousehoverable.h"
IconButton::IconButton(QWidget *fader) :
MouseHoverComposite(new MouseHoverable(this))
{
setMouseHoverColor(WidgetSettings::iconButtonMouseOverColor());
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
RecalcSize();
}
QSize IconButton::sizeHint() const
{
return m_size;
}
QSize IconButton::minimumSizeHint() const
{
return m_size;
}
void IconButton::paintEvent(QPaintEvent *)
{
int xOff = (rect().width() - m_size.width()) / 2;
int yOff = (rect().height() - m_size.height()) / 2;
QRect target(xOff + WidgetSettings::iconButtonMargins(),
yOff + WidgetSettings::iconButtonMargins(),
m_size.width() - WidgetSettings::iconButtonMargins() * 2,
m_size.height() - WidgetSettings::iconButtonMargins() * 2);
QPainter painter(this);
DrawMouseHoverRect(painter);
m_svgRenderer.render(&painter, target);
}
void IconButton::resizeEvent(QResizeEvent *)
{
RecalcSize();
}
void IconButton::RecalcSize()
{
int h = rect().height();
if (h < (WidgetSettings::minimalIconSize().width() + 2 * WidgetSettings::iconButtonMargins()))
{
h = WidgetSettings::minimalIconSize().width() + 2 * WidgetSettings::iconButtonMargins();
}
m_size = QSize(h, h);
setFixedSize(m_size);
}
void IconButton::setSVG(const QString &name)
{
m_svgRenderer.load(name);
}