working menu to switch between panel alignments

This commit is contained in:
Marco Martin 2013-05-09 16:16:28 +02:00
parent c13a58cf11
commit bbb5e08d58
3 changed files with 168 additions and 5 deletions

View File

@ -116,6 +116,7 @@ void PanelView::setAlignment(Qt::Alignment alignment)
}
m_alignment = alignment;
config().writeEntry("alignment", (int)m_alignment);
positionPanel();
}
@ -158,6 +159,31 @@ void PanelView::setThickness(int value)
m_corona->requestApplicationConfigSync();
}
int PanelView::length() const
{
if (formFactor() == Plasma::Vertical) {
config().readEntry<int>("length", screen()->size().height());
} else {
config().readEntry<int>("length", screen()->size().width());
}
}
void PanelView::setLength(int value)
{
if (value == length()) {
return;
}
if (formFactor() == Plasma::Vertical) {
setHeight(value);
} else {
setWidth(value);
}
config().writeEntry("length", value);
emit lengthChanged();
m_corona->requestApplicationConfigSync();
}
int PanelView::maximumLength() const
{
return m_maxLength;
@ -181,6 +207,7 @@ void PanelView::setMaximumLength(int length)
config().writeEntry("maxLength", length);
m_maxLength = length;
emit maximumLengthChanged();
positionPanel();
m_corona->requestApplicationConfigSync();
}
@ -206,6 +233,7 @@ void PanelView::setMinimumLength(int length)
}
config().writeEntry("minLength", length);
m_minLength = length;
positionPanel();
emit minimumLengthChanged();
m_corona->requestApplicationConfigSync();
}
@ -223,12 +251,13 @@ void PanelView::positionPanel()
case Plasma::TopEdge:
containment()->setFormFactor(Plasma::Horizontal);
restore();
switch (m_alignment) {
case Qt::AlignCenter:
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().top()) + QPoint(m_offset - size().width()/2, 0));
break;
case Qt::AlignRight:
setPosition(s->virtualGeometry().topRight() + QPoint(-m_offset - size().width(), 0));
setPosition(s->virtualGeometry().topRight() - QPoint(m_offset + size().width(), 0));
break;
case Qt::AlignLeft:
default:
@ -244,7 +273,7 @@ void PanelView::positionPanel()
setPosition(QPoint(s->virtualGeometry().left(), s->virtualGeometry().center().y()) + QPoint(0, m_offset));
break;
case Qt::AlignRight:
setPosition(s->virtualGeometry().bottomLeft() + QPoint(0, -m_offset - size().height()));
setPosition(s->virtualGeometry().bottomLeft() - QPoint(0, m_offset + size().height()));
break;
case Qt::AlignLeft:
default:
@ -260,7 +289,7 @@ void PanelView::positionPanel()
setPosition(QPoint(s->virtualGeometry().right(), s->virtualGeometry().center().y()) - QPoint(width(), 0) + QPoint(0, m_offset - size().height()/2));
break;
case Qt::AlignRight:
setPosition(s->virtualGeometry().bottomRight() - QPoint(width(), 0) + QPoint(0, -m_offset - size().height()));
setPosition(s->virtualGeometry().bottomRight() - QPoint(width(), 0) - QPoint(0, m_offset + size().height()));
break;
case Qt::AlignLeft:
default:
@ -277,7 +306,7 @@ void PanelView::positionPanel()
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().bottom()) + QPoint(m_offset - size().width()/2, 0));
break;
case Qt::AlignRight:
setPosition(s->virtualGeometry().bottomRight() - QPoint(0, height()) + QPoint(-m_offset - size().width(), 0));
setPosition(s->virtualGeometry().bottomRight() - QPoint(0, height()) - QPoint(m_offset + size().width(), 0));
break;
case Qt::AlignLeft:
default:
@ -334,4 +363,29 @@ void PanelView::restore()
emit offsetChanged();
}
void PanelView::resizeEvent(QResizeEvent *ev)
{
if (containment()->formFactor() == Plasma::Vertical) {
config().writeEntry("length", ev->size().height());
config().writeEntry("thickness", ev->size().width());
if (ev->size().height() != ev->oldSize().height()) {
emit lengthChanged();
}
if (ev->size().width() != ev->oldSize().width()) {
emit thicknessChanged();
}
} else {
config().writeEntry("length", ev->size().width());
config().writeEntry("thickness", ev->size().height());
if (ev->size().width() != ev->oldSize().width()) {
emit lengthChanged();
}
if (ev->size().height() != ev->oldSize().height()) {
emit thicknessChanged();
}
}
View::resizeEvent(ev);
}
#include "moc_panelview.cpp"

View File

@ -32,6 +32,7 @@ class PanelView : public View
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
Q_PROPERTY(int thickness READ thickness WRITE setThickness NOTIFY thicknessChanged)
Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
Q_PROPERTY(int maximumLength READ maximumLength WRITE setMaximumLength NOTIFY maximumLengthChanged)
Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
@ -52,17 +53,24 @@ public:
int thickness() const;
void setThickness(int thickness);
int length() const;
void setLength(int value);
int maximumLength() const;
void setMaximumLength(int length);
int minimumLength() const;
void setMinimumLength(int length);
protected:
void resizeEvent(QResizeEvent *ev);
Q_SIGNALS:
void alignmentChanged();
void offsetChanged();
void screenGeometryChanged();
void thicknessChanged();
void lengthChanged();
void maximumLengthChanged();
void minimumLengthChanged();

View File

@ -59,6 +59,63 @@ Item {
}
}
PlasmaComponents.Button {
id: moreSettingsButton
property QtObject contextMenu
text: "More settings"
onClicked: {
if (!contextMenu) {
contextMenu = contextMenuComponent.createObject(moreSettingsButton)
}
contextMenu.open()
}
}
Component {
id: contextMenuComponent
PlasmaComponents.ContextMenu {
visualParent: moreSettingsButton
PlasmaComponents.MenuItem {
id: leftToggle
text: "Left"
checkable: true
checked: panel.alignment == Qt.AlignLeft
onClicked: panel.alignment = Qt.AlignLeft
onToggled: {
if (checked) {
centerToggle.checked = false
rightToggle.checked = false
}
}
}
PlasmaComponents.MenuItem {
id: centerToggle
text: "Center"
checkable: true
checked: panel.alignment == Qt.AlignCenter
onClicked: panel.alignment = Qt.AlignCenter
onToggled: {
if (checked) {
leftToggle.checked = false
rightToggle.checked = false
}
}
}
PlasmaComponents.MenuItem {
id: rightToggle
text: "Right"
checkable: true
checked: panel.alignment == Qt.AlignRight
onClicked: panel.alignment = Qt.AlignRight
onToggled: {
if (checked) {
centerToggle.checked = false
leftToggle.checked = false
}
}
}
}
}
//BEGIN States
states: [
@ -77,6 +134,17 @@ Item {
right: root.parent.right
}
}
AnchorChanges {
target: moreSettingsButton
anchors {
verticalCenter: root.verticalCenter
horizontalCenter: undefined
top: undefined
bottom: undefined
left: undefined
right: root.right
}
}
},
State {
name: "BottomEdge"
@ -93,6 +161,17 @@ Item {
right: root.parent.right
}
}
AnchorChanges {
target: moreSettingsButton
anchors {
verticalCenter: root.verticalCenter
horizontalCenter: undefined
top: undefined
bottom: undefined
left: undefined
right: root.right
}
}
},
State {
name: "LeftEdge"
@ -109,6 +188,17 @@ Item {
right: root.parent.right
}
}
AnchorChanges {
target: moreSettingsButton
anchors {
verticalCenter: undefined
horizontalCenter: root.verticalCenter
top: undefined
bottom: root.bottom
left: undefined
right: undefined
}
}
},
State {
name: "RightEdge"
@ -125,6 +215,17 @@ Item {
right: undefined
}
}
AnchorChanges {
target: moreSettingsButton
anchors {
verticalCenter: undefined
horizontalCenter: root.verticalCenter
top: undefined
bottom: root.bottom
left: undefined
right: undefined
}
}
}
]
//END States