1
/***************************************************************************
2
* Copyright (C) 2011 by Dario Freddi <drf@kde.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (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 General Public License *
15
* 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 . *
18
***************************************************************************/
20
#include "ErrorOverlay.h"
22
#include <QtCore/QEvent>
23
#include <QtGui/QLabel>
24
#include <QtGui/QVBoxLayout>
27
#include <KLocalizedString>
29
ErrorOverlay::ErrorOverlay(QWidget *baseWidget, const QString &details, QWidget *parent) :
30
QWidget(parent ? parent : baseWidget->window()),
31
m_BaseWidget(baseWidget)
34
QVBoxLayout *layout = new QVBoxLayout;
35
layout->setSpacing(10);
37
QLabel *pixmap = new QLabel();
38
pixmap->setPixmap(KIcon("dialog-error").pixmap(64));
40
QLabel *message = new QLabel(i18n("Power Management configuration module could not be loaded.\n%1", details));
42
pixmap->setAlignment(Qt::AlignHCenter);
43
message->setAlignment(Qt::AlignHCenter);
46
layout->addWidget(pixmap);
47
layout->addWidget(message);
52
// Draw the transparent overlay background
53
QPalette p = palette();
54
p.setColor(backgroundRole(), QColor(0, 0, 0, 128));
55
p.setColor(foregroundRole(), Qt::white);
57
setAutoFillBackground(true);
59
m_BaseWidget->installEventFilter(this);
64
ErrorOverlay::~ErrorOverlay()
68
void ErrorOverlay::reposition()
74
// reparent to the current top level widget of the base widget if needed
75
// needed eg. in dock widgets
76
if (parentWidget() != m_BaseWidget->window()) {
77
setParent(m_BaseWidget->window());
80
// follow base widget visibility
81
// needed eg. in tab widgets
82
if (!m_BaseWidget->isVisible()) {
89
// follow position changes
90
const QPoint topLevelPos = m_BaseWidget->mapTo(window(), QPoint(0, 0));
91
const QPoint parentPos = parentWidget()->mapFrom(window(), topLevelPos);
94
// follow size changes
95
// TODO: hide/scale icon if we don't have enough space
96
resize(m_BaseWidget->size());
99
bool ErrorOverlay::eventFilter(QObject * object, QEvent * event)
101
if (object == m_BaseWidget &&
102
(event->type() == QEvent::Move || event->type() == QEvent::Resize ||
103
event->type() == QEvent::Show || event->type() == QEvent::Hide ||
104
event->type() == QEvent::ParentChange)) {
107
return QWidget::eventFilter(object, event);
110
#include "ErrorOverlay.moc"