mirror of
https://gitee.com/spark-store-project/spark-web-app-runtime.git
synced 2025-06-02 13:19:51 +08:00
Improve Feature
Add options "Fix Size" and "Hide Buttons" in titlebar GUI menu. P.S. Command Line settings is not included.
This commit is contained in:
parent
c826db09c1
commit
7d82812fc9
spark-webapp-runtime
@ -2,7 +2,6 @@
|
||||
|
||||
#include <DMainWindow>
|
||||
#include <DTitlebar>
|
||||
#include <DToolButton>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QFileInfo>
|
||||
@ -17,10 +16,18 @@ MainWindow::MainWindow(QString szTitle,
|
||||
: DMainWindow(parent)
|
||||
, m_widget(new Widget(szUrl))
|
||||
, m_dialog(dialog)
|
||||
, btnBackward(new DToolButton(titlebar()))
|
||||
, btnForward(new DToolButton(titlebar()))
|
||||
, btnRefresh(new DToolButton(titlebar()))
|
||||
, m_menu(new QMenu)
|
||||
, m_fixSize(new QAction(tr("Fix Size")))
|
||||
, m_hideButtons(new QAction(tr("Hide Buttons")))
|
||||
, m_width(nWidth)
|
||||
, m_height(nHeight)
|
||||
{
|
||||
// setFixedSize(nWidth, nHeight);
|
||||
// 应 shenmo 要求改成设置最小尺寸试试效果
|
||||
setMinimumSize(nWidth, nHeight);
|
||||
setMinimumSize(m_width, m_height);
|
||||
|
||||
setCentralWidget(m_widget);
|
||||
centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
@ -30,13 +37,10 @@ MainWindow::MainWindow(QString szTitle,
|
||||
titlebar()->setTitle(szTitle);
|
||||
titlebar()->setIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
DToolButton *btnBackward = new DToolButton(titlebar());
|
||||
btnBackward->setIcon(QIcon(":/images/go-previous-24.svg"));
|
||||
btnBackward->setIconSize(QSize(36, 36));
|
||||
DToolButton *btnForward = new DToolButton(titlebar());
|
||||
btnForward->setIcon(QIcon(":/images/go-next-24.svg"));
|
||||
btnForward->setIconSize(QSize(36, 36));
|
||||
DToolButton *btnRefresh = new DToolButton(titlebar());
|
||||
btnRefresh->setIcon(QIcon(":/images/view-refresh.svg"));
|
||||
btnRefresh->setIconSize(QSize(36, 36));
|
||||
|
||||
@ -44,6 +48,14 @@ MainWindow::MainWindow(QString szTitle,
|
||||
titlebar()->addWidget(btnForward, Qt::AlignLeft);
|
||||
titlebar()->addWidget(btnRefresh, Qt::AlignLeft);
|
||||
|
||||
m_fixSize->setCheckable(true);
|
||||
m_fixSize->setChecked(false);
|
||||
m_hideButtons->setCheckable(true);
|
||||
m_hideButtons->setChecked(false);
|
||||
m_menu->addAction(m_fixSize);
|
||||
m_menu->addAction(m_hideButtons);
|
||||
titlebar()->setMenu(m_menu);
|
||||
|
||||
connect(btnBackward, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
if (m_widget)
|
||||
@ -65,6 +77,15 @@ MainWindow::MainWindow(QString szTitle,
|
||||
m_widget->refresh();
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_fixSize, &QAction::triggered, this, [=]()
|
||||
{
|
||||
fixSize();
|
||||
});
|
||||
connect(m_hideButtons, &QAction::triggered, this, [=]()
|
||||
{
|
||||
hideButtons();
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -97,6 +118,42 @@ void MainWindow::setIcon(QString szIconPath)
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::fixSize()
|
||||
{
|
||||
if(m_fixSize->isChecked())
|
||||
{
|
||||
setFixedSize(this->width(), this->height()); // setFixedSize() 等同于同时设置 MaximumSize 和 MinimumSize
|
||||
resize(this->width(), this->height());
|
||||
|
||||
/*
|
||||
* 尝试固定窗口大小后禁用最大化按钮,但是取消勾选后无法恢复
|
||||
* titlebar()->setDisableFlags(Qt::WindowMaximizeButtonHint);
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
setMinimumSize(m_width, m_height);
|
||||
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||
resize(this->width(), this->height());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::hideButtons()
|
||||
{
|
||||
if(m_hideButtons->isChecked())
|
||||
{
|
||||
titlebar()->removeWidget(btnBackward);
|
||||
titlebar()->removeWidget(btnForward);
|
||||
titlebar()->removeWidget(btnRefresh);
|
||||
}
|
||||
else
|
||||
{
|
||||
titlebar()->addWidget(btnBackward, Qt::AlignLeft);
|
||||
titlebar()->addWidget(btnForward, Qt::AlignLeft);
|
||||
titlebar()->addWidget(btnRefresh, Qt::AlignLeft);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
m_dialog->close();
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <DMainWindow>
|
||||
#include <DAboutDialog>
|
||||
#include <DToolButton>
|
||||
|
||||
#include "widget.h"
|
||||
#include "globaldefine.h"
|
||||
@ -23,6 +24,8 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
void setIcon(QString);
|
||||
void fixSize();
|
||||
void hideButtons();
|
||||
|
||||
signals:
|
||||
void sigQuit();
|
||||
@ -31,6 +34,16 @@ private:
|
||||
Widget *m_widget;
|
||||
DAboutDialog *m_dialog;
|
||||
|
||||
DToolButton *btnBackward;
|
||||
DToolButton *btnForward;
|
||||
DToolButton *btnRefresh;
|
||||
|
||||
QMenu *m_menu;
|
||||
QAction *m_fixSize;
|
||||
QAction *m_hideButtons;
|
||||
|
||||
int m_width, m_height;
|
||||
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
};
|
||||
|
Binary file not shown.
@ -1,6 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="23"/>
|
||||
<source>Fix Size</source>
|
||||
<translation>固定大小</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="24"/>
|
||||
<source>Hide Buttons</source>
|
||||
<translation>隐藏按钮</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
|
Loading…
x
Reference in New Issue
Block a user