26#include "kdialogqueue_p.h"
30#include <QApplication>
31#include <QDesktopWidget>
32#include <QDialogButtonBox>
49#include <qx11info_x11.h>
55void KDialogPrivate::setupLayout()
59 QMetaObject::invokeMethod( q,
"queuedLayoutUpdate", Qt::QueuedConnection );
64void KDialogPrivate::queuedLayoutUpdate()
75 QPointer<QWidget> focusWidget = mMainWidget ? mMainWidget->focusWidget() : 0;
77 if (q->layout() && q->layout() != mTopLayout) {
78 kWarning(240) << q->metaObject()->className() <<
"created with a layout; don't do that, KDialog takes care of it, use mainWidget or setMainWidget instead";
84 if ( mButtonOrientation == Qt::Horizontal )
85 mTopLayout =
new QVBoxLayout(q);
87 mTopLayout =
new QHBoxLayout(q);
90 mTopLayout->addWidget( mUrlHelp, 0, Qt::AlignRight );
93 mTopLayout->addWidget( mMainWidget, 10 );
96 mTopLayout->addWidget( mDetailsWidget );
98 if ( mActionSeparator )
99 mTopLayout->addWidget( mActionSeparator );
102 mButtonBox->setOrientation( mButtonOrientation );
103 mTopLayout->addWidget( mButtonBox );
107 focusWidget->setFocus();
115 QDialogButtonBox::ButtonRole role = QDialogButtonBox::InvalidRole;
119 role = QDialogButtonBox::HelpRole;
123 role = QDialogButtonBox::ResetRole;
126 role = QDialogButtonBox::AcceptRole;
129 role = QDialogButtonBox::ApplyRole;
133 role = QDialogButtonBox::YesRole;
137 role = QDialogButtonBox::RejectRole;
140 role = QDialogButtonBox::NoRole;
145 role = QDialogButtonBox::ActionRole;
148 role = QDialogButtonBox::InvalidRole;
152 if ( role == QDialogButtonBox::InvalidRole )
156 mButtonBox->addButton( button, role );
158 mButtonList.insert( key, button );
159 mButtonSignalMapper.setMapping( button, key );
161 QObject::connect(button, SIGNAL(clicked()),
162 &mButtonSignalMapper, SLOT(map()) );
164 if (key == mDefaultButton) {
166 q->setDefaultButton(mDefaultButton);
170void KDialogPrivate::init(
KDialog *q)
179 q->connect(&mButtonSignalMapper, SIGNAL(mapped(
int)), q, SLOT(slotButtonClicked(
int)));
184void KDialogPrivate::helpLinkClicked()
209 if ( d->mButtonBox ) {
210 d->mButtonList.clear();
212 delete d->mButtonBox;
216 if ( buttonMask &
Cancel )
217 buttonMask &= ~Close;
219 if ( buttonMask &
Apply )
223 buttonMask &= ~Default;
225 if ( buttonMask ==
None ) {
230 d->mEscapeButton = (buttonMask & Cancel) ? Cancel :
Close;
233 if ( buttonMask &
Help )
237 if ( buttonMask &
Reset )
239 if ( buttonMask &
User3 )
240 d->appendButton( User3,
KGuiItem() );
241 if ( buttonMask &
User2 )
242 d->appendButton( User2,
KGuiItem() );
243 if ( buttonMask &
User1 )
244 d->appendButton( User1,
KGuiItem() );
245 if ( buttonMask &
Ok )
247 if ( buttonMask & Apply )
249 if ( buttonMask &
Try )
251 if ( buttonMask & Cancel )
253 if ( buttonMask &
Close )
255 if ( buttonMask &
Yes )
257 if ( buttonMask &
No )
259 if ( buttonMask & Details ) {
260 d->appendButton( Details,
KGuiItem(QString(),
"help-about") );
271 if ( d->mButtonOrientation != orientation ) {
272 d->mButtonOrientation = orientation;
274 if ( d->mActionSeparator )
275 d->mActionSeparator->setOrientation( d->mButtonOrientation );
277 if ( d->mButtonOrientation == Qt::Vertical )
284 d_func()->mEscapeButton = id;
291 if (newDefaultButton ==
None)
296 bool oldDefaultHadFocus =
false;
301 oldDefaultHadFocus = (focusWidget() == old);
302 old->setDefault(
false);
310 if (focusWidget() == 0 || oldDefaultHadFocus) {
320 d->mDefaultButton = newDefaultButton;
327 QHashIterator<int, KPushButton*> it( d->mButtonList );
328 while ( it.hasNext() ) {
330 if (it.value()->isDefault()) {
335 return d->mDefaultButton;
341 if ( d->mMainWidget == widget )
343 d->mMainWidget = widget;
344 if (d->mMainWidget && d->mMainWidget->layout()) {
346 d->mMainWidget->layout()->setMargin(0);
356 return d->mMainWidget;
363 if (!d->mMinSize.isEmpty())
367 const_cast<KDialogPrivate*
>(d)->queuedLayoutUpdate();
368 return QDialog::sizeHint() + d->mIncSize;
377 const_cast<KDialogPrivate*
>(d)->queuedLayoutUpdate();
378 return QDialog::minimumSizeHint() + d->mIncSize;
387 if ( event->modifiers() == 0 ) {
388 if ( event->key() == Qt::Key_F1 ) {
392 button->animateClick();
398 if ( event->key() == Qt::Key_Escape ) {
399 KPushButton *button = this->button( d->mEscapeButton );
402 button->animateClick();
408 }
else if ( event->key() == Qt::Key_F1 && event->modifiers() == Qt::ShiftModifier ) {
409 QWhatsThis::enterWhatsThisMode();
412 }
else if ( event->modifiers() == Qt::ControlModifier &&
413 ( event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter ) ) {
418 button->animateClick();
424 QDialog::keyPressEvent( event );
429 return QApplication::style()->pixelMetric( QStyle::PM_DefaultChildMargin );
434 return QApplication::style()->pixelMetric( QStyle::PM_DefaultLayoutSpacing );
439 return QApplication::fontMetrics().lineSpacing();
448 QString captionString = userCaption.isEmpty() ? caption : userCaption;
452 captionString += QString::fromUtf8(
" [") +
i18n(
"modified") + QString::fromUtf8(
"]");
454 if ( !userCaption.isEmpty() ) {
458 !caption.isEmpty() &&
459 !userCaption.endsWith(caption) ) {
462 captionString +=
i18nc(
"Document/application separator in titlebar",
" – ") + caption;
466 return captionString;
491 win->setWindowTitle( caption );
493 NETWinInfo info( QX11Info::display(), win->winId(), QX11Info::appRootWindow(), 0 );
494 info.
setName( caption.toUtf8().constData() );
501 if ( widget->layout() )
504 if ( widget->children().count() > 0 ) {
506 foreach (
QObject *
object, list ) {
507 if ( object->isWidgetType() )
518 while ( (child = layout->itemAt( pos ) ) ) {
519 if ( child->layout() )
525 if ( layout->layout() ) {
526 layout->layout()->setMargin( margin );
527 layout->layout()->setSpacing( spacing );
533 QDesktopWidget *desktop = QApplication::desktop();
536 if ( desktop->isVirtualDesktop() &&
537 cg.
readEntry(
"XineramaEnabled",
true ) &&
538 cg.
readEntry(
"XineramaPlacementEnabled",
true ) ) {
540 if ( screen < 0 || screen >= desktop->numScreens() ) {
542 screen = desktop->primaryScreen();
543 else if ( screen == -3 )
544 screen = desktop->screenNumber( QCursor::pos() );
546 screen = desktop->screenNumber( widget );
549 return desktop->availableGeometry( screen );
551 return desktop->geometry();
560 if( !( widget->windowFlags() & Qt::X11BypassWindowManagerHint ) && widget->windowType() != Qt::Popup
568 widget->move( rect.center().x() - widget->width() / 2,
569 rect.center().y() - widget->height() / 2 );
577 QRect fg = widget->frameGeometry();
578 if ( !fg.intersects( area ) )
581 const QRect scr =
screenRect( widget, screen );
583 avoid.translate( -5, -5 );
584 avoid.setRight( avoid.right() + 10 );
585 avoid.setBottom( avoid.bottom() + 10 );
587 if ( qMax( fg.top(), avoid.top() ) <= qMin( fg.bottom(), avoid.bottom() ) ) {
589 int spaceAbove = qMax( 0, avoid.top() - scr.top() );
590 int spaceBelow = qMax( 0, scr.bottom() - avoid.bottom() );
591 if ( spaceAbove > spaceBelow )
592 if ( fg.height() <= spaceAbove )
593 fg.setY( avoid.top() - fg.height() );
597 if ( fg.height() <= spaceBelow )
598 fg.setY( avoid.bottom() );
603 if ( qMax( fg.left(), avoid.left() ) <= qMin( fg.right(), avoid.right() ) ) {
605 const int spaceLeft = qMax( 0, avoid.left() - scr.left() );
606 const int spaceRight = qMax( 0, scr.right() - avoid.right() );
607 if ( spaceLeft > spaceRight )
608 if ( fg.width() <= spaceLeft )
609 fg.setX( avoid.left() - fg.width() );
613 if ( fg.width() <= spaceRight )
614 fg.setX( avoid.right() );
619 widget->move( fg.x(), fg.y() );
627 if ( ( d->mActionSeparator != 0 ) == state )
630 if ( d->mActionSeparator )
634 d->mActionSeparator->setOrientation( d->mButtonOrientation );
636 delete d->mActionSeparator;
637 d->mActionSeparator = 0;
645 d_func()->mMinSize = size;
651 d_func()->mIncSize = size;
658 return d->mButtonList.value(
id, 0 );
665 button->setEnabled( state );
672 return button->isEnabled();
696 state ? button->show() : button->hide();
713 button->setMenu( menu );
722 if ( !d->mSettingDetails && (
id ==
Details) ) {
723 d->mDetailsButtonText = text;
737 return button->text();
753 return KIcon(button->icon());
762 if ( text.isEmpty() )
763 button->setToolTip( QString() );
765 button->setToolTip( text );
773 return button->toolTip();
782 if ( text.isEmpty() )
783 button->setWhatsThis( QString() );
785 button->setWhatsThis( text );
793 return button->whatsThis();
809 if ( d->mDetailsWidget == detailsWidget )
811 delete d->mDetailsWidget;
812 d->mDetailsWidget = detailsWidget;
814 if ( d->mDetailsWidget->parentWidget() !=
this )
815 d->mDetailsWidget->setParent(
this );
817 d->mDetailsWidget->hide();
820 if ( !d->mSettingDetails )
826 return d_func()->mDetailsVisible;
832 if ( d->mDetailsButtonText.isEmpty() )
833 d->mDetailsButtonText =
i18n(
"&Details" );
835 d->mSettingDetails =
true;
836 d->mDetailsVisible = visible;
837 if ( d->mDetailsVisible ) {
840 if ( d->mDetailsWidget ) {
842 layout()->setEnabled(
false );
844 d->mDetailsWidget->show();
849 layout()->activate();
850 layout()->setEnabled(
true );
855 if ( d->mDetailsWidget )
856 d->mDetailsWidget->hide();
859 layout()->activate();
865 d->mSettingDetails =
false;
920 if ( !d->mAnchor.isEmpty() || !d->mHelpApp.isEmpty() )
935 if (d->mDeferredDelete) {
936 d->mDeferredDelete =
false;
944 if ( ( d->mUrlHelp != 0 ) == state )
952 d->mUrlHelp->setFloatEnabled(
true );
953 d->mUrlHelp->setUnderline(
true );
954 d->mUrlHelp->setMinimumHeight( fontMetrics().height() +
marginHint() );
955 connect( d->mUrlHelp, SIGNAL(leftClickedUrl()), SLOT(helpLinkClicked()) );
971 d->mHelpApp = appname;
978 d->mHelpLinkText = text;
986 return ( d->mHelpLinkText.isEmpty() ?
i18n(
"Get help..." ) : d->mHelpLinkText );
997 if ( !event->spontaneous() )
1004 KPushButton *button = this->button(d->mEscapeButton);
1005 if (button && !isHidden()) {
1006 button->animateClick();
1008 if (testAttribute(Qt::WA_DeleteOnClose)) {
1010 d->mDeferredDelete =
true;
1011 setAttribute(Qt::WA_DeleteOnClose,
false);
1014 QDialog::closeEvent(event);
1021 int scnum = QApplication::desktop()->screenNumber( parentWidget() );
1022 QRect desk = QApplication::desktop()->screenGeometry( scnum );
1027 width = cfg.
readEntry( QString::fromLatin1(
"Width %1" ).arg( desk.width() ), width );
1028 height = cfg.
readEntry( QString::fromLatin1(
"Height %1" ).arg( desk.height() ), height );
1030 resize( width, height );
1035 int scnum = QApplication::desktop()->screenNumber( parentWidget() );
1036 QRect desk = QApplication::desktop()->screenGeometry( scnum );
1038 const QSize sizeToSave = size();
1040 config.writeEntry( QString::fromLatin1(
"Width %1").arg( desk.width() ), sizeToSave.width(), options );
1041 config.writeEntry( QString::fromLatin1(
"Height %1").arg( desk.height() ), sizeToSave.height(), options );
1050class KDialogQueue::Private
1053 Private(KDialogQueue *q): q(q) {}
1055 void slotShowQueuedDialog();
1063KDialogQueue* KDialogQueue::self()
1069KDialogQueue::KDialogQueue()
1070 : d( new Private(this) )
1075KDialogQueue::~KDialogQueue()
1081void KDialogQueue::queueDialog(
QDialog *dialog )
1083 KDialogQueue *_this = self();
1084 _this->d->queue.append( dialog );
1086 QTimer::singleShot( 0, _this, SLOT(slotShowQueuedDialog()) );
1089void KDialogQueue::Private::slotShowQueuedDialog()
1096 if ( queue.isEmpty() )
1098 dialog = queue.first();
1107 if ( !queue.isEmpty() )
1108 QTimer::singleShot( 20, q, SLOT(slotShowQueuedDialog()) );
1111#include "kdialog.moc"
1112#include "kdialogqueue_p.moc"
QString readEntry(const char *key, const char *aDefault=0) const
A dialog base class with standard buttons and predefined layouts.
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
virtual QSize minimumSizeHint() const
Reimplemented from QDialog.
void defaultClicked()
The Default button was pressed.
void setButtonIcon(ButtonCode id, const KIcon &icon)
Sets the icon of any button.
~KDialog()
Destroys the dialog.
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text,...
void setButtonMenu(ButtonCode id, QMenu *menu, ButtonPopupMode popupmode=InstantPopup)
Sets the menu of any button.
void incrementInitialSize(const QSize &size)
Convenience method.
static void resizeLayout(QWidget *widget, int margin, int spacing)
Resize every layout manager used in widget and its nested children.
QString buttonText(ButtonCode id) const
Returns the text of any button.
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
void setInitialSize(const QSize &size)
Convenience method.
static int groupSpacingHint()
Returns the number of pixels that should be used to visually separate groups of related options in a ...
void enableLinkedHelp(bool state)
Display or hide the help link area on the top of the dialog.
virtual void closeEvent(QCloseEvent *e)
Detects when a dialog is being closed from the window manager controls.
void setButtonFocus(ButtonCode id)
Sets the focus to the button of the passed id.
void setButtonToolTip(ButtonCode id, const QString &text)
Sets the tooltip text of any button.
KPushButton * button(ButtonCode id) const
Returns the button that corresponds to the id.
void setButtonWhatsThis(ButtonCode id, const QString &text)
Sets the "What's this?" text of any button.
void aboutToShowDetails()
The detailsWidget is about to get shown.
virtual void setPlainCaption(const QString &caption)
Make a plain caption without any modifications.
void setHelp(const QString &anchor, const QString &appname=QString())
Sets the help path and topic.
virtual QSize sizeHint() const
Reimplemented from QDialog.
static void setAllowEmbeddingInGraphicsView(bool allowEmbedding)
Allow embedding the dialogs based on KDialog into a graphics view.
void setHelpLinkText(const QString &text)
Sets the text that is shown as the linked text.
virtual void hideEvent(QHideEvent *)
Emits the #hidden signal.
void closeClicked()
The Close button was pressed.
void enableButtonOk(bool state)
Enable or disable (gray out) the OK button.
virtual void slotButtonClicked(int button)
Activated when the button button is clicked.
static bool avoidArea(QWidget *widget, const QRect &area, int screen=-1)
Places widget so that it doesn't cover a certain area of the screen.
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
virtual void keyPressEvent(QKeyEvent *)
void user3Clicked()
The User3 button was pressed.
bool isDetailsWidgetVisible() const
Returns the status of the Details button.
void saveDialogSize(KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal) const
Saves the dialog's size dependent on the screen dimension either to the global or application config ...
void restoreDialogSize(const KConfigGroup &config)
Restores the dialog's size from the configuration according to the screen size.
static QString makeStandardCaption(const QString &userCaption, QWidget *window=0, CaptionFlags flags=HIGCompliantCaption)
Builds a caption that contains the application name along with the userCaption using a standard layou...
void tryClicked()
The Try button was pressed.
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
void updateGeometry()
Updates the margins and spacings.
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
void user2Clicked()
The User2 button was pressed.
void resetClicked()
The Reset button was pressed.
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
@ NoDefault
Used when specifying a default button; indicates that no button should be marked by default.
@ Help
Show Help button. (this button will run the help set with setHelp)
@ Details
Show Details button. (this button will show the detail widget set with setDetailsWidget)
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
@ Default
Show Default button.
@ Reset
Show Reset button.
@ Yes
Show Yes button. (this button closes the dialog and sets the result to KDialog::Yes)
@ User1
Show User defined button 1.
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
@ Apply
Show Apply button.
@ Close
Show Close-button. (this button closes the dialog)
@ User3
Show User defined button 3.
@ No
Show No button. (this button closes the dialog and sets the result to KDialog::No)
@ User2
Show User defined button 2.
KDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
Creates a dialog.
static void centerOnScreen(QWidget *widget, int screen=-1)
Centers widget on the desktop, taking multi-head setups into account.
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
KDialogPrivate *const d_ptr
QString helpLinkText() const
Returns the help link text.
void setEscapeButton(ButtonCode id)
Sets the button that will be activated when the Escape key is pressed.
void buttonClicked(KDialog::ButtonCode button)
A button has been pressed.
void yesClicked()
The Yes button was pressed.
void showButtonSeparator(bool state)
Hide or display the separator line drawn between the action buttons an the main widget.
void enableButtonCancel(bool state)
Enable or disable (gray out) the Cancel button.
void okClicked()
The OK button was pressed.
QString buttonWhatsThis(ButtonCode id) const
Returns the "What's this?" text of any button.
void hidden()
The dialog is about to be hidden.
QString buttonToolTip(ButtonCode id) const
Returns the tooltip of any button.
void setDetailsWidget(QWidget *detailsWidget)
Sets the widget that gets shown when "Details" is enabled.
void noClicked()
The No button was pressed.
void applyClicked()
The Apply button was pressed.
void setButtonsOrientation(Qt::Orientation orientation)
Sets the orientation of the button box.
void enableButtonApply(bool state)
Enable or disable (gray out) the Apply button.
void setDetailsWidgetVisible(bool visible)
Sets the status of the Details button.
void cancelClicked()
The Cancel button was pressed.
void delayedDestruct()
Destruct the dialog delayed.
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
ButtonCode defaultButton() const
Returns the button code of the default button, or NoDefault if there is no default button.
void helpClicked()
The Help button was pressed.
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
KIcon buttonIcon(ButtonCode id) const
Returns the icon of any button.
void user1Clicked()
The User1 button was pressed.
bool isButtonEnabled(ButtonCode id) const
Returns whether any button is enabled.
void finished()
The dialog has finished.
An abstract class for GUI data such as ToolTip and Icon.
A wrapper around QIcon that provides KDE icon features.
Standard horizontal or vertical separator.
A drop-in replacement for QLabel that displays hyperlinks.
Common API for root window properties/protocols.
Common API for application window properties/protocols.
void setName(const char *name)
Sets the name for the application window.
#define K_GLOBAL_STATIC(TYPE, NAME)
static bool sAllowEmbeddingInGraphicsView
static QRect screenRect(QWidget *widget, int screen)
QString i18n(const char *text)
QString i18nc(const char *ctxt, const char *text)
KGuiItem reset()
Returns the 'Reset' gui item.
KGuiItem yes()
Returns the 'Yes' gui item.
KGuiItem no()
Returns the 'No' gui item.
KGuiItem cancel()
Returns the 'Cancel' gui item.
KGuiItem defaults()
Returns the 'Defaults' gui item.
KGuiItem apply()
Returns the 'Apply' gui item.
KGuiItem ok()
Returns the 'Ok' gui item.
KGuiItem help()
Returns the 'Help' gui item.
KGuiItem close()
Returns the 'Close' gui item.