editor: support custom zoom delta

This commit is contained in:
Le Tan 2018-06-01 19:37:45 +08:00
parent 7f8075f0ca
commit 8d3a7874d0
7 changed files with 70 additions and 0 deletions

View File

@ -546,6 +546,13 @@ VReadEditTab::VReadEditTab(QWidget *p_parent)
connect(m_autoSave, &QCheckBox::stateChanged,
this, &VReadEditTab::showTipsAboutAutoSave);
// Editor zoom delta.
m_editorZoomDeltaSpin = new QSpinBox();
m_editorZoomDeltaSpin->setToolTip(tr("Set the zoom delta of the editor font"));
m_editorZoomDeltaSpin->setMaximum(c_editorZoomDeltaMax);
m_editorZoomDeltaSpin->setMinimum(c_editorZoomDeltaMin);
m_editorZoomDeltaSpin->setSingleStep(1);
QVBoxLayout *readLayout = new QVBoxLayout();
readLayout->addLayout(zoomFactorLayout);
readLayout->addWidget(m_flashAnchor);
@ -554,6 +561,7 @@ VReadEditTab::VReadEditTab(QWidget *p_parent)
QFormLayout *editLayout = new QFormLayout();
editLayout->addRow(m_swapFile);
editLayout->addRow(m_autoSave);
editLayout->addRow(tr("Editor zoom delta:"), m_editorZoomDeltaSpin);
m_editBox->setLayout(editLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
@ -592,6 +600,10 @@ bool VReadEditTab::loadConfiguration()
return false;
}
if (!loadEditorZoomDelta()) {
return false;
}
return true;
}
@ -613,6 +625,10 @@ bool VReadEditTab::saveConfiguration()
return false;
}
if (!saveEditorZoomDelta()) {
return false;
}
return true;
}
@ -646,6 +662,18 @@ bool VReadEditTab::saveWebZoomFactor()
return true;
}
bool VReadEditTab::loadEditorZoomDelta()
{
m_editorZoomDeltaSpin->setValue(g_config->getEditorZoomDelta());
return true;
}
bool VReadEditTab::saveEditorZoomDelta()
{
g_config->setEditorZoomDelta(m_editorZoomDeltaSpin->value());
return true;
}
bool VReadEditTab::loadFlashAnchor()
{
m_flashAnchor->setChecked(g_config->getEnableFlashAnchor());

View File

@ -94,6 +94,9 @@ private:
bool loadFlashAnchor();
bool saveFlashAnchor();
bool loadEditorZoomDelta();
bool saveEditorZoomDelta();
// Web zoom factor.
QCheckBox *m_customWebZoom;
QDoubleSpinBox *m_webZoomFactorSpin;
@ -107,6 +110,9 @@ private:
// Auto save.
QCheckBox *m_autoSave;
// Editor zoom delta.
QSpinBox *m_editorZoomDeltaSpin;
QGroupBox *m_readBox;
QGroupBox *m_editBox;
};

View File

@ -55,6 +55,9 @@ enable_graphviz=false
; -1 - calculate the factor
web_zoom_factor=-1
; Delta font size of the editor
editor_zoom_delta=0
; Syntax highlight within code blocks in edit mode
enable_code_block_highlight=true

View File

@ -130,6 +130,8 @@ void VConfigManager::initialize()
qDebug() << "set WebZoomFactor to" << m_webZoomFactor;
}
m_editorZoomDelta = getConfigFromSettings("global", "editor_zoom_delta").toInt();
m_enableCodeBlockHighlight = getConfigFromSettings("global",
"enable_code_block_highlight").toBool();

View File

@ -228,6 +228,9 @@ public:
void setWebZoomFactor(qreal p_factor);
bool isCustomWebZoomFactor();
int getEditorZoomDelta() const;
void setEditorZoomDelta(int p_delta);
const QString &getEditorCurrentLineBg() const;
const QString &getEditorTrailingSpaceBg() const;
@ -672,6 +675,9 @@ private:
// Zoom factor of the QWebEngineView.
qreal m_webZoomFactor;
// Editor zoom delta.
int m_editorZoomDelta;
// Current line background color in editor.
QString m_editorCurrentLineBg;
@ -1449,6 +1455,21 @@ inline bool VConfigManager::isCustomWebZoomFactor()
return factorFromIni > 0;
}
inline int VConfigManager::getEditorZoomDelta() const
{
return m_editorZoomDelta;
}
inline void VConfigManager::setEditorZoomDelta(int p_delta)
{
if (m_editorZoomDelta == p_delta) {
return;
}
m_editorZoomDelta = p_delta;
setConfigToSettings("global", "editor_zoom_delta", m_editorZoomDelta);
}
inline const QString &VConfigManager::getEditorCurrentLineBg() const
{
return m_editorCurrentLineBg;

View File

@ -32,6 +32,9 @@ enum class OpenFileMode {Read = 0, Edit, Invalid };
static const qreal c_webZoomFactorMax = 5;
static const qreal c_webZoomFactorMin = 0.25;
static const int c_editorZoomDeltaMax = 10;
static const int c_editorZoomDeltaMin = -10;
static const int c_tabSequenceBase = 1;
// HTML and JS.

View File

@ -475,6 +475,13 @@ void VMdTab::setupMarkdownEditor()
m_editor = new VMdEditor(m_file, m_document, m_mdConType, this);
m_editor->setProperty("MainEditor", true);
m_editor->setEditTab(this);
int delta = g_config->getEditorZoomDelta();
if (delta > 0) {
m_editor->zoomInW(delta);
} else if (delta < 0) {
m_editor->zoomOutW(-delta);
}
connect(m_editor, &VMdEditor::headersChanged,
this, &VMdTab::updateOutlineFromHeaders);
connect(m_editor, SIGNAL(currentHeaderChanged(int)),