VirtualBox

Changeset 88436 in vbox


Ignore:
Timestamp:
Apr 9, 2021 1:35:23 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Moving the weird zoom widget to menu

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

Legend:

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

    r88423 r88436  
    3939# include <QFontDatabase>
    4040#endif
     41#include <QWidgetAction>
    4142
    4243/* GUI includes: */
     
    7172
    7273/*********************************************************************************************************************************
    73 *   UIZoomWidget definition.                                                                                         *
     74*   UIZoomMenuAction definition.                                                                                    *
    7475*********************************************************************************************************************************/
    75 class UIZoomWidget : public QIWithRetranslateUI<QWidget>
     76class UIZoomMenuAction : public QIWithRetranslateUI<QWidgetAction>
    7677{
    7778
     
    8081signals:
    8182
    82     void sigZoomChanged(UIHelpViewer::ZoomOperation enmOperation);
     83    void sigZoomChanged(int iOperation);
    8384
    8485public:
    8586
    86 
    87     UIZoomWidget(QWidget *pParent = 0);
    88     int zoomPercentage() const;
     87    UIZoomMenuAction(QWidget *pParent = 0);
    8988    void setZoomPercentage(int iZoomPercentage);
    9089
     
    101100    void prepare();
    102101
    103     QHBoxLayout  *m_pMainLayout;
    104102    QIToolButton *m_pMinusButton;
    105103    QIToolButton *m_pResetButton;
    106104    QIToolButton *m_pPlusButton;
    107105    QLabel *m_pValueLabel;
     106    QLabel *m_pLabel;
    108107};
    109108
     
    255254    void sigTabsListChanged(const QStringList &titleList);
    256255    void sigLinkHighlighted(const QString &strLink);
     256    void sigZoomPercentageChanged(int iPercentage);
    257257
    258258public:
     
    271271    void setToolBarVisible(bool fVisible);
    272272    void printCurrent(QPrinter &printer);
    273     void setZoomWidgetVisible(bool fToggled);
    274273    void switchToTab(int iIndex);
    275     /** returns the zoom percentage of 0th tab. */
     274    /** Returns the zoom percentage of 0th tab. */
    276275    int zoomPercentage() const;
    277276    /** Sets the zoom percentage of all tabs. */
     
    284283    void sltHandleCloseOtherTabs();
    285284    void sltHandleZoomOperation(UIHelpViewer::ZoomOperation enmZoomOperation);
    286 
    287 protected:
    288 
    289     virtual void paintEvent(QPaintEvent *pEvent) /* override */;
    290285
    291286private slots:
     
    298293    void sltShowTabBarContextMenu(const QPoint &pos);
    299294    void sltHandleCloseOtherTabsContextMenuAction();
    300     void sltZoomPercentageChanged(int iPercentage);
    301295
    302296private:
     
    313307
    314308    const QHelpEngine* m_pHelpEngine;
    315     UIZoomWidget *m_pZoomWidget;
    316309    QUrl m_homeUrl;
    317310    QStringList m_savedUrlList;
     
    325318
    326319/*********************************************************************************************************************************
    327 *   UIZoomWidget implementation.                                                                                          *
     320*   UIZoomMenuAction implementation.                                                                                *
    328321*********************************************************************************************************************************/
    329 
    330 UIZoomWidget::UIZoomWidget(QWidget *pParent /* = 0 */)
    331     :QIWithRetranslateUI<QWidget>(pParent)
    332     , m_pMainLayout(0)
     322UIZoomMenuAction::UIZoomMenuAction(QWidget *pParent /* = 0 */)
     323    :QIWithRetranslateUI<QWidgetAction>(pParent)
    333324    , m_pMinusButton(0)
    334325    , m_pResetButton(0)
    335326    , m_pPlusButton(0)
    336327    , m_pValueLabel(0)
     328    , m_pLabel(0)
    337329{
    338330    prepare();
    339 }
    340 
    341 void UIZoomWidget::retranslateUi()
    342 {
    343 }
    344 
    345 void UIZoomWidget::prepare()
    346 {
    347     setAutoFillBackground(true);
    348     m_pMainLayout = new QHBoxLayout(this);
    349     AssertReturnVoid(m_pMainLayout);
    350     m_pMainLayout->setSpacing(0);
    351     m_pMainLayout->setContentsMargins(0, 0, 0, 0);
     331    retranslateUi();
     332}
     333
     334void UIZoomMenuAction::setZoomPercentage(int iZoomPercentage)
     335{
     336    if (m_pValueLabel)
     337        m_pValueLabel->setText(QString("%1%2").arg(QString::number(iZoomPercentage)).arg("%"));
     338}
     339
     340void UIZoomMenuAction::retranslateUi()
     341{
     342    if (m_pLabel)
     343        m_pLabel->setText(UIHelpBrowserWidget::tr("Zoom"));
     344}
     345
     346void UIZoomMenuAction::prepare()
     347{
     348    QWidget *pWidget = new QWidget;
     349    setDefaultWidget(pWidget);
     350    // if (pWidget)
     351    //     pWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
     352
     353    QHBoxLayout *pMainLayout = new QHBoxLayout(pWidget);
     354    pMainLayout->setSpacing(0);
     355    AssertReturnVoid(pMainLayout);
     356
     357    m_pLabel = new QLabel;
    352358    m_pMinusButton = new QIToolButton;
    353359    m_pResetButton = new QIToolButton;
    354360    m_pPlusButton = new QIToolButton;
    355361    m_pValueLabel = new QLabel;
     362    m_pValueLabel->setAlignment(Qt::AlignCenter);
     363    m_pValueLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
    356364    AssertReturnVoid(m_pMinusButton &&
    357365                     m_pResetButton &&
     
    363371    m_pPlusButton->setIcon(UIIconPool::iconSet(":/help_browser_plus_32px.png"));
    364372
    365     connect(m_pPlusButton, &QIToolButton::pressed, this, &UIZoomWidget::sltZoomOperation);
    366     connect(m_pMinusButton, &QIToolButton::pressed, this, &UIZoomWidget::sltZoomOperation);
    367     connect(m_pResetButton, &QIToolButton::pressed, this, &UIZoomWidget::sltZoomOperation);
    368 
    369     m_pMainLayout->addWidget(m_pResetButton);
    370     m_pMainLayout->addWidget(m_pMinusButton);
    371     m_pMainLayout->addWidget(m_pValueLabel);
    372     m_pMainLayout->addWidget(m_pPlusButton);
    373 }
    374 
    375 void UIZoomWidget::setZoomPercentage(int iZoomPercentage)
    376 {
    377     if (m_pValueLabel)
    378         m_pValueLabel->setText(QString("%1%2").arg(QString::number(iZoomPercentage)).arg("%"));
    379 }
    380 
    381 void UIZoomWidget::sltZoomOperation()
     373    connect(m_pPlusButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
     374    connect(m_pMinusButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
     375    connect(m_pResetButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
     376
     377    pMainLayout->addWidget(m_pLabel);
     378    pMainLayout->addWidget(m_pResetButton);
     379    pMainLayout->addWidget(m_pMinusButton);
     380    pMainLayout->addWidget(m_pValueLabel, Qt::AlignCenter);
     381    pMainLayout->addWidget(m_pPlusButton);
     382}
     383
     384void UIZoomMenuAction::sltZoomOperation()
    382385{
    383386    if (!sender())
     
    390393    else if (sender() == m_pResetButton)
    391394        enmOperation = UIHelpViewer::ZoomOperation_Reset;
    392     emit sigZoomChanged(enmOperation);
     395    emit sigZoomChanged((int)enmOperation);
    393396}
    394397
     
    807810    : QITabWidget(pParent)
    808811    , m_pHelpEngine(pHelpEngine)
    809     , m_pZoomWidget(0)
    810812    , m_homeUrl(homeUrl)
    811813    , m_savedUrlList(urlList)
     
    840842            this, &UIHelpBrowserTabManager::sigAddBookmark);
    841843    connect(pTabWidget, &UIHelpBrowserTab::sigZoomPercentageChanged,
    842             this, &UIHelpBrowserTabManager::sltZoomPercentageChanged);
     844            this, &UIHelpBrowserTabManager::sigZoomPercentageChanged);
    843845    connect(pTabWidget, &UIHelpBrowserTab::sigLinkHighlighted,
    844846            this, &UIHelpBrowserTabManager::sigLinkHighlighted);
     
    849851    if (!fBackground)
    850852        setCurrentIndex(index);
    851 
    852     if (!m_pZoomWidget)
    853     {
    854         m_pZoomWidget = new UIZoomWidget(this);
    855         connect(m_pZoomWidget, &UIZoomWidget::sigZoomChanged,
    856                 this, &UIHelpBrowserTabManager::sltHandleZoomOperation);
    857         m_pZoomWidget->setZoomPercentage(100);
    858     }
    859853}
    860854
     
    985979}
    986980
    987 void UIHelpBrowserTabManager::paintEvent(QPaintEvent *pEvent)
    988 {
    989     if (m_pZoomWidget)
    990     {
    991         int iMargin = 1.5 * qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
    992         m_pZoomWidget->move(width() - m_pZoomWidget->width() - iMargin,
    993                             height() - m_pZoomWidget->height() - iMargin);
    994     }
    995     QITabWidget::paintEvent(pEvent);
    996 }
    997 
    998 void UIHelpBrowserTabManager::setZoomWidgetVisible(bool fToggled)
    999 {
    1000     if (m_pZoomWidget)
    1001         m_pZoomWidget->setVisible(fToggled);
    1002 }
    1003 
    1004981void UIHelpBrowserTabManager::switchToTab(int iIndex)
    1005982{
     
    10861063        return;
    10871064    closeAllTabsBut(iTabIndex);
    1088 }
    1089 
    1090 void UIHelpBrowserTabManager::sltZoomPercentageChanged(int iPercentage)
    1091 {
    1092     if (m_pZoomWidget)
    1093         m_pZoomWidget->setZoomPercentage(iPercentage);
    10941065}
    10951066
     
    11911162    , m_pShowHideSideBarAction(0)
    11921163    , m_pShowHideToolBarAction(0)
    1193     , m_pShowHideZoomWidgetAction(0)
    11941164    , m_pShowHideStatusBarAction(0)
    1195     , m_pZoomInAction(0)
    1196     , m_pZoomOutAction(0)
    1197     , m_pZoomResetAction(0)
     1165    , m_pZoomMenuAction(0)
    11981166    , m_fModelContentCreated(false)
    11991167    , m_fIndexingFinished(false)
     
    12641232            this, &UIHelpBrowserWidget::sltHandleWidgetVisibilityToggle);
    12651233
    1266     m_pShowHideZoomWidgetAction = new QAction(this);
    1267     m_pShowHideZoomWidgetAction->setCheckable(true);
    1268     m_pShowHideZoomWidgetAction->setChecked(true);
    1269     connect(m_pShowHideZoomWidgetAction, &QAction::toggled,
    1270             this, &UIHelpBrowserWidget::sltHandleWidgetVisibilityToggle);
    1271 
    12721234    m_pShowHideStatusBarAction = new QAction(this);
    12731235    m_pShowHideStatusBarAction->setCheckable(true);
     
    12851247            this, &UIHelpBrowserWidget::sigCloseDialog);
    12861248
    1287     /* For size control actions: */
    1288     m_pZoomInAction = new QAction(this);
    1289     m_pZoomInAction->setIcon(UIIconPool::iconSet(":/help_browser_plus_32px.png"));
    1290 
    1291     m_pZoomOutAction = new QAction(this);
    1292     m_pZoomOutAction->setIcon(UIIconPool::iconSet(":/help_browser_minus_32px.png"));
    1293 
    1294     m_pZoomResetAction = new QAction(this);
    1295     m_pZoomResetAction->setIcon(UIIconPool::iconSet(":/help_browser_reset_32px.png"));
    1296 
    1297     connect(m_pZoomInAction, &QAction::triggered,
    1298             this, &UIHelpBrowserWidget::sltHandleZoomActions);
    1299     connect(m_pZoomOutAction, &QAction::triggered,
    1300             this, &UIHelpBrowserWidget::sltHandleZoomActions);
    1301     connect(m_pZoomResetAction, &QAction::triggered,
     1249    m_pZoomMenuAction = new UIZoomMenuAction(this);
     1250    connect(m_pZoomMenuAction, &UIZoomMenuAction::sigZoomChanged,
    13021251            this, &UIHelpBrowserWidget::sltHandleZoomActions);
    13031252}
     
    13481297    connect(m_pTabManager, &UIHelpBrowserTabManager::sigLinkHighlighted,
    13491298            this, &UIHelpBrowserWidget::sigLinkHighlighted);
     1299    connect(m_pTabManager, &UIHelpBrowserTabManager::sigZoomPercentageChanged,
     1300            this, &UIHelpBrowserWidget::sltZoomPercentageChanged);
    13501301
    13511302    connect(m_pHelpEngine, &QHelpEngine::setupFinished,
     
    14441395        m_pFileMenu->addAction(m_pCloseDialogAction);
    14451396
    1446     if (m_pZoomInAction)
    1447         m_pViewMenu->addAction(m_pZoomInAction);
    1448     if (m_pZoomOutAction)
    1449         m_pViewMenu->addAction(m_pZoomOutAction);
    1450     if (m_pZoomResetAction)
    1451         m_pViewMenu->addAction(m_pZoomResetAction);
    1452     m_pViewMenu->addSeparator();
     1397    if (m_pZoomMenuAction)
     1398        m_pViewMenu->addAction(m_pZoomMenuAction);
    14531399    if (m_pShowHideSideBarAction)
    14541400        m_pViewMenu->addAction(m_pShowHideSideBarAction);
    14551401    if (m_pShowHideToolBarAction)
    14561402        m_pViewMenu->addAction(m_pShowHideToolBarAction);
    1457     if (m_pShowHideZoomWidgetAction)
    1458         m_pViewMenu->addAction(m_pShowHideZoomWidgetAction);
    14591403    if (m_pShowHideStatusBarAction)
    14601404        m_pViewMenu->addAction(m_pShowHideStatusBarAction);
     
    15791523    if (m_pShowHideToolBarAction)
    15801524        m_pShowHideToolBarAction->setText(tr("Show Tool Bar"));
    1581     if (m_pShowHideZoomWidgetAction)
    1582         m_pShowHideZoomWidgetAction->setText(tr("Show Zoom Widget"));
    15831525    if (m_pShowHideStatusBarAction)
    15841526        m_pShowHideStatusBarAction->setText(tr("Show Status Bar"));
    1585 
    15861527
    15871528    if (m_pPrintAction)
     
    15891530    if (m_pCloseDialogAction)
    15901531        m_pCloseDialogAction->setText(tr("Close"));
    1591 
    1592     if (m_pZoomInAction)
    1593         m_pZoomInAction->setText(tr("Zoom &In"));
    1594     if (m_pZoomOutAction)
    1595         m_pZoomOutAction->setText(tr("Zoom &Out"));
    1596     if (m_pZoomResetAction)
    1597         m_pZoomResetAction->setText(tr("&Reset Zoom"));
    15981532}
    15991533
     
    16341568        if (m_pTabManager)
    16351569            m_pTabManager->setToolBarVisible(fToggled);
    1636     }
    1637     else if (sender() == m_pShowHideZoomWidgetAction)
    1638     {
    1639         if (m_pTabManager)
    1640             m_pTabManager->setZoomWidgetVisible(fToggled);
    16411570    }
    16421571    else if (sender() == m_pShowHideStatusBarAction)
     
    18641793}
    18651794
    1866 void UIHelpBrowserWidget::sltHandleZoomActions()
    1867 {
    1868     if (!sender() || !m_pTabManager)
    1869         return;
    1870     UIHelpViewer::ZoomOperation enmOperation = UIHelpViewer::ZoomOperation_Reset;
    1871     if (sender() == m_pZoomResetAction)
    1872         enmOperation = UIHelpViewer::ZoomOperation_Reset;
    1873     else if (sender() == m_pZoomInAction)
    1874         enmOperation = UIHelpViewer::ZoomOperation_In;
    1875     else if (sender() == m_pZoomOutAction)
    1876         enmOperation = UIHelpViewer::ZoomOperation_Out;
     1795void UIHelpBrowserWidget::sltHandleZoomActions(int iZoomOperation)
     1796{
     1797    if (iZoomOperation >= (int) UIHelpViewer::ZoomOperation_Max)
     1798        return;
     1799    UIHelpViewer::ZoomOperation enmOperation = (UIHelpViewer::ZoomOperation)(iZoomOperation);
    18771800    m_pTabManager->sltHandleZoomOperation(enmOperation);
    18781801}
     
    19091832}
    19101833
     1834void UIHelpBrowserWidget::sltZoomPercentageChanged(int iPercentage)
     1835{
     1836    if (m_pZoomMenuAction)
     1837        m_pZoomMenuAction->setZoomPercentage(iPercentage);
     1838}
     1839
    19111840
    19121841#include "UIHelpBrowserWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r88410 r88436  
    4646class UIBookmarksListContainer;
    4747class UIHelpBrowserTabManager;
     48class UIZoomMenuAction;
    4849
    4950#ifdef VBOX_WITH_QHELP_VIEWER
     
    9192    void sltCopyLink();
    9293    void sltAddNewBookmark(const QUrl &url, const QString &strTitle);
    93     void sltHandleZoomActions();
     94    void sltHandleZoomActions(int iZoomOperation);
    9495    void sltHandleTabListChanged(const QStringList &titleList);
    9596    void sltHandleTabChoose();
    9697    void sltHandleCurrentTabChanged(int iIndex);
     98    void sltZoomPercentageChanged(int iPercentage);
    9799
    98100private:
     
    165167    QAction             *m_pShowHideSideBarAction;
    166168    QAction             *m_pShowHideToolBarAction;
    167     QAction             *m_pShowHideZoomWidgetAction;
    168169    QAction             *m_pShowHideStatusBarAction;
    169     QAction             *m_pZoomInAction;
    170     QAction             *m_pZoomOutAction;
    171     QAction             *m_pZoomResetAction;
     170    UIZoomMenuAction    *m_pZoomMenuAction;
    172171
    173172    /* This is set t true when handling QHelpContentModel::contentsCreated signal. */
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp

    r88430 r88436  
    7878    void setForwardAvailable(bool fAvailable);
    7979
    80 protected:
    81 
    82 
    83 private slots:
    84 
    85 
    8680private:
    8781
     
    185179    pMainLayout->addWidget(m_pAddBookmarkButton);
    186180    pMainLayout->setContentsMargins(0, 0, 0, 0);
    187     //pMainLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
    188181
    189182    connect(m_pBackwardButton, &QIToolButton::pressed,
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