Changeset View
Changeset View
Standalone View
Standalone View
sidebar/SidebarMode.cpp
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Line(s) | 221 | public: | |||
---|---|---|---|---|---|
251 | int activeSubCategory; | 251 | int activeSubCategory; | ||
252 | }; | 252 | }; | ||
253 | 253 | | |||
254 | SidebarMode::SidebarMode( QObject *parent, const QVariantList& ) | 254 | SidebarMode::SidebarMode( QObject *parent, const QVariantList& ) | ||
255 | : BaseMode( parent ) | 255 | : BaseMode( parent ) | ||
256 | , d( new Private() ) | 256 | , d( new Private() ) | ||
257 | { | 257 | { | ||
258 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | 258 | qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); | ||
259 | qApp->installEventFilter(this); | ||||
259 | d->aboutIcon = new KAboutData( QStringLiteral("SidebarView"), i18n( "Sidebar View" ), | 260 | d->aboutIcon = new KAboutData( QStringLiteral("SidebarView"), i18n( "Sidebar View" ), | ||
260 | QStringLiteral("1.0"), i18n( "Provides a categorized sidebar for control modules." ), | 261 | QStringLiteral("1.0"), i18n( "Provides a categorized sidebar for control modules." ), | ||
261 | KAboutLicense::GPL, i18n( "(c) 2017, Marco Martin" ) ); | 262 | KAboutLicense::GPL, i18n( "(c) 2017, Marco Martin" ) ); | ||
262 | d->aboutIcon->addAuthor( i18n( "Marco Martin" ), i18n( "Author" ), QStringLiteral("mart@kde.org") ); | 263 | d->aboutIcon->addAuthor( i18n( "Marco Martin" ), i18n( "Author" ), QStringLiteral("mart@kde.org") ); | ||
263 | d->aboutIcon->addAuthor( i18n( "Ben Cooksley" ), i18n( "Author" ), QStringLiteral("bcooksley@kde.org") ); | 264 | d->aboutIcon->addAuthor( i18n( "Ben Cooksley" ), i18n( "Author" ), QStringLiteral("bcooksley@kde.org") ); | ||
264 | d->aboutIcon->addAuthor( i18n( "Mathias Soeken" ), i18n( "Developer" ), QStringLiteral("msoeken@informatik.uni-bremen.de") ); | 265 | d->aboutIcon->addAuthor( i18n( "Mathias Soeken" ), i18n( "Developer" ), QStringLiteral("msoeken@informatik.uni-bremen.de") ); | ||
265 | 266 | | |||
266 | qmlRegisterType<QAction>(); | 267 | qmlRegisterType<QAction>(); | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 332 | if (d->activeCategoryIndex.isValid() && d->activeCategoryIndex.row() >= 0) { | |||
333 | emit activeCategoryChanged(); | 334 | emit activeCategoryChanged(); | ||
334 | } | 335 | } | ||
335 | }); | 336 | }); | ||
336 | 337 | | |||
337 | d->mostUsedModel = new MostUsedModel( this ); | 338 | d->mostUsedModel = new MostUsedModel( this ); | ||
338 | 339 | | |||
339 | d->subCategoryModel = new SubcategoryModel( d->searchModel, this ); | 340 | d->subCategoryModel = new SubcategoryModel( d->searchModel, this ); | ||
340 | d->mainWidget = new FocusHackWidget(); | 341 | d->mainWidget = new FocusHackWidget(); | ||
341 | d->mainWidget->installEventFilter(this); | | |||
342 | d->mainLayout = new QHBoxLayout(d->mainWidget); | 342 | d->mainLayout = new QHBoxLayout(d->mainWidget); | ||
343 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | 343 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | ||
344 | d->moduleView = new ModuleView( d->mainWidget ); | 344 | d->moduleView = new ModuleView( d->mainWidget ); | ||
345 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | 345 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | ||
346 | d->quickWidget = nullptr; | 346 | d->quickWidget = nullptr; | ||
347 | moduleView()->setFaceType(KPageView::Plain); | 347 | moduleView()->setFaceType(KPageView::Plain); | ||
348 | } | 348 | } | ||
349 | 349 | | |||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
393 | { | 393 | { | ||
394 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | 394 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | ||
395 | d->moduleView->closeModules(); | 395 | d->moduleView->closeModules(); | ||
396 | d->moduleView->loadModule( idx ); | 396 | d->moduleView->loadModule( idx ); | ||
397 | } | 397 | } | ||
398 | 398 | | |||
399 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | 399 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | ||
400 | { | 400 | { | ||
401 | d->moduleView->closeModules(); | 401 | d->moduleView->closeModules(); | ||
broulik: This leaks.
`menu->setAttribute(Qt::WA_DeleteOnClose);` | |||||
402 | 402 | | |||
broulik: `const` | |||||
403 | const int subRows = d->searchModel->rowCount(activeModule); | 403 | const int subRows = d->searchModel->rowCount(activeModule); | ||
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… | |||||
404 | if ( subRows < 2) { | 404 | if ( subRows < 2) { | ||
405 | d->moduleView->loadModule( activeModule ); | 405 | d->moduleView->loadModule( activeModule ); | ||
406 | } else { | 406 | } else { | ||
407 | d->moduleView->loadModule( d->searchModel->index(0, 0, activeModule) ); | 407 | d->moduleView->loadModule( d->searchModel->index(0, 0, activeModule) ); | ||
408 | } | 408 | } | ||
409 | 409 | | |||
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 | |||||
410 | d->subCategoryModel->setParentIndex( activeModule ); | 410 | d->subCategoryModel->setParentIndex( activeModule ); | ||
411 | } | 411 | } | ||
412 | 412 | | |||
413 | void SidebarMode::moduleLoaded() | 413 | void SidebarMode::moduleLoaded() | ||
414 | { | 414 | { | ||
415 | d->placeHolderWidget->hide(); | 415 | d->placeHolderWidget->hide(); | ||
416 | d->moduleView->show(); | 416 | d->moduleView->show(); | ||
417 | } | 417 | } | ||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 511 | if (rootImplicitWidth != 0) { | |||
512 | d->quickWidget->setFixedWidth(rootImplicitWidth); | 512 | d->quickWidget->setFixedWidth(rootImplicitWidth); | ||
513 | } else { | 513 | } else { | ||
514 | d->quickWidget->setFixedWidth(240); | 514 | d->quickWidget->setFixedWidth(240); | ||
515 | } | 515 | } | ||
516 | }); | 516 | }); | ||
517 | connect(d->quickWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext())); | 517 | connect(d->quickWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext())); | ||
518 | connect(d->quickWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious())); | 518 | connect(d->quickWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious())); | ||
519 | 519 | | |||
520 | d->quickWidget->installEventFilter(this); | | |||
521 | | ||||
522 | d->toolTipManager = new ToolTipManager(d->searchModel, d->quickWidget); | 520 | d->toolTipManager = new ToolTipManager(d->searchModel, d->quickWidget); | ||
523 | d->subCategoryToolTipManager = new ToolTipManager(d->subCategoryModel, d->quickWidget); | 521 | d->subCategoryToolTipManager = new ToolTipManager(d->subCategoryModel, d->quickWidget); | ||
524 | 522 | | |||
525 | d->placeHolderWidget = new QQuickWidget(d->mainWidget); | 523 | d->placeHolderWidget = new QQuickWidget(d->mainWidget); | ||
526 | d->placeHolderWidget->quickWindow()->setTitle(i18n("Most Used")); | 524 | d->placeHolderWidget->quickWindow()->setTitle(i18n("Most Used")); | ||
527 | d->placeHolderWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); | 525 | d->placeHolderWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); | ||
528 | d->placeHolderWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(d->placeHolderWidget)); | 526 | d->placeHolderWidget->engine()->rootContext()->setContextObject(new KLocalizedContext(d->placeHolderWidget)); | ||
529 | d->placeHolderWidget->engine()->rootContext()->setContextProperty(QStringLiteral("systemsettings"), this); | 527 | d->placeHolderWidget->engine()->rootContext()->setContextProperty(QStringLiteral("systemsettings"), this); | ||
530 | d->placeHolderWidget->setSource(QUrl::fromLocalFile(d->package.filePath("ui", QStringLiteral("introPage.qml")))); | 528 | d->placeHolderWidget->setSource(QUrl::fromLocalFile(d->package.filePath("ui", QStringLiteral("introPage.qml")))); | ||
531 | connect(d->placeHolderWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext())); | 529 | connect(d->placeHolderWidget->rootObject(), SIGNAL(focusNextRequest()), d->mainWidget, SLOT(focusNext())); | ||
532 | connect(d->placeHolderWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious())); | 530 | connect(d->placeHolderWidget->rootObject(), SIGNAL(focusPreviousRequest()), d->mainWidget, SLOT(focusPrevious())); | ||
533 | d->placeHolderWidget->installEventFilter(this); | | |||
534 | 531 | | |||
535 | d->mainLayout->addWidget( d->quickWidget ); | 532 | d->mainLayout->addWidget( d->quickWidget ); | ||
536 | d->moduleView->hide(); | 533 | d->moduleView->hide(); | ||
537 | d->mainLayout->addWidget( d->moduleView ); | 534 | d->mainLayout->addWidget( d->moduleView ); | ||
538 | d->mainLayout->addWidget( d->placeHolderWidget ); | 535 | d->mainLayout->addWidget( d->placeHolderWidget ); | ||
539 | emit changeToolBarItems(BaseMode::NoItems); | 536 | emit changeToolBarItems(BaseMode::NoItems); | ||
540 | 537 | | |||
541 | d->mostUsedModel->setResultModel(new ResultModel( AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this)); | 538 | d->mostUsedModel->setResultModel(new ResultModel( AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this)); | ||
Show All 23 Lines | 557 | if (qqw && qqw->rootObject()) { | |||
565 | } | 562 | } | ||
566 | } | 563 | } | ||
567 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | 564 | } else if (watched == d->quickWidget && event->type() == QEvent::Leave) { | ||
568 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | 565 | QCoreApplication::sendEvent(d->quickWidget->quickWindow(), event); | ||
569 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | 566 | } else if (watched == d->mainWidget && event->type() == QEvent::Resize) { | ||
570 | emit widthChanged(); | 567 | emit widthChanged(); | ||
571 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | 568 | } else if (watched == d->mainWidget && event->type() == QEvent::Show) { | ||
572 | emit changeToolBarItems(BaseMode::NoItems); | 569 | emit changeToolBarItems(BaseMode::NoItems); | ||
570 | } else if (watched->inherits("QWidgetWindow") && event->type() == QEvent::MouseButtonPress) { | ||||
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… | |||||
571 | QMetaObject::invokeMethod(d->quickWidget->rootObject(), "closeMenu"); | ||||
573 | } | 572 | } | ||
574 | return BaseMode::eventFilter(watched, event); | 573 | return BaseMode::eventFilter(watched, event); | ||
575 | } | 574 | } | ||
576 | 575 | | |||
577 | void SidebarMode::giveFocus() | 576 | void SidebarMode::giveFocus() | ||
578 | { | 577 | { | ||
579 | d->quickWidget->setFocus(); | 578 | d->quickWidget->setFocus(); | ||
580 | } | 579 | } | ||
581 | 580 | | |||
582 | #include "SidebarMode.moc" | 581 | #include "SidebarMode.moc" |
This leaks.
menu->setAttribute(Qt::WA_DeleteOnClose);