Changeset 86812 in vbox
- Timestamp:
- Nov 5, 2020 1:50:30 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141253
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc
r86735 r86812 163 163 <file alias="drag_drop_16px.png">images/drag_drop_16px.png</file> 164 164 <file alias="drag_drop_disabled_16px.png">images/drag_drop_disabled_16px.png</file> 165 <file alias="drag_move_16px.png">images/drag_move_16px.png</file> 165 166 <file alias="edata_add_16px.png">images/edata_add_16px.png</file> 166 167 <file alias="edata_add_24px.png">images/edata_add_24px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp
r86807 r86812 30 30 #include <QtHelp/QHelpSearchResultWidget> 31 31 #endif 32 #include <QLabel> 32 33 #include <QMenu> 33 34 #include <QMouseEvent> 35 #include <QPixmap> 34 36 #include <QScrollBar> 35 37 #include <QSpacerItem> … … 43 45 44 46 /* GUI includes: */ 47 #include "UICommon.h" 45 48 #include "QIFileDialog.h" 46 49 #include "QITabWidget.h" 50 #include "QIToolBar.h" 51 #include "QIToolButton.h" 47 52 #include "UIActionPool.h" 48 53 #include "UIExtraDataManager.h" 54 #include "UIHelpBrowserWidget.h" 49 55 #include "UIIconPool.h" 50 56 #include "UIMessageCenter.h" 51 #include "UIHelpBrowserWidget.h" 52 #include "QITabWidget.h" 53 #include "QIToolBar.h" 54 #include "UICommon.h" 55 #include "UIIconPool.h" 57 #include "UISearchLineEdit.h" 58 56 59 57 60 /* COM includes: */ … … 63 66 { 64 67 HelpBrowserTabs_TOC = 0, 65 HelpBrowserTabs_Index,66 68 HelpBrowserTabs_Search, 67 69 HelpBrowserTabs_Bookmarks, 70 HelpBrowserTabs_Index, 68 71 HelpBrowserTabs_Max 69 72 }; 70 73 Q_DECLARE_METATYPE(HelpBrowserTabs); 71 74 75 76 /********************************************************************************************************************************* 77 * UIFindInPageWidget definition. * 78 *********************************************************************************************************************************/ 79 class UIFindInPageWidget : public QIWithRetranslateUI<QWidget> 80 { 81 82 Q_OBJECT; 83 84 signals: 85 86 void sigDragging(const QPoint &delta); 87 88 public: 89 90 UIFindInPageWidget(QWidget *pParent = 0); 91 92 protected: 93 94 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */; 95 96 private: 97 98 void prepare(); 99 void retranslateUi(); 100 UISearchLineEdit *m_pSearchLineEdit; 101 QIToolButton *m_pDownButton; 102 QIToolButton *m_pUpButton; 103 QLabel *m_pDragMoveLabel; 104 QPoint m_previousMousePosition; 105 }; 72 106 73 107 /********************************************************************************************************************************* … … 96 130 97 131 void contextMenuEvent(QContextMenuEvent *event) /* override */; 132 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 133 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 98 134 99 135 private slots: 100 136 101 137 void sltHandleOpenInNewTab(); 138 void sltHandleFindWidgetDrag(const QPoint &delta); 102 139 103 140 private: … … 105 142 void retranslateUi(); 106 143 const QHelpEngine* m_pHelpEngine; 144 UIFindInPageWidget *m_pFindInPageWidget; 145 /* Initilized as false and set to true once the find widget is positioned during first resize. */ 146 bool m_fFindWidgetPositioned; 107 147 }; 108 148 … … 129 169 void setSource(const QUrl &url); 130 170 QString documentTitle() const; 171 void setToolBarVisible(bool fVisible); 131 172 132 173 private slots: … … 151 192 QAction *m_pBackwardAction; 152 193 QAction *m_pAddBookmarkAction; 194 QAction *m_pFindInPageAction; 153 195 154 196 QVBoxLayout *m_pMainLayout; 155 197 QIToolBar *m_pToolBar; 156 QComboBox *m_pAddressBar;198 QComboBox *m_pAddressBar; 157 199 UIHelpBrowserViewer *m_pContentViewer; 158 200 const QHelpEngine* m_pHelpEngine; … … 185 227 /* Return the list of urls of all open tabs as QStringList. */ 186 228 QStringList tabUrlList(); 229 void setToolBarVisible(bool fVisible); 187 230 188 231 private slots: … … 205 248 206 249 /********************************************************************************************************************************* 250 * UIFindInPageWidget implementation. * 251 *********************************************************************************************************************************/ 252 UIFindInPageWidget::UIFindInPageWidget(QWidget *pParent /* = 0 */) 253 : QIWithRetranslateUI<QWidget>(pParent) 254 , m_pSearchLineEdit(0) 255 , m_pDownButton(0) 256 , m_pUpButton(0) 257 , m_previousMousePosition(-1, -1) 258 { 259 prepare(); 260 } 261 262 bool UIFindInPageWidget::eventFilter(QObject *pObject, QEvent *pEvent) 263 { 264 if (pObject == m_pDragMoveLabel) 265 { 266 if (pEvent->type() == QEvent::MouseMove) 267 { 268 QMouseEvent *pMouseEvent = static_cast<QMouseEvent*>(pEvent); 269 if (pMouseEvent->buttons() == Qt::LeftButton) 270 { 271 if (m_previousMousePosition != QPoint(-1, -1)) 272 emit sigDragging(pMouseEvent->globalPos() - m_previousMousePosition); 273 m_previousMousePosition = pMouseEvent->globalPos(); 274 } 275 } 276 else if (pEvent->type() == QEvent::MouseButtonRelease) 277 m_previousMousePosition = QPoint(-1, -1); 278 } 279 return QIWithRetranslateUI<QWidget>::eventFilter(pObject, pEvent); 280 } 281 282 void UIFindInPageWidget::prepare() 283 { 284 setAutoFillBackground(true); 285 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); 286 287 QHBoxLayout *pLayout = new QHBoxLayout(this); 288 m_pSearchLineEdit = new UISearchLineEdit; 289 AssertReturnVoid(pLayout && m_pSearchLineEdit); 290 291 pLayout->setContentsMargins(0, 0, 0, 0); 292 pLayout->setContentsMargins(0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 293 0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin), 294 0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin), 295 0.5 * qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); 296 m_pDragMoveLabel = new QLabel; 297 AssertReturnVoid(m_pDragMoveLabel); 298 m_pDragMoveLabel->installEventFilter(this); 299 m_pDragMoveLabel->setPixmap(QPixmap(":/drag_move_16px.png")); 300 pLayout->addWidget(m_pDragMoveLabel); 301 302 303 pLayout->setSpacing(0); 304 pLayout->addWidget(m_pSearchLineEdit); 305 306 m_pUpButton = new QIToolButton; 307 m_pDownButton = new QIToolButton; 308 309 pLayout->addWidget(m_pUpButton); 310 pLayout->addWidget(m_pDownButton); 311 312 m_pUpButton->setIcon(UIIconPool::iconSet(":/arrow_up_10px.png")); 313 m_pDownButton->setIcon(UIIconPool::iconSet(":/arrow_down_10px.png")); 314 315 } 316 317 void UIFindInPageWidget::retranslateUi() 318 { 319 } 320 321 /********************************************************************************************************************************* 207 322 * UIHelpBrowserTab implementation. * 208 323 *********************************************************************************************************************************/ … … 215 330 , m_pBackwardAction(0) 216 331 , m_pAddBookmarkAction(0) 332 , m_pFindInPageAction(0) 217 333 , m_pMainLayout(0) 218 334 , m_pToolBar(0) … … 252 368 return QString(); 253 369 return m_pContentViewer->documentTitle(); 370 } 371 372 void UIHelpBrowserTab::setToolBarVisible(bool fVisible) 373 { 374 if (m_pToolBar) 375 m_pToolBar->setVisible(fVisible); 376 if (m_pAddressBar) 377 m_pAddressBar->setVisible(fVisible); 254 378 } 255 379 … … 293 417 m_pAddBookmarkAction = 294 418 new QAction(UIIconPool::iconSet(":/help_browser_add_bookmark.png"), QString(), this); 419 m_pFindInPageAction = 420 new QAction(UIIconPool::iconSet(":/help_browser_search.png"), QString(), this); 295 421 296 422 connect(m_pHomeAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleHomeAction); … … 308 434 m_pToolBar->addAction(m_pHomeAction); 309 435 m_pToolBar->addAction(m_pAddBookmarkAction); 436 m_pToolBar->addAction(m_pFindInPageAction); 310 437 311 438 m_pAddressBar = new QComboBox(); … … 427 554 :QIWithRetranslateUI<QTextBrowser>(pParent) 428 555 , m_pHelpEngine(pHelpEngine) 429 { 430 Q_UNUSED(pHelpEngine); 556 , m_pFindInPageWidget(new UIFindInPageWidget(this)) 557 , m_fFindWidgetPositioned(false) 558 { 559 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigDragging, 560 this, &UIHelpBrowserViewer::sltHandleFindWidgetDrag); 431 561 retranslateUi(); 432 562 } … … 471 601 delete pMenu; 472 602 } 603 604 void UIHelpBrowserViewer::paintEvent(QPaintEvent *pEvent) 605 { 606 // if (m_pFindInPageWidget) 607 // { 608 // m_pFindInPageWidget->show(); 609 // m_pFindInPageWidget->update(); 610 // } 611 QIWithRetranslateUI<QTextBrowser>::paintEvent(pEvent); 612 } 613 614 void UIHelpBrowserViewer::resizeEvent(QResizeEvent *pEvent) 615 { 616 printf("resize %d\n", width()); 617 if (m_pFindInPageWidget && !m_fFindWidgetPositioned) 618 { 619 m_pFindInPageWidget->move(width() - m_pFindInPageWidget->width() - 50, 10); 620 m_fFindWidgetPositioned = true; 621 } 622 QIWithRetranslateUI<QTextBrowser>::resizeEvent(pEvent); 623 } 624 473 625 474 626 void UIHelpBrowserViewer::retranslateUi() … … 486 638 } 487 639 640 void UIHelpBrowserViewer::sltHandleFindWidgetDrag(const QPoint &delta) 641 { 642 if (!m_pFindInPageWidget) 643 return; 644 QRect geo = m_pFindInPageWidget->geometry(); 645 geo.translate(delta); 646 int margin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin); 647 bool fIn = true; 648 if (geo.left() < margin || geo.top() < margin) 649 fIn = false; 650 if (geo.right() > width() - margin || geo.bottom() > height() - margin) 651 fIn = false; 652 if (fIn) 653 m_pFindInPageWidget->move(m_pFindInPageWidget->pos() + delta); 654 update(); 655 } 488 656 489 657 /********************************************************************************************************************************* … … 559 727 } 560 728 return list; 729 } 730 731 void UIHelpBrowserTabManager::setToolBarVisible(bool fVisible) 732 { 733 for (int i = 0; i < count(); ++i) 734 { 735 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i)); 736 if (!pTab) 737 continue; 738 pTab->setToolBarVisible(fVisible); 739 } 561 740 } 562 741 … … 636 815 , m_pHelpEngine(0) 637 816 , m_pSplitter(0) 638 , m_pMenu(0) 817 , m_pFileMenu(0) 818 , m_pViewMenu(0) 639 819 , m_pContentWidget(0) 640 820 , m_pIndexWidget(0) … … 663 843 QMenu *UIHelpBrowserWidget::menu() const 664 844 { 665 return m_p Menu;845 return m_pViewMenu; 666 846 } 667 847 … … 764 944 AssertReturnVoid(m_pSearchQueryWidget && m_pSearchResultWidget); 765 945 m_pSearchResultWidget->setContextMenuPolicy(Qt::CustomContextMenu); 946 m_pSearchQueryWidget->setCompactMode(false); 766 947 767 948 QVBoxLayout *pSearchLayout = new QVBoxLayout(m_pSearchContainerWidget); … … 827 1008 void UIHelpBrowserWidget::prepareMenu() 828 1009 { 829 m_pMenu = new QMenu(tr("View"), this); 830 AssertReturnVoid(m_pMenu); 831 832 m_pMenu->addAction(m_pShowHideSideBarAction); 833 m_pMenu->addAction(m_pShowHideToolBarAction); 1010 m_pFileMenu = new QMenu(tr("File"), this); 1011 m_pViewMenu = new QMenu(tr("View"), this); 1012 AssertReturnVoid(m_pViewMenu); 1013 1014 m_pFileMenu->addAction("asd"); 1015 m_pViewMenu->addAction(m_pShowHideSideBarAction); 1016 m_pViewMenu->addAction(m_pShowHideToolBarAction); 834 1017 835 1018 } … … 971 1154 void UIHelpBrowserWidget::sltHandleToolBarVisibility(bool fToggled) 972 1155 { 973 if (m_pT oolBar)974 m_pT oolBar->setVisible(fToggled);1156 if (m_pTabManager) 1157 m_pTabManager->setToolBarVisible(fToggled); 975 1158 } 976 1159 … … 1060 1243 return; 1061 1244 QPoint browserPos = browser->mapFromGlobal(m_pSearchResultWidget->mapToGlobal(pos)); 1062 printf("pos %d %d\n", pos.x(), pos.y());1063 1245 url = browser->anchorAt(browserPos); 1064 1246 } -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h
r86807 r86812 150 150 QHelpEngine *m_pHelpEngine; 151 151 QSplitter *m_pSplitter; 152 QMenu *m_pMenu; 152 QMenu *m_pFileMenu; 153 QMenu *m_pViewMenu; 153 154 QHelpContentWidget *m_pContentWidget; 154 155 QHelpIndexWidget *m_pIndexWidget;
Note:
See TracChangeset
for help on using the changeset viewer.