center align starts to work
still not perfect
This commit is contained in:
parent
c2640b28c6
commit
b57d9e02c0
@ -327,7 +327,11 @@ void PanelView::restore()
|
||||
|
||||
static const int MINSIZE = 10;
|
||||
|
||||
m_offset = qMax(0, config().readEntry<int>("offset", 0));
|
||||
m_offset = config().readEntry<int>("offset", 0);
|
||||
if (m_alignment != Qt::AlignCenter) {
|
||||
m_offset = qMax(0, m_offset);
|
||||
}
|
||||
|
||||
m_maxLength = config().readEntry<int>("maxLength", -1);
|
||||
m_minLength = config().readEntry<int>("minLength", -1);
|
||||
m_alignment = (Qt::Alignment)config().readEntry<int>("alignment", Qt::AlignLeft);
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user