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

# kdialog.cpp

    00001 /*  This file is part of the KDE Libraries
    00002  *  Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)
    00003  *  Additions 1999-2000 by Espen Sand (espen@kde.org)
    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 as published by the Free Software Foundation; either
    00008  *  version 2 of the License, or (at your option) any later version.
    00009  *
    00010  *  This library is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  *  Library General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU Library General Public License
    00016  *  along with this library; see the file COPYING.LIB.  If not, write to
    00017  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  *  Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021 #include <qlayout.h>
    00022 #include <qobjectlist.h>
    00023 #include <qguardedptr.h>
    00024 #include <qlineedit.h>
    00025 #include <qvaluelist.h>
    00026 #include <qtimer.h>
    00027 #include <netwm.h>
    00028
    00029 #include <kapplication.h>
    00030 #include <kdialog.h>
    00031 #include <kdebug.h>
    00032 #include <kstaticdeleter.h>
    00033
    00034 int KDialog::mMarginSize = 11;
    00035 int KDialog::mSpacingSize = 6;
    00036
    00037 template class QPtrList<QLayoutItem>;
    00038
    00039 KDialog::KDialog(QWidget *parent, const char *name, bool modal, WFlags f)
    00040   : QDialog(parent, name, modal, f)
    00041 {
    00042 }
    00043
    00044 //
    00045 // Grab QDialogs keypresses if non-modal.
    00046 //
    00047 void KDialog::keyPressEvent(QKeyEvent *e)
    00048 {
    00049   if ( e->state() == 0 )
    00050   {
    00051     switch ( e->key() )
    00052     {
    00053       case Key_Escape:
    00054       case Key_Enter:
    00055       case Key_Return:
    00056       {
    00057         if(testWFlags(WType_Dialog | WShowModal))
    00058         {
    00059           QDialog::keyPressEvent(e);
    00060         }
    00061         else
    00062         {
    00063           e->ignore();
    00064         }
    00065       }
    00066       break;
    00067       default:
    00068         e->ignore();
    00069         return;
    00070     }
    00071   }
    00072   else
    00073   {
    00074       // accept the dialog when Ctrl-Return is pressed
    00075       if ( e->state() == ControlButton &&
    00076            qApp->focusWidget()  &&
    00077            (qApp->focusWidget()->inherits( "QTextEdit" ) ||
    00078             qApp->focusWidget()->inherits( "QLineEdit" )) &&
    00079            (e->key() == Key_Return || e->key() == Key_Enter) )
    00080       {
    00081           e->accept();
    00082           accept();
    00083       }
    00084       else
    00085       {
    00086           e->ignore();
    00087       }
    00088   }
    00089 }
    00090
    00091
    00092 int KDialog::marginHint()
    00093 {
    00094   return( mMarginSize );
    00095 }
    00096
    00097
    00098 int KDialog::spacingHint()
    00099 {
    00100   return( mSpacingSize );
    00101 }
    00102
    00103
    00104 void KDialog::polish()
    00105 {
    00106   QDialog::polish();
    00107   QWidget *w = focusWidget();
    00108   if( w && w->isEnabled() && w->inherits( "QLineEdit" ) &&
    00109       !w->inherits( "KPasswordEdit" ))
    00110     ((QLineEdit*)w)->selectAll();
    00111 }
    00112
    00113
    00114 void KDialog::setCaption( const QString &_caption )
    00115 {
    00116   QString caption = kapp ? kapp->makeStdCaption( _caption ) : _caption;
    00117   setPlainCaption( caption );
    00118 }
    00119
    00120
    00121 void KDialog::setPlainCaption( const QString &caption )
    00122 {
    00123   QDialog::setCaption( caption );
    00124
    00125 #ifdef Q_WS_X11 //FIXME(E) Implement for Qt/E
    00126   NETWinInfo info( qt_xdisplay(), winId(), qt_xrootwin(), 0 );
    00127   info.setName( caption.utf8().data() );
    00128 #endif
    00129 }
    00130
    00131
    00132 void KDialog::resizeLayout( QWidget *w, int margin, int spacing )
    00133 {
    00134   if( w->layout() )
    00135   {
    00136     resizeLayout( w->layout(), margin, spacing );
    00137   }
    00138
    00139   if( w->children() )
    00140   {
    00141     QObjectList *l = (QObjectList*)w->children(); // silence please
    00142     for( uint i=0; i < l->count(); i++ )
    00143     {
    00144       QObject *o = l->at(i);
    00145       if( o->isWidgetType() )
    00146       {
    00147         resizeLayout( (QWidget*)o, margin, spacing );
    00148       }
    00149     }
    00150   }
    00151 }
    00152
    00153
    00154 void KDialog::resizeLayout( QLayoutItem *lay, int margin, int spacing )
    00155 {
    00156   QLayoutIterator it = lay->iterator();
    00157   QLayoutItem *child;
    00158   while ( (child = it.current() ) )
    00159   {
    00160     resizeLayout( child, margin, spacing );
    00161     ++it;
    00162   }
    00163   if( lay->layout() != 0 )
    00164   {
    00165     lay->layout()->setMargin( margin );
    00166     lay->layout()->setSpacing( spacing );
    00167   }
    00168 }
    00169
    00170 void KDialog::centerOnScreen( QWidget *w, int screen )
    00171 {
    00172   if ( !w )
    00173     return;
    00174
    00175   QDesktopWidget *desktop = QApplication::desktop();
    00176   if ( screen < 0 || screen >= desktop->numScreens() )
    00177   {
    00178     screen = desktop->screenNumber( w );
    00179     if ( screen == -1 )
    00180       screen = desktop->primaryScreen();
    00181   }
    00182
    00183   QRect r = desktop->screenGeometry( screen );
    00184   w->move( r.center().x() - w->width()/2,
    00185            r.center().y() - w->height()/2 );
    00186 }
    00187
    00188 class KDialogQueuePrivate
    00189 {
    00190 public:
    00191   QValueList< QGuardedPtr<QDialog> > queue;
    00192   bool busy;
    00193 };
    00194
    00195 static KStaticDeleter<KDialogQueue> ksdkdq;
    00196
    00197 KDialogQueue *KDialogQueue::_self=0;
    00198
    00199 KDialogQueue* KDialogQueue::self()
    00200 {
    00201    if (!_self)
    00202       _self = ksdkdq.setObject(new KDialogQueue);
    00203    return _self;
    00204 }
    00205
    00206 KDialogQueue::KDialogQueue()
    00207 {
    00208    d = new KDialogQueuePrivate;
    00209    d->busy = false;
    00210 }
    00211
    00212 KDialogQueue::~KDialogQueue()
    00213 {
    00214    delete d; d = 0;
    00215    _self = 0;
    00216 }
    00217
    00218 // static
    00219 void KDialogQueue::queueDialog(QDialog *dialog)
    00220 {
    00221    KDialogQueue *_this = self();
    00222    _this->d->queue.append(dialog);
    00223    QTimer::singleShot(0, _this, SLOT(slotShowQueuedDialog()));
    00224 }
    00225
    00226 void KDialogQueue::slotShowQueuedDialog()
    00227 {
    00228    if (d->busy)
    00229       return;
    00230    QDialog *dialog;
    00231    do {
    00232       if(!d->queue.count())
    00233          return;
    00234       dialog = d->queue.first();
    00235       d->queue.remove(d->queue.begin());
    00236    }
    00237    while(!dialog);
    00238
    00239    d->busy = true;
    00240    dialog->exec();
    00241    d->busy = false;
    00242    delete dialog;
    00243
    00244    if (d->queue.count())
    00245       QTimer::singleShot(20, this, SLOT(slotShowQueuedDialog()));
    00246    else
    00247       ksdkdq.destructObject(); // Suicide.
    00248 }
    00249
    00250 void KDialog::virtual_hook( int, void* )
    00251 { /*BASE::virtual_hook( id, data );*/ }
    00252
    00253 #include "kdialog.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:56:28 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001