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?
KWindowEffects::enableBlurBehind(winId(), true);
connect(this, &View::containmentChanged,
this, &PanelView::manageNewContainment);
//Screen management
connect(screen(), &QScreen::virtualGeometryChanged,
this, &PanelView::positionPanel);
@ -155,21 +152,55 @@ void PanelView::setThickness(int value)
config().writeEntry("thickness", value);
emit thicknessChanged();
}
void PanelView::manageNewContainment()
int PanelView::maximumLength() const
{
connect(containment()->actions()->action("configure"), &QAction::triggered,
this, &PanelView::showPanelController);
return m_maxLength;
}
void PanelView::showPanelController()
void PanelView::setMaximumLength(int length)
{
if (!m_panelConfigView) {
m_panelConfigView = new PanelConfigView(containment(), this);
m_panelConfigView->init();
if (length == m_maxLength) {
return;
}
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()
@ -286,8 +317,11 @@ void PanelView::restore()
}
resize(config().readEntry<int>("length", screen()->size().width()),
config().readEntry<int>("thickness", 32));
}
emit maximumLengthChanged();
emit minimumLengthChanged();
emit offsetChanged();
}
#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(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
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:
explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0);
@ -49,15 +51,21 @@ public:
int thickness() const;
void setThickness(int thickness);
int maximumLength() const;
void setMaximumLength(int length);
int minimumLength() const;
void setMinimumLength(int length);
Q_SIGNALS:
void alignmentChanged();
void offsetChanged();
void screenGeometryChanged();
void thicknessChanged();
void maximumLengthChanged();
void minimumLengthChanged();
private Q_SLOTS:
void manageNewContainment();
void showPanelController();
void positionPanel();
void restore();

View File

@ -34,6 +34,7 @@ Rectangle {
//END properties
//BEGIN UI components
// Offset
Rectangle {
width: 32
height: 32
@ -52,92 +53,189 @@ Rectangle {
}
Component.onCompleted: {
if (panel.location == 5 || panel.location == 6) {
panel.offset = parent.y
parent.y = panel.offset
} else {
panel.offset = parent.x
parent.x = panel.offset
}
}
}
}
//Minimum length
Rectangle {
width: 100
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.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 {
centerIn: parent
}
QtExtras.MouseEventListener {
anchors.fill: parent
property int lastX
property int lastY
property int startMouseX
property int startMouseY
onPressed: {
lastX = mouse.screenX
lastY = mouse.screenY
startMouseX = mouse.x
startMouseY = mouse.y
}
onPositionChanged: {
switch (panel.location) {
//TopEdge
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
Rectangle {
width: 100
height: 32
QtExtras.MouseEventListener {
anchors.fill: parent
property int lastX
property int lastY
property int startMouseX
property int startMouseY
onPressed: {
lastX = mouse.screenX
lastY = mouse.screenY
startMouseX = mouse.x
startMouseY = mouse.y
}
lastX = mouse.screenX
lastY = mouse.screenY
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 {
newLocation = 6; //FIXME: Plasma::RightEdge;
onPositionChanged: {
switch (panel.location) {
//TopEdge
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
}
} else {
if (mouse.screenY < panel.screenGeometry.y + panel.screenGeometry.height-(mouse.screenX-panel.screenGeometry.x)*screenAspect) {
if (panel.location == 5) {
return;
lastX = mouse.screenX
lastY = mouse.screenY
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 {
newLocation = 5; //FIXME: Plasma::LeftEdge;
newLocation = 6; //FIXME: Plasma::RightEdge;
}
} else if(panel.location == 4) {
return;
} 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
print("New Location: " + newLocation);
PlasmaComponents.Label {
text: "Height"
}
}
onReleased: panelResetAnimation.running = true
}
}
ParallelAnimation {