[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    [PATCH] panel placement at the center (or whatever) of the screen
From:       Marco Martin <notmart () gmail ! com>
Date:       2008-03-30 18:37:13
Message-ID: 200803302037.14097.notmart () gmail ! com
[Download RAW message or body]

Hi,
This patch allows a different placement for panels with a lenght < of the 
screen width (or height) to obtain something like this:
 http://www.notmart.org/misc/centerpanel.jpg
there is a new config param in the config dialog of panel, for lack of better 
words i've called it "offset" at the moment (but yeah, the config dialog 
should be killed anyway...)
i've tried it with both vertical and horizontal panels and it seem to behave 
quite well.

Cheers,
Marco Martin

["panel_moving.diff" (text/x-diff)]

Index: libs/plasma/containment.cpp
===================================================================
--- libs/plasma/containment.cpp	(revision 791371)
+++ libs/plasma/containment.cpp	(working copy)
@@ -199,7 +199,7 @@
     kDebug() << "    formfactor:" << group->readEntry("formfactor", (int)d->formFactor);
     kDebug() << "    screen:" << group->readEntry("screen", d->screen);*/
 
-    QRectF geo = group->readEntry("geometry", geometry());
+    QRectF geo = group->readEntry("geometry", QRect(QPoint(0,0), geometry().size().toSize()));
     //override max/min
     if (geo.size() != geo.size().boundedTo(maximumSize())) {
         setMaximumSize(maximumSize().expandedTo(geo.size()));
@@ -207,11 +207,12 @@
     if (geo.size() != geo.size().expandedTo(minimumSize())) {
         setMinimumSize(minimumSize().boundedTo(geo.size()));
     }
-    setGeometry(geo);
 
     setLocation((Plasma::Location)group->readEntry("location", (int)d->location));
     setFormFactor((Plasma::FormFactor)group->readEntry("formfactor", (int)d->formFactor));
     setScreen(group->readEntry("screen", d->screen));
+
+    setGeometry(geo);
 }
 
 void Containment::saveConstraints(KConfigGroup* group) const
@@ -1007,19 +1008,21 @@
     }
 
     kDebug() << "positioning" << (horiz ? "" : "non-") << "horizontal panel; forced?" << force;
+
     // give a space equal to the height again of the last item so there is
     // room to grow.
     QPointF newPos;
     if (horiz) {
         bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
         //TODO: fix x position for non-flush-left panels
-        kDebug() << "moved to" << QPointF(0, bottom - size().height());
-        newPos = QPointF(0, bottom - size().height());
+        kDebug() << "moved to" << QPointF(geometry().left(), bottom - size().height());
+        newPos = QPointF(geometry().left(), bottom - size().height());
     } else {
         bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
         //TODO: fix y position for non-flush-top panels
-        kDebug() << "moved to" << QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height());
-        newPos = QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height());
+        kDebug() << "moved to" << QPointF(bottom + size().width(), geometry().top());
+
+        newPos = QPointF(bottom + size().width(), geometry().top());
     }
 
     d->positioning = true;
Index: plasma/containments/panel/panel.cpp
===================================================================
--- plasma/containments/panel/panel.cpp	(revision 791805)
+++ plasma/containments/panel/panel.cpp	(working copy)
@@ -56,6 +56,7 @@
     setContainmentType(Containment::PanelContainment);
 
     connect(Plasma::Theme::self(), SIGNAL(changed()), this, SLOT(themeUpdated()));
+
     //make sure the default size is picked up
     resize(m_currentSize);
 }
@@ -275,17 +276,20 @@
         QRectF screenRect = screen() >= 0 ? QApplication::desktop()->screenGeometry(screen()) : geometry();
         int screenlength = 0;
         int currentlength = 0;
+        int currentOffset = 0;
         switch (location()) {
             case BottomEdge:
             case TopEdge:
             case Floating:
                 screenlength = screenRect.width();
                 currentlength = m_currentSize.width();
+                currentOffset = pos().x();
                 break;
             case RightEdge:
             case LeftEdge:
                 screenlength = screenRect.height();
                 currentlength = m_currentSize.height();
+                currentOffset = pos().y();
                 break;
             default:
                 kDebug() << "shouldn't happen!" << location();
@@ -295,11 +299,19 @@
         m_lengthEdit->setValue(currentlength);
         l->addWidget(m_lengthEdit, 2, 1);
 
+
+        QLabel *offsetLabel = new QLabel(i18n("Offset:"), p);
+        l->addWidget(offsetLabel, 3, 0);
+        m_offsetEdit = new KIntNumInput(p);
+        m_offsetEdit->setRange(0, screenlength);
+        m_offsetEdit->setValue(currentOffset);
+        l->addWidget(m_offsetEdit, 3, 1);
+
         QLabel *locationLabel = new QLabel(i18n("Location:"), p);
-        l->addWidget(locationLabel, 3, 0);
+        l->addWidget(locationLabel, 4, 0);
         m_locationCombo = new QComboBox(p);
         locationLabel->setBuddy(m_locationCombo);
-        l->addWidget(m_locationCombo, 3, 1);
+        l->addWidget(m_locationCombo, 4, 1);
         m_locationCombo->addItem(i18n("Bottom"), Plasma::BottomEdge);
         m_locationCombo->addItem(i18n("Top"), Plasma::TopEdge);
         m_locationCombo->addItem(i18n("Right"), Plasma::RightEdge);
@@ -356,10 +368,16 @@
         m_currentSize = newSize;
         setFormFactorFromLocation(newLoc);
         setLocation(newLoc);
-    } else if (newSize != m_currentSize) {
+    }
+    if (newSize != m_currentSize) {
         updateSize(newSize);
     }
 
+    if (formFactor() == Horizontal) {
+        setGeometry(QRect(m_offsetEdit->value(), geometry().top(), geometry().width(), geometry().height()));
+    } else if (formFactor() == Vertical) {
+        setPos(geometry().left(), m_offsetEdit->value());
+    }
 }
 
 void Panel::setFormFactorFromLocation(Plasma::Location loc) {
Index: plasma/containments/panel/panel.h
===================================================================
--- plasma/containments/panel/panel.h	(revision 791371)
+++ plasma/containments/panel/panel.h	(working copy)
@@ -79,6 +79,7 @@
     QComboBox* m_sizeCombo;
     KIntNumInput* m_sizeEdit;
     KIntNumInput* m_lengthEdit;
+    KIntNumInput* m_offsetEdit;
     QComboBox* m_locationCombo;
     QAction* m_appletBrowserAction;
     QAction* m_configureAction;
Index: plasma/plasma/panelview.cpp
===================================================================
--- plasma/plasma/panelview.cpp	(revision 791371)
+++ plasma/plasma/panelview.cpp	(working copy)
@@ -84,9 +84,11 @@
 void PanelView::updatePanelGeometry()
 {
     kDebug() << "New panel geometry is" << containment()->geometry();
+
     QSize size = containment()->size().toSize();
-    QRect geom(QPoint(0,0), size);
+    QRect geom = containment()->geometry().toRect();
     int screen = containment()->screen();
+    int offset = 0;
 
     if (screen < 0) {
         //TODO: is there a valid use for -1 with a panel? floating maybe?
@@ -95,26 +97,60 @@
 
     QRect screenGeom = QApplication::desktop()->screenGeometry(screen);
 
+    // Don't change the geometry again if a same one was asked
+    if (geom == screenGeom) {
+        return;
+    }
+
+
     //FIXME: we need to support center, left, right, etc.. perhaps
     //       pixel precision placed containments as well?
     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:
+        if (geom.left() > 0 && geom.left() < screenGeom.right()) {
+            offset = screenGeom.left() + geom.left();
+        } else {
+            offset = screenGeom.left();
+        }
+        geom.moveTopLeft(QPoint(offset, screenGeom.top()));
+        break;
+
+    case Plasma::LeftEdge:
+        if (geom.top() > 0 && geom.top() < screenGeom.bottom()) {
+            offset = screenGeom.top() + geom.top();
+        } else {
+            offset = screenGeom.top();
+        }
+        geom.moveTopLeft(QPoint(screenGeom.left(), offset));
+        break;
+
+    case Plasma::RightEdge:
+        if (geom.top() > 0 && geom.top() < screenGeom.bottom()) {
+            offset = screenGeom.top() + geom.top();
+        } else {
+            offset = screenGeom.top();
+        }
+        geom.moveTopLeft(QPoint(screenGeom.right() - size.width() + 1, offset));
+        break;
+
+    case Plasma::BottomEdge:
+    default:
+        if (geom.left() > 0 && geom.left() < screenGeom.right()) {
+            offset = screenGeom.left() + geom.left();
+        } else {
+            offset = screenGeom.left();
+        }
+        geom.moveTopLeft(QPoint(offset, screenGeom.bottom() - size.height() + 1));
+        break;
     }
 
+    //cut away things that would exit from screen
+    geom = screenGeom.intersect(geom);
+
     kDebug() << (QObject*)this << "thinks its panel is at " << geom;
+
     setGeometry(geom);
+
 }
 
 void PanelView::showAppletBrowser()


_______________________________________________
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