VirtualBox

Changeset 77724 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 15, 2019 1:21:41 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9376: Cursor drawing functionality, initial implementation.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp

    r77703 r77724  
    2525#include "UIActionPool.h"
    2626#include "UIActionPoolRuntime.h"
     27#include "UIConsoleEventHandler.h"
    2728#include "UIFrameBuffer.h"
    2829#include "UISession.h"
     
    273274    virtual void viewportScrolled(int, int) {}
    274275#endif /* VBOX_WITH_VIDEOHWACCEL */
     276
     277protected slots:
     278
     279    /** Handles guest request to change the cursor position to @a uX * @a uY.
     280      * @param  fContainsData  Brings whether the @a uX and @a uY values are valid and could be used by the GUI now. */
     281    void sltCursorPositionChange(bool fContainsData, unsigned long uX, unsigned long uY);
    275282
    276283protected:
     
    388395     /** Identifier returned by AttachFramebuffer. Used in DetachFramebuffer. */
    389396     QUuid m_uFramebufferId;
     397
     398     /** Holds whether cursor position is valid. */
     399     bool   m_fCursorPositionValid;
     400     /** Holds the last cursor rectangle. */
     401     QRect  m_cursorRectangle;
    390402};
    391403
     
    530542    , m_dDevicePixelRatioActual(1.0)
    531543    , m_fUseUnscaledHiDPIOutput(false)
     544    , m_fCursorPositionValid(false)
    532545{
    533546    /* Update coordinate-system: */
     
    12901303}
    12911304
     1305void UIFrameBufferPrivate::sltCursorPositionChange(bool fContainsData, unsigned long uX, unsigned long uY)
     1306{
     1307    /* Remember whether cursor position is valid: */
     1308    m_fCursorPositionValid = fContainsData;
     1309
     1310    /* Do we have view and valid cursor position? */
     1311    if (m_pMachineView && m_fCursorPositionValid)
     1312    {
     1313        /* Acquire cursor position and size: */
     1314        QPoint cursorPosition = QPoint(uX, uY);
     1315        QSize cursorSize = m_pMachineView->uisession()->cursorSize();
     1316
     1317        /* Apply the scale-factor if necessary: */
     1318        cursorPosition *= scaleFactor();
     1319        cursorSize *= scaleFactor();
     1320
     1321        /* Take the device-pixel-ratio into account: */
     1322        if (!useUnscaledHiDPIOutput())
     1323        {
     1324            cursorPosition *= devicePixelRatioActual();
     1325            cursorSize *= devicePixelRatioActual();
     1326        }
     1327        cursorPosition /= devicePixelRatio();
     1328        cursorSize /= devicePixelRatio();
     1329
     1330        /* Call for a viewport update, we need to update cumulative
     1331         * region containing previous and current cursor rectagles. */
     1332        const QRect cursorRectangle = QRect(cursorPosition, cursorSize);
     1333        m_pMachineView->viewport()->update(QRegion(m_cursorRectangle) + cursorRectangle);
     1334
     1335        /* Remember current cursor rectangle: */
     1336        m_cursorRectangle = cursorRectangle;
     1337    }
     1338}
     1339
    12921340void UIFrameBufferPrivate::prepareConnections()
    12931341{
     
    13051353            m_pMachineView, SLOT(sltHandle3DOverlayVisibilityChange(bool)),
    13061354            Qt::QueuedConnection);
     1355
     1356    /* Attach GUI connections: */
     1357    connect(gConsoleEvents, &UIConsoleEventHandler::sigCursorPositionChange,
     1358            this, &UIFrameBufferPrivate::sltCursorPositionChange);
    13071359}
    13081360
     
    13181370    disconnect(this, SIGNAL(sigNotifyAbout3DOverlayVisibilityChange(bool)),
    13191371               m_pMachineView, SLOT(sltHandle3DOverlayVisibilityChange(bool)));
     1372
     1373    /* Detach GUI connections: */
     1374    disconnect(gConsoleEvents, &UIConsoleEventHandler::sigCursorPositionChange,
     1375               this, &UIFrameBufferPrivate::sltCursorPositionChange);
    13201376}
    13211377
     
    14071463        pSourceImage = 0;
    14081464    }
     1465
     1466    /* Paint cursor if it has valid shape and position: */
     1467    if (m_pMachineView->uisession()->isValidPointerShapePresent() && m_fCursorPositionValid)
     1468    {
     1469        /* Acquire session cursor pixmap: */
     1470        QPixmap cursorPixmap = m_pMachineView->uisession()->cursorPixmap();
     1471
     1472        /* Take the device-pixel-ratio into account: */
     1473        cursorPixmap.setDevicePixelRatio(devicePixelRatio());
     1474
     1475        /* Draw sub-pixmap: */
     1476        painter.drawPixmap(m_cursorRectangle.topLeft(), cursorPixmap);
     1477    }
    14091478}
    14101479
     
    14971566        pSourceImage = 0;
    14981567    }
     1568
     1569    /* Paint cursor if it has valid shape and position: */
     1570    if (m_pMachineView->uisession()->isValidPointerShapePresent() && m_fCursorPositionValid)
     1571    {
     1572        /* Acquire session cursor pixmap: */
     1573        QPixmap cursorPixmap = m_pMachineView->uisession()->cursorPixmap();
     1574
     1575        /* Take the device-pixel-ratio into account: */
     1576        cursorPixmap.setDevicePixelRatio(devicePixelRatio());
     1577
     1578        /* Draw sub-pixmap: */
     1579        painter.drawPixmap(m_cursorRectangle.topLeft(), cursorPixmap);
     1580    }
    14991581}
    15001582
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r76613 r77724  
    628628    /* Notify listeners about mouse capability changed: */
    629629    emit sigMousePointerShapeChange();
    630 
    631630}
    632631
     
    18311830
    18321831#endif
     1832
     1833    /* Cache cursor pixmap data: */
     1834    m_cursorPixmap = m_cursor.pixmap();
     1835    m_cursorSize = m_cursorPixmap.size();
    18331836}
    18341837
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r76581 r77724  
    2727#include <QEvent>
    2828#include <QMap>
     29#include <QPixmap>
    2930
    3031/* GUI includes: */
     
    132133    WId mainMachineWindowId() const;
    133134    UIMachineWindow *activeMachineWindow() const;
     135
     136    /** Returns currently cached mouse cursor. */
    134137    QCursor cursor() const { return m_cursor; }
     138    /** Returns currently cached mouse cursor pixmap. */
     139    QPixmap cursorPixmap() const { return m_cursorPixmap; }
     140    /** Returns currently cached mouse cursor size. */
     141    QSize cursorSize() const { return m_cursorSize; }
    135142
    136143    /** @name Branding stuff.
     
    476483    KMachineState m_machineStatePrevious;
    477484    KMachineState m_machineState;
    478     QCursor m_cursor;
     485
     486    /** Holds cached mouse cursor. */
     487    QCursor  m_cursor;
     488    /** Holds cached mouse cursor pixmap. */
     489    QPixmap  m_cursorPixmap;
     490    /** Holds cached mouse cursor size. */
     491    QSize    m_cursorSize;
    479492
    480493    /** @name Branding variables.
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