[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: Re: [PATCH] panel placement at the center (or whatever) of the screen
From: Marco Martin <notmart () gmail ! com>
Date: 2008-04-02 20:39:06
Message-ID: 200804022239.06470.notmart () gmail ! com
[Download RAW message or body]
On Tuesday 01 April 2008, Aaron J. Seigo wrote:
> On Tuesday 01 April 2008, Marco Martin wrote:
> > here it's an early patch to panelview, posting now only to hear if i'm on
> > the right track.
> > the config of the view is saved in plasmarc under [Views] it still uses
> > the id of the panel to differentiate between the various panels.
>
> cool; btw, classes not in lbiplasma don't need to use dptrs ... they have
> no need for BC.
>
> as for altering the containment to get edges shown, yes, there will need to
> be some interaction between view/containment there. perhaps some simple but
> minimal shifting of the containment
well, i feel a little dumb but it's gotta be waay more tricky than i tought :(
now it kinda works, even if i still have not thoroughly tested it (especially
other alignments)
the real problem now is that when i set the geometry of the containment for
the first time it doesn't seem to work (does it need a fully constructed view
to work?) so the left border is not set, and is set only when i manually
change the geometry of the panel.
also when i change the containment geometry in updatePanelGeometry it triggers
updatePanelGeometry again another time, it feels a little bleach, but don't
know how to do it otherwise...
Cheers,
Marco Martin
["panel_moving2.diff" (text/x-diff)]
Index: plasma/panelview.h
===================================================================
--- plasma/panelview.h (revision 792839)
+++ plasma/panelview.h (working copy)
@@ -24,6 +24,7 @@
#include <plasma/view.h>
class QWidget;
+class KConfigGroup;
namespace Plasma
{
@@ -42,6 +43,8 @@
* @arg parent the QWidget this panel is parented to
*/
explicit PanelView(Plasma::Containment *panel, QWidget *parent = 0);
+
+ ~PanelView();
/**
* Sets the location (screen edge) where this panel is positioned.
@@ -59,6 +62,34 @@
*/
Plasma::Corona *corona() const;
+ /**
+ * Sets the offset the left border, the offset is the distance of the left
+ * border of the panel from the left border of the screen when the alignment is
+ * Qt::AlignLeft, right border and right edge if the alignment is Qt::alignRight
+ * and the distance between the center of the panel and the center of the screen \
if + * the alignment is Qt::AlignCenter.
+ * Similar way for vertical panels.
+ * @param newOffset the offset of the panel
+ */
+ void setOffset(int newOffset);
+
+ /**
+ * @return the offset of the panel from the left screen edge
+ */
+ int offset();
+
+ /**
+ * Sets the edge of the screen the panel will be aligned and will grow
+ * @param align the direction (for instance Qt::AlignLeft) means the panel will \
start + * from the left of the screen and grow to the right
+ */
+ void setAlignment(Qt::Alignment align);
+
+ /**
+ * @return the panel alignment
+ */
+ Qt::Alignment alignment();
+
protected:
void updateStruts();
virtual void moveEvent(QMoveEvent *event);
@@ -70,6 +101,12 @@
private:
Plasma::Svg *m_background;
+
+ KConfigGroup *m_mainConfig;
+ KConfigGroup *m_viewConfig;
+
+ int m_offset;
+ Qt::Alignment m_alignment;
};
#endif
Index: plasma/panelview.cpp
===================================================================
--- plasma/panelview.cpp (revision 792839)
+++ plasma/panelview.cpp (working copy)
@@ -25,6 +25,7 @@
#include <KWindowSystem>
#include <KDebug>
+#include <kconfiggroup.h>
#include <plasma/containment.h>
#include <plasma/corona.h>
@@ -33,10 +34,18 @@
#include "plasmaapp.h"
+
PanelView::PanelView(Plasma::Containment *panel, QWidget *parent)
: Plasma::View(panel, parent)
{
Q_ASSERT(qobject_cast<Plasma::Corona*>(panel->scene()));
+
+ m_mainConfig = new KConfigGroup(KGlobal::config(), "Views");
+ m_viewConfig = new KConfigGroup(m_mainConfig, QString::number(panel->id()));
+
+ m_offset = m_viewConfig->readEntry("Offset", 0);
+ m_alignment = (Qt::Alignment)m_viewConfig->readEntry("Alignment", \
(int)Qt::AlignLeft); +
updatePanelGeometry();
if (panel) {
@@ -65,6 +74,11 @@
updateStruts();
}
+PanelView::~PanelView()
+{
+ delete m_mainConfig;
+ delete m_viewConfig;
+}
void PanelView::setLocation(Plasma::Location loc)
{
@@ -84,6 +98,7 @@
void PanelView::updatePanelGeometry()
{
kDebug() << "New panel geometry is" << containment()->geometry();
+
QSize size = containment()->size().toSize();
QRect geom(QPoint(0,0), size);
int screen = containment()->screen();
@@ -95,28 +110,153 @@
QRect screenGeom = QApplication::desktop()->screenGeometry(screen);
- //FIXME: we need to support center, left, right, etc.. perhaps
- // pixel precision placed containments as well?
+ // Don't change the geometry again if a same one was asked
+ if (geom == screenGeom) {
+ return;
+ }
+
+ if (m_alignment != Qt::AlignCenter) {
+ m_offset = qMax(m_offset, 0);
+ }
+
+ //Sanity controls
switch (location()) {
- case Plasma::TopEdge:
- geom.moveTopLeft(screenGeom.topLeft());
- break;
- case Plasma::LeftEdge:
- geom.moveTopLeft(screenGeom.topLeft());
- break;
- case Plasma::RightEdge:
- geom.moveTopLeft(QPoint(screenGeom.right() - size.width() + 1, \
screenGeom.top()));
- break;
- case Plasma::BottomEdge:
- default:
- geom.moveTopLeft(QPoint(screenGeom.left(), screenGeom.bottom() - \
size.height() + 1));
- break;
+ case Plasma::TopEdge:
+ case Plasma::BottomEdge:
+ //resize the panel if is too large
+ if (geom.width() > screenGeom.width()) {
+ geom.setWidth(screenGeom.width());
+ }
+
+ //move the panel left/right if there is not enough room
+ if (m_alignment == Qt::AlignLeft) {
+ if (m_offset + screenGeom.left() + geom.width() > screenGeom.right()) {
+ m_offset = screenGeom.width() - geom.width();
+ }
+ } else if (m_alignment == Qt::AlignRight) {
+ if (screenGeom.right() - m_offset - geom.width() < 0 ) {
+ m_offset = screenGeom.right() - geom.width();
+ }
+ } else if (m_alignment == Qt::AlignCenter) {
+ if (screenGeom.center().x() + m_offset + geom.width()/2 > \
screenGeom.right()) { + m_offset = screenGeom.right() - \
geom.width()/2 - screenGeom.center().x(); + } else if \
(screenGeom.center().x() + m_offset - geom.width()/2 < 0) { + \
m_offset = screenGeom.center().x() - geom.width()/2; + }
+ }
+
+ case Plasma::LeftEdge:
+ case Plasma::RightEdge:
+ //resize the panel if is too tall
+ if (geom.height() > screenGeom.height()) {
+ geom.setHeight(screenGeom.height());
+ }
+
+ //move the panel bottom if there is not enough room
+ //FIXME: still using alignleft/alignright is simpler and less error prone, \
but aligntop/alignbottom is more correct? + if (m_alignment == Qt::AlignLeft) \
{ + if (m_offset + screenGeom.top() + geom.height() > screenGeom.bottom()) \
{ + m_offset = screenGeom.height() - geom.height();
+ }
+ } else if (m_alignment == Qt::AlignRight) {
+ if (screenGeom.bottom() - m_offset - geom.height() < 0) {
+ m_offset = screenGeom.bottom() - geom.height();
+ }
+ } else if (m_alignment == Qt::AlignCenter) {
+ if (screenGeom.center().y() + m_offset + geom.height()/2 > \
screenGeom.right()) { + m_offset = screenGeom.bottom() - \
geom.height()/2 - screenGeom.center().y(); + } else if \
(screenGeom.center().y() + m_offset - geom.width()/2 < 0) { + m_offset \
= screenGeom.center().y() - geom.width()/2; + }
+ }
+
+ //TODO: floating panels (probably they will save their own geometry)
+ default:
+ break;
}
+ //Actual movement
+ switch (location()) {
+ case Plasma::TopEdge:
+ if (m_alignment == Qt::AlignLeft) {
+ geom.moveTopLeft(QPoint(m_offset, screenGeom.top()));
+ } else if (m_alignment == Qt::AlignRight) {
+ geom.moveTopRight(QPoint(m_offset, screenGeom.top()));
+ } else if (m_alignment == Qt::AlignCenter) {
+ geom.moveCenter(QPoint(m_offset, screenGeom.top() + geom.height()/2));
+ }
+
+ //enable borders if needed
+ containment()->setGeometry(QRect(geom.left(), \
containment()->geometry().top(), geom.width(), geom.height())); + break;
+
+ case Plasma::LeftEdge:
+ if (m_alignment == Qt::AlignLeft) {
+ geom.moveTopLeft(QPoint(screenGeom.left(), m_offset));
+ } else if (m_alignment == Qt::AlignRight) {
+ geom.moveBottomLeft(QPoint(screenGeom.left(), m_offset));
+ } else if (m_alignment == Qt::AlignCenter) {
+ geom.moveCenter(QPoint(screenGeom.left()+geom.height()/2, m_offset));
+ }
+
+ //enable borders if needed
+ containment()->setGeometry(QRect(containment()->geometry().left(), \
geom.top(), geom.width(), geom.height())); + break;
+
+ case Plasma::RightEdge:
+ if (m_alignment == Qt::AlignLeft) {
+ geom.moveTopLeft(QPoint(screenGeom.right() - size.width() + 1, \
m_offset)); + } else if (m_alignment == Qt::AlignRight) {
+ geom.moveBottomLeft(QPoint(screenGeom.right() - size.width() + 1, \
m_offset)); + } else if (m_alignment == Qt::AlignCenter) {
+ geom.moveCenter(QPoint(screenGeom.right() - size.width()/2 + 1, \
m_offset)); + }
+
+ //enable borders if needed
+ containment()->setGeometry(QRect(containment()->geometry().left(), \
geom.top(), geom.width(), geom.height())); + break;
+
+ case Plasma::BottomEdge:
+ default:
+ if (m_alignment == Qt::AlignLeft) {
+ geom.moveTopLeft(QPoint(m_offset, screenGeom.bottom() - size.height() + \
1)); + } else if (m_alignment == Qt::AlignRight) {
+ geom.moveTopRight(QPoint(m_offset, screenGeom.bottom() - size.height() + \
1)); + } else if (m_alignment == Qt::AlignCenter) {
+ geom.moveCenter(QPoint(m_offset, screenGeom.bottom() - size.height()/2 + \
1)); + }
+
+ //enable borders if needed
+ containment()->setGeometry(QRect(geom.left(), \
containment()->geometry().top(), geom.width(), geom.height())); + break;
+ }
+
kDebug() << (QObject*)this << "thinks its panel is at " << geom;
+
setGeometry(geom);
+
}
+void PanelView::setOffset(int newOffset)
+{
+ m_offset = newOffset;
+}
+
+int PanelView::offset()
+{
+ return m_offset;
+}
+
+void PanelView::setAlignment(Qt::Alignment align)
+{
+ m_alignment = align;
+}
+
+Qt::Alignment PanelView::alignment()
+{
+ return m_alignment;
+}
+
void PanelView::showAppletBrowser()
{
PlasmaApp::self()->showAppletBrowser(containment());
_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic