working menu to switch between panel alignments
This commit is contained in:
parent
c13a58cf11
commit
bbb5e08d58
@ -116,6 +116,7 @@ void PanelView::setAlignment(Qt::Alignment alignment)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_alignment = alignment;
|
m_alignment = alignment;
|
||||||
|
config().writeEntry("alignment", (int)m_alignment);
|
||||||
positionPanel();
|
positionPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +159,31 @@ void PanelView::setThickness(int value)
|
|||||||
m_corona->requestApplicationConfigSync();
|
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
|
int PanelView::maximumLength() const
|
||||||
{
|
{
|
||||||
return m_maxLength;
|
return m_maxLength;
|
||||||
@ -181,6 +207,7 @@ void PanelView::setMaximumLength(int length)
|
|||||||
config().writeEntry("maxLength", length);
|
config().writeEntry("maxLength", length);
|
||||||
m_maxLength = length;
|
m_maxLength = length;
|
||||||
emit maximumLengthChanged();
|
emit maximumLengthChanged();
|
||||||
|
positionPanel();
|
||||||
m_corona->requestApplicationConfigSync();
|
m_corona->requestApplicationConfigSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,6 +233,7 @@ void PanelView::setMinimumLength(int length)
|
|||||||
}
|
}
|
||||||
config().writeEntry("minLength", length);
|
config().writeEntry("minLength", length);
|
||||||
m_minLength = length;
|
m_minLength = length;
|
||||||
|
positionPanel();
|
||||||
emit minimumLengthChanged();
|
emit minimumLengthChanged();
|
||||||
m_corona->requestApplicationConfigSync();
|
m_corona->requestApplicationConfigSync();
|
||||||
}
|
}
|
||||||
@ -223,12 +251,13 @@ void PanelView::positionPanel()
|
|||||||
case Plasma::TopEdge:
|
case Plasma::TopEdge:
|
||||||
containment()->setFormFactor(Plasma::Horizontal);
|
containment()->setFormFactor(Plasma::Horizontal);
|
||||||
restore();
|
restore();
|
||||||
|
|
||||||
switch (m_alignment) {
|
switch (m_alignment) {
|
||||||
case Qt::AlignCenter:
|
case Qt::AlignCenter:
|
||||||
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().top()) + QPoint(m_offset - size().width()/2, 0));
|
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().top()) + QPoint(m_offset - size().width()/2, 0));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignRight:
|
case Qt::AlignRight:
|
||||||
setPosition(s->virtualGeometry().topRight() + QPoint(-m_offset - size().width(), 0));
|
setPosition(s->virtualGeometry().topRight() - QPoint(m_offset + size().width(), 0));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignLeft:
|
case Qt::AlignLeft:
|
||||||
default:
|
default:
|
||||||
@ -244,7 +273,7 @@ void PanelView::positionPanel()
|
|||||||
setPosition(QPoint(s->virtualGeometry().left(), s->virtualGeometry().center().y()) + QPoint(0, m_offset));
|
setPosition(QPoint(s->virtualGeometry().left(), s->virtualGeometry().center().y()) + QPoint(0, m_offset));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignRight:
|
case Qt::AlignRight:
|
||||||
setPosition(s->virtualGeometry().bottomLeft() + QPoint(0, -m_offset - size().height()));
|
setPosition(s->virtualGeometry().bottomLeft() - QPoint(0, m_offset + size().height()));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignLeft:
|
case Qt::AlignLeft:
|
||||||
default:
|
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));
|
setPosition(QPoint(s->virtualGeometry().right(), s->virtualGeometry().center().y()) - QPoint(width(), 0) + QPoint(0, m_offset - size().height()/2));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignRight:
|
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;
|
break;
|
||||||
case Qt::AlignLeft:
|
case Qt::AlignLeft:
|
||||||
default:
|
default:
|
||||||
@ -277,7 +306,7 @@ void PanelView::positionPanel()
|
|||||||
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().bottom()) + QPoint(m_offset - size().width()/2, 0));
|
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().bottom()) + QPoint(m_offset - size().width()/2, 0));
|
||||||
break;
|
break;
|
||||||
case Qt::AlignRight:
|
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;
|
break;
|
||||||
case Qt::AlignLeft:
|
case Qt::AlignLeft:
|
||||||
default:
|
default:
|
||||||
@ -334,4 +363,29 @@ void PanelView::restore()
|
|||||||
emit offsetChanged();
|
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"
|
#include "moc_panelview.cpp"
|
||||||
|
@ -32,6 +32,7 @@ class PanelView : public View
|
|||||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||||
Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
|
Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
|
||||||
Q_PROPERTY(int thickness READ thickness WRITE setThickness NOTIFY thicknessChanged)
|
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 maximumLength READ maximumLength WRITE setMaximumLength NOTIFY maximumLengthChanged)
|
||||||
Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
|
Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
|
||||||
|
|
||||||
@ -52,17 +53,24 @@ public:
|
|||||||
int thickness() const;
|
int thickness() const;
|
||||||
void setThickness(int thickness);
|
void setThickness(int thickness);
|
||||||
|
|
||||||
|
int length() const;
|
||||||
|
void setLength(int value);
|
||||||
|
|
||||||
int maximumLength() const;
|
int maximumLength() const;
|
||||||
void setMaximumLength(int length);
|
void setMaximumLength(int length);
|
||||||
|
|
||||||
int minimumLength() const;
|
int minimumLength() const;
|
||||||
void setMinimumLength(int length);
|
void setMinimumLength(int length);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *ev);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void alignmentChanged();
|
void alignmentChanged();
|
||||||
void offsetChanged();
|
void offsetChanged();
|
||||||
void screenGeometryChanged();
|
void screenGeometryChanged();
|
||||||
void thicknessChanged();
|
void thicknessChanged();
|
||||||
|
void lengthChanged();
|
||||||
void maximumLengthChanged();
|
void maximumLengthChanged();
|
||||||
void minimumLengthChanged();
|
void minimumLengthChanged();
|
||||||
|
|
||||||
|
@ -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
|
//BEGIN States
|
||||||
states: [
|
states: [
|
||||||
@ -77,6 +134,17 @@ Item {
|
|||||||
right: root.parent.right
|
right: root.parent.right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AnchorChanges {
|
||||||
|
target: moreSettingsButton
|
||||||
|
anchors {
|
||||||
|
verticalCenter: root.verticalCenter
|
||||||
|
horizontalCenter: undefined
|
||||||
|
top: undefined
|
||||||
|
bottom: undefined
|
||||||
|
left: undefined
|
||||||
|
right: root.right
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "BottomEdge"
|
name: "BottomEdge"
|
||||||
@ -93,6 +161,17 @@ Item {
|
|||||||
right: root.parent.right
|
right: root.parent.right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AnchorChanges {
|
||||||
|
target: moreSettingsButton
|
||||||
|
anchors {
|
||||||
|
verticalCenter: root.verticalCenter
|
||||||
|
horizontalCenter: undefined
|
||||||
|
top: undefined
|
||||||
|
bottom: undefined
|
||||||
|
left: undefined
|
||||||
|
right: root.right
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "LeftEdge"
|
name: "LeftEdge"
|
||||||
@ -109,6 +188,17 @@ Item {
|
|||||||
right: root.parent.right
|
right: root.parent.right
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AnchorChanges {
|
||||||
|
target: moreSettingsButton
|
||||||
|
anchors {
|
||||||
|
verticalCenter: undefined
|
||||||
|
horizontalCenter: root.verticalCenter
|
||||||
|
top: undefined
|
||||||
|
bottom: root.bottom
|
||||||
|
left: undefined
|
||||||
|
right: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
State {
|
State {
|
||||||
name: "RightEdge"
|
name: "RightEdge"
|
||||||
@ -125,6 +215,17 @@ Item {
|
|||||||
right: undefined
|
right: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AnchorChanges {
|
||||||
|
target: moreSettingsButton
|
||||||
|
anchors {
|
||||||
|
verticalCenter: undefined
|
||||||
|
horizontalCenter: root.verticalCenter
|
||||||
|
top: undefined
|
||||||
|
bottom: root.bottom
|
||||||
|
left: undefined
|
||||||
|
right: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
//END States
|
//END States
|
||||||
|
Loading…
Reference in New Issue
Block a user