mirror of
https://gitee.com/spark-store-project/spark-web-app-runtime.git
synced 2025-12-15 03:22:05 +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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user