Ref T369, allow to change font size +/- in text message style settings

This commit is contained in:
Klaus Basan
2018-09-26 03:36:54 +02:00
parent 499236c391
commit 1a0bcdaecc
3 changed files with 110 additions and 22 deletions

View File

@@ -12,11 +12,17 @@
#include "settingsfontdialog.h"
#include "texteditdialog.h"
#include "settingstextmessagestyle.h"
#include "blackgui/shortcut.h"
#include <QTextEdit>
#include <QPushButton>
#include <QRegularExpression>
#include <QStringBuilder>
#include <QKeySequence>
#include <QStringBuilder>
#include <QShortcut>
namespace BlackGui
{
@@ -32,6 +38,12 @@ namespace BlackGui
connect(ui->pb_Style, &QPushButton::released, this, &CSettingsTextMessageStyle::changeStyle);
connect(ui->pb_Reset, &QPushButton::released, this, &CSettingsTextMessageStyle::resetStyle);
connect(ui->pb_Reset, &QPushButton::released, this, &CSettingsTextMessageStyle::changed);
connect(ui->pb_FontMinus, &QPushButton::released, this, &CSettingsTextMessageStyle::fontSizeMinus);
connect(ui->pb_FontPlus, &QPushButton::released, this, &CSettingsTextMessageStyle::fontSizePlus);
// QShortcut *sc = new QShortcut(CShortcut::keyFontMinus(), this);
// sc->setContext(Qt::WidgetWithChildrenShortcut);
// QObject::connect(sc, &QShortcut::activatedAmbiguously, this, &CSettingsTextMessageStyle::fontSizePlus);
}
CSettingsTextMessageStyle::~CSettingsTextMessageStyle()
@@ -84,13 +96,62 @@ namespace BlackGui
if (familySizeStlye.size() != 3) { return false; }
static const QString f("font-family: \"%1\"; font-size: %2; font-style: %3");
QString style = m_style;
const QString tableStyle = QStringLiteral("table { ") % f.arg(familySizeStlye.at(0), familySizeStlye.at(1), familySizeStlye.at(2)) % QStringLiteral(" }");
this->replaceTableStyle(tableStyle);
return true;
}
void CSettingsTextMessageStyle::replaceTableStyle(const QString &newTableStyle)
{
QString style = m_style;
thread_local const QRegularExpression re("table\\s*\\{.*\\}");
style.replace(re, tableStyle);
style.replace(re, newTableStyle);
m_style = style;
}
void CSettingsTextMessageStyle::fontSizeMinus()
{
if (this->changeFontSize(false))
{
emit this->changed();
}
}
void CSettingsTextMessageStyle::fontSizePlus()
{
if (this->changeFontSize(true))
{
emit this->changed();
}
}
bool CSettingsTextMessageStyle::changeFontSize(bool increase)
{
QString style = m_style;
thread_local const QRegularExpression re("table\\s*\\{.*:\\s*(\\d{1,2}).*\\}");
const QRegularExpressionMatch match = re.match(style);
const QStringList matches = match.capturedTexts();
if (matches.size() != 2) { return false; }
bool ok;
int ptSize = matches.last().toInt(&ok);
if (!ok) { return false; }
if (increase)
{
ptSize++;
if (ptSize > 16) { return false; }
}
else
{
ptSize--;
if (ptSize < 6) { return false; }
}
const QString pt = QString::number(ptSize) % "pt";
QString tableStyle = matches.front();
thread_local const QRegularExpression rePt("\\d{1,2}pt");
tableStyle.replace(rePt, pt);
this->replaceTableStyle(tableStyle);
return true;
}
} // ns

View File

@@ -45,6 +45,11 @@ namespace BlackGui
//! Style
void setStyle(const QString &style) { m_style = style; }
//! Font size @{
void fontSizeMinus();
void fontSizePlus();
//! @}
//! Reset style
void resetStyle() { m_style.clear(); }
@@ -66,6 +71,12 @@ namespace BlackGui
//! Update the font part
bool setFontFamilySizeStyle(const QStringList &familySizeStlye);
//! Replace the table style in style
void replaceTableStyle(const QString &newTableStyle);
//! Increase/decrease font size
bool changeFontSize(bool increase);
};
} // ns
} // ns

View File

@@ -2,16 +2,8 @@
<ui version="4.0">
<class>CSettingsTextMessageStyle</class>
<widget class="QFrame" name="CSettingsTextMessageStyle">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>301</width>
<height>26</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
<string>Text message style</string>
</property>
<layout class="QHBoxLayout" name="hl_SettingsTextMessageStyle">
<property name="leftMargin">
@@ -27,17 +19,32 @@
<number>3</number>
</property>
<item>
<spacer name="hs_TextMessageStyle">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QPushButton" name="pb_FontPlus">
<property name="toolTip">
<string>font enlarge (plus)</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="text">
<string>+</string>
</property>
</spacer>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/font-enlarge.png</normaloff>:/pastel/icons/pastel/16/font-enlarge.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_FontMinus">
<property name="toolTip">
<string>font shrink (minus)</string>
</property>
<property name="text">
<string>-</string>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/font-shrink.png</normaloff>:/pastel/icons/pastel/16/font-shrink.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Reset">
@@ -62,6 +69,15 @@
</item>
</layout>
</widget>
<resources/>
<tabstops>
<tabstop>pb_FontPlus</tabstop>
<tabstop>pb_FontMinus</tabstop>
<tabstop>pb_Reset</tabstop>
<tabstop>pb_Style</tabstop>
<tabstop>pb_Font</tabstop>
</tabstops>
<resources>
<include location="../../blackmisc/blackmisc.qrc"/>
</resources>
<connections/>
</ui>