[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [plasma-framework] src/shell: working menu to switch between panel alignments
From: Marco Martin <notmart () gmail ! com>
Date: 2013-05-09 14:16:52
Message-ID: 20130509141652.592E0A6071 () git ! kde ! org
[Download RAW message or body]
Git commit bbb5e08d5899d0fc31f168c5c506e0afb70a97d1 by Marco Martin.
Committed on 09/05/2013 at 16:16.
Pushed by mart into branch 'master'.
working menu to switch between panel alignments
M +59 -5 src/shell/panelview.cpp
M +8 -0 src/shell/panelview.h
M +101 -0 src/shell/qmlpackages/desktop/contents/configuration/panelconfiguration/ToolBar.qml
http://commits.kde.org/plasma-framework/bbb5e08d5899d0fc31f168c5c506e0afb70a97d1
diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp
index 472fabc..116474f 100644
--- a/src/shell/panelview.cpp
+++ b/src/shell/panelview.cpp
@@ -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();
}
@@ -218,17 +246,18 @@ void PanelView::positionPanel()
QScreen *s = screen();
const int oldThickness = thickness();
-
+
switch (containment()->location()) {
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"
diff --git a/src/shell/panelview.h b/src/shell/panelview.h
index 29e1687..d8d86a7 100644
--- a/src/shell/panelview.h
+++ b/src/shell/panelview.h
@@ -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();
diff --git a/src/shell/qmlpackages/desktop/contents/configuration/panelconfiguration/ToolBar.qml \
b/src/shell/qmlpackages/desktop/contents/configuration/panelconfiguration/ToolBar.qml \
index ac3bb2e..18ddf50 100644
--- a/src/shell/qmlpackages/desktop/contents/configuration/panelconfiguration/ToolBar.qml
+++ b/src/shell/qmlpackages/desktop/contents/configuration/panelconfiguration/ToolBar.qml
@@ -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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic