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 333 Lines • ▼ Show 20 Line(s) | |||||
391 | 392 | | |||
392 | void SidebarMode::loadMostUsed(int index) | 393 | void SidebarMode::loadMostUsed(int index) | ||
393 | { | 394 | { | ||
394 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | 395 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | ||
395 | d->moduleView->closeModules(); | 396 | d->moduleView->closeModules(); | ||
396 | d->moduleView->loadModule( idx ); | 397 | d->moduleView->loadModule( idx ); | ||
397 | } | 398 | } | ||
398 | 399 | | |||
400 | void SidebarMode::showActionMenu(const QPoint &position) | ||||
401 | { | ||||
402 | QMenu *menu = new QMenu(); | ||||
broulik: This leaks.
`menu->setAttribute(Qt::WA_DeleteOnClose);` | |||||
403 | connect(menu, &QMenu::aboutToHide, this, [this] () { setActionMenuVisible(false); } ); | ||||
broulik: `const` | |||||
404 | 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… | |||||
405 | | ||||
406 | const QStringList actionList { QStringLiteral("configure"), QStringLiteral("help_contents"), QStringLiteral("help_about_app"), QStringLiteral("help_about_kde") }; | ||||
407 | for (const QString &actionName : actionList) { | ||||
408 | menu->addAction(d->collection->action(actionName)); | ||||
409 | } | ||||
410 | | ||||
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 | |||||
411 | menu->popup(position); | ||||
412 | setActionMenuVisible(true); | ||||
413 | } | ||||
414 | | ||||
399 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | 415 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | ||
400 | { | 416 | { | ||
401 | d->moduleView->closeModules(); | 417 | d->moduleView->closeModules(); | ||
402 | 418 | | |||
403 | const int subRows = d->searchModel->rowCount(activeModule); | 419 | const int subRows = d->searchModel->rowCount(activeModule); | ||
404 | if ( subRows < 2) { | 420 | if ( subRows < 2) { | ||
405 | d->moduleView->loadModule( activeModule ); | 421 | d->moduleView->loadModule( activeModule ); | ||
406 | } else { | 422 | } else { | ||
Show All 30 Lines | 441 | { | |||
437 | d->activeCategory = newCategoryRow; | 453 | d->activeCategory = newCategoryRow; | ||
438 | 454 | | |||
439 | changeModule(idx); | 455 | changeModule(idx); | ||
440 | d->activeSubCategory = 0; | 456 | d->activeSubCategory = 0; | ||
441 | emit activeCategoryChanged(); | 457 | emit activeCategoryChanged(); | ||
442 | emit activeSubCategoryChanged(); | 458 | emit activeSubCategoryChanged(); | ||
443 | } | 459 | } | ||
444 | 460 | | |||
445 | int SidebarMode::activeSubCategory() const | | |||
446 | { | | |||
447 | return d->activeSubCategory; | | |||
448 | } | | |||
449 | | ||||
450 | void SidebarMode::setActiveSubCategory(int cat) | 461 | void SidebarMode::setActiveSubCategory(int cat) | ||
451 | { | 462 | { | ||
452 | if (d->activeSubCategory == cat) { | 463 | if (d->activeSubCategory == cat) { | ||
453 | return; | 464 | return; | ||
454 | } | 465 | } | ||
455 | 466 | | |||
456 | if( !d->moduleView->resolveChanges() ) { | 467 | if( !d->moduleView->resolveChanges() ) { | ||
457 | return; | 468 | return; | ||
458 | } | 469 | } | ||
459 | 470 | | |||
460 | d->activeSubCategory = cat; | 471 | d->activeSubCategory = cat; | ||
461 | d->moduleView->closeModules(); | 472 | d->moduleView->closeModules(); | ||
462 | d->moduleView->loadModule( d->subCategoryModel->index(cat, 0) ); | 473 | d->moduleView->loadModule( d->subCategoryModel->index(cat, 0) ); | ||
463 | emit activeSubCategoryChanged(); | 474 | emit activeSubCategoryChanged(); | ||
464 | } | 475 | } | ||
465 | 476 | | |||
466 | int SidebarMode::width() const | 477 | int SidebarMode::width() const | ||
467 | { | 478 | { | ||
468 | return d->mainWidget->width(); | 479 | return d->mainWidget->width(); | ||
469 | } | 480 | } | ||
470 | 481 | | |||
482 | bool SidebarMode::actionMenuVisible() const | ||||
483 | { | ||||
484 | return m_actionMenuVisible; | ||||
485 | } | ||||
486 | | ||||
487 | void SidebarMode::setActionMenuVisible(const bool &actionMenuVisible) | ||||
488 | { | ||||
489 | if (m_actionMenuVisible == actionMenuVisible) { | ||||
490 | return; | ||||
491 | } | ||||
492 | | ||||
493 | m_actionMenuVisible = actionMenuVisible; | ||||
494 | emit actionMenuVisibleChanged(); | ||||
495 | } | ||||
496 | | ||||
497 | int SidebarMode::activeSubCategory() const | ||||
498 | { | ||||
499 | return d->activeSubCategory; | ||||
500 | } | ||||
501 | | ||||
471 | void SidebarMode::initWidget() | 502 | void SidebarMode::initWidget() | ||
472 | { | 503 | { | ||
473 | // Create the widgets | 504 | // Create the widgets | ||
474 | 505 | | |||
475 | if (!KMainWindow::memberList().isEmpty()) { | 506 | if (!KMainWindow::memberList().isEmpty()) { | ||
476 | KXmlGuiWindow *mainWindow = qobject_cast<KXmlGuiWindow *>(KMainWindow::memberList().first()); | 507 | KXmlGuiWindow *mainWindow = qobject_cast<KXmlGuiWindow *>(KMainWindow::memberList().first()); | ||
477 | if (mainWindow) { | 508 | if (mainWindow) { | ||
478 | d->collection = mainWindow->actionCollection(); | 509 | d->collection = mainWindow->actionCollection(); | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 591 | if (qqw && qqw->rootObject()) { | |||
565 | } | 596 | } | ||
566 | } | 597 | } | ||
567 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | 598 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | ||
568 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | 599 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | ||
569 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | 600 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | ||
570 | emit widthChanged(); | 601 | emit widthChanged(); | ||
571 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | 602 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | ||
572 | emit changeToolBarItems(BaseMode::NoItems); | 603 | emit changeToolBarItems(BaseMode::NoItems); | ||
573 | } | 604 | } | ||
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); | 605 | return BaseMode::eventFilter(watched, event); | ||
575 | } | 606 | } | ||
576 | 607 | | |||
577 | void SidebarMode::giveFocus() | 608 | void SidebarMode::giveFocus() | ||
578 | { | 609 | { | ||
579 | d->quickWidget->setFocus(); | 610 | d->quickWidget->setFocus(); | ||
580 | } | 611 | } | ||
581 | 612 | | |||
582 | #include "SidebarMode.moc" | 613 | #include "SidebarMode.moc" |
This leaks.
menu->setAttribute(Qt::WA_DeleteOnClose);