rulers work for left and right alignments

This commit is contained in:
Marco Martin 2013-05-09 17:13:07 +02:00
parent bbb5e08d58
commit c2640b28c6
3 changed files with 52 additions and 30 deletions

View File

@ -117,6 +117,7 @@ void PanelView::setAlignment(Qt::Alignment alignment)
m_alignment = alignment;
config().writeEntry("alignment", (int)m_alignment);
emit alignmentChanged();
positionPanel();
}
@ -324,38 +325,39 @@ void PanelView::restore()
return;
}
m_offset = config().readEntry<int>("offset", 0);
static const int MINSIZE = 10;
m_offset = qMax(0, config().readEntry<int>("offset", 0));
m_maxLength = config().readEntry<int>("maxLength", -1);
m_minLength = config().readEntry<int>("minLength", -1);
m_alignment = (Qt::Alignment)config().readEntry<int>("alignment", Qt::AlignLeft);
setMinimumSize(QSize(-1, -1));
//FIXME: an invalid size doesn't work with QWindows
setMaximumSize(QSize(10000, 10000));
setMaximumSize(screen()->size());
if (containment()->formFactor() == Plasma::Vertical) {
resize(config().readEntry<int>("thickness", 32),
config().readEntry<int>("length", screen()->size().height()));
const int maxSize = screen()->size().height() - m_offset;
m_maxLength = qBound<int>(MINSIZE, m_maxLength, maxSize);
m_minLength = qBound<int>(MINSIZE, m_minLength, maxSize);
if (m_minLength > 0) {
setMinimumHeight(m_minLength);
}
if (m_maxLength > 0) {
setMaximumHeight(m_maxLength);
}
resize(config().readEntry<int>("thickness", 32),
qBound<int>(MINSIZE, config().readEntry<int>("length", screen()->size().height()), maxSize));
setMinimumHeight(m_minLength);
setMaximumHeight(m_maxLength);
//Horizontal
} else {
resize(config().readEntry<int>("length", screen()->size().width()),
const int maxSize = screen()->size().width() - m_offset;
m_maxLength = qBound<int>(MINSIZE, m_maxLength, maxSize);
m_minLength = qBound<int>(MINSIZE, m_minLength, maxSize);
resize(qBound<int>(MINSIZE, config().readEntry<int>("length", screen()->size().height()), maxSize),
config().readEntry<int>("thickness", 32));
if (m_minLength > 0) {
setMinimumWidth(m_minLength);
}
if (m_maxLength > 0) {
setMaximumWidth(m_maxLength);
}
setMinimumWidth(m_minLength);
setMaximumWidth(m_maxLength);
}
emit maximumLengthChanged();

View File

@ -49,17 +49,20 @@ PlasmaCore.FrameSvgItem {
SliderHandle {
id: offsetHandle
inverted: panel.alignment == Qt.AlignRight
graphicElementName: "offsetslider"
onValueChanged: panel.offset = value
}
SliderHandle {
id: minimumLengthHandle
inverted: panel.alignment == Qt.AlignRight
offset: panel.offset
graphicElementName: "minslider"
onValueChanged: panel.minimumLength = value
}
SliderHandle {
id: maximumLengthHandle
inverted: panel.alignment == Qt.AlignRight
offset: panel.offset
graphicElementName: "maxslider"
onValueChanged: panel.maximumLength = value

View File

@ -34,21 +34,30 @@ PlasmaCore.SvgItem {
property int value
property string graphicElementName
property int offset: 0
property bool inverted: false
onValueChanged: {
function syncPos() {
if (panel.location == 5 || panel.location == 6) {
y = value + offset - root.height/2
if (inverted) {
y = root.parent.height - (value + offset + root.height/2)
} else {
y = value + offset - root.height/2
}
} else {
x = value + offset - root.width/2
if (inverted) {
x = root.parent.width - (value + offset + root.width/2)
} else {
x = value + offset - root.width/2
}
}
}
onOffsetChanged: {
if (panel.location == 5 || panel.location == 6) {
y = value + offset - root.height/2
} else {
x = value + offset - root.width/2
}
onValueChanged: syncPos()
onOffsetChanged: syncPos()
onInvertedChanged: syncPos()
Connections {
target: root.parent
onWidthChanged: syncPos()
onHeightChanged: syncPos()
}
MouseArea {
@ -59,9 +68,17 @@ PlasmaCore.SvgItem {
anchors.fill: parent
onPositionChanged: {
if (panel.location == 5 || panel.location == 6) {
root.value = parent.y - offset + root.height/2
if (root.inverted) {
root.value = root.parent.height - (parent.y + offset + root.height/2)
} else {
root.value = parent.y - offset + root.height/2
}
} else {
root.value = parent.x - offset + root.width/2
if (root.inverted) {
root.value = root.parent.width - (parent.x + offset + root.width/2)
} else {
root.value = parent.x - offset + root.width/2
}
}
}
}