From fb4765d50aa7a7744ae950566e5978abdc6207b3 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 27 Apr 2015 11:01:18 +0200 Subject: [PATCH] capability to remove items better history delegate --- dialer/package/contents/ui/Dialer/History.qml | 46 ++----- .../contents/ui/Dialer/HistoryDelegate.qml | 122 ++++++++++++++++++ dialer/package/contents/ui/main.qml | 18 ++- 3 files changed, 147 insertions(+), 39 deletions(-) create mode 100644 dialer/package/contents/ui/Dialer/HistoryDelegate.qml diff --git a/dialer/package/contents/ui/Dialer/History.qml b/dialer/package/contents/ui/Dialer/History.qml index a21e503c..9479bb1f 100644 --- a/dialer/package/contents/ui/Dialer/History.qml +++ b/dialer/package/contents/ui/Dialer/History.qml @@ -17,14 +17,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 2.0 +import QtQuick 2.4 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras -Rectangle { - color: syspal.base +Item { function secondsToTimeString(seconds) { seconds = Math.floor(seconds/1000) @@ -50,46 +49,17 @@ Rectangle { section { property: "date" labelPositioning: ViewSection.CurrentLabelAtStart - delegate: Rectangle { - width: view.width - height: childrenRect.height - color: syspal.base + delegate: PlasmaComponents.ListItem { + //width: view.width + //height: childrenRect.height + //color: syspal.base + sectionDelegate: true PlasmaComponents.Label { text: Qt.formatDate(section, Qt.locale().dateFormat(Locale.LongFormat)); } } } - delegate: MouseArea { - width: view.width - height: childrenRect.height - onClicked: call(model.number); - - RowLayout { - width: view.width - PlasmaComponents.Label { - text: { - switch (model.callType) { - case 0: - return "miss"; - case 1: - return "incoming"; - case 2: - return "outgoing"; - } - } - } - PlasmaComponents.Label { - text: model.number - Layout.fillWidth: true - } - PlasmaComponents.Label { - text: i18n("Duration: %1", secondsToTimeString(model.duration)); - } - PlasmaComponents.Label { - text: Qt.formatTime(model.date+" "+model.time, Qt.locale().timeFormat(Locale.LongFormat)); - } - } - } + delegate: HistoryDelegate {} } } } \ No newline at end of file diff --git a/dialer/package/contents/ui/Dialer/HistoryDelegate.qml b/dialer/package/contents/ui/Dialer/HistoryDelegate.qml new file mode 100644 index 00000000..57bc9f9e --- /dev/null +++ b/dialer/package/contents/ui/Dialer/HistoryDelegate.qml @@ -0,0 +1,122 @@ +/* + * Copyright 2015 Marco Martin + * + * 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.4 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras + +Item { + id: delegateParent + width: view.width + height: childrenRect.height + + Behavior on height { + SpringAnimation { spring: 5; damping: 0.3 } + } + SequentialAnimation { + id: removeAnim + XAnimator { + target: delegate + from: delegate.x + to: delegate.x > 0 ? width : -width + duration: units.longDuration + easing.type: Easing.InOutQuad + } + PropertyAnimation { + target: delegateParent + properties: "height" + to: 0 + duration: units.longDuration + easing.type: Easing.InOutQuad + } + ScriptAction { + script: removeCallFromHistory(index); + } + } + + XAnimator { + id: resetAnim + target: delegate + from: delegate.x + to: 0 + duration: units.longDuration + easing.type: Easing.InOutQuad + } + + PlasmaComponents.ListItem { + id: delegate + + MouseArea { + width: parent.width + height: childrenRect.height + onClicked: call(model.number); + drag.axis: Drag.XAxis + drag.target: delegate + onReleased: { + if (drag.active) { + if (delegate.x > delegate.width / 3 || delegate.x < width / -3) { + removeAnim.running = true; + } else { + resetAnim.running = true; + } + } + } + + RowLayout { + width: parent.width + //FIXME: ad hoc icons + PlasmaCore.IconItem { + width: units.iconSizes.medium + height: width + source: { + switch (model.callType) { + case 0: + return "list-remove"; + case 1: + return "go-down"; + case 2: + return "go-up"; + } + } + } + ColumnLayout { + PlasmaComponents.Label { + text: "Name (todo)" + } + PlasmaComponents.Label { + text: i18n("Number: %1", model.number) + Layout.fillWidth: true + } + } + ColumnLayout { + PlasmaComponents.Label { + Layout.alignment: Qt.AlignRight + text: Qt.formatTime(model.date+" "+model.time, Qt.locale().timeFormat(Locale.ShortFormat)); + } + PlasmaComponents.Label { + Layout.alignment: Qt.AlignRight + text: i18n("Duration: %1", secondsToTimeString(model.duration)); + } + } + } + } + } +} diff --git a/dialer/package/contents/ui/main.qml b/dialer/package/contents/ui/main.qml index 7cd2b453..94f5288b 100644 --- a/dialer/package/contents/ui/main.qml +++ b/dialer/package/contents/ui/main.qml @@ -115,6 +115,23 @@ ApplicationWindow { ) } + function removeCallFromHistory(id) { + var item = historyModel.get(id); + + if (!item) { + return; + } + + var db = LocalStorage.openDatabaseSync("PlasmaPhoneDialer", "1.0", "Call history of the Plasma Phone dialer", 1000000); + + db.transaction( + function(tx) { + tx.executeSql("DELETE from History WHERE id=?", [id]); + } + ) + + historyModel.remove(id); + } //END FUNCTIONS //BEGIN DATABASE @@ -223,7 +240,6 @@ ApplicationWindow { } } - SystemPalette {id: syspal} //END MODELS //BEGIN UI