-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
IconButton.cxx
81 lines (58 loc) · 2.06 KB
/
IconButton.cxx
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
/*
This file is part of liquidshell.
SPDX-FileCopyrightText: 2017 - 2024 Martin Koller <kollix@aon.at>
SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <IconButton.hxx>
#include <QHBoxLayout>
//--------------------------------------------------------------------------------
IconButton::IconButton(QWidget *parent)
: QToolButton(parent)
{
setAutoRaise(true);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
QHBoxLayout *hbox = new QHBoxLayout(this);
iconLabel = new QLabel;
iconLabel->setFixedSize(iconSize());
iconLabel->setContextMenuPolicy(Qt::PreventContextMenu);
hbox->addWidget(iconLabel);
icon2Label = new QLabel;
icon2Label->setFixedSize(iconSize());
icon2Label->setContextMenuPolicy(Qt::PreventContextMenu);
icon2Label->hide(); // until an icon is set
hbox->addWidget(icon2Label);
textLabel = new QLabel;
hbox->addWidget(textLabel);
}
//--------------------------------------------------------------------------------
IconButton::IconButton(QWidget *parent, const QIcon &icon, int theIconSize, const QString &name)
: IconButton(parent)
{
if ( theIconSize != -1 )
setIconSize(QSize(theIconSize, theIconSize));
iconLabel->setFixedSize(iconSize());
iconLabel->setPixmap(icon.pixmap(iconSize()));
textLabel->setText(name);
}
//--------------------------------------------------------------------------------
void IconButton::setText(const QString &txt)
{
textLabel->setText(txt);
}
//--------------------------------------------------------------------------------
void IconButton::setIcon(const QIcon &icon)
{
iconLabel->setPixmap(icon.pixmap(iconSize()));
}
//--------------------------------------------------------------------------------
void IconButton::setIcon2(const QIcon &icon)
{
icon2Label->setPixmap(icon.pixmap(iconSize()));
icon2Label->show();
}
//--------------------------------------------------------------------------------
QSize IconButton::sizeHint() const
{
return layout()->sizeHint();
}
//--------------------------------------------------------------------------------