Commit a8f84a11 authored by eekkelund's avatar eekkelund

[Controls] Buttonrow: added fixedWidth and made the selÃector draggable as in spec.

parent b99b332e
...@@ -43,8 +43,10 @@ Page { ...@@ -43,8 +43,10 @@ Page {
Column { Column {
spacing: 40 spacing: 40
anchors.centerIn: parent anchors.centerIn: parent
width: parent.width
ButtonRow { ButtonRow {
id: row id: row
anchors.horizontalCenter: parent.horizontalCenter
model: ListModel { model: ListModel {
id: buttonModel id: buttonModel
ListElement { ListElement {
...@@ -73,11 +75,14 @@ Page { ...@@ -73,11 +75,14 @@ Page {
Label { Label {
id: selector id: selector
anchors.horizontalCenter: parent.horizontalCenter
text: "Nothing selected" text: "Nothing selected"
} }
ButtonRow { ButtonRow {
id: row2 id: row2
enabled: false enabled: false
anchors.horizontalCenter: parent.horizontalCenter
fixedWidth: parent.width * .8
model: ListModel { model: ListModel {
ListElement { ListElement {
name: "swim" name: "swim"
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <QObject> #include <QObject>
#include <QEvent> #include <QEvent>
#include <QString> #include <QString>
#include <QVariant>
#include "nemofocussingleton.h" #include "nemofocussingleton.h"
class EditFilter : public QObject class EditFilter : public QObject
......
...@@ -35,12 +35,21 @@ import QtQuick.Controls.Styles.Nemo 1.0 ...@@ -35,12 +35,21 @@ import QtQuick.Controls.Styles.Nemo 1.0
Rectangle { Rectangle {
id: main id: main
width: childrenRect.width implicitWidth: fixedWidth ? fixedWidth : childrenRectWidth()
color: Theme.fillDarkColor color: Theme.fillDarkColor
height: Theme.itemHeightSmall height: Theme.itemHeightSmall
property ListModel model: ListModel {} property ListModel model: ListModel {}
property bool enabled: true property bool enabled: true
property int currentIndex: -1 property int currentIndex: -1
property int fixedWidth
function childrenRectWidth() {
var childWidth = 0
for(var i=0; i < rectangles.count; i++) {
childWidth = childWidth + rectangles.itemAt(i).width
}
return childWidth
}
Image { Image {
anchors.fill: parent anchors.fill: parent
...@@ -48,24 +57,51 @@ Rectangle { ...@@ -48,24 +57,51 @@ Rectangle {
source: "images/disabled-overlay.png" source: "images/disabled-overlay.png"
fillMode: Image.Tile fillMode: Image.Tile
} }
Rectangle{ Rectangle{
id: selecter id: selecter
x: rowElement.children[main.currentIndex].x || 0 //x: main.currentIndex > -1 ? rowElement.children[main.currentIndex].x : 0
anchors.verticalCenter: rowElement.verticalCenter anchors.verticalCenter: rowElement.verticalCenter
width: rowElement.children[main.currentIndex].width || 0
height: Theme.itemHeightMedium height: Theme.itemHeightMedium
color: Theme.accentColor color: Theme.accentColor
clip: true
visible: main.currentIndex > -1 visible: main.currentIndex > -1
Behavior on x { Behavior on x {
NumberAnimation { duration: 200 } NumberAnimation { duration: 200; easing.type: Easing.OutCubic}
} }
Behavior on width { Behavior on width {
NumberAnimation { duration: 200 } NumberAnimation { duration: 200; easing.type: Easing.OutCubic}
}
}
MouseArea {
id:dragArea
anchors.fill:parent
enabled: main.enabled
drag.target: main.enabled ? selecter.visible ? selecter : null : null
drag.axis: Drag.XAxis
drag.minimumX: x
drag.maximumX: main.width - selecter.width
property int inBoundsX
hoverEnabled: true
onReleased: {
if(inBoundsX > -1) {
if(mouseX < drag.minimumX)
rowElement.childAt(inBoundsX,y).changeIndex()
else if (mouseX > drag.maximumX+selecter.width)
rowElement.childAt(inBoundsX+selecter.width, y).changeIndex()
else rowElement.childAt(mouseX,y).changeIndex()
selecter.x = rowElement.children[main.currentIndex].x
selecter.width = main.currentIndex > -1 ? rowElement.children[main.currentIndex].width : 0
}
}
onClicked: {
inBoundsX = -1
rowElement.childAt(mouseX,y).changeIndex()
selecter.x = rowElement.children[main.currentIndex].x
selecter.width= main.currentIndex > -1 ? rowElement.children[main.currentIndex].width : 0
} }
onPositionChanged: if(mouseX>=drag.minimumX && mouseX <= drag.maximumX) inBoundsX = mouseX
} }
Row { Row {
...@@ -76,19 +112,9 @@ Rectangle { ...@@ -76,19 +112,9 @@ Rectangle {
delegate: Rectangle { delegate: Rectangle {
id: rowItem id: rowItem
height: Theme.itemHeightSmall height: Theme.itemHeightSmall
width: text.width+(text.width/name.length*2) width: main.fixedWidth ? (main.fixedWidth/main.model.count) : (text.width+(text.width/name.length*2))
color: "transparent" color: "transparent"
MouseArea { function changeIndex() { main.currentIndex = index}
width: parent.width
height: parent.height
enabled: main.enabled
onClicked: {
main.currentIndex = index
}
}
Label { Label {
id: text id: text
text: name text: name
......
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