messagewindow.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "messagewindow.h"
00021
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 #include <qtimer.h>
00025 #include <qpixmap.h>
00026 #include <qhbox.h>
00027 #include <kiconloader.h>
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030
00031 QPtrDict<MessageWindow> MessageWindow::m_windows;
00032
00033 MessageWindow::MessageWindow( const QString& txt, int delay, QWidget *parent, const char *name )
00034 : QWidget( parent, name, WStyle_Customize|WStyle_NoBorder|WShowModal|WType_Dialog|WDestructiveClose )
00035 {
00036 QHBox *box = new QHBox( this );
00037 box->setFrameStyle( QFrame::Panel|QFrame::Raised );
00038 box->setLineWidth( 1 );
00039 box->setSpacing( 10 );
00040 box->setMargin( 5 );
00041 QLabel *pix = new QLabel( box );
00042 pix->setPixmap( DesktopIcon( "kdeprint_printer" ) );
00043 m_text = new QLabel( txt, box );
00044
00045 QHBoxLayout *l0 = new QHBoxLayout( this, 0, 0 );
00046 l0->addWidget( box );
00047
00048 m_windows.insert( parent, this );
00049
00050 if ( delay == 0 )
00051 slotTimer();
00052 else
00053 QTimer::singleShot( delay, this, SLOT( slotTimer() ) );
00054 }
00055
00056 MessageWindow::~MessageWindow()
00057 {
00058 m_windows.remove( parentWidget() );
00059 }
00060
00061 void MessageWindow::slotTimer()
00062 {
00063 QSize psz = parentWidget()->size(), sz = sizeHint();
00064 move( parentWidget()->mapToGlobal( QPoint( (psz.width()-sz.width())/2, (psz.height()-sz.height())/2 ) ) );
00065 if ( !isVisible() )
00066 {
00067 show();
00068 kapp->processEvents();
00069 }
00070 }
00071
00072 QString MessageWindow::text() const
00073 {
00074 return m_text->text();
00075 }
00076
00077 void MessageWindow::setText( const QString& txt )
00078 {
00079 m_text->setText( txt );
00080 }
00081
00082 void MessageWindow::add( QWidget *parent, const QString& txt, int delay )
00083 {
00084 if ( !parent )
00085 kdWarning( 500 ) << "Cannot add a message window to a null parent" << endl;
00086 else
00087 {
00088 MessageWindow *w = m_windows.find( parent );
00089 if ( w )
00090 w->setText( txt );
00091 else
00092 new MessageWindow( txt, delay, parent, "MessageWindow" );
00093 }
00094 }
00095
00096 void MessageWindow::remove( QWidget *parent )
00097 {
00098 if ( parent )
00099 delete m_windows.find( parent );
00100 }
00101
00102 void MessageWindow::change( QWidget *parent, const QString& txt )
00103 {
00104 if ( parent )
00105 {
00106 MessageWindow *w = m_windows.find( parent );
00107 if ( w )
00108 w->setText( txt );
00109 else
00110 kdWarning( 500 ) << "MessageWindow::change, no message window found" << endl;
00111 }
00112 }
00113
00114 void MessageWindow::removeAll()
00115 {
00116 QPtrDictIterator<MessageWindow> it( m_windows );
00117 while ( it.current() )
00118 delete it.current();
00119 }
00120
00121 #include "messagewindow.moc"
|