• 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
TextArea.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 Item {
28  id: textArea
29 
30  // Common API
37  property alias font: textEdit.font
38 
44  property int inputMethodHints
45 
53  property bool errorHighlight
54 
59  property alias cursorPosition: textEdit.cursorPosition
60 
77  property alias horizontalAlignment: textEdit.horizontalAlignment
78 
90  property alias verticalAlignment: textEdit.verticalAlignment
91 
99  property alias readOnly: textEdit.readOnly
100 
108  property alias selectedText: textEdit.selectedText
109 
116  property alias selectionEnd: textEdit.selectionEnd
117 
124  property alias selectionStart: textEdit.selectionStart
125 
126 
131  property alias text: textEdit.text
132 
149  property alias textFormat: textEdit.textFormat
150 
171  property alias wrapMode: textEdit.wrapMode
172 
178  property string placeholderText
179 
180  // functions
184  function copy() {
185  textEdit.copy();
186  }
191  function paste() {
192  textEdit.paste();
193  }
194 
198  function cut() {
199  textEdit.cut();
200  }
201 
213  function select(start, end) {
214  textEdit.select(start, end);
215  }
216 
220  function selectAll() {
221  textEdit.selectAll();
222  }
223 
227  function selectWord() {
228  textEdit.selectWord();
229  }
230 
244  // Does this work at all? doc for TextEdit says positionAt() accepts two
245  // ints: x and y
246  function positionAt(pos) {
247  return textEdit.positionAt(pos);
248  }
249 
259  function positionToRectangle(pos) {
260  return textEdit.positionToRectangle(pos);
261  }
262 
263  // Plasma API
271  property alias interactive: flickArea.interactive
272 
277  property alias contentMaxWidth: textEdit.width
278 
283  property alias contentMaxHeight: textEdit.height
284 
285  // Set active focus to it's internal textInput.
286  // Overriding QtQuick.Item forceActiveFocus function.
287  function forceActiveFocus() {
288  textEdit.forceActiveFocus();
289  }
290 
291  // Overriding QtQuick.Item activeFocus property.
292  property alias activeFocus: textEdit.activeFocus
293 
294  opacity: enabled ? 1.0 : 0.5
295 
296  Private.TextFieldFocus {
297  id: hover
298  state: textArea.activeFocus ? "focus" : (mouseWatcher.containsMouse ? "hover" : "hidden")
299  anchors.fill: base
300  }
301 
302  MouseArea {
303  id: mouseWatcher
304  anchors.fill: hover
305  hoverEnabled: true
306  }
307 
308  PlasmaCore.FrameSvgItem {
309  id: base
310 
311  // TODO: see what is the best policy for margins
312  anchors {
313  fill: parent
314  }
315  imagePath: "widgets/lineedit"
316  prefix: "base"
317  }
318 
319  Flickable {
320  id: flickArea
321  anchors {
322  fill: parent
323  leftMargin: 2 * base.margins.left
324  rightMargin: 2 * base.margins.right + (verticalScroll.visible ? verticalScroll.width : 0)
325  topMargin: 2 * base.margins.top
326  bottomMargin: 2 * base.margins.bottom + (horizontalScroll.visible ? verticalScroll.width : 0)
327  }
328  interactive: !verticalScroll.interactive //textArea.activeFocus
329  contentWidth: {
330  if (textEdit.wrapMode == TextEdit.NoWrap)
331  return textEdit.paintedWidth;
332 
333  return Math.min(textEdit.paintedWidth, textEdit.width);
334  }
335  contentHeight: Math.min(textEdit.paintedHeight, textEdit.height)
336  clip: true
337 
338  TextEdit {
339  id: textEdit
340 
341  width: flickArea.width
342  height: flickArea.height
343  clip: true
344  wrapMode: TextEdit.Wrap
345  enabled: textArea.enabled
346  font.capitalization: theme.defaultFont.capitalization
347  font.family: theme.defaultFont.family
348  font.italic: theme.defaultFont.italic
349  font.letterSpacing: theme.defaultFont.letterSpacing
350  font.pointSize: theme.defaultFont.pointSize
351  font.strikeout: theme.defaultFont.strikeout
352  font.underline: theme.defaultFont.underline
353  font.weight: theme.defaultFont.weight
354  font.wordSpacing: theme.defaultFont.wordSpacing
355  color: theme.buttonTextColor
356  selectByMouse: verticalScroll.interactive
357 
358  onCursorPositionChanged: {
359  if (cursorRectangle.x < flickArea.contentX) {
360  flickArea.contentX = cursorRectangle.x;
361  return;
362  }
363 
364  if (cursorRectangle.x > flickArea.contentX +
365  flickArea.width - cursorRectangle.width) {
366  flickArea.contentX = cursorRectangle.x -
367  cursorRectangle.width;
368  return;
369  }
370 
371  if (cursorRectangle.y < flickArea.contentY) {
372  flickArea.contentY = cursorRectangle.y;
373  return;
374  }
375 
376  if (cursorRectangle.y > flickArea.contentY +
377  flickArea.height - cursorRectangle.height) {
378  flickArea.contentY = cursorRectangle.y -
379  cursorRectangle.height;
380  return;
381  }
382  }
383 
384  // Proxying keys events is not required by the
385  // common API but is desired in the plasma API.
386  Keys.onPressed: textArea.Keys.pressed(event);
387  Keys.onReleased: textArea.Keys.released(event);
388 
389  Text {
390  anchors.fill: parent
391  text: textArea.placeholderText
392  visible: textEdit.text == "" && !textArea.activeFocus
393  color: theme.buttonTextColor
394  opacity: 0.5
395  }
396  onActiveFocusChanged: {
397  if (!textEdit.activeFocus) {
398  textEdit.closeSoftwareInputPanel()
399  }
400  }
401  }
402  }
403 
404  ScrollBar {
405  id: horizontalScroll
406  anchors {
407  bottom: parent.bottom
408  left: parent.left
409  right: flickArea.right
410  }
411  enabled: parent.enabled
412  flickableItem: flickArea
413  orientation: Qt.Horizontal
414  stepSize: textEdit.font.pixelSize
415  }
416 
417  ScrollBar {
418  id: verticalScroll
419  anchors {
420  right: parent.right
421  top: parent.top
422  bottom: flickArea.bottom
423  }
424  enabled: parent.enabled
425  flickableItem: flickArea
426  orientation: Qt.Vertical
427  stepSize: textEdit.font.pixelSize
428  }
429 }
ScrollBar
A simple Scroll Bar using the plasma theme.
Definition: ScrollBar.qml:34
Item
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