diff --git a/src/declarativeimports/CMakeLists.txt b/src/declarativeimports/CMakeLists.txt --- a/src/declarativeimports/CMakeLists.txt +++ b/src/declarativeimports/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(accessdenied) add_subdirectory(core) add_subdirectory(plasmacomponents) +add_subdirectory(plasmaconfig) add_subdirectory(plasmaextracomponents) add_subdirectory(platformcomponents) add_subdirectory(calendar) diff --git a/src/declarativeimports/plasmaconfig/ConfigIcon.qml b/src/declarativeimports/plasmaconfig/ConfigIcon.qml new file mode 100644 --- /dev/null +++ b/src/declarativeimports/plasmaconfig/ConfigIcon.qml @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Chris Holland + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program 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 Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.0 +import QtQuick.Controls 2.5 as QtControls +import QtQuick.Layouts 1.0 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons + +RowLayout { + id: configIcon + + property alias value: textField.text + property int previewIconSize: units.iconSizes.large + property int previewIconPadding: units.smallSpacing + property string defaultValue: "" + property var presetValues: [] + + QtControls.Button { + id: iconButton + + implicitWidth: previewFrame.width + previewIconPadding * 2 + implicitHeight: previewFrame.height + previewIconPadding * 2 + + KQuickAddons.IconDialog { + id: iconDialog + onIconNameChanged: configIcon.value = iconName + } + + onPressed: iconMenu.opened ? iconMenu.close() : iconMenu.open() + + PlasmaCore.FrameSvgItem { + id: previewFrame + anchors.centerIn: parent + imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal + ? "widgets/panel-background" : "widgets/background" + width: previewIconSize + fixedMargins.left + fixedMargins.right + height: previewIconSize + fixedMargins.top + fixedMargins.bottom + + PlasmaCore.IconItem { + anchors.centerIn: parent + width: previewIconSize + height: previewIconSize + source: configIcon.value + } + } + + QtControls.Menu { + id: iconMenu + + // Appear below the button + y: +parent.height + + QtControls.MenuItem { + text: i18ndc("plasma_applet_org.kde.plasma.kickoff", "@item:inmenu Open icon chooser dialog", "Choose...") + icon.name: "document-open" + onClicked: iconDialog.open() + } + + QtControls.MenuItem { + text: i18ndc("plasma_applet_org.kde.plasma.kickoff", "@item:inmenu Reset icon to default", "Clear Icon"); + icon.name: icon.name = "edit-clear" + onClicked: configIcon.value = defaultValue + } + + // "visible:false" leaves leftover whitespace + Loader { + active: configIcon.presetValues.length > 0 + sourceComponent: QtControls.MenuSeparator {} + } + + Repeater { + model: configIcon.presetValues + QtControls.MenuItem { + text: modelData + icon.name: modelData + onClicked: configIcon.value = modelData + } + } + } + } + + QtControls.TextField { + id: textField + Layout.fillWidth: true + + text: configIcon.configValue + + QtControls.ToolButton { + visible: configIcon.value != defaultValue + icon.name: "edit-clear" + onClicked: configIcon.value = defaultValue + + anchors.top: parent.top + anchors.right: parent.right + anchors.bottom: parent.bottom + + width: height + } + } + + QtControls.Button { + icon.name: "document-open" + onClicked: iconDialog.open() + } +} diff --git a/src/declarativeimports/plasmaconfig/qmldir b/src/declarativeimports/plasmaconfig/qmldir new file mode 100644 --- /dev/null +++ b/src/declarativeimports/plasmaconfig/qmldir @@ -0,0 +1,3 @@ +module org.kde.plasma.config + +ConfigIcon 3.0 ConfigIcon.qml