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:
parent
843bd1c1e9
commit
a2c5a76eff
@ -65,7 +65,13 @@ PanelView::~PanelView()
|
|||||||
config().writeEntry("offset", m_offset);
|
config().writeEntry("offset", m_offset);
|
||||||
config().writeEntry("max", m_maxLength);
|
config().writeEntry("max", m_maxLength);
|
||||||
config().writeEntry("min", m_minLength);
|
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);
|
config().writeEntry("alignment", (int)m_alignment);
|
||||||
containment()->corona()->requestConfigSync();
|
containment()->corona()->requestConfigSync();
|
||||||
}
|
}
|
||||||
@ -95,6 +101,7 @@ void PanelView::init()
|
|||||||
|
|
||||||
setResizeMode(View::SizeRootObjectToView);
|
setResizeMode(View::SizeRootObjectToView);
|
||||||
setSource(QUrl::fromLocalFile(corona()->package().filePath("views", "Panel.qml")));
|
setSource(QUrl::fromLocalFile(corona()->package().filePath("views", "Panel.qml")));
|
||||||
|
positionPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::Alignment PanelView::alignment() const
|
Qt::Alignment PanelView::alignment() const
|
||||||
@ -124,6 +131,7 @@ void PanelView::setOffset(int offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_offset = offset;
|
m_offset = offset;
|
||||||
|
config().writeEntry("offset", m_offset);
|
||||||
positionPanel();
|
positionPanel();
|
||||||
emit offsetChanged();
|
emit offsetChanged();
|
||||||
}
|
}
|
||||||
@ -153,6 +161,7 @@ void PanelView::positionPanel()
|
|||||||
switch (containment()->location()) {
|
switch (containment()->location()) {
|
||||||
case Plasma::TopEdge:
|
case Plasma::TopEdge:
|
||||||
containment()->setFormFactor(Plasma::Horizontal);
|
containment()->setFormFactor(Plasma::Horizontal);
|
||||||
|
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));
|
||||||
@ -168,6 +177,7 @@ void PanelView::positionPanel()
|
|||||||
|
|
||||||
case Plasma::LeftEdge:
|
case Plasma::LeftEdge:
|
||||||
containment()->setFormFactor(Plasma::Vertical);
|
containment()->setFormFactor(Plasma::Vertical);
|
||||||
|
restore();
|
||||||
switch (m_alignment) {
|
switch (m_alignment) {
|
||||||
case Qt::AlignCenter:
|
case Qt::AlignCenter:
|
||||||
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));
|
||||||
@ -183,6 +193,7 @@ void PanelView::positionPanel()
|
|||||||
|
|
||||||
case Plasma::RightEdge:
|
case Plasma::RightEdge:
|
||||||
containment()->setFormFactor(Plasma::Vertical);
|
containment()->setFormFactor(Plasma::Vertical);
|
||||||
|
restore();
|
||||||
switch (m_alignment) {
|
switch (m_alignment) {
|
||||||
case Qt::AlignCenter:
|
case Qt::AlignCenter:
|
||||||
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));
|
||||||
@ -199,6 +210,7 @@ void PanelView::positionPanel()
|
|||||||
case Plasma::BottomEdge:
|
case Plasma::BottomEdge:
|
||||||
default:
|
default:
|
||||||
containment()->setFormFactor(Plasma::Horizontal);
|
containment()->setFormFactor(Plasma::Horizontal);
|
||||||
|
restore();
|
||||||
switch (m_alignment) {
|
switch (m_alignment) {
|
||||||
case Qt::AlignCenter:
|
case Qt::AlignCenter:
|
||||||
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));
|
||||||
@ -235,7 +247,10 @@ void PanelView::restore()
|
|||||||
if (m_maxLength > 0) {
|
if (m_maxLength > 0) {
|
||||||
setMaximumHeight(m_maxLength);
|
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 {
|
} else {
|
||||||
if (m_minLength > 0) {
|
if (m_minLength > 0) {
|
||||||
setMinimumWidth(m_minLength);
|
setMinimumWidth(m_minLength);
|
||||||
@ -243,10 +258,10 @@ void PanelView::restore()
|
|||||||
if (m_maxLength > 0) {
|
if (m_maxLength > 0) {
|
||||||
setMaximumWidth(m_maxLength);
|
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"
|
#include "moc_panelview.cpp"
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
class PanelView : public View
|
class PanelView : public View
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
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)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -45,7 +46,9 @@ public:
|
|||||||
void setOffset(int offset);
|
void setOffset(int offset);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
void alignmentChanged();
|
||||||
void offsetChanged();
|
void offsetChanged();
|
||||||
|
void screenGeometryChanged();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void manageNewContainment();
|
void manageNewContainment();
|
||||||
|
@ -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.extras 2.0 as PlasmaExtras
|
||||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
import org.kde.plasma.configuration 2.0
|
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
|
//TODO: all of this will be done with desktop components
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@ -40,10 +40,167 @@ Rectangle {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
drag {
|
drag {
|
||||||
target: parent
|
target: parent
|
||||||
axis: Drag.XAxis
|
axis: (panel.location == 5 || panel.location == 6) ? Drag.YAxis : Drag.XAxis
|
||||||
}
|
}
|
||||||
anchors.fill: parent
|
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
|
//END UI components
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QScreen>
|
||||||
#include "plasma/pluginloader.h"
|
#include "plasma/pluginloader.h"
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ View::View(Plasma::Corona *corona, QWindow *parent)
|
|||||||
QSurfaceFormat format;
|
QSurfaceFormat format;
|
||||||
format.setAlphaBufferSize(8);
|
format.setAlphaBufferSize(8);
|
||||||
setFormat(format);
|
setFormat(format);
|
||||||
|
|
||||||
|
connect(screen(), &QScreen::virtualGeometryChanged,
|
||||||
|
this, &View::screenGeometryChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
View::~View()
|
View::~View()
|
||||||
@ -67,7 +71,7 @@ void View::init()
|
|||||||
|
|
||||||
void View::setContainment(Plasma::Containment *cont)
|
void View::setContainment(Plasma::Containment *cont)
|
||||||
{
|
{
|
||||||
Plasma::Location oldLoc = location();
|
Plasma::Location oldLoc = (Plasma::Location)location();
|
||||||
Plasma::FormFactor oldForm = formFactor();
|
Plasma::FormFactor oldForm = formFactor();
|
||||||
|
|
||||||
if (m_containment) {
|
if (m_containment) {
|
||||||
@ -82,7 +86,7 @@ void View::setContainment(Plasma::Containment *cont)
|
|||||||
m_containment = cont;
|
m_containment = cont;
|
||||||
|
|
||||||
if (oldLoc != location()) {
|
if (oldLoc != location()) {
|
||||||
emit locationChanged(location());
|
emit locationChanged((Plasma::Location)location());
|
||||||
}
|
}
|
||||||
if (oldForm != formFactor()) {
|
if (oldForm != formFactor()) {
|
||||||
emit formFactorChanged(formFactor());
|
emit formFactorChanged(formFactor());
|
||||||
@ -120,7 +124,14 @@ Plasma::Containment *View::containment() const
|
|||||||
return m_containment.data();
|
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) {
|
if (!m_containment) {
|
||||||
return Plasma::Desktop;
|
return Plasma::Desktop;
|
||||||
@ -136,4 +147,9 @@ Plasma::FormFactor View::formFactor()
|
|||||||
return m_containment.data()->formFactor();
|
return m_containment.data()->formFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF View::screenGeometry()
|
||||||
|
{
|
||||||
|
return screen()->geometry();
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_view.cpp"
|
#include "moc_view.cpp"
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
class View : public QQuickView
|
class View : public QQuickView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int location READ location WRITE setLocation NOTIFY locationChanged)
|
||||||
|
Q_PROPERTY(QRectF screenGeometry READ screenGeometry NOTIFY screenGeometryChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
explicit View(Plasma::Corona *corona, QWindow *parent = 0);
|
||||||
@ -44,13 +46,19 @@ public:
|
|||||||
void setContainment(Plasma::Containment *cont);
|
void setContainment(Plasma::Containment *cont);
|
||||||
Plasma::Containment *containment() const;
|
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();
|
Plasma::FormFactor formFactor();
|
||||||
|
|
||||||
|
QRectF screenGeometry();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void locationChanged(Plasma::Location location);
|
void locationChanged(Plasma::Location location);
|
||||||
void formFactorChanged(Plasma::FormFactor formFactor);
|
void formFactorChanged(Plasma::FormFactor formFactor);
|
||||||
void containmentChanged();
|
void containmentChanged();
|
||||||
|
void screenGeometryChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plasma::Corona *m_corona;
|
Plasma::Corona *m_corona;
|
||||||
|
Loading…
Reference in New Issue
Block a user