[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-panel-devel
Subject: [Panel-devel] minimization to taskbar
From: Jason Stubbs <jasonbstubbs () gmail ! com>
Date: 2007-11-30 16:21:49
Message-ID: 200712010121.49420.jasonbstubbs () gmail ! com
[Download RAW message or body]
Hi all.
I've had a go at getting the task bar to report it's position to kwin.
Rather than copying the code from systemtray, I've moved it into
Plasma::Widget so that it can be reused by anything else that might
need to know this sort of stuff.
Attached are three patches:
* Add associatedViews(), mapToView() and mapFromView() to Widget
* Modify SystemTray to use the new methods
* Add reporting of position to kwin in tasks.cpp
Comments?
--
Jason Stubbs
["widget-views.patch" (text/x-diff)]
Index: workspace/libs/plasma/widgets/widget.cpp
===================================================================
--- workspace/libs/plasma/widgets/widget.cpp (revision 742660)
+++ workspace/libs/plasma/widgets/widget.cpp (working copy)
@@ -25,6 +25,8 @@
#include <limits>
#include <QApplication>
+#include <QGraphicsScene>
+#include <QGraphicsView>
#include <QList>
#include <QPainter>
#include <QPixmapCache>
@@ -479,5 +481,29 @@ void Widget::managingLayoutChanged()
}
}
+QList<QGraphicsView *> Widget::associatedViews() const
+{
+ QList<QGraphicsView *> views;
+ if (!scene()) {
+ return views;
+ }
+ foreach (QGraphicsView *view, scene()->views()) {
+ if (view->sceneRect().intersects(sceneBoundingRect())) {
+ views.append(view);
+ }
+ }
+ return views;
+}
+
+QRectF Widget::mapFromView(const QGraphicsView *view, const QRect &rect) const
+{
+ return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1);
+}
+
+QRect Widget::mapToView(const QGraphicsView *view, const QRectF &rect) const
+{
+ return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1);
+}
+
} // Plasma namespace
Index: workspace/libs/plasma/widgets/widget.h
===================================================================
--- workspace/libs/plasma/widgets/widget.h (revision 742660)
+++ workspace/libs/plasma/widgets/widget.h (working copy)
@@ -30,6 +30,8 @@
#include <plasma/layouts/layoutitem.h>
#include <plasma/plasma_export.h>
+class QGraphicsView;
+
namespace Plasma
{
@@ -242,6 +244,25 @@ TODO: implement once we decide how to ha
virtual QGraphicsItem* graphicsItem();
+ /**
+ * Returns a list of QGraphicsViews that are currently displaying the widget.
+ */
+ QList<QGraphicsView *> associatedViews() const;
+
+ /**
+ * Maps a QRect from a view's coordinates to local coordinates.
+ * @param view the view from which rect should be mapped
+ * @param rect the rect to be mapped
+ */
+ QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const;
+
+ /**
+ * Maps a QRectF from local coordinates to a view's coordinates.
+ * @param view the view to which rect should be mapped
+ * @param rect the rect to be mapped
+ */
+ QRect mapToView(const QGraphicsView *view, const QRectF &rect) const;
+
protected:
/**
* Paints the widget
["systray-views.patch" (text/x-diff)]
Index: workspace/plasma/applets/systemtray/systemtray.cpp
===================================================================
--- workspace/plasma/applets/systemtray/systemtray.cpp (revision 742660)
+++ workspace/plasma/applets/systemtray/systemtray.cpp (working copy)
@@ -39,13 +39,9 @@ QSizeF SystemTray::contentSizeHint() con
return QSizeF();
}
- QRect widgetRect;
- widgetRect.setSize(m_systemTrayWidget->minimumSizeHint());
-
// Transform the size into the coordinates used by our QGraphicsView
- // Using mapToScene() causes us to lose QSize(1, 1) so we add it back
- QSizeF size = m_currentView->mapToScene(widgetRect).boundingRect().size() + QSize(1, 1);
- return size;
+ QRect rect(m_systemTrayWidget->pos(), m_systemTrayWidget->minimumSizeHint());
+ return mapFromView(m_currentView, rect).size();
}
Qt::Orientations SystemTray::expandingDirections() const
@@ -90,27 +86,26 @@ void SystemTray::handleSceneChange(const
}
// Find out which QGraphicsView (if any) that we are visible on
- QGraphicsView *view = findView();
- if (!view) {
- return;
+ QList<QGraphicsView *> views = associatedViews();
+ if (views.isEmpty()) {
+ return;
}
// If the view is different to the view we were previously visible on or we
// had no view up until now, (re)create or reparent our SystemTrayWidget
- if (view != m_currentView) {
- m_currentView = view;
+ if (views.first() != m_currentView) {
+ m_currentView = views.first();
if (m_systemTrayWidget) {
m_systemTrayWidget->setParent(m_currentView);
} else {
- m_systemTrayWidget = new SystemTrayWidget(view);
+ m_systemTrayWidget = new SystemTrayWidget(m_currentView);
connect(m_systemTrayWidget, SIGNAL(sizeShouldChange()), this, SLOT(updateSize()));
}
m_systemTrayWidget->setVisible(true);
}
// Set our SystemTrayWidget's size and position equal to that of this item
- // Using mapFromScene() causes us to gain QSize(1, 1) so we take it off
- QRect rect = m_currentView->mapFromScene(sceneBoundingRect()).boundingRect().adjusted(0, 0, -1, -1);
+ QRect rect = mapToView(m_currentView, boundingRect());
m_systemTrayWidget->setMaximumSize(rect.size());
m_systemTrayWidget->setGeometry(rect);
}
@@ -125,18 +120,6 @@ bool SystemTray::intersectsRegion(const
return false;
}
-QGraphicsView * SystemTray::findView()
-{
- // We may be visible on more than one QGraphicsView but we only take the
- // first because we are only able to display one system tray
- foreach (QGraphicsView *view, m_currentScene->views()) {
- if (view->sceneRect().contains(scenePos())) {
- return view;
- }
- }
- return 0;
-}
-
void SystemTray::updateSize()
{
// Just ask our parent's layout to give us an appropriate size
Index: workspace/plasma/applets/systemtray/systemtray.h
===================================================================
--- workspace/plasma/applets/systemtray/systemtray.h (revision 742660)
+++ workspace/plasma/applets/systemtray/systemtray.h (working copy)
@@ -54,7 +54,6 @@ private slots:
private:
bool intersectsRegion(const QList<QRectF> ®ion);
- QGraphicsView * findView();
// These can all be deleted externally so we guard them
QPointer<SystemTrayWidget> m_systemTrayWidget;
["tasks-views.patch" (text/x-diff)]
Index: workspace/plasma/applets/tasks/tasks.cpp
===================================================================
--- workspace/plasma/applets/tasks/tasks.cpp (revision 742660)
+++ workspace/plasma/applets/tasks/tasks.cpp (working copy)
@@ -29,6 +29,7 @@
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsSceneDragDropEvent>
+#include <QGraphicsView>
#include <QIcon>
#include <QLinearGradient>
#include <QTimeLine>
@@ -491,6 +492,14 @@ void AbstractTaskItem::paint(QPainter *p
// draw icon and text
drawTask(painter, option, widget);
+
+ QList<QGraphicsView *> views = associatedViews();
+ if (!views.isEmpty()) {
+ QGraphicsView *view = views.first();
+ QRect rect = mapToView(view, boundingRect());
+ rect.moveTopLeft(view->mapToGlobal(rect.topLeft()));
+ publishIconGeometry(rect);
+ }
}
void AbstractTaskItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
@@ -715,6 +724,13 @@ void TaskGroupItem::drawBorder(QPainter
}
}
+void TaskGroupItem::publishIconGeometry(const QRect& rect)
+{
+ foreach (TaskEntry entry, _tasks) {
+ entry.task->publishIconGeometry(rect);
+ }
+}
+
StartupTaskItem::StartupTaskItem(QGraphicsItem *parent, QObject *parentObject)
: AbstractTaskItem(parent, parentObject)
{
@@ -728,6 +744,11 @@ void StartupTaskItem::setStartupTask(Sta
setIcon(KIcon(task->icon()));
}
+void StartupTaskItem::publishIconGeometry(const QRect& rect)
+{
+ Q_UNUSED(rect);
+}
+
Startup::StartupPtr StartupTaskItem::startupTask() const
{
return _task;
@@ -821,5 +842,11 @@ void WindowTaskItem::contextMenuEvent(QG
TaskRMBMenu menu( windowTask() );
menu.exec( e->screenPos() );
}
+
+void WindowTaskItem::publishIconGeometry(const QRect& rect)
+{
+ _task->publishIconGeometry(rect);
+}
+
#include "tasks.moc"
Index: workspace/plasma/applets/tasks/tasks.h
===================================================================
--- workspace/plasma/applets/tasks/tasks.h (revision 742660)
+++ workspace/plasma/applets/tasks/tasks.h (working copy)
@@ -192,6 +192,13 @@ public:
// reimplemented from LayoutItem
virtual QSizeF maximumSize() const;
+ /**
+ * Called to with the global geometry of the graphics item.
+ * Implementations should ensure that this is passed to
+ * the relevant TaskPtr.
+ */
+ virtual void publishIconGeometry(const QRect& rect) = 0;
+
protected:
/** Constructs a new task item. */
AbstractTaskItem(QGraphicsItem *parent, QObject *parentObject);
@@ -292,6 +299,7 @@ public:
virtual void activate();
virtual void close();
+ virtual void publishIconGeometry(const QRect& rect);
protected:
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
@@ -322,6 +330,7 @@ public:
// reimplemented, does nothing because there is no window to show
virtual void activate() {};
+ virtual void publishIconGeometry(const QRect& rect);
private:
Startup::StartupPtr _task;
@@ -418,6 +427,7 @@ public:
virtual void activate();
virtual void close();
virtual QSizeF maximumSize() const;
+ virtual void publishIconGeometry(const QRect& rect);
private:
enum DropAction
_______________________________________________
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