VirtualBox

Changeset 86747 in vbox


Ignore:
Timestamp:
Oct 28, 2020 7:01:14 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141139
Message:

FE/Qt: bugref:9831. Adding ad address bar

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

Legend:

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

    r86736 r86747  
    1717
    1818/* Qt includes: */
     19#include <QComboBox>
    1920#include <QDateTime>
    2021#include <QDir>
     
    2829#include <QMenu>
    2930#include <QScrollBar>
     31#include <QSpacerItem>
    3032#include <QStyle>
    3133#include <QSplitter>
     
    6062Q_DECLARE_METATYPE(HelpBrowserTabs);
    6163
     64class UIHelpBrowserAddressBar : public QComboBox
     65{
     66    Q_OBJECT;
     67
     68public:
     69    UIHelpBrowserAddressBar(QWidget *pParent = 0);
     70
     71};
     72
    6273class UIHelpBrowserViewer : public QTextBrowser
    6374{
     
    6879    UIHelpBrowserViewer(const QHelpEngine *pHelpEngine, QWidget *pParent = 0);
    6980    virtual QVariant loadResource(int type, const QUrl &name) /* override */;
     81    void emitHistoryChangedSignal();
     82
     83public slots:
     84
     85    //virtual void setSource(const QUrl &name) /* override */;
    7086
    7187private:
     
    7591#endif
    7692};
     93
     94UIHelpBrowserAddressBar::UIHelpBrowserAddressBar(QWidget *pParent /* = 0 */)
     95    :QComboBox(pParent)
     96{
     97}
    7798
    7899UIHelpBrowserViewer::UIHelpBrowserViewer(const QHelpEngine *pHelpEngine, QWidget *pParent /* = 0 */)
     
    99120}
    100121
     122void UIHelpBrowserViewer::emitHistoryChangedSignal()
     123{
     124    emit historyChanged();
     125    emit backwardAvailable(true);
     126}
    101127
    102128UIHelpBrowserWidget::UIHelpBrowserWidget(EmbedTo enmEmbedding,
     
    109135    , m_fIsPolished(false)
    110136    , m_pMainLayout(0)
     137    , m_pTopLayout(0)
    111138    , m_pTabWidget(0)
    112139    , m_pToolBar(0)
     
    115142    , m_pHelpEngine(0)
    116143#endif
     144    , m_pAddressBar(0)
    117145    , m_pContentViewer(0)
    118146    , m_pSplitter(0)
     
    227255    connect(m_pContentViewer, &UIHelpBrowserViewer::sourceChanged,
    228256        this, &UIHelpBrowserWidget::sltHandleHelpBrowserViewerSourceChange);
     257    connect(m_pContentViewer, &UIHelpBrowserViewer::historyChanged,
     258        this, &UIHelpBrowserWidget::sltHandleHistoryChanged);
    229259
    230260    m_pSplitter->addWidget(m_pContentViewer);
     
    249279#endif
    250280}
    251 
     281#include <QPushButton>
    252282void UIHelpBrowserWidget::prepareToolBar()
    253283{
     284    m_pTopLayout = new QHBoxLayout;
    254285    /* Create toolbar: */
    255286    m_pToolBar = new QIToolBar(parentWidget());
     
    269300        {
    270301            /* Add into layout: */
    271             m_pMainLayout->addWidget(m_pToolBar);
     302            m_pTopLayout->addWidget(m_pToolBar);
     303            m_pMainLayout->addLayout(m_pTopLayout);
    272304        }
    273305#else
    274306        /* Add into layout: */
    275         m_pMainLayout->addWidget(m_pToolBar);
    276 #endif
    277     }
     307        m_pTopLayout->addWidget(m_pToolBar);
     308        m_pMainLayout->addLayout(m_pTopLayout);
     309#endif
     310    }
     311    m_pAddressBar = new UIHelpBrowserAddressBar();
     312    m_pAddressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     313    m_pTopLayout->addWidget(m_pAddressBar);
     314    connect(m_pAddressBar, static_cast<void(UIHelpBrowserAddressBar::*)(int)>(&UIHelpBrowserAddressBar::currentIndexChanged),
     315            this, &UIHelpBrowserWidget::sltHandleAddressBarIndexChanged);
     316
     317    //m_pTopLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
    278318}
    279319
     
    299339        {
    300340            if (m_pHelpEngine->findFile(url).isValid())
     341            {
    301342                m_pContentViewer->setSource(url);
     343                m_pContentViewer->clearHistory();
     344            }
    302345            else
    303346                show404Error(url);
     
    469512    m_pContentViewer->setSource(url);
    470513    m_pContentViewer->blockSignals(false);
     514    /* emit historyChanged signal explicitly since we have blocked the signals: */
     515    m_pContentViewer->emitHistoryChangedSignal();
    471516#else
    472517    Q_UNUSED(index);
     
    537582}
    538583
     584void UIHelpBrowserWidget::sltHandleHistoryChanged()
     585{
     586    if (!m_pContentViewer)
     587        return;
     588    int iCurrentIndex = 0;
     589    /* QTextBrower history has negative and positive indices for bacward and forward items, respectively.
     590     * 0 is the current item: */
     591    m_pAddressBar->blockSignals(true);
     592    m_pAddressBar->clear();
     593    for (int i = -1 * m_pContentViewer->backwardHistoryCount(); i <= m_pContentViewer->forwardHistoryCount(); ++i)
     594    {
     595        m_pAddressBar->addItem(m_pContentViewer->historyTitle(i), i);
     596        if (i == 0)
     597            iCurrentIndex = m_pAddressBar->count();
     598    }
     599    /* Make sure address bar show the current item: */
     600    m_pAddressBar->setCurrentIndex(iCurrentIndex - 1);
     601    m_pAddressBar->blockSignals(false);
     602}
     603
     604void UIHelpBrowserWidget::sltHandleAddressBarIndexChanged(int iIndex)
     605{
     606    if (!m_pAddressBar && iIndex >= m_pAddressBar->count())
     607        return;
     608    int iHistoryIndex = m_pAddressBar->itemData(iIndex).toInt();
     609    /* There seems to be no way to one-step-jump to a history item: */
     610    if (iHistoryIndex == 0)
     611        return;
     612    else if (iHistoryIndex > 0)
     613        for (int i = 0; i < iHistoryIndex; ++i)
     614            m_pContentViewer->forward();
     615    else
     616        for (int i = 0; i > iHistoryIndex ; --i)
     617            m_pContentViewer->backward();
     618
     619}
     620
    539621#include "UIHelpBrowserWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86736 r86747  
    3737
    3838/* Forward declarations: */
     39class QHBoxLayout;
    3940class QVBoxLayout;
    4041class QHelpEngine;
     
    4849class UIActionPool;
    4950class UIDialogPanel;
     51class UIHelpBrowserAddressBar;
    5052class UIHelpBrowserViewer;
    5153
     
    8991    void sltHandleForwardAvailable(bool fAvailable);
    9092    void sltHandleBackwardAvailable(bool fAvailable);
     93    void sltHandleHistoryChanged();
     94    void sltHandleAddressBarIndexChanged(int index);
    9195
    9296private:
     
    126130    /** Holds container for log-pages. */
    127131    QVBoxLayout         *m_pMainLayout;
     132    QHBoxLayout         *m_pTopLayout;
     133
    128134    QITabWidget *m_pTabWidget;
    129135    /** @name Toolbar and menu variables.
     
    136142    QHelpEngine  *m_pHelpEngine;
    137143#endif
     144    UIHelpBrowserAddressBar *m_pAddressBar;
    138145    UIHelpBrowserViewer *m_pContentViewer;
    139146    QSplitter           *m_pSplitter;
Note: See TracChangeset for help on using the changeset viewer.

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