Changeset View
Changeset View
Standalone View
Standalone View
sidebar/SidebarMode.cpp
Show All 25 Lines | |||||
26 | #include "BaseData.h" | 26 | #include "BaseData.h" | ||
27 | #include "ToolTips/tooltipmanager.h" | 27 | #include "ToolTips/tooltipmanager.h" | ||
28 | 28 | | |||
29 | #include <QHBoxLayout> | 29 | #include <QHBoxLayout> | ||
30 | 30 | | |||
31 | #include <QAction> | 31 | #include <QAction> | ||
32 | #include <KAboutData> | 32 | #include <KAboutData> | ||
33 | #include <KCModuleInfo> | 33 | #include <KCModuleInfo> | ||
34 | #include <KDescendantsProxyModel> | ||||
34 | #include <KStandardAction> | 35 | #include <KStandardAction> | ||
35 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
36 | #include <KIconLoader> | 37 | #include <KIconLoader> | ||
37 | #include <KLocalizedContext> | 38 | #include <KLocalizedContext> | ||
38 | #include <KServiceTypeTrader> | 39 | #include <KServiceTypeTrader> | ||
39 | #include <KXmlGuiWindow> | 40 | #include <KXmlGuiWindow> | ||
40 | #include <KActionCollection> | 41 | #include <KActionCollection> | ||
41 | #include <KPackage/Package> | 42 | #include <KPackage/Package> | ||
Show All 30 Lines | 72 | { | |||
72 | focusNextChild(); | 73 | focusNextChild(); | ||
73 | } | 74 | } | ||
74 | 75 | | |||
75 | void FocusHackWidget::focusPrevious() | 76 | void FocusHackWidget::focusPrevious() | ||
76 | { | 77 | { | ||
77 | focusNextPrevChild(false); | 78 | focusNextPrevChild(false); | ||
78 | } | 79 | } | ||
79 | 80 | | |||
80 | class SubcategoryModel : public QStandardItemModel | 81 | SubcategoryModel::SubcategoryModel(QAbstractItemModel *parentModel, QObject *parent) | ||
81 | { | | |||
82 | public: | | |||
83 | explicit SubcategoryModel(QAbstractItemModel *parentModel, QObject *parent = nullptr) | | |||
84 | : QStandardItemModel(parent), | 82 | : QStandardItemModel(parent), | ||
85 | m_parentModel(parentModel) | 83 | m_parentModel(parentModel) | ||
86 | {} | 84 | {} | ||
87 | 85 | | |||
88 | void setParentIndex(const QModelIndex &activeModule) | 86 | QString SubcategoryModel::title() const | ||
87 | { | ||||
88 | return m_title; | ||||
89 | } | ||||
90 | | ||||
91 | void SubcategoryModel::setParentIndex(const QModelIndex &activeModule) | ||||
89 | { | 92 | { | ||
90 | blockSignals(true); | 93 | blockSignals(true); | ||
91 | //make the view receive a single signal when the new subcategory is loaded, | 94 | //make the view receive a single signal when the new subcategory is loaded, | ||
92 | //never make the view believe there are zero items if this is not the final count | 95 | //never make the view believe there are zero items if this is not the final count | ||
93 | //this avoids the brief flash it had | 96 | //this avoids the brief flash it had | ||
94 | clear(); | 97 | clear(); | ||
95 | const int subRows = m_parentModel->rowCount(activeModule); | 98 | const int subRows = m_parentModel->rowCount(activeModule); | ||
96 | if ( subRows > 1) { | 99 | if ( subRows > 1) { | ||
97 | for (int i = 0; i < subRows; ++i) { | 100 | for (int i = 0; i < subRows; ++i) { | ||
98 | const QModelIndex& index = m_parentModel->index(i, 0, activeModule); | 101 | const QModelIndex& index = m_parentModel->index(i, 0, activeModule); | ||
99 | QStandardItem *item = new QStandardItem(m_parentModel->data(index, Qt::DecorationRole).value<QIcon>(), m_parentModel->data(index, Qt::DisplayRole).toString()); | 102 | QStandardItem *item = new QStandardItem(m_parentModel->data(index, Qt::DecorationRole).value<QIcon>(), m_parentModel->data(index, Qt::DisplayRole).toString()); | ||
100 | item->setData(index.data(Qt::UserRole), Qt::UserRole); | 103 | item->setData(index.data(Qt::UserRole), Qt::UserRole); | ||
101 | appendRow(item); | 104 | appendRow(item); | ||
102 | } | 105 | } | ||
103 | } | 106 | } | ||
104 | blockSignals(false); | 107 | blockSignals(false); | ||
105 | beginResetModel(); | 108 | beginResetModel(); | ||
106 | endResetModel(); | 109 | endResetModel(); | ||
110 | m_title = activeModule.data(Qt::DisplayRole).toString(); | ||||
111 | emit titleChanged(); | ||||
107 | } | 112 | } | ||
108 | 113 | | |||
109 | private: | | |||
110 | QAbstractItemModel *m_parentModel; | | |||
111 | }; | | |||
112 | 114 | | |||
113 | class MostUsedModel : public QSortFilterProxyModel | 115 | class MostUsedModel : public QSortFilterProxyModel | ||
114 | { | 116 | { | ||
115 | public: | 117 | public: | ||
116 | explicit MostUsedModel(QObject *parent = nullptr) | 118 | explicit MostUsedModel(QObject *parent = nullptr) | ||
117 | : QSortFilterProxyModel (parent) | 119 | : QSortFilterProxyModel (parent) | ||
118 | { | 120 | { | ||
119 | sort(0, Qt::DescendingOrder); | 121 | sort(0, Qt::DescendingOrder); | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 217 | case ResultModel::ScoreRole: | |||
216 | return QSortFilterProxyModel::data(index, ResultModel::ScoreRole).toInt(); | 218 | return QSortFilterProxyModel::data(index, ResultModel::ScoreRole).toInt(); | ||
217 | default: | 219 | default: | ||
218 | return QVariant(); | 220 | return QVariant(); | ||
219 | } | 221 | } | ||
220 | } | 222 | } | ||
221 | 223 | | |||
222 | private: | 224 | private: | ||
223 | QHash<QString, MenuItem *> m_menuItems; | 225 | QHash<QString, MenuItem *> m_menuItems; | ||
226 | // Model when there is nothing from kactivities-stat | ||||
224 | QStandardItemModel *m_defaultModel; | 227 | QStandardItemModel *m_defaultModel; | ||
228 | // Model fed by kactivities-stats | ||||
225 | ResultModel *m_resultModel; | 229 | ResultModel *m_resultModel; | ||
226 | }; | 230 | }; | ||
227 | 231 | | |||
228 | class SidebarMode::Private { | 232 | class SidebarMode::Private { | ||
229 | public: | 233 | public: | ||
230 | Private() | 234 | Private() | ||
231 | : quickWidget( nullptr ), | 235 | : quickWidget( nullptr ), | ||
232 | moduleView( nullptr ), | 236 | moduleView( nullptr ), | ||
233 | collection( nullptr ), | 237 | collection( nullptr ), | ||
234 | activeCategory( -1 ), | 238 | activeCategoryRow( -1 ), | ||
235 | activeSubCategory( -1 ) | 239 | activeSubCategoryRow( -1 ) | ||
236 | {} | 240 | {} | ||
237 | 241 | | |||
238 | virtual ~Private() { | 242 | virtual ~Private() { | ||
239 | delete aboutIcon; | 243 | delete aboutIcon; | ||
240 | } | 244 | } | ||
241 | 245 | | |||
242 | ToolTipManager *toolTipManager = nullptr; | 246 | ToolTipManager *toolTipManager = nullptr; | ||
243 | ToolTipManager *subCategoryToolTipManager = nullptr; | | |||
244 | ToolTipManager *mostUsedToolTipManager = nullptr; | 247 | ToolTipManager *mostUsedToolTipManager = nullptr; | ||
245 | QQuickWidget * quickWidget = nullptr; | 248 | QQuickWidget * quickWidget = nullptr; | ||
246 | KPackage::Package package; | 249 | KPackage::Package package; | ||
247 | SubcategoryModel * subCategoryModel = nullptr; | 250 | SubcategoryModel * subCategoryModel = nullptr; | ||
248 | MostUsedModel * mostUsedModel = nullptr; | 251 | MostUsedModel * mostUsedModel = nullptr; | ||
249 | FocusHackWidget * mainWidget = nullptr; | 252 | FocusHackWidget * mainWidget = nullptr; | ||
250 | QQuickWidget * placeHolderWidget = nullptr; | 253 | QQuickWidget * placeHolderWidget = nullptr; | ||
251 | QHBoxLayout * mainLayout = nullptr; | 254 | QHBoxLayout * mainLayout = nullptr; | ||
252 | KDeclarative::KDeclarative kdeclarative; | 255 | KDeclarative::KDeclarative kdeclarative; | ||
256 | MenuModel * model = nullptr; | ||||
253 | MenuProxyModel * categorizedModel = nullptr; | 257 | MenuProxyModel * categorizedModel = nullptr; | ||
254 | MenuProxyModel * searchModel = nullptr; | 258 | MenuProxyModel * searchModel = nullptr; | ||
259 | KDescendantsProxyModel * flatModel = nullptr; | ||||
255 | KAboutData * aboutIcon = nullptr; | 260 | KAboutData * aboutIcon = nullptr; | ||
256 | ModuleView * moduleView = nullptr; | 261 | ModuleView * moduleView = nullptr; | ||
257 | KActionCollection *collection = nullptr; | 262 | KActionCollection *collection = nullptr; | ||
258 | QPersistentModelIndex activeCategoryIndex; | 263 | QPersistentModelIndex activeCategoryIndex; | ||
259 | int activeCategory; | 264 | int activeCategoryRow = -1; | ||
260 | int activeSubCategory; | 265 | int activeSubCategoryRow = -1; | ||
266 | int activeSearchRow = -1; | ||||
davidedmundson: calling an int categoryRow makes sense, as the int refers to the row.
Calling an index… | |||||
261 | bool m_actionMenuVisible = false; | 267 | bool m_actionMenuVisible = false; | ||
262 | void setActionMenuVisible(SidebarMode* sidebarMode, const bool &actionMenuVisible) | 268 | void setActionMenuVisible(SidebarMode* sidebarMode, const bool &actionMenuVisible) | ||
263 | { | 269 | { | ||
264 | if (m_actionMenuVisible == actionMenuVisible) { | 270 | if (m_actionMenuVisible == actionMenuVisible) { | ||
265 | return; | 271 | return; | ||
266 | } | 272 | } | ||
267 | m_actionMenuVisible = actionMenuVisible; | 273 | m_actionMenuVisible = actionMenuVisible; | ||
268 | emit sidebarMode->actionMenuVisibleChanged(); | 274 | emit sidebarMode->actionMenuVisibleChanged(); | ||
Show All 37 Lines | 311 | { | |||
306 | if( !d->quickWidget ) { | 312 | if( !d->quickWidget ) { | ||
307 | initWidget(); | 313 | initWidget(); | ||
308 | } | 314 | } | ||
309 | return d->mainWidget; | 315 | return d->mainWidget; | ||
310 | } | 316 | } | ||
311 | 317 | | |||
312 | QAbstractItemModel * SidebarMode::categoryModel() const | 318 | QAbstractItemModel * SidebarMode::categoryModel() const | ||
313 | { | 319 | { | ||
320 | return d->categorizedModel; | ||||
321 | } | ||||
322 | | ||||
323 | QAbstractItemModel * SidebarMode::searchModel() const | ||||
324 | { | ||||
314 | return d->searchModel; | 325 | return d->searchModel; | ||
315 | } | 326 | } | ||
316 | 327 | | |||
317 | QAbstractItemModel * SidebarMode::subCategoryModel() const | 328 | QAbstractItemModel * SidebarMode::subCategoryModel() const | ||
318 | { | 329 | { | ||
319 | return d->subCategoryModel; | 330 | return d->subCategoryModel; | ||
320 | } | 331 | } | ||
321 | 332 | | |||
322 | QAbstractItemModel * SidebarMode::mostUsedModel() const | 333 | QAbstractItemModel * SidebarMode::mostUsedModel() const | ||
323 | { | 334 | { | ||
324 | return d->mostUsedModel; | 335 | return d->mostUsedModel; | ||
325 | } | 336 | } | ||
326 | 337 | | |||
327 | QList<QAbstractItemView*> SidebarMode::views() const | 338 | QList<QAbstractItemView*> SidebarMode::views() const | ||
328 | { | 339 | { | ||
329 | QList<QAbstractItemView*> list; | 340 | QList<QAbstractItemView*> list; | ||
330 | //list.append( d->categoryView ); | 341 | //list.append( d->categoryView ); | ||
331 | return list; | 342 | return list; | ||
332 | } | 343 | } | ||
333 | 344 | | |||
334 | void SidebarMode::initEvent() | 345 | void SidebarMode::initEvent() | ||
335 | { | 346 | { | ||
336 | MenuModel * model = new MenuModel( rootItem(), this ); | 347 | d->model = new MenuModel( rootItem(), this ); | ||
337 | foreach( MenuItem * child, rootItem()->children() ) { | 348 | foreach( MenuItem * child, rootItem()->children() ) { | ||
338 | model->addException( child ); | 349 | d->model->addException( child ); | ||
339 | } | 350 | } | ||
340 | 351 | | |||
341 | d->categorizedModel = new MenuProxyModel( this ); | 352 | d->categorizedModel = new MenuProxyModel( this ); | ||
342 | d->categorizedModel->setCategorizedModel( true ); | 353 | d->categorizedModel->setCategorizedModel( true ); | ||
343 | d->categorizedModel->setSourceModel( model ); | 354 | d->categorizedModel->setSourceModel( d->model ); | ||
344 | d->categorizedModel->sort( 0 ); | 355 | d->categorizedModel->sort( 0 ); | ||
345 | d->categorizedModel->setFilterHighlightsEntries( false ); | 356 | d->categorizedModel->setFilterHighlightsEntries( false ); | ||
346 | 357 | | |||
358 | d->flatModel = new KDescendantsProxyModel( this ); | ||||
359 | d->flatModel->setSourceModel( d->model ); | ||||
360 | | ||||
347 | d->searchModel = new MenuProxyModel( this ); | 361 | d->searchModel = new MenuProxyModel( this ); | ||
362 | d->searchModel->setCategorizedModel( true ); | ||||
348 | d->searchModel->setFilterHighlightsEntries( false ); | 363 | d->searchModel->setFilterHighlightsEntries( false ); | ||
349 | d->searchModel->setSourceModel( d->categorizedModel ); | 364 | d->searchModel->setSourceModel( d->flatModel ); | ||
350 | connect( d->searchModel, &MenuProxyModel::filterRegExpChanged, this, [this] () { | | |||
351 | if (d->activeCategoryIndex.isValid() && d->activeCategoryIndex.row() >= 0) { | | |||
352 | d->subCategoryModel->setParentIndex( d->activeCategoryIndex ); | | |||
353 | emit activeCategoryChanged(); | | |||
354 | } | | |||
355 | }); | | |||
356 | 365 | | |||
357 | d->mostUsedModel = new MostUsedModel( this ); | 366 | d->mostUsedModel = new MostUsedModel( this ); | ||
358 | 367 | | |||
359 | d->subCategoryModel = new SubcategoryModel( d->searchModel, this ); | 368 | d->subCategoryModel = new SubcategoryModel( d->categorizedModel, this ); | ||
360 | d->mainWidget = new FocusHackWidget(); | 369 | d->mainWidget = new FocusHackWidget(); | ||
361 | d->mainWidget->installEventFilter(this); | 370 | d->mainWidget->installEventFilter(this); | ||
362 | d->mainLayout = new QHBoxLayout(d->mainWidget); | 371 | d->mainLayout = new QHBoxLayout(d->mainWidget); | ||
363 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | 372 | d->mainLayout->setContentsMargins(0, 0, 0, 0); | ||
364 | d->moduleView = new ModuleView( d->mainWidget ); | 373 | d->moduleView = new ModuleView( d->mainWidget ); | ||
365 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | 374 | connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded ); | ||
366 | d->quickWidget = nullptr; | 375 | d->quickWidget = nullptr; | ||
367 | moduleView()->setFaceType(KPageView::Plain); | 376 | moduleView()->setFaceType(KPageView::Plain); | ||
Show All 12 Lines | |||||
380 | { | 389 | { | ||
381 | if (QAction *a = action(name)) { | 390 | if (QAction *a = action(name)) { | ||
382 | return a->icon().name(); | 391 | return a->icon().name(); | ||
383 | } | 392 | } | ||
384 | 393 | | |||
385 | return QString(); | 394 | return QString(); | ||
386 | } | 395 | } | ||
387 | 396 | | |||
388 | void SidebarMode::requestToolTip(int index, const QRectF &rect) | 397 | void SidebarMode::requestToolTip(const QModelIndex &index, const QRectF &rect) | ||
389 | { | 398 | { | ||
390 | if (showToolTips()) { | 399 | if (showToolTips() && index.model()) { | ||
391 | d->toolTipManager->requestToolTip(d->searchModel->index(index, 0), rect.toRect()); | 400 | d->toolTipManager->setModel(index.model()); | ||
392 | } | 401 | d->toolTipManager->requestToolTip(index, rect.toRect()); | ||
please check validity, otherwise model is null and we'll crash. also ..why make it const, only to cast it? davidedmundson: please check validity, otherwise model is null and we'll crash.
also ..why make it const, only… | |||||
mart: QModelIndex::index() is always const? | |||||
mart: got rif of the cast | |||||
393 | } | | |||
394 | | ||||
395 | void SidebarMode::requestSubCategoryToolTip(int index, const QRectF &rect) | | |||
396 | { | | |||
397 | if (showToolTips()) { | | |||
398 | d->subCategoryToolTipManager->requestToolTip(d->subCategoryModel->index(index, 0), rect.toRect()); | | |||
399 | } | 402 | } | ||
400 | } | 403 | } | ||
401 | 404 | | |||
402 | void SidebarMode::requestMostUsedToolTip(int index, const QRectF &rect) | 405 | void SidebarMode::requestMostUsedToolTip(int index, const QRectF &rect) | ||
403 | { | 406 | { | ||
404 | if (showToolTips()) { | 407 | if (showToolTips()) { | ||
405 | d->mostUsedToolTipManager->requestToolTip(d->mostUsedModel->index(index, 0), rect.toRect()); | 408 | d->mostUsedToolTipManager->requestToolTip(d->mostUsedModel->index(index, 0), rect.toRect()); | ||
406 | } | 409 | } | ||
407 | } | 410 | } | ||
408 | 411 | | |||
409 | void SidebarMode::hideToolTip() | 412 | void SidebarMode::hideToolTip() | ||
410 | { | 413 | { | ||
411 | d->toolTipManager->hideToolTip(); | 414 | d->toolTipManager->hideToolTip(); | ||
412 | } | 415 | } | ||
413 | 416 | | |||
414 | void SidebarMode::hideSubCategoryToolTip() | | |||
415 | { | | |||
416 | d->subCategoryToolTipManager->hideToolTip(); | | |||
417 | } | | |||
418 | | ||||
419 | void SidebarMode::hideMostUsedToolTip() | 417 | void SidebarMode::hideMostUsedToolTip() | ||
420 | { | 418 | { | ||
421 | d->mostUsedToolTipManager->hideToolTip(); | 419 | d->mostUsedToolTipManager->hideToolTip(); | ||
422 | } | 420 | } | ||
423 | 421 | | |||
424 | void SidebarMode::loadMostUsed(int index) | | |||
425 | { | | |||
426 | const QModelIndex idx = d->mostUsedModel->index(index, 0); | | |||
427 | d->moduleView->closeModules(); | | |||
428 | d->moduleView->loadModule( idx ); | | |||
429 | setIntroPageVisible(false); | | |||
430 | } | | |||
431 | | ||||
432 | void SidebarMode::showActionMenu(const QPoint &position) | 422 | void SidebarMode::showActionMenu(const QPoint &position) | ||
433 | { | 423 | { | ||
434 | QMenu *menu = new QMenu(); | 424 | QMenu *menu = new QMenu(); | ||
435 | connect(menu, &QMenu::aboutToHide, this, [this] () { d->setActionMenuVisible(this, false); } ); | 425 | connect(menu, &QMenu::aboutToHide, this, [this] () { d->setActionMenuVisible(this, false); } ); | ||
436 | menu->setAttribute(Qt::WA_DeleteOnClose); | 426 | menu->setAttribute(Qt::WA_DeleteOnClose); | ||
437 | 427 | | |||
438 | const QStringList actionList { QStringLiteral("configure"), QStringLiteral("help_contents"), QStringLiteral("help_about_app"), QStringLiteral("help_about_kde") }; | 428 | const QStringList actionList { QStringLiteral("configure"), QStringLiteral("help_contents"), QStringLiteral("help_about_app"), QStringLiteral("help_about_kde") }; | ||
439 | for (const QString &actionName : actionList) { | 429 | for (const QString &actionName : actionList) { | ||
440 | menu->addAction(d->collection->action(actionName)); | 430 | menu->addAction(d->collection->action(actionName)); | ||
441 | } | 431 | } | ||
442 | 432 | | |||
443 | menu->popup(position); | 433 | menu->popup(position); | ||
444 | d->setActionMenuVisible(this, true); | 434 | d->setActionMenuVisible(this, true); | ||
445 | } | 435 | } | ||
446 | 436 | | |||
447 | void SidebarMode::changeModule( const QModelIndex& activeModule ) | 437 | void SidebarMode::loadModule( const QModelIndex& activeModule ) | ||
448 | { | 438 | { | ||
439 | if (!activeModule.isValid()) { | ||||
440 | return; | ||||
441 | } | ||||
442 | | ||||
449 | d->moduleView->closeModules(); | 443 | d->moduleView->closeModules(); | ||
450 | 444 | | |||
451 | if (!activeModule.isValid()) { | 445 | MenuItem *mi = activeModule.data(MenuModel::MenuItemRole).value<MenuItem *>(); | ||
446 | | ||||
447 | if (!mi) { | ||||
452 | return; | 448 | return; | ||
453 | } | 449 | } | ||
454 | 450 | | |||
455 | const int subRows = d->searchModel->rowCount(activeModule); | 451 | setIntroPageVisible(false); | ||
456 | if ( subRows < 2) { | 452 | if ( mi->children().length() < 1) { | ||
457 | d->moduleView->loadModule( activeModule ); | 453 | d->moduleView->loadModule( activeModule ); | ||
458 | } else { | 454 | } else { | ||
459 | d->moduleView->loadModule( d->searchModel->index(0, 0, activeModule) ); | 455 | d->moduleView->loadModule( activeModule.model()->index(0, 0, activeModule) ); | ||
456 | } | ||||
457 | | ||||
458 | if (activeModule.model() == d->categorizedModel) { | ||||
459 | const int newCategoryRow = activeModule.row(); | ||||
460 | | ||||
461 | if (d->activeCategoryRow == newCategoryRow) { | ||||
462 | return; | ||||
460 | } | 463 | } | ||
464 | if( !d->moduleView->resolveChanges() ) { | ||||
465 | return; | ||||
466 | } | ||||
467 | | ||||
468 | d->activeCategoryIndex = activeModule; | ||||
469 | d->activeCategoryRow = newCategoryRow; | ||||
470 | | ||||
471 | d->activeSubCategoryRow = 0; | ||||
461 | 472 | | |||
462 | d->subCategoryModel->setParentIndex( activeModule ); | 473 | d->subCategoryModel->setParentIndex( activeModule ); | ||
474 | | ||||
475 | if (d->activeSearchRow > -1) { | ||||
476 | d->activeSearchRow = -1; | ||||
477 | emit activeSearchRowChanged(); | ||||
463 | } | 478 | } | ||
464 | 479 | | |||
465 | void SidebarMode::moduleLoaded() | 480 | emit activeCategoryRowChanged(); | ||
466 | { | 481 | emit activeSubCategoryRowChanged(); | ||
467 | d->placeHolderWidget->hide(); | 482 | | ||
468 | d->moduleView->show(); | 483 | } else if (activeModule.model() == d->subCategoryModel) { | ||
484 | if (d->activeSearchRow > -1) { | ||||
485 | d->activeSearchRow = -1; | ||||
486 | emit activeSearchRowChanged(); | ||||
469 | } | 487 | } | ||
488 | d->activeSubCategoryRow = activeModule.row(); | ||||
489 | emit activeSubCategoryRowChanged(); | ||||
470 | 490 | | |||
471 | int SidebarMode::activeCategory() const | 491 | } else if (activeModule.model() == d->searchModel | ||
472 | { | 492 | && mi->parent() && mi->parent()->menu()) { | ||
473 | return d->searchModel->mapFromSource(d->searchModel->sourceModel()->index(d->activeCategory, 0)).row(); | 493 | QModelIndex originalIndex = d->categorizedModel->mapFromSource( | ||
494 | d->flatModel->mapToSource( | ||||
495 | d->searchModel->mapToSource(activeModule))); | ||||
496 | | ||||
497 | if (originalIndex.isValid()) { | ||||
498 | d->subCategoryModel->setParentIndex( originalIndex.parent() ); | ||||
499 | d->activeCategoryRow = originalIndex.parent().row(); | ||||
500 | d->activeSubCategoryRow = originalIndex.row(); | ||||
501 | emit activeCategoryRowChanged(); | ||||
502 | emit activeSubCategoryRowChanged(); | ||||
474 | } | 503 | } | ||
475 | 504 | | |||
476 | void SidebarMode::setActiveCategory(int cat) | 505 | d->activeSearchRow = activeModule.row(); | ||
477 | { | 506 | emit activeSearchRowChanged(); | ||
478 | const QModelIndex idx = d->searchModel->index(cat, 0); | 507 | | ||
479 | int newCategoryRow; | 508 | } else if (activeModule.model() == d->mostUsedModel) { | ||
480 | if (cat != -1) { | 509 | if (d->activeSearchRow > -1) { | ||
481 | setIntroPageVisible(false); | 510 | d->activeSearchRow = -1; | ||
482 | newCategoryRow = d->searchModel->mapToSource(idx).row(); | 511 | emit activeSearchRowChanged(); | ||
483 | } else { | | |||
484 | newCategoryRow = cat; | | |||
485 | } | 512 | } | ||
486 | 513 | | |||
487 | if (d->activeCategory == newCategoryRow) { | 514 | QModelIndex flatIndex; | ||
488 | return; | 515 | | ||
516 | // search the corresponding item on the main model | ||||
517 | for (int i = 0; i < d->flatModel->rowCount(); ++i) { | ||||
518 | QModelIndex idx = d->flatModel->index(i, 0); | ||||
519 | MenuItem *otherMi = idx.data(MenuModel::MenuItemRole).value<MenuItem *>(); | ||||
520 | | ||||
521 | if (otherMi->item() == mi->item()) { | ||||
522 | flatIndex = idx; | ||||
523 | break; | ||||
489 | } | 524 | } | ||
490 | if( !d->moduleView->resolveChanges() ) { | | |||
491 | return; | | |||
492 | } | 525 | } | ||
493 | 526 | | |||
494 | d->activeCategoryIndex = idx; | 527 | if (flatIndex.isValid()) { | ||
495 | d->activeCategory = newCategoryRow; | 528 | QModelIndex idx = d->categorizedModel->mapFromSource(d->flatModel->mapToSource(flatIndex)); | ||
496 | 529 | | |||
497 | changeModule(idx); | 530 | MenuItem *parentMi = idx.parent().data(MenuModel::MenuItemRole).value<MenuItem *>(); | ||
498 | d->activeSubCategory = 0; | 531 | if (idx.isValid()) { | ||
499 | emit activeCategoryChanged(); | 532 | if (parentMi->menu()) { | ||
500 | emit activeSubCategoryChanged(); | 533 | d->subCategoryModel->setParentIndex( idx.parent() ); | ||
534 | d->activeCategoryRow = idx.parent().row(); | ||||
535 | d->activeSubCategoryRow = idx.row(); | ||||
536 | } else { | ||||
537 | d->activeCategoryRow = idx.row(); | ||||
538 | d->activeSubCategoryRow = -1; | ||||
539 | } | ||||
540 | emit activeCategoryRowChanged(); | ||||
541 | emit activeSubCategoryRowChanged(); | ||||
542 | } | ||||
543 | } | ||||
544 | } | ||||
501 | } | 545 | } | ||
502 | 546 | | |||
503 | void SidebarMode::setActiveSubCategory(int cat) | 547 | void SidebarMode::moduleLoaded() | ||
504 | { | 548 | { | ||
505 | if (d->activeSubCategory == cat) { | 549 | d->placeHolderWidget->hide(); | ||
506 | return; | 550 | d->moduleView->show(); | ||
507 | } | 551 | } | ||
508 | 552 | | |||
509 | if( !d->moduleView->resolveChanges() ) { | 553 | int SidebarMode::activeSearchRow() const | ||
510 | return; | 554 | { | ||
555 | return d->activeSearchRow; | ||||
511 | } | 556 | } | ||
512 | 557 | | |||
513 | d->activeSubCategory = cat; | 558 | int SidebarMode::activeCategoryRow() const | ||
514 | d->moduleView->closeModules(); | 559 | { | ||
515 | d->moduleView->loadModule( d->subCategoryModel->index(cat, 0) ); | 560 | return d->activeCategoryRow; | ||
516 | setIntroPageVisible(cat < 0); | | |||
517 | emit activeSubCategoryChanged(); | | |||
518 | } | 561 | } | ||
519 | 562 | | |||
520 | void SidebarMode::setIntroPageVisible(const bool &introPageVisible) | 563 | void SidebarMode::setIntroPageVisible(const bool &introPageVisible) | ||
521 | { | 564 | { | ||
522 | if (d->m_introPageVisible == introPageVisible) { | 565 | if (d->m_introPageVisible == introPageVisible) { | ||
523 | return; | 566 | return; | ||
524 | } | 567 | } | ||
525 | 568 | | |||
526 | if (introPageVisible) { | 569 | if (introPageVisible) { | ||
527 | setActiveCategory(-1); | 570 | d->activeCategoryRow = -1; | ||
528 | setActiveSubCategory(-1); | 571 | emit activeCategoryRowChanged(); | ||
572 | d->activeSubCategoryRow = -1; | ||||
573 | emit activeSubCategoryRowChanged(); | ||||
529 | d->placeHolderWidget->show(); | 574 | d->placeHolderWidget->show(); | ||
530 | d->moduleView->hide(); | 575 | d->moduleView->hide(); | ||
531 | } else { | 576 | } else { | ||
532 | d->placeHolderWidget->hide(); | 577 | d->placeHolderWidget->hide(); | ||
533 | d->moduleView->show(); | 578 | d->moduleView->show(); | ||
534 | } | 579 | } | ||
535 | 580 | | |||
536 | d->m_introPageVisible = introPageVisible; | 581 | d->m_introPageVisible = introPageVisible; | ||
537 | emit introPageVisibleChanged(); | 582 | emit introPageVisibleChanged(); | ||
538 | } | 583 | } | ||
539 | 584 | | |||
540 | int SidebarMode::width() const | 585 | int SidebarMode::width() const | ||
541 | { | 586 | { | ||
542 | return d->mainWidget->width(); | 587 | return d->mainWidget->width(); | ||
543 | } | 588 | } | ||
544 | 589 | | |||
545 | bool SidebarMode::actionMenuVisible() const | 590 | bool SidebarMode::actionMenuVisible() const | ||
546 | { | 591 | { | ||
547 | return d->m_actionMenuVisible; | 592 | return d->m_actionMenuVisible; | ||
548 | } | 593 | } | ||
549 | 594 | | |||
550 | int SidebarMode::activeSubCategory() const | 595 | int SidebarMode::activeSubCategoryRow() const | ||
551 | { | 596 | { | ||
552 | return d->activeSubCategory; | 597 | return d->activeSubCategoryRow; | ||
553 | } | 598 | } | ||
554 | 599 | | |||
555 | bool SidebarMode::introPageVisible() const | 600 | bool SidebarMode::introPageVisible() const | ||
556 | { | 601 | { | ||
557 | return (d->m_introPageVisible); | 602 | return (d->m_introPageVisible); | ||
558 | } | 603 | } | ||
559 | 604 | | |||
560 | void SidebarMode::initWidget() | 605 | void SidebarMode::initWidget() | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 606 | { | |||
619 | d->placeHolderWidget->installEventFilter(this); | 664 | d->placeHolderWidget->installEventFilter(this); | ||
620 | 665 | | |||
621 | d->mainLayout->addWidget( d->quickWidget ); | 666 | d->mainLayout->addWidget( d->quickWidget ); | ||
622 | d->moduleView->hide(); | 667 | d->moduleView->hide(); | ||
623 | d->mainLayout->addWidget( d->moduleView ); | 668 | d->mainLayout->addWidget( d->moduleView ); | ||
624 | d->mainLayout->addWidget( d->placeHolderWidget ); | 669 | d->mainLayout->addWidget( d->placeHolderWidget ); | ||
625 | emit changeToolBarItems(BaseMode::NoItems); | 670 | emit changeToolBarItems(BaseMode::NoItems); | ||
626 | 671 | | |||
627 | d->toolTipManager = new ToolTipManager(d->searchModel, d->quickWidget, ToolTipManager::ToolTipPosition::Right); | 672 | d->toolTipManager = new ToolTipManager(d->categorizedModel, d->quickWidget, ToolTipManager::ToolTipPosition::Right); | ||
628 | d->subCategoryToolTipManager = new ToolTipManager(d->subCategoryModel, d->quickWidget, ToolTipManager::ToolTipPosition::Right); | | |||
629 | d->mostUsedToolTipManager = new ToolTipManager(d->mostUsedModel, d->placeHolderWidget, ToolTipManager::ToolTipPosition::BottomCenter); | 673 | d->mostUsedToolTipManager = new ToolTipManager(d->mostUsedModel, d->placeHolderWidget, ToolTipManager::ToolTipPosition::BottomCenter); | ||
630 | 674 | | |||
631 | d->mostUsedModel->setResultModel(new ResultModel( AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this)); | 675 | d->mostUsedModel->setResultModel(new ResultModel( AllResources | Agent(QStringLiteral("org.kde.systemsettings")) | HighScoredFirst | Limit(5), this)); | ||
632 | } | 676 | } | ||
633 | 677 | | |||
634 | bool SidebarMode::eventFilter(QObject* watched, QEvent* event) | 678 | bool SidebarMode::eventFilter(QObject* watched, QEvent* event) | ||
635 | { | 679 | { | ||
636 | //FIXME: those are all workarounds around the QQuickWidget brokeness | 680 | //FIXME: those are all workarounds around the QQuickWidget brokeness | ||
Show All 36 Lines |
calling an int categoryRow makes sense, as the int refers to the row.
Calling an index CategoryRow doesn't.