24 #include "kdialog_p.h" 26 #include "kdialogqueue_p.h" 30 #include <QApplication> 31 #include <QDesktopWidget> 32 #include <QDialogButtonBox> 33 #include <QHBoxLayout> 38 #include <QVBoxLayout> 49 #include <qx11info_x11.h> 55 void KDialogPrivate::setupLayout()
59 QMetaObject::invokeMethod( q,
"queuedLayoutUpdate", Qt::QueuedConnection );
64 void 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);
170 void KDialogPrivate::init(
KDialog *q)
179 q->connect(&mButtonSignalMapper, SIGNAL(mapped(
int)), q, SLOT(slotButtonClicked(
int)));
184 void 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 )
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 ) {
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;
880 emit
buttonClicked( static_cast<KDialog::ButtonCode>(button) );
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() )
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 );
1050 class KDialogQueue::Private
1055 void slotShowQueuedDialog();
1069 KDialogQueue::KDialogQueue()
1070 : d(
new Private(
this) )
1075 KDialogQueue::~KDialogQueue()
1081 void KDialogQueue::queueDialog(
QDialog *dialog )
1084 _this->d->queue.append( dialog );
1086 QTimer::singleShot( 0, _this, SLOT(slotShowQueuedDialog()) );
1089 void 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" KGuiItem cancel()
Returns the 'Cancel' gui item.
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
void helpClicked()
The Help button was pressed.
QString i18n(const char *text)
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text, tooltip and whatsthis strings.
static void centerOnScreen(QWidget *widget, int screen=-1)
Centers widget on the desktop, taking multi-head setups into account.
void okClicked()
The OK button was pressed.
void setInitialSize(const QSize &size)
Convenience method.
void yesClicked()
The Yes button was pressed.
void delayedDestruct()
Destruct the dialog delayed.
KDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
Creates a dialog.
void finished()
The dialog has finished.
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 defaultClicked()
The Default button was pressed.
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected) ...
#define K_GLOBAL_STATIC(TYPE, NAME)
void user3Clicked()
The User3 button was pressed.
void setHelp(const QString &anchor, const QString &appname=QString())
Sets the help path and topic.
Show Yes button. (this button closes the dialog and sets the result to KDialog::Yes) ...
static void resizeLayout(QWidget *widget, int margin, int spacing)
Resize every layout manager used in widget and its nested children.
static void setAllowEmbeddingInGraphicsView(bool allowEmbedding)
Allow embedding the dialogs based on KDialog into a graphics view.
bool isSupported(NET::Property property) const
Returns true if the given property is supported by the window manager.
void updateGeometry()
Updates the margins and spacings.
QString buttonToolTip(ButtonCode id) const
Returns the tooltip of any button.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
void incrementInitialSize(const QSize &size)
Convenience method.
A dialog base class with standard buttons and predefined layouts.
virtual void slotButtonClicked(int button)
Activated when the button button is clicked.
void setButtonWhatsThis(ButtonCode id, const QString &text)
Sets the "What's this?" text of any button.
void buttonClicked(KDialog::ButtonCode button)
A button has been pressed.
ButtonCode defaultButton() const
Returns the button code of the default button, or NoDefault if there is no default button...
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.
Common API for root window properties/protocols.
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
void enableButtonApply(bool state)
Enable or disable (gray out) the Apply button.
QString helpLinkText() const
Returns the help link text.
QString i18nc(const char *ctxt, const char *text)
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
bool isButtonEnabled(ButtonCode id) const
Returns whether any button is enabled.
KIcon buttonIcon(ButtonCode id) const
Returns the icon of any button.
Standard horizontal or vertical separator.
void showButtonSeparator(bool state)
Hide or display the separator line drawn between the action buttons an the main widget.
KDialogPrivate *const d_ptr
void hidden()
The dialog is about to be hidden.
void aboutToShowDetails()
The detailsWidget is about to get shown.
static QRect screenRect(QWidget *widget, int screen)
void setButtonMenu(ButtonCode id, QMenu *menu, ButtonPopupMode popupmode=InstantPopup)
Sets the menu of any button.
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 user2Clicked()
The User2 button was pressed.
void setButtonsOrientation(Qt::Orientation orientation)
Sets the orientation of the button box.
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
void cancelClicked()
The Cancel button was pressed.
Show Close-button. (this button closes the dialog)
void setEscapeButton(ButtonCode id)
Sets the button that will be activated when the Escape key is pressed.
An abstract class for GUI data such as ToolTip and Icon.
void setHelpLinkText(const QString &text)
Sets the text that is shown as the linked text.
A wrapper around QIcon that provides KDE icon features.
void closeClicked()
The Close button was pressed.
void applyClicked()
The Apply button was pressed.
void resetClicked()
The Reset button was pressed.
static bool sAllowEmbeddingInGraphicsView
void restoreDialogSize(const KConfigGroup &config)
Restores the dialog's size from the configuration according to the screen size.
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 setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Show Help button. (this button will run the help set with setHelp)
Show User defined button 3.
void setButtonIcon(ButtonCode id, const KIcon &icon)
Sets the icon of any button.
KGuiItem apply()
Returns the 'Apply' gui item.
QString buttonText(ButtonCode id) const
Returns the text of any button.
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted) ...
void enableButtonOk(bool state)
Enable or disable (gray out) the OK button.
static int groupSpacingHint()
Returns the number of pixels that should be used to visually separate groups of related options in a ...
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
bool isDetailsWidgetVisible() const
Returns the status of the Details button.
KGuiItem close()
Returns the 'Close' gui item.
void setDetailsWidget(QWidget *detailsWidget)
Sets the widget that gets shown when "Details" is enabled.
KGuiItem ok()
Returns the 'Ok' gui item.
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
virtual QSize minimumSizeHint() const
Reimplemented from QDialog.
KGuiItem help()
Returns the 'Help' gui item.
Show No button. (this button closes the dialog and sets the result to KDialog::No) ...
virtual QSize sizeHint() const
Reimplemented from QDialog.
T readEntry(const QString &key, const T &aDefault) const
Used when specifying a default button; indicates that no button should be marked by default...
Show User defined button 2.
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
KGuiItem no()
Returns the 'No' gui item.
virtual void hideEvent(QHideEvent *)
Emits the hidden signal.
QString buttonWhatsThis(ButtonCode id) const
Returns the "What's this?" text of any button.
void setDetailsWidgetVisible(bool visible)
Sets the status of the Details button.
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
void enableButtonCancel(bool state)
Enable or disable (gray out) the Cancel button.
KGuiItem defaults()
Returns the 'Defaults' gui item.
Common API for application window properties/protocols.
KGuiItem reset()
Returns the 'Reset' gui item.
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
virtual void setPlainCaption(const QString &caption)
Make a plain caption without any modifications.
void user1Clicked()
The User1 button was pressed.
Show User defined button 1.
void enableLinkedHelp(bool state)
Display or hide the help link area on the top of the dialog.
virtual void keyPressEvent(QKeyEvent *)
Show Details button. (this button will show the detail widget set with setDetailsWidget) ...
void setName(const char *name)
Sets the name for the application window.
virtual void closeEvent(QCloseEvent *e)
Detects when a dialog is being closed from the window manager controls.
A drop-in replacement for QLabel that displays hyperlinks.
KGuiItem yes()
Returns the 'Yes' gui item.
KPushButton * button(ButtonCode id) const
Returns the button that corresponds to the id.
~KDialog()
Destroys the dialog.
void tryClicked()
The Try button was pressed.
void noClicked()
The No button was pressed.