-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbottombuttongroup.cpp
72 lines (64 loc) · 2.21 KB
/
bottombuttongroup.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
#include "bottombuttongroup.h"
#include "opacityhelper.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <functional>
BottomButtonGroup::BottomButtonGroup(QWidget *parent)
: QGroupBox(parent)
, m_opacityHelper(new OpacityHelper(this))
{
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
this->setLayout(mainLayout);
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->setStyleSheet("BottomButtonGroup {"
"border: 1px solid gray;"
"border-top-left-radius: 10px;"
"border-top-right-radius: 10px;"
"border-style: none;"
"background-color:rgba(0,0,0,120)"
"}"
"QPushButton {"
"background-color:rgba(225,255,255,0);"
"color: white;"
"border-style: none"
"}");
auto newBtn = [](QString text, std::function<void()> func) -> QPushButton * {
QPushButton *btn = new QPushButton(QIcon(QStringLiteral(":/icons/") + text), "");
btn->setIconSize(QSize(40, 40));
btn->setFixedSize(40, 40);
connect(btn, &QPushButton::clicked, btn, func);
return btn;
};
// 1:1大小
addButton(newBtn("zoom-original", [this]() {
emit resetToOriginalBtnClicked();
}));
addButton(newBtn("view-fullscreen", [this]() {
emit toggleWindowMaximum();
}));
// 放大
addButton(newBtn("zoom-in", [this]() {
emit zoomInBtnClicked();
}));
// 缩小
addButton(newBtn("zoom-out", [this]() {
emit zoomOutBtnClicked();
}));
// 背景马赛克
addButton(newBtn("view-background-checkerboard", [this]() {
emit toggleCheckerboardBtnClicked();
}));
addButton(newBtn("object-rotate-right", [this]() {
emit rotateRightBtnClicked();
}));
}
void BottomButtonGroup::setOpacity(qreal opacity, bool animated)
{
m_opacityHelper->setOpacity(opacity, animated);
}
void BottomButtonGroup::addButton(QAbstractButton *button)
{
layout()->addWidget(button);
updateGeometry();
}