Changeset 77723 in vbox
- Timestamp:
- Mar 15, 2019 12:52:07 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItem.cpp
r77701 r77723 463 463 void UIChooserItem::makeSureItsVisible() 464 464 { 465 /* If item is not visible: */ 465 /* Get parrent item: */ 466 UIChooserItemGroup *pParentItem = parentItem()->toGroupItem(); 467 if (!pParentItem) 468 return; 469 /* If item is not visible. That is all the parent group(s) are opened (expanded): */ 466 470 if (!isVisible()) 467 471 { 468 /* Get parrent item, assert if can't: */ 469 if (UIChooserItemGroup *pParentItem = parentItem()->toGroupItem()) 470 { 471 /* We should make parent visible: */ 472 pParentItem->makeSureItsVisible(); 473 /* And make sure its opened: */ 474 if (pParentItem->isClosed()) 475 pParentItem->open(false); 476 } 477 } 472 /* We should make parent visible: */ 473 pParentItem->makeSureItsVisible(); 474 /* And make sure its opened: */ 475 if (pParentItem->isClosed()) 476 pParentItem->open(false); 477 } 478 /* Make sure we scroll to the item's rectangle: */ 479 pParentItem->makeSureItemIsVisible(this); 478 480 } 479 481 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp
r77654 r77723 142 142 { 143 143 return "UIChooserItemGroup"; 144 } 145 146 void UIChooserItemGroup::makeSureItemIsVisible(UIChooserItem *pItem) 147 { 148 /* Make sure item exists: */ 149 AssertPtrReturnVoid(pItem); 150 151 /* Convert child rectangle to local coordinates for this group. This also 152 * works for a child at any sub-level, doesn't necessary of this group. */ 153 const QPointF positionInScene = pItem->mapToScene(QPointF(0, 0)); 154 const QPointF positionInGroup = mapFromScene(positionInScene); 155 const QRectF itemRectInGroup = QRectF(positionInGroup, pItem->size()); 156 m_pScrollArea->makeSureRectIsVisible(itemRectInGroup); 144 157 } 145 158 … … 695 708 /* Else call to base-class: */ 696 709 return UIChooserItem::sizeHint(enmWhich, constraint); 697 }698 699 void UIChooserItemGroup::makeSureItemIsVisible(UIChooserItem *pItem)700 {701 /* Make sure item exists: */702 AssertPtrReturnVoid(pItem);703 704 /* Convert child rectangle to local coordinates for this group. This also705 * works for a child at any sub-level, doesn't necessary of this group. */706 const QPointF positionInScene = pItem->mapToScene(QPointF(0, 0));707 const QPointF positionInGroup = mapFromScene(positionInScene);708 const QRectF itemRectInGroup = QRectF(positionInGroup, pItem->size());709 m_pScrollArea->makeSureRectIsVisible(itemRectInGroup);710 710 } 711 711 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h
r77638 r77723 86 86 /** Class-name used for drag&drop mime-data format. */ 87 87 static QString className(); 88 /** Makes sure passed child @a pItem is visible. */ 89 virtual void makeSureItemIsVisible(UIChooserItem *pItem) /* override */; 88 90 /** @} */ 89 91 … … 168 170 /** @name Navigation stuff. 169 171 * @{ */ 170 /** Makes sure passed child @a pItem is visible. */171 virtual void makeSureItemIsVisible(UIChooserItem *pItem) /* override */;172 173 172 /** Returns pixmap item representation. */ 174 173 virtual QPixmap toPixmap() /* override */; -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp
r77701 r77723 68 68 , m_pContextMenuGroup(0) 69 69 , m_pContextMenuMachine(0) 70 , m_iCurrentScrolledIndex(-1) 70 71 , m_pInvisibleRootNode(0) 71 72 , m_iScrollingTokenSize(30) … … 131 132 { 132 133 return m_pScene; 134 } 135 136 UIChooserView *UIChooserModel::view() 137 { 138 if (!scene()) 139 return 0; 140 UIChooserView *pChooserView = qobject_cast<UIChooserView*>(scene()->views()[0]); 141 return pChooserView; 133 142 } 134 143 … … 426 435 427 436 /* If dialog is visible and item exists => make it visible as well: */ 428 if (scene()->views()[0]->window()->isVisible() && pItem) 429 root()->makeSureItemIsVisible(pItem); 437 if (view() && view()->window() && root()) 438 if (view()->window()->isVisible() && pItem) 439 root()->makeSureItemIsVisible(pItem); 430 440 } 431 441 … … 459 469 /* Currently we perform the search only for machines. when this to be changed make sure the disabled flags 460 470 of the other item types are also managed correctly: */ 471 472 QList<UIChooserNode*> allNodes = resetSearch(); 473 if (strSearchTerm.isEmpty()) 474 return; 475 476 m_pInvisibleRootNode->searchForNodes(strSearchTerm, iItemSearchFlags, m_searchResults); 477 478 foreach (UIChooserNode* pNode, allNodes) 479 { 480 if (!pNode) 481 continue; 482 pNode->setDisabled(!m_searchResults.contains(pNode)); 483 } 484 485 scrollToSearchResult(true); 486 } 487 488 QList<UIChooserNode*> UIChooserModel::resetSearch() 489 { 461 490 QList<UIChooserNode*> allNodes; 462 491 /* Calling UIChooserNode::searchForNodes with an empty search string returns a list all nodes (of the whole treee) of the required type: */ 463 m_pInvisibleRootNode->searchForNodes(QString(), iItemSearchFlags, allNodes);492 m_pInvisibleRootNode->searchForNodes(QString(), UIChooserItemSearchFlag_Machine, allNodes); 464 493 465 494 /* Reset the disabled flag of the node items first. */ … … 470 499 pNode->setDisabled(false); 471 500 } 472 473 if (strSearchTerm.isEmpty()) 474 return; 475 476 QList<UIChooserNode*> matchedNodes; 477 m_pInvisibleRootNode->searchForNodes(strSearchTerm, iItemSearchFlags, matchedNodes); 478 479 foreach (UIChooserNode* pNode, allNodes) 480 { 481 if (!pNode) 482 continue; 483 pNode->setDisabled(!matchedNodes.contains(pNode)); 484 } 501 /* Reset the search result relate data: */ 502 m_searchResults.clear(); 503 m_iCurrentScrolledIndex = -1; 504 return allNodes; 505 } 506 507 void UIChooserModel::scrollToSearchResult(bool fIsNext) 508 { 509 if (m_searchResults.isEmpty()) 510 { 511 m_iCurrentScrolledIndex = -1; 512 if (view()) 513 view()->setSearchResultsCount(m_searchResults.size(), m_iCurrentScrolledIndex); 514 return; 515 } 516 517 if (fIsNext) 518 { 519 if (++m_iCurrentScrolledIndex >= m_searchResults.size()) 520 m_iCurrentScrolledIndex = 0; 521 } 522 else 523 { 524 if (m_iCurrentScrolledIndex < 0) 525 m_iCurrentScrolledIndex = m_searchResults.size() - 1; 526 } 527 528 if (m_searchResults.at(m_iCurrentScrolledIndex)) 529 { 530 UIChooserItem *pItem = m_searchResults.at(m_iCurrentScrolledIndex)->item(); 531 if (pItem) 532 { 533 pItem->makeSureItsVisible(); 534 } 535 } 536 537 538 /* Update the search widget's match count(s): */ 539 if (view()) 540 view()->setSearchResultsCount(m_searchResults.size(), m_iCurrentScrolledIndex); 541 485 542 } 486 543 … … 619 676 void UIChooserModel::updateLayout() 620 677 { 678 if (!view() || !root()) 679 return; 680 621 681 /* Initialize variables: */ 622 const QSize viewportSize = scene()->views()[0]->size();682 const QSize viewportSize = view()->size(); 623 683 const int iViewportWidth = viewportSize.width(); 624 684 const int iViewportHeight = viewportSize.height(); … … 814 874 void UIChooserModel::sltShowHideSearchWidget() 815 875 { 816 UIChooserView *pChooserView = qobject_cast<UIChooserView*>(scene()->views()[0]);876 UIChooserView *pChooserView = view(); 817 877 if (!pChooserView) 818 878 return; … … 1182 1242 1183 1243 /* Get view/scrollbar: */ 1184 QGraphicsView *pView = scene()->views()[0];1244 QGraphicsView *pView = view(); 1185 1245 QScrollBar *pVerticalScrollBar = pView->verticalScrollBar(); 1186 1246 … … 1947 2007 /* Install root as event-filter for scene view, 1948 2008 * we need QEvent::Scroll events from it: */ 1949 root()->installEventFilterHelper( scene()->views()[0]);2009 root()->installEventFilterHelper(view()); 1950 2010 } 1951 2011 … … 2049 2109 2050 2110 /* Get view: */ 2051 QGraphicsView *pView = scene()->views()[0];2111 QGraphicsView *pView = view(); 2052 2112 2053 2113 /* Check scroll-area: */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h
r77683 r77723 42 42 class UIChooserItem; 43 43 class UIChooserNode; 44 class UIChooserView; 44 45 class UIVirtualMachineItem; 45 46 class CMachine; … … 191 192 /** Performs a search starting from the m_pInvisibleRootNode. */ 192 193 void performSearch(const QString &strSearchTerm, int iItemSearchFlags); 194 /** Clean the search result data members and disables item's visual effects. Also returns a list of 195 * all nodes which may be utilized by the calling code. */ 196 QList<UIChooserNode*> resetSearch(); 197 void scrollToSearchResult(bool fIsNext); 193 198 /** @} */ 194 199 … … 359 364 /** Popups context-menu of certain @a enmType in specified @a point. */ 360 365 void popupContextMenu(UIGraphicsSelectorContextMenuType enmType, QPoint point); 366 /** Returns the reference of the first view of the scene(). */ 367 UIChooserView *view(); 361 368 /** @} */ 362 369 … … 464 471 /** @} */ 465 472 473 /** @name Virtual Machine/Group search stuff. 474 * @{ */ 475 /** Stores the results of the current search. */ 476 QList<UIChooserNode*> m_searchResults; 477 /** Stores the index (within the m_searchResults) of the currently scrolled item. */ 478 int m_iCurrentScrolledIndex; 479 /** @} */ 480 466 481 /** @name Children stuff. 467 482 * @{ */ -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.cpp
r77683 r77723 21 21 /* GUI includes: */ 22 22 #include "QILineEdit.h" 23 #include "QIToolButton.h" 23 24 #include "UIChooserDefs.h" 24 25 #include "UIChooserSearchWidget.h" 26 #include "UIIconPool.h" 27 #include "UISearchLineEdit.h" 25 28 26 29 UIChooserSearchWidget::UIChooserSearchWidget(QWidget *pParent) … … 28 31 , m_pLineEdit(0) 29 32 , m_pMainLayout(0) 30 33 , m_pScrollToNextMatchButton(0) 34 , m_pScrollToPreviousMatchButton(0) 31 35 { 32 36 prepareWidgets(); 33 37 prepareConnections(); 38 } 39 40 void UIChooserSearchWidget::setMatchCount(int iMatchCount) 41 { 42 if (!m_pLineEdit) 43 return; 44 m_pLineEdit->setMatchCount(iMatchCount); 45 } 46 47 void UIChooserSearchWidget::setScroolToIndex(int iScrollToIndex) 48 { 49 if (!m_pLineEdit) 50 return; 51 m_pLineEdit->setScroolToIndex(iScrollToIndex); 34 52 } 35 53 … … 41 59 m_pMainLayout->setSpacing(2); 42 60 m_pMainLayout->setContentsMargins(0, 0, 0, 0); 43 m_pLineEdit = new QILineEdit;61 m_pLineEdit = new UISearchLineEdit; 44 62 if (m_pLineEdit) 45 63 { 46 64 m_pMainLayout->addWidget(m_pLineEdit); 65 m_pLineEdit->installEventFilter(this); 66 } 67 68 m_pScrollToPreviousMatchButton = new QIToolButton; 69 if (m_pScrollToPreviousMatchButton) 70 { 71 m_pScrollToPreviousMatchButton->setIcon(UIIconPool::iconSet(":/log_viewer_search_backward_16px.png", ":/log_viewer_search_backward_disabled_16px.png")); 72 m_pMainLayout->addWidget(m_pScrollToPreviousMatchButton); 73 } 74 m_pScrollToNextMatchButton = new QIToolButton; 75 if (m_pScrollToNextMatchButton) 76 { 77 m_pScrollToNextMatchButton->setIcon(UIIconPool::iconSet(":/log_viewer_search_forward_16px.png", ":/log_viewer_search_forward_disabled_16px.png")); 78 m_pMainLayout->addWidget(m_pScrollToNextMatchButton); 47 79 } 48 80 … … 57 89 this, &UIChooserSearchWidget::sltHandleSearchTermChange); 58 90 } 91 if (m_pScrollToPreviousMatchButton) 92 connect(m_pScrollToPreviousMatchButton, &QIToolButton::clicked, this, &UIChooserSearchWidget::sltHandleScroolToButtonClick); 93 if (m_pScrollToNextMatchButton) 94 connect(m_pScrollToNextMatchButton, &QIToolButton::clicked, this, &UIChooserSearchWidget::sltHandleScroolToButtonClick); 59 95 } 60 96 … … 66 102 } 67 103 104 void UIChooserSearchWidget::hideEvent(QHideEvent *pEvent) 105 { 106 Q_UNUSED(pEvent); 107 if (m_pLineEdit) 108 m_pLineEdit->clear(); 109 } 110 68 111 void UIChooserSearchWidget::retranslateUi() 69 112 { 113 } 114 115 bool UIChooserSearchWidget::eventFilter(QObject *pWatched, QEvent *pEvent) 116 { 117 Q_UNUSED(pWatched); 118 if (pEvent->type() == QEvent::KeyPress) 119 { 120 QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent); 121 if (pKeyEvent) 122 { 123 if (pKeyEvent->key() == Qt::Key_Escape) 124 emit sigToggleVisibility(false); 125 } 126 } 127 return false; 70 128 } 71 129 … … 74 132 emit sigRedoSearch(strSearchTerm, UIChooserItemSearchFlag_Machine); 75 133 } 134 135 void UIChooserSearchWidget::sltHandleScroolToButtonClick() 136 { 137 if (sender() == m_pScrollToNextMatchButton) 138 emit sigScrollToMatch(true); 139 else if (sender() == m_pScrollToPreviousMatchButton) 140 emit sigScrollToMatch(false); 141 } -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.h
r77683 r77723 31 31 class QHBoxLayout; 32 32 class QILineEdit; 33 class QIToolButton; 34 class UISearchLineEdit; 33 35 34 36 /** QWidget extension used as virtual machine search widget in the VM Chooser-pane. */ … … 40 42 41 43 void sigRedoSearch(const QString &strSearchTerm, int iItemSearchFlags); 44 /** Is being signalled as next/prev tool buttons are pressed. @a fIsNext is true 45 * for the next and false for the previous case. */ 46 void sigScrollToMatch(bool fIsNext); 47 /** Is used for signalling show/hide event from this to parent. */ 48 void sigToggleVisibility(bool fIsVisible); 42 49 43 50 public: 44 51 45 52 UIChooserSearchWidget(QWidget *pParent); 53 void setMatchCount(int iMatchCount); 54 void setScroolToIndex(int iScrollToIndex); 46 55 47 56 protected: 48 57 49 void showEvent(QShowEvent *pEvent); 58 virtual void showEvent(QShowEvent *pEvent) /* override */; 59 virtual void hideEvent(QHideEvent *pEvent) /* override */; 50 60 virtual void retranslateUi() /* override */; 61 virtual bool eventFilter(QObject *pWatched, QEvent *pEvent) /* override */; 51 62 52 63 public slots: … … 55 66 56 67 void sltHandleSearchTermChange(const QString &strSearchTerm); 68 void sltHandleScroolToButtonClick(); 57 69 58 70 private: … … 61 73 void prepareConnections(); 62 74 63 QILineEdit *m_pLineEdit; 64 QHBoxLayout *m_pMainLayout; 75 UISearchLineEdit *m_pLineEdit; 76 QHBoxLayout *m_pMainLayout; 77 QIToolButton *m_pScrollToNextMatchButton; 78 QIToolButton *m_pScrollToPreviousMatchButton; 65 79 }; 66 80 -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.cpp
r77686 r77723 108 108 m_pSearchWidget->setVisible(!m_pSearchWidget->isVisible()); 109 109 if (m_pSearchWidget->isVisible()) 110 updateSearchWidget(); 110 updateSearchWidgetGeometry(); 111 } 112 113 void UIChooserView::setSearchResultsCount(int iTotalMacthCount, int iCurrentlyScrolledItemIndex) 114 { 115 if (!m_pSearchWidget) 116 return; 117 m_pSearchWidget->setMatchCount(iTotalMacthCount); 118 m_pSearchWidget->setScroolToIndex(iCurrentlyScrolledItemIndex); 111 119 } 112 120 … … 135 143 if (!pModel) 136 144 return; 137 138 145 pModel->performSearch(strSearchTerm, iItemSearchFlags); 146 } 147 148 void UIChooserView::sltHandleScrollToSearchResult(bool fIsNext) 149 { 150 UIChooserModel *pModel = m_pChooser->model(); 151 if (!pModel) 152 return; 153 pModel->scrollToSearchResult(fIsNext); 154 } 155 156 void UIChooserView::sltHandleSearchWidgetVisibilityToggle(bool fIsVisible) 157 { 158 if (!m_pSearchWidget) 159 return; 160 if (m_pSearchWidget->isVisible() == fIsVisible) 161 return; 162 m_pSearchWidget->setVisible(fIsVisible); 163 UIChooserModel *pModel = m_pChooser->model(); 164 if (!pModel) 165 return; 166 pModel->resetSearch(); 139 167 } 140 168 … … 169 197 connect(m_pSearchWidget, &UIChooserSearchWidget::sigRedoSearch, 170 198 this, &UIChooserView::sltRedoSearch); 199 connect(m_pSearchWidget, &UIChooserSearchWidget::sigScrollToMatch, 200 this, &UIChooserView::sltHandleScrollToSearchResult); 201 connect(m_pSearchWidget, &UIChooserSearchWidget::sigToggleVisibility, 202 this, &UIChooserView::sltHandleSearchWidgetVisibilityToggle); 171 203 172 204 /* Update scene-rect: */ … … 174 206 175 207 /* Update the location and size of the search widget: */ 176 updateSearchWidget ();208 updateSearchWidgetGeometry(); 177 209 178 210 /* Apply language settings: */ … … 198 230 /* Update scene-rect: */ 199 231 updateSceneRect(); 200 updateSearchWidget ();232 updateSearchWidgetGeometry(); 201 233 } 202 234 … … 206 238 } 207 239 208 void UIChooserView::updateSearchWidget ()240 void UIChooserView::updateSearchWidgetGeometry() 209 241 { 210 242 if (!m_pSearchWidget || !m_pSearchWidget->isVisible()) -
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserView.h
r77683 r77723 50 50 /** Returns the chooser reference. */ 51 51 UIChooser *chooser() const { return m_pChooser; } 52 /** @} */ 53 54 /** @name Virtual Machine search stuff. 55 * @{ */ 52 56 /** Shows/hides machine search widget. */ 53 57 void toggleSearchWidget(); 58 /** Updates the search widget's counts. */ 59 void setSearchResultsCount(int iTotalMacthCount, int iCurrentlyScrolledItemIndex); 54 60 /** @} */ 55 61 … … 75 81 private slots: 76 82 83 /** Is connected to search widget's signal for a new search. */ 77 84 void sltRedoSearch(const QString &strSearchTerm, int iItemSearchFlags); 85 /** Is connected to search widget's scroll to next/prev search result signal. */ 86 void sltHandleScrollToSearchResult(bool fIsNext); 87 void sltHandleSearchWidgetVisibilityToggle(bool fIsVisible); 78 88 79 89 private: … … 91 101 /** Updates scene rectangle. */ 92 102 void updateSceneRect(); 93 /** Updates search widget's geometry. */94 void updateSearchWidget();95 103 /** @} */ 96 104 105 /** @name Virtual Machine search stuff. 106 * @{ */ 107 /** Updates search widget's geometry. */ 108 void updateSearchWidgetGeometry(); 109 /** @} */ 97 110 98 111 /** @name General stuff. -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp
r77702 r77723 34 34 QLineEdit::paintEvent(pEvent); 35 35 36 /* No search terms. no search. nothing to show here . mone along please: */36 /* No search terms. no search. nothing to show here: */ 37 37 if (text().isEmpty()) 38 38 return; 39 39 40 /* Draw the total match count and the current scrolled item's index on the right hand side of the line edit: */ 40 41 QPainter painter(this); 41 42 QFont pfont = font(); … … 49 50 int iTopMargin = (height() - textSize.height()) / 2; 50 51 int iRightMargin = iTopMargin; 51 52 52 53 53 QColor fontColor(Qt::darkGray); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.h
r77702 r77723 32 32 * mostly used for entering a search term and then label show total number of matched items 33 33 * and currently selected, scrolled item. */ 34 class SHARED_LIBRARY_STUFF 35 UISearchLineEdit : public QLineEdit 34 class SHARED_LIBRARY_STUFF UISearchLineEdit : public QLineEdit 36 35 { 37 36 … … 50 49 private: 51 50 51 /** Stores the total number of matched items. */ 52 52 int m_iMatchCount; 53 /** Stores the index of the currently scrolled/made-visible item withing the list of search results. 54 * Must be smaller that or equal to m_iMatchCount. */ 53 55 int m_iScrollToIndex; 54 56 };
Note:
See TracChangeset
for help on using the changeset viewer.