From 220c9e1dbfa4630e38b1a67ce6824325c4c0e1a9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 9 May 2013 20:30:31 +0200 Subject: [PATCH] center align starts to work still not perfect --- panelview.cpp | 6 +- .../panelconfiguration/Ruler.qml | 100 +++++++++++++++++- .../panelconfiguration/SliderHandle.qml | 49 +++++++-- 3 files changed, 141 insertions(+), 14 deletions(-) diff --git a/panelview.cpp b/panelview.cpp index b69cf36f4..d2d4b734a 100644 --- a/panelview.cpp +++ b/panelview.cpp @@ -327,7 +327,11 @@ void PanelView::restore() static const int MINSIZE = 10; - m_offset = qMax(0, config().readEntry("offset", 0)); + m_offset = config().readEntry("offset", 0); + if (m_alignment != Qt::AlignCenter) { + m_offset = qMax(0, m_offset); + } + m_maxLength = config().readEntry("maxLength", -1); m_minLength = config().readEntry("minLength", -1); m_alignment = (Qt::Alignment)config().readEntry("alignment", Qt::AlignLeft); diff --git a/qmlpackages/desktop/contents/configuration/panelconfiguration/Ruler.qml b/qmlpackages/desktop/contents/configuration/panelconfiguration/Ruler.qml index f13eb508f..e4b66444e 100644 --- a/qmlpackages/desktop/contents/configuration/panelconfiguration/Ruler.qml +++ b/qmlpackages/desktop/contents/configuration/panelconfiguration/Ruler.qml @@ -36,10 +36,15 @@ PlasmaCore.FrameSvgItem { implicitWidth: offsetHandle.width + minimumLengthHandle.width implicitHeight: offsetHandle.height + minimumLengthHandle.height + onMinimumLengthChanged: leftMinimumLengthHandle.value = minimumLength + onMaximumLengthChanged: leftMaximumLengthHandle.value = maximumLength + Component.onCompleted: { offsetHandle.value = panel.offset minimumLengthHandle.value = panel.minimumLength maximumLengthHandle.value = panel.maximumLength + leftMinimumLengthHandle.value = panel.minimumLength + leftMaximumLengthHandle.value = panel.maximumLength } PlasmaCore.Svg { @@ -49,24 +54,41 @@ PlasmaCore.FrameSvgItem { SliderHandle { id: offsetHandle - inverted: panel.alignment == Qt.AlignRight graphicElementName: "offsetslider" onValueChanged: panel.offset = value } SliderHandle { id: minimumLengthHandle - inverted: panel.alignment == Qt.AlignRight + alignment: panel.alignment | Qt.AlignLeft + visible: panel.alignment != Qt.AlignRight offset: panel.offset graphicElementName: "minslider" onValueChanged: panel.minimumLength = value } SliderHandle { id: maximumLengthHandle - inverted: panel.alignment == Qt.AlignRight + alignment: panel.alignment | Qt.AlignLeft + visible: panel.alignment != Qt.AlignRight offset: panel.offset graphicElementName: "maxslider" onValueChanged: panel.maximumLength = value } + SliderHandle { + id: leftMinimumLengthHandle + alignment: panel.alignment | Qt.AlignRight + visible: panel.alignment != Qt.AlignLeft + offset: panel.offset + graphicElementName: "maxslider" + onValueChanged: panel.minimumLength = value + } + SliderHandle { + id: leftMaximumLengthHandle + alignment: panel.alignment | Qt.AlignRight + visible: panel.alignment != Qt.AlignLeft + offset: panel.offset + graphicElementName: "minslider" + onValueChanged: panel.maximumLength = value + } states: [ State { @@ -112,6 +134,24 @@ PlasmaCore.FrameSvgItem { right: undefined } } + AnchorChanges { + target: leftMinimumLengthHandle + anchors { + top: root.top + bottom: undefined + left: undefined + right: undefined + } + } + AnchorChanges { + target: leftMaximumLengthHandle + anchors { + top: undefined + bottom: root.bottom + left: undefined + right: undefined + } + } }, State { name: "BottomEdge" @@ -156,6 +196,24 @@ PlasmaCore.FrameSvgItem { right: undefined } } + AnchorChanges { + target: leftMinimumLengthHandle + anchors { + top: undefined + bottom: root.bottom + left: undefined + right: undefined + } + } + AnchorChanges { + target: leftMaximumLengthHandle + anchors { + top: root.top + bottom: undefined + left: undefined + right: undefined + } + } }, State { name: "LeftEdge" @@ -200,6 +258,24 @@ PlasmaCore.FrameSvgItem { right: root.right } } + AnchorChanges { + target: leftMinimumLengthHandle + anchors { + top: undefined + bottom: undefined + left: root.left + right: undefined + } + } + AnchorChanges { + target: leftMaximumLengthHandle + anchors { + top: undefined + bottom: undefined + left: undefined + right: root.right + } + } }, State { name: "RightEdge" @@ -244,6 +320,24 @@ PlasmaCore.FrameSvgItem { right: undefined } } + AnchorChanges { + target: leftMinimumLengthHandle + anchors { + top: undefined + bottom: undefined + left: undefined + right: parent.right + } + } + AnchorChanges { + target: leftMaximumLengthHandle + anchors { + top: undefined + bottom: undefined + left: parent.left + right: undefined + } + } } ] } diff --git a/qmlpackages/desktop/contents/configuration/panelconfiguration/SliderHandle.qml b/qmlpackages/desktop/contents/configuration/panelconfiguration/SliderHandle.qml index 1a6d4bbb4..7fa1d992e 100644 --- a/qmlpackages/desktop/contents/configuration/panelconfiguration/SliderHandle.qml +++ b/qmlpackages/desktop/contents/configuration/panelconfiguration/SliderHandle.qml @@ -31,29 +31,49 @@ PlasmaCore.SvgItem { width: naturalSize.width height: naturalSize.height + //value expressed by this slider property int value + //name of the graphics to load property string graphicElementName + //where the point "0" is property int offset: 0 - property bool inverted: false + //handle type: behave in different ways based on the alignment + property int alignment: panel.alignment function syncPos() { if (panel.location == 5 || panel.location == 6) { - if (inverted) { + if (alignment == Qt.AlignRight) { y = root.parent.height - (value + offset + root.height/2) - } else { + } else if (alignment == Qt.AlignLeft) { y = value + offset - root.height/2 + } else { + if (root.alignment & Qt.AlignRight) { + y = root.parent.height/2 - value/2 - offset + root.height/2 + } else if (root.alignment & Qt.AlignLeft) { + y = root.parent.height/2 + value/2 + offset - root.height/2 + } else { + y = root.parent.height/2 + value + offset -root.height/2 + } } } else { - if (inverted) { + if (alignment == Qt.AlignRight) { x = root.parent.width - (value + offset + root.width/2) - } else { + } else if (alignment == Qt.AlignLeft) { x = value + offset - root.width/2 + } else { + if (root.alignment & Qt.AlignRight) { + x = root.parent.width/2 - value/2 + offset - root.width/2 + } else if (root.alignment & Qt.AlignLeft) { + x = root.parent.width/2 + value/2 + offset -root.width/2 + } else { + x = root.parent.width/2 + value + offset -root.width/2 + } } } } onValueChanged: syncPos() onOffsetChanged: syncPos() - onInvertedChanged: syncPos() + onAlignmentChanged: syncPos() Connections { target: root.parent onWidthChanged: syncPos() @@ -68,16 +88,25 @@ PlasmaCore.SvgItem { anchors.fill: parent onPositionChanged: { if (panel.location == 5 || panel.location == 6) { - if (root.inverted) { + if (root.alignment == Qt.AlignRight) { root.value = root.parent.height - (parent.y + offset + root.height/2) - } else { + } else if (alignment == Qt.AlignLeft) { root.value = parent.y - offset + root.height/2 } } else { - if (root.inverted) { + if (root.alignment == Qt.AlignRight) { root.value = root.parent.width - (parent.x + offset + root.width/2) - } else { + } else if (alignment == Qt.AlignLeft) { root.value = parent.x - offset + root.width/2 + //Center + } else { + if (root.alignment & Qt.AlignRight) { + root.value = (root.parent.width/2 - parent.x + offset)*2 + root.width/2 + } else if (root.alignment & Qt.AlignLeft) { + root.value = (parent.x - offset - root.parent.width/2)*2 + root.width/2 + } else { + root.value = parent.x - root.parent.width/2 - offset + root.width/2 + } } } }