• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaComponents

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • plasmacomponents
  • qml
SelectionDialog.qml
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Marco Martin <mart@kde.org>
4 **
5 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 ** All rights reserved.
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** This file is part of the Qt Components project.
10 **
11 ** $QT_BEGIN_LICENSE:BSD$
12 ** You may use this file under the terms of the BSD license as follows:
13 **
14 ** "Redistribution and use in source and binary forms, with or without
15 ** modification, are permitted provided that the following conditions are
16 ** met:
17 ** * Redistributions of source code must retain the above copyright
18 ** notice, this list of conditions and the following disclaimer.
19 ** * Redistributions in binary form must reproduce the above copyright
20 ** notice, this list of conditions and the following disclaimer in
21 ** the documentation and/or other materials provided with the
22 ** distribution.
23 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
24 ** the names of its contributors may be used to endorse or promote
25 ** products derived from this software without specific prior written
26 ** permission.
27 **
28 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42 
43 import QtQuick 1.1
44 import org.kde.plasma.core 0.1 as PlasmaCore
45 
46 import "." 0.1
47 
55 CommonDialog {
56  id: root
57 
58  // Common API
64  property alias model: listView.model
65 
71  property int selectedIndex: -1
72 
76  property Component delegate: defaultDelegate
77 
78  Component {
79  id: defaultDelegate
80 
81  Label {
82  visible: modelData.search(RegExp(filterField.filterText, "i")) != -1
83  height: visible? paintedHeight*2 : 0
84  text: modelData
85  MouseArea {
86  anchors.fill: parent
87  onClicked: {
88  selectedIndex = index
89  root.accept()
90  }
91  }
92 
93  Keys.onPressed: {
94  if (event.key == Qt.Key_Up || event.key == Qt.Key_Down)
95  scrollBar.flash()
96  }
97  }
98  }
99 
100  content: Item {
101  id: contentItem
102  property alias filterText: filterField.filterText
103  implicitWidth: theme.defaultFont.mSize.width * 40
104  implicitHeight: theme.defaultFont.mSize.height * 12
105  height: implicitHeight
106 
107  TextField {
108  id: filterField
109  property string filterText
110  onTextChanged: searchTimer.restart()
111  clearButtonShown: true
112  anchors {
113  top: parent.top
114  left: parent.left
115  right: parent.right
116  }
117  Timer {
118  id: searchTimer
119  running: false
120  repeat: false
121  interval: 500
122  onTriggered: filterField.filterText = filterField.text
123  }
124  }
125  ListView {
126  id: listView
127 
128  anchors {
129  top: filterField.bottom
130  left: parent.left
131  right: parent.right
132  bottom: parent.bottom
133  }
134  currentIndex : -1
135  delegate: root.delegate
136  clip: true
137 
138  Keys.onPressed: {
139  if (event.key == Qt.Key_Up || event.key == Qt.Key_Down
140  || event.key == Qt.Key_Left || event.key == Qt.Key_Right
141  || event.key == Qt.Key_Select || event.key == Qt.Key_Enter
142  || event.key == Qt.Key_Return) {
143  listView.currentIndex = 0
144  event.accepted = true
145  }
146  }
147  }
148 
149  ScrollBar {
150  id: scrollBar
151  flickableItem: listView
152  visible: listView.contentHeight > contentItem.height
153  //platformInverted: root.platformInverted
154  anchors { top: contentItem.top; right: contentItem.right }
155  }
156  }
157 
158  onClickedOutside: {
159  reject()
160  }
161 
162  Timer {
163  id: focusTimer
164  interval: 100
165  onTriggered: {
166  filterField.forceActiveFocus()
167  }
168  }
169  onStatusChanged: {
170  //FIXME: why needs focus deactivation then activation?
171  if (status == DialogStatus.Open) {
172  filterField.focus = false
173  focusTimer.running = true
174  }
175 
176  if (status == DialogStatus.Opening) {
177  if (listView.currentItem != null) {
178  listView.currentItem.focus = false
179  }
180  listView.currentIndex = -1
181  listView.positionViewAtIndex(0, ListView.Beginning)
182  } else if (status == DialogStatus.Open) {
183  listView.focus = true
184  }
185  }
186 }
ScrollBar
A simple Scroll Bar using the plasma theme.
Definition: ScrollBar.qml:34
DialogStatus::Opening
Definition: enums.h:34
DialogStatus::Open
Definition: enums.h:35
Label
This is a label which uses the plasma theme.
Definition: Label.qml:32
Item
DialogStatus
Definition: enums.h:27
TextField
A plasma theme based text field widget.
Definition: TextField.qml:25
TextField::text
string text
The text in the text field.
Definition: TextField.qml:149
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaComponents

Skip menu "PlasmaComponents"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal