~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/kabc/waitingoverlay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008 Volker Krause <vkrause@kde.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "waitingoverlay.h"
 
21
 
 
22
#include <KDebug>
 
23
#include <KIcon>
 
24
#include <KJob>
 
25
#include <KLocale>
 
26
 
 
27
#include <QtCore/QEvent>
 
28
#include <QtGui/QBoxLayout>
 
29
#include <QtGui/QLabel>
 
30
#include <QtGui/QPalette>
 
31
#include <QtGui/QProgressBar>
 
32
 
 
33
//@cond PRIVATE
 
34
 
 
35
WaitingOverlay::WaitingOverlay( KJob *job, QWidget *baseWidget, QWidget * parent )
 
36
  : QWidget( parent ? parent : baseWidget->window() ),
 
37
    mBaseWidget( baseWidget )
 
38
{
 
39
  Q_ASSERT( baseWidget );
 
40
  Q_ASSERT( parentWidget() != baseWidget );
 
41
 
 
42
  connect( baseWidget, SIGNAL( destroyed() ), SLOT( deleteLater() ) );
 
43
  connect( job, SIGNAL( result( KJob* ) ), SLOT( deleteLater() ) );
 
44
  mPreviousState = mBaseWidget->isEnabled();
 
45
 
 
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();
 
53
 
 
54
  QPalette p = palette();
 
55
  p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
 
56
  setPalette( p );
 
57
  setAutoFillBackground( true );
 
58
 
 
59
  mBaseWidget->installEventFilter( this );
 
60
 
 
61
  reposition();
 
62
}
 
63
 
 
64
WaitingOverlay::~ WaitingOverlay()
 
65
{
 
66
  if ( mBaseWidget )
 
67
    mBaseWidget->setEnabled( mPreviousState );
 
68
}
 
69
 
 
70
void WaitingOverlay::reposition()
 
71
{
 
72
  if ( !mBaseWidget )
 
73
    return;
 
74
 
 
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() );
 
79
 
 
80
  // follow base widget visibility
 
81
  // needed eg. in tab widgets
 
82
  if ( !mBaseWidget->isVisible() ) {
 
83
    hide();
 
84
    return;
 
85
  }
 
86
  show();
 
87
 
 
88
  // follow position changes
 
89
  const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
 
90
  const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
 
91
  move( parentPos );
 
92
 
 
93
  // follow size changes
 
94
  // TODO: hide/scale icon if we don't have enough space
 
95
  resize( mBaseWidget->size() );
 
96
}
 
97
 
 
98
bool WaitingOverlay::eventFilter(QObject * object, QEvent * event)
 
99
{
 
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 ) ) {
 
104
    reposition();
 
105
  }
 
106
  return QWidget::eventFilter( object, event );
 
107
}
 
108
 
 
109
//@endcond