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