VirtualBox

Changeset 99115 in vbox for trunk


Ignore:
Timestamp:
Mar 22, 2023 1:11:49 PM (19 months ago)
Author:
vboxsync
Message:

Docs: bugref:10302. Fixing image zoom overlay functionality of our help viewer.

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

Legend:

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

    r98103 r99115  
    4242#include <QGraphicsBlurEffect>
    4343#include <QLabel>
     44#include <QMimeDatabase>
    4445#include <QPainter>
    4546#include <QScrollBar>
     
    410411    , m_iSearchTermLength(0)
    411412    , m_fOverlayMode(false)
    412     , m_fCursorChanged(false)
    413413    , m_pOverlayLabel(0)
    414414    , m_iZoomPercentage(100)
     
    427427    connect(m_pFindInPageWidget, &UIFindInPageWidget::sigClose,
    428428            this, &UIHelpViewer::sltCloseFindInPageWidget);
    429 
    430     m_defaultCursor = cursor();
    431     m_handCursor = QCursor(Qt::PointingHandCursor);
    432429
    433430    m_pFindInPageWidget->setVisible(false);
     
    675672void UIHelpViewer::mouseReleaseEvent(QMouseEvent *pEvent)
    676673{
     674    /* If overlay mode is active just clear it and return: */
    677675    bool fOverlayMode = m_fOverlayMode;
    678676    clearOverlay();
    679 
     677    if (fOverlayMode)
     678        return;
    680679    QString strAnchor = anchorAt(pEvent->pos());
    681680
    682681    if (!strAnchor.isEmpty())
    683682    {
    684 
    685683        QString strLink = source().resolved(strAnchor).toString();
    686 
     684        QFileInfo fInfo(strLink);
     685        QMimeDatabase base;
     686        QMimeType type = base.mimeTypeForFile(fInfo);
     687        if (type.isValid() && type.inherits("image/png"))
     688        {
     689            if (!fOverlayMode)
     690                loadImage(source().resolved(strAnchor));
     691            return;
     692        }
    687693        if (source().resolved(strAnchor).scheme() != "qthelp" && pEvent->button() == Qt::LeftButton)
    688694        {
     
    700706    }
    701707    QIWithRetranslateUI<QTextBrowser>::mousePressEvent(pEvent);
    702 
    703     if (!fOverlayMode)
    704         loadImageAtPosition(pEvent->globalPos());
    705708}
    706709
     
    710713}
    711714
    712 void UIHelpViewer::setImageOverCursor(QPoint globalPosition)
    713 {
    714     QPoint viewportCoordinates = viewport()->mapFromGlobal(globalPosition);
    715     QTextCursor cursor = cursorForPosition(viewportCoordinates);
    716     if (!m_fCursorChanged && cursor.charFormat().isImageFormat())
    717     {
    718         m_fCursorChanged = true;
    719         UICursor::setCursor(viewport(), m_handCursor);
    720         emit sigMouseOverImage(cursor.charFormat().toImageFormat().name());
    721     }
    722     if (m_fCursorChanged && !cursor.charFormat().isImageFormat())
    723     {
    724         UICursor::setCursor(viewport(), m_defaultCursor);
    725         m_fCursorChanged = false;
    726     }
    727 
    728 }
    729 
    730715void UIHelpViewer::mouseMoveEvent(QMouseEvent *pEvent)
    731716{
    732     if (m_fOverlayMode)
    733         return;
    734     setImageOverCursor(pEvent->globalPos());
     717    /*if (m_fOverlayMode)
     718        return;*/
    735719    QIWithRetranslateUI<QTextBrowser>::mouseMoveEvent(pEvent);
    736720}
     
    10211005{
    10221006    AssertReturnVoid(m_pOverlayLabel);
    1023     setImageOverCursor(cursor().pos());
    10241007
    10251008    if (!m_fOverlayMode)
     
    10381021    if (m_pOverlayBlurEffect)
    10391022        m_pOverlayBlurEffect->setEnabled(true);
    1040     UICursor::setCursor(viewport(), m_defaultCursor);
    1041     m_fCursorChanged = false;
    10421023    toggleFindInPageWidget(false);
    10431024
     
    10661047}
    10671048
    1068 void UIHelpViewer::loadImageAtPosition(const QPoint &globalPosition)
     1049void UIHelpViewer::loadImage(const QUrl &imageFileUrl)
    10691050{
    10701051    clearOverlay();
    1071     QPoint viewportCoordinates = viewport()->mapFromGlobal(globalPosition);
    1072     QTextCursor cursor = cursorForPosition(viewportCoordinates);
    1073     if (!cursor.charFormat().isImageFormat())
    1074         return;
    10751052    /* Dont zoom into image if mouse button released after a mouse drag: */
    10761053    if (textCursor().hasSelection())
    10771054        return;
    1078 
    1079     QTextImageFormat imageFormat = cursor.charFormat().toImageFormat();
    1080     QUrl imageFileUrl;
    1081     foreach (const QUrl &fileUrl, m_helpFileList)
    1082     {
    1083         if (fileUrl.toString().contains(imageFormat.name(), Qt::CaseInsensitive))
    1084         {
    1085             imageFileUrl = fileUrl;
    1086             break;
    1087         }
    1088     }
    1089 
    10901055    if (!imageFileUrl.isValid())
    10911056        return;
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpViewer.h

    r98103 r99115  
    4949  * rendering and didn't want to use WebKit module, this extension redraws the document images as overlays with improved QPainter
    5050  * parameters. There is also a small hack to render clicked image 1:1 (and the rest of the document blurred)
    51   * for a zoom-in-image functionality. This extension can also scale the images while scaling the document. In contrast
     51  * for a zoom-in-image functionality. This extension can also scale the images while scaling the document. In contrast,
    5252  * QTextBrowser scales only fonts. */
    5353class UIHelpViewer : public QIWithRetranslateUI<QTextBrowser>
     
    147147    void scaleFont();
    148148    void scaleImages();
    149     /** If there is image at @p globalPosition then its data is loaded to m_overlayPixmap. */
    150     void loadImageAtPosition(const QPoint &globalPosition);
     149    void loadImage(const QUrl &imageFileUrl);
    151150    void clearOverlay();
    152151    void enableOverlay();
    153     void setImageOverCursor(QPoint globalPosition);
    154152
    155153    const QHelpEngine* m_pHelpEngine;
     
    165163    /** A container to store the original image sizes/positions in the document. key is image name value is DocumentImage. */
    166164    QHash<QString, DocumentImage> m_imageMap;
    167     /** Used to change th document cursor back from m_handCursor. */
    168     QCursor m_defaultCursor;
    169     QCursor m_handCursor;
    170165    /** We need this list from th QHelp system to obtain information of images. */
    171166    QList<QUrl> m_helpFileList;
    172167    QPixmap m_overlayPixmap;
    173168    bool m_fOverlayMode;
    174     bool m_fCursorChanged;
    175169    QLabel *m_pOverlayLabel;
    176170    QGraphicsBlurEffect *m_pOverlayBlurEffect;
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