Timeline.qml 3.91 KB
Newer Older
1 2 3
import QtQuick 2.7
import QtQuick.Layouts 1.3

4
import Common 1.0
5
import Linphone 1.0
6
import Linphone.Styles 1.0
7 8

import 'Timeline.js' as Logic
9

10
// =============================================================================
Ronan's avatar
Ronan committed
11

12
Rectangle {
Ronan's avatar
Ronan committed
13 14
  id: timeline

15 16
  // ---------------------------------------------------------------------------

17
  property alias model: view.model
18 19
  property string _selectedSipAddress

20 21
  property var _newInsertedItem

22 23
  // ---------------------------------------------------------------------------

24
  signal entrySelected (var entry)
Ronan's avatar
Ronan committed
25

26
  // ---------------------------------------------------------------------------
27

Ronan's avatar
Ronan committed
28
  function setSelectedEntry (sipAddress) {
29
    Logic.setSelectedEntry(sipAddress)
Ronan's avatar
Ronan committed
30 31 32
  }

  function resetSelectedEntry () {
33
    Logic.resetSelectedEntry()
34 35
  }

36
  // ---------------------------------------------------------------------------
37

38
  color: TimelineStyle.color
Ronan's avatar
Ronan committed
39

40 41 42
  ColumnLayout {
    anchors.fill: parent
    spacing: 0
Ronan's avatar
Ronan committed
43

44
    // -------------------------------------------------------------------------
45

46 47
    Connections {
      target: model
48

49 50 51
      onDataChanged: Logic.handleDataChanged(topLeft, bottomRight, roles)
      onRowsAboutToBeRemoved: Logic.handleRowsAboutToBeRemoved(parent, first, last)
    }
52

53 54 55
    // -------------------------------------------------------------------------
    // Legend.
    // -------------------------------------------------------------------------
Ronan's avatar
Ronan committed
56

57 58 59 60
    Rectangle {
      Layout.fillWidth: true
      Layout.preferredHeight: TimelineStyle.legend.height
      color: TimelineStyle.legend.backgroundColor
Ronan's avatar
Ronan committed
61

62 63 64 65 66 67 68
      Row {
        anchors {
          fill: parent
          leftMargin: TimelineStyle.legend.leftMargin
          rightMargin: TimelineStyle.legend.rightMargin
        }
        spacing: TimelineStyle.legend.spacing
Ronan's avatar
Ronan committed
69

70 71
        Icon {
          anchors.verticalCenter: parent.verticalCenter
Ronan's avatar
Ronan committed
72
          icon: 'timeline_history'
73 74
          iconSize: TimelineStyle.legend.iconSize
        }
Ronan's avatar
Ronan committed
75

76 77 78 79 80 81 82
        Text {
          color: TimelineStyle.legend.color
          font.pointSize: TimelineStyle.legend.pointSize
          height: parent.height
          text: qsTr('timelineTitle')
          verticalAlignment: Text.AlignVCenter
        }
Ronan's avatar
Ronan committed
83 84
      }
    }
Ronan's avatar
Ronan committed
85

86 87 88 89 90 91 92 93 94 95
    // -------------------------------------------------------------------------
    // History.
    // -------------------------------------------------------------------------

    ScrollableListView {
      id: view

      Layout.fillHeight: true
      Layout.fillWidth: true
      currentIndex: -1
Ronan's avatar
Ronan committed
96

97 98 99 100 101
      delegate: Item {
        height: TimelineStyle.contact.height
        width: parent ? parent.width : 0

        Contact {
102 103
          readonly property bool isSelected: view.currentIndex === index

104
          anchors.fill: parent
105
          color: isSelected
106 107 108 109 110
            ? TimelineStyle.contact.backgroundColor.selected
            : (
              index % 2 == 0
                ? TimelineStyle.contact.backgroundColor.a
                : TimelineStyle.contact.backgroundColor.b
111
            )
112 113 114 115 116 117 118 119
          displayUnreadMessagesCount: SettingsModel.chatEnabled
          entry: $timelineEntry
          sipAddressColor: isSelected
            ? TimelineStyle.contact.sipAddress.color.selected
            : TimelineStyle.contact.sipAddress.color.normal
          usernameColor: isSelected
            ? TimelineStyle.contact.username.color.selected
            : TimelineStyle.contact.username.color.normal
120 121 122 123 124 125 126 127 128

          Loader {
            anchors.fill: parent
            sourceComponent: TooltipArea {
              text: $timelineEntry.timestamp.toLocaleString(
                Qt.locale(App.locale),
                Locale.ShortFormat
              )
            }
129
          }
130
        }
Ronan's avatar
Ronan committed
131

132 133 134 135 136 137
        MouseArea {
          anchors.fill: parent
          onClicked: {
            view.currentIndex = index
            timeline.entrySelected($timelineEntry.sipAddress)
          }
138
        }
Ronan's avatar
Ronan committed
139
      }
140

141 142
      onCountChanged: Logic.handleCountChanged(count)
    }
Ronan's avatar
Ronan committed
143
  }
144
}