diff --git a/examples/simpleexamples/Sidebar.qml b/examples/simpleexamples/Sidebar.qml
--- a/examples/simpleexamples/Sidebar.qml
+++ b/examples/simpleexamples/Sidebar.qml
@@ -20,7 +20,7 @@
import QtQuick 2.1
import QtQuick.Controls 2.3 as Controls
import QtQuick.Layouts 1.2
-import org.kde.kirigami 2.5 as Kirigami
+import org.kde.kirigami 2.7 as Kirigami
Kirigami.ApplicationWindow {
id: root
@@ -118,8 +118,50 @@
Item {
Layout.fillWidth: true
}
- Controls.TextField {
-
+ Kirigami.ActionTextField {
+ id: searchField
+
+ placeholderText: "Search..."
+
+ focusSequence: "Ctrl+F"
+ leftActions: [
+ Kirigami.Action {
+ iconName: "edit-clear"
+ visible: searchField.text != ""
+ onTriggered: {
+ searchField.text = ""
+ searchField.accepted()
+ }
+ },
+ Kirigami.Action {
+ iconName: "edit-clear"
+ visible: searchField.text != ""
+ onTriggered: {
+ searchField.text = ""
+ searchField.accepted()
+ }
+ }
+ ]
+ rightActions: [
+ Kirigami.Action {
+ iconName: "edit-clear"
+ visible: searchField.text != ""
+ onTriggered: {
+ searchField.text = ""
+ searchField.accepted()
+ }
+ },
+ Kirigami.Action {
+ iconName: "anchor"
+ visible: searchField.text != ""
+ onTriggered: {
+ searchField.text = ""
+ searchField.accepted()
+ }
+ }
+ ]
+
+ onAccepted: console.log("Search text is " + searchField.text)
}
}
}
diff --git a/kirigami.qrc b/kirigami.qrc
--- a/kirigami.qrc
+++ b/kirigami.qrc
@@ -17,6 +17,7 @@
src/controls/templates/InlineMessage.qml
src/controls/InlineMessage.qml
src/controls/ToolBarApplicationHeader.qml
+ src/controls/ActionTextField.qml
src/controls/private/PrivateActionToolButton.qml
src/controls/private/GlobalDrawerActionItem.qml
src/controls/private/ContextDrawerActionItem.qml
diff --git a/kirigami.qrc.in b/kirigami.qrc.in
--- a/kirigami.qrc.in
+++ b/kirigami.qrc.in
@@ -17,6 +17,7 @@
@kirigami_QML_DIR@/src/controls/templates/InlineMessage.qml
@kirigami_QML_DIR@/src/controls/InlineMessage.qml
@kirigami_QML_DIR@/src/controls/ToolBarApplicationHeader.qml
+ @kirigami_QML_DIR@/src/controls/ActionTextField.qml
@kirigami_QML_DIR@/src/controls/private/PrivateActionToolButton.qml
@kirigami_QML_DIR@/src/controls/private/GlobalDrawerActionItem.qml
@kirigami_QML_DIR@/src/controls/private/ContextDrawerActionItem.qml
diff --git a/src/controls/ActionTextField.qml b/src/controls/ActionTextField.qml
new file mode 100644
--- /dev/null
+++ b/src/controls/ActionTextField.qml
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2019 Carl-Lucien Schwan *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library/Lesser General Public License
+ * version 2, or (at your option) any later version, as published by the
+ * Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details
+ *
+ * You should have received a copy of the GNU Library/Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1 as Controls
+import org.kde.kirigami 2.7 as Kirigami
+
+/**
+ * This is advanced textfield. It is recommanded to us this class when there
+ * is a need to create a create a textfield with action boutons(e.g a clear
+ * action).
+ *
+ * Example usage for a search field:
+ * @code
+ * import org.kde.kirigami 2.7 as Kirigami
+ *
+ * Kirigami.ActionTextField {
+ * id: searchField
+ *
+ * placeholderText: i18n("Search...")
+ *
+ * focusSequence: "Ctrl+F"
+ *
+ * rightActions: [
+ * Kirigami.Action {
+ * iconName: "edit-clear"
+ * visible: searchField.text != ""
+ * onTriggered: {
+ * searchField.text = ""
+ * searchField.accepted()
+ * }
+ * }
+ * ]
+ *
+ * onAccepted: console.log("Search text is " + searchField.text)
+ * }
+ */
+Controls.TextField
+{
+ id: root
+
+ /**
+ * focusSequence: keysequence
+ * This property hold the a list of shortcut sequence that put the text
+ * field into focus.
+ */
+ property string focusSequence: null
+
+ /**
+ * leftActions: list
+ * This propery hold the action that is left in the field. By default this
+ * field is null.
+ */
+ property list leftActions
+
+ /**
+ * rightActions: list
+ * This propery hold the action that is right in the field. By default this
+ * field is null.
+ */
+ property list rightActions
+
+ hoverEnabled: true
+
+ leftPadding: leftActionsRow.width
+ rightPadding: rightActionsRow.width
+
+ Shortcut {
+ id: focusShortcut
+ enabled: root.focusSequence != null
+ sequence: root.focusSequence
+ onActivated: {
+ root.forceActiveFocus()
+ root.selectAll()
+ }
+ }
+
+ Controls.ToolTip {
+ visible: root.focusSequence != null && root.hovered && !rightActionsRow.hovered && !leftActionsRow.hovered
+ text: root.focusSequence ? root.focusSequence : ""
+ }
+
+ Row {
+ id: leftActionsRow
+ padding: Kirigami.Units.smallSpacing
+ Repeater {
+ model: root.leftActions
+ Kirigami.Icon {
+ height: root.implicitHeight - 2 * Kirigami.Units.smallSpacing
+ width: this.implicitHeight - 2 * Kirigami.Units.smallSpacing
+ source: modelData.icon.name.length > 0 ? modelData.icon.name : modelData.icon.source
+ visible: modelData.visible
+ MouseArea {
+ anchors.fill: parent
+ onClicked: modelData.trigger()
+ cursorShape: Qt.PointingHandCursor
+ }
+ }
+ }
+ }
+
+ Row {
+ id: rightActionsRow
+ padding: Kirigami.Units.smallSpacing
+ layoutDirection: Qt.RightToLeft
+ anchors.right: parent.right
+ Repeater {
+ model: root.rightActions
+ Kirigami.Icon {
+ height: root.implicitHeight - 2 * Kirigami.Units.smallSpacing
+ width: this.implicitHeight - 2 * Kirigami.Units.smallSpacing
+ source: modelData.icon.name.length > 0 ? modelData.icon.name : modelData.icon.source
+ visible: modelData.visible
+ MouseArea {
+ anchors.fill: parent
+ onClicked: modelData.trigger()
+ cursorShape: Qt.PointingHandCursor
+ }
+ }
+ }
+ }
+}
diff --git a/src/kirigamiplugin.cpp b/src/kirigamiplugin.cpp
--- a/src/kirigamiplugin.cpp
+++ b/src/kirigamiplugin.cpp
@@ -177,6 +177,9 @@
qmlRegisterType(componentUrl(QStringLiteral("LinkButton.qml")), uri, 2, 6, "LinkButton");
qmlRegisterType(componentUrl(QStringLiteral("UrlButton.qml")), uri, 2, 6, "UrlButton");
+ //2.7
+ qmlRegisterType(componentUrl(QStringLiteral("ActionTextField.qml")), uri, 2, 7, "ActionTextField");
+
qmlProtectModule(uri, 2);
}
diff --git a/src/qmldir b/src/qmldir
--- a/src/qmldir
+++ b/src/qmldir
@@ -46,3 +46,4 @@
AboutPage 2.6 AboutPage.qml
UrlButton 2.6 UrlButton.qml
LinkButton 2.6 LinkButton.qml
+ActionTextField 2.7 ActionTextField.qml