Changeset 86861 in vbox
- Timestamp:
- Nov 11, 2020 2:15:22 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
-
VirtualBox1.qrc (modified) (1 diff)
-
src/helpbrowser/UIHelpBrowserWidget.cpp (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc
r86812 r86861 380 380 <file alias="hd_warning_16px.png">images/hd_warning_16px.png</file> 381 381 <file alias="hd_write_16px.png">images/hd_write_16px.png</file> 382 <file alias="help_browser_plus_32px.png">images/help_browser_plus_32px.png</file> 383 <file alias="help_browser_minus_32px.png">images/help_browser_minus_32px.png</file> 384 <file alias="help_browser_reset_32px.png">images/help_browser_reset_32px.png</file> 382 385 <file alias="help_browser_add_bookmark.png">images/help_browser_add_bookmark.png</file> 383 386 <file alias="help_browser_backward_32px.png">images/help_browser_backward_32px.png</file> -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp
r86844 r86861 34 34 #include <QMenu> 35 35 #include <QMouseEvent> 36 #include <QPainter> 36 37 #include <QPixmap> 37 38 #include <QtPrintSupport/QPrintDialog> 38 39 #include <QtPrintSupport/QPrinter> 39 40 #include <QPushButton> 40 #include <QScrollBar>41 41 #include <QSpacerItem> 42 #include <QStyle>43 42 #include <QSplitter> 44 43 #include <QTextBrowser> 45 44 #include <QVBoxLayout> 45 #include <QWidgetAction> 46 46 #ifdef RT_OS_SOLARIS 47 47 # include <QFontDatabase> … … 50 50 /* GUI includes: */ 51 51 #include "UICommon.h" 52 #include "QIAdvancedSlider.h" 52 53 #include "QIFileDialog.h" 53 54 #include "QITabWidget.h" … … 77 78 Q_DECLARE_METATYPE(HelpBrowserTabs); 78 79 79 const int iBookmarkUrlDataType = 6; 80 static const int iBookmarkUrlDataType = 6; 81 static const QPair<float, float> fontScaleMinMax(0.5f, 3.f); 82 83 /********************************************************************************************************************************* 84 * UIFontScaleWidget definition. * 85 *********************************************************************************************************************************/ 86 class UIFontScaleWidget : public QIWithRetranslateUI<QWidget> 87 { 88 89 Q_OBJECT; 90 91 signals: 92 93 void sigFontPointSizeChanged(int iNewFontPointSize); 94 95 public: 96 97 UIFontScaleWidget(int iInitialFontPointSize, QWidget *pParent = 0); 98 void setFontPointSize(int iFontPointSize); 99 int fontPointSize() const; 100 101 protected: 102 103 void retranslateUi() /* override */; 104 105 private slots: 106 107 void sltSetFontPointSize(); 108 109 private: 110 111 void prepare(); 112 int fontPercentage() const; 113 QHBoxLayout *m_pMainLayout; 114 QIToolButton *m_pMinusButton; 115 QIToolButton *m_pResetButton; 116 QIToolButton *m_pPlusButton; 117 QIAdvancedSlider *m_pSlider; 118 QLabel *m_pValueLabel; 119 int m_iInitialFontPointSize; 120 int m_iFontPointSize; 121 }; 80 122 81 123 … … 185 227 void sigOpenLinkInNewTab(const QUrl &url); 186 228 void sigCloseFindInPageWidget(); 229 void sigFontPointSizeChanged(int iFontPointSize); 187 230 188 231 public: … … 193 236 void setSource(const QUrl &url, const QString &strError); 194 237 void toggleFindInPageWidget(bool fVisible); 238 int initialFontPointSize() const; 195 239 196 240 public slots: … … 200 244 201 245 void contextMenuEvent(QContextMenuEvent *event) /* override */; 202 virtual void paintEvent(QPaintEvent *pEvent) /* override */;203 246 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 247 virtual void wheelEvent(QWheelEvent *pEvent) /* override */; 204 248 205 249 private slots: … … 228 272 int m_iSelectedMatchIndex; 229 273 int m_iSearchTermLength; 274 int m_iInitialFontPointSize; 230 275 }; 231 276 … … 244 289 void sigOpenLinkInNewTab(const QUrl &url); 245 290 void sigAddBookmark(const QUrl &url, const QString &strTitle); 291 void sigFontPointSizeChanged(int iFontPointSize); 246 292 247 293 public: … … 254 300 QString documentTitle() const; 255 301 void setToolBarVisible(bool fVisible); 256 void printCurrent(QPrinter &printer); 302 void print(QPrinter &printer); 303 int initialFontPointSize() const; 304 void setFontPointSize(int iPointSize); 257 305 258 306 private slots: … … 318 366 void setToolBarVisible(bool fVisible); 319 367 void printCurrent(QPrinter &printer); 368 int initialFontPointSize() const; 369 void setFontPointSize(int iPointSize); 370 371 protected: 372 373 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 320 374 321 375 private slots: … … 325 379 void sltHandleTabClose(int iTabIndex); 326 380 void sltHandleCurrentChanged(int iTabIndex); 381 void sltHandleFontSizeChange(int iFontPointSize); 327 382 328 383 private: … … 332 387 void addNewTab(const QUrl &initialUrl); 333 388 const QHelpEngine* m_pHelpEngine; 389 UIFontScaleWidget *m_pFontScaleWidget; 334 390 QUrl m_homeUrl; 335 391 QStringList m_savedUrlList; 336 392 bool m_fSwitchToNewTab; 337 393 }; 394 395 396 /********************************************************************************************************************************* 397 * UIFontScaleWidget implementation. * 398 *********************************************************************************************************************************/ 399 400 UIFontScaleWidget::UIFontScaleWidget(int iInitialFontPointSize, QWidget *pParent /* = 0 */) 401 :QIWithRetranslateUI<QWidget>(pParent) 402 , m_pMainLayout(0) 403 , m_pMinusButton(0) 404 , m_pResetButton(0) 405 , m_pPlusButton(0) 406 , m_pSlider(0) 407 , m_pValueLabel(0) 408 , m_iInitialFontPointSize(iInitialFontPointSize) 409 , m_iFontPointSize(iInitialFontPointSize) 410 { 411 prepare(); 412 } 413 414 void UIFontScaleWidget::setFontPointSize(int iFontPointSize) 415 { 416 if (m_iFontPointSize == iFontPointSize) 417 return; 418 m_iFontPointSize = iFontPointSize; 419 if (m_pValueLabel && m_iInitialFontPointSize != 0) 420 { 421 m_pValueLabel->setText(QString("%1\%").arg(QString::number(fontPercentage()))); 422 } 423 } 424 425 int UIFontScaleWidget::fontPointSize() const 426 { 427 return m_iFontPointSize; 428 } 429 430 void UIFontScaleWidget::retranslateUi() 431 { 432 } 433 434 void UIFontScaleWidget::prepare() 435 { 436 setAutoFillBackground(true); 437 m_pMainLayout = new QHBoxLayout(this); 438 AssertReturnVoid(m_pMainLayout); 439 m_pMainLayout->setSpacing(0); 440 m_pMainLayout->setContentsMargins(0, 0, 0, 0); 441 m_pMinusButton = new QIToolButton; 442 m_pResetButton = new QIToolButton; 443 m_pPlusButton = new QIToolButton; 444 //m_pSlider = new QIAdvancedSlider; 445 m_pValueLabel = new QLabel; 446 AssertReturnVoid(m_pMinusButton && 447 m_pResetButton && 448 m_pPlusButton && 449 m_pValueLabel); 450 451 m_pValueLabel->setText(QString("%1\%").arg(QString::number(fontPercentage()))); 452 453 m_pMinusButton->setIcon(UIIconPool::iconSet(":/help_browser_minus_32px.png")); 454 m_pResetButton->setIcon(UIIconPool::iconSet(":/help_browser_reset_32px.png")); 455 m_pPlusButton->setIcon(UIIconPool::iconSet(":/help_browser_plus_32px.png")); 456 457 connect(m_pPlusButton, &QIToolButton::pressed, this, &UIFontScaleWidget::sltSetFontPointSize); 458 connect(m_pMinusButton, &QIToolButton::pressed, this, &UIFontScaleWidget::sltSetFontPointSize); 459 connect(m_pResetButton, &QIToolButton::pressed, this, &UIFontScaleWidget::sltSetFontPointSize); 460 461 m_pMainLayout->addWidget(m_pResetButton); 462 m_pMainLayout->addWidget(m_pMinusButton); 463 //m_pMainLayout->addWidget(m_pSlider); 464 m_pMainLayout->addWidget(m_pValueLabel); 465 m_pMainLayout->addWidget(m_pPlusButton); 466 } 467 468 int UIFontScaleWidget::fontPercentage() const 469 { 470 if (m_iInitialFontPointSize == 0) 471 return 0; 472 return 100 * m_iFontPointSize / m_iInitialFontPointSize; 473 } 474 475 void UIFontScaleWidget::sltSetFontPointSize() 476 { 477 if (!sender()) 478 return; 479 int iStep = 2; 480 int iNewSize = m_iFontPointSize; 481 if (sender() == m_pMinusButton) 482 iNewSize -= iStep; 483 else if (sender() == m_pPlusButton) 484 iNewSize += iStep; 485 else if (sender() == m_pResetButton) 486 iNewSize = m_iInitialFontPointSize; 487 if (iNewSize >= fontScaleMinMax.second * m_iInitialFontPointSize || 488 iNewSize <= fontScaleMinMax.first * m_iInitialFontPointSize) 489 iNewSize = m_iFontPointSize; 490 setFontPointSize(iNewSize); 491 emit sigFontPointSizeChanged(m_iFontPointSize); 492 } 338 493 339 494 … … 587 742 } 588 743 589 void UIHelpBrowserTab::print Current(QPrinter &printer)744 void UIHelpBrowserTab::print(QPrinter &printer) 590 745 { 591 746 if (m_pContentViewer) 592 {593 747 m_pContentViewer->print(&printer); 748 } 749 750 int UIHelpBrowserTab::initialFontPointSize() const 751 { 752 if (m_pContentViewer) 753 return m_pContentViewer->initialFontPointSize(); 754 return 0; 755 } 756 757 void UIHelpBrowserTab::setFontPointSize(int iPointSize) 758 { 759 if (m_pContentViewer) 760 { 761 if (m_pContentViewer->font().pointSize() == iPointSize) 762 return; 763 QFont mFont = m_pContentViewer->font(); 764 mFont.setPointSize(iPointSize); 765 m_pContentViewer->setFont(mFont); 594 766 } 595 767 } … … 613 785 m_pMainLayout->addWidget(m_pContentViewer); 614 786 m_pContentViewer->setOpenExternalLinks(false); 615 616 787 connect(m_pContentViewer, &UIHelpBrowserViewer::sourceChanged, 617 788 this, &UIHelpBrowserTab::sigSourceChanged); … … 624 795 connect(m_pContentViewer, &UIHelpBrowserViewer::sigCloseFindInPageWidget, 625 796 this, &UIHelpBrowserTab::sltCloseFindInPageWidget); 797 connect(m_pContentViewer, &UIHelpBrowserViewer::sigFontPointSizeChanged, 798 this, &UIHelpBrowserTab::sigFontPointSizeChanged); 626 799 627 800 m_pContentViewer->setSource(initialUrl, m_strPageNotFoundText); … … 794 967 , m_iSearchTermLength(0) 795 968 { 969 m_iInitialFontPointSize = font().pointSize(); 796 970 setUndoRedoEnabled(true); 797 971 connect(m_pFindInPageWidget, &UIFindInPageWidget::sigDragging, … … 853 1027 } 854 1028 1029 int UIHelpBrowserViewer::initialFontPointSize() const 1030 { 1031 return m_iInitialFontPointSize; 1032 } 1033 855 1034 void UIHelpBrowserViewer::contextMenuEvent(QContextMenuEvent *event) 856 1035 { … … 871 1050 } 872 1051 873 void UIHelpBrowserViewer::paintEvent(QPaintEvent *pEvent)874 {875 QIWithRetranslateUI<QTextBrowser>::paintEvent(pEvent);876 }877 878 1052 void UIHelpBrowserViewer::resizeEvent(QResizeEvent *pEvent) 879 1053 { … … 887 1061 } 888 1062 1063 void UIHelpBrowserViewer::wheelEvent(QWheelEvent *pEvent) 1064 { 1065 int iPreviousSize = font().pointSize(); 1066 QTextBrowser::wheelEvent(pEvent); 1067 /* Don't allow font size to get too large or small: */ 1068 if (font().pointSize() >= fontScaleMinMax.second * m_iInitialFontPointSize || 1069 font().pointSize() <= fontScaleMinMax.first * m_iInitialFontPointSize) 1070 { 1071 QFont mFont = font(); 1072 mFont.setPointSize(iPreviousSize); 1073 setFont(mFont); 1074 } 1075 else 1076 emit sigFontPointSizeChanged(font().pointSize()); 1077 } 889 1078 890 1079 void UIHelpBrowserViewer::retranslateUi() … … 1035 1224 : QITabWidget(pParent) 1036 1225 , m_pHelpEngine(pHelpEngine) 1226 , m_pFontScaleWidget(0) 1037 1227 , m_homeUrl(homeUrl) 1038 1228 , m_savedUrlList(urlList) … … 1055 1245 connect(pTabWidget, &UIHelpBrowserTab::sigAddBookmark, 1056 1246 this, &UIHelpBrowserTabManager::sigAddBookmark); 1247 connect(pTabWidget, &UIHelpBrowserTab::sigFontPointSizeChanged, 1248 this, &UIHelpBrowserTabManager::sltHandleFontSizeChange); 1249 1057 1250 if (m_fSwitchToNewTab) 1058 1251 setCurrentIndex(index); 1252 1253 if (!m_pFontScaleWidget) 1254 { 1255 m_pFontScaleWidget = new UIFontScaleWidget(initialFontPointSize(), this); 1256 connect(m_pFontScaleWidget, &UIFontScaleWidget::sigFontPointSizeChanged, 1257 this, &UIHelpBrowserTabManager::sltHandleFontSizeChange); 1258 } 1059 1259 } 1060 1260 … … 1119 1319 if (!pTab) 1120 1320 return; 1121 return pTab->printCurrent(printer); 1321 return pTab->print(printer); 1322 } 1323 1324 void UIHelpBrowserTabManager::paintEvent(QPaintEvent *pEvent) 1325 { 1326 if (m_pFontScaleWidget) 1327 { 1328 int iMargin = 20; 1329 m_pFontScaleWidget->move(width() - m_pFontScaleWidget->width() - iMargin, 1330 height() - m_pFontScaleWidget->height() - iMargin); 1331 } 1332 QITabWidget::paintEvent(pEvent); 1333 } 1334 1335 int UIHelpBrowserTabManager::initialFontPointSize() const 1336 { 1337 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget()); 1338 if (!pTab) 1339 return 0; 1340 return pTab->initialFontPointSize(); 1341 } 1342 1343 void UIHelpBrowserTabManager::setFontPointSize(int iPointSize) 1344 { 1345 for (int i = 0; i < count(); ++i) 1346 { 1347 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i)); 1348 if (!pTab) 1349 continue; 1350 pTab->setFontPointSize(iPointSize); 1351 } 1352 if (m_pFontScaleWidget) 1353 m_pFontScaleWidget->setFontPointSize(iPointSize); 1122 1354 } 1123 1355 … … 1156 1388 Q_UNUSED(iTabIndex); 1157 1389 emit sigSourceChanged(currentSource()); 1390 } 1391 1392 void UIHelpBrowserTabManager::sltHandleFontSizeChange(int iFontPointSize) 1393 { 1394 setFontPointSize(iFontPointSize); 1158 1395 } 1159 1396 … … 1233 1470 } 1234 1471 1235 1236 1472 bool UIHelpBrowserWidget::shouldBeMaximized() const 1237 1473 { … … 1408 1644 m_pViewMenu = new QMenu(tr("View"), this); 1409 1645 AssertReturnVoid(m_pViewMenu); 1646 1410 1647 if (m_pPrintDialogAction) 1411 1648 m_pFileMenu->addAction(m_pPrintDialogAction); … … 1717 1954 m_pTabManager->setSource(url, false); 1718 1955 } 1956 1719 1957 #include "UIHelpBrowserWidget.moc" 1720 1958
Note:
See TracChangeset
for help on using the changeset viewer.

