• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • krita API Reference
  • KDE Home
  • Contact Us
 

KritaWidgets

  • sources
  • kfour-appscomplete
  • krita
  • libs
  • widgets
KoDialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE Libraries
2  * SPDX-FileCopyrightText: 1998 Thomas Tanghus ([email protected])
3  * SPDX-FileCopyrightText: 1999-2000 Espen Sand ([email protected])
4  * SPDX-FileCopyrightText: 1999-2000 Holger Freyther <[email protected]>
5  * SPDX-FileCopyrightText: 2005-2009 Olivier Goffart (ogoffart at kde.org)
6  *
7  * SPDX-License-Identifier: LGPL-2.0-or-later
8  */
9 
10 #include "KoDialog.h"
11 #include "KoDialog_p.h"
12 
13 #include <QApplication>
14 #include <QGuiApplication>
15 #include <QDialogButtonBox>
16 #include <QHBoxLayout>
17 #include <QHideEvent>
18 #include <QPointer>
19 #include <QStyle>
20 #include <QTimer>
21 #include <QVBoxLayout>
22 #include <QWhatsThis>
23 #include <QDebug>
24 #include <QPushButton>
25 
26 #include <kconfig.h>
27 #include <klocalizedstring.h>
28 
29 #include <kseparator.h>
30 #include <kstandardguiitem.h>
31 #include <khelpclient.h>
32 #include <kurllabel.h>
33 #include <kwindowconfig.h>
34 
35 void KoDialogPrivate::setupLayout()
36 {
37  Q_Q(KoDialog);
38  if (!dirty) {
39  QMetaObject::invokeMethod(q, "queuedLayoutUpdate", Qt::QueuedConnection);
40  dirty = true;
41  }
42 }
43 
44 void KoDialogPrivate::queuedLayoutUpdate()
45 {
46  if (!dirty) {
47  return;
48  }
49 
50  dirty = false;
51 
52  Q_Q(KoDialog);
53 
54  // Don't lose the focus widget when re-creating the layout.
55  // Testcase: KOrganizer's "Select Categories" dialog
56  QPointer<QWidget> focusWidget = mMainWidget ? mMainWidget->focusWidget() : 0;
57 
58  if (q->layout() && q->layout() != mTopLayout) {
59  qWarning() << q->metaObject()->className() << "created with a layout; don't do that, KoDialog takes care of it, use mainWidget or setMainWidget instead";
60  delete q->layout();
61  }
62 
63  delete mTopLayout;
64 
65  if (mButtonOrientation == Qt::Horizontal) {
66  mTopLayout = new QVBoxLayout(q);
67  } else {
68  mTopLayout = new QHBoxLayout(q);
69  }
70 
71  if (mUrlHelp) {
72  mTopLayout->addWidget(mUrlHelp, 0, Qt::AlignRight);
73  }
74 
75  if (mMainWidget) {
76  mTopLayout->addWidget(mMainWidget, 10);
77  }
78 
79  if (mDetailsWidget) {
80  mTopLayout->addWidget(mDetailsWidget);
81  }
82 
83  if (mActionSeparator) {
84  mTopLayout->addWidget(mActionSeparator);
85  }
86 
87  if (mButtonBox) {
88  mButtonBox->setOrientation(mButtonOrientation);
89  mTopLayout->addWidget(mButtonBox);
90  }
91 
92  if (focusWidget) {
93  focusWidget->setFocus();
94  }
95 }
96 
97 void KoDialogPrivate::appendButton(KoDialog::ButtonCode key, const KGuiItem &item)
98 {
99  Q_Q(KoDialog);
100 
101  QDialogButtonBox::ButtonRole role = QDialogButtonBox::InvalidRole;
102  switch (key) {
103  case KoDialog::Help:
104  case KoDialog::Details:
105  role = QDialogButtonBox::HelpRole;
106  break;
107  case KoDialog::Default:
108  case KoDialog::Reset:
109  role = QDialogButtonBox::ResetRole;
110  break;
111  case KoDialog::Ok:
112  role = QDialogButtonBox::AcceptRole;
113  break;
114  case KoDialog::Apply:
115  role = QDialogButtonBox::ApplyRole;
116  break;
117  case KoDialog::Try:
118  case KoDialog::Yes:
119  role = QDialogButtonBox::YesRole;
120  break;
121  case KoDialog::Close:
122  case KoDialog::Cancel:
123  role = QDialogButtonBox::RejectRole;
124  break;
125  case KoDialog::No:
126  role = QDialogButtonBox::NoRole;
127  break;
128  case KoDialog::User1:
129  case KoDialog::User2:
130  case KoDialog::User3:
131  role = QDialogButtonBox::ActionRole;
132  break;
133  default:
134  role = QDialogButtonBox::InvalidRole;
135  break;
136  }
137 
138  if (role == QDialogButtonBox::InvalidRole) {
139  return;
140  }
141 
142  QPushButton *button = new QPushButton;
143  KGuiItem::assign(button, item);
144  mButtonBox->addButton(button, role);
145 
146  mButtonList.insert(key, button);
147 
148  QObject::connect(button, &QPushButton::clicked, [=] { q->slotButtonClicked(key); });
149 
150  if (key == mDefaultButton) {
151  // Now that it exists, set it as default
152  q->setDefaultButton(mDefaultButton);
153  }
154 }
155 
156 void KoDialogPrivate::init(KoDialog *q)
157 {
158  q_ptr = q;
159 
160  dirty = false;
161 
162  q->setButtons(KoDialog::Ok | KoDialog::Cancel);
163  q->setDefaultButton(KoDialog::Ok);
164 
165  q->setPlainCaption(qApp->applicationDisplayName()); // set appropriate initial window title for case it gets not set later
166 }
167 
168 void KoDialogPrivate::helpLinkClicked()
169 {
170  q_ptr->slotButtonClicked(KoDialog::Help);
171 }
172 
173 KoDialog::KoDialog(QWidget *parent, Qt::WindowFlags flags)
174  : QDialog(parent, flags)
175  , d_ptr(new KoDialogPrivate)
176 {
177  d_ptr->init(this);
178 }
179 
180 KoDialog::KoDialog(KoDialogPrivate &dd, QWidget *parent, Qt::WindowFlags flags)
181  : QDialog(parent, flags)
182  , d_ptr(&dd)
183 {
184  d_ptr->init(this);
185 }
186 
187 KoDialog::~KoDialog()
188 {
189  delete d_ptr;
190 }
191 
192 void KoDialog::setButtons(ButtonCodes buttonMask)
193 {
194  Q_D(KoDialog);
195  if (d->mButtonBox) {
196  d->mButtonList.clear();
197 
198  delete d->mButtonBox;
199  d->mButtonBox = 0;
200  }
201 
202  if (buttonMask & Cancel) {
203  buttonMask &= ~Close;
204  }
205 
206  if (buttonMask & Apply) {
207  buttonMask &= ~Try;
208  }
209 
210  if (buttonMask & Details) {
211  buttonMask &= ~Default;
212  }
213 
214  if (buttonMask == None) {
215  d->setupLayout();
216  return; // When we want no button box
217  }
218 
219  d->mEscapeButton = (buttonMask & Cancel) ? Cancel : Close;
220  d->mButtonBox = new QDialogButtonBox(this);
221 
222  if (buttonMask & Help) {
223  d->appendButton(Help, KStandardGuiItem::help());
224  }
225  if (buttonMask & Default) {
226  d->appendButton(Default, KStandardGuiItem::defaults());
227  }
228  if (buttonMask & Reset) {
229  d->appendButton(Reset, KStandardGuiItem::reset());
230  }
231  if (buttonMask & User3) {
232  d->appendButton(User3, KGuiItem());
233  }
234  if (buttonMask & User2) {
235  d->appendButton(User2, KGuiItem());
236  }
237  if (buttonMask & User1) {
238  d->appendButton(User1, KGuiItem());
239  }
240  if (buttonMask & Ok) {
241  d->appendButton(Ok, KStandardGuiItem::ok());
242  }
243  if (buttonMask & Apply) {
244  d->appendButton(Apply, KStandardGuiItem::apply());
245  }
246  if (buttonMask & Try) {
247  d->appendButton(Try, KGuiItem(i18n("&Try")));
248  }
249  if (buttonMask & Cancel) {
250  d->appendButton(Cancel, KStandardGuiItem::cancel());
251  }
252  if (buttonMask & Close) {
253  d->appendButton(Close, KStandardGuiItem::close());
254  }
255  if (buttonMask & Yes) {
256  d->appendButton(Yes, KStandardGuiItem::yes());
257  }
258  if (buttonMask & No) {
259  d->appendButton(No, KStandardGuiItem::no());
260  }
261  if (buttonMask & Details) {
262  d->appendButton(Details, KGuiItem(QString(), "help-about"));
263  setDetailsWidgetVisible(false);
264  }
265 
266  d->setupLayout();
267 }
268 
269 void KoDialog::setButtonsOrientation(Qt::Orientation orientation)
270 {
271  Q_D(KoDialog);
272  if (d->mButtonOrientation != orientation) {
273  d->mButtonOrientation = orientation;
274 
275  if (d->mActionSeparator) {
276  d->mActionSeparator->setOrientation(d->mButtonOrientation);
277  }
278 
279  if (d->mButtonOrientation == Qt::Vertical) {
280  enableLinkedHelp(false); // 2000-06-18 Espen: No support for this yet.
281  }
282  }
283 }
284 
285 void KoDialog::setEscapeButton(ButtonCode id)
286 {
287  d_func()->mEscapeButton = id;
288 }
289 
290 void KoDialog::setDefaultButton(ButtonCode newDefaultButton)
291 {
292  Q_D(KoDialog);
293 
294  if (newDefaultButton == None) {
295  newDefaultButton = NoDefault; // #148969
296  }
297 
298  const KoDialog::ButtonCode oldDefault = defaultButton();
299 
300  bool oldDefaultHadFocus = false;
301 
302  if (oldDefault != NoDefault) {
303  QPushButton *old = button(oldDefault);
304  if (old) {
305  oldDefaultHadFocus = (focusWidget() == old);
306  old->setDefault(false);
307  }
308  }
309 
310  if (newDefaultButton != NoDefault) {
311  QPushButton *b = button(newDefaultButton);
312  if (b) {
313  b->setDefault(true);
314  if (focusWidget() == 0 || oldDefaultHadFocus) {
315  // No widget had focus yet, or the old default button had
316  // -> ok to give focus to the new default button, so that it's
317  // really default (Enter triggers it).
318  // But we don't do this if the kdialog user gave focus to a
319  // specific widget in the dialog.
320  b->setFocus();
321  }
322  }
323  }
324  d->mDefaultButton = newDefaultButton;
325  Q_ASSERT(defaultButton() == newDefaultButton);
326 }
327 
328 KoDialog::ButtonCode KoDialog::defaultButton() const
329 {
330  Q_D(const KoDialog);
331  QHashIterator<int, QPushButton *> it(d->mButtonList);
332  while (it.hasNext()) {
333  it.next();
334  if (it.value()->isDefault()) {
335  return (ButtonCode)it.key();
336  }
337  }
338 
339  return d->mDefaultButton;
340 }
341 
342 void KoDialog::setMainWidget(QWidget *widget)
343 {
344  Q_D(KoDialog);
345  if (d->mMainWidget == widget) {
346  return;
347  }
348  d->mMainWidget = widget;
349  if (d->mMainWidget && d->mMainWidget->layout()) {
350  // Avoid double-margin problem
351  d->mMainWidget->layout()->setMargin(0);
352  }
353  d->setupLayout();
354 }
355 
356 QWidget *KoDialog::mainWidget()
357 {
358  Q_D(KoDialog);
359  if (!d->mMainWidget) {
360  setMainWidget(new QWidget(this));
361  }
362  return d->mMainWidget;
363 }
364 
365 QSize KoDialog::sizeHint() const
366 {
367  Q_D(const KoDialog);
368 
369  if (!d->mMinSize.isEmpty()) {
370  return d->mMinSize.expandedTo(minimumSizeHint()) + d->mIncSize;
371  } else {
372  if (d->dirty) {
373  const_cast<KoDialogPrivate *>(d)->queuedLayoutUpdate();
374  }
375  return QDialog::sizeHint() + d->mIncSize;
376  }
377 }
378 
379 QSize KoDialog::minimumSizeHint() const
380 {
381  Q_D(const KoDialog);
382 
383  if (d->dirty) {
384  const_cast<KoDialogPrivate *>(d)->queuedLayoutUpdate();
385  }
386  return QDialog::minimumSizeHint() + d->mIncSize;
387 }
388 
389 //
390 // Grab QDialogs keypresses if non-modal.
391 //
392 void KoDialog::keyPressEvent(QKeyEvent *event)
393 {
394  Q_D(KoDialog);
395  if (event->modifiers() == 0) {
396  if (event->key() == Qt::Key_F1) {
397  QPushButton *button = this->button(Help);
398 
399  if (button) {
400  button->animateClick();
401  event->accept();
402  return;
403  }
404  }
405 
406  if (event->key() == Qt::Key_Escape) {
407  QPushButton *button = this->button(d->mEscapeButton);
408 
409  if (button) {
410  button->animateClick();
411  event->accept();
412  return;
413  }
414 
415  }
416  } else if (event->key() == Qt::Key_F1 && event->modifiers() == Qt::ShiftModifier) {
417  QWhatsThis::enterWhatsThisMode();
418  event->accept();
419  return;
420  } else if (event->modifiers() == Qt::ControlModifier &&
421  (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) {
422  // accept the dialog when Ctrl-Return is pressed
423  QPushButton *button = this->button(Ok);
424 
425  if (button) {
426  button->animateClick();
427  event->accept();
428  return;
429  }
430  }
431 
432  QDialog::keyPressEvent(event);
433 }
434 
435 int KoDialog::marginHint()
436 {
437  return QApplication::style()->pixelMetric(QStyle::PM_DefaultChildMargin);
438 }
439 
440 int KoDialog::spacingHint()
441 {
442  return QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
443 }
444 
445 int KoDialog::groupSpacingHint()
446 {
447  return QApplication::fontMetrics().lineSpacing();
448 }
449 
450 QString KoDialog::makeStandardCaption(const QString &userCaption,
451  QWidget *window,
452  CaptionFlags flags)
453 {
454  Q_UNUSED(window);
455  QString caption = qApp->applicationDisplayName();
456  QString captionString = userCaption.isEmpty() ? caption : userCaption;
457 
458  // If the document is modified, add '[modified]'.
459  if (flags & ModifiedCaption) {
460  captionString += QString::fromUtf8(" [") + i18n("modified") + QString::fromUtf8("]");
461  }
462 
463  if (!userCaption.isEmpty()) {
464  // Add the application name if:
465  // User asked for it, it's not a duplication and the app name (caption()) is not empty
466  if (flags & AppNameCaption &&
467  !caption.isEmpty() &&
468  !userCaption.endsWith(caption)) {
469  // TODO: check to see if this is a transient/secondary window before trying to add the app name
470  // on platforms that need this
471  captionString += i18nc("Document/application separator in titlebar", " – ") + caption;
472  }
473  }
474 
475  return captionString;
476 }
477 
478 void KoDialog::setCaption(const QString &_caption)
479 {
480  const QString caption = makeStandardCaption(_caption, this);
481  setPlainCaption(caption);
482 }
483 
484 void KoDialog::setCaption(const QString &caption, bool modified)
485 {
486  CaptionFlags flags = HIGCompliantCaption;
487 
488  // ### Qt5 TODO: port to [*], see QWidget::setWindowFilePath
489  if (modified) {
490  flags |= ModifiedCaption;
491  }
492 
493  setPlainCaption(makeStandardCaption(caption, this, flags));
494 }
495 
496 void KoDialog::setPlainCaption(const QString &caption)
497 {
498  if (QWidget *win = window()) {
499  win->setWindowTitle(caption);
500  }
501 }
502 
503 void KoDialog::resizeLayout(QWidget *widget, int margin, int spacing) //static
504 {
505  if (widget->layout()) {
506  resizeLayout(widget->layout(), margin, spacing);
507  }
508 
509  if (widget->children().count() > 0) {
510  const QList<QObject *> list = widget->children();
511  foreach (QObject *object, list) {
512  if (object->isWidgetType()) {
513  resizeLayout((QWidget *)object, margin, spacing);
514  }
515  }
516  }
517 }
518 
519 void KoDialog::resizeLayout(QLayout *layout, int margin, int spacing) //static
520 {
521  QLayoutItem *child;
522  int pos = 0;
523 
524  while ((child = layout->itemAt(pos))) {
525  if (child->layout()) {
526  resizeLayout(child->layout(), margin, spacing);
527  }
528 
529  ++pos;
530  }
531 
532  if (layout->layout()) {
533  layout->layout()->setMargin(margin);
534  layout->layout()->setSpacing(spacing);
535  }
536 }
537 
538 void KoDialog::showButtonSeparator(bool state)
539 {
540  Q_D(KoDialog);
541  if ((d->mActionSeparator != 0) == state) {
542  return;
543  }
544  if (state) {
545  if (d->mActionSeparator) {
546  return;
547  }
548 
549  d->mActionSeparator = new KSeparator(this);
550  d->mActionSeparator->setOrientation(d->mButtonOrientation);
551  } else {
552  delete d->mActionSeparator;
553  d->mActionSeparator = 0;
554  }
555 
556  d->setupLayout();
557 }
558 
559 void KoDialog::setInitialSize(const QSize &size)
560 {
561  d_func()->mMinSize = size;
562  adjustSize();
563 }
564 
565 void KoDialog::incrementInitialSize(const QSize &size)
566 {
567  d_func()->mIncSize = size;
568  adjustSize();
569 }
570 
571 QPushButton *KoDialog::button(ButtonCode id) const
572 {
573  Q_D(const KoDialog);
574  return d->mButtonList.value(id, 0);
575 }
576 
577 void KoDialog::enableButton(ButtonCode id, bool state)
578 {
579  QPushButton *button = this->button(id);
580  if (button) {
581  button->setEnabled(state);
582  }
583 }
584 
585 bool KoDialog::isButtonEnabled(ButtonCode id) const
586 {
587  QPushButton *button = this->button(id);
588  if (button) {
589  return button->isEnabled();
590  }
591 
592  return false;
593 }
594 
595 void KoDialog::enableButtonOk(bool state)
596 {
597  enableButton(Ok, state);
598 }
599 
600 void KoDialog::enableButtonApply(bool state)
601 {
602  enableButton(Apply, state);
603 }
604 
605 void KoDialog::enableButtonCancel(bool state)
606 {
607  enableButton(Cancel, state);
608 }
609 
610 void KoDialog::showButton(ButtonCode id, bool state)
611 {
612  QPushButton *button = this->button(id);
613  if (button) {
614  state ? button->show() : button->hide();
615  }
616 }
617 
618 void KoDialog::setButtonGuiItem(ButtonCode id, const KGuiItem &item)
619 {
620  QPushButton *button = this->button(id);
621  if (!button) {
622  return;
623  }
624 
625  KGuiItem::assign(button, item);
626 }
627 
628 void KoDialog::setButtonText(ButtonCode id, const QString &text)
629 {
630  Q_D(KoDialog);
631  if (!d->mSettingDetails && (id == Details)) {
632  d->mDetailsButtonText = text;
633  setDetailsWidgetVisible(d->mDetailsVisible);
634  return;
635  }
636 
637  QPushButton *button = this->button(id);
638  if (button) {
639  button->setText(text);
640  }
641 }
642 
643 QString KoDialog::buttonText(ButtonCode id) const
644 {
645  QPushButton *button = this->button(id);
646  if (button) {
647  return button->text();
648  } else {
649  return QString();
650  }
651 }
652 
653 void KoDialog::setButtonIcon(ButtonCode id, const QIcon &icon)
654 {
655  QPushButton *button = this->button(id);
656  if (button) {
657  button->setIcon(icon);
658  }
659 }
660 
661 QIcon KoDialog::buttonIcon(ButtonCode id) const
662 {
663  QPushButton *button = this->button(id);
664  if (button) {
665  return button->icon();
666  } else {
667  return QIcon();
668  }
669 }
670 
671 void KoDialog::setButtonToolTip(ButtonCode id, const QString &text)
672 {
673  QPushButton *button = this->button(id);
674  if (button) {
675  if (text.isEmpty()) {
676  button->setToolTip(QString());
677  } else {
678  button->setToolTip(text);
679  }
680  }
681 }
682 
683 QString KoDialog::buttonToolTip(ButtonCode id) const
684 {
685  QPushButton *button = this->button(id);
686  if (button) {
687  return button->toolTip();
688  } else {
689  return QString();
690  }
691 }
692 
693 void KoDialog::setButtonWhatsThis(ButtonCode id, const QString &text)
694 {
695  QPushButton *button = this->button(id);
696  if (button) {
697  if (text.isEmpty()) {
698  button->setWhatsThis(QString());
699  } else {
700  button->setWhatsThis(text);
701  }
702  }
703 }
704 
705 QString KoDialog::buttonWhatsThis(ButtonCode id) const
706 {
707  QPushButton *button = this->button(id);
708  if (button) {
709  return button->whatsThis();
710  } else {
711  return QString();
712  }
713 }
714 
715 void KoDialog::setButtonFocus(ButtonCode id)
716 {
717  QPushButton *button = this->button(id);
718  if (button) {
719  button->setFocus();
720  }
721 }
722 
723 void KoDialog::setDetailsWidget(QWidget *detailsWidget)
724 {
725  Q_D(KoDialog);
726  if (d->mDetailsWidget == detailsWidget) {
727  return;
728  }
729  delete d->mDetailsWidget;
730  d->mDetailsWidget = detailsWidget;
731 
732  if (d->mDetailsWidget->parentWidget() != this) {
733  d->mDetailsWidget->setParent(this);
734  }
735 
736  d->mDetailsWidget->hide();
737  d->setupLayout();
738 
739  if (!d->mSettingDetails) {
740  setDetailsWidgetVisible(d->mDetailsVisible);
741  }
742 }
743 
744 bool KoDialog::isDetailsWidgetVisible() const
745 {
746  return d_func()->mDetailsVisible;
747 }
748 
749 void KoDialog::setDetailsWidgetVisible(bool visible)
750 {
751  Q_D(KoDialog);
752  if (d->mDetailsButtonText.isEmpty()) {
753  d->mDetailsButtonText = i18n("&Details");
754  }
755 
756  d->mSettingDetails = true;
757  d->mDetailsVisible = visible;
758  if (d->mDetailsVisible) {
759  emit aboutToShowDetails();
760  setButtonText(Details, d->mDetailsButtonText + " <<");
761  if (d->mDetailsWidget) {
762  if (layout()) {
763  layout()->setEnabled(false);
764  }
765 
766  d->mDetailsWidget->show();
767 
768  adjustSize();
769 
770  if (layout()) {
771  layout()->activate();
772  layout()->setEnabled(true);
773  }
774  }
775  } else {
776  setButtonText(Details, d->mDetailsButtonText + " >>");
777  if (d->mDetailsWidget) {
778  d->mDetailsWidget->hide();
779  }
780 
781  if (layout()) {
782  layout()->activate();
783  adjustSize();
784  }
785 
786  }
787 
788  d->mSettingDetails = false;
789 }
790 
791 void KoDialog::delayedDestruct()
792 {
793  if (isVisible()) {
794  hide();
795  }
796 
797  deleteLater();
798 }
799 
800 void KoDialog::slotButtonClicked(int button)
801 {
802  Q_D(KoDialog);
803  emit buttonClicked(static_cast<KoDialog::ButtonCode>(button));
804 
805  switch (button) {
806  case Ok:
807  emit okClicked();
808  accept();
809  break;
810  case Apply:
811  emit applyClicked();
812  break;
813  case Try:
814  emit tryClicked();
815  break;
816  case User3:
817  emit user3Clicked();
818  break;
819  case User2:
820  emit user2Clicked();
821  break;
822  case User1:
823  emit user1Clicked();
824  break;
825  case Yes:
826  emit yesClicked();
827  done(Yes);
828  break;
829  case No:
830  emit noClicked();
831  done(No);
832  break;
833  case Cancel:
834  emit cancelClicked();
835  reject();
836  break;
837  case Close:
838  emit closeClicked();
839  done(Close); // KDE5: call reject() instead; more QDialog-like.
840  break;
841  case Help:
842  emit helpClicked();
843  if (!d->mAnchor.isEmpty() || !d->mHelpApp.isEmpty()) {
844  KHelpClient::invokeHelp(d->mAnchor, d->mHelpApp);
845  }
846  break;
847  case Default:
848  emit defaultClicked();
849  break;
850  case Reset:
851  emit resetClicked();
852  break;
853  case Details:
854  setDetailsWidgetVisible(!d->mDetailsVisible);
855  break;
856  }
857 
858  // If we're here from the closeEvent, and auto-delete is on, well, auto-delete now.
859  if (d->mDeferredDelete) {
860  d->mDeferredDelete = false;
861  delayedDestruct();
862  }
863 }
864 
865 void KoDialog::enableLinkedHelp(bool state)
866 {
867  Q_D(KoDialog);
868  if ((d->mUrlHelp != 0) == state) {
869  return;
870  }
871  if (state) {
872  if (d->mUrlHelp) {
873  return;
874  }
875 
876  d->mUrlHelp = new KUrlLabel(this);
877  d->mUrlHelp->setText(helpLinkText());
878  d->mUrlHelp->setFloatEnabled(true);
879  d->mUrlHelp->setUnderline(true);
880  d->mUrlHelp->setMinimumHeight(fontMetrics().height() + marginHint());
881  connect(d->mUrlHelp, SIGNAL(leftClickedUrl()), SLOT(helpLinkClicked()));
882 
883  d->mUrlHelp->show();
884  } else {
885  delete d->mUrlHelp;
886  d->mUrlHelp = 0;
887  }
888 
889  d->setupLayout();
890 }
891 
892 void KoDialog::setHelp(const QString &anchor, const QString &appname)
893 {
894  Q_D(KoDialog);
895  d->mAnchor = anchor;
896  d->mHelpApp = appname;
897 }
898 
899 void KoDialog::setHelpLinkText(const QString &text)
900 {
901  Q_D(KoDialog);
902  d->mHelpLinkText = text;
903  if (d->mUrlHelp) {
904  d->mUrlHelp->setText(helpLinkText());
905  }
906 }
907 
908 QString KoDialog::helpLinkText() const
909 {
910  Q_D(const KoDialog);
911  return (d->mHelpLinkText.isEmpty() ? i18n("Get help...") : d->mHelpLinkText);
912 }
913 
914 void KoDialog::updateGeometry()
915 {
916 }
917 
918 void KoDialog::hideEvent(QHideEvent *event)
919 {
920  emit hidden();
921 
922  if (!event->spontaneous()) {
923  emit finished();
924  }
925 }
926 
927 void KoDialog::closeEvent(QCloseEvent *event)
928 {
929  Q_D(KoDialog);
930  QPushButton *button = this->button(d->mEscapeButton);
931  if (button && !isHidden()) {
932  button->animateClick();
933 
934  if (testAttribute(Qt::WA_DeleteOnClose)) {
935  // Don't let QWidget::close do a deferred delete just yet, wait for the click first
936  d->mDeferredDelete = true;
937  setAttribute(Qt::WA_DeleteOnClose, false);
938  }
939  } else {
940  QDialog::closeEvent(event);
941  }
942 }
943 
944 #include "moc_KoDialog.cpp"
KoDialog::showButtonSeparator
void showButtonSeparator(bool state)
Hide or display the a separator line drawn between the action buttons an the main widget.
Definition: KoDialog.cpp:538
QWidget::adjustSize
void adjustSize()
QDialog::orientation
Qt::Orientation orientation() const
KoDialogPrivate::mUrlHelp
KUrlLabel * mUrlHelp
Definition: KoDialog_p.h:54
QPointer< QWidget >
QLayout::itemAt
virtual QLayoutItem * itemAt(int index) const=0
KoDialog::buttonText
QString buttonText(ButtonCode id) const
Returns the text of any button.
Definition: KoDialog.cpp:643
KoDialog::setDetailsWidgetVisible
void setDetailsWidgetVisible(bool visible)
Sets the status of the Details button.
Definition: KoDialog.cpp:749
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
KoDialogPrivate::mDetailsWidget
QWidget * mDetailsWidget
Definition: KoDialog_p.h:47
QWidget::setWhatsThis
void setWhatsThis(const QString &)
QWidget::setParent
void setParent(QWidget *parent)
KoDialog::updateGeometry
void updateGeometry()
Updates the margins and spacings.
Definition: KoDialog.cpp:914
QVBoxLayout
QWidget::window
QWidget * window() const
KoDialogPrivate::q_ptr
KoDialog * q_ptr
Definition: KoDialog_p.h:39
KoDialog::Try
Show Try button.
Definition: KoDialog.h:129
KoDialog::User1
Show User defined button 1.
Definition: KoDialog.h:136
KoDialog::enableButtonApply
void enableButtonApply(bool state)
Enable or disable (gray out) the Apply button.
Definition: KoDialog.cpp:600
KoDialog::tryClicked
void tryClicked()
The Try button was pressed.
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
KoDialog::User2
Show User defined button 2.
Definition: KoDialog.h:137
KoDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: KoDialog.cpp:478
KoDialog::NoDefault
Used when specifying a default button; indicates that no button should be marked by default.
Definition: KoDialog.h:139
KoDialog::ModifiedCaption
Definition: KoDialog.h:401
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QWidget::pos
QPoint pos() const
QDialog::reject
virtual void reject()
QLayout::layout
virtual QLayout * layout()
KoDialog::buttonClicked
void buttonClicked(KoDialog::ButtonCode button)
A button has been pressed.
KoDialog::setDetailsWidget
void setDetailsWidget(QWidget *detailsWidget)
Sets the widget that gets shown when "Details" is enabled.
Definition: KoDialog.cpp:723
KoDialog::buttonIcon
QIcon buttonIcon(ButtonCode id) const
Returns the icon of any button.
Definition: KoDialog.cpp:661
QWidget::layout
QLayout * layout() const
KoDialog::enableLinkedHelp
void enableLinkedHelp(bool state)
Display or hide the help link area on the top of the dialog.
Definition: KoDialog.cpp:865
KoDialog::isDetailsWidgetVisible
bool isDetailsWidgetVisible() const
Returns the status of the Details button.
Definition: KoDialog.cpp:744
QAbstractButton::clicked
void clicked(bool checked)
QLayout::setMargin
void setMargin(int margin)
QWidget
QApplication::fontMetrics
QFontMetrics fontMetrics()
KoDialog::marginHint
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
Definition: KoDialog.cpp:435
KoDialog::setButtonToolTip
void setButtonToolTip(ButtonCode id, const QString &text)
Sets the tooltip text of any button.
Definition: KoDialog.cpp:671
KoDialog::user2Clicked
void user2Clicked()
The User2 button was pressed.
KoDialogPrivate::appendButton
void appendButton(KoDialog::ButtonCode code, const KGuiItem &item)
Definition: KoDialog.cpp:97
KoDialog::resetClicked
void resetClicked()
The Reset button was pressed.
KoDialog::setHelpLinkText
void setHelpLinkText(const QString &text)
Sets the text that is shown as the linked text.
Definition: KoDialog.cpp:899
KoDialog::helpLinkText
QString helpLinkText() const
Returns the help link text.
Definition: KoDialog.cpp:908
KoDialog::setButtonGuiItem
void setButtonGuiItem(ButtonCode id, const KGuiItem &item)
Sets the KGuiItem directly for the button instead of using 3 methods to set the text,...
Definition: KoDialog.cpp:618
QSize
KoDialog::Default
Show Default button.
Definition: KoDialog.h:126
KoDialogPrivate::mButtonList
QHash< int, QPushButton * > mButtonList
Definition: KoDialog_p.h:66
KoDialog::user1Clicked
void user1Clicked()
The User1 button was pressed.
KoDialog::incrementInitialSize
void incrementInitialSize(const QSize &size)
Convenience method.
Definition: KoDialog.cpp:565
KoDialog.h
KoDialog::Yes
Show Yes button. (this button closes the dialog and sets the result to KoDialog::Yes)
Definition: KoDialog.h:133
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QDialog::closeEvent
virtual void closeEvent(QCloseEvent *e)
KoDialogPrivate::setupLayout
void setupLayout()
Definition: KoDialog.cpp:35
QList
KoDialog_p.h
KoDialog::User3
Show User defined button 3.
Definition: KoDialog.h:138
QHashIterator::value
const T & value() const
KoDialog::setHelp
void setHelp(const QString &anchor, const QString &appname=QString())
Sets the help path and topic.
Definition: KoDialog.cpp:892
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLayout::setEnabled
void setEnabled(bool enable)
QWidget::focusWidget
QWidget * focusWidget() const
KoDialog::setButtonIcon
void setButtonIcon(ButtonCode id, const QIcon &icon)
Sets the icon of any button.
Definition: KoDialog.cpp:653
QHash::insert
iterator insert(const Key &key, const T &value)
QWidget::hide
void hide()
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
KoDialog::okClicked
void okClicked()
The OK button was pressed.
KoDialog
A dialog base class with standard buttons and predefined layouts.
Definition: KoDialog.h:115
QLayout
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const=0
KoDialog::slotButtonClicked
virtual void slotButtonClicked(int button)
Activated when the button button is clicked.
Definition: KoDialog.cpp:800
KoDialog::setButtonText
void setButtonText(ButtonCode id, const QString &text)
Sets the text of any button.
Definition: KoDialog.cpp:628
KoDialog::AppNameCaption
Definition: KoDialog.h:400
QWidget::visible
visible
KoDialog::setEscapeButton
void setEscapeButton(ButtonCode id)
Sets the button that will be activated when the Escape key is pressed.
Definition: KoDialog.cpp:285
QObject::deleteLater
void deleteLater()
KoDialog::Details
Show Details button. (this button will show the detail widget set with setDetailsWidget)
Definition: KoDialog.h:135
QDialog::minimumSizeHint
virtual QSize minimumSizeHint() const
QCloseEvent
QPushButton
QFontMetrics::lineSpacing
int lineSpacing() const
QObject
KoDialog::HIGCompliantCaption
Definition: KoDialog.h:402
QString
QWidget::icon
const QPixmap * icon() const
KoDialog::cancelClicked
void cancelClicked()
The Cancel button was pressed.
QHashIterator::next
Item next()
KoDialog::enableButton
void enableButton(ButtonCode id, bool state)
Enable or disable (gray out) a general action button.
Definition: KoDialog.cpp:577
KoDialog::ButtonCode
ButtonCode
Definition: KoDialog.h:123
QString::isEmpty
bool isEmpty() const
KoDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: KoDialog.cpp:192
KoDialog::enableButtonOk
void enableButtonOk(bool state)
Enable or disable (gray out) the OK button.
Definition: KoDialog.cpp:595
KoDialog::Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition: KoDialog.h:130
KoDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
Definition: KoDialog.cpp:290
KoDialog::defaultClicked
void defaultClicked()
The Default button was pressed.
KoDialog::Reset
Show Reset button.
Definition: KoDialog.h:134
KoDialog::KoDialog
KoDialog(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
Creates a dialog.
Definition: KoDialog.cpp:173
KoDialog::Apply
Show Apply button.
Definition: KoDialog.h:128
KoDialogPrivate::mTopLayout
QBoxLayout * mTopLayout
Definition: KoDialog_p.h:52
QWidget::caption
QString caption() const
KoDialog::noClicked
void noClicked()
The No button was pressed.
QDialog::accept
virtual void accept()
KoDialog::sizeHint
QSize sizeHint() const override
Reimplemented from QDialog.
Definition: KoDialog.cpp:365
KoDialog::applyClicked
void applyClicked()
The Apply button was pressed.
QAbstractButton::animateClick
void animateClick(int msec)
QDialogButtonBox::setOrientation
void setOrientation(Qt::Orientation orientation)
QDialogButtonBox::addButton
void addButton(QAbstractButton *button, ButtonRole role)
KoDialog::~KoDialog
~KoDialog() override
Destroys the dialog.
Definition: KoDialog.cpp:187
QHideEvent
QIcon
KoDialogPrivate
Definition: KoDialog_p.h:23
KoDialog::Help
Show Help button. (this button will run the help set with setHelp)
Definition: KoDialog.h:125
QDialog::done
virtual void done(int r)
KoDialog::isButtonEnabled
bool isButtonEnabled(ButtonCode id) const
Returns whether any button is enabled.
Definition: KoDialog.cpp:585
KoDialog::Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition: KoDialog.h:127
KoDialog::Close
Show Close-button. (this button closes the dialog)
Definition: KoDialog.h:131
QWidget::testAttribute
bool testAttribute(Qt::WidgetAttribute attribute) const
QHashIterator
KoDialog::No
Show No button. (this button closes the dialog and sets the result to KoDialog::No)
Definition: KoDialog.h:132
QLayoutItem
KoDialogPrivate::queuedLayoutUpdate
void queuedLayoutUpdate()
Definition: KoDialog.cpp:44
QWidget::setEnabled
void setEnabled(bool)
KoDialog::makeStandardCaption
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...
Definition: KoDialog.cpp:450
QWidget::show
void show()
QHashIterator::hasNext
bool hasNext() const
KoDialog::yesClicked
void yesClicked()
The Yes button was pressed.
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
QDialog::keyPressEvent
virtual void keyPressEvent(QKeyEvent *e)
KoDialog::spacingHint
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
Definition: KoDialog.cpp:440
KoDialog::closeClicked
void closeClicked()
The Close button was pressed.
QWidget::height
int height() const
QObject::child
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
QWidget::setToolTip
void setToolTip(const QString &)
KoDialogPrivate::helpLinkClicked
void helpLinkClicked()
Definition: KoDialog.cpp:168
KoDialogPrivate::mDefaultButton
KoDialog::ButtonCode mDefaultButton
Definition: KoDialog_p.h:62
QObject::isWidgetType
bool isWidgetType() const
KoDialog::user3Clicked
void user3Clicked()
The User3 button was pressed.
QWhatsThis::enterWhatsThisMode
void enterWhatsThisMode()
QHBoxLayout
KoDialog::showButton
void showButton(ButtonCode id, bool state)
Hide or display a general action button.
Definition: KoDialog.cpp:610
QMetaObject::invokeMethod
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
KoDialog::None
Definition: KoDialog.h:124
KoDialog::closeEvent
void closeEvent(QCloseEvent *e) override
Detects when a dialog is being closed from the window manager controls.
Definition: KoDialog.cpp:927
KoDialog::mainWidget
QWidget * mainWidget()
Definition: KoDialog.cpp:356
KoDialog::setInitialSize
void setInitialSize(const QSize &size)
Convenience method.
Definition: KoDialog.cpp:559
KoDialog::button
QPushButton * button(ButtonCode id) const
Returns the button that corresponds to the id.
Definition: KoDialog.cpp:571
QLayout::setSpacing
void setSpacing(int)
Qt::WindowFlags
typedef WindowFlags
QPushButton::setDefault
void setDefault(bool)
KoDialog::delayedDestruct
void delayedDestruct()
Destruct the dialog delayed.
Definition: KoDialog.cpp:791
KoDialog::groupSpacingHint
static int groupSpacingHint()
Returns the number of pixels that should be used to visually separate groups of related options in a ...
Definition: KoDialog.cpp:445
KoDialog::resizeLayout
static void resizeLayout(QWidget *widget, int margin, int spacing)
Resize every layout manager used in widget and its nested children.
Definition: KoDialog.cpp:503
KoDialog::finished
void finished()
The dialog has finished.
KoDialog::setPlainCaption
virtual void setPlainCaption(const QString &caption)
Make a plain caption without any modifications.
Definition: KoDialog.cpp:496
KoDialog::setButtonFocus
void setButtonFocus(ButtonCode id)
Sets the focus to the button of the passed id.
Definition: KoDialog.cpp:715
KoDialog::hidden
void hidden()
The dialog is about to be hidden.
KoDialog::minimumSizeHint
QSize minimumSizeHint() const override
Reimplemented from QDialog.
Definition: KoDialog.cpp:379
KoDialog::setButtonsOrientation
void setButtonsOrientation(Qt::Orientation orientation)
Sets the orientation of the button box.
Definition: KoDialog.cpp:269
QKeyEvent
QLayout::activate
bool activate()
KoDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: KoDialog.cpp:342
QDialog
QWidget::isHidden
bool isHidden() const
KoDialogPrivate::mMainWidget
QPointer< QWidget > mMainWidget
Definition: KoDialog_p.h:53
KoDialog::hideEvent
void hideEvent(QHideEvent *) override
Emits the hidden signal.
Definition: KoDialog.cpp:918
KoDialog::aboutToShowDetails
void aboutToShowDetails()
The detailsWidget is about to get shown.
KoDialog::buttonToolTip
QString buttonToolTip(ButtonCode id) const
Returns the tooltip of any button.
Definition: KoDialog.cpp:683
QWidget::setFocus
void setFocus()
KoDialog::keyPressEvent
void keyPressEvent(QKeyEvent *) override
Definition: KoDialog.cpp:392
KoDialogPrivate::mButtonOrientation
Qt::Orientation mButtonOrientation
Definition: KoDialog_p.h:61
QWidget::size
QSize size() const
QHashIterator::key
const Key & key() const
QDialogButtonBox
KoDialog::enableButtonCancel
void enableButtonCancel(bool state)
Enable or disable (gray out) the Cancel button.
Definition: KoDialog.cpp:605
KoDialogPrivate::mButtonBox
QDialogButtonBox * mButtonBox
Definition: KoDialog_p.h:65
QAbstractButton::setText
void setText(const QString &text)
QApplication::style
QStyle * style()
KoDialog::setButtonWhatsThis
void setButtonWhatsThis(ButtonCode id, const QString &text)
Sets the "What's this?" text of any button.
Definition: KoDialog.cpp:693
KoDialog::defaultButton
ButtonCode defaultButton() const
Returns the button code of the default button, or NoDefault if there is no default button.
Definition: KoDialog.cpp:328
KoDialogPrivate::mActionSeparator
KSeparator * mActionSeparator
Definition: KoDialog_p.h:55
QObject::children
const QObjectList & children() const
QDialog::sizeHint
virtual QSize sizeHint() const
QDialog::event
virtual bool event(QEvent *e)
KoDialog::buttonWhatsThis
QString buttonWhatsThis(ButtonCode id) const
Returns the "What's this?" text of any button.
Definition: KoDialog.cpp:705
KoDialog::helpClicked
void helpClicked()
The Help button was pressed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 19 2021 23:44:00 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KritaWidgets

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

krita API Reference

Skip menu "krita API Reference"
  • libs
  •   KritaBasicFlakes
  •   brush
  •   KritaUndo2
  •   KritaFlake
  •   image
  •   KritaPlugin
  •   Krita
  •   KritaPigment
  •   KritaResources
  •   KritaStore
  •   ui
  •   KritaWidgets
  •   KritaWidgetUtils
  • plugins
  •   Assitants
  •   Extensions
  •   Filters
  •   Generators
  •   Formats
  •           src
  •   PaintOps
  •     libpaintop

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal