VirtualBox

Changeset 88410 in vbox for trunk/src


Ignore:
Timestamp:
Apr 8, 2021 10:49:01 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Fixing font scaling.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r88408 r88410  
    100100
    101101    void prepare();
    102     //int fontPercentage() const;
    103102
    104103    QHBoxLayout  *m_pMainLayout;
     
    189188    void sigAddBookmark(const QUrl &url, const QString &strTitle);
    190189    void sigLinkHighlighted(const QString &strLink);
     190    void sigZoomPercentageChanged(int iPercentage);
    191191
    192192public:
     
    221221    virtual void retranslateUi() /* override */;
    222222    void setActionTextAndToolTip(QAction *pAction, const QString &strText, const QString &strToolTip);
    223     // int initialFontPointSize() const;
    224     // void setFontPointSize(int iPointSize);
    225     // int fontPointSize() const;
    226223
    227224    QAction     *m_pHomeAction;
     
    278275    void sltHandleCloseCurrentTab();
    279276    void sltHandleCloseOtherTabs();
     277    void sltHandleZoomOperation(UIHelpViewer::ZoomOperation enmZoomOperation);
    280278
    281279protected:
     
    290288    void sltHandleContextMenuTabClose();
    291289    void sltHandleCurrentChanged(int iTabIndex);
    292     void sltHandleZoomOperation(UIHelpViewer::ZoomOperation enmZoomOperation);
    293290    void sltShowTabBarContextMenu(const QPoint &pos);
    294291    void sltHandleCloseOtherTabsContextMenuAction();
     292    void sltZoomPercentageChanged(int iPercentage);
    295293
    296294private:
     
    305303    /* Returns the tab index with @Url if there is one. Returns -1 otherwise. */
    306304    int  findTab(const QUrl &Url) const;
    307     // void setFontPointSize(int iPointSize);
    308     // int  initialFontPointSize() const;
    309     // int  fontPointSize() const;
    310305
    311306    const QHelpEngine* m_pHelpEngine;
     
    354349                     m_pPlusButton &&
    355350                     m_pValueLabel);
    356 
    357     //m_pValueLabel->setText(QString("%1%2").arg(QString::number(fontPercentage())).arg("%"));
    358351
    359352    m_pMinusButton->setIcon(UIIconPool::iconSet(":/help_browser_minus_32px.png"));
     
    582575        m_pContentViewer->zoom(enmZoomOperation);
    583576}
    584 // void UIHelpBrowserTab::setZoomPercentage(int iZoomPercentage)
    585 // {
    586 //     if (m_pContentViewer)
    587 //         m_pContentViewer->setZoomPercentage(iZoomPercentage);
    588 // }
    589 
    590 // int UIHelpBrowserTab::initialFontPointSize() const
    591 // {
    592 //     if (m_pContentViewer)
    593 //         return m_pContentViewer->initialFontPointSize();
    594 //     return 0;
    595 // }
    596 
    597 // void UIHelpBrowserTab::setFontPointSize(int iPointSize)
    598 // {
    599 //     if (m_pContentViewer)
    600 //     {
    601 //         if (m_pContentViewer->font().pointSize() == iPointSize)
    602 //             return;
    603 //         QFont mFont = m_pContentViewer->font();
    604 //         mFont.setPointSize(iPointSize);
    605 //         m_pContentViewer->setFont(mFont);
    606 //     }
    607 // }
    608 
    609 // int UIHelpBrowserTab::fontPointSize() const
    610 // {
    611 //     if (!m_pContentViewer)
    612 //         return 0;
    613 //     return m_pContentViewer->font().pointSize();
    614 // }
    615577
    616578void UIHelpBrowserTab::prepare(const QUrl &initialUrl)
     
    652614    connect(m_pContentViewer, static_cast<void(UIHelpViewer::*)(const QString&)>(&UIHelpViewer::highlighted),
    653615            this, &UIHelpBrowserTab::sigLinkHighlighted);
     616    connect(m_pContentViewer, &UIHelpViewer::sigZoomPercentageChanged,
     617            this, &UIHelpBrowserTab::sigZoomPercentageChanged);
    654618
    655619    m_pContentViewer->setSource(initialUrl);
     
    847811    connect(pTabWidget, &UIHelpBrowserTab::sigAddBookmark,
    848812            this, &UIHelpBrowserTabManager::sigAddBookmark);
    849     // connect(pTabWidget, &UIHelpBrowserTab::sigZoomPercentageChanged,
    850     //         this, &UIHelpBrowserTabManager::sltHandleZoomOperation);
     813    connect(pTabWidget, &UIHelpBrowserTab::sigZoomPercentageChanged,
     814            this, &UIHelpBrowserTabManager::sltZoomPercentageChanged);
    851815    connect(pTabWidget, &UIHelpBrowserTab::sigLinkHighlighted,
    852816            this, &UIHelpBrowserTabManager::sigLinkHighlighted);
     
    860824        connect(m_pZoomWidget, &UIZoomWidget::sigZoomChanged,
    861825                this, &UIHelpBrowserTabManager::sltHandleZoomOperation);
     826        m_pZoomWidget->setZoomPercentage(100);
    862827    }
    863828}
     
    1000965}
    1001966
    1002 // int UIHelpBrowserTabManager::initialFontPointSize() const
    1003 // {
    1004 //     UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
    1005 //     if (!pTab)
    1006 //         return 0;
    1007 //     return pTab->initialFontPointSize();
    1008 // }
    1009 
    1010 // void UIHelpBrowserTabManager::setFontPointSize(int iPointSize)
    1011 // {
    1012 //     for (int i = 0; i < count(); ++i)
    1013 //     {
    1014 //         UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
    1015 //         if (!pTab)
    1016 //             continue;
    1017 //         pTab->setFontPointSize(iPointSize);
    1018 //     }
    1019 //     // if (m_pZoomWidget)
    1020 //     //     m_pZoomWidget->setFontPointSize(iPointSize);
    1021 // }
    1022 
    1023 // int UIHelpBrowserTabManager::fontPointSize() const
    1024 // {
    1025 //     UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
    1026 //     if (!pTab)
    1027 //         return 0;
    1028 //     return pTab->fontPointSize();
    1029 // }
    1030 
    1031967void UIHelpBrowserTabManager::setZoomWidgetVisible(bool fToggled)
    1032968{
     
    10961032        return;
    10971033    closeAllTabsBut(iTabIndex);
     1034}
     1035
     1036void UIHelpBrowserTabManager::sltZoomPercentageChanged(int iPercentage)
     1037{
     1038    if (m_pZoomWidget)
     1039        m_pZoomWidget->setZoomPercentage(iPercentage);
    10981040}
    10991041
     
    11991141    , m_pZoomInAction(0)
    12001142    , m_pZoomOutAction(0)
    1201     , m_pFontSizeResetAction(0)
     1143    , m_pZoomResetAction(0)
    12021144    , m_fModelContentCreated(false)
    12031145    , m_fIndexingFinished(false)
     
    12961238    m_pZoomOutAction->setIcon(UIIconPool::iconSet(":/help_browser_minus_32px.png"));
    12971239
    1298     m_pFontSizeResetAction = new QAction(this);
    1299     m_pFontSizeResetAction->setIcon(UIIconPool::iconSet(":/help_browser_reset_32px.png"));
     1240    m_pZoomResetAction = new QAction(this);
     1241    m_pZoomResetAction->setIcon(UIIconPool::iconSet(":/help_browser_reset_32px.png"));
    13001242
    13011243    connect(m_pZoomInAction, &QAction::triggered,
     
    13031245    connect(m_pZoomOutAction, &QAction::triggered,
    13041246            this, &UIHelpBrowserWidget::sltHandleZoomActions);
    1305     connect(m_pFontSizeResetAction, &QAction::triggered,
     1247    connect(m_pZoomResetAction, &QAction::triggered,
    13061248            this, &UIHelpBrowserWidget::sltHandleZoomActions);
    13071249}
     
    14511393    if (m_pZoomOutAction)
    14521394        m_pViewMenu->addAction(m_pZoomOutAction);
    1453     if (m_pFontSizeResetAction)
    1454         m_pViewMenu->addAction(m_pFontSizeResetAction);
     1395    if (m_pZoomResetAction)
     1396        m_pViewMenu->addAction(m_pZoomResetAction);
    14551397    m_pViewMenu->addSeparator();
    14561398    if (m_pShowHideSideBarAction)
     
    15781520        m_pShowHideToolBarAction->setText(tr("Show Tool Bar"));
    15791521    if (m_pShowHideZoomWidgetAction)
    1580         m_pShowHideZoomWidgetAction->setText(tr("Show Font Scale Widget"));
     1522        m_pShowHideZoomWidgetAction->setText(tr("Show Zoom Widget"));
    15811523    if (m_pShowHideStatusBarAction)
    15821524        m_pShowHideStatusBarAction->setText(tr("Show Status Bar"));
     
    15921534    if (m_pZoomOutAction)
    15931535        m_pZoomOutAction->setText(tr("Zoom &Out"));
    1594     if (m_pFontSizeResetAction)
    1595         m_pFontSizeResetAction->setText(tr("&Reset Zoom"));
     1536    if (m_pZoomResetAction)
     1537        m_pZoomResetAction->setText(tr("&Reset Zoom"));
    15961538}
    15971539
     
    18641806void UIHelpBrowserWidget::sltHandleZoomActions()
    18651807{
    1866     // if (!sender() || !m_pTabManager)
    1867     //     return;
    1868     // int iFontPointSize = m_pTabManager->fontPointSize();
    1869     // if (sender() == m_pFontSizeResetAction)
    1870     //     iFontPointSize = m_pTabManager->initialFontPointSize();
    1871     // else if (sender() == m_pZoomInAction)
    1872     //     iFontPointSize += iZoomPercentageStep;
    1873     // else if (sender() == m_pZoomOutAction)
    1874     //     iFontPointSize -= iZoomPercentageStep;
    1875 
    1876     // if (iFontPointSize >= zoomPercentageMinMax.second * m_pTabManager->initialFontPointSize() ||
    1877     //     iFontPointSize <= zoomPercentageMinMax.first * m_pTabManager->initialFontPointSize())
    1878     //     return;
    1879     // m_pTabManager->setFontPointSize(iFontPointSize);
     1808    if (!sender() || !m_pTabManager)
     1809        return;
     1810    UIHelpViewer::ZoomOperation enmOperation = UIHelpViewer::ZoomOperation_Reset;
     1811    if (sender() == m_pZoomResetAction)
     1812        enmOperation = UIHelpViewer::ZoomOperation_Reset;
     1813    else if (sender() == m_pZoomInAction)
     1814        enmOperation = UIHelpViewer::ZoomOperation_In;
     1815    else if (sender() == m_pZoomOutAction)
     1816        enmOperation = UIHelpViewer::ZoomOperation_Out;
     1817    m_pTabManager->sltHandleZoomOperation(enmOperation);
    18801818}
    18811819
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r88408 r88410  
    169169    QAction             *m_pZoomInAction;
    170170    QAction             *m_pZoomOutAction;
    171     QAction             *m_pFontSizeResetAction;
     171    QAction             *m_pZoomResetAction;
    172172
    173173    /* This is set t true when handling QHelpContentModel::contentsCreated signal. */
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp

    r88408 r88410  
    5050#ifdef VBOX_WITH_QHELP_VIEWER
    5151
    52 //static int iZoomPercentageStep = 20;
     52static int iZoomPercentageStep = 20;
    5353const QPair<int, int> UIHelpViewer::zoomPercentageMinMax = QPair<int, int>(20, 300);
    5454
     
    341341    , m_iSelectedMatchIndex(0)
    342342    , m_iSearchTermLength(0)
     343    , m_iZoomPercentage(100)
    343344{
    344345    m_iInitialFontPointSize = font().pointSize();
     
    415416}
    416417
    417 int UIHelpViewer::initialFontPointSize() const
    418 {
    419     return m_iInitialFontPointSize;
    420 }
    421 
    422418void UIHelpViewer::setFont(const QFont &font)
    423419{
     
    441437void UIHelpViewer::zoom(ZoomOperation enmZoomOperation)
    442438{
    443     Q_UNUSED(enmZoomOperation);
    444 }
    445 
     439    int iPrevZoom = m_iZoomPercentage;
     440    switch (enmZoomOperation)
     441    {
     442        case ZoomOperation_In:
     443            m_iZoomPercentage += iZoomPercentageStep;
     444            break;
     445        case ZoomOperation_Out:
     446            m_iZoomPercentage -= iZoomPercentageStep;
     447            break;
     448        case ZoomOperation_Reset:
     449        default:
     450            m_iZoomPercentage = 100;
     451            break;
     452    }
     453
     454    if (m_iZoomPercentage > zoomPercentageMinMax.second ||
     455        m_iZoomPercentage < zoomPercentageMinMax.first)
     456        m_iZoomPercentage = iPrevZoom;
     457    scaleFont();
     458
     459    emit sigZoomPercentageChanged(m_iZoomPercentage);
     460}
    446461
    447462void UIHelpViewer::contextMenuEvent(QContextMenuEvent *event)
     
    640655}
    641656
    642 void UIHelpViewer::iterateDocumentImages()
    643 {
    644     m_imageSizesMap.clear();
    645     QTextCursor cursor = textCursor();
    646     cursor.movePosition(QTextCursor::Start);
    647     while (!cursor.atEnd())
    648     {
    649         cursor.movePosition(QTextCursor::NextCharacter);
    650         if (cursor.charFormat().isImageFormat())
    651         {
    652            QTextImageFormat imageFormat = cursor.charFormat().toImageFormat();
    653            m_imageSizesMap[imageFormat.name()] = imageFormat.width();
    654         }
    655     }
    656 }
    657 
    658657void UIHelpViewer::sltHandleOpenLinkInNewTab()
    659658{
     
    731730}
    732731
     732void UIHelpViewer::iterateDocumentImages()
     733{
     734    m_imageSizesMap.clear();
     735    QTextCursor cursor = textCursor();
     736    cursor.movePosition(QTextCursor::Start);
     737    while (!cursor.atEnd())
     738    {
     739        cursor.movePosition(QTextCursor::NextCharacter);
     740        if (cursor.charFormat().isImageFormat())
     741        {
     742           QTextImageFormat imageFormat = cursor.charFormat().toImageFormat();
     743           m_imageSizesMap[imageFormat.name()] = imageFormat.width();
     744        }
     745    }
     746}
     747
     748void UIHelpViewer::scaleFont()
     749{
     750    QFont mFont = font();
     751    mFont.setPointSize(m_iInitialFontPointSize * m_iZoomPercentage / 100.);
     752    setFont(mFont);
     753}
     754
    733755#include "UIHelpViewer.moc"
    734756
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h

    r88408 r88410  
    3636class UIHelpViewer : public QIWithRetranslateUI<QTextBrowser>
    3737{
     38
    3839    Q_OBJECT;
    3940
     
    4748    void sigGoHome();
    4849    void sigAddBookmark();
     50    void sigZoomPercentageChanged(int iPercentage);
    4951
    5052public:
     
    6264    void emitHistoryChangedSignal();
    6365    void setSource(const QUrl &url) /* override */;
    64     int initialFontPointSize() const;
    6566    void setFont(const QFont &);
    6667    bool isFindInPageWidgetVisible() const;
     
    99100    void selectMatch(int iMatchIndex, int iSearchStringLength);
    100101    void iterateDocumentImages();
     102    void scaleFont();
    101103    const QHelpEngine* m_pHelpEngine;
    102104    UIFindInPageWidget *m_pFindInPageWidget;
     
    111113    /** A container to store the original image sizes in the document. key is image name value is the width. */
    112114    QMap<QString, qreal> m_imageSizesMap;
     115    /** As percentage. */
     116    int m_iZoomPercentage;
    113117};
    114118
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette