• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.5 API Reference
  • KDE Home
  • Contact Us
 

akonadi

waitingoverlay.cpp
00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2008 Volker Krause <vkrause@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "waitingoverlay_p.h"
00023 
00024 #include <KDebug>
00025 #include <KIcon>
00026 #include <KJob>
00027 #include <KLocale>
00028 
00029 #include <QtCore/QEvent>
00030 #include <QtGui/QBoxLayout>
00031 #include <QtGui/QLabel>
00032 #include <QtGui/QPalette>
00033 #include <QtGui/QProgressBar>
00034 
00035 //@cond PRIVATE
00036 
00037 WaitingOverlay::WaitingOverlay( KJob *job, QWidget *baseWidget, QWidget * parent )
00038   : QWidget( parent ? parent : baseWidget->window() ),
00039     mBaseWidget( baseWidget )
00040 {
00041   Q_ASSERT( baseWidget );
00042   Q_ASSERT( parentWidget() != baseWidget );
00043 
00044   connect( baseWidget, SIGNAL(destroyed()), SLOT(deleteLater()) );
00045   connect( job, SIGNAL(result(KJob*)), SLOT(deleteLater()) );
00046   mPreviousState = mBaseWidget->isEnabled();
00047 
00048   QBoxLayout *topLayout = new QVBoxLayout( this );
00049   topLayout->addStretch();
00050   mDescription = new QLabel( this );
00051   mDescription->setText( i18n( "<p style=\"color: white;\"><b>Waiting for operation</b><br/></p>" ) );
00052   mDescription->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
00053   topLayout->addWidget( mDescription );
00054   topLayout->addStretch();
00055 
00056   QPalette p = palette();
00057   p.setColor( backgroundRole(), QColor( 0, 0, 0, 128 ) );
00058   setPalette( p );
00059   setAutoFillBackground( true );
00060 
00061   mBaseWidget->installEventFilter( this );
00062 
00063   reposition();
00064 }
00065 
00066 WaitingOverlay::~ WaitingOverlay()
00067 {
00068   if ( mBaseWidget )
00069     mBaseWidget->setEnabled( mPreviousState );
00070 }
00071 
00072 void WaitingOverlay::reposition()
00073 {
00074   if ( !mBaseWidget )
00075     return;
00076 
00077   // reparent to the current top level widget of the base widget if needed
00078   // needed eg. in dock widgets
00079   if ( parentWidget() != mBaseWidget->window() )
00080     setParent( mBaseWidget->window() );
00081 
00082   // follow base widget visibility
00083   // needed eg. in tab widgets
00084   if ( !mBaseWidget->isVisible() ) {
00085     hide();
00086     return;
00087   }
00088   show();
00089 
00090   // follow position changes
00091   const QPoint topLevelPos = mBaseWidget->mapTo( window(), QPoint( 0, 0 ) );
00092   const QPoint parentPos = parentWidget()->mapFrom( window(), topLevelPos );
00093   move( parentPos );
00094 
00095   // follow size changes
00096   // TODO: hide/scale icon if we don't have enough space
00097   resize( mBaseWidget->size() );
00098 }
00099 
00100 bool WaitingOverlay::eventFilter(QObject * object, QEvent * event)
00101 {
00102   if ( object == mBaseWidget &&
00103     ( event->type() == QEvent::Move || event->type() == QEvent::Resize ||
00104       event->type() == QEvent::Show || event->type() == QEvent::Hide ||
00105       event->type() == QEvent::ParentChange ) ) {
00106     reposition();
00107   }
00108   return QWidget::eventFilter( object, event );
00109 }
00110 
00111 //@endcond
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:20 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal