• 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
TextField.qml
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2011 by Daker Fernandes Pinheiro <dakerfp@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 import QtQuick 1.1
21 import org.kde.plasma.core 0.1 as PlasmaCore
22 import "private" as Private
23 
27 FocusScope {
28  id: textField
29 
30  // Common API
38  property bool errorHighlight: false // TODO
39 
47  property string placeholderText
48 
55  property alias inputMethodHints: textInput.inputMethodHints
56 
63  property alias font: textInput.font
64 
69  property alias cursorPosition: textInput.cursorPosition
70 
77  property alias readOnly: textInput.readOnly
78 
93  property alias echoMode: textInput.echoMode
94 
95 
96  property alias passwordCharacter: textInput.passwordCharacter
97  property alias acceptableInput: textInput.acceptableInput // read-only
98 
108  property alias inputMask: textInput.inputMask
109 
132  property alias validator: textInput.validator
133 
140  property alias selectedText: textInput.selectedText
141 
148  property alias selectionEnd: textInput.selectionEnd
149 
156  property alias selectionStart: textInput.selectionStart
157 
162  property alias text: textInput.text
163 
172  property alias maximumLength: textInput.maximumLength
173 
177  signal accepted()
178 
179  //Plasma api
183  property bool clearButtonShown: false
184 
188  function copy() {
189  textInput.copy();
190  }
191 
196  function paste() {
197  textInput.paste();
198  }
199 
203  function cut() {
204  textInput.cut();
205  }
206 
218  function select(start, end) {
219  textInput.select(start, end);
220  }
221 
225  function selectAll() {
226  textInput.selectAll();
227  }
228 
232  function selectWord() {
233  textInput.selectWord();
234  }
235 
249  function positionAt(pos) {
250  return textInput.positionAt(pos);
251  }
252 
262  function positionToRectangle(pos) {
263  return textInput.positionToRectangle(pos);
264  }
265 
266  // Set active focus to it's internal textInput.
267  // Overriding QtQuick.Item forceActiveFocus function.
268  function forceActiveFocus() {
269  textInput.forceActiveFocus();
270  }
271 
272  // Overriding QtQuick.Item activeFocus property.
273  property alias activeFocus: textInput.activeFocus
274 
275  // TODO: fix default size
276  implicitWidth: theme.defaultFont.mSize.width*12 + base.internalPadding*2
277  implicitHeight: theme.defaultFont.mSize.height + base.internalPadding*2
278  // TODO: needs to define if there will be specific graphics for
279  // disabled text fields
280  opacity: enabled ? 1.0 : 0.5
281 
282  Private.TextFieldFocus {
283  id: hover
284  state: textInput.activeFocus ? "focus" : (mouseWatcher.containsMouse ? "hover" : "hidden")
285  anchors.fill: base
286  }
287 
288  PlasmaCore.FrameSvgItem {
289  id: base
290 
291  // TODO: see what is the correct policy for margins
292  anchors.fill: parent
293  imagePath: "widgets/lineedit"
294  prefix: "base"
295  property real internalPadding: theme.defaultFont.mSize.height*0.3
296  }
297 
298  MouseArea {
299  id: mouseWatcher
300  anchors.fill: hover
301  hoverEnabled: true
302  onClicked: {
303  // If we don't set focus on click here then clicking between the
304  // line of text and the bottom or top of the widget will not focus
305  // it.
306  textInput.forceActiveFocus();
307  }
308  }
309 
310  Text {
311  anchors {
312  left: parent.left
313  right: parent.right
314  verticalCenter: parent.verticalCenter
315  leftMargin: base.margins.left + base.internalPadding
316  rightMargin: base.margins.right + base.internalPadding
317  }
318  text: placeholderText
319  visible: textInput.text == ""
320  // XXX: using textColor and low opacity for theming placeholderText
321  color: theme.buttonTextColor
322  opacity: 0.5
323  elide: Text.ElideRight
324  clip: true
325  font.capitalization: theme.defaultFont.capitalization
326  font.family: theme.defaultFont.family
327  font.italic: theme.defaultFont.italic
328  font.letterSpacing: theme.defaultFont.letterSpacing
329  font.pointSize: theme.defaultFont.pointSize
330  font.strikeout: theme.defaultFont.strikeout
331  font.underline: theme.defaultFont.underline
332  font.weight: theme.defaultFont.weight
333  font.wordSpacing: theme.defaultFont.wordSpacing
334  }
335 
336  TextInput {
337  id: textInput
338 
339  anchors {
340  left: parent.left
341  right: parent.right
342  verticalCenter: parent.verticalCenter
343  // TODO: see what is the correct policy for margins
344  leftMargin: base.margins.left + base.internalPadding
345  rightMargin: base.margins.right + (clearButton.opacity > 0 ? clearButton.width : 0) + base.internalPadding
346  }
347  passwordCharacter: "•"
348  selectByMouse: true
349  color: theme.buttonTextColor
350  enabled: textField.enabled
351  clip: true
352  focus: true
353  onActiveFocusChanged: {
354  if (!textField.activeFocus) {
355  textInput.closeSoftwareInputPanel()
356  }
357  }
358  onAccepted: textField.accepted()
359  Keys.forwardTo: textField
360  }
361 
362  PlasmaCore.IconItem {
363  id: clearButton
364  source: "edit-clear-locationbar-rtl"
365  height: Math.max(textInput.height, theme.smallIconSize)
366  width: height
367  opacity: (textInput.text != "" && clearButtonShown) ? 1 : 0
368  Behavior on opacity {
369  NumberAnimation {
370  duration: 250
371  easing.type: Easing.InOutQuad
372  }
373  }
374  anchors {
375  right: parent.right
376  rightMargin: y
377  verticalCenter: textInput.verticalCenter
378  }
379  MouseArea {
380  anchors.fill: parent
381  onClicked: {
382  textInput.text = ""
383  textInput.forceActiveFocus()
384  }
385  }
386  }
387 }
FocusScope
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