|
|
@@ -4,12 +4,15 @@
|
|
|
#include "utils/vutils.h"
|
|
|
|
|
|
extern VConfigManager vconfig;
|
|
|
+static const qreal c_webZoomFactorMax = 5;
|
|
|
+static const qreal c_webZoomFactorMin = 0.25;
|
|
|
|
|
|
VSettingsDialog::VSettingsDialog(QWidget *p_parent)
|
|
|
: QDialog(p_parent)
|
|
|
{
|
|
|
m_tabs = new QTabWidget;
|
|
|
m_tabs->addTab(new VGeneralTab(), tr("General"));
|
|
|
+ m_tabs->addTab(new VReadEditTab(), tr("Read/Edit"));
|
|
|
|
|
|
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
connect(m_btnBox, &QDialogButtonBox::accepted, this, &VSettingsDialog::saveConfiguration);
|
|
|
@@ -28,11 +31,21 @@ VSettingsDialog::VSettingsDialog(QWidget *p_parent)
|
|
|
void VSettingsDialog::loadConfiguration()
|
|
|
{
|
|
|
// General Tab.
|
|
|
- VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
|
|
- Q_ASSERT(generalTab);
|
|
|
- bool ret = generalTab->loadConfiguration();
|
|
|
- if (!ret) {
|
|
|
- goto err;
|
|
|
+ {
|
|
|
+ VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
|
|
+ Q_ASSERT(generalTab);
|
|
|
+ if (!generalTab->loadConfiguration()) {
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Read/Edit Tab.
|
|
|
+ {
|
|
|
+ VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1));
|
|
|
+ Q_ASSERT(readEditTab);
|
|
|
+ if (!readEditTab->loadConfiguration()) {
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
@@ -46,11 +59,21 @@ err:
|
|
|
void VSettingsDialog::saveConfiguration()
|
|
|
{
|
|
|
// General Tab.
|
|
|
- VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
|
|
- Q_ASSERT(generalTab);
|
|
|
- bool ret = generalTab->saveConfiguration();
|
|
|
- if (!ret) {
|
|
|
- goto err;
|
|
|
+ {
|
|
|
+ VGeneralTab *generalTab = dynamic_cast<VGeneralTab *>(m_tabs->widget(0));
|
|
|
+ Q_ASSERT(generalTab);
|
|
|
+ if (!generalTab->saveConfiguration()) {
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Read/Edit Tab.
|
|
|
+ {
|
|
|
+ VReadEditTab *readEditTab = dynamic_cast<VReadEditTab *>(m_tabs->widget(1));
|
|
|
+ Q_ASSERT(readEditTab);
|
|
|
+ if (!readEditTab->saveConfiguration()) {
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
accept();
|
|
|
@@ -64,7 +87,7 @@ err:
|
|
|
const QVector<QString> VGeneralTab::c_availableLangs = { "System", "English", "Chinese" };
|
|
|
|
|
|
VGeneralTab::VGeneralTab(QWidget *p_parent)
|
|
|
- : QWidget(p_parent), m_langChanged(false)
|
|
|
+ : QWidget(p_parent)
|
|
|
{
|
|
|
QLabel *langLabel = new QLabel(tr("&Language:"));
|
|
|
m_langCombo = new QComboBox(this);
|
|
|
@@ -73,8 +96,6 @@ VGeneralTab::VGeneralTab(QWidget *p_parent)
|
|
|
for (auto lang : langs) {
|
|
|
m_langCombo->addItem(lang.second, lang.first);
|
|
|
}
|
|
|
- connect(m_langCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
- this, SLOT(handleIndexChange(int)));
|
|
|
langLabel->setBuddy(m_langCombo);
|
|
|
|
|
|
QFormLayout *optionLayout = new QFormLayout();
|
|
|
@@ -112,7 +133,7 @@ bool VGeneralTab::loadLanguage()
|
|
|
return true;
|
|
|
}
|
|
|
bool found = false;
|
|
|
- // Lang is the value, not name.
|
|
|
+ // lang is the value, not name.
|
|
|
for (int i = 0; i < m_langCombo->count(); ++i) {
|
|
|
if (m_langCombo->itemData(i).toString() == lang) {
|
|
|
found = true;
|
|
|
@@ -129,16 +150,91 @@ bool VGeneralTab::loadLanguage()
|
|
|
|
|
|
bool VGeneralTab::saveLanguage()
|
|
|
{
|
|
|
- if (m_langChanged) {
|
|
|
- vconfig.setLanguage(m_langCombo->currentData().toString());
|
|
|
+ QString curLang = m_langCombo->currentData().toString();
|
|
|
+ vconfig.setLanguage(curLang);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+VReadEditTab::VReadEditTab(QWidget *p_parent)
|
|
|
+ : QWidget(p_parent)
|
|
|
+{
|
|
|
+ m_readBox = new QGroupBox(tr("Read Mode (For Markdown Only)"));
|
|
|
+ m_editBox = new QGroupBox(tr("Edit Mode"));
|
|
|
+
|
|
|
+ // Web Zoom Factor.
|
|
|
+ m_customWebZoom = new QCheckBox(tr("Custom Web zoom factor"), this);
|
|
|
+ m_customWebZoom->setToolTip(tr("Set the zoom factor of the Web page when reading"));
|
|
|
+ connect(m_customWebZoom, &QCheckBox::stateChanged,
|
|
|
+ this, &VReadEditTab::customWebZoomChanged);
|
|
|
+ m_webZoomFactorSpin = new QDoubleSpinBox(this);
|
|
|
+ m_webZoomFactorSpin->setMaximum(c_webZoomFactorMax);
|
|
|
+ m_webZoomFactorSpin->setMinimum(c_webZoomFactorMin);
|
|
|
+ m_webZoomFactorSpin->setSingleStep(0.25);
|
|
|
+ QHBoxLayout *zoomFactorLayout = new QHBoxLayout();
|
|
|
+ zoomFactorLayout->addWidget(m_customWebZoom);
|
|
|
+ zoomFactorLayout->addWidget(m_webZoomFactorSpin);
|
|
|
+
|
|
|
+ QFormLayout *readLayout = new QFormLayout();
|
|
|
+ readLayout->addRow(zoomFactorLayout);
|
|
|
+
|
|
|
+ m_readBox->setLayout(readLayout);
|
|
|
+
|
|
|
+ QVBoxLayout *mainLayout = new QVBoxLayout();
|
|
|
+ mainLayout->addWidget(m_readBox);
|
|
|
+ mainLayout->addWidget(m_editBox);
|
|
|
+ m_editBox->hide();
|
|
|
+ setLayout(mainLayout);
|
|
|
+}
|
|
|
+
|
|
|
+bool VReadEditTab::loadConfiguration()
|
|
|
+{
|
|
|
+ if (!loadWebZoomFactor()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool VReadEditTab::saveConfiguration()
|
|
|
+{
|
|
|
+ if (!saveWebZoomFactor()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool VReadEditTab::loadWebZoomFactor()
|
|
|
+{
|
|
|
+ qreal factor = vconfig.getWebZoomFactor();
|
|
|
+ bool customFactor = vconfig.isCustomWebZoomFactor();
|
|
|
+ if (customFactor) {
|
|
|
+ if (factor < c_webZoomFactorMin || factor > c_webZoomFactorMax) {
|
|
|
+ factor = 1;
|
|
|
+ }
|
|
|
+ m_customWebZoom->setChecked(true);
|
|
|
+ m_webZoomFactorSpin->setValue(factor);
|
|
|
+ } else {
|
|
|
+ m_customWebZoom->setChecked(false);
|
|
|
+ m_webZoomFactorSpin->setValue(factor);
|
|
|
+ m_webZoomFactorSpin->setEnabled(false);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool VReadEditTab::saveWebZoomFactor()
|
|
|
+{
|
|
|
+ if (m_customWebZoom->isChecked()) {
|
|
|
+ vconfig.setWebZoomFactor(m_webZoomFactorSpin->value());
|
|
|
+ } else {
|
|
|
+ vconfig.setWebZoomFactor(-1);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void VGeneralTab::handleIndexChange(int p_index)
|
|
|
+void VReadEditTab::customWebZoomChanged(int p_state)
|
|
|
{
|
|
|
- if (p_index == -1) {
|
|
|
- return;
|
|
|
+ if (p_state == Qt::Unchecked) {
|
|
|
+ m_webZoomFactorSpin->setEnabled(false);
|
|
|
+ } else {
|
|
|
+ m_webZoomFactorSpin->setEnabled(true);
|
|
|
}
|
|
|
- m_langChanged = true;
|
|
|
}
|