refactor: use .ui to replace manual layout for aboutdialog
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#include "aboutdialog.h"
|
#include "aboutdialog.h"
|
||||||
|
#include "ui_aboutdialog.h"
|
||||||
|
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
@@ -17,16 +18,10 @@
|
|||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
AboutDialog::AboutDialog(QWidget *parent)
|
AboutDialog::AboutDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent), ui(new Ui::AboutDialog)
|
||||||
, m_tabWidget(new QTabWidget)
|
|
||||||
, m_buttonBox(new QDialogButtonBox)
|
|
||||||
, m_helpTextEdit(new QTextBrowser)
|
|
||||||
, m_aboutTextEdit(new QTextBrowser)
|
|
||||||
, m_specialThanksTextEdit(new QTextBrowser)
|
|
||||||
, m_licenseTextEdit(new QTextBrowser)
|
|
||||||
, m_3rdPartyLibsTextEdit(new QTextBrowser)
|
|
||||||
{
|
{
|
||||||
this->setWindowTitle(tr("About"));
|
ui->setupUi(this);
|
||||||
|
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
||||||
|
|
||||||
const QStringList helpStr {
|
const QStringList helpStr {
|
||||||
u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")),
|
u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")),
|
||||||
@@ -137,42 +132,30 @@ SOFTWARE.
|
|||||||
u"</ul>"_s
|
u"</ul>"_s
|
||||||
};
|
};
|
||||||
|
|
||||||
m_helpTextEdit->setText(helpStr.join('\n'));
|
ui->m_helpTextEdit->setText(helpStr.join('\n'));
|
||||||
|
|
||||||
m_aboutTextEdit->setText(aboutStr.join('\n'));
|
ui->m_aboutTextEdit->setText(aboutStr.join('\n'));
|
||||||
m_aboutTextEdit->setOpenExternalLinks(true);
|
ui->m_aboutTextEdit->setOpenExternalLinks(true);
|
||||||
|
|
||||||
m_specialThanksTextEdit->setText(specialThanksStr.join('\n'));
|
ui->m_specialThanksTextEdit->setText(specialThanksStr.join('\n'));
|
||||||
m_specialThanksTextEdit->setOpenExternalLinks(true);
|
ui->m_specialThanksTextEdit->setOpenExternalLinks(true);
|
||||||
|
|
||||||
m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));
|
ui->m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));
|
||||||
|
|
||||||
m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
|
ui->m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
|
||||||
m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);
|
ui->m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);
|
||||||
|
|
||||||
m_tabWidget->addTab(m_helpTextEdit, tr("&Help"));
|
connect(ui->m_buttonBox, QOverload<QAbstractButton *>::of(&QDialogButtonBox::clicked), this, [this](QAbstractButton * btn){
|
||||||
m_tabWidget->addTab(m_aboutTextEdit, tr("&About"));
|
Q_UNUSED(btn)
|
||||||
m_tabWidget->addTab(m_specialThanksTextEdit, tr("&Special Thanks"));
|
|
||||||
m_tabWidget->addTab(m_licenseTextEdit, tr("&License"));
|
|
||||||
m_tabWidget->addTab(m_3rdPartyLibsTextEdit, tr("&Third-party Libraries"));
|
|
||||||
|
|
||||||
m_buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
|
||||||
connect(m_buttonBox, QOverload<QAbstractButton *>::of(&QDialogButtonBox::clicked), this, [this](){
|
|
||||||
this->close();
|
this->close();
|
||||||
});
|
});
|
||||||
|
|
||||||
setLayout(new QVBoxLayout);
|
|
||||||
|
|
||||||
layout()->addWidget(m_tabWidget);
|
|
||||||
layout()->addWidget(m_buttonBox);
|
|
||||||
|
|
||||||
setMinimumSize(361, 161); // not sure why it complain "Unable to set geometry"
|
setMinimumSize(361, 161); // not sure why it complain "Unable to set geometry"
|
||||||
setWindowFlag(Qt::WindowContextHelpButtonHint, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AboutDialog::~AboutDialog()
|
AboutDialog::~AboutDialog()
|
||||||
{
|
{
|
||||||
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize AboutDialog::sizeHint() const
|
QSize AboutDialog::sizeHint() const
|
||||||
|
|||||||
@@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTextBrowser;
|
namespace Ui {
|
||||||
class QTabWidget;
|
class AboutDialog;
|
||||||
class QDialogButtonBox;
|
}
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class AboutDialog : public QDialog
|
class AboutDialog : public QDialog
|
||||||
@@ -23,14 +24,7 @@ public:
|
|||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTabWidget * m_tabWidget = nullptr;
|
QT_PREPEND_NAMESPACE(Ui::AboutDialog) *ui;
|
||||||
QDialogButtonBox * m_buttonBox = nullptr;
|
|
||||||
|
|
||||||
QTextBrowser * m_helpTextEdit = nullptr;
|
|
||||||
QTextBrowser * m_aboutTextEdit = nullptr;
|
|
||||||
QTextBrowser * m_specialThanksTextEdit = nullptr;
|
|
||||||
QTextBrowser * m_licenseTextEdit = nullptr;
|
|
||||||
QTextBrowser * m_3rdPartyLibsTextEdit = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ABOUTDIALOG_H
|
#endif // ABOUTDIALOG_H
|
||||||
|
|||||||
86
app/aboutdialog.ui
Normal file
86
app/aboutdialog.ui
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AboutDialog</class>
|
||||||
|
<widget class="QDialog" name="AboutDialog">
|
||||||
|
<property name="windowModality">
|
||||||
|
<enum>Qt::NonModal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>About</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>361</width>
|
||||||
|
<height>161</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTabWidget" name="m_tabWidget">
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="helpTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>&Help</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="helpTabLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="m_helpTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="aboutTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>&About</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="aboutTabLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="m_aboutTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="specialThanksTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>&Special Thanks</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="specialThanksTabLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="m_specialThanksTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="licenseTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>&License</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="licenseTabLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="m_licenseTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="thirdPartyLibsTab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>&Third-party Libraries</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="thirdPartyLibsTabLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextBrowser" name="m_3rdPartyLibsTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Close</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
#ifndef SETTINGSDIALOG_H
|
#ifndef SETTINGSDIALOG_H
|
||||||
#define SETTINGSDIALOG_H
|
#define SETTINGSDIALOG_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|||||||
Reference in New Issue
Block a user