tdeprint
messagewindow.cpp
00001
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 <tqlabel.h>
00023 #include <tqlayout.h>
00024 #include <tqtimer.h>
00025 #include <tqpixmap.h>
00026 #include <tqhbox.h>
00027 #include <kiconloader.h>
00028 #include <tdeapplication.h>
00029 #include <kdebug.h>
00030
00031 TQPtrDict<MessageWindow> MessageWindow::m_windows;
00032
00033 MessageWindow::MessageWindow( const TQString& txt, int delay, TQWidget *parent, const char *name )
00034 : TQWidget( parent, name, (WFlags)(WStyle_Customize|WStyle_NoBorder|WShowModal|WType_Dialog|WDestructiveClose) )
00035 {
00036 TQHBox *box = new TQHBox( this );
00037 box->setFrameStyle( TQFrame::Panel|TQFrame::Raised );
00038 box->setLineWidth( 1 );
00039 box->setSpacing( 10 );
00040 box->setMargin( 5 );
00041 TQLabel *pix = new TQLabel( box );
00042 pix->setPixmap( DesktopIcon( "tdeprint_printer" ) );
00043 m_text = new TQLabel( txt, box );
00044
00045 TQHBoxLayout *l0 = new TQHBoxLayout( this, 0, 0 );
00046 l0->addWidget( box );
00047
00048 m_windows.insert( parent, this );
00049
00050 if ( delay == 0 )
00051 slotTimer();
00052 else
00053 TQTimer::singleShot( delay, this, TQT_SLOT( slotTimer() ) );
00054 }
00055
00056 MessageWindow::~MessageWindow()
00057 {
00058 m_windows.remove( parentWidget() );
00059 }
00060
00061 void MessageWindow::slotTimer()
00062 {
00063 TQSize psz = parentWidget()->size(), sz = sizeHint();
00064 move( parentWidget()->mapToGlobal( TQPoint( (psz.width()-sz.width())/2, (psz.height()-sz.height())/2 ) ) );
00065 if ( !isVisible() )
00066 {
00067 show();
00068 kapp->processEvents();
00069 }
00070 }
00071
00072 TQString MessageWindow::text() const
00073 {
00074 return m_text->text();
00075 }
00076
00077 void MessageWindow::setText( const TQString& txt )
00078 {
00079 m_text->setText( txt );
00080 }
00081
00082 void MessageWindow::add( TQWidget *parent, const TQString& 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( TQWidget *parent )
00097 {
00098 if ( parent )
00099 delete m_windows.find( parent );
00100 }
00101
00102 void MessageWindow::change( TQWidget *parent, const TQString& 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 TQPtrDictIterator<MessageWindow> it( m_windows );
00117 while ( it.current() )
00118 delete it.current();
00119 }
00120
00121 #include "messagewindow.moc"