Changeset View
Changeset View
Standalone View
Standalone View
sidebar/SidebarMode.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <KPackage/PackageLoader> | 42 | #include <KPackage/PackageLoader> | ||
43 | #include <KDeclarative/KDeclarative> | 43 | #include <KDeclarative/KDeclarative> | ||
44 | #include <QStandardItemModel> | 44 | #include <QStandardItemModel> | ||
45 | #include <QQuickWidget> | 45 | #include <QQuickWidget> | ||
46 | #include <QQmlEngine> | 46 | #include <QQmlEngine> | ||
47 | #include <QQmlContext> | 47 | #include <QQmlContext> | ||
48 | #include <QGraphicsOpacityEffect> | 48 | #include <QGraphicsOpacityEffect> | ||
49 | #include <QLabel> | 49 | #include <QLabel> | ||
50 | #include <QMenu> | ||||
50 | #include <QDebug> | 51 | #include <QDebug> | ||
51 | 52 | | |||
52 | #include <KActivities/Stats/ResultModel> | 53 | #include <KActivities/Stats/ResultModel> | ||
53 | #include <KActivities/Stats/ResultSet> | 54 | #include <KActivities/Stats/ResultSet> | ||
54 | #include <KActivities/Stats/Terms> | 55 | #include <KActivities/Stats/Terms> | ||
55 | 56 | | |||
56 | namespace KAStats = KActivities::Stats; | 57 | namespace KAStats = KActivities::Stats; | ||
57 | 58 | | |||
▲ Show 20 Lines • Show All 186 Lines • ▼ Show 20 Line(s) | 222 | public: | |||
244 | MenuProxyModel * categorizedModel = nullptr; | 245 | MenuProxyModel * categorizedModel = nullptr; | ||
245 | MenuProxyModel * searchModel = nullptr; | 246 | MenuProxyModel * searchModel = nullptr; | ||
246 | KAboutData * aboutIcon = nullptr; | 247 | KAboutData * aboutIcon = nullptr; | ||
247 | ModuleView * moduleView = nullptr; | 248 | ModuleView * moduleView = nullptr; | ||
248 | KActionCollection *collection = nullptr; | 249 | KActionCollection *collection = nullptr; | ||
249 | QPersistentModelIndex activeCategoryIndex; | 250 | QPersistentModelIndex activeCategoryIndex; | ||
250 | int activeCategory; | 251 | int activeCategory; | ||
251 | int activeSubCategory; | 252 | int activeSubCategory; | ||
253 | bool m_actionMenuVisible = false; | ||||
252 | }; | 254 | }; | ||
253 | 255 | | |||
254 | SidebarMode::SidebarMode( QObject *parent, const QVariantList& ) | 256 | SidebarMode::SidebarMode( QObject *parent, const QVariantList& ) | ||
255 | : BaseMode( parent ) | 257 | : BaseMode( parent ) | ||
256 | , d( new Private() ) | 258 | , d( new Private() ) | ||
257 | { | 259 | { | ||
258 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | 260 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | ||
259 | d->aboutIcon = new KAboutData( QStringLiteral("SidebarView"), i18n( "Sidebar View" ), | 261 | d->aboutIcon = new KAboutData( QStringLiteral("SidebarView"), i18n( "Sidebar View" ), | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | |||||
391 | 393 | | |||
392 | void SidebarMode::loadMostUsed(int index) | 394 | void SidebarMode::loadMostUsed(int index) | ||
393 | { | 395 | { | ||
394 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | 396 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | ||
395 | d->moduleView->closeModules(); | 397 | d->moduleView->closeModules(); | ||
396 | d->moduleView->loadModule( idx ); | 398 | d->moduleView->loadModule( idx ); | ||
397 | } | 399 | } | ||
398 | 400 | | |||
401 | void SidebarMode::showActionMenu(const QPoint &position) | ||||
402 | { | ||||
403 | QMenu *menu = new QMenu(); | ||||
broulik: This leaks.
`menu->setAttribute(Qt::WA_DeleteOnClose);` | |||||
404 | connect(menu, &QMenu::aboutToHide, this, [this] () { setActionMenuVisible(false); } ); | ||||
broulik: `const` | |||||
405 | menu->setAttribute(Qt::WA_DeleteOnClose); | ||||
I think it's better to iterate the list of actions and then get them from the collection. This way the order is also preserved correctly: for (const QString &actionName : actionList) { menu->addAction(d->collection->action(actionName); } broulik: I think it's better to iterate the list of actions and then get them from the collection. This… | |||||
406 | | ||||
407 | const QStringList actionList { QStringLiteral("configure"), QStringLiteral("help_contents"), QStringLiteral("help_about_app"), QStringLiteral("help_about_kde") }; | ||||
408 | for (const QString &actionName : actionList) { | ||||
409 | menu->addAction(d->collection->action(actionName)); | ||||
410 | } | ||||
411 | | ||||
Don't exec() in conjunction with QML, this is just asking for trouble. Use popup() instead broulik: Don't `exec()` in conjunction with QML, this is just asking for trouble. Use `popup()` instead | |||||
412 | menu->popup(position); | ||||
413 | setActionMenuVisible(true); | ||||
414 | } | ||||
415 | | ||||
399 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | 416 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | ||
400 | { | 417 | { | ||
401 | d->moduleView->closeModules(); | 418 | d->moduleView->closeModules(); | ||
402 | 419 | | |||
403 | const int subRows = d->searchModel->rowCount(activeModule); | 420 | const int subRows = d->searchModel->rowCount(activeModule); | ||
404 | if ( subRows < 2) { | 421 | if ( subRows < 2) { | ||
405 | d->moduleView->loadModule( activeModule ); | 422 | d->moduleView->loadModule( activeModule ); | ||
406 | } else { | 423 | } else { | ||
Show All 30 Lines | 442 | { | |||
437 | d->activeCategory = newCategoryRow; | 454 | d->activeCategory = newCategoryRow; | ||
438 | 455 | | |||
439 | changeModule(idx); | 456 | changeModule(idx); | ||
440 | d->activeSubCategory = 0; | 457 | d->activeSubCategory = 0; | ||
441 | emit activeCategoryChanged(); | 458 | emit activeCategoryChanged(); | ||
442 | emit activeSubCategoryChanged(); | 459 | emit activeSubCategoryChanged(); | ||
443 | } | 460 | } | ||
444 | 461 | | |||
445 | int SidebarMode::activeSubCategory() const | | |||
446 | { | | |||
447 | return d->activeSubCategory; | | |||
448 | } | | |||
449 | | ||||
450 | void SidebarMode::setActiveSubCategory(int cat) | 462 | void SidebarMode::setActiveSubCategory(int cat) | ||
451 | { | 463 | { | ||
452 | if (d->activeSubCategory == cat) { | 464 | if (d->activeSubCategory == cat) { | ||
453 | return; | 465 | return; | ||
454 | } | 466 | } | ||
455 | 467 | | |||
456 | if( !d->moduleView->resolveChanges() ) { | 468 | if( !d->moduleView->resolveChanges() ) { | ||
457 | return; | 469 | return; | ||
458 | } | 470 | } | ||
459 | 471 | | |||
460 | d->activeSubCategory = cat; | 472 | d->activeSubCategory = cat; | ||
461 | d->moduleView->closeModules(); | 473 | d->moduleView->closeModules(); | ||
462 | d->moduleView->loadModule( d->subCategoryModel->index(cat, 0) ); | 474 | d->moduleView->loadModule( d->subCategoryModel->index(cat, 0) ); | ||
463 | emit activeSubCategoryChanged(); | 475 | emit activeSubCategoryChanged(); | ||
464 | } | 476 | } | ||
465 | 477 | | |||
466 | int SidebarMode::width() const | 478 | int SidebarMode::width() const | ||
467 | { | 479 | { | ||
468 | return d->mainWidget->width(); | 480 | return d->mainWidget->width(); | ||
469 | } | 481 | } | ||
470 | 482 | | |||
483 | bool SidebarMode::actionMenuVisible() const | ||||
484 | { | ||||
485 | return d->m_actionMenuVisible; | ||||
486 | } | ||||
487 | | ||||
488 | void SidebarMode::setActionMenuVisible(const bool &actionMenuVisible) | ||||
489 | { | ||||
490 | if (d->m_actionMenuVisible == actionMenuVisible) { | ||||
491 | return; | ||||
492 | } | ||||
493 | | ||||
494 | d->m_actionMenuVisible = actionMenuVisible; | ||||
495 | emit actionMenuVisibleChanged(); | ||||
496 | } | ||||
497 | | ||||
498 | int SidebarMode::activeSubCategory() const | ||||
499 | { | ||||
500 | return d->activeSubCategory; | ||||
501 | } | ||||
502 | | ||||
471 | void SidebarMode::initWidget() | 503 | void SidebarMode::initWidget() | ||
472 | { | 504 | { | ||
473 | // Create the widgets | 505 | // Create the widgets | ||
474 | 506 | | |||
475 | if (!KMainWindow::memberList().isEmpty()) { | 507 | if (!KMainWindow::memberList().isEmpty()) { | ||
476 | KXmlGuiWindow *mainWindow = qobject_cast<KXmlGuiWindow *>(KMainWindow::memberList().first()); | 508 | KXmlGuiWindow *mainWindow = qobject_cast<KXmlGuiWindow *>(KMainWindow::memberList().first()); | ||
477 | if (mainWindow) { | 509 | if (mainWindow) { | ||
478 | d->collection = mainWindow->actionCollection(); | 510 | d->collection = mainWindow->actionCollection(); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 592 | if (qqw && qqw->rootObject()) { | |||
565 | } | 597 | } | ||
566 | } | 598 | } | ||
567 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | 599 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | ||
568 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | 600 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | ||
569 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | 601 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | ||
570 | emit widthChanged(); | 602 | emit widthChanged(); | ||
571 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | 603 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | ||
572 | emit changeToolBarItems(BaseMode::NoItems); | 604 | emit changeToolBarItems(BaseMode::NoItems); | ||
573 | } | 605 | } | ||
Not a huge fan of this. broulik: Not a huge fan of this.
Can this be done in qqc2-desktop-style to be generic and fix every… | |||||
Not really, seems like the KQuickStyleItem only has access to the QML window of the menu control and also can't detect events on the rest of the QWidget window :( GB_2: Not really, seems like the KQuickStyleItem only has access to the QML window of the menu… | |||||
574 | return BaseMode::eventFilter(watched, event); | 606 | return BaseMode::eventFilter(watched, event); | ||
575 | } | 607 | } | ||
576 | 608 | | |||
577 | void SidebarMode::giveFocus() | 609 | void SidebarMode::giveFocus() | ||
578 | { | 610 | { | ||
579 | d->quickWidget->setFocus(); | 611 | d->quickWidget->setFocus(); | ||
580 | } | 612 | } | ||
581 | 613 | | |||
582 | #include "SidebarMode.moc" | 614 | #include "SidebarMode.moc" |
This leaks.
menu->setAttribute(Qt::WA_DeleteOnClose);