Changeset View
Changeset View
Standalone View
Standalone View
src/kcmultidialog.cpp
Show All 26 Lines | |||||
27 | 27 | | |||
28 | #include "kcmoduleqml_p.h" | 28 | #include "kcmoduleqml_p.h" | ||
29 | #include "kcmoduleproxy.h" | 29 | #include "kcmoduleproxy.h" | ||
30 | 30 | | |||
31 | #include <QApplication> | 31 | #include <QApplication> | ||
32 | #include <QDebug> | 32 | #include <QDebug> | ||
33 | #include <QDesktopServices> | 33 | #include <QDesktopServices> | ||
34 | #include <QDesktopWidget> | 34 | #include <QDesktopWidget> | ||
35 | #include <QLayout> | ||||
35 | #include <QProcess> | 36 | #include <QProcess> | ||
36 | #include <QPushButton> | 37 | #include <QPushButton> | ||
37 | #include <QScrollArea> | 38 | #include <QScrollArea> | ||
38 | #include <QStringList> | 39 | #include <QStringList> | ||
40 | #include <QStyle> | ||||
39 | #include <QUrl> | 41 | #include <QUrl> | ||
40 | 42 | | |||
41 | #include <KAuthAction> | 43 | #include <KAuthAction> | ||
zzag: It looks like includes are sorted. Maybe keep it that way? | |||||
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> | ||
48 | 50 | | |||
49 | bool KCMultiDialogPrivate::resolveChanges(KCModuleProxy *currentProxy) | 51 | bool KCMultiDialogPrivate::resolveChanges(KCModuleProxy *currentProxy) | ||
Show All 28 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 | // TODO KF6 Fix this situation. | ||||
108 | | ||||
109 | if (currentModule->realModule() && currentModule->realModule()->inherits("KCModuleQml")) { | ||||
110 | bool padHackLeft = false; | ||||
111 | bool padHackRight = false; | ||||
112 | if (q->pageWidget()->model()->rowCount() < 2) { | ||||
113 | padHackLeft = true; | ||||
114 | padHackRight = true; | ||||
115 | } else if (qApp->isRightToLeft()) { | ||||
116 | padHackLeft = true; | ||||
117 | } else { | ||||
118 | padHackRight = true; | ||||
97 | } | 119 | } | ||
98 | 120 | | |||
121 | q->layout()->setContentsMargins(padHackLeft ? 0: q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), | ||||
122 | q->style()->pixelMetric(QStyle::PM_LayoutTopMargin), | ||||
123 | padHackRight ? 0 : q->style()->pixelMetric(QStyle::PM_LayoutRightMargin), | ||||
124 | q->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); | ||||
125 | q->pageWidget()->layout()->setSpacing(0); | ||||
126 | q->buttonBox()->setContentsMargins(padHackLeft ? q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) : 0, | ||||
127 | 0, | ||||
128 | padHackRight ? q->style()->pixelMetric(QStyle::PM_LayoutRightMargin) : 0, | ||||
129 | 0); | ||||
130 | } else { | ||||
131 | q->buttonBox()->setContentsMargins(0, 0, 0, 0); | ||||
132 | q->pageWidget()->layout()->setSpacing(q->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing)); | ||||
133 | q->layout()->setContentsMargins( | ||||
134 | q->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), | ||||
135 | q->style()->pixelMetric(QStyle::PM_LayoutTopMargin), | ||||
136 | q->style()->pixelMetric(QStyle::PM_LayoutRightMargin), | ||||
137 | q->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); | ||||
138 | } | ||||
139 | | ||||
140 | q->blockSignals(true); | ||||
141 | q->setCurrentPage(previous); | ||||
142 | | ||||
143 | | ||||
144 | | ||||
99 | if (resolveChanges(previousModule)) { | 145 | if (resolveChanges(previousModule)) { | ||
100 | q->setCurrentPage(current); | 146 | q->setCurrentPage(current); | ||
101 | } | 147 | } | ||
102 | q->blockSignals(false); | 148 | q->blockSignals(false); | ||
103 | 149 | | |||
104 | // We need to get the state of the now active module | 150 | // We need to get the state of the now active module | ||
105 | _k_clientChanged(); | 151 | _k_clientChanged(); | ||
106 | } | 152 | } | ||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 460 | { | |||
421 | KService::Ptr service = KService::serviceByStorageId(complete); | 467 | KService::Ptr service = KService::serviceByStorageId(complete); | ||
422 | 468 | | |||
423 | return addModule(KCModuleInfo(service), nullptr, args); | 469 | return addModule(KCModuleInfo(service), nullptr, args); | ||
424 | } | 470 | } | ||
425 | 471 | | |||
426 | KPageWidgetItem *KCMultiDialog::addModule(const KCModuleInfo &moduleInfo, | 472 | KPageWidgetItem *KCMultiDialog::addModule(const KCModuleInfo &moduleInfo, | ||
427 | KPageWidgetItem *parentItem, const QStringList &args) | 473 | KPageWidgetItem *parentItem, const QStringList &args) | ||
428 | { | 474 | { | ||
475 | Q_D(KCMultiDialog); | ||||
429 | if (!moduleInfo.service()) { | 476 | if (!moduleInfo.service()) { | ||
430 | return nullptr; | 477 | return nullptr; | ||
431 | } | 478 | } | ||
432 | 479 | | |||
433 | //KAuthorized::authorizeControlModule( moduleInfo.service()->menuId() ) is | 480 | //KAuthorized::authorizeControlModule( moduleInfo.service()->menuId() ) is | ||
434 | //checked in noDisplay already | 481 | //checked in noDisplay already | ||
435 | if (moduleInfo.service()->noDisplay()) { | 482 | if (moduleInfo.service()->noDisplay()) { | ||
436 | return nullptr; | 483 | return nullptr; | ||
437 | } | 484 | } | ||
438 | 485 | | |||
439 | // Create the scroller | 486 | // Create the scroller | ||
440 | auto *moduleScroll = new UnboundScrollArea(this); | 487 | auto *moduleScroll = new UnboundScrollArea(this); | ||
441 | // Prepare the scroll area | 488 | // Prepare the scroll area | ||
442 | moduleScroll->setWidgetResizable(true); | 489 | moduleScroll->setWidgetResizable(true); | ||
443 | moduleScroll->setFrameStyle(QFrame::NoFrame); | 490 | moduleScroll->setFrameStyle(QFrame::NoFrame); | ||
444 | moduleScroll->viewport()->setAutoFillBackground(false); | 491 | moduleScroll->viewport()->setAutoFillBackground(false); | ||
445 | 492 | | |||
446 | KCModuleProxy *kcm = new KCModuleProxy(moduleInfo, moduleScroll, args); | 493 | KCModuleProxy *kcm = new KCModuleProxy(moduleInfo, moduleScroll, args); | ||
447 | moduleScroll->setWidget(kcm); | 494 | moduleScroll->setWidget(kcm); | ||
448 | 495 | | |||
449 | // qDebug() << moduleInfo.moduleName(); | 496 | // qDebug() << moduleInfo.moduleName(); | ||
450 | KPageWidgetItem *item = new KPageWidgetItem(moduleScroll, moduleInfo.moduleName()); | 497 | KPageWidgetItem *item = new KPageWidgetItem(moduleScroll, moduleInfo.moduleName()); | ||
451 | 498 | | |||
499 | KCMultiDialogPrivate::CreatedModule cm; | ||||
500 | cm.kcm = kcm; | ||||
501 | cm.item = item; | ||||
502 | cm.componentNames = moduleInfo.service()->property(QStringLiteral("X-KDE-ParentComponents")).toStringList(); | ||||
503 | d->modules.append(cm); | ||||
504 | | ||||
452 | if (qobject_cast<KCModuleQml *>(kcm->realModule())) { | 505 | if (qobject_cast<KCModuleQml *>(kcm->realModule())) { | ||
453 | item->setHeaderVisible(false); | 506 | item->setHeaderVisible(false); | ||
454 | } | 507 | } | ||
455 | 508 | | |||
456 | if (kcm->realModule() && kcm->realModule()->useRootOnlyMessage()) { | 509 | if (kcm->realModule() && kcm->realModule()->useRootOnlyMessage()) { | ||
457 | item->setHeader(QStringLiteral("<b>") + | 510 | item->setHeader(QStringLiteral("<b>") + | ||
458 | moduleInfo.comment() + | 511 | moduleInfo.comment() + | ||
459 | QStringLiteral("</b><br><i>") + | 512 | QStringLiteral("</b><br><i>") + | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 559 | if (row == siblingCount) { | |||
508 | // qDebug() << "adding KCM " << item->name() << " at the top level"; | 561 | // qDebug() << "adding KCM " << item->name() << " at the top level"; | ||
509 | addPage(item); | 562 | addPage(item); | ||
510 | } | 563 | } | ||
511 | } | 564 | } | ||
512 | 565 | | |||
513 | connect(kcm, SIGNAL(changed(bool)), this, SLOT(_k_clientChanged())); | 566 | connect(kcm, SIGNAL(changed(bool)), this, SLOT(_k_clientChanged())); | ||
514 | connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), this, SLOT(_k_updateHeader(bool,QString))); | 567 | connect(kcm->realModule(), SIGNAL(rootOnlyMessageChanged(bool,QString)), this, SLOT(_k_updateHeader(bool,QString))); | ||
515 | 568 | | |||
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) { | 569 | if (d->modules.count() == 1 || updateCurrentPage) { | ||
524 | setCurrentPage(item); | 570 | setCurrentPage(item); | ||
525 | d->_k_clientChanged(); | 571 | d->_k_clientChanged(); | ||
526 | } | 572 | } | ||
527 | return item; | 573 | return item; | ||
528 | } | 574 | } | ||
529 | 575 | | |||
530 | void KCMultiDialog::clear() | 576 | void KCMultiDialog::clear() | ||
Show All 15 Lines |
It looks like includes are sorted. Maybe keep it that way?