-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttontool.cpp
More file actions
135 lines (118 loc) · 3.52 KB
/
Copy pathbuttontool.cpp
File metadata and controls
135 lines (118 loc) · 3.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "buttontool.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QShowEvent>
#include <QFile>
#include <QDebug>
#include <QCoreApplication>
ButtonTool::ButtonTool(QWidget *parent)
: QWidget(parent)
{
InitUi();
InitProperty();
}
ButtonTool::~ButtonTool()
{
}
void ButtonTool::InitUi() //初始化界面
{
m_pRootLayout = new QVBoxLayout(this);
m_pRootLayout->setContentsMargins(0,0,0,0);
m_pRootLayout->setSpacing(0);
m_pRootWidget = new QWidget(this);
m_pRootWidget->setObjectName("RootWidget");
m_pRootWidgetLayout = new QHBoxLayout(m_pRootWidget);
m_pRootWidgetLayout->setContentsMargins(2,2,2,2);
m_pRootWidgetLayout->setSpacing(0);
m_pRootLayout->addWidget(m_pRootWidget);
}
void ButtonTool::InitProperty() //初始化按钮属性
{
setWindowFlags(Qt::FramelessWindowHint);//无边框
setAttribute(Qt::WA_TranslucentBackground);//背景透明
//获取程序当前运行目录
//QString path = QCoreApplication::applicationDirPath();
QFile resourceqss(":/ImageTools/qss/ButtonTool.qss");
resourceqss.open(QFile::ReadOnly);
this->setStyleSheet(resourceqss.readAll());
resourceqss.close();
m_qButtons.clear();
}
void ButtonTool::SetCutToolTip()//设置裁剪部件提示
{
for(auto temp : m_qButtons)
{
if(temp->objectName() == "CutButton")
{
temp->setToolTip(tr("cut"));
}
}
}
void ButtonTool::SetSaveToolTip()//设置保存部件提示
{
for(auto temp : m_qButtons)
{
if(temp->objectName() == "SaveButton")
{
temp->setToolTip(tr("save"));
}
}
}
void ButtonTool::SetCloseToolTip()//设置关闭部件提示
{
for(auto temp : m_qButtons)
{
if(temp->objectName() == "CloseButton")
{
temp->setToolTip(tr("close"));
}
}
}
void ButtonTool::InitButtons(QStringList buttons)//初始化按钮部件
{
m_qButtonList = buttons;
for(auto button : m_qButtonList)
{
QPushButton *m_pButton = new QPushButton(m_pRootWidget);
m_pButton->setObjectName(button);
/*button.replace("Button", "");
m_pButton->setToolTip(tr(button.toUtf8().data()));*/
connect(m_pButton, &QPushButton::clicked, this, [=](){
QPushButton* button = qobject_cast<QPushButton*>(sender());
if(button->objectName() == "CutButton") //根据按钮转换到各自信号
{
emit clicked(STATE::CUT);
} else if(button->objectName() == "LampButton")
{
emit clicked(STATE::LAMP);
} else if(button->objectName() == "SaveButton")
{
emit clicked(STATE::SAVE);
} else if(button->objectName() == "CloseButton")
{
emit clicked(STATE::CLOSE);
}
});
m_qButtons.push_back(m_pButton);
m_pRootWidgetLayout->addWidget(m_pButton);
}
SetCutToolTip();
SetSaveToolTip();
SetCloseToolTip();
}
void ButtonTool::SetLampToolTip(bool lamp) //灯光部件提示
{
for(auto temp : m_qButtons)
{
if(temp->objectName() == "LampButton")//根据按钮状态修改提示内容
{
if(lamp)
{
temp->setToolTip(tr("CloseLamp"));
} else {
temp->setToolTip(tr("OpenLamp"));
}
}
}
}