kdeprint Library API Documentation

messagewindow.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2002 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 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"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:44:31 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003