VirtualBox

Changeset 88423 in vbox for trunk


Ignore:
Timestamp:
Apr 8, 2021 6:08:52 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Implementing click and enlarge thingy

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

Legend:

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

    r88419 r88423  
    203203    int zoomPercentage() const;
    204204    void setZoomPercentage(int iZoomPercentage);
     205    void setHelpFileList(const QList<QUrl> &helpFileList);
    205206
    206207private slots:
     
    276277    /** Sets the zoom percentage of all tabs. */
    277278    void setZoomPercentage(int iZoomPercentage);
     279    void setHelpFileList(const QList<QUrl> &helpFileList);
    278280
    279281public slots:
     
    318320    bool m_fToolBarVisible;
    319321    QStringList m_tabTitleList;
     322    QList<QUrl> m_helpFileList;
    320323};
    321324
     
    586589    if (m_pContentViewer)
    587590        m_pContentViewer->setZoomPercentage(iZoomPercentage);
     591}
     592
     593void UIHelpBrowserTab::setHelpFileList(const QList<QUrl> &helpFileList)
     594{
     595    if (m_pContentViewer)
     596        m_pContentViewer->setHelpFileList(helpFileList);
    588597}
    589598
     
    836845
    837846    pTabWidget->setZoomPercentage(zoomPercentage());
     847    pTabWidget->setHelpFileList(m_helpFileList);
    838848
    839849    if (!fBackground)
     
    10171027}
    10181028
     1029void UIHelpBrowserTabManager::setHelpFileList(const QList<QUrl> &helpFileList)
     1030{
     1031    m_helpFileList = helpFileList;
     1032}
    10191033
    10201034void UIHelpBrowserTabManager::sltHandletabTitleChange(const QString &strTitle)
     
    12991313    m_pTabWidget = new QITabWidget;
    13001314    m_pTabManager = new UIHelpBrowserTabManager(m_pHelpEngine, findIndexHtml(), loadSavedUrlList());
     1315    m_pTabManager->setHelpFileList(m_pHelpEngine->files(m_pHelpEngine->namespaceName(m_strHelpFilePath), QStringList()));
    13011316
    13021317    AssertReturnVoid(m_pTabWidget &&
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.cpp

    r88418 r88423  
    3030#include <QMenu>
    3131#include <QHBoxLayout>
     32#include <QGraphicsBlurEffect>
     33#include <QLabel>
     34#include <QPainter>
    3235#include <QScrollBar>
    3336#include <QTextBlock>
     
    342345    , m_iSearchTermLength(0)
    343346    , m_iZoomPercentage(100)
     347    , m_fImageOverlay(false)
     348    , m_pOverlayWidget(0)
     349    , m_pOverlayLabel(0)
    344350{
    345351    m_iInitialFontPointSize = font().pointSize();
     
    357363            this, &UIHelpViewer::sigCloseFindInPageWidget);
    358364
     365    m_defaultCursor = cursor();
     366    m_handCursor = QCursor(Qt::PointingHandCursor);
     367
    359368    m_pFindInPageWidget->setVisible(false);
     369
     370
     371    m_pOverlayWidget = new QWidget(this);
     372    QHBoxLayout *overlayLayout = new QHBoxLayout(m_pOverlayWidget);
     373    m_pOverlayLabel = new QLabel;
     374    overlayLayout->addWidget(m_pOverlayLabel);
     375    m_pOverlayWidget->hide();
     376
     377    m_pOverlayBlurEffect = new QGraphicsBlurEffect(this);
     378    viewport()->setGraphicsEffect(m_pOverlayBlurEffect);
     379    m_pOverlayBlurEffect->setEnabled(false);
     380    m_pOverlayBlurEffect->setBlurRadius(8);
    360381    retranslateUi();
    361382}
     
    468489}
    469490
     491void UIHelpViewer::setHelpFileList(const QList<QUrl> &helpFileList)
     492{
     493    m_helpFileList = helpFileList;
     494}
    470495
    471496int UIHelpViewer::zoomPercentage() const
     
    546571void UIHelpViewer::wheelEvent(QWheelEvent *pEvent)
    547572{
     573    if (m_fImageOverlay)
     574        return;
     575
    548576    /* QTextBrowser::wheelEvent scales font when some modifiers are pressed. We dont want: */
    549577    if (pEvent && pEvent->modifiers() == Qt::NoModifier)
     
    553581void UIHelpViewer::mousePressEvent(QMouseEvent *pEvent)
    554582{
     583    if (m_fImageOverlay)
     584        clearOverlay();
     585
     586    QIWithRetranslateUI<QTextBrowser>::mousePressEvent(pEvent);
     587
    555588    QString strAnchor = anchorAt(pEvent->pos());
    556589    if (!strAnchor.isEmpty())
     
    563596        }
    564597    }
    565     QIWithRetranslateUI<QTextBrowser>::mousePressEvent(pEvent);
     598
     599    loadImageAtPosition(pEvent->globalPos());
     600}
     601
     602void UIHelpViewer::mouseMoveEvent(QMouseEvent *pEvent)
     603{
     604    if (m_fImageOverlay)
     605        return;
     606
     607    QIWithRetranslateUI<QTextBrowser>::mouseMoveEvent(pEvent);
     608
     609    QPoint viewportCoordinates = viewport()->mapFromGlobal(pEvent->globalPos());
     610    QTextCursor cursor = cursorForPosition(viewportCoordinates);
     611    if (cursor.charFormat().isImageFormat())
     612        viewport()->setCursor(m_handCursor);
     613    else
     614        viewport()->setCursor(m_defaultCursor);
     615}
     616
     617void UIHelpViewer::mouseDoubleClickEvent(QMouseEvent *pEvent)
     618{
     619    if (m_fImageOverlay)
     620        clearOverlay();
     621
     622    QIWithRetranslateUI<QTextBrowser>::mouseDoubleClickEvent(pEvent);
     623}
     624
     625void UIHelpViewer::paintEvent(QPaintEvent *pEvent)
     626{
     627    QIWithRetranslateUI<QTextBrowser>::paintEvent(pEvent);
     628    // if (m_pOverlayBlurEffect && m_pOverlayBlurEffect->isEnabled())
     629    //     m_pOverlayBlurEffect->setEnabled(false);
     630
     631    if (m_pOverlayLabel && m_pOverlayWidget)
     632    {
     633        if (m_fImageOverlay)
     634        {
     635
     636            // QPainter painter(viewport());
     637            // painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
     638            QSize size(0.8 * width(), 0.8 * height());
     639            m_pOverlayLabel->setPixmap(m_overlayPixmap.scaled(size,  Qt::KeepAspectRatio, Qt::SmoothTransformation));
     640            m_pOverlayWidget->move(0.1 * width(), 0.1 * height());
     641            m_pOverlayWidget->show();
     642            // QRect rect(10, 10, 0.4 * width() - 20, height() - 20);
     643            // painter.drawPixmap(rect, m_overlayPixmap);
     644            //painter.fillRect(rect, Qt::red);
     645        }
     646        else
     647            m_pOverlayWidget->hide();
     648
     649    }
    566650}
    567651
     
    776860}
    777861
     862void UIHelpViewer::clearOverlay()
     863{
     864    m_overlayPixmap = QPixmap();
     865    m_fImageOverlay = false;
     866    if (m_pOverlayBlurEffect)
     867        m_pOverlayBlurEffect->setEnabled(false);
     868}
     869
     870void UIHelpViewer::loadImageAtPosition(const QPoint &globalPosition)
     871{
     872    clearOverlay();
     873    QPoint viewportCoordinates = viewport()->mapFromGlobal(globalPosition);
     874    QTextCursor cursor = cursorForPosition(viewportCoordinates);
     875    if (!cursor.charFormat().isImageFormat())
     876        return;
     877
     878    QTextImageFormat imageFormat = cursor.charFormat().toImageFormat();
     879    QUrl imageFileUrl;
     880    foreach (const QUrl &fileUrl, m_helpFileList)
     881    {
     882        if (fileUrl.toString().contains(imageFormat.name(), Qt::CaseInsensitive))
     883        {
     884            imageFileUrl = fileUrl;
     885            break;
     886        }
     887    }
     888
     889    if (!imageFileUrl.isValid())
     890        return;
     891    QByteArray fileData = m_pHelpEngine->fileData(imageFileUrl);
     892    if (!fileData.isEmpty())
     893    {
     894        m_overlayPixmap.loadFromData(fileData,"PNG");
     895        if (!m_overlayPixmap.isNull())
     896        {
     897            m_fImageOverlay = true;
     898            if (m_pOverlayBlurEffect)
     899                m_pOverlayBlurEffect->setEnabled(true);
     900            viewport()->setCursor(m_defaultCursor);
     901        }
     902    }
     903}
    778904
    779905#include "UIHelpViewer.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h

    r88418 r88423  
    3030/* Forward declarations: */
    3131class QHelpEngine;
     32class QGraphicsBlurEffect;
     33class QLabel;
    3234class UIFindInPageWidget;
    3335
     
    6971    int zoomPercentage() const;
    7072    void setZoomPercentage(int iZoomPercentage);
     73    void setHelpFileList(const QList<QUrl> &helpFileList);
    7174
    7275    static const QPair<int, int> zoomPercentageMinMax;
     
    8285    virtual void wheelEvent(QWheelEvent *pEvent) /* override */;
    8386    virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
     87    virtual void mouseMoveEvent(QMouseEvent *pEvent) /* override */;
     88    virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) /* override */;
     89    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
    8490
    8591private slots:
     
    110116    void scaleFont();
    111117    void scaleImages();
     118    /** If there is image at @p globalPosition then its data is loaded to m_overlayPixmap. */
     119    void loadImageAtPosition(const QPoint &globalPosition);
     120    void clearOverlay();
     121
    112122    const QHelpEngine* m_pHelpEngine;
    113123    UIFindInPageWidget *m_pFindInPageWidget;
     
    124134    /** As percentage. */
    125135    int m_iZoomPercentage;
     136    QCursor m_defaultCursor;
     137    QCursor m_handCursor;
     138    QList<QUrl> m_helpFileList;
     139    QPixmap m_overlayPixmap;
     140    bool m_fImageOverlay;
     141
     142    QWidget *m_pOverlayWidget;
     143    QLabel *m_pOverlayLabel;
     144    QGraphicsBlurEffect *m_pOverlayBlurEffect;
    126145};
    127146
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