2 * Copyright 2007 Aaron Seigo <aseigo@kde.org>
3 * Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
4 * Copyright 2007 André Duffeck <duffeck@kde.org>
5 * Copyright 2008 Chani Armitage <chanika@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details
17 * You should have received a copy of the GNU Library General Public
18 * License along with this program; if not, write to the
19 * Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "saverview.h"
28 //#include <KWindowSystem>
30 #include <Plasma/Applet>
31 #include <Plasma/Corona>
32 #include <Plasma/Containment>
35 #include "appletbrowser.h"
36 #include "plasmaapp.h"
38 static const int SUPPRESS_SHOW_TIMEOUT
= 500; // Number of millis to prevent reshow of dashboard
40 SaverView::SaverView(Plasma::Containment
*containment
, QWidget
*parent
)
41 : Plasma::View(containment
, parent
),
43 m_suppressShow(false),
46 setWindowFlags(Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint
|
47 Qt::X11BypassWindowManagerHint
);
48 if (!PlasmaApp::hasComposite()) {
49 setAutoFillBackground(false);
50 setAttribute(Qt::WA_NoSystemBackground
);
53 //app is doing this for us - if needed
54 //QDesktopWidget *desktop = QApplication::desktop();
55 //setGeometry(desktop->screenGeometry(containment->screen()));
57 setWallpaperEnabled(!PlasmaApp::hasComposite());
59 installEventFilter(this);
62 SaverView::~SaverView()
64 delete m_appletBrowser
;
67 void SaverView::enableSetupMode()
75 void SaverView::disableSetupMode()
83 void SaverView::drawBackground(QPainter
* painter
, const QRectF
& rect
)
85 if (PlasmaApp::hasComposite()) {
86 painter
->setCompositionMode(QPainter::CompositionMode_Source
);
87 painter
->fillRect(rect
, QColor(0, 0, 0, 0));
88 //FIXME kwin's shadow effect is getting drawn behind me. do not want.
90 Plasma::View::drawBackground(painter
, rect
);
94 void SaverView::showAppletBrowser()
96 if (!m_appletBrowser
) {
97 m_appletBrowser
= new Plasma::AppletBrowser(this, Qt::FramelessWindowHint
);
98 m_appletBrowser
->setContainment(containment());
99 //TODO: make this proportional to the screen
100 m_appletBrowser
->setInitialSize(QSize(400, 400));
101 m_appletBrowser
->setApplication();
102 m_appletBrowser
->setWindowTitle(i18n("Add Widgets"));
103 QPalette p
= m_appletBrowser
->palette();
104 p
.setBrush(QPalette::Background
, QBrush(QColor(0, 0, 0, 180)));
105 m_appletBrowser
->setPalette(p
);
106 m_appletBrowser
->setBackgroundRole(QPalette::Background
);
107 m_appletBrowser
->setAutoFillBackground(true);
108 m_appletBrowser
->setWindowFlags(Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint
|
109 Qt::X11BypassWindowManagerHint
);
110 //KWindowSystem::setState(m_appletBrowser->winId(), NET::KeepAbove|NET::SkipTaskbar);
111 m_appletBrowser
->move(0, 0);
112 m_appletBrowser
->installEventFilter(this);
115 //TODO give the filter kbd focus
116 m_appletBrowser
->setHidden(m_appletBrowser
->isVisible());
119 void SaverView::hideAppletBrowser()
121 if (m_appletBrowser
) {
122 m_appletBrowser
->hide();
126 void SaverView::appletBrowserDestroyed()
131 void SaverView::paintEvent(QPaintEvent
*event
)
133 Plasma::View::paintEvent(event
);
138 // now draw a little label reminding the user their screen's not quite locked
139 const QRect r
= rect();
140 const QString text
= i18n("Setup Mode - Screen is NOT locked");
143 const QFontMetrics
fm(f
);
144 const int margin
= 6;
145 const int textWidth
= fm
.width(text
);
146 const QPoint
centered(r
.width() / 2 - textWidth
/ 2 - margin
, r
.y());
147 const QRect
boundingBox(centered
, QSize(margin
* 2 + textWidth
, fm
.height() + margin
* 2));
149 if (!viewport() || !event
->rect().intersects(boundingBox
)) {
154 box
.moveTo(boundingBox
.topLeft());
155 box
.lineTo(boundingBox
.bottomLeft() + QPoint(0, -margin
* 2));
156 box
.quadTo(boundingBox
.bottomLeft(), boundingBox
.bottomLeft() + QPoint(margin
* 2, 0));
157 box
.lineTo(boundingBox
.bottomRight() + QPoint(-margin
* 2, 0));
158 box
.quadTo(boundingBox
.bottomRight(), boundingBox
.bottomRight() + QPoint(0, -margin
* 2));
159 box
.lineTo(boundingBox
.topRight());
162 QPainter
painter(viewport());
163 painter
.setRenderHint(QPainter::Antialiasing
);
165 //kDebug() << "******************** painting from" << centered << boundingBox << rect() << event->rect();
166 QColor highlight
= palette().highlight().color();
167 highlight
.setAlphaF(0.7);
168 painter
.setPen(highlight
.darker());
169 painter
.setBrush(highlight
);
170 painter
.drawPath(box
);
171 painter
.setPen(palette().highlightedText().color());
172 painter
.drawText(boundingBox
, Qt::AlignCenter
| Qt::AlignVCenter
, text
);
175 bool SaverView::eventFilter(QObject
*watched
, QEvent
*event
)
177 if (watched
!= m_appletBrowser
) {
178 /*if (event->type() == QEvent::MouseButtonPress) {
179 QMouseEvent *me = static_cast<QMouseEvent *>(event);
180 if (me->button() == Qt::LeftButton) {
187 if (event
->type() == QEvent::MouseButtonPress
) {
188 QMouseEvent
*me
= static_cast<QMouseEvent
*>(event
);
189 m_appletBrowserDragStart
= me
->globalPos();
190 } else if (event
->type() == QEvent::MouseMove
&& m_appletBrowserDragStart
!= QPoint()) {
191 QMouseEvent
*me
= static_cast<QMouseEvent
*>(event
);
192 QPoint newPos
= me
->globalPos();
193 QPoint curPos
= m_appletBrowser
->pos();
197 if (curPos
.y() == 0 || curPos
.y() + m_appletBrowser
->height() >= height()) {
198 x
= curPos
.x() + (newPos
.x() - m_appletBrowserDragStart
.x());
201 } else if (x
+ m_appletBrowser
->width() > width()) {
202 x
= width() - m_appletBrowser
->width();
206 if (x
== 0 || x
+ m_appletBrowser
->width() >= width()) {
207 y
= m_appletBrowser
->y() + (newPos
.y() - m_appletBrowserDragStart
.y());
211 } else if (y
+ m_appletBrowser
->height() > height()) {
212 y
= height() - m_appletBrowser
->height();
215 m_appletBrowser
->move(x
, y
);
216 m_appletBrowserDragStart
= newPos
;
217 } else if (event
->type() == QEvent::MouseButtonRelease
) {
218 m_appletBrowserDragStart
= QPoint();
224 void SaverView::showView()
227 if (m_suppressShow
) {
228 kDebug() << "show was suppressed";
232 setWindowState(Qt::WindowFullScreen
);
233 //KWindowSystem::setOnAllDesktops(winId(), true);
234 //KWindowSystem::setState(winId(), NET::KeepAbove|NET::SkipTaskbar);
239 m_suppressShow
= true;
240 QTimer::singleShot(SUPPRESS_SHOW_TIMEOUT
, this, SLOT(suppressShowTimeout()));
244 void SaverView::setContainment(Plasma::Containment
*newContainment
)
246 if (newContainment
== containment()) {
251 disconnect(containment(), SIGNAL(showAddWidgetsInterface(QPointF
)), this, SLOT(showAppletBrowser()));
252 connect(newContainment
, SIGNAL(showAddWidgetsInterface(QPointF
)), this, SLOT(showAppletBrowser()));
255 if (m_appletBrowser
) {
256 m_appletBrowser
->setContainment(newContainment
);
259 View::setContainment(newContainment
);
262 void SaverView::hideView()
267 if (m_appletBrowser
) {
268 m_appletBrowser
->hide();
271 disconnect(containment(), SIGNAL(showAddWidgetsInterface(QPointF
)), this, SLOT(showAppletBrowser()));
273 containment()->closeToolBox();
275 //let the lockprocess know
279 void SaverView::suppressShowTimeout()
281 kDebug() << "SaverView::suppressShowTimeout";
282 m_suppressShow
= false;
285 void SaverView::keyPressEvent(QKeyEvent
*event
)
287 /*if (event->key() == Qt::Key_Escape) {
293 //kDebug() << event->key() << event->spontaneous();
294 Plasma::View::keyPressEvent(event
);
297 //eeeeew. why did dashboard ever have this? wtf!
298 void SaverView::showEvent(QShowEvent
*event
)
300 //KWindowSystem::setState(winId(), NET::SkipPager);
301 connect(containment(), SIGNAL(showAddWidgetsInterface(QPointF
)), this, SLOT(showAppletBrowser()));
302 Plasma::View::showEvent(event
);
305 #include "saverview.moc"