2
Copyright (c) 2008 Volker Krause <vkrause@kde.org>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
#include "waitingoverlay.h"
27
#include <QtCore/QEvent>
28
#include <QtGui/QBoxLayout>
29
#include <QtGui/QLabel>
30
#include <QtGui/QPalette>
31
#include <QtGui/QProgressBar>
35
WaitingOverlay::WaitingOverlay( KJob *job, QWidget *baseWidget, QWidget * parent )
36
: QWidget( parent ? parent : baseWidget->window() ),
37
mBaseWidget( baseWidget )
39
Q_ASSERT( baseWidget );
40
Q_ASSERT( parentWidget() != baseWidget );
42
connect( baseWidget, SIGNAL( destroyed() ), SLOT( deleteLater() ) );
43
connect( job, SIGNAL( result( KJob* ) ), SLOT( deleteLater() ) );
44
mPreviousState = mBaseWidget->isEnabled();
46
QBoxLayout *topLayout = new QVBoxLayout( this );
47
topLayout->addStretch();
48
mDescription = new QLabel( this );
49
mDescription->setText( i18n( "<p style=\"color: white;\"><b>Waiting for operation</b><br/></p>" ) );
50
mDescription->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
51
topLayout->addWidget( mDescription );
52
topLayout->addStretch();
54
QPalette p = palette();
55
p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
57
setAutoFillBackground( true );
59
mBaseWidget->installEventFilter( this );
64
WaitingOverlay::~ WaitingOverlay()
67
mBaseWidget->setEnabled( mPreviousState );
70
void WaitingOverlay::reposition()
75
// reparent to the current top level widget of the base widget if needed
76
// needed eg. in dock widgets
77
if ( parentWidget() != mBaseWidget->window() )
78
setParent( mBaseWidget->window() );
80
// follow base widget visibility
81
// needed eg. in tab widgets
82
if ( !mBaseWidget->isVisible() ) {
88
// follow position changes
89
const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
90
const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
93
// follow size changes
94
// TODO: hide/scale icon if we don't have enough space
95
resize( mBaseWidget->size() );
98
bool WaitingOverlay::eventFilter(QObject * object, QEvent * event)
100
if ( object == mBaseWidget &&
101
( event->type() == QEvent::Move || event->type() == QEvent::Resize ||
102
event->type() == QEvent::Show || event->type() == QEvent::Hide ||
103
event->type() == QEvent::ParentChange ) ) {
106
return QWidget::eventFilter( object, event );