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>
26 #include <KWindowSystem>
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();
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);
56 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
57 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
60 KWindowSystem::setType(winId(), NET::Dock
);
61 KWindowSystem::setState(winId(), NET::Sticky
);
62 KWindowSystem::setOnAllDesktops(winId(), true);
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();
92 //TODO: is there a valid use for -1 with a panel? floating maybe?
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());
104 case Plasma::LeftEdge
:
105 geom
.moveTopLeft(screenGeom
.topLeft());
107 case Plasma::RightEdge
:
108 geom
.moveTopLeft(QPoint(screenGeom
.right() - size
.width() + 1, screenGeom
.top()));
110 case Plasma::BottomEdge
:
112 geom
.moveTopLeft(QPoint(screenGeom
.left(), screenGeom
.bottom() - size
.height() + 1));
116 kDebug() << (QObject
*)this << "thinks its panel is at " << geom
;
120 void PanelView::showAppletBrowser()
122 PlasmaApp::self()->showAppletBrowser(containment());
125 void PanelView::updateStruts()
127 NETExtendedStrut strut
;
131 case Plasma::TopEdge
:
132 strut
.top_width
= height();
133 strut
.top_start
= x();
134 strut
.top_end
= x() + width() - 1;
137 case Plasma::BottomEdge
:
138 strut
.bottom_width
= height();
139 strut
.bottom_start
= x();
140 strut
.bottom_end
= x() + width() - 1;
143 case Plasma::RightEdge
:
144 strut
.right_width
= width();
145 strut
.right_start
= y();
146 strut
.right_end
= y() + height() - 1;
149 case Plasma::LeftEdge
:
150 strut
.left_width
= width();
151 strut
.left_start
= y();
152 strut
.left_end
= y() + height() - 1;
159 KWindowSystem::setExtendedStrut(winId(), strut
.left_width
,
173 void PanelView::moveEvent(QMoveEvent
*event
)
175 QWidget::moveEvent(event
);
179 void PanelView::resizeEvent(QResizeEvent
*event
)
181 QWidget::resizeEvent(event
);
185 #include "panelview.moc"