Commit ad9b6639 authored by Shantanu Tushar's avatar Shantanu Tushar Committed by Nate Graham
Browse files

Config option to adjust font size

The font size is often too small if you have the notes on a smaller
secondary screen (laptop next to a monitor, for example). Being able to
set a font size for the notes is very useful in this case.

BUG: 360115
parent 96f6bbc9
......@@ -11,6 +11,9 @@
<default>yellow</default>
</entry>
<entry name="fontSize" type="int">
</entry>
<entry name="noteId" type="String">
<default></default>
</entry>
......
......@@ -5,74 +5,107 @@
*/
import QtQuick 2.5
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.5 as QQC2
import org.kde.kcm 1.1 as KCM
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.kirigami 2.5 as Kirigami
KCM.GridView {
id: appearancePage
ColumnLayout {
property string cfg_color
property alias cfg_fontSize: fontSizeSpinBox.value
contentWidth: implicitWidth
contentHeight: implicitHeight
Kirigami.FormLayout {
Layout.fillWidth: true
PlasmaCore.Svg {
id: noteSvg
imagePath: "widgets/notes"
}
QQC2.SpinBox {
id: fontSizeSpinBox
implicitWidth: Kirigami.Units.gridUnit * 3
from: 4
to: 128
textFromValue: function (value) {
return i18n("%1pt", value)
}
valueFromText: function (text) {
return parseInt(text)
}
view.model: ["white", "black", "red", "orange", "yellow", "green", "blue", "pink", "translucent", "translucent-light"]
view.currentIndex: view.model.indexOf(cfg_color)
view.onCurrentIndexChanged: cfg_color = view.model[view.currentIndex]
Kirigami.FormData.label: i18n("Text font size:")
}
}
Kirigami.Heading {
level: 2
text: i18n("Background color")
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
view.delegate: KCM.GridDelegate {
id: delegate
thumbnailAvailable: true
thumbnail: PlasmaCore.SvgItem {
KCM.GridView {
id: appearancePage
anchors.fill: parent
anchors.margins: PlasmaCore.Units.gridUnit / 2
svg: noteSvg
elementId: modelData + "-notes"
QQC2.Label {
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: {
switch (modelData) {
case "white": return i18n("A white sticky note")
case "black": return i18n("A black sticky note")
case "red": return i18n("A red sticky note")
case "orange": return i18n("An orange sticky note")
case "yellow": return i18n("A yellow sticky note")
case "green": return i18n("A green sticky note")
case "blue": return i18n("A blue sticky note")
case "pink": return i18n("A pink sticky note")
case "translucent": return i18n("A translucent sticky note")
case "translucent-light": return i18n("A translucent sticky note with light text")
PlasmaCore.Svg {
id: noteSvg
imagePath: "widgets/notes"
}
view.model: ["white", "black", "red", "orange", "yellow", "green", "blue", "pink", "translucent", "translucent-light"]
view.currentIndex: view.model.indexOf(cfg_color)
view.onCurrentIndexChanged: cfg_color = view.model[view.currentIndex]
view.delegate: KCM.GridDelegate {
id: delegate
thumbnailAvailable: true
thumbnail: PlasmaCore.SvgItem {
anchors.fill: parent
anchors.margins: PlasmaCore.Units.gridUnit / 2
svg: noteSvg
elementId: modelData + "-notes"
QQC2.Label {
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
text: {
switch (modelData) {
case "white": return i18n("A white sticky note")
case "black": return i18n("A black sticky note")
case "red": return i18n("A red sticky note")
case "orange": return i18n("An orange sticky note")
case "yellow": return i18n("A yellow sticky note")
case "green": return i18n("A green sticky note")
case "blue": return i18n("A blue sticky note")
case "pink": return i18n("A pink sticky note")
case "translucent": return i18n("A translucent sticky note")
case "translucent-light": return i18n("A translucent sticky note with light text")
}
}
elide: Text.ElideRight
wrapMode: Text.WordWrap
//this is deliberately _NOT_ the theme color as we are over a known bright background
//an unknown colour over a known colour is a bad move as you end up with white on yellow
color: {
if (modelData === "black" || modelData === "translucent-light") {
return "#dfdfdf"
} else {
return "#202020"
}
}
}
}
elide: Text.ElideRight
wrapMode: Text.WordWrap
//this is deliberately _NOT_ the theme color as we are over a known bright background
//an unknown colour over a known colour is a bad move as you end up with white on yellow
color: {
if (modelData === "black" || modelData === "translucent-light") {
return "#dfdfdf"
} else {
return "#202020"
}
onClicked: {
cfg_color = modelData
appearancePage.forceActiveFocus()
}
}
}
onClicked: {
cfg_color = modelData
appearancePage.forceActiveFocus();
}
}
}
......@@ -122,6 +122,7 @@ PlasmaCore.SvgItem {
cursorPosition: mainTextArea.cursorPosition
selectionStart: mainTextArea.selectionStart
selectionEnd: mainTextArea.selectionEnd
defaultFontSize: mainTextArea.cfgFontPointSize
}
FocusScope {
......@@ -148,6 +149,7 @@ PlasmaCore.SvgItem {
PlasmaComponents3.TextArea {
id: mainTextArea
property real cfgFontPointSize: plasmoid.configuration.fontSize
textFormat: TextEdit.RichText
onLinkActivated: Qt.openUrlExternally(link)
......@@ -156,6 +158,8 @@ PlasmaCore.SvgItem {
persistentSelection: true
wrapMode: TextEdit.Wrap
font.pointSize: cfgFontPointSize
Keys.onPressed: {
if(event.key === Qt.Key_Escape) {
plasmoid.expanded = false;
......@@ -185,6 +189,15 @@ PlasmaCore.SvgItem {
}
}
// Apply the font size change to existing texts
onCfgFontPointSizeChanged: {
var [start, end] = [mainTextArea.selectionStart, mainTextArea.selectionEnd];
mainTextArea.selectAll();
documentHandler.fontSize = cfgFontPointSize;
mainTextArea.select(start, end);
}
// update the note if the source changes, but only if the user isn't editing it currently
Binding {
target: mainTextArea
......@@ -210,6 +223,12 @@ PlasmaCore.SvgItem {
}
}
Component.onCompleted: {
if (!plasmoid.configuration.fontSize)
// Set fontSize to default if it is not set
plasmoid.configuration.fontSize = mainTextArea.font.pointSize
}
QQC2.Menu {
id: contextMenu
......
......@@ -259,9 +259,29 @@ void DocumentHandler::setFontSize(int arg)
QTextCharFormat format;
format.setFontPointSize(arg);
mergeFormatOnWordOrSelection(format);
// Also set the block char format, otherwise the old block font will stay and
// end up taking effect if the user deletes all the text.
cursor.mergeBlockCharFormat(format);
Q_EMIT fontSizeChanged();
}
int DocumentHandler::defaultFontSize() const
{
return m_doc ? m_doc->defaultFont().pointSize() : 0;
}
void DocumentHandler::setDefaultFontSize(int arg)
{
if (!m_doc)
return;
auto font = m_doc->defaultFont();
font.setPointSize(arg);
m_doc->setDefaultFont(font);
Q_EMIT defaultFontSizeChanged();
}
QColor DocumentHandler::textColor() const
{
QTextCursor cursor = textCursor();
......
......@@ -35,6 +35,7 @@ class DocumentHandler : public QObject
Q_PROPERTY(bool strikeOut READ strikeOut WRITE setStrikeOut NOTIFY strikeOutChanged)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(int defaultFontSize READ defaultFontSize WRITE setDefaultFontSize NOTIFY defaultFontSizeChanged)
Q_PROPERTY(QStringList defaultFontSizes READ defaultFontSizes NOTIFY defaultFontSizesChanged)
......@@ -82,6 +83,7 @@ public:
bool underline() const;
bool strikeOut() const;
int fontSize() const;
int defaultFontSize() const;
QStringList defaultFontSizes() const;
QString text() const;
......@@ -97,6 +99,7 @@ public Q_SLOTS:
void setUnderline(bool arg);
void setStrikeOut(bool arg);
void setFontSize(int arg);
void setDefaultFontSize(int arg);
void setTextColor(const QColor &arg);
void setFontFamily(const QString &arg);
......@@ -123,6 +126,7 @@ Q_SIGNALS:
void strikeOutChanged();
void fontSizeChanged();
void defaultFontSizeChanged();
void defaultFontSizesChanged();
void fileUrlChanged();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment