diff --git a/src/qmlcontrols/CMakeLists.txt b/src/qmlcontrols/CMakeLists.txt --- a/src/qmlcontrols/CMakeLists.txt +++ b/src/qmlcontrols/CMakeLists.txt @@ -1,6 +1,7 @@ add_subdirectory(draganddrop) add_subdirectory(kquickcontrolsaddons) +add_subdirectory(kcmcontrols) if(KF5I18n_FOUND AND KF5Config_FOUND AND KF5WidgetsAddons_FOUND AND KF5WindowSystem_FOUND AND KF5GlobalAccel_FOUND AND KF5KIO_FOUND AND KF5GuiAddons_FOUND) add_subdirectory(kquickcontrols) diff --git a/src/qmlcontrols/kcmcontrols/CMakeLists.txt b/src/qmlcontrols/kcmcontrols/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/CMakeLists.txt @@ -0,0 +1,19 @@ +project(draganddrop) + +set(declarativedragdrop_SRCS + kcmcontrolsplugin.cpp +) + +add_library(kcmcontrolsplugin SHARED ${declarativedragdrop_SRCS}) +target_link_libraries(kcmcontrolsplugin + Qt5::Core + Qt5::Quick + Qt5::Qml + Qt5::Gui + KF5::CoreAddons + KF5::QuickAddons +) + +install(TARGETS kcmcontrolsplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kcm) + +install(DIRECTORY qml/ DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kcm) diff --git a/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.h b/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.h new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.h @@ -0,0 +1,37 @@ +/* + Copyright 2011 by Marco Martin + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#ifndef KCMCONTROLSPLUGIN_H +#define KCMCONTROLSPLUGIN_H + +#include + +class KCMControlsPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) Q_DECL_OVERRIDE; +}; + +#endif diff --git a/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.cpp b/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.cpp new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/kcmcontrolsplugin.cpp @@ -0,0 +1,36 @@ +/* + Copyright 2017 by Marco Martin + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "kcmcontrolsplugin.h" + +#include + +#include + + +void KCMControlsPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("org.kde.kcm")); + + qmlRegisterUncreatableType("org.kde.kcm", 1, 0, "ConfigModule", + QLatin1String("Do not create objects of type ConfigModule")); +} diff --git a/src/qmlcontrols/kcmcontrols/qml/GridDelegate.qml b/src/qmlcontrols/kcmcontrols/qml/GridDelegate.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/GridDelegate.qml @@ -0,0 +1,165 @@ +/* + Copyright (c) 2015 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.2 as Controls +import QtQuick.Templates 2.2 as T2 +import QtGraphicalEffects 1.0 + +import org.kde.kirigami 2.2 as Kirigami + + +T2.ItemDelegate { + id: delegate + + property string toolTip + property alias thumbnail: thumbnailArea.data + property bool thumbnailAvailable: false + property list actions + + width: view.cellWidth + height: view.cellHeight + hoverEnabled: true + + Rectangle { + id: thumbnail + anchors { + left: parent.left + right: parent.right + top: parent.top + margins: Kirigami.Units.smallSpacing * 2 + } + height: width/1.6 + radius: Kirigami.Units.smallSpacing + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.View + + color: { + if (delegate.GridView.isCurrentItem) { + return Kirigami.Theme.highlightColor; + } else if (parent.hovered) { + return Qt.tint(Kirigami.Theme.backgroundColor, Qt.rgba(Kirigami.Theme.highlightColor.r, Kirigami.Theme.highlightColor.g, Kirigami.Theme.highlightColor.b, 0.3)) + } else { + return Kirigami.Theme.backgroundColor + } + } + Behavior on color { + ColorAnimation { + duration: Kirigami.Units.longDuration + easing.type: Easing.OutQuad + } + } + + Rectangle { + id: thumbnailArea + radius: Kirigami.Units.smallSpacing/2 + anchors { + fill: parent + margins: Kirigami.Units.smallSpacing + } + + color: Kirigami.Theme.backgroundColor + Kirigami.Icon { + visible: !delegate.thumbnailAvailable + anchors.centerIn: parent + width: Kirigami.Units.iconSizes.large + height: width + source: "view-preview" + } + } + + Rectangle { + anchors.fill: parent + visible: actionsRow.children.length > 0 + opacity: delegate.hovered || (actionsScope.focus) ? 1 : 0 + radius: Kirigami.Units.smallSpacing + color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.4) + + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.Complementary + + Behavior on opacity { + PropertyAnimation { + duration: Kirigami.Units.longDuration + easing.type: Easing.OutQuad + } + } + + FocusScope { + id: actionsScope + anchors { + right: parent.right + bottom: parent.bottom + margins: Kirigami.Units.smallSpacing + } + width: actionsRow.width + height: actionsRow.height + RowLayout { + id: actionsRow + + Repeater { + model: delegate.actions + delegate: Controls.ToolButton { + Kirigami.Icon { + Kirigami.Theme.inherit: false + Kirigami.Theme.colorSet: Kirigami.Theme.Complementary + anchors.centerIn: parent + width: Kirigami.Units.iconSizes.smallMedium + height: width + source: modelData.iconName + } + activeFocusOnTab: focus || delegate.focus + onClicked: modelData.trigger() + enabled: modelData.enabled + //NOTE: there aren't any global settings where to take "official" tooltip timeouts + Controls.ToolTip.delay: 1000 + Controls.ToolTip.timeout: 5000 + Controls.ToolTip.visible: hovered + Controls.ToolTip.text: modelData.tooltip + } + } + } + } + } + layer.enabled: true + layer.effect: DropShadow { + horizontalOffset: 0 + verticalOffset: 2 + radius: 10 + samples: 32 + color: Qt.rgba(0, 0, 0, 0.3) + } + } + + Controls.Label { + anchors { + left: parent.left + right: parent.right + top: thumbnail.bottom + topMargin: Kirigami.Units.smallSpacing + } + text: delegate.text + horizontalAlignment: Text.AlignHCenter + elide: Text.ElideRight + } + Controls.ToolTip.delay: 1000 + Controls.ToolTip.timeout: 5000 + Controls.ToolTip.visible: hovered + Controls.ToolTip.text: toolTip +} diff --git a/src/qmlcontrols/kcmcontrols/qml/GridView.qml b/src/qmlcontrols/kcmcontrols/qml/GridView.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/GridView.qml @@ -0,0 +1,63 @@ +/* + Copyright (c) 2017 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.2 as QtControls +import org.kde.kirigami 2.3 as Kirigami + +QtControls.ScrollView { + id: scroll + property alias view: view + + + implicitWidth: Math.max(view.cellWidth * 2 + internal.scrollBarSpace + , Math.floor(internal.availableWidth / view.cellWidth) * view.cellWidth + internal.scrollBarSpace + 4) + activeFocusOnTab: false + Kirigami.Theme.colorSet: Kirigami.Theme.View + Kirigami.Theme.inherit: false + + Component.onCompleted: scroll.background.visible = true; + + GridView { + id: view + property int implicitCellWidth: Kirigami.Units.gridUnit * 10 + property int implicitCellHeight: Math.round(implicitCellWidth / 1.6) + Kirigami.Units.gridUnit + QtObject { + id: internal + readonly property int availableWidth: scroll.parent.width - internal.scrollBarSpace - 4 + readonly property int scrollBarSpace: scroll.QtControls.ScrollBar.vertical.width + } + anchors { + fill: parent + margins: 2 + leftMargin: contentHeight <= height ? internal.scrollBarSpace/2 : 2 + rightMargin: contentHeight <= height ? internal.scrollBarSpace/2 : internal.scrollBarSpace + 2 + } + clip: true + activeFocusOnTab: true + + cellWidth: Math.min(Math.floor(internal.availableWidth / 2), implicitCellWidth) + cellHeight: Math.round(cellWidth / 1.6) + Kirigami.Units.gridUnit + + keyNavigationEnabled: true + keyNavigationWraps: true + highlightMoveDuration: 0 + } + QtControls.ScrollBar.horizontal.visible: false +} diff --git a/src/qmlcontrols/kcmcontrols/qml/GridViewKCM.qml b/src/qmlcontrols/kcmcontrols/qml/GridViewKCM.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/GridViewKCM.qml @@ -0,0 +1,48 @@ +/* + Copyright (c) 2017 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 2.2 as QtControls +import org.kde.kirigami 2.2 as Kirigami +import org.kde.kcm 1.1 as KCM + +Kirigami.Page { + id: root + + title: kcm.name + implicitWidth: view.implicitCellWidth * 3 + scroll.QtControls.ScrollBar.vertical.width + Kirigami.Units.gridUnit + implicitHeight: view.implicitCellHeight * 3 + (header ? header.height : 0) + (footer ? footer.height : 0) + Kirigami.Units.gridUnit + + property alias view: scroll.view + + topPadding: 0 + leftPadding: 0 + rightPadding: 0 + bottomPadding: footer ? Kirigami.Units.smallSpacing : 0 + + KCM.GridView { + id: scroll + width: Math.min(implicitWidth, root.width) + anchors { + top: parent.top + bottom: parent.bottom + horizontalCenter: parent.horizontalCenter + } + } +} diff --git a/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml b/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/SimpleKCM.qml @@ -0,0 +1,50 @@ +/* + Copyright (c) 2017 Marco Martin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +import QtQuick 2.7 +import org.kde.kirigami 2.2 as Kirigami +import org.kde.kcm 1.1 as KCM + +Kirigami.ScrollablePage { + id: root + + title: kcm.name + implicitWidth: Kirigami.Units.gridUnit * 20 + implicitHeight: Math.min(flickable.contentHeight, Kirigami.Units.gridUnit * 20) + + children: [ + Kirigami.Separator { + z: 999 + anchors { + left: parent.left + right: parent.right + top: parent.top + } + visible: !root.flickable.atYBeginning + }, + Kirigami.Separator { + z: 999 + anchors { + left: parent.left + right: parent.right + bottom: parent.bottom + } + visible: !root.flickable.atYEnd + } + ] +} diff --git a/src/qmlcontrols/kcmcontrols/qml/qmldir b/src/qmlcontrols/kcmcontrols/qml/qmldir new file mode 100644 --- /dev/null +++ b/src/qmlcontrols/kcmcontrols/qml/qmldir @@ -0,0 +1,7 @@ +module org.kde.kcm +plugin kcmcontrolsplugin + +GridDelegate 1.1 GridDelegate.qml +GridViewKCM 1.1 GridViewKCM.qml +GridView 1.1 GridView.qml +SimpleKCM 1.1 SimpleKCM.qml diff --git a/src/quickaddons/configmodule.cpp b/src/quickaddons/configmodule.cpp --- a/src/quickaddons/configmodule.cpp +++ b/src/quickaddons/configmodule.cpp @@ -55,8 +55,6 @@ _needsAuthorization(false), _needsSave(false) { - qmlRegisterUncreatableType("org.kde.kcm", 1, 0, "ConfigModule", - QLatin1String("Do not create objects of type ConfigModule")); } void authStatusChanged(int status);