summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2014-07-18 08:39:12 +0200
committerJ-P Nurmi <jpnurmi@digia.com>2014-07-18 17:37:55 +0200
commit8a13f087d3c0c7b9010b9861890b27a17889aeaa (patch)
treefab8ac15c7b59b2d2df18f985b8e4948c234ccc1
parent15d7ab65d1b8772a68258573141874d7f5cd2be5 (diff)
downloadqtquickcontrols-8a13f087d3c0c7b9010b9861890b27a17889aeaa.tar.gz
ComboBox: add support for selection handles
Task-number: QTBUG-38934 Change-Id: I0d7bfc821ff345e76d1ae89818f6a5e0120695f5 Reviewed-by: Liang Qi <liang.qi@digia.com>
-rw-r--r--src/controls/ComboBox.qml28
-rw-r--r--src/controls/Styles/Base/ComboBoxStyle.qml38
-rw-r--r--tests/manual/texthandles/main.qml27
3 files changed, 82 insertions, 11 deletions
diff --git a/src/controls/ComboBox.qml b/src/controls/ComboBox.qml
index 51694e73..768077a9 100644
--- a/src/controls/ComboBox.qml
+++ b/src/controls/ComboBox.qml
@@ -162,7 +162,7 @@ Control {
This property indicates whether the control is being hovered.
*/
- readonly property bool hovered: mouseArea.containsMouse || cursorArea.containsMouse
+ readonly property bool hovered: mouseArea.containsMouse || input.containsMouse
/*! \qmlproperty int ComboBox::count
\since QtQuick.Controls 1.1
@@ -238,6 +238,17 @@ Control {
readonly property alias acceptableInput: input.acceptableInput
/*!
+ \qmlproperty bool ComboBox::selectByMouse
+ \since QtQuick.Controls 1.3
+
+ This property determines if the user can select the text in
+ the editable text field with the mouse.
+
+ The default value is \c true.
+ */
+ property bool selectByMouse: true
+
+ /*!
\qmlproperty bool ComboBox::inputMethodComposing
\since QtQuick.Controls 1.3
@@ -370,7 +381,7 @@ Control {
}
}
- TextInput {
+ TextInputWithHandles {
id: input
visible: editable
@@ -378,6 +389,10 @@ Control {
focus: true
clip: contentWidth > width
+ control: comboBox
+ cursorHandle: __style ? __style.cursorHandle : undefined
+ selectionHandle: __style ? __style.selectionHandle : undefined
+
anchors.fill: parent
anchors.leftMargin: 8
anchors.rightMargin: __panel.dropDownButtonWidth + __style.padding.right
@@ -386,7 +401,6 @@ Control {
font: __panel && __panel.font !== undefined ? __panel.font : TextSingleton.font
renderType: __style ? __style.renderType : Text.NativeRendering
- selectByMouse: true
color: __panel ? __panel.textColor : "black"
selectionColor: __panel ? __panel.selectionColor : "blue"
selectedTextColor: __panel ? __panel.selectedTextColor : "white"
@@ -474,14 +488,6 @@ Control {
}
prevText = text
}
-
- MouseArea {
- id: cursorArea
- anchors.fill: parent
- hoverEnabled: true
- cursorShape: Qt.IBeamCursor
- acceptedButtons: Qt.NoButton
- }
}
Binding {
diff --git a/src/controls/Styles/Base/ComboBoxStyle.qml b/src/controls/Styles/Base/ComboBoxStyle.qml
index d2fd0549..f7236ba7 100644
--- a/src/controls/Styles/Base/ComboBoxStyle.qml
+++ b/src/controls/Styles/Base/ComboBoxStyle.qml
@@ -277,4 +277,42 @@ Style {
property Component __scrollerStyle: null
}
+
+ /*! The cursor handle.
+ \since QtQuick.Controls.Styles 1.3
+
+ The parent of the handle is positioned to the top left corner of
+ the cursor position. The interactive area is determined by the
+ geometry of the handle delegate.
+
+ The following signals and read-only properties are available within the scope
+ of the handle delegate:
+ \table
+ \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
+ \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
+ \row \li \b {styleData.position} : int \li The character position of the handle.
+ \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
+ \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
+ \endtable
+ */
+ property Component cursorHandle
+
+ /*! The selection handle.
+ \since QtQuick.Controls.Styles 1.3
+
+ The parent of the handle is positioned to the top left corner of
+ the first selected character. The interactive area is determined
+ by the geometry of the handle delegate.
+
+ The following signals and read-only properties are available within the scope
+ of the handle delegate:
+ \table
+ \row \li \b {styleData.activated()} [signal] \li Emitted when the handle is activated ie. the editor is clicked.
+ \row \li \b {styleData.pressed} : bool \li Whether the handle is pressed.
+ \row \li \b {styleData.position} : int \li The character position of the handle.
+ \row \li \b {styleData.lineHeight} : real \li The height of the line the handle is on.
+ \row \li \b {styleData.hasSelection} : bool \li Whether the editor has selected text.
+ \endtable
+ */
+ property Component selectionHandle
}
diff --git a/tests/manual/texthandles/main.qml b/tests/manual/texthandles/main.qml
index c9c21d9f..ab10b861 100644
--- a/tests/manual/texthandles/main.qml
+++ b/tests/manual/texthandles/main.qml
@@ -126,6 +126,33 @@ ApplicationWindow {
}
}
+ ComboBox {
+ id: combobox
+ z: 1
+ editable: true
+ currentIndex: 1
+ Layout.fillWidth: true
+ selectByMouse: selectBox.checked
+ model: ListModel {
+ id: combomodel
+ ListElement { text: "Apple" }
+ ListElement { text: "Banana" }
+ ListElement { text: "Coconut" }
+ ListElement { text: "Orange" }
+ }
+ onAccepted: {
+ if (find(currentText) === -1) {
+ combomodel.append({text: editText})
+ currentIndex = find(editText)
+ }
+ }
+
+ style: ComboBoxStyle {
+ cursorHandle: handleBox.checked ? cursorDelegate : null
+ selectionHandle: handleBox.checked ? selectionDelegate : null
+ }
+ }
+
TextArea {
id: edit
Layout.fillWidth: true