Changeset View
Changeset View
Standalone View
Standalone View
src/kcmultidialog.cpp
Show All 31 Lines | |||||
32 | #include <QDebug> | 32 | #include <QDebug> | ||
33 | #include <QDesktopServices> | 33 | #include <QDesktopServices> | ||
34 | #include <QDesktopWidget> | 34 | #include <QDesktopWidget> | ||
35 | #include <QProcess> | 35 | #include <QProcess> | ||
36 | #include <QPushButton> | 36 | #include <QPushButton> | ||
37 | #include <QScrollArea> | 37 | #include <QScrollArea> | ||
38 | #include <QStringList> | 38 | #include <QStringList> | ||
39 | #include <QUrl> | 39 | #include <QUrl> | ||
40 | #include <QLayout> | ||||
41 | #include <QStyle> | ||||
zzag: It looks like includes are sorted. Maybe keep it that way? | |||||
40 | 42 | | |||
41 | #include <KAuthAction> | 43 | #include <KAuthAction> | ||
42 | #include <KAuthObjectDecorator> | 44 | #include <KAuthObjectDecorator> | ||
43 | #include <KGuiItem> | 45 | #include <KGuiItem> | ||
44 | #include <KIconLoader> | 46 | #include <KIconLoader> | ||
45 | #include <KLocalizedString> | 47 | #include <KLocalizedString> | ||
46 | #include <KMessageBox> | 48 | #include <KMessageBox> | ||
47 | #include <KPageWidgetModel> | 49 | #include <KPageWidgetModel> | ||
Show All 30 Lines | 79 | default: | |||
78 | Q_ASSERT(false); | 80 | Q_ASSERT(false); | ||
79 | return false; | 81 | return false; | ||
80 | } | 82 | } | ||
81 | } | 83 | } | ||
82 | 84 | | |||
83 | void KCMultiDialogPrivate::_k_slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *previous) | 85 | void KCMultiDialogPrivate::_k_slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *previous) | ||
84 | { | 86 | { | ||
85 | Q_Q(KCMultiDialog); | 87 | Q_Q(KCMultiDialog); | ||
86 | // qDebug(); | | |||
87 | 88 | | |||
88 | q->blockSignals(true); | | |||
89 | q->setCurrentPage(previous); | | |||
90 | 89 | | |||
90 | KCModuleProxy *currentModule = nullptr; | ||||
91 | KCModuleProxy *previousModule = nullptr; | 91 | KCModuleProxy *previousModule = nullptr; | ||
92 | for (int i = 0; i < modules.count(); ++i) { | 92 | for (int i = 0; i < modules.count(); ++i) { | ||
93 | if (modules[ i ].item == previous) { | 93 | if (modules[i].item == previous) { | ||
94 | previousModule = modules[ i ].kcm; | 94 | previousModule = modules[i].kcm; | ||
95 | break; | | |||
96 | } | 95 | } | ||
96 | if (modules[i].item == current) { | ||||
97 | currentModule = modules[i].kcm; | ||||
98 | } | ||||
99 | } | ||||
100 | Q_ASSERT(currentModule); | ||||
101 | | ||||
102 | // For some reason the KCModuleQml modules handle their own margin internally | ||||
103 | // to match that we need to adjust the spacing of our page widget | ||||
104 | // by removing the spacing between the left pane and the edge, and the layout on the right | ||||
105 | // when we reduce the layout on the right we need to pad the buttons back to match | ||||
106 | | ||||
107 | bool reverse = qApp->isRightToLeft(); | ||||
108 | | ||||
109 | if (currentModule->realModule() && currentModule->realModule()->inherits("KCModuleQml")) { | ||||
110 | q->layout()->setContentsMargins(reverse ? 0 : q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), | ||||
111 | q->style()->pixelMetric(QStyle::PM_LayoutTopMargin), | ||||
112 | reverse ? q->style()->pixelMetric(QStyle::PM_LayoutRightMargin) : 0, | ||||
113 | q->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); | ||||
114 | q->pageWidget()->layout()->setSpacing(0); | ||||
115 | q->buttonBox()->setContentsMargins(reverse ? q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) : 0, | ||||
116 | 0, | ||||
117 | reverse ? 0 : q->style()->pixelMetric(QStyle::PM_LayoutRightMargin), | ||||
118 | 0); | ||||
119 | } else { | ||||
120 | q->buttonBox()->setContentsMargins(0, 0, 0, 0); | ||||
121 | q->pageWidget()->layout()->setSpacing(q->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing)); | ||||
122 | q->layout()->setContentsMargins( | ||||
123 | q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), | ||||
124 | q->style()->pixelMetric(QStyle::PM_LayoutTopMargin), | ||||
125 | q->style()->pixelMetric(QStyle::PM_LayoutRightMargin), | ||||
126 | q->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); | ||||
97 | } | 127 | } | ||
98 | 128 | | |||
129 | q->blockSignals(true); | ||||
130 | q->setCurrentPage(previous); | ||||
131 | | ||||
132 | | ||||
133 | | ||||
99 | if (resolveChanges(previousModule)) { | 134 | if (resolveChanges(previousModule)) { | ||
100 | q->setCurrentPage(current); | 135 | q->setCurrentPage(current); | ||
101 | } | 136 | } | ||
102 | q->blockSignals(false); | 137 | q->blockSignals(false); | ||
103 | 138 | | |||
104 | // We need to get the state of the now active module | 139 | // We need to get the state of the now active module | ||
105 | _k_clientChanged(); | 140 | _k_clientChanged(); | ||
106 | } | 141 | } | ||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 449 | { | |||
421 | KService::Ptr service = KService::serviceByStorageId(complete); | 456 | KService::Ptr service = KService::serviceByStorageId(complete); | ||
422 | 457 | | |||
423 | return addModule(KCModuleInfo(service), nullptr, args); | 458 | return addModule(KCModuleInfo(service), nullptr, args); | ||
424 | } | 459 | } | ||
425 | 460 | | |||
426 | KPageWidgetItem *KCMultiDialog::addModule(const KCModuleInfo &moduleInfo, | 461 | KPageWidgetItem *KCMultiDialog::addModule(const KCModuleInfo &moduleInfo, | ||
427 | KPageWidgetItem *parentItem, const QStringList &args) | 462 | KPageWidgetItem *parentItem, const QStringList &args) | ||
428 | { | 463 | { | ||
464 | Q_D(KCMultiDialog); | ||||
429 | if (!moduleInfo.service()) { | 465 | if (!moduleInfo.service()) { | ||
430 | return nullptr; | 466 | return nullptr; | ||
431 | } | 467 | } | ||
432 | 468 | | |||
433 | //KAuthorized::authorizeControlModule( moduleInfo.service()->menuId() ) is | 469 | //KAuthorized::authorizeControlModule( moduleInfo.service()->menuId() ) is | ||
434 | //checked in noDisplay already | 470 | //checked in noDisplay already | ||
435 | if (moduleInfo.service()->noDisplay()) { | 471 | if (moduleInfo.service()->noDisplay()) { | ||
436 | return nullptr; | 472 | return nullptr; | ||
437 | } | 473 | } | ||
438 | 474 | | |||
439 | // Create the scroller | 475 | // Create the scroller | ||
440 | auto *moduleScroll = new UnboundScrollArea(this); | 476 | auto *moduleScroll = new UnboundScrollArea(this); | ||
441 | // Prepare the scroll area | 477 | // Prepare the scroll area | ||
442 | moduleScroll->setWidgetResizable(true); | 478 | moduleScroll->setWidgetResizable(true); | ||
443 | moduleScroll->setFrameStyle(QFrame::NoFrame); | 479 | moduleScroll->setFrameStyle(QFrame::NoFrame); | ||
444 | moduleScroll->viewport()->setAutoFillBackground(false); | 480 | moduleScroll->viewport()->setAutoFillBackground(false); | ||
445 | 481 | | |||
446 | KCModuleProxy *kcm = new KCModuleProxy(moduleInfo, moduleScroll, args); | 482 | KCModuleProxy *kcm = new KCModuleProxy(moduleInfo, moduleScroll, args); | ||
447 | moduleScroll->setWidget(kcm); | 483 | moduleScroll->setWidget(kcm); | ||
448 | 484 | | |||
449 | // qDebug() << moduleInfo.moduleName(); | 485 | // qDebug() << moduleInfo.moduleName(); | ||
450 | KPageWidgetItem *item = new KPageWidgetItem(moduleScroll, moduleInfo.moduleName()); | 486 | KPageWidgetItem *item = new KPageWidgetItem(moduleScroll, moduleInfo.moduleName()); | ||
451 | 487 | | |||
488 | KCMultiDialogPrivate::CreatedModule cm; | ||||
489 | cm.kcm = kcm; | ||||
490 | cm.item = item; | ||||
491 | cm.componentNames = moduleInfo.service()->property(QStringLiteral("X-KDE-ParentComponents")).toStringList(); | ||||
492 | d->modules.append(cm); | ||||
493 | | ||||
452 | if (qobject_cast<KCModuleQml *>(kcm->realModule())) { | 494 | if (qobject_cast<KCModuleQml *>(kcm->realModule())) { | ||
453 | item->setHeaderVisible(false); | 495 | item->setHeaderVisible(false); | ||
454 | } | 496 | } | ||
455 | 497 | | |||
456 | if (kcm->realModule() && kcm->realModule()->useRootOnlyMessage()) { | 498 | if (kcm->realModule() && kcm->realModule()->useRootOnlyMessage()) { | ||
457 | item->setHeader(QStringLiteral("<b>") + | 499 | item->setHeader(QStringLiteral("<b>") + | ||
458 | moduleInfo.comment() + | 500 | moduleInfo.comment() + | ||
459 | QStringLiteral("</b><br><i>") + | 501 | QStringLiteral("</b><br><i>") + | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 548 | if (row == siblingCount) { | |||
508 | // qDebug() << "adding KCM " << item->name() << " at the top level"; | 550 | // qDebug() << "adding KCM " << item->name() << " at the top level"; | ||
509 | addPage(item); | 551 | addPage(item); | ||
510 | } | 552 | } | ||
511 | } | 553 | } | ||
512 | 554 | | |||
513 | connect(kcm, SIGNAL(changed(bool)), this, SLOT(_k_clientChanged())); | 555 | connect(kcm, SIGNAL(changed(bool)), this, SLOT(_k_clientChanged())); | ||
514 | connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), this, SLOT(_k_updateHeader(bool,QString))); | 556 | connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), this, SLOT(_k_updateHeader(bool,QString))); | ||
515 | 557 | | |||
516 | Q_D(KCMultiDialog); | | |||
517 | KCMultiDialogPrivate::CreatedModule cm; | | |||
518 | cm.kcm = kcm; | | |||
519 | cm.item = item; | | |||
520 | cm.componentNames = moduleInfo.service()->property(QStringLiteral("X-KDE-ParentComponents")).toStringList(); | | |||
521 | d->modules.append(cm); | | |||
522 | | ||||
523 | if (d->modules.count() == 1 || updateCurrentPage) { | 558 | if (d->modules.count() == 1 || updateCurrentPage) { | ||
524 | setCurrentPage(item); | 559 | setCurrentPage(item); | ||
525 | d->_k_clientChanged(); | 560 | d->_k_clientChanged(); | ||
526 | } | 561 | } | ||
527 | return item; | 562 | return item; | ||
528 | } | 563 | } | ||
529 | 564 | | |||
530 | void KCMultiDialog::clear() | 565 | void KCMultiDialog::clear() | ||
Show All 15 Lines |
It looks like includes are sorted. Maybe keep it that way?