VirtualBox

Changeset 86812 in vbox


Ignore:
Timestamp:
Nov 5, 2020 1:50:30 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141253
Message:

FE/Qt: bugref:9831. Adding a search widget to in-page string searches

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/VirtualBox1.qrc

    r86735 r86812  
    163163        <file alias="drag_drop_16px.png">images/drag_drop_16px.png</file>
    164164        <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>
    165166        <file alias="edata_add_16px.png">images/edata_add_16px.png</file>
    166167        <file alias="edata_add_24px.png">images/edata_add_24px.png</file>
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r86807 r86812  
    3030 #include <QtHelp/QHelpSearchResultWidget>
    3131#endif
     32#include <QLabel>
    3233#include <QMenu>
    3334#include <QMouseEvent>
     35#include <QPixmap>
    3436#include <QScrollBar>
    3537#include <QSpacerItem>
     
    4345
    4446/* GUI includes: */
     47#include "UICommon.h"
    4548#include "QIFileDialog.h"
    4649#include "QITabWidget.h"
     50#include "QIToolBar.h"
     51#include "QIToolButton.h"
    4752#include "UIActionPool.h"
    4853#include "UIExtraDataManager.h"
     54#include "UIHelpBrowserWidget.h"
    4955#include "UIIconPool.h"
    5056#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
    5659
    5760/* COM includes: */
     
    6366{
    6467    HelpBrowserTabs_TOC = 0,
    65     HelpBrowserTabs_Index,
    6668    HelpBrowserTabs_Search,
    6769    HelpBrowserTabs_Bookmarks,
     70    HelpBrowserTabs_Index,
    6871    HelpBrowserTabs_Max
    6972};
    7073Q_DECLARE_METATYPE(HelpBrowserTabs);
    7174
     75
     76/*********************************************************************************************************************************
     77*   UIFindInPageWidget definition.                                                                                        *
     78*********************************************************************************************************************************/
     79class UIFindInPageWidget : public QIWithRetranslateUI<QWidget>
     80{
     81
     82    Q_OBJECT;
     83
     84signals:
     85
     86    void sigDragging(const QPoint &delta);
     87
     88public:
     89
     90    UIFindInPageWidget(QWidget *pParent = 0);
     91
     92protected:
     93
     94    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     95
     96private:
     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};
    72106
    73107/*********************************************************************************************************************************
     
    96130
    97131    void contextMenuEvent(QContextMenuEvent *event) /* override */;
     132    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
     133    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    98134
    99135private slots:
    100136
    101137    void sltHandleOpenInNewTab();
     138    void sltHandleFindWidgetDrag(const QPoint &delta);
    102139
    103140private:
     
    105142    void retranslateUi();
    106143    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;
    107147};
    108148
     
    129169    void setSource(const QUrl &url);
    130170    QString documentTitle() const;
     171    void setToolBarVisible(bool fVisible);
    131172
    132173private slots:
     
    151192    QAction     *m_pBackwardAction;
    152193    QAction     *m_pAddBookmarkAction;
     194    QAction     *m_pFindInPageAction;
    153195
    154196    QVBoxLayout *m_pMainLayout;
    155197    QIToolBar   *m_pToolBar;
    156     QComboBox *m_pAddressBar;
     198    QComboBox   *m_pAddressBar;
    157199    UIHelpBrowserViewer *m_pContentViewer;
    158200    const QHelpEngine* m_pHelpEngine;
     
    185227    /* Return the list of urls of all open tabs as QStringList. */
    186228    QStringList tabUrlList();
     229    void setToolBarVisible(bool fVisible);
    187230
    188231private slots:
     
    205248
    206249/*********************************************************************************************************************************
     250*   UIFindInPageWidget implementation.                                                                                        *
     251*********************************************************************************************************************************/
     252UIFindInPageWidget::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
     262bool 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
     282void 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
     317void UIFindInPageWidget::retranslateUi()
     318{
     319}
     320
     321/*********************************************************************************************************************************
    207322*   UIHelpBrowserTab implementation.                                                                                        *
    208323*********************************************************************************************************************************/
     
    215330    , m_pBackwardAction(0)
    216331    , m_pAddBookmarkAction(0)
     332    , m_pFindInPageAction(0)
    217333    , m_pMainLayout(0)
    218334    , m_pToolBar(0)
     
    252368        return QString();
    253369    return m_pContentViewer->documentTitle();
     370}
     371
     372void UIHelpBrowserTab::setToolBarVisible(bool fVisible)
     373{
     374    if (m_pToolBar)
     375        m_pToolBar->setVisible(fVisible);
     376    if (m_pAddressBar)
     377        m_pAddressBar->setVisible(fVisible);
    254378}
    255379
     
    293417    m_pAddBookmarkAction =
    294418        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);
    295421
    296422    connect(m_pHomeAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleHomeAction);
     
    308434    m_pToolBar->addAction(m_pHomeAction);
    309435    m_pToolBar->addAction(m_pAddBookmarkAction);
     436    m_pToolBar->addAction(m_pFindInPageAction);
    310437
    311438    m_pAddressBar = new QComboBox();
     
    427554    :QIWithRetranslateUI<QTextBrowser>(pParent)
    428555    , 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);
    431561    retranslateUi();
    432562}
     
    471601    delete pMenu;
    472602}
     603
     604void 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
     614void 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
    473625
    474626void UIHelpBrowserViewer::retranslateUi()
     
    486638}
    487639
     640void 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}
    488656
    489657/*********************************************************************************************************************************
     
    559727    }
    560728    return list;
     729}
     730
     731void 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    }
    561740}
    562741
     
    636815    , m_pHelpEngine(0)
    637816    , m_pSplitter(0)
    638     , m_pMenu(0)
     817    , m_pFileMenu(0)
     818    , m_pViewMenu(0)
    639819    , m_pContentWidget(0)
    640820    , m_pIndexWidget(0)
     
    663843QMenu *UIHelpBrowserWidget::menu() const
    664844{
    665     return m_pMenu;
     845    return m_pViewMenu;
    666846}
    667847
     
    764944    AssertReturnVoid(m_pSearchQueryWidget && m_pSearchResultWidget);
    765945    m_pSearchResultWidget->setContextMenuPolicy(Qt::CustomContextMenu);
     946    m_pSearchQueryWidget->setCompactMode(false);
    766947
    767948    QVBoxLayout *pSearchLayout = new QVBoxLayout(m_pSearchContainerWidget);
     
    8271008void UIHelpBrowserWidget::prepareMenu()
    8281009{
    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);
    8341017
    8351018}
     
    9711154void UIHelpBrowserWidget::sltHandleToolBarVisibility(bool fToggled)
    9721155{
    973     if (m_pToolBar)
    974         m_pToolBar->setVisible(fToggled);
     1156    if (m_pTabManager)
     1157        m_pTabManager->setToolBarVisible(fToggled);
    9751158}
    9761159
     
    10601243            return;
    10611244        QPoint browserPos = browser->mapFromGlobal(m_pSearchResultWidget->mapToGlobal(pos));
    1062         printf("pos %d %d\n", pos.x(), pos.y());
    10631245        url = browser->anchorAt(browserPos);
    10641246    }
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86807 r86812  
    150150    QHelpEngine  *m_pHelpEngine;
    151151    QSplitter           *m_pSplitter;
    152     QMenu               *m_pMenu;
     152    QMenu               *m_pFileMenu;
     153    QMenu               *m_pViewMenu;
    153154    QHelpContentWidget  *m_pContentWidget;
    154155    QHelpIndexWidget    *m_pIndexWidget;
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