重构标题栏框架构建函数
This commit is contained in:
parent
25b4c9146c
commit
8678fb6978
@ -4,7 +4,7 @@ QWidget#m_widget{
|
||||
color:#F0F0F0F0;
|
||||
}
|
||||
|
||||
QPushButton#ico_button{
|
||||
QPushButton#btn_opt{
|
||||
image:url(:/res/img/xsteam.png);
|
||||
border:none;
|
||||
}
|
||||
@ -82,7 +82,7 @@ QWidget#sui_title{
|
||||
margin-bottom:1px;
|
||||
margin-left:1px;
|
||||
}
|
||||
QPushButton#min_button,QPushButton#max_button,QPushButton#close_button{
|
||||
QPushButton#btn_min,QPushButton#btn_max,QPushButton#btn_close{
|
||||
margin-right:3px;
|
||||
margin-bottom:0px;
|
||||
border-radius:8px;
|
||||
@ -90,31 +90,31 @@ QPushButton#min_button,QPushButton#max_button,QPushButton#close_button{
|
||||
font-weight: bold;
|
||||
font: bold 12px;
|
||||
}
|
||||
QPushButton#min_button{
|
||||
QPushButton#btn_min{
|
||||
image:url(":/res/img/btn/btn_min.png");
|
||||
border:none;
|
||||
width:20px;
|
||||
height:20px;
|
||||
}
|
||||
QPushButton#max_button{
|
||||
QPushButton#btn_max{
|
||||
image:url(":/res/img/btn/btn_max.png");
|
||||
border:none;
|
||||
width:20px;
|
||||
height:20px;
|
||||
}
|
||||
QPushButton#close_button{
|
||||
QPushButton#btn_close{
|
||||
image:url(":/res/img/btn/btn_close.png");
|
||||
border:none;
|
||||
width:20px;
|
||||
height:20px;
|
||||
}
|
||||
|
||||
QPushButton#min_button:hover,QPushButton#max_button:hover,QPushButton#close_button:hover{
|
||||
QPushButton#btn_min:hover,QPushButton#btn_max:hover,QPushButton#btn_close:hover{
|
||||
padding-left:1px;
|
||||
padding-top:1px;
|
||||
}
|
||||
|
||||
QPushButton#min_button:pressed,QPushButton#max_button:pressed,QPushButton#close_button:pressed{
|
||||
QPushButton#btn_min:pressed,QPushButton#btn_max:pressed,QPushButton#btn_close:pressed{
|
||||
padding-left:1px;
|
||||
padding-top:1px;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ QWidget#m_widget{
|
||||
color:#2F4F4F;
|
||||
}
|
||||
|
||||
QPushButton#ico_button{
|
||||
QPushButton#btn_opt{
|
||||
image:url(:/res/img/xsteam.png);
|
||||
border:none;
|
||||
}
|
||||
@ -58,37 +58,37 @@ QWidget#sui_title{
|
||||
margin-bottom:1px;
|
||||
margin-left:1px;
|
||||
}
|
||||
QPushButton#min_button,QPushButton#max_button,QPushButton#close_button{
|
||||
QPushButton#btn_min,QPushButton#btn_max,QPushButton#btn_close{
|
||||
margin-right:3px;
|
||||
margin-bottom:0px;
|
||||
border-radius:8px;
|
||||
}
|
||||
|
||||
QPushButton#min_button{
|
||||
QPushButton#btn_min{
|
||||
image:url(":/res/img/btn/btn_min.png");
|
||||
border:none;
|
||||
width:25px;
|
||||
height:25px;
|
||||
}
|
||||
QPushButton#max_button{
|
||||
QPushButton#btn_max{
|
||||
image:url(":/res/img/btn/btn_max.png");
|
||||
border:none;
|
||||
width:25px;
|
||||
height:25px;
|
||||
}
|
||||
QPushButton#close_button{
|
||||
QPushButton#btn_close{
|
||||
image:url(":/res/img/btn/btn_close.png");
|
||||
border:none;
|
||||
width:25px;
|
||||
height:25px;
|
||||
}
|
||||
|
||||
QPushButton#min_button:hover,QPushButton#max_button:hover,QPushButton#close_button:hover{
|
||||
QPushButton#btn_min:hover,QPushButton#btn_max:hover,QPushButton#btn_close:hover{
|
||||
padding-left:1px;
|
||||
padding-top:1px;
|
||||
}
|
||||
|
||||
QPushButton#min_button:pressed,QPushButton#max_button:pressed,QPushButton#close_button:pressed{
|
||||
QPushButton#btn_min:pressed,QPushButton#btn_max:pressed,QPushButton#btn_close:pressed{
|
||||
padding-left:1px;
|
||||
padding-top:1px;
|
||||
}
|
||||
|
19
src/sui.cpp
19
src/sui.cpp
@ -1,22 +1,12 @@
|
||||
#include "sui.h"
|
||||
sui::sui(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_widget(new QDialog),
|
||||
m_layout(new QVBoxLayout),
|
||||
m_widget(new QWidget),
|
||||
m_press(false),
|
||||
m_border_width(5)
|
||||
{
|
||||
|
||||
init_layout();
|
||||
}
|
||||
sui::~sui()
|
||||
{
|
||||
|
||||
}
|
||||
void sui::init_layout()
|
||||
{
|
||||
m_title=new sui_title(this);
|
||||
m_title->set_title(tr("XSteam"));
|
||||
setObjectName(tr("m_widget"));
|
||||
m_layout->addWidget(m_title);
|
||||
m_title->setMouseTracking(true);
|
||||
@ -28,10 +18,11 @@ void sui::init_layout()
|
||||
setBaseSize(800, 600);
|
||||
resize(800, 600);
|
||||
setLayout(m_layout);
|
||||
connect(m_title, SIGNAL(signals_close()), this, SLOT(slots_close()));
|
||||
connect(m_title, SIGNAL(signals_close()), this, SLOT(close()));
|
||||
}
|
||||
void sui::slots_close(){
|
||||
this->close();
|
||||
sui::~sui()
|
||||
{
|
||||
|
||||
}
|
||||
void sui::showEvent(QShowEvent *event)
|
||||
{
|
||||
|
@ -16,8 +16,6 @@ public:
|
||||
explicit sui(QWidget *parent = 0);
|
||||
~sui();
|
||||
sui_title* title() { return m_title; }
|
||||
private:
|
||||
void init_layout();
|
||||
private:
|
||||
QVBoxLayout *m_layout;
|
||||
QWidget *m_widget;
|
||||
@ -25,8 +23,6 @@ private:
|
||||
bool m_press;
|
||||
int m_border_width;
|
||||
sui_title *m_title;
|
||||
public slots:
|
||||
void slots_close();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void showEvent(QShowEvent *event);
|
||||
|
@ -7,39 +7,17 @@ sui_title::sui_title(QWidget *parent)
|
||||
m_type(QD_TYPE::QD_EXIT)
|
||||
{
|
||||
m_parent = parent;
|
||||
// 给成员变量申请内存
|
||||
m_icon_button = new QPushButton(/*this*/);
|
||||
m_min_button = new QPushButton(this);
|
||||
m_max_button = new QPushButton(this);
|
||||
m_close_button = new QPushButton(this);
|
||||
// 初始化图标Label
|
||||
m_icon_button->setFixedSize(35, 35);
|
||||
m_icon_button->setAutoFillBackground(true);
|
||||
m_icon_button->setFlat(true);
|
||||
|
||||
// 设置按钮的固定大小、图片、取消边框
|
||||
m_min_button->setIconSize(QSize(25, 25));
|
||||
m_min_button->setAutoFillBackground(true);
|
||||
m_min_button->setFlat(true);
|
||||
//--
|
||||
m_max_button->setIconSize(QSize(25, 25));
|
||||
m_max_button->setAutoFillBackground(true);
|
||||
m_max_button->setFlat(true);
|
||||
//--
|
||||
m_close_button->setIconSize(QSize(25, 25));
|
||||
m_close_button->setAutoFillBackground(true);
|
||||
m_close_button->setFlat(true);
|
||||
|
||||
// 设置窗口部件的名称
|
||||
setObjectName(tr("sui_title"));
|
||||
m_icon_button->setObjectName(tr("ico_button"));
|
||||
m_min_button->setObjectName(tr("min_button"));
|
||||
m_max_button->setObjectName(tr("max_button"));
|
||||
m_close_button->setObjectName(tr("close_button"));
|
||||
// 给按钮设置静态tooltip,当鼠标移上去时显示tooltip
|
||||
m_min_button->setToolTip(tr("最小化"));
|
||||
m_max_button->setToolTip(tr("最大化"));
|
||||
m_close_button->setToolTip(tr("关闭"));
|
||||
for (int i = 0; i <= m_btn_obj_str.count() - 1; i++)
|
||||
{
|
||||
QPushButton *btn = new QPushButton(this);
|
||||
btn->setFixedSize(35, 35);
|
||||
btn->setAutoFillBackground(true);
|
||||
btn->setFlat(true);
|
||||
btn->setObjectName(m_btn_obj_str[i]);
|
||||
btn->setToolTip(m_btn_tips_str[i]);
|
||||
m_btn_vectors.push_back(btn);
|
||||
}
|
||||
// 标题栏布局
|
||||
m_title_label = new QLabel(this);
|
||||
m_title_label->setAlignment(Qt::AlignCenter);
|
||||
@ -49,13 +27,13 @@ sui_title::sui_title(QWidget *parent)
|
||||
m_title_label->setFont(font);
|
||||
m_layout = new QHBoxLayout(this);
|
||||
m_layout->setAlignment(Qt::AlignCenter);
|
||||
m_layout->addWidget(m_icon_button);
|
||||
m_layout->addWidget(m_btn_vectors[0]);
|
||||
m_layout->addItem(sparcer_item);
|
||||
m_layout->addWidget(m_title_label);
|
||||
m_layout->addItem(sparcer_item);
|
||||
m_layout->addWidget(m_min_button);
|
||||
m_layout->addWidget(m_max_button);
|
||||
m_layout->addWidget(m_close_button);
|
||||
m_layout->addWidget(m_btn_vectors[1]);
|
||||
m_layout->addWidget(m_btn_vectors[2]);
|
||||
m_layout->addWidget(m_btn_vectors[3]);
|
||||
m_layout->setSpacing(5);
|
||||
m_layout->setContentsMargins(5, 0, 5, 0);
|
||||
setFixedHeight(40);
|
||||
@ -64,7 +42,8 @@ sui_title::sui_title(QWidget *parent)
|
||||
}
|
||||
sui_title::~sui_title()
|
||||
{
|
||||
if(m_thread){
|
||||
if (m_thread)
|
||||
{
|
||||
m_thread->quit();
|
||||
m_thread->exit();
|
||||
}
|
||||
@ -72,13 +51,12 @@ sui_title::~sui_title()
|
||||
|
||||
void sui_title::connect_slots()
|
||||
{
|
||||
// 连接三个按钮的信号槽3
|
||||
connect(m_icon_button, SIGNAL(clicked(bool)), this, SLOT(slots_ico_menu()));
|
||||
connect(m_min_button, SIGNAL(clicked(bool)), this, SLOT(on_clicked()));
|
||||
connect(m_max_button, SIGNAL(clicked(bool)), this, SLOT(on_clicked()));
|
||||
connect(m_close_button, SIGNAL(clicked(bool)), this, SLOT(on_clicked()));
|
||||
for (auto btn : m_btn_vectors)
|
||||
{
|
||||
connect(btn, SIGNAL(clicked(bool)), this, SLOT(on_clicked()));
|
||||
}
|
||||
void sui_title::slots_ico_menu()
|
||||
}
|
||||
void sui_title::btn_ico_menu()
|
||||
{
|
||||
m_menu = new QMenu();
|
||||
// 外观
|
||||
@ -255,26 +233,24 @@ void sui_title::change_style(int index)
|
||||
void sui_title::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event); // 没有实质性的作用,只是用来允许event可以不使用,用来避免编译器警告
|
||||
emit m_max_button->clicked();
|
||||
emit m_btn_vectors[2]->clicked();
|
||||
}
|
||||
// 进行最小化、最大化/还原、关闭操作
|
||||
void sui_title::on_clicked()
|
||||
{
|
||||
// QObject::Sender()返回发送信号的对象的指针,返回类型为QObject *
|
||||
QPushButton *pButton = qobject_cast<QPushButton *>(sender());
|
||||
QWidget *pWindow = this->window(); // 获得标题栏所在的窗口
|
||||
if (pWindow->isWindow())
|
||||
if (sender()->objectName() == "btn_opt")
|
||||
{
|
||||
// 判断发送信号的对象使哪个按钮
|
||||
if (pButton == m_min_button)
|
||||
{
|
||||
pWindow->showMinimized(); // 窗口最小化显示
|
||||
btn_ico_menu();
|
||||
}
|
||||
else if (pButton == m_max_button)
|
||||
else if (sender()->objectName() == "btn_min")
|
||||
{
|
||||
pWindow->isFullScreen() ? pWindow->showNormal() : pWindow->showFullScreen();
|
||||
window()->showMinimized();
|
||||
}
|
||||
else if (pButton == m_close_button)
|
||||
else if (sender()->objectName() == "btn_max")
|
||||
{
|
||||
window()->isFullScreen() ? window()->showNormal() : window()->showFullScreen();
|
||||
}
|
||||
else if (sender()->objectName() == "btn_close")
|
||||
{
|
||||
if (m_type == QD_TYPE::QD_CLOSE)
|
||||
{
|
||||
@ -287,7 +263,6 @@ void sui_title::on_clicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 最大化/还原
|
||||
void sui_title::up_maximize()
|
||||
{
|
||||
@ -298,18 +273,18 @@ void sui_title::up_maximize()
|
||||
if (bMaximize)
|
||||
{
|
||||
// 目前窗口是最大化状态,则最大化/还原的toolTip设置为"Restore"
|
||||
m_max_button->setToolTip(tr("Restore"));
|
||||
m_btn_vectors[2]->setToolTip(tr("Restore"));
|
||||
// 设置按钮的属性名为"maximizeProperty"
|
||||
m_max_button->setProperty("maximizeProperty", tr("restore"));
|
||||
m_btn_vectors[2]->setProperty("maximizeProperty", tr("restore"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 目前窗口是还原状态,则最大化/还原的toolTip设置为"Maximize"
|
||||
m_max_button->setToolTip(tr("Maximize"));
|
||||
m_btn_vectors[2]->setToolTip(tr("Maximize"));
|
||||
// 设置按钮的属性名为"maximizeProperty"
|
||||
m_max_button->setProperty("maximizeProperty", tr("maximize"));
|
||||
m_btn_vectors[2]->setProperty("maximizeProperty", tr("maximize"));
|
||||
}
|
||||
m_max_button->setStyle(QApplication::style());
|
||||
m_btn_vectors[2]->setStyle(QApplication::style());
|
||||
}
|
||||
}
|
||||
void sui_title::set_type(QD_TYPE _type)
|
||||
@ -328,7 +303,7 @@ void sui_title::set_type(QD_TYPE _type)
|
||||
}
|
||||
else
|
||||
{
|
||||
disconnect(m_icon_button, SIGNAL(clicked(bool)), this, SLOT(slots_ico_menu()));
|
||||
disconnect(m_btn_vectors[0], SIGNAL(clicked(bool)), this, SLOT(btn_ico_menu()));
|
||||
}
|
||||
}
|
||||
void sui_title::set_title(QString str)
|
||||
|
@ -47,14 +47,12 @@ private:
|
||||
//最大化/还原
|
||||
void up_maximize();
|
||||
void connect_slots();
|
||||
void btn_ico_menu();
|
||||
private:
|
||||
QWidget *m_parent;
|
||||
QHBoxLayout *m_layout;
|
||||
QPushButton *m_icon_button; //标题栏图标
|
||||
QLabel *m_title_label; //标题栏标题
|
||||
QPushButton *m_min_button; //最小化按钮
|
||||
QPushButton *m_max_button; //最大化/还原按钮
|
||||
QPushButton *m_close_button; //关闭按钮
|
||||
QLabel *m_title_label;
|
||||
std::vector<QPushButton*> m_btn_vectors;
|
||||
QSpacerItem *sparcer_item = new QSpacerItem(0,0,QSizePolicy::Expanding,QSizePolicy::Fixed);
|
||||
QMenu *m_menu;
|
||||
QMenu *s_menu;
|
||||
@ -62,8 +60,9 @@ private:
|
||||
QD_TYPE m_type;
|
||||
QThread* m_thread=nullptr;
|
||||
sui_sys_style* m_style=nullptr;
|
||||
QStringList m_btn_obj_str={"btn_opt","btn_min","btn_max","btn_close"};
|
||||
QStringList m_btn_tips_str={"功能","最小化","最大化","关闭"};
|
||||
public slots:
|
||||
void slots_ico_menu();
|
||||
void slots_set_style_change();
|
||||
void slots_set_font_change();
|
||||
void slots_style_system();
|
||||
|
@ -559,7 +559,7 @@ void xsteam_run_steam_steamtools(RUN_MODE _mode)
|
||||
}
|
||||
else if (_mode == RUN_MODE::STEAMTOOLS)
|
||||
{
|
||||
run_steam_steamtools_path = QString::fromStdString(_data.x_config.steamtools_dir) + "Steamtools.exe";
|
||||
run_steam_steamtools_path = QString::fromStdString(_data.x_config.steamtools_dir) + "/Steamtools.exe";
|
||||
_tips = "未检测到SteamTools安装,请先配置SteamTools路径";
|
||||
}
|
||||
if (QFile(run_steam_steamtools_path).exists())
|
||||
|
@ -46,6 +46,7 @@ void xsteam_ui::xsteam_init_info_layout()
|
||||
}
|
||||
void xsteam_ui::xsteam_init_mind_layout()
|
||||
{
|
||||
title()->set_title(tr("XSteam"));
|
||||
mind_widget = new QWidget();
|
||||
mind_layout = new QVBoxLayout();
|
||||
server_layout = new QHBoxLayout();
|
||||
|
Loading…
Reference in New Issue
Block a user