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

tdeui

  • tdeui
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 <tdeconfig.h>
22#include <tdeapplication.h>
23#include <kdialog.h>
24#include <kwhatsthismanager_p.h>
25#include <kdebug.h>
26#include <kstaticdeleter.h>
27#include <kiconloader.h>
28#include <tdeglobalsettings.h>
29#include <tdelocale.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#include <tqpushbutton.h>
42
43#include "config.h"
44#ifdef TQ_WS_X11
45#include <netwm.h>
46#endif
47
48const int KDialog::mMarginSize = 11;
49const int KDialog::mSpacingSize = 6;
50
51template class TQPtrList<TQLayoutItem>;
52
53KDialog::KDialog(TQWidget *parent, const char *name, bool modal, WFlags f)
54 : TQDialog(parent, name, modal, f), d(0)
55{
56 KWhatsThisManager::init ();
57}
58
59//
60// Grab QDialogs keypresses if non-modal.
61//
62void KDialog::keyPressEvent(TQKeyEvent *e)
63{
64 if ( e->state() == 0 )
65 {
66 switch ( e->key() )
67 {
68 case Key_Escape:
69 case Key_Enter:
70 case Key_Return:
71 {
72 if(testWFlags((WFlags)(WType_Dialog | WShowModal)))
73 {
74 TQDialog::keyPressEvent(e);
75 }
76 else
77 {
78 e->ignore();
79 }
80 }
81 break;
82 default:
83 e->ignore();
84 return;
85 }
86 }
87 else
88 {
89 // accept the dialog when Ctrl-Return is pressed
90 if ( e->state() == ControlButton &&
91 (e->key() == Key_Return || e->key() == Key_Enter) )
92 {
93 e->accept();
94 accept();
95 }
96 else
97 {
98 e->ignore();
99 }
100 }
101}
102
103
104int KDialog::marginHint()
105{
106 return mMarginSize;
107}
108
109
110int KDialog::spacingHint()
111{
112 return mSpacingSize;
113}
114
115// KDE4: Remove me
116void KDialog::polish()
117{
118 TQDialog::polish();
119}
120
121
122void KDialog::setCaption( const TQString &_caption )
123{
124 TQString caption = tdeApp ? tdeApp->makeStdCaption( _caption ) : _caption;
125 setPlainCaption( caption );
126}
127
128
129void KDialog::setPlainCaption( const TQString &caption )
130{
131 TQDialog::setCaption( caption );
132
133#ifdef TQ_WS_X11
134 NETWinInfo info( tqt_xdisplay(), winId(), tqt_xrootwin(), 0 );
135 info.setName( caption.utf8().data() );
136#endif
137}
138
139
140void KDialog::resizeLayout( TQWidget *w, int margin, int spacing )
141{
142 if( w->layout() )
143 {
144 resizeLayout( w->layout(), margin, spacing );
145 }
146
147 if( !w->childrenListObject().isEmpty() )
148 {
149 const TQObjectList l = w->childrenListObject();
150 TQObjectListIterator itr(l);
151 TQObject *o;
152 while ((o = itr.current()) != 0) {
153 if( o->isWidgetType() )
154 {
155 resizeLayout( (TQWidget*)o, margin, spacing );
156 }
157 ++itr;
158 }
159 }
160}
161
162
163void KDialog::resizeLayout( TQLayoutItem *lay, int margin, int spacing )
164{
165 TQLayoutIterator it = lay->iterator();
166 TQLayoutItem *child;
167 while ( (child = it.current() ) )
168 {
169 resizeLayout( child, margin, spacing );
170 ++it;
171 }
172 if( lay->layout() )
173 {
174 lay->layout()->setMargin( margin );
175 lay->layout()->setSpacing( spacing );
176 }
177}
178
179static TQRect screenRect( TQWidget *w, int screen )
180{
181 TQDesktopWidget *desktop = TQApplication::desktop();
182 TDEConfig gc("kdeglobals", false, false);
183 gc.setGroup("Windows");
184 if (desktop->isVirtualDesktop() &&
185 gc.readBoolEntry("XineramaEnabled", true) &&
186 gc.readBoolEntry("XineramaPlacementEnabled", true)) {
187 if ( screen < 0 || screen >= desktop->numScreens() ) {
188 if ( screen == -1 ) {
189 screen = desktop->primaryScreen();
190 } else if ( screen == -3 ) {
191 screen = desktop->screenNumber( TQCursor::pos() );
192 } else {
193 screen = desktop->screenNumber( w );
194 }
195 }
196 return desktop->availableGeometry(screen);
197 } else {
198 return desktop->geometry();
199 }
200}
201
202void KDialog::centerOnScreen( TQWidget *w, int screen )
203{
204 if ( !w )
205 return;
206 TQRect r = screenRect( w, screen );
207
208 w->move( r.center().x() - w->width()/2,
209 r.center().y() - w->height()/2 );
210}
211
212bool KDialog::avoidArea( TQWidget *w, const TQRect& area, int screen )
213{
214 if ( !w )
215 return false;
216 TQRect fg = w->frameGeometry();
217 if ( !fg.intersects( area ) )
218 return true; // nothing to do.
219
220 TQRect scr = screenRect( w, screen );
221 TQRect avoid( area ); // let's add some margin
222 avoid.moveBy( -5, -5 );
223 avoid.rRight() += 10;
224 avoid.rBottom() += 10;
225
226 if ( TQMAX( fg.top(), avoid.top() ) <= TQMIN( fg.bottom(), avoid.bottom() ) )
227 {
228 // We need to move the widget up or down
229 int spaceAbove = TQMAX(0, avoid.top() - scr.top());
230 int spaceBelow = TQMAX(0, scr.bottom() - avoid.bottom());
231 if ( spaceAbove > spaceBelow ) // where's the biggest side?
232 if ( fg.height() <= spaceAbove ) // big enough?
233 fg.setY( avoid.top() - fg.height() );
234 else
235 return false;
236 else
237 if ( fg.height() <= spaceBelow ) // big enough?
238 fg.setY( avoid.bottom() );
239 else
240 return false;
241 }
242
243 if ( TQMAX( fg.left(), avoid.left() ) <= TQMIN( fg.right(), avoid.right() ) )
244 {
245 // We need to move the widget left or right
246 int spaceLeft = TQMAX(0, avoid.left() - scr.left());
247 int spaceRight = TQMAX(0, scr.right() - avoid.right());
248 if ( spaceLeft > spaceRight ) // where's the biggest side?
249 if ( fg.width() <= spaceLeft ) // big enough?
250 fg.setX( avoid.left() - fg.width() );
251 else
252 return false;
253 else
254 if ( fg.width() <= spaceRight ) // big enough?
255 fg.setX( avoid.right() );
256 else
257 return false;
258 }
259 //kdDebug() << "Moving window to " << fg.x() << "," << fg.y() << endl;
260 w->move(fg.x(), fg.y());
261 return true;
262}
263
264class KDialogQueuePrivate
265{
266public:
267 TQValueList< TQGuardedPtr<TQDialog> > queue;
268 bool busy;
269};
270
271static KStaticDeleter<KDialogQueue> ksdkdq;
272
273KDialogQueue *KDialogQueue::_self=0;
274
275KDialogQueue* KDialogQueue::self()
276{
277 if (!_self)
278 _self = ksdkdq.setObject(_self, new KDialogQueue);
279 return _self;
280}
281
282KDialogQueue::KDialogQueue() : d(new KDialogQueuePrivate)
283{
284 d->busy = false;
285}
286
287KDialogQueue::~KDialogQueue()
288{
289 delete d;
290 _self = 0;
291}
292
293// static
294void KDialogQueue::queueDialog(TQDialog *dialog)
295{
296 KDialogQueue *_this = self();
297 _this->d->queue.append(dialog);
298 TQTimer::singleShot(0, _this, TQ_SLOT(slotShowQueuedDialog()));
299}
300
301void KDialogQueue::slotShowQueuedDialog()
302{
303 if (d->busy)
304 return;
305 TQDialog *dialog;
306 do {
307 if(d->queue.isEmpty())
308 return;
309 dialog = d->queue.first();
310 d->queue.pop_front();
311 }
312 while(!dialog);
313
314 d->busy = true;
315 dialog->exec();
316 d->busy = false;
317 delete dialog;
318
319 if (!d->queue.isEmpty())
320 TQTimer::singleShot(20, this, TQ_SLOT(slotShowQueuedDialog()));
321 else
322 ksdkdq.destructObject(); // Suicide.
323}
324
325void KDialog::virtual_hook( int, void* )
326{ /*BASE::virtual_hook( id, data );*/ }
327
328KSMModalDialogHeader::KSMModalDialogHeader(TQWidget* parent)
329 : TQWidget( parent, "", TQt::WDestructiveClose )
330{
331 TQVBoxLayout* vbox = new TQVBoxLayout( this );
332
333 TQFrame* frame = new TQFrame( this );
334 frame->setFrameStyle( TQFrame::NoFrame );
335 frame->setLineWidth( 0 );
336 // we need to set the minimum size for the window
337 frame->setMinimumWidth(400);
338 vbox->addWidget( frame );
339 TQGridLayout* gbox = new TQGridLayout( frame, 1, 1, 0, KDialog::spacingHint() );
340 TQHBoxLayout* centerbox = new TQHBoxLayout( KDialog::spacingHint() );
341 TQHBoxLayout* seperatorbox = new TQHBoxLayout( 0 );
342 centerbox->setMargin(0);
343 seperatorbox->setMargin(0);
344
345 TQWidget* ticon = new TQWidget( frame );
346 TDEIconLoader * ldr = TDEGlobal::iconLoader();
347 TQPixmap trinityPixmap = ldr->loadIcon("kmenu", TDEIcon::Panel, TDEIcon::SizeLarge, TDEIcon::DefaultState, 0L, true);
348
349 // Manually draw the alpha portions of the icon onto the widget background color...
350 TQRgb backgroundRgb = ticon->paletteBackgroundColor().rgb();
351 TQImage correctedImage = trinityPixmap.convertToImage();
352 correctedImage = correctedImage.convertDepth(32);
353 correctedImage.setAlphaBuffer(true);
354 int w = correctedImage.width();
355 int h = correctedImage.height();
356 for (int y = 0; y < h; ++y) {
357 TQRgb *ls = (TQRgb *)correctedImage.scanLine( y );
358 for (int x = 0; x < w; ++x) {
359 TQRgb l = ls[x];
360 float alpha_adjust = tqAlpha( l )/255.0;
361 int r = int( (tqRed( l ) * alpha_adjust) + (tqRed( backgroundRgb ) * (1.0-alpha_adjust)) );
362 int g = int( (tqGreen( l ) * alpha_adjust) + (tqGreen( backgroundRgb ) * (1.0-alpha_adjust)) );
363 int b = int( (tqBlue( l ) * alpha_adjust) + (tqBlue( backgroundRgb ) * (1.0-alpha_adjust)) );
364 int a = int( 255 );
365 ls[x] = tqRgba( r, g, b, a );
366 }
367 }
368 trinityPixmap.convertFromImage(correctedImage);
369
370 ticon->setBackgroundPixmap(trinityPixmap);
371 ticon->setMinimumSize(trinityPixmap.size());
372 ticon->setMaximumSize(trinityPixmap.size());
373 ticon->resize(trinityPixmap.size());
374 centerbox->addWidget( ticon, AlignCenter );
375
376 TQWidget* swidget = new TQWidget( frame );
377 swidget->resize(2, frame->sizeHint().width());
378 swidget->setBackgroundColor(TQt::black);
379 seperatorbox->addWidget( swidget, AlignCenter );
380
381 TQLabel* label = new TQLabel( i18n("Trinity Desktop Environment"), frame );
382 TQFont fnt = label->font();
383 fnt.setBold( true );
384 fnt.setPointSize( fnt.pointSize() * 3 / 2 );
385 label->setFont( fnt );
386 centerbox->addWidget( label, AlignCenter );
387
388 gbox->addLayout(centerbox, 0, 0);
389 gbox->addLayout(seperatorbox, 1, 0);
390
391 setFixedSize( sizeHint() );
392}
393
394KSMModalDialogHeader::~KSMModalDialogHeader()
395{
396}
397
398KSMModalDialog::KSMModalDialog(TQWidget* parent)
399 : TQWidget( 0, "systemmodaldialogclass", TQt::WStyle_Customize | TQt::WType_Dialog | TQt::WStyle_Title | TQt::WStyle_StaysOnTop | TQt::WDestructiveClose ), m_keepOnTopTimer(NULL), m_allowClose(false)
400
401{
402 // Signal that we do not want any window controls to be shown at all
403 Atom kde_wm_system_modal_notification;
404 kde_wm_system_modal_notification = XInternAtom(tqt_xdisplay(), "_TDE_WM_MODAL_SYS_NOTIFICATION", False);
405 XChangeProperty(tqt_xdisplay(), winId(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L);
406
407 TQVBoxLayout* vbox = new TQVBoxLayout( this );
408
409 TQFrame* frame = new TQFrame( this );
410 frame->setFrameStyle( TQFrame::NoFrame );
411 frame->setLineWidth( style().pixelMetric( TQStyle::PM_DefaultFrameWidth, frame ) );
412 // we need to set the minimum size for the window
413 frame->setMinimumWidth(400);
414 vbox->addWidget( frame );
415 m_gridlayout = new TQGridLayout( frame, 1, 1, KDialog::marginHint(), KDialog::spacingHint() );
416 TQHBoxLayout* centerbox = new TQHBoxLayout( KDialog::spacingHint() );
417
418 m_statusLabel = new TQLabel( i18n("Pondering what to do next").append("..."), frame );
419 TQFont fnt = m_statusLabel->font();
420 fnt.setBold( false );
421 fnt.setPointSize( fnt.pointSize() * 1 );
422 m_statusLabel->setFont( fnt );
423 m_gridlayout->addMultiCellWidget( m_statusLabel, 2, 2, 0, 2, AlignLeft | AlignVCenter );
424
425 KSMModalDialogHeader *theader = new KSMModalDialogHeader(this);
426 centerbox->addWidget( theader, AlignCenter );
427
428 m_gridlayout->addLayout(centerbox, 0, 0);
429
430 m_buttonframe = new TQFrame( this );
431 m_buttonframe->setFrameStyle( TQFrame::NoFrame );
432 m_buttonframe->setLineWidth( style().pixelMetric( TQStyle::PM_DefaultFrameWidth, frame ) );
433 m_buttonbox = new TQHBoxLayout( m_buttonframe, 0, KDialog::spacingHint() );
434
435 m_button1 = new TQPushButton( m_buttonframe );
436 m_button2 = new TQPushButton( m_buttonframe );
437 m_button3 = new TQPushButton( m_buttonframe );
438 m_buttonbox->addWidget( m_button1 );
439 m_buttonbox->addWidget( m_button2 );
440 m_buttonbox->addWidget( m_button3 );
441 m_button1->hide();
442 m_button2->hide();
443 m_button3->hide();
444
445 m_buttonframe->hide();
446 m_gridlayout->addMultiCellWidget( m_buttonframe, 3, 3, 0, 2, 0 );
447
448 setFixedSize( sizeHint() );
449 setCaption( i18n("Please wait...") );
450
451 // Center the dialog
452 TQSize sh = sizeHint();
453 TQRect rect = TDEGlobalSettings::desktopGeometry(TQCursor::pos());
454 move(rect.x() + (rect.width() - sh.width())/2, rect.y() + (rect.height() - sh.height())/2);
455
456 show();
457 keepMeOnTop();
458}
459
460void KSMModalDialog::keepMeOnTop()
461{
462 if (!m_keepOnTopTimer) {
463 m_keepOnTopTimer = new TQTimer();
464 connect(m_keepOnTopTimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(keepMeOnTop()));
465 m_keepOnTopTimer->start(100, false);
466 }
467 setActiveWindow();
468 raise();
469 setFocus();
470}
471
472KSMModalDialog::~KSMModalDialog()
473{
474 m_keepOnTopTimer->stop();
475 delete m_keepOnTopTimer;
476}
477
478void KSMModalDialog::setStatusMessage(TQString message)
479{
480 if (message == "") {
481 m_statusLabel->setText(i18n("Pondering what to do next").append("..."));
482 }
483 else {
484 m_statusLabel->setText(message);
485 }
486}
487
488void KSMModalDialog::closeSMDialog()
489{
490 m_allowClose = true;
491 close();
492}
493
494void KSMModalDialog::closeEvent(TQCloseEvent *e)
495{
496 //---------------------------------------------
497 // Don't call the base function because
498 // we want to ignore the close event
499 //---------------------------------------------
500
501 if (m_allowClose)
502 TQWidget::closeEvent(e);
503}
504
505void KSMModalDialog::setStartupPhase(TQString msg)
506{
507 if (msg == TQString("dcop")) setStatusMessage(i18n("Starting DCOP").append("..."));
508 if (msg == TQString("kded")) setStatusMessage(i18n("Starting TDE daemon").append("..."));
509 if (msg == TQString("kcminit")) setStatusMessage(i18n("Starting services").append("..."));
510 if (msg == TQString("ksmserver")) setStatusMessage(i18n("Starting session").append("..."));
511 if (msg == TQString("wm started")) setStatusMessage(i18n("Initializing window manager").append("..."));
512 if (msg == TQString("kdesktop")) setStatusMessage(i18n("Loading desktop").append("..."));
513 if (msg == TQString("kicker")) setStatusMessage(i18n("Loading panels").append("..."));
514 if (msg == TQString("session ready")) setStatusMessage(i18n("Restoring applications").append("..."));
515}
516
517#include "kdialog.moc"
KDialog::marginHint
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
Definition: kdialog.cpp:104
KDialog::KDialog
KDialog(TQWidget *parent=0, const char *name=0, bool modal=false, WFlags f=0)
Constructor.
Definition: kdialog.cpp:53
KDialog::keyPressEvent
virtual void keyPressEvent(TQKeyEvent *)
Definition: kdialog.cpp:62
KDialog::centerOnScreen
static void centerOnScreen(TQWidget *widget, int screen=-1)
Centers widget on the desktop, taking multi-head setups into account.
Definition: kdialog.cpp:202
KDialog::setPlainCaption
virtual void setPlainCaption(const TQString &caption)
Make a plain caption without any modifications.
Definition: kdialog.cpp:129
KDialog::polish
virtual void polish()
If the dialog starts with focus in a TQLineEdit child, then call selectAll() on the child.
Definition: kdialog.cpp:116
KDialog::spacingHint
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
Definition: kdialog.cpp:110
KDialog::avoidArea
static bool avoidArea(TQWidget *widget, const TQRect &area, int screen=-1)
Places widget so that it doesn't cover a certain area of the screen.
Definition: kdialog.cpp:212
KDialog::setCaption
virtual void setCaption(const TQString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:122
KDialog::resizeLayout
static void resizeLayout(TQWidget *widget, int margin, int spacing)
Resize every layout manager used in widget and its nested children.
Definition: kdialog.cpp:140
KSMModalDialogHeader
The default system modal dialog header.
Definition: kdialog.h:219
KStaticDeleter
TDEConfig
TDEGlobalSettings::desktopGeometry
static TQRect desktopGeometry(const TQPoint &point)
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
TDEIconLoader
TDEIconLoader::loadIcon
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
TDEIcon::DefaultState
DefaultState
TDEIcon::Panel
Panel
TDEIcon::SizeLarge
SizeLarge
TDEStdAccel::close
const TDEShortcut & close()
TDEStdAccel::label
TQString label(StdAccel id)
tdelocale.h

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.