• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kdialog.cpp
1 /* This file is part of the KDE Libraries
2  * Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)
3  * Additions 1999-2000 by Espen Sand (espen@kde.org)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include <kconfig.h>
22 #include <kapplication.h>
23 #include <kdialog.h>
24 #include <kwhatsthismanager_p.h>
25 #include <kdebug.h>
26 #include <kstaticdeleter.h>
27 #include <kiconloader.h>
28 #include <kglobalsettings.h>
29 #include <klocale.h>
30 
31 #include <tqlayout.h>
32 #include <tqobjectlist.h>
33 #include <tqguardedptr.h>
34 #include <tqlineedit.h>
35 #include <tqvaluelist.h>
36 #include <tqtimer.h>
37 #include <tqcursor.h>
38 #include <tqlabel.h>
39 #include <tqstyle.h>
40 #include <tqimage.h>
41 
42 #include "config.h"
43 #ifdef Q_WS_X11
44 #include <netwm.h>
45 #endif
46 
47 const int KDialog::mMarginSize = 11;
48 const int KDialog::mSpacingSize = 6;
49 
50 template class TQPtrList<TQLayoutItem>;
51 
52 KDialog::KDialog(TQWidget *parent, const char *name, bool modal, WFlags f)
53  : TQDialog(parent, name, modal, f), d(0)
54 {
55  KWhatsThisManager::init ();
56 }
57 
58 //
59 // Grab QDialogs keypresses if non-modal.
60 //
61 void KDialog::keyPressEvent(TQKeyEvent *e)
62 {
63  if ( e->state() == 0 )
64  {
65  switch ( e->key() )
66  {
67  case Key_Escape:
68  case Key_Enter:
69  case Key_Return:
70  {
71  if(testWFlags((WFlags)(WType_Dialog | WShowModal)))
72  {
73  TQDialog::keyPressEvent(e);
74  }
75  else
76  {
77  e->ignore();
78  }
79  }
80  break;
81  default:
82  e->ignore();
83  return;
84  }
85  }
86  else
87  {
88  // accept the dialog when Ctrl-Return is pressed
89  if ( e->state() == ControlButton &&
90  (e->key() == Key_Return || e->key() == Key_Enter) )
91  {
92  e->accept();
93  accept();
94  }
95  else
96  {
97  e->ignore();
98  }
99  }
100 }
101 
102 
103 int KDialog::marginHint()
104 {
105  return mMarginSize;
106 }
107 
108 
109 int KDialog::spacingHint()
110 {
111  return mSpacingSize;
112 }
113 
114 // KDE4: Remove me
115 void KDialog::polish()
116 {
117  TQDialog::polish();
118 }
119 
120 
121 void KDialog::setCaption( const TQString &_caption )
122 {
123  TQString caption = kapp ? kapp->makeStdCaption( _caption ) : _caption;
124  setPlainCaption( caption );
125 }
126 
127 
128 void KDialog::setPlainCaption( const TQString &caption )
129 {
130  TQDialog::setCaption( caption );
131 
132 #ifdef Q_WS_X11
133  NETWinInfo info( qt_xdisplay(), winId(), qt_xrootwin(), 0 );
134  info.setName( caption.utf8().data() );
135 #endif
136 }
137 
138 
139 void KDialog::resizeLayout( TQWidget *w, int margin, int spacing )
140 {
141  if( w->layout() )
142  {
143  resizeLayout( TQT_TQLAYOUTITEM(w->layout()), margin, spacing );
144  }
145 
146  if( !w->childrenListObject().isEmpty() )
147  {
148  const TQObjectList l = w->childrenListObject();
149  TQObjectListIterator itr(l);
150  TQObject *o;
151  while ((o = itr.current()) != 0) {
152  if( o->isWidgetType() )
153  {
154  resizeLayout( (TQWidget*)o, margin, spacing );
155  }
156  ++itr;
157  }
158  }
159 }
160 
161 
162 void KDialog::resizeLayout( TQLayoutItem *lay, int margin, int spacing )
163 {
164  TQLayoutIterator it = lay->iterator();
165  TQLayoutItem *child;
166  while ( (child = it.current() ) )
167  {
168  resizeLayout( child, margin, spacing );
169  ++it;
170  }
171  if( lay->layout() )
172  {
173  lay->layout()->setMargin( margin );
174  lay->layout()->setSpacing( spacing );
175  }
176 }
177 
178 static TQRect screenRect( TQWidget *w, int screen )
179 {
180  TQDesktopWidget *desktop = TQApplication::desktop();
181  KConfig gc("kdeglobals", false, false);
182  gc.setGroup("Windows");
183  if (desktop->isVirtualDesktop() &&
184  gc.readBoolEntry("XineramaEnabled", true) &&
185  gc.readBoolEntry("XineramaPlacementEnabled", true)) {
186  if ( screen < 0 || screen >= desktop->numScreens() ) {
187  if ( screen == -1 ) {
188  screen = desktop->primaryScreen();
189  } else if ( screen == -3 ) {
190  screen = desktop->screenNumber( TQCursor::pos() );
191  } else {
192  screen = desktop->screenNumber( w );
193  }
194  }
195  return desktop->availableGeometry(screen);
196  } else {
197  return desktop->geometry();
198  }
199 }
200 
201 void KDialog::centerOnScreen( TQWidget *w, int screen )
202 {
203  if ( !w )
204  return;
205  TQRect r = screenRect( w, screen );
206 
207  w->move( r.center().x() - w->width()/2,
208  r.center().y() - w->height()/2 );
209 }
210 
211 bool KDialog::avoidArea( TQWidget *w, const TQRect& area, int screen )
212 {
213  if ( !w )
214  return false;
215  TQRect fg = w->frameGeometry();
216  if ( !fg.intersects( area ) )
217  return true; // nothing to do.
218 
219  TQRect scr = screenRect( w, screen );
220  TQRect avoid( area ); // let's add some margin
221  avoid.moveBy( -5, -5 );
222  avoid.rRight() += 10;
223  avoid.rBottom() += 10;
224 
225  if ( QMAX( fg.top(), avoid.top() ) <= QMIN( fg.bottom(), avoid.bottom() ) )
226  {
227  // We need to move the widget up or down
228  int spaceAbove = QMAX(0, avoid.top() - scr.top());
229  int spaceBelow = QMAX(0, scr.bottom() - avoid.bottom());
230  if ( spaceAbove > spaceBelow ) // where's the biggest side?
231  if ( fg.height() <= spaceAbove ) // big enough?
232  fg.setY( avoid.top() - fg.height() );
233  else
234  return false;
235  else
236  if ( fg.height() <= spaceBelow ) // big enough?
237  fg.setY( avoid.bottom() );
238  else
239  return false;
240  }
241 
242  if ( QMAX( fg.left(), avoid.left() ) <= QMIN( fg.right(), avoid.right() ) )
243  {
244  // We need to move the widget left or right
245  int spaceLeft = QMAX(0, avoid.left() - scr.left());
246  int spaceRight = QMAX(0, scr.right() - avoid.right());
247  if ( spaceLeft > spaceRight ) // where's the biggest side?
248  if ( fg.width() <= spaceLeft ) // big enough?
249  fg.setX( avoid.left() - fg.width() );
250  else
251  return false;
252  else
253  if ( fg.width() <= spaceRight ) // big enough?
254  fg.setX( avoid.right() );
255  else
256  return false;
257  }
258  //kdDebug() << "Moving window to " << fg.x() << "," << fg.y() << endl;
259  w->move(fg.x(), fg.y());
260  return true;
261 }
262 
263 class KDialogQueuePrivate
264 {
265 public:
266  TQValueList< TQGuardedPtr<TQDialog> > queue;
267  bool busy;
268 };
269 
270 static KStaticDeleter<KDialogQueue> ksdkdq;
271 
272 KDialogQueue *KDialogQueue::_self=0;
273 
274 KDialogQueue* KDialogQueue::self()
275 {
276  if (!_self)
277  _self = ksdkdq.setObject(_self, new KDialogQueue);
278  return _self;
279 }
280 
281 KDialogQueue::KDialogQueue() : d(new KDialogQueuePrivate)
282 {
283  d->busy = false;
284 }
285 
286 KDialogQueue::~KDialogQueue()
287 {
288  delete d;
289  _self = 0;
290 }
291 
292 // static
293 void KDialogQueue::queueDialog(TQDialog *dialog)
294 {
295  KDialogQueue *_this = self();
296  _this->d->queue.append(dialog);
297  TQTimer::singleShot(0, _this, TQT_SLOT(slotShowQueuedDialog()));
298 }
299 
300 void KDialogQueue::slotShowQueuedDialog()
301 {
302  if (d->busy)
303  return;
304  TQDialog *dialog;
305  do {
306  if(d->queue.isEmpty())
307  return;
308  dialog = d->queue.first();
309  d->queue.pop_front();
310  }
311  while(!dialog);
312 
313  d->busy = true;
314  dialog->exec();
315  d->busy = false;
316  delete dialog;
317 
318  if (!d->queue.isEmpty())
319  TQTimer::singleShot(20, this, TQT_SLOT(slotShowQueuedDialog()));
320  else
321  ksdkdq.destructObject(); // Suicide.
322 }
323 
324 void KDialog::virtual_hook( int, void* )
325 { /*BASE::virtual_hook( id, data );*/ }
326 
327 KSMModalDialogHeader::KSMModalDialogHeader(TQWidget* parent)
328  : TQWidget( parent, "", Qt::WDestructiveClose )
329 {
330  TQVBoxLayout* vbox = new TQVBoxLayout( this );
331 
332  TQFrame* frame = new TQFrame( this );
333  frame->setFrameStyle( TQFrame::NoFrame );
334  frame->setLineWidth( 0 );
335  // we need to set the minimum size for the window
336  frame->setMinimumWidth(400);
337  vbox->addWidget( frame );
338  TQGridLayout* gbox = new TQGridLayout( frame, 1, 1, 0, KDialog::spacingHint() );
339  TQHBoxLayout* centerbox = new TQHBoxLayout( KDialog::spacingHint() );
340  TQHBoxLayout* seperatorbox = new TQHBoxLayout( 0 );
341  centerbox->setMargin(0);
342  seperatorbox->setMargin(0);
343 
344  TQWidget* ticon = new TQWidget( frame );
345  KIconLoader * ldr = KGlobal::iconLoader();
346  TQPixmap trinityPixmap = ldr->loadIcon("kmenu", KIcon::Panel, KIcon::SizeLarge, KIcon::DefaultState, 0L, true);
347 
348  // Manually draw the alpha portions of the icon onto the widget background color...
349  TQRgb backgroundRgb = ticon->paletteBackgroundColor().rgb();
350  TQImage correctedImage = trinityPixmap.convertToImage();
351  correctedImage = correctedImage.convertDepth(32);
352  correctedImage.setAlphaBuffer(true);
353  int w = correctedImage.width();
354  int h = correctedImage.height();
355  for (int y = 0; y < h; ++y) {
356  TQRgb *ls = (TQRgb *)correctedImage.scanLine( y );
357  for (int x = 0; x < w; ++x) {
358  TQRgb l = ls[x];
359  float alpha_adjust = tqAlpha( l )/255.0;
360  int r = int( (tqRed( l ) * alpha_adjust) + (tqRed( backgroundRgb ) * (1.0-alpha_adjust)) );
361  int g = int( (tqGreen( l ) * alpha_adjust) + (tqGreen( backgroundRgb ) * (1.0-alpha_adjust)) );
362  int b = int( (tqBlue( l ) * alpha_adjust) + (tqBlue( backgroundRgb ) * (1.0-alpha_adjust)) );
363  int a = int( 255 );
364  ls[x] = tqRgba( r, g, b, a );
365  }
366  }
367  trinityPixmap.convertFromImage(correctedImage);
368 
369  ticon->setBackgroundPixmap(trinityPixmap);
370  ticon->setMinimumSize(trinityPixmap.size());
371  ticon->setMaximumSize(trinityPixmap.size());
372  ticon->resize(trinityPixmap.size());
373  centerbox->addWidget( ticon, AlignCenter );
374 
375  TQWidget* swidget = new TQWidget( frame );
376  swidget->resize(2, frame->sizeHint().width());
377  swidget->setBackgroundColor(Qt::black);
378  seperatorbox->addWidget( swidget, AlignCenter );
379 
380  TQLabel* label = new TQLabel( i18n("Trinity Desktop Environment"), frame );
381  TQFont fnt = label->font();
382  fnt.setBold( true );
383  fnt.setPointSize( fnt.pointSize() * 3 / 2 );
384  label->setFont( fnt );
385  centerbox->addWidget( label, AlignCenter );
386 
387  gbox->addLayout(centerbox, 0, 0);
388  gbox->addLayout(seperatorbox, 1, 0);
389 
390  setFixedSize( sizeHint() );
391 }
392 
393 KSMModalDialogHeader::~KSMModalDialogHeader()
394 {
395 }
396 
397 KSMModalDialog::KSMModalDialog(TQWidget* parent)
398  : TQWidget( 0, "systemmodaldialogclass", Qt::WStyle_Customize | Qt::WType_Dialog | Qt::WStyle_Title | Qt::WStyle_StaysOnTop | Qt::WDestructiveClose ), m_keepOnTopTimer(NULL), m_allowClose(false)
399 
400 {
401  // Signal that we do not want any window controls to be shown at all
402  Atom kde_wm_system_modal_notification;
403  kde_wm_system_modal_notification = XInternAtom(qt_xdisplay(), "_KDE_WM_MODAL_SYS_NOTIFICATION", False);
404  XChangeProperty(qt_xdisplay(), winId(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
405 
406  TQVBoxLayout* vbox = new TQVBoxLayout( this );
407 
408  TQFrame* frame = new TQFrame( this );
409  frame->setFrameStyle( TQFrame::NoFrame );
410  frame->setLineWidth( style().pixelMetric( TQStyle::PM_DefaultFrameWidth, frame ) );
411  // we need to set the minimum size for the window
412  frame->setMinimumWidth(400);
413  vbox->addWidget( frame );
414  TQGridLayout* gbox = new TQGridLayout( frame, 1, 1, KDialog::marginHint(), KDialog::spacingHint() );
415  TQHBoxLayout* centerbox = new TQHBoxLayout( KDialog::spacingHint() );
416 
417  m_statusLabel = new TQLabel( i18n("Pondering what to do next").append("..."), frame );
418  TQFont fnt = m_statusLabel->font();
419  fnt.setBold( false );
420  fnt.setPointSize( fnt.pointSize() * 1 );
421  m_statusLabel->setFont( fnt );
422  gbox->addMultiCellWidget( m_statusLabel, 2, 2, 0, 0, AlignLeft | AlignVCenter );
423 
424  KSMModalDialogHeader *theader = new KSMModalDialogHeader(this);
425  centerbox->addWidget( theader, AlignCenter );
426 
427  gbox->addLayout(centerbox, 0, 0);
428 
429  setFixedSize( sizeHint() );
430  setCaption( i18n("Please wait...") );
431 
432  // Center the dialog
433  TQSize sh = sizeHint();
434  TQRect rect = KGlobalSettings::desktopGeometry(TQCursor::pos());
435  move(rect.x() + (rect.width() - sh.width())/2, rect.y() + (rect.height() - sh.height())/2);
436 
437  show();
438  keepMeOnTop();
439 }
440 
441 void KSMModalDialog::keepMeOnTop()
442 {
443  if (!m_keepOnTopTimer) {
444  m_keepOnTopTimer = new TQTimer();
445  connect(m_keepOnTopTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(keepMeOnTop()));
446  m_keepOnTopTimer->start(100, FALSE);
447  }
448  setActiveWindow();
449  raise();
450  setFocus();
451 }
452 
453 KSMModalDialog::~KSMModalDialog()
454 {
455  m_keepOnTopTimer->stop();
456  delete m_keepOnTopTimer;
457 }
458 
459 void KSMModalDialog::setStatusMessage(TQString message)
460 {
461  if (message == "") {
462  m_statusLabel->setText(i18n("Pondering what to do next").append("..."));
463  }
464  else {
465  m_statusLabel->setText(message);
466  }
467 }
468 
469 void KSMModalDialog::closeSMDialog()
470 {
471  m_allowClose = true;
472  close();
473 }
474 
475 void KSMModalDialog::closeEvent(TQCloseEvent *e)
476 {
477  //---------------------------------------------
478  // Don't call the base function because
479  // we want to ignore the close event
480  //---------------------------------------------
481 
482  if (m_allowClose)
483  TQWidget::closeEvent(e);
484 }
485 
486 void KSMModalDialog::setStartupPhase(TQString msg)
487 {
488  if (msg == TQString("dcop")) setStatusMessage(i18n("Starting DCOP").append("..."));
489  if (msg == TQString("kded")) setStatusMessage(i18n("Starting TDE daemon").append("..."));
490  if (msg == TQString("kcminit")) setStatusMessage(i18n("Starting services").append("..."));
491  if (msg == TQString("ksmserver")) setStatusMessage(i18n("Starting session").append("..."));
492  if (msg == TQString("wm started")) setStatusMessage(i18n("Initializing window manager").append("..."));
493  if (msg == TQString("kdesktop")) setStatusMessage(i18n("Loading desktop").append("..."));
494  if (msg == TQString("kicker")) setStatusMessage(i18n("Loading panels").append("..."));
495  if (msg == TQString("session ready")) setStatusMessage(i18n("Restoring applications").append("..."));
496 }
497 
498 #include "kdialog.moc"

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |