Commit 91c86152 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Complete refactor of the ComboList and its delegate's API

parent 4f8caa6e
Pipeline #990 passed with stage
in 7 seconds
......@@ -3,6 +3,8 @@
QQuickGroupItem::QQuickGroupItem (QQuickItem * parent)
: QQuickItem { parent }
, m_title { }
, m_icon { Q_NULLPTR }
{ }
QQuickGroupItem::~QQuickGroupItem (void) { }
......
......@@ -5,8 +5,8 @@ Item {
id: base;
width: implicitWidth;
height: implicitHeight;
implicitWidth: (dumbLayout.width + arrow.width + padding * 3);
implicitHeight: (dumbLayout.height / count + padding * 2);
implicitWidth: (stackControls.implicitWidth + arrow.width + base.padding * 3);
implicitHeight: (stackControls.implicitHeight + base.padding * 2);
property int padding : Style.spacingNormal;
property bool filterable : false;
......@@ -14,34 +14,28 @@ Item {
property alias backColor : rect.color;
property string placeholder : "";
property var model : undefined;
property Component delegate : ComboListDelegateForModelWithRoles { }
property int currentIdx : -1;
property var model : undefined;
property Component delegateForControl : ComboListDelegateForControl { }
property Component delegateForDropdown : ComboListDelegateForDropdown { }
readonly property int count : repeater.count;
readonly property var currentValue : ((currentIdx >= 0 && currentIdx < repeater.count)
? repeater.itemAt (currentIdx) ["value"]
: undefined);
readonly property var currentKey : ((currentIdx >= 0 && currentIdx < repeater.count)
? repeater.itemAt (currentIdx) ["key"]
: undefined);
property var value : undefined;
function selectByKey (key) {
var ret = false;
readonly property string text : {
var ret = "";
for (var idx = 0; idx < repeater.count; ++idx) {
var item = repeater.itemAt (idx);
if (item ["key"] === key) {
currentIdx = idx;
ret = true;
if (item ["value"] === value) {
ret = item ["text"];
break;
}
}
return ret;
}
signal edited ();
Rectangle {
id: rect;
radius: Style.roundness;
......@@ -59,30 +53,36 @@ Item {
}
anchors.fill: parent;
}
ColumnContainer {
id: dumbLayout;
opacity: 0;
StackContainer {
id: stackControls;
clip: true;
anchors {
left: (parent ? parent.left : undefined);
right: arrow.left;
margins: base.padding;
verticalCenter: (parent ? parent.verticalCenter : undefined);
}
Repeater {
id: repeater;
model: base.model;
delegate: Loader {
id: loaderDumb;
sourceComponent: base.delegate;
enabled: (isCurrent && base.enabled);
opacity: (isCurrent ? 1.0 : 0.0);
sourceComponent: base.delegateForControl;
onInstanceChanged: {
if (instance !== null) {
instance.active = true;
instance.model = model;
instance.modelData = model.modelData;
instance.index = Qt.binding (function () { return loaderDumb.idx; });
instance ["model"] = model;
instance ["modelData"] = model.modelData;
}
}
readonly property ComboListDelegate instance : item;
readonly property ComboListDelegateForControl instance : item;
readonly property var idx : model.index;
readonly property var value : (instance ? instance.value : undefined);
readonly property var key : (instance ? instance.key : undefined);
readonly property var value : (instance ? instance.value : undefined);
readonly property string text : (instance ? instance.text : "");
readonly property bool isCurrent : (value === base.value);
}
}
}
......@@ -99,7 +99,9 @@ Item {
createDropdown ();
}
}
Component.onDestruction: { destroyDropdown (); }
Component.onDestruction: {
destroyDropdown ();
}
property Item dropdownItem : null;
......@@ -114,29 +116,6 @@ Item {
}
}
}
Loader {
id: loaderCurrent;
clip: true;
enabled: base.enabled;
sourceComponent: base.delegate;
anchors {
left: (parent ? parent.left : undefined);
right: arrow.left;
margins: padding;
verticalCenter: (parent ? parent.verticalCenter : undefined);
}
onInstanceChanged: {
if (instance !== null) {
instance.active = false;
instance.index = Qt.binding (function () { return base.currentIdx; });
instance.key = Qt.binding (function () { return base.currentKey; });
instance.value = Qt.binding (function () { return (base.currentValue || base.placeholder); });
instance.opacity = Qt.binding (function () { return (base.currentKey !== undefined ? 1.0 : 0.65); });
}
}
readonly property ComboListDelegate instance : item;
}
SymbolLoader {
id: arrow;
size: Style.fontSizeNormal;
......@@ -145,7 +124,7 @@ Item {
enabled: base.enabled;
anchors {
right: (parent ? parent.right : undefined);
margins: padding;
margins: base.padding;
verticalCenter: (parent ? parent.verticalCenter : undefined);
}
}
......@@ -267,19 +246,17 @@ Item {
model: base.model;
delegate: MouseArea {
id: dlg;
visible: frame.matches (loader.instance.value);
visible: frame.matches (loader.value);
hoverEnabled: Style.useHovering;
implicitWidth: (loader.implicitWidth + padding * 2);
implicitHeight: (loader.implicitHeight + padding * 2);
onClicked: {
currentIdx = idx;
base.value = loader.value;
base.edited ();
clicker.destroyDropdown ();
}
ExtraAnchors.horizontalFill: parent;
readonly property var idx : model.index;
readonly property bool curr : (idx === base.currentIdx);
Rectangle {
color: Style.colorHighlight;
opacity: 0.65;
......@@ -290,22 +267,24 @@ Item {
Loader {
id: loader;
clip: true;
sourceComponent: base.delegate;
sourceComponent: base.delegateForDropdown;
anchors {
margins: padding;
margins: base.padding;
verticalCenter: (parent ? parent.verticalCenter : undefined);
}
ExtraAnchors.horizontalFill: parent;
onInstanceChanged: {
if (instance !== null) {
instance.index = Qt.binding (function () { return dlg.idx; });
instance.active = Qt.binding (function () { return dlg.curr; });
instance.active = Qt.binding (function () { return loader.isCurrent; });
instance.model = model;
instance.modelData = model.modelData;
}
}
readonly property ComboListDelegate instance : item;
readonly property ComboListDelegateForDropdown instance : item;
readonly property var value : (instance ? instance.value : undefined);
readonly property bool isCurrent : (value === base.value);
}
}
}
......
import QtQuick 2.6;
Column {
id: self;
property var value : undefined;
property string text : "";
property var model : undefined;
property var modelData : undefined;
}
import QtQuick 2.6;
Column {
id: self;
property var value : undefined;
property string text : "";
property var model : undefined;
property var modelData : undefined;
property bool active : false;
}
import QtQuick 2.6;
import QtQmlTricks 3.0;
ComboListDelegate {
id: base;
key: (base.modelData ? base.modelData [base.attributeKey] : undefined);
value: (base.modelData ? base.modelData [base.attributeValue] : "");
implicitWidth: lbl.implicitWidth;
implicitHeight: lbl.implicitHeight;
property string attributeKey : "key";
property string attributeValue : "value";
readonly property alias label : lbl;
TextLabel {
id: lbl;
text: base.value;
emphasis: base.active;
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
}
}
import QtQuick 2.6;
import QtQmlTricks 3.0;
ComboListDelegate {
id: base;
key: (base.model ? base.model [base.roleKey] : undefined);
value: (base.model ? base.model [base.roleValue] : "");
implicitWidth: lbl.implicitWidth;
implicitHeight: lbl.implicitHeight;
property string roleKey : "key";
property string roleValue : "value";
readonly property alias label : lbl;
TextLabel {
id: lbl;
text: base.value;
emphasis: base.active;
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
}
}
import QtQuick 2.6;
import QtQmlTricks 3.0;
ComboListDelegate {
id: base;
key: base.modelData;
value: (base.modelData ? base.modelData : "");
implicitWidth: lbl.implicitWidth;
implicitHeight: lbl.implicitHeight;
readonly property alias label : lbl;
TextLabel {
id: lbl;
text: base.value;
emphasis: base.active;
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
}
}
......@@ -53,22 +53,31 @@ FocusScope {
id: combo;
model: FileSystem.drivesList;
visible: (FileSystem.rootPath !== "/");
delegate: ComboListDelegateForSimpleVar { }
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
onCurrentKeyChanged: {
if (currentKey !== undefined && currentKey !== "" && ready) {
rootFolder = currentKey;
goToFolder (rootFolder);
delegateForControl: ComboListDelegateForControl {
text: modelData;
value: modelData;
TextLabel {
text: parent.text;
}
}
delegateForDropdown: ComboListDelegateForDropdown {
text: modelData;
value: modelData;
TextLabel {
text: parent.text;
}
}
Component.onCompleted: {
if (FileSystem.rootPath !== "/") {
selectByKey (folder.substring (0, 3));
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
onEdited: {
if (value !== undefined && value !== "") {
rootFolder = value;
goToFolder (rootFolder);
}
ready = true;
}
property bool ready : false;
Binding on value { value: (FileSystem.rootPath !== "/" ? folder.substring (0, 3) : "/"); }
}
ColumnContainer {
anchors.verticalCenter: (parent ? parent.verticalCenter : undefined);
......
......@@ -8,8 +8,9 @@ FocusScope {
implicitWidth: -1;
implicitHeight: -1;
property bool stayAtBottom : false;
property bool showBorder : true;
property bool indicatorOnly : false;
property bool indicatorOnly : stayAtBottom;
property alias placeholder : lbl.text;
property alias background : rect.color;
property alias headerItem : loaderHeader.sourceComponent;
......@@ -52,6 +53,12 @@ FocusScope {
return (val > max ? max : (val < min ? min : val));
}
Binding {
target: flickableItem;
property: "contentY";
value: (flickableItem ? Math.max (0, flickableItem.contentHeight - flickableItem.height) : 0);
when: stayAtBottom;
}
Rectangle {
id: rect;
color: Style.colorEditable;
......
......@@ -3,25 +3,20 @@ import QtQmlTricks 3.0;
Item {
id: base;
width: implicitWidth;
height: implicitHeight;
visible: (icon !== "");
implicitWidth: (helper.size * helper.horizontalRatio);
implicitHeight: (helper.size * helper.verticalRatio);
implicitWidth: helper.size;
implicitHeight: helper.size;
property int size : Style.iconSize (1);
property color color : Style.colorNone;
property alias icon : helper.icon;
property alias verticalRatio : helper.verticalRatio;
property alias horizontalRatio : helper.horizontalRatio;
property int size : Style.iconSize (1);
property bool dimmed : !base.enabled;
property color color : Style.colorNone;
property alias icon : helper.icon;
Image {
id: img;
cache: !helper.live;
width: helper.size;
height: helper.size;
smooth: false;
opacity: (enabled ? 1.0 : 0.65);
opacity: (dimmed ? 0.65 : 1.0);
fillMode: Image.Pad;
antialiasing: false;
asynchronous: true;
......@@ -31,7 +26,7 @@ Item {
SvgIconHelper on source {
id: helper;
size: base.size;
color: (base.enabled ? base.color : Style.colorBorder);
color: (base.dimmed ? Style.colorBorder : base.color);
}
}
}
......@@ -21,6 +21,7 @@ FocusScope {
property alias validator : input.validator;
property alias acceptable : input.acceptableInput;
property alias rounding : rect.radius;
property alias value : input.text;
readonly property bool isEmpty : (text.trim () === "");
......
......@@ -7,10 +7,8 @@ AutoRepeatableClicker 3.0 AutoRepeatableClicker.qml
Balloon 3.0 Balloon.qml
CheckableBox 3.0 CheckableBox.qml
ComboList 3.0 ComboList.qml
ComboListDelegate 3.0 ComboListDelegate.qml
ComboListDelegateForSimpleVar 3.0 ComboListDelegateForSimpleVar.qml
ComboListDelegateForModelWithRoles 3.0 ComboListDelegateForModelWithRoles.qml
ComboListDelegateForModelDataAttributes 3.0 ComboListDelegateForModelDataAttributes.qml
ComboListDelegateForControl 3.0 ComboListDelegateForControl.qml
ComboListDelegateForDropdown 3.0 ComboListDelegateForDropdown.qml
FileSelector 3.0 FileSelector.qml
Group 3.0 Group.qml
Line 3.0 Line.qml
......
......@@ -19,13 +19,12 @@
<file>imports/QtQmlTricks.3/Balloon.qml</file>
<file>imports/QtQmlTricks.3/StatusBar.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegate.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegateForModelWithRoles.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegateForSimpleVar.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegateForModelDataAttributes.qml</file>
<file>imports/QtQmlTricks.3/SymbolLoader.qml</file>
<file>imports/QtQmlTricks.3/AbstractSymbol.qml</file>
<file>imports/QtQmlTricks.3/ModalDialog.qml</file>
<file>imports/QtQmlTricks.3/AutoRepeatableClicker.qml</file>
<file>imports/QtQmlTricks.3/SvgIconLoader.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegateForControl.qml</file>
<file>imports/QtQmlTricks.3/ComboListDelegateForDropdown.qml</file>
</qresource>
</RCC>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment