From f7094ca1879fe7737ef998c1a828ab1aeb7420f2 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Sun, 2 Oct 2016 01:43:12 +0300 Subject: [PATCH] add font dialog, some color dialog improvements --- .../package/contents/ui/ButtonSelector.qml | 3 ++ .../package/contents/ui/ColorSelector.qml | 19 ++----- .../package/contents/ui/FontSelector.qml | 54 +++++++++++++++++++ .../package/contents/ui/advanced.qml | 2 - .../package/contents/ui/appearance.qml | 52 +++--------------- .../awesome-widget/package/contents/ui/qmldir | 1 + .../package/contents/ui/tooltip.qml | 2 - 7 files changed, 69 insertions(+), 64 deletions(-) create mode 100644 sources/awesome-widget/package/contents/ui/FontSelector.qml diff --git a/sources/awesome-widget/package/contents/ui/ButtonSelector.qml b/sources/awesome-widget/package/contents/ui/ButtonSelector.qml index dc244c6..854bda5 100644 --- a/sources/awesome-widget/package/contents/ui/ButtonSelector.qml +++ b/sources/awesome-widget/package/contents/ui/ButtonSelector.qml @@ -25,6 +25,7 @@ Row { property alias text: label.text property alias value: button.text + property alias style: button.style signal buttonActivated @@ -32,6 +33,8 @@ Row { id: label height: parent.height width: parent.width * 2 / 5 + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter } QtControls.Button { id: button diff --git a/sources/awesome-widget/package/contents/ui/ColorSelector.qml b/sources/awesome-widget/package/contents/ui/ColorSelector.qml index d74927c..1ecaac0 100644 --- a/sources/awesome-widget/package/contents/ui/ColorSelector.qml +++ b/sources/awesome-widget/package/contents/ui/ColorSelector.qml @@ -16,7 +16,6 @@ ***************************************************************************/ import QtQuick 2.0 -import QtQuick.Controls 1.3 as QtControls import QtQuick.Controls.Styles 1.3 as QtStyles import QtQuick.Dialogs 1.1 as QtDialogs @@ -25,25 +24,17 @@ Row { height: implicitHeight width: parent.width - property alias text: label.text - property alias value: colorButton.text + property alias text: selector.text + property alias value: selector.value - QtControls.Label { - id: label - height: parent.height - width: parent.width * 2 / 5 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - } - QtControls.Button { - id: colorButton - width: parent.width * 3 / 5 + ButtonSelector { + id: selector style: QtStyles.ButtonStyle { background: Rectangle { color: value } } - onClicked: colorDialog.visible = true + onButtonActivated: colorDialog.visible = true } QtDialogs.ColorDialog { diff --git a/sources/awesome-widget/package/contents/ui/FontSelector.qml b/sources/awesome-widget/package/contents/ui/FontSelector.qml new file mode 100644 index 0000000..aed4731 --- /dev/null +++ b/sources/awesome-widget/package/contents/ui/FontSelector.qml @@ -0,0 +1,54 @@ +/*************************************************************************** + * This file is part of awesome-widgets * + * * + * awesome-widgets is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * awesome-widgets is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with awesome-widgets. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Dialogs 1.1 as QtDialogs + + +Row { + height: implicitHeight + width: parent.width + + property alias text: selector.text + property alias value: selector.value + + ButtonSelector { + id: selector + text: label.text + onButtonActivated: { + fontDialog.setFont() + fontDialog.visible = true + } + } + + QtDialogs.FontDialog { + id: fontDialog + title: i18n("Select a font") + + signal setFont + + onAccepted: value = fontDialog.font.family + onSetFont: { + fontDialog.font = Qt.font({ + family: value, + pointSize: 12, + italic: false, + weight: Font.Normal, + }) + } + } +} diff --git a/sources/awesome-widget/package/contents/ui/advanced.qml b/sources/awesome-widget/package/contents/ui/advanced.qml index bbe344c..1b5ea33 100644 --- a/sources/awesome-widget/package/contents/ui/advanced.qml +++ b/sources/awesome-widget/package/contents/ui/advanced.qml @@ -16,8 +16,6 @@ ***************************************************************************/ import QtQuick 2.0 -import QtQuick.Controls 1.3 as QtControls -import QtQuick.Dialogs 1.2 as QtDialogs import org.kde.plasma.private.awesomewidget 1.0 diff --git a/sources/awesome-widget/package/contents/ui/appearance.qml b/sources/awesome-widget/package/contents/ui/appearance.qml index 48f2ec8..5c2f28a 100644 --- a/sources/awesome-widget/package/contents/ui/appearance.qml +++ b/sources/awesome-widget/package/contents/ui/appearance.qml @@ -16,8 +16,6 @@ ***************************************************************************/ import QtQuick 2.0 -import QtQuick.Controls 1.3 as QtControls -import QtQuick.Dialogs 1.1 as QtDialogs import org.kde.plasma.private.awesomewidget 1.0 @@ -43,7 +41,7 @@ Item { 87: 5 } - property alias cfg_fontFamily: selectFont.text + property alias cfg_fontFamily: font.value property alias cfg_fontSize: fontSize.value property string cfg_fontWeight: fontWeight.value property string cfg_fontStyle: fontStyle.value @@ -55,26 +53,11 @@ Item { Column { id: pageColumn anchors.fill: parent - Row { - height: implicitHeight - width: parent.width - QtControls.Label { - height: parent.height - width: parent.width / 3 - horizontalAlignment: Text.AlignRight - verticalAlignment: Text.AlignVCenter - text: i18n("Font") - } - QtControls.Button { - id: selectFont - width: parent.width * 2 / 3 - text: plasmoid.configuration.fontFamily - onClicked: { - if (debug) console.debug() - fontDialog.setFont() - fontDialog.visible = true - } - } + + FontSelector { + id: font + text: i18n("Font") + value: plasmoid.configuration.fontFamily } IntegerSelector { @@ -170,29 +153,6 @@ Item { } } - QtDialogs.FontDialog { - id: fontDialog - title: i18n("Select a font") - signal setFont - - onAccepted: { - if (debug) console.debug() - selectFont.text = fontDialog.font.family - fontSize.value = fontDialog.font.pointSize - fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 - fontWeight.currentIndex = weight[fontDialog.font.weight] - } - onSetFont: { - if (debug) console.debug() - fontDialog.font = Qt.font({ - family: selectFont.text, - pointSize: fontSize.value > 0 ? fontSize.value : 12, - italic: fontStyle.currentIndex == 1, - weight: Font.Normal, - }) - } - } - Component.onCompleted: { if (debug) console.debug() diff --git a/sources/awesome-widget/package/contents/ui/qmldir b/sources/awesome-widget/package/contents/ui/qmldir index 3cc294b..e26da51 100644 --- a/sources/awesome-widget/package/contents/ui/qmldir +++ b/sources/awesome-widget/package/contents/ui/qmldir @@ -5,6 +5,7 @@ CheckBoxSelector ./CheckBoxSelector.qml ColorSelector ./ColorSelector.qml ComboBoxSelector ./ComboBoxSelector.qml ExportDialog ./ExportDialog.qml +FontSelector ./FontSelector.qml ImportDialog ./ImportDialog.qml IntegerSelector ./IntegerSelector.qml LineSelector ./LineSelector.qml diff --git a/sources/awesome-widget/package/contents/ui/tooltip.qml b/sources/awesome-widget/package/contents/ui/tooltip.qml index e6758da..e7a3db1 100644 --- a/sources/awesome-widget/package/contents/ui/tooltip.qml +++ b/sources/awesome-widget/package/contents/ui/tooltip.qml @@ -17,8 +17,6 @@ import QtQuick 2.0 import QtQuick.Controls 1.3 as QtControls -import QtQuick.Controls.Styles 1.3 as QtStyles -import QtQuick.Dialogs 1.1 as QtDialogs import org.kde.plasma.private.awesomewidget 1.0