diff --git a/src/qml/common/IconLabel.qml b/src/qml/common/IconLabel.qml new file mode 100644 index 0000000..d1e1f86 --- /dev/null +++ b/src/qml/common/IconLabel.qml @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Sebastian Gottfried + * + * This program 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 2 of + * the License, 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 +import QtQuick.Controls 2.0 + +Label { + property string icon: "" + property bool reserveSpaceForIcon: false + id: label + elide: Text.ElideRight + + padding: Math.ceil(0.7 * font.pixelSize) + leftPadding: iconItem.visible || reserveSpaceForIcon? 2 * padding + iconItem.width: padding + verticalAlignment: Text.AlignVCenter + + MonochromeIcon { + id: iconItem + visible: label.icon != "" + color: label.color + anchors { + left: parent.left + leftMargin: label.padding + verticalCenter: parent.verticalCenter + } + icon: label.icon + width: 22 + height: 22 + } +} diff --git a/src/qml/common/IconToolButton.qml b/src/qml/common/IconToolButton.qml index 64ae30a..ef8a4ad 100644 --- a/src/qml/common/IconToolButton.qml +++ b/src/qml/common/IconToolButton.qml @@ -1,71 +1,45 @@ /* * Copyright 2017 Sebastian Gottfried * * This program 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 2 of * the License, 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.4 import QtQuick.Controls 2.0 -import QtGraphicalEffects 1.0 -import QtQuick.Layouts 1.1 -import org.kde.kquickcontrolsaddons 2.0 ToolButton { id: button - property color color: "#000000" + property alias color: content.color + property alias icon: content.icon property color backgroundColor: "#ffffff" - property alias icon: icon.icon + padding: 0 hoverEnabled: true - implicitWidth: button.text == ""? implicitHeight: icon.implicitWidth + label.implicitWidth + layout.spacing - implicitHeight: 40 - contentItem: RowLayout { - id: layout - spacing: button.text != ""? 5: 0 - Item { - Layout.fillHeight: true - Layout.preferredWidth: icon.width - Layout.fillWidth: button.text == "" - QIconItem { - id: icon - width: 24 - height: 24 - anchors.centerIn: parent - } - ColorOverlay { - anchors.fill: icon - source: icon - color: button.color - } - } - Text { - id: label - Layout.fillWidth: true - color: button.color - text: button.text - } + contentItem: IconLabel { + id: content + text: button.text } background: Rectangle { opacity: (checked? 0.6: 0) + (hovered? 0.3: 0) color: button.backgroundColor Behavior on opacity { NumberAnimation { duration: 150 } } } } diff --git a/src/qml/common/ListItem.qml b/src/qml/common/ListItem.qml index 2185b57..8a31a0c 100644 --- a/src/qml/common/ListItem.qml +++ b/src/qml/common/ListItem.qml @@ -1,100 +1,63 @@ /* * Copyright 2012 Sebastian Gottfried * Copyright 2015 Sebastian Gottfried * * This program 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 2 of * the License, 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import QtQuick 2.4 -import QtQuick.Controls 1.3 -import QtQuick.Layouts 1.1 -import org.kde.kquickcontrolsaddons 2.0 +import QtQuick.Controls 2.0 import ktouch 1.0 -Item { +ItemDelegate { id: root - property alias title: label.text - property string iconSource + property string icon property alias label: label - property bool isCurrent: ListView.isCurrentItem; - signal clicked - signal doubleClicked - height: 2 * content.height + property alias bg: bg + property alias reserveSpaceForIcon: label.reserveSpaceForIcon + hoverEnabled: true + padding: 0 + + KColorScheme { + id: listItemColorSchemeNormal + colorGroup: KColorScheme.Active + colorSet: KColorScheme.View + } - SystemPalette { - id: listItemPallete - colorGroup: SystemPalette.Active + KColorScheme { + id: listItemColorSchemeHighlighted + colorGroup: KColorScheme.Active + colorSet: KColorScheme.Selection } - Rectangle { + background: Rectangle { id: bg anchors.fill: parent - color: Qt.rgba(listItemPallete.highlight.r, listItemPallete.highlight.g, listItemPallete.highlight.b, 0.3) - radius: 0.2 * height - border { - width: 1 - color: listItemPallete.highlight - } - opacity: root.isCurrent || mouseArea.containsMouse? 1: 0 + color: listItemColorSchemeHighlighted.normalBackground + opacity: root.highlighted ? 1 : (root.hovered? 0.3: 0) Behavior on opacity { NumberAnimation { duration: 150 - } - } - } - - Item { - id: content - anchors { - verticalCenter: parent.verticalCenter - left: parent.left - right: parent.right - leftMargin: 5 - rightMargin: 5 - } - - height: Math.max(label.height, label.height) - - QIconItem { - id: iconItem - visible: !!root.iconSource - anchors { - left: parent.left - verticalCenter: parent.verticalCenter - } - icon: root.iconSource - width: 22 - height: 22 - } - - Label { - id: label - elide: Text.ElideRight - anchors { - left: iconItem.visible? iconItem.right: parent.left - right: parent.right - verticalCenter: parent.verticalCenter } } } - MouseArea { - id: mouseArea - anchors.fill: parent - hoverEnabled: true - onClicked: root.clicked() - onDoubleClicked: root.doubleClicked() + contentItem: IconLabel { + id: label + text: root.text + icon: root.icon + color: root.highlighted? listItemColorSchemeHighlighted.activeText: listItemColorSchemeNormal.normalText; } } diff --git a/src/qml/common/MonochromeIcon.qml b/src/qml/common/MonochromeIcon.qml new file mode 100644 index 0000000..1649e0b --- /dev/null +++ b/src/qml/common/MonochromeIcon.qml @@ -0,0 +1,32 @@ +/* + * Copyright 2017 Sebastian Gottfried + * + * This program 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 2 of + * the License, 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.4 +import QtGraphicalEffects 1.0 +import org.kde.kquickcontrolsaddons 2.0 + +QIconItem { + property color color: "#000000" + id: icon + width: 24 + height: 24 + ColorOverlay { + anchors.fill: parent + source: icon + color: parent.color + } +} diff --git a/src/qml/qml.qrc b/src/qml/qml.qrc index 298ca13..657960c 100644 --- a/src/qml/qml.qrc +++ b/src/qml/qml.qrc @@ -1,45 +1,47 @@ main.qml meters/AccuracyMeter.qml meters/CharactersPerMinuteMeter.qml meters/ElapsedTimeMeter.qml meters/Meter.qml meters/StatBox.qml common/DetailedRadioButton.qml common/InfoItem.qml common/InformationTable.qml common/InlineToolbar.qml common/LearningProgressChart.qml common/ListItem.qml common/MessageBox.qml common/SelectionGrip.qml common/SelectionRectangle.qml common/SheetDialog.qml common/Balloon.qml scorescreen/ScoreScreen.qml trainingscreen/KeyboardUnavailableNotice.qml trainingscreen/TrainingScreenMenuOverlay.qml trainingscreen/TrainingScreen.qml trainingscreen/TrainingScreenToolbar.qml trainingscreen/TrainingWidget.qml homescreen/CourseDescriptionItem.qml homescreen/CoursePage.qml homescreen/CourseSelector.qml homescreen/InitialProfileForm.qml homescreen/LessonLockedNotice.qml homescreen/LessonPreview.qml homescreen/LessonSelectorBase.qml homescreen/HomeScreen.qml homescreen/CustomLessonSelector.qml homescreen/ProfileForm.qml homescreen/LessonSelector.qml homescreen/ProfileSelector.qml homescreen/ProfileDetailsItem.qml keyboard/Keyboard.qml keyboard/KeyItem.qml keyboard/KeyLabel.qml keyboard/KeyboardLayoutEditor.qml common/IconToolButton.qml + common/IconLabel.qml + common/MonochromeIcon.qml