Changeset View
Standalone View
src/controls/TextField.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Carl-Lucien Schwan <carl@carlschwan.eu> * | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library/Lesser General Public License | ||||
6 | * version 2, or (at your option) any later version, as published by the | ||||
7 | * Free Software Foundation | ||||
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/Lesser 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 2.5 | ||||
21 | import QtQuick.Controls 2.1 | ||||
mart: always namespace the controls import as
import QtQuick.Controls 2.1 as Controls | |||||
22 | import org.kde.kirigami 2.4 as Kirigami | ||||
23 | | ||||
24 | /** | ||||
25 | * This is advanced textfield. It is recommanded to us this class when there | ||||
26 | * is a need to create a create a textfield with actions (e.g a clear action). | ||||
27 | * | ||||
28 | * Example usage for a search field: | ||||
29 | * @code | ||||
30 | * import org.kde.kirigami 2.??? as Kirigami | ||||
31 | * | ||||
32 | * Kirigami.TextField { | ||||
33 | * id: searchField | ||||
34 | * | ||||
35 | * placeholderText: i18n("Search...") | ||||
36 | * | ||||
37 | * focusSequences: "Ctrl+F" | ||||
38 | * | ||||
39 | * rightAction: Kirigami.Action { | ||||
40 | * iconName: "edit-clear" | ||||
41 | * visible: searchField.text != "" | ||||
42 | * onTriggered: { | ||||
43 | * searchField.text = "" | ||||
44 | * searchField.accepted() | ||||
45 | * } | ||||
46 | * } | ||||
47 | * | ||||
48 | * onAccepted: console.log("Search text is " + searchField.text) | ||||
49 | * } | ||||
50 | */ | ||||
51 | TextField | ||||
52 | { | ||||
53 | id: root | ||||
54 | | ||||
55 | /** | ||||
56 | * focusSequence: keysequence | ||||
57 | * This property hold the a list of shortcut sequence that put the text | ||||
58 | * field into focus. | ||||
59 | */ | ||||
60 | property string focusSequence | ||||
61 | | ||||
62 | /** | ||||
63 | * leftAction: QtObject | ||||
64 | * This propery hold the action that is left in the field. By default this | ||||
65 | * field is null. | ||||
66 | */ | ||||
67 | property QtObject leftAction | ||||
68 | | ||||
69 | /** | ||||
70 | * rightAction: QtObject | ||||
71 | * This propery hold the action that is right in the field. By default this | ||||
72 | * field is null. | ||||
73 | */ | ||||
74 | property QtObject rightAction | ||||
mart: I would like those to actually be lists as we do have use cases for more than one icon… | |||||
75 | | ||||
76 | Shortcut { | ||||
77 | id: focusShortcut | ||||
78 | enabled: root.focusSequence != null | ||||
79 | sequence: root.focusSequence | ||||
80 | onActivated: { | ||||
81 | root.forceActiveFocus() | ||||
82 | root.selectAll() | ||||
83 | } | ||||
84 | } | ||||
85 | | ||||
86 | hoverEnabled: true | ||||
87 | | ||||
88 | ToolTip { | ||||
89 | delay: Kirigami.Units.longDuration | ||||
the style already sets the correct values for duration and timeout, this line should be removed mart: the style already sets the correct values for duration and timeout, this line should be removed | |||||
90 | visible: root.focusSequence != null && root.focusSequence.hovered | ||||
91 | text: root.focusSequence != null ? root.focusSequence.nativeText : "" | ||||
92 | } | ||||
93 | | ||||
94 | ToolButton { | ||||
this should be a repeater with the toolbutton as aproperty (maybe shouldn't even be a toolbotton, as usually they're just icons without any button graphics) mart: this should be a repeater with the toolbutton as aproperty (maybe shouldn't even be a… | |||||
95 | anchors { | ||||
96 | top: parent.top | ||||
97 | left: parent.left | ||||
98 | bottom: parent.bottom | ||||
99 | margins: Kirigami.Units.smallSpacing | ||||
100 | } | ||||
101 | icon.name: root.leftAction != null ? root.rightAction.iconName : "" | ||||
@mart I'm not sure if it's the right way to convert the icon from the action to the one needed by the toolButton (don't support icon.source) ognarb: @mart I'm not sure if it's the right way to convert the icon from the action to the one needed… | |||||
you can try to use a private class. mart: you can try to use a private class.
PrivateActionToolButton {
kirigamiAction: the action… | |||||
102 | visible: root.leftAction != null && root.leftAction.visible | ||||
103 | onClicked: root.leftAction.trigger() | ||||
104 | } | ||||
105 | | ||||
106 | ToolButton { | ||||
text will go under both buttons, in order to avoid that, probably anchors should be added to the TextField's contentItem to make space for the buttons. mart: text will go under both buttons, in order to avoid that, probably anchors should be added to… | |||||
err, TextField is not a Control, right. so, it should set leftPadding and rightPadding to the space of the buttons mart: err, TextField is not a Control, right.
so, it should set leftPadding and rightPadding to the… | |||||
107 | anchors { | ||||
108 | top: parent.top | ||||
109 | right: parent.right | ||||
110 | bottom: parent.bottom | ||||
111 | margins: Kirigami.Units.smallSpacing | ||||
112 | } | ||||
113 | icon.name: root.rightAction != null ? root.rightAction.iconName : "" | ||||
114 | visible: root.rightAction != null && root.rightAction.visible | ||||
115 | onClicked: root.rightAction.trigger() | ||||
116 | } | ||||
117 | } |
always namespace the controls import as
import QtQuick.Controls 2.1 as Controls