| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kwindowinfo.cpp

    00001 /*
    00002  *   copyright            : (C) 2001-2002 by Richard Moore
    00003  *   License              : This file is released under the terms of the LGPL, version 2.
    00004  *   email                : rich@kde.org
    00005  */
    00006
    00007 #include <qobjectlist.h>
    00008 #include <qpixmap.h>
    00009 #include <qtimer.h>
    00010 #include <qtooltip.h>
    00011 #include <ksystemtray.h>
    00012 #include <kwin.h>
    00013
    00014 #include "kwindowinfo.h"
    00015 #include "kwindowinfo.moc"
    00016
    00017 static const int UNSPECIFIED_TIMEOUT = -1;
    00018 static const int DEFAULT_MESSAGE_TIMEOUT = 3000;
    00019
    00020 KWindowInfo::KWindowInfo( QWidget *parent, const char *name )
    00021     : QObject( parent, name ), win( parent ), autoDel( false )
    00022 {
    00023 }
    00024
    00025 KWindowInfo::~KWindowInfo()
    00026 {
    00027 }
    00028
    00029 void KWindowInfo::showMessage( QWidget *window, const QString &text, int timeout )
    00030 {
    00031     KWindowInfo *info = new KWindowInfo( window );
    00032     info->autoDel = true;
    00033     info->message( text, timeout );
    00034     if ( timeout == 0 )
    00035     delete info;
    00036 }
    00037
    00038 void KWindowInfo::showMessage( QWidget *window, const QString &text, const QPixmap &pix, int timeout )
    00039 {
    00040     KWindowInfo *info = new KWindowInfo( window );
    00041     info->autoDel = true;
    00042     info->message( text, pix, timeout );
    00043 }
    00044
    00045 void KWindowInfo::message( const QString &text )
    00046 {
    00047     message( text, QPixmap(), UNSPECIFIED_TIMEOUT );
    00048 }
    00049
    00050 void KWindowInfo::message( const QString &text, const QPixmap &pix )
    00051 {
    00052     message( text, pix, UNSPECIFIED_TIMEOUT );
    00053 }
    00054
    00055 void KWindowInfo::message( const QString &text, int timeout )
    00056 {
    00057     message( text, QPixmap(), timeout );
    00058 }
    00059
    00060 void KWindowInfo::message( const QString &text, const QPixmap &pix, int timeout )
    00061 {
    00062     if ( timeout != 0 )
    00063     save();
    00064
    00065     display( text, pix );
    00066
    00067     if ( timeout < 0 )
    00068     timeout = DEFAULT_MESSAGE_TIMEOUT;
    00069     if ( timeout != 0 )
    00070     QTimer::singleShot( timeout, this, SLOT( restore() ) );
    00071 }
    00072
    00073 void KWindowInfo::permanent( const QString &text )
    00074 {
    00075 #ifdef Q_WS_X11
    00076     oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
    00077     oldIcon = KWin::icon( win->winId(), 34, 34, false );
    00078     if ( oldIcon.isNull() )
    00079     oldIcon = KWin::icon( win->winId(), 32, 32, true );
    00080 #endif
    00081
    00082     permanent( text, oldIcon );
    00083 }
    00084
    00085 void KWindowInfo::permanent( const QString &text, const QPixmap &pix )
    00086 {
    00087     if ( !oldText.isNull() ) {
    00088     QObjectList *l = queryList( "QTimer" );
    00089     QObjectListIt it( *l );
    00090     QObject *obj;
    00091
    00092     while ( (obj = it.current()) != 0 ) {
    00093         ++it;
    00094         delete obj;
    00095     }
    00096     delete l;
    00097     }
    00098
    00099     oldText = QString::null;
    00100     display( text, pix );
    00101 }
    00102
    00103 void KWindowInfo::display( const QString &text, const QPixmap &pix )
    00104 {
    00105     QPixmap icon;
    00106     if ( pix.isNull() )
    00107     icon.load( "bell.png" );
    00108     else
    00109     icon = pix;
    00110
    00111     if ( win->inherits( "KSystemTray" ) ) {
    00112     KSystemTray *tray = static_cast<KSystemTray *>( win );
    00113     tray->setPixmap( icon );
    00114     QToolTip::add( tray, text );
    00115     return;
    00116     }
    00117
    00118     win->setCaption( text );
    00119     win->setIcon( icon );
    00120 #ifdef Q_WS_X11
    00121     KWin::setIcons( win->winId(), icon, icon );
    00122 #endif
    00123 }
    00124
    00125 void KWindowInfo::save()
    00126 {
    00127     if ( !oldText.isNull() )
    00128     return;
    00129
    00130     if ( win->inherits( "KSystemTray" ) ) {
    00131     KSystemTray *tray = static_cast<KSystemTray *>( win );
    00132     oldIcon = *(tray->pixmap());
    00133     oldText = QToolTip::textFor( tray );
    00134     return;
    00135     }
    00136
    00137     oldText = win->caption();
    00138 #ifdef Q_WS_X11
    00139     oldMiniIcon = KWin::icon( win->winId(), 16, 16, true );
    00140     oldIcon = KWin::icon( win->winId(), 34, 34, false );
    00141     if ( oldIcon.isNull() )
    00142     oldIcon = KWin::icon( win->winId(), 32, 32, true );
    00143 #endif
    00144
    00145     if ( oldIcon.isNull() ) {
    00146     const QPixmap *px = win->icon();
    00147     if ( px )
    00148         oldIcon = *px;
    00149     else
    00150         oldIcon.resize( 0, 0 );
    00151     }
    00152 }
    00153
    00154 void KWindowInfo::restore()
    00155 {
    00156     if ( win->inherits( "KSystemTray" ) ) {
    00157     KSystemTray *tray = static_cast<KSystemTray *>( win );
    00158     tray->setPixmap( oldIcon );
    00159     QToolTip::add( tray, oldText );
    00160     oldText = QString::null;
    00161     return;
    00162     }
    00163
    00164     win->setIcon( oldIcon );
    00165 #ifdef Q_WS_X11
    00166     KWin::setIcons( win->winId(), oldIcon, oldMiniIcon );
    00167 #endif
    00168     win->setCaption( oldText );
    00169     oldText = QString::null;
    00170
    00171     if ( autoDel )
    00172     delete this;
    00173 }
    00174
    00175
    00176
    00177
    00178

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:24 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003