add more properties to views

control them with the panel controller
probably will change architecture: seems safer to put the panel controller in an "expanded" panelview instead?
This commit is contained in:
Marco Martin 2013-03-22 14:39:33 +01:00
parent 843bd1c1e9
commit a2c5a76eff
5 changed files with 211 additions and 12 deletions

View File

@ -65,7 +65,13 @@ PanelView::~PanelView()
config().writeEntry("offset", m_offset);
config().writeEntry("max", m_maxLength);
config().writeEntry("min", m_minLength);
config().writeEntry("size", size());
if (formFactor() == Plasma::Vertical) {
config().writeEntry("length", size().height());
config().writeEntry("thickness", size().width());
} else {
config().writeEntry("length", size().width());
config().writeEntry("thickness", size().height());
}
config().writeEntry("alignment", (int)m_alignment);
containment()->corona()->requestConfigSync();
}
@ -95,6 +101,7 @@ void PanelView::init()
setResizeMode(View::SizeRootObjectToView);
setSource(QUrl::fromLocalFile(corona()->package().filePath("views", "Panel.qml")));
positionPanel();
}
Qt::Alignment PanelView::alignment() const
@ -124,6 +131,7 @@ void PanelView::setOffset(int offset)
}
m_offset = offset;
config().writeEntry("offset", m_offset);
positionPanel();
emit offsetChanged();
}
@ -153,6 +161,7 @@ void PanelView::positionPanel()
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));
@ -168,6 +177,7 @@ void PanelView::positionPanel()
case Plasma::LeftEdge:
containment()->setFormFactor(Plasma::Vertical);
restore();
switch (m_alignment) {
case Qt::AlignCenter:
setPosition(QPoint(s->virtualGeometry().left(), s->virtualGeometry().center().y()) + QPoint(0, m_offset));
@ -183,6 +193,7 @@ void PanelView::positionPanel()
case Plasma::RightEdge:
containment()->setFormFactor(Plasma::Vertical);
restore();
switch (m_alignment) {
case Qt::AlignCenter:
setPosition(QPoint(s->virtualGeometry().right(), s->virtualGeometry().center().y()) - QPoint(width(), 0) + QPoint(0, m_offset - size().height()/2));
@ -199,6 +210,7 @@ void PanelView::positionPanel()
case Plasma::BottomEdge:
default:
containment()->setFormFactor(Plasma::Horizontal);
restore();
switch (m_alignment) {
case Qt::AlignCenter:
setPosition(QPoint(s->virtualGeometry().center().x(), s->virtualGeometry().bottom()) + QPoint(m_offset - size().width()/2, 0));
@ -235,7 +247,10 @@ void PanelView::restore()
if (m_maxLength > 0) {
setMaximumHeight(m_maxLength);
}
resize(config().readEntry<QSize>("size", QSize(32, screen()->size().width())));
resize(config().readEntry<int>("thickness", 32),
config().readEntry<int>("length", screen()->size().height()));
//Horizontal
} else {
if (m_minLength > 0) {
setMinimumWidth(m_minLength);
@ -243,10 +258,10 @@ void PanelView::restore()
if (m_maxLength > 0) {
setMaximumWidth(m_maxLength);
}
resize(config().readEntry<QSize>("size", QSize(screen()->size().height(), 32)));
resize(config().readEntry<int>("length", screen()->size().width()),
config().readEntry<int>("thickness", 32));
}
positionPanel();
}
#include "moc_panelview.cpp"

View File

@ -28,6 +28,7 @@
class PanelView : public View
{
Q_OBJECT
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged)
public:
@ -45,7 +46,9 @@ public:
void setOffset(int offset);
Q_SIGNALS:
void alignmentChanged();
void offsetChanged();
void screenGeometryChanged();
private Q_SLOTS:
void manageNewContainment();

View File

@ -21,7 +21,7 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.configuration 2.0
import org.kde.qtextracomponents 2.0 as QtExtras
//TODO: all of this will be done with desktop components
Rectangle {
@ -40,10 +40,167 @@ Rectangle {
MouseArea {
drag {
target: parent
axis: Drag.XAxis
axis: (panel.location == 5 || panel.location == 6) ? Drag.YAxis : Drag.XAxis
}
anchors.fill: parent
onPositionChanged: panel.offset = parent.x
onPositionChanged: {
if (panel.location == 5 || panel.location == 6) {
panel.offset = parent.y
} else {
panel.offset = parent.x
}
}
Component.onCompleted: {
if (panel.location == 5 || panel.location == 6) {
panel.offset = parent.y
} else {
panel.offset = parent.x
}
}
}
}
Rectangle {
width: 100
height: 32
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
}
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;
}
} else {
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
if (panel.location == 5 || panel.location == 6) {
configDialog.y = panel.screenGeometry.y
root.width = 100
root.height = panel.screenGeometry.height
} else {
configDialog.x = panel.screenGeometry.x
root.height = 100
root.width = panel.screenGeometry.width
}
print("New Location: " + newLocation);
}
onReleased: panelResetAnimation.running = true
}
}
ParallelAnimation {
id: panelResetAnimation
NumberAnimation {
target: panel
properties: (panel.location == 5 || panel.location == 6) ? "x" : "y"
to: {
switch (panel.location) {
//TopEdge
case 3:
return 0
break
//LeftEdge
case 5:
return 0
break;
//RightEdge
case 6:
return panel.screenGeometry.y + panel.screenGeometry.height - panel.height
break;
//BottomEdge
case 4:
default:
return panel.screenGeometry.x + panel.screenGeometry.width - panel.width
}
}
duration: 150
}
NumberAnimation {
target: configDialog
properties: "y"
to: {
panel.height
switch (panel.location) {
//TopEdge
case 3:
return panel.height
break
//LeftEdge
case 5:
return panel.width
break;
//RightEdge
case 6:
return panel.x - configDialog.width
break;
//BottomEdge
case 4:
default:
return panel.y - configDialog.height
}
}
duration: 150
}
}
//END UI components

View File

@ -22,6 +22,7 @@
#include <QQuickItem>
#include <QQmlContext>
#include <QTimer>
#include <QScreen>
#include "plasma/pluginloader.h"
@ -34,6 +35,9 @@ View::View(Plasma::Corona *corona, QWindow *parent)
QSurfaceFormat format;
format.setAlphaBufferSize(8);
setFormat(format);
connect(screen(), &QScreen::virtualGeometryChanged,
this, &View::screenGeometryChanged);
}
View::~View()
@ -67,7 +71,7 @@ void View::init()
void View::setContainment(Plasma::Containment *cont)
{
Plasma::Location oldLoc = location();
Plasma::Location oldLoc = (Plasma::Location)location();
Plasma::FormFactor oldForm = formFactor();
if (m_containment) {
@ -82,7 +86,7 @@ void View::setContainment(Plasma::Containment *cont)
m_containment = cont;
if (oldLoc != location()) {
emit locationChanged(location());
emit locationChanged((Plasma::Location)location());
}
if (oldForm != formFactor()) {
emit formFactorChanged(formFactor());
@ -120,7 +124,14 @@ Plasma::Containment *View::containment() const
return m_containment.data();
}
Plasma::Location View::location()
//FIXME: wrong types
void View::setLocation(int location)
{
return m_containment.data()->setLocation((Plasma::Location)location);
}
//FIXME: wrong types
int View::location() const
{
if (!m_containment) {
return Plasma::Desktop;
@ -136,4 +147,9 @@ Plasma::FormFactor View::formFactor()
return m_containment.data()->formFactor();
}
QRectF View::screenGeometry()
{
return screen()->geometry();
}
#include "moc_view.cpp"

View File

@ -29,6 +29,8 @@
class View : public QQuickView
{
Q_OBJECT
Q_PROPERTY(int location READ location WRITE setLocation NOTIFY locationChanged)
Q_PROPERTY(QRectF screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
public:
explicit View(Plasma::Corona *corona, QWindow *parent = 0);
@ -44,13 +46,19 @@ public:
void setContainment(Plasma::Containment *cont);
Plasma::Containment *containment() const;
Plasma::Location location();
//FIXME: Plasma::Location should be something qml can understand
int location() const;
void setLocation(int location);
Plasma::FormFactor formFactor();
QRectF screenGeometry();
Q_SIGNALS:
void locationChanged(Plasma::Location location);
void formFactorChanged(Plasma::FormFactor formFactor);
void containmentChanged();
void screenGeometryChanged();
private:
Plasma::Corona *m_corona;