capability to remove items

better history delegate
This commit is contained in:
Marco Martin 2015-04-27 11:01:18 +02:00
parent c58e932db2
commit fb4765d50a
3 changed files with 147 additions and 39 deletions

View file

@ -17,14 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import QtQuick 2.0 import QtQuick 2.4
import QtQuick.Layouts 1.1 import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.extras 2.0 as PlasmaExtras
Rectangle { Item {
color: syspal.base
function secondsToTimeString(seconds) { function secondsToTimeString(seconds) {
seconds = Math.floor(seconds/1000) seconds = Math.floor(seconds/1000)
@ -50,46 +49,17 @@ Rectangle {
section { section {
property: "date" property: "date"
labelPositioning: ViewSection.CurrentLabelAtStart labelPositioning: ViewSection.CurrentLabelAtStart
delegate: Rectangle { delegate: PlasmaComponents.ListItem {
width: view.width //width: view.width
height: childrenRect.height //height: childrenRect.height
color: syspal.base //color: syspal.base
sectionDelegate: true
PlasmaComponents.Label { PlasmaComponents.Label {
text: Qt.formatDate(section, Qt.locale().dateFormat(Locale.LongFormat)); text: Qt.formatDate(section, Qt.locale().dateFormat(Locale.LongFormat));
} }
} }
} }
delegate: MouseArea { delegate: HistoryDelegate {}
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));
}
}
}
} }
} }
} }

View file

@ -0,0 +1,122 @@
/*
* Copyright 2015 Marco Martin <mart@kde.org>
*
* 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));
}
}
}
}
}
}

View file

@ -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 //END FUNCTIONS
//BEGIN DATABASE //BEGIN DATABASE
@ -223,7 +240,6 @@ ApplicationWindow {
} }
} }
SystemPalette {id: syspal}
//END MODELS //END MODELS
//BEGIN UI //BEGIN UI