Changeset View
Changeset View
Standalone View
Standalone View
treeview.cpp
Show First 20 Lines • Show All 491 Lines • ▼ Show 20 Line(s) | 481 | foreach (MenuInfo *info, folderInfo->initialLayout) { | |||
---|---|---|---|---|---|
492 | } | 492 | } | ||
493 | MenuSeparatorInfo *separator = dynamic_cast<MenuSeparatorInfo *>(info); | 493 | MenuSeparatorInfo *separator = dynamic_cast<MenuSeparatorInfo *>(info); | ||
494 | if (separator) { | 494 | if (separator) { | ||
495 | after = createTreeItem(parent, after, separator); | 495 | after = createTreeItem(parent, after, separator); | ||
496 | continue; | 496 | continue; | ||
497 | } | 497 | } | ||
498 | } | 498 | } | ||
499 | } | 499 | } | ||
500 | | ||||
501 | void TreeView::closeAllItems(QTreeWidgetItem *item) | | |||
502 | { | | |||
503 | item->setExpanded(false); | | |||
504 | for (int i = 0; i < item->childCount(); ++i) { | | |||
505 | closeAllItems(item->child(i)); | | |||
506 | } | | |||
507 | } | | |||
508 | | ||||
509 | TreeItem *TreeView::expandPath(TreeItem *item, const QString &path) | 500 | TreeItem *TreeView::expandPath(TreeItem *item, const QString &path) | ||
510 | { | 501 | { | ||
511 | int i = path.indexOf(QStringLiteral("/")); | 502 | int i = path.indexOf(QStringLiteral("/")); | ||
512 | QString subMenu = path.left(i+1); | 503 | QString subMenu = path.left(i+1); | ||
513 | QString restMenu = path.mid(i+1); | 504 | QString restMenu = path.mid(i+1); | ||
514 | 505 | | |||
515 | for (int i = 0; i < item->childCount(); ++i) { | 506 | for (int i = 0; i < item->childCount(); ++i) { | ||
516 | TreeItem *childItem = dynamic_cast<TreeItem *>(item->child(i)); | 507 | TreeItem *childItem = dynamic_cast<TreeItem *>(item->child(i)); | ||
Show All 12 Lines | |||||
529 | } | 520 | } | ||
530 | } | 521 | } | ||
531 | 522 | | |||
532 | return nullptr; | 523 | return nullptr; | ||
533 | } | 524 | } | ||
534 | 525 | | |||
535 | void TreeView::selectMenu(const QString &menu) | 526 | void TreeView::selectMenu(const QString &menu) | ||
536 | { | 527 | { | ||
537 | for (int i = 0; i < topLevelItemCount(); ++i) { | 528 | | ||
538 | closeAllItems(topLevelItem(i)); | 529 | // close all parent expansions and deselect everything | ||
539 | } | 530 | collapseAll(); | ||
531 | setCurrentIndex(rootIndex()); | ||||
540 | 532 | | |||
541 | if (menu.length() <= 1) { | 533 | if (menu.length() <= 1) { | ||
542 | setCurrentItem(topLevelItem(0)); | 534 | setCurrentItem(topLevelItem(0)); | ||
543 | clearSelection(); | 535 | clearSelection(); | ||
544 | return; // Root menu | 536 | return; // Root menu | ||
545 | } | 537 | } | ||
546 | 538 | | |||
547 | QString restMenu = menu; | 539 | QString restMenu = menu; | ||
▲ Show 20 Lines • Show All 1373 Lines • ▼ Show 20 Line(s) | |||||
1921 | } | 1913 | } | ||
1922 | 1914 | | |||
1923 | void TreeView::sendReloadMenu() | 1915 | void TreeView::sendReloadMenu() | ||
1924 | { | 1916 | { | ||
1925 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/kickoff"), QStringLiteral("org.kde.plasma"), QStringLiteral("reloadMenu")); | 1917 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/kickoff"), QStringLiteral("org.kde.plasma"), QStringLiteral("reloadMenu")); | ||
1926 | QDBusConnection::sessionBus().send(message); | 1918 | QDBusConnection::sessionBus().send(message); | ||
1927 | } | 1919 | } | ||
1928 | 1920 | | |||
1921 | // Slot to expand or retract items in tree based on length of search string | ||||
1922 | void TreeView::searchUpdated(const QString &searchString) { | ||||
ngraham: I'm not sure this is actually working around anything; it's just a nice UI behavior! :) | |||||
1923 | // expand all categories if we typed more than a few characters, otherwise collapse and un-select everything | ||||
1924 | if (searchString.length() > 2) { | ||||
cfeck: Maybe use KStringHandler::logicalLength() for CJK users. | |||||
1925 | expandAll(); | ||||
1926 | } else { | ||||
1927 | collapseAll(); | ||||
1928 | setCurrentIndex(rootIndex()); | ||||
1929 | } | ||||
1930 | } | ||||
1931 | | ||||
1929 | MenuItemMimeData::MenuItemMimeData(TreeItem *item) | 1932 | MenuItemMimeData::MenuItemMimeData(TreeItem *item) | ||
1930 | : QMimeData() | 1933 | : QMimeData() | ||
1931 | , m_item(item) | 1934 | , m_item(item) | ||
1932 | { | 1935 | { | ||
1933 | } | 1936 | } | ||
1934 | 1937 | | |||
1935 | TreeItem *MenuItemMimeData::item() const | 1938 | TreeItem *MenuItemMimeData::item() const | ||
1936 | { | 1939 | { | ||
Show All 29 Lines |
I'm not sure this is actually working around anything; it's just a nice UI behavior! :)