Add (and install) svg for the new krunner interface.
[kdebase/uwolfer.git] / workspace / plasma / plasma / panelview.cpp
blob5abe6fa20dbbc0895c83eeeb30cbfa31df649935
1 /*
2 * Copyright 2007 by Matt Broadstone <mbroadst@kde.org>
3 * Copyright 2007 by Robert Knight <robertknight@gmail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License version 2,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "panelview.h"
22 #include <QApplication>
23 #include <QDesktopWidget>
24 #include <QTimeLine>
26 #include <KWindowSystem>
27 #include <KDebug>
29 #include <plasma/containment.h>
30 #include <plasma/corona.h>
31 #include <plasma/plasma.h>
32 #include <plasma/svg.h>
34 #include "plasmaapp.h"
36 PanelView::PanelView(Plasma::Containment *panel, QWidget *parent)
37 : Plasma::View(panel, parent)
39 Q_ASSERT(qobject_cast<Plasma::Corona*>(panel->scene()));
40 updatePanelGeometry();
42 if (containment()) {
43 connect(containment(), SIGNAL(showAddWidgets()), this, SLOT(showAppletBrowser()));
46 connect(panel, SIGNAL(geometryChanged()), this, SLOT(updatePanelGeometry()));
47 kDebug() << "Panel geometry is" << panel->geometry();
49 // Graphics view setup
50 setFrameStyle(QFrame::NoFrame);
51 //setAutoFillBackground(true);
52 //setDragMode(QGraphicsView::RubberBandDrag);
53 //setCacheMode(QGraphicsView::CacheBackground);
54 setInteractive(true);
55 setAcceptDrops(true);
56 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
59 // KWin setup
60 KWindowSystem::setType(winId(), NET::Dock);
61 KWindowSystem::setState(winId(), NET::Sticky);
62 KWindowSystem::setOnAllDesktops(winId(), true);
64 updateStruts();
68 void PanelView::setLocation(Plasma::Location loc)
70 containment()->setLocation(loc);
71 updatePanelGeometry();
74 Plasma::Location PanelView::location() const
76 return containment()->location();
79 Plasma::Corona *PanelView::corona() const
81 return qobject_cast<Plasma::Corona*>(scene());
84 void PanelView::updatePanelGeometry()
86 kDebug() << "New panel geometry is" << containment()->geometry();
87 QSize size = containment()->size().toSize();
88 QRect geom(QPoint(0,0), size);
89 int screen = containment()->screen();
91 if (screen < 0) {
92 //TODO: is there a valid use for -1 with a panel? floating maybe?
93 screen = 0;
96 QRect screenGeom = QApplication::desktop()->screenGeometry(screen);
98 //FIXME: we need to support center, left, right, etc.. perhaps
99 // pixel precision placed containments as well?
100 switch (location()) {
101 case Plasma::TopEdge:
102 geom.moveTopLeft(screenGeom.topLeft());
103 break;
104 case Plasma::LeftEdge:
105 geom.moveTopLeft(screenGeom.topLeft());
106 break;
107 case Plasma::RightEdge:
108 geom.moveTopLeft(QPoint(screenGeom.right() - size.width() + 1, screenGeom.top()));
109 break;
110 case Plasma::BottomEdge:
111 default:
112 geom.moveTopLeft(QPoint(screenGeom.left(), screenGeom.bottom() - size.height() + 1));
113 break;
116 kDebug() << (QObject*)this << "thinks its panel is at " << geom;
117 setGeometry(geom);
120 void PanelView::showAppletBrowser()
122 PlasmaApp::self()->showAppletBrowser(containment());
125 void PanelView::updateStruts()
127 NETExtendedStrut strut;
129 switch (location())
131 case Plasma::TopEdge:
132 strut.top_width = height();
133 strut.top_start = x();
134 strut.top_end = x() + width() - 1;
135 break;
137 case Plasma::BottomEdge:
138 strut.bottom_width = height();
139 strut.bottom_start = x();
140 strut.bottom_end = x() + width() - 1;
141 break;
143 case Plasma::RightEdge:
144 strut.right_width = width();
145 strut.right_start = y();
146 strut.right_end = y() + height() - 1;
147 break;
149 case Plasma::LeftEdge:
150 strut.left_width = width();
151 strut.left_start = y();
152 strut.left_end = y() + height() - 1;
153 break;
155 default:
156 break;
159 KWindowSystem::setExtendedStrut(winId(), strut.left_width,
160 strut.left_start,
161 strut.left_end,
162 strut.right_width,
163 strut.right_start,
164 strut.right_end,
165 strut.top_width,
166 strut.top_start,
167 strut.top_end,
168 strut.bottom_width,
169 strut.bottom_start,
170 strut.bottom_end);
173 void PanelView::moveEvent(QMoveEvent *event)
175 QWidget::moveEvent(event);
176 updateStruts();
179 void PanelView::resizeEvent(QResizeEvent *event)
181 QWidget::resizeEvent(event);
182 updateStruts();
185 #include "panelview.moc"