crude controls for panel geometry

This commit is contained in:
Marco Martin 2013-05-08 11:16:38 +02:00
parent 67c901db1a
commit 37cfe4a023
3 changed files with 221 additions and 81 deletions

View File

@ -47,9 +47,6 @@ PanelView::PanelView(Plasma::Corona *corona, QWindow *parent)
//TODO: how to take the shape from the framesvg? //TODO: how to take the shape from the framesvg?
KWindowEffects::enableBlurBehind(winId(), true); KWindowEffects::enableBlurBehind(winId(), true);
connect(this, &View::containmentChanged,
this, &PanelView::manageNewContainment);
//Screen management //Screen management
connect(screen(), &QScreen::virtualGeometryChanged, connect(screen(), &QScreen::virtualGeometryChanged,
this, &PanelView::positionPanel); this, &PanelView::positionPanel);
@ -156,20 +153,54 @@ void PanelView::setThickness(int value)
emit thicknessChanged(); emit thicknessChanged();
} }
int PanelView::maximumLength() const
void PanelView::manageNewContainment()
{ {
connect(containment()->actions()->action("configure"), &QAction::triggered, return m_maxLength;
this, &PanelView::showPanelController);
} }
void PanelView::showPanelController() void PanelView::setMaximumLength(int length)
{ {
if (!m_panelConfigView) { if (length == m_maxLength) {
m_panelConfigView = new PanelConfigView(containment(), this); return;
m_panelConfigView->init();
} }
m_panelConfigView->show();
if (m_minLength > length) {
setMinimumLength(length);
}
if (formFactor() == Plasma::Vertical) {
setMaximumHeight(length);
} else {
setMaximumWidth(length);
}
config().writeEntry("maxLength", length);
m_maxLength = length;
emit maximumLengthChanged();
}
int PanelView::minimumLength() const
{
return m_minLength;
}
void PanelView::setMinimumLength(int length)
{
if (length == m_minLength) {
return;
}
if (m_maxLength < length) {
setMaximumLength(length);
}
if (formFactor() == Plasma::Vertical) {
setMinimumHeight(length);
} else {
setMinimumWidth(length);
}
config().writeEntry("minLength", length);
m_minLength = length;
emit minimumLengthChanged();
} }
void PanelView::positionPanel() void PanelView::positionPanel()
@ -286,8 +317,11 @@ void PanelView::restore()
} }
resize(config().readEntry<int>("length", screen()->size().width()), resize(config().readEntry<int>("length", screen()->size().width()),
config().readEntry<int>("thickness", 32)); config().readEntry<int>("thickness", 32));
} }
emit maximumLengthChanged();
emit minimumLengthChanged();
emit offsetChanged();
} }
#include "moc_panelview.cpp" #include "moc_panelview.cpp"

View File

@ -31,6 +31,8 @@ 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 maximumLength READ maximumLength WRITE setMaximumLength NOTIFY maximumLengthChanged)
Q_PROPERTY(int minimumLength READ minimumLength WRITE setMinimumLength NOTIFY minimumLengthChanged)
public: public:
explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0); explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0);
@ -49,15 +51,21 @@ public:
int thickness() const; int thickness() const;
void setThickness(int thickness); void setThickness(int thickness);
int maximumLength() const;
void setMaximumLength(int length);
int minimumLength() const;
void setMinimumLength(int length);
Q_SIGNALS: Q_SIGNALS:
void alignmentChanged(); void alignmentChanged();
void offsetChanged(); void offsetChanged();
void screenGeometryChanged(); void screenGeometryChanged();
void thicknessChanged(); void thicknessChanged();
void maximumLengthChanged();
void minimumLengthChanged();
private Q_SLOTS: private Q_SLOTS:
void manageNewContainment();
void showPanelController();
void positionPanel(); void positionPanel();
void restore(); void restore();

View File

@ -34,6 +34,7 @@ Rectangle {
//END properties //END properties
//BEGIN UI components //BEGIN UI components
// Offset
Rectangle { Rectangle {
width: 32 width: 32
height: 32 height: 32
@ -52,92 +53,189 @@ Rectangle {
} }
Component.onCompleted: { Component.onCompleted: {
if (panel.location == 5 || panel.location == 6) { if (panel.location == 5 || panel.location == 6) {
panel.offset = parent.y parent.y = panel.offset
} else { } else {
panel.offset = parent.x parent.x = panel.offset
} }
} }
} }
} }
//Minimum length
Rectangle { Rectangle {
width: 100 width: 32
height: 32 height: 32
MouseArea {
drag {
target: parent
axis: (panel.location == 5 || panel.location == 6) ? Drag.YAxis : Drag.XAxis
}
anchors.fill: parent
onPositionChanged: {
if (panel.location == 5 || panel.location == 6) {
panel.minimumLength = parent.y
} else {
panel.minimumLength = parent.x
}
}
Component.onCompleted: {
if (panel.location == 5 || panel.location == 6) {
parent.y = panel.minimumLength
} else {
parent.x = panel.minimumLength
}
}
}
}
//Maximum length
Rectangle {
width: 32
height: 32
MouseArea {
drag {
target: parent
axis: (panel.location == 5 || panel.location == 6) ? Drag.YAxis : Drag.XAxis
}
anchors.fill: parent
onPositionChanged: {
if (panel.location == 5 || panel.location == 6) {
panel.maximumLength = parent.y
} else {
panel.maximumLength = parent.x
}
}
Component.onCompleted: {
if (panel.location == 5 || panel.location == 6) {
parent.y = panel.maximumLength
} else {
parent.x = panel.maximumLength
}
}
}
}
Row {
anchors { anchors {
centerIn: parent centerIn: parent
} }
QtExtras.MouseEventListener { Rectangle {
anchors.fill: parent width: 100
property int lastX height: 32
property int lastY
property int startMouseX QtExtras.MouseEventListener {
property int startMouseY anchors.fill: parent
onPressed: { property int lastX
lastX = mouse.screenX property int lastY
lastY = mouse.screenY property int startMouseX
startMouseX = mouse.x property int startMouseY
startMouseY = mouse.y onPressed: {
} lastX = mouse.screenX
onPositionChanged: { lastY = mouse.screenY
switch (panel.location) { startMouseX = mouse.x
//TopEdge startMouseY = mouse.y
case 3:
configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
panel.y = configDialog.y - panel.height
break
//LeftEdge
case 5:
configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
panel.x = configDialog.x - panel.width
break;
//RightEdge
case 6:
configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
panel.x = configDialog.x + configDialog.width
break;
//BottomEdge
case 4:
default:
configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
panel.y = configDialog.y + configDialog.height
} }
onPositionChanged: {
lastX = mouse.screenX switch (panel.location) {
lastY = mouse.screenY //TopEdge
case 3:
var screenAspect = panel.screenGeometry.height / panel.screenGeometry.width configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
var newLocation = panel.location panel.y = configDialog.y - panel.height
break
if (mouse.screenY < panel.screenGeometry.y+(mouse.screenX-panel.screenGeometry.x)*screenAspect) { //LeftEdge
if (mouse.screenY < panel.screenGeometry.y + panel.screenGeometry.height-(mouse.screenX-panel.screenGeometry.x)*screenAspect) { case 5:
if (panel.location == 3) { configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
return; panel.x = configDialog.x - panel.width
} else { break;
newLocation = 3; //FIXME: Plasma::TopEdge; //RightEdge
} case 6:
} else if (panel.location == 6) { configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
return; panel.x = configDialog.x + configDialog.width
} else { break;
newLocation = 6; //FIXME: Plasma::RightEdge; //BottomEdge
case 4:
default:
configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
panel.y = configDialog.y + configDialog.height
} }
} else { lastX = mouse.screenX
if (mouse.screenY < panel.screenGeometry.y + panel.screenGeometry.height-(mouse.screenX-panel.screenGeometry.x)*screenAspect) { lastY = mouse.screenY
if (panel.location == 5) {
return; var screenAspect = panel.screenGeometry.height / panel.screenGeometry.width
var newLocation = panel.location
if (mouse.screenY < panel.screenGeometry.y+(mouse.screenX-panel.screenGeometry.x)*screenAspect) {
if (mouse.screenY < panel.screenGeometry.y + panel.screenGeometry.height-(mouse.screenX-panel.screenGeometry.x)*screenAspect) {
if (panel.location == 3) {
return;
} else {
newLocation = 3; //FIXME: Plasma::TopEdge;
}
} else if (panel.location == 6) {
return;
} else { } else {
newLocation = 5; //FIXME: Plasma::LeftEdge; newLocation = 6; //FIXME: Plasma::RightEdge;
} }
} else if(panel.location == 4) {
return;
} else { } else {
newLocation = 4; //FIXME: Plasma::BottomEdge; if (mouse.screenY < panel.screenGeometry.y + panel.screenGeometry.height-(mouse.screenX-panel.screenGeometry.x)*screenAspect) {
if (panel.location == 5) {
return;
} else {
newLocation = 5; //FIXME: Plasma::LeftEdge;
}
} else if(panel.location == 4) {
return;
} else {
newLocation = 4; //FIXME: Plasma::BottomEdge;
}
}
panel.location = newLocation
print("New Location: " + newLocation);
}
onReleased: panelResetAnimation.running = true
PlasmaComponents.Label {
text: "Position"
}
}
}
Rectangle {
width: 100
height: 32
QtExtras.MouseEventListener {
anchors.fill: parent
property int startMouseX
property int startMouseY
onPressed: {
startMouseX = mouse.x
startMouseY = mouse.y
}
onPositionChanged: {
switch (panel.location) {
//TopEdge
case 3:
configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
panel.thickness = configDialog.y - panel.y
//LeftEdge
case 5:
configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
panel.thickness = configDialog.x - panel.x
//RightEdge
case 6:
configDialog.x = mouse.screenX - mapToItem(root, startMouseX, 0).x
panel.thickness = (panel.x + panel.width) - (configDialog.x + configDialog.width)
//BottomEdge
case 4:
default:
configDialog.y = mouse.screenY - mapToItem(root, 0, startMouseY).y
panel.thickness = (panel.y + panel.height) - (configDialog.y + configDialog.height)
} }
} }
panel.location = newLocation PlasmaComponents.Label {
print("New Location: " + newLocation); text: "Height"
}
} }
onReleased: panelResetAnimation.running = true
} }
} }
ParallelAnimation { ParallelAnimation {