Changeset 77321 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 14, 2019 7:56:39 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 128850
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium/viso
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.cpp
r77309 r77321 102 102 bool UILocationSelector::eventFilter(QObject *pObj, QEvent *pEvent) 103 103 { 104 if (pObj == m_pLineEdit && pEvent->type() == QEvent::MouseButtonPress) 105 { 106 emit sigExpandCollapseTreeView(); 104 if (pObj == m_pLineEdit) 105 { 106 if(pEvent->type() == QEvent::MouseButtonPress) 107 { 108 QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent); 109 if (pMouseEvent && pMouseEvent->button() == Qt::LeftButton) 110 emit sigExpandCollapseTreeView(); 111 } 107 112 } 108 113 /* Pass the events to event system for further processing: */ 109 114 return false; 110 115 } 116 111 117 void UILocationSelector::prepareWidget() 112 118 { … … 155 161 } 156 162 163 bool UIVisoBrowserBase::isTreeViewVisible() const 164 { 165 if (!m_pTreeView) 166 return false; 167 return m_pTreeView->isVisible(); 168 } 169 170 void UIVisoBrowserBase::hideTreeView() 171 { 172 if (isTreeViewVisible()) 173 sltExpandCollapseTreeView(); 174 } 175 157 176 void UIVisoBrowserBase::prepareObjects() 158 177 { … … 179 198 m_pTreeView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); 180 199 m_pTreeView->setFrameStyle(QFrame::Panel | QFrame::Plain); 200 m_pTreeView->installEventFilter(this); 181 201 } 182 202 … … 217 237 } 218 238 239 /* Close the tree view when it recieves focus-out and enter key press event: */ 240 bool UIVisoBrowserBase::eventFilter(QObject *pObj, QEvent *pEvent) 241 { 242 if (pObj == m_pTreeView) 243 { 244 if(pEvent->type() == QEvent::KeyPress) 245 { 246 QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent); 247 if (pKeyEvent && 248 (pKeyEvent->key() == Qt::Key_Return || 249 pKeyEvent->key() == Qt::Key_Enter)) 250 { 251 sltExpandCollapseTreeView(); 252 } 253 } 254 else if (pEvent->type() == QEvent::FocusOut) 255 { 256 sltExpandCollapseTreeView(); 257 } 258 } 259 return false; 260 } 261 262 void UIVisoBrowserBase::keyPressEvent(QKeyEvent *pEvent) 263 { 264 if (pEvent->key() == Qt::Key_Escape) 265 { 266 if (m_pTreeView->isVisible()) 267 updateTreeViewGeometry(false); 268 269 } 270 QIWithRetranslateUI<QWidget>::keyPressEvent(pEvent); 271 } 272 273 219 274 void UIVisoBrowserBase::sltHandleTableViewItemDoubleClick(const QModelIndex &index) 220 275 { … … 232 287 } 233 288 234 235 289 void UIVisoBrowserBase::sltHandleTreeItemClicked(const QModelIndex &modelIndex) 236 290 { … … 239 293 m_pTreeView->setExpanded(modelIndex, true); 240 294 m_pTreeView->hide(); 295 emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible()); 241 296 } 242 297 … … 256 311 { 257 312 m_pTreeView->hide(); 258 return; 313 emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible()); 314 m_pTreeView->clearFocus(); 315 return; 259 316 } 260 317 if (!m_pLocationSelector) … … 264 321 int ix = m_pLocationSelector->x(); 265 322 int iWidth = m_pLocationSelector->lineEditWidth(); 266 267 323 m_pTreeView-> move(ix, iy); 268 324 m_pTreeView->raise(); 269 325 m_pTreeView->resize(iWidth, 0.75 * height()); 270 326 m_pTreeView->show(); 271 272 //m_pTreeView->scrollTo(m_pTreeView->currentIndex(), QAbstractItemView::PositionAtTop);327 m_pTreeView->setFocus(); 328 emit sigTreeViewVisibilityChanged(m_pTreeView->isVisible()); 273 329 } 274 330 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoBrowserBase.h
r77308 r77321 45 45 Q_OBJECT; 46 46 47 signals: 48 49 void sigTreeViewVisibilityChanged(bool fVisible); 50 47 51 public: 48 52 /** @p pMenu is the pointer to the menu related to this browser widget. … … 51 55 ~UIVisoBrowserBase(); 52 56 virtual void showHideHiddenObjects(bool bShow) = 0; 57 /* Returns true if tree view is currently visible: */ 58 bool isTreeViewVisible() const; 59 void hideTreeView(); 53 60 54 61 public slots: … … 68 75 69 76 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 77 virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */; 78 virtual void keyPressEvent(QKeyEvent *pEvent) /* override */; 70 79 71 80 QTreeView *m_pTreeView; … … 73 82 QMenu *m_pMenu; 74 83 QGridLayout *m_pMainLayout; 75 76 private:77 84 78 85 private slots: -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.cpp
r77308 r77321 586 586 { 587 587 QString strPath = pItem->data(UICustomFileSystemModelColumn_Path).toString(); 588 if (strPath == QDir::fromNativeSeparators("/"))589 strPath += m_strVisoName;590 588 updateLocationSelectorText(strPath); 591 589 } -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.cpp
r77308 r77321 120 120 } 121 121 122 // bool UIVisoCreator::event(QEvent *pEvent) 123 // { 124 125 // if (pEvent->type() == QEvent::KeyPress) 126 // { 127 // printf("key press %d\n", pEvent->type()); 128 // } 129 // return false; 130 // } 131 132 // bool UIVisoCreator::eventFilter(QObject *, QEvent *pEvent) 133 // { 134 // if (pEvent->type() == QEvent::KeyPress) 135 // { 136 // printf("key press in filter %d\n", pEvent->type()); 137 // } 138 139 // return false; 140 // } 141 122 142 void UIVisoCreator::sltHandleAddObjectsToViso(QStringList pathList) 123 143 { … … 174 194 { 175 195 hidePanel(pPanel); 196 } 197 198 void UIVisoCreator::sltHandleBrowserTreeViewVisibilityChanged(bool fVisible) 199 { 200 Q_UNUSED(fVisible); 201 manageEscapeShortCut(); 176 202 } 177 203 … … 220 246 if (m_pActionOptions) 221 247 m_pToolBar->addAction(m_pActionOptions); 222 223 248 m_pMainLayout->addWidget(m_pToolBar); 224 249 } … … 240 265 connect(m_pHostBrowser, &UIVisoHostBrowser::sigAddObjectsToViso, 241 266 this, &UIVisoCreator::sltHandleAddObjectsToViso); 267 connect(m_pHostBrowser, &UIVisoHostBrowser::sigTreeViewVisibilityChanged, 268 this, &UIVisoCreator::sltHandleBrowserTreeViewVisibilityChanged); 242 269 } 243 270 … … 275 302 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape); 276 303 m_pMainLayout->addWidget(m_pButtonBox); 277 278 304 } 279 305 retranslateUi(); … … 365 391 } 366 392 367 368 369 393 void UIVisoCreator::manageEscapeShortCut() 370 394 { 395 /* Take the escape key from m_pButtonBox and from the panels in case treeview(s) in 396 host and/or content browser is open. We use the escape key to close those first: */ 397 if ((m_pHostBrowser && m_pHostBrowser->isTreeViewVisible()) || 398 (m_pVisoBrowser && m_pVisoBrowser->isTreeViewVisible())) 399 { 400 if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel)) 401 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence()); 402 for (int i = 0; i < m_visiblePanelsList.size(); ++i) 403 m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence()); 404 return; 405 } 406 371 407 /* if there are no visible panels then assign esc. key to cancel button of the button box: */ 372 408 if (m_visiblePanelsList.isEmpty()) … … 382 418 panel which made visible latest */ 383 419 for (int i = 0; i < m_visiblePanelsList.size() - 1; ++i) 384 {385 420 m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence()); 386 }387 421 m_visiblePanelsList.back()->setCloseButtonShortCut(QKeySequence(Qt::Key_Escape)); 388 422 } -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h
r77308 r77321 70 70 protected: 71 71 72 void retranslateUi(); 72 virtual void retranslateUi() /* override */; 73 // virtual bool event(QEvent *pEvent) /* override */; 74 // virtual bool eventFilter(QObject *pObj, QEvent *pEvent) /* override */; 73 75 74 76 private slots: … … 80 82 void sltHandleShowHiddenObjectsChange(bool fShow); 81 83 void sltHandleHidePanel(UIDialogPanel *pPanel); 84 void sltHandleBrowserTreeViewVisibilityChanged(bool fVisible); 82 85 83 86 private: … … 108 111 /** Makes sure escape key is assigned to only a single widget. This is done by checking 109 112 several things in the following order: 113 - when tree views of browser panes are visible esc. key used to close those. thus it is taken from the dialog and panels 110 114 - when there are no more panels visible assign it to the parent dialog 111 115 - grab it from the dialog as soon as a panel becomes visible again
Note:
See TracChangeset
for help on using the changeset viewer.