VirtualBox

Changeset 82032 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Nov 20, 2019 4:21:59 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134836
Message:

FE/Qt: bugref:9598: UISession, UIMachineView and UIMouseHandler: Now the curious one, mouse pointer shape scaling should be done on per-screen basis, so we had to move corresponding functionality from session to particular machine-view and keep proper signal order hierarchy accordingly; This will probably break frame-buffer cursor functionality.

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

Legend:

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

    r82030 r82032  
    1717
    1818/* Qt includes: */
     19#include <QBitmap>
    1920#include <QMainWindow>
    2021#include <QPainter>
     
    620621}
    621622
     623void UIMachineView::sltMousePointerShapeChange()
     624{
     625    /* Fetch the shape and the mask: */
     626    QPixmap pixmapShape = uisession()->cursorShapePixmap();
     627    QPixmap pixmapMask = uisession()->cursorMaskPixmap();
     628    const QPoint hotspot = uisession()->cursorHotspot();
     629    uint uXHot = hotspot.x();
     630    uint uYHot = hotspot.y();
     631
     632    /* If there is no mask: */
     633    if (pixmapMask.isNull())
     634    {
     635        /* Scale the shape pixmap and
     636         * compose the cursor on the basis of shape only: */
     637        updateMousePointerPixmapScaling(pixmapShape, uXHot, uYHot);
     638        m_cursor = QCursor(pixmapShape, uXHot, uYHot);
     639    }
     640    /* Otherwise: */
     641    else
     642    {
     643        /* Scale the shape and the mask pixmaps and
     644         * compose the cursor on the basis of shape and mask both: */
     645        updateMousePointerPixmapScaling(pixmapShape, uXHot, uYHot);
     646        /// @todo updateMousePointerPixmapScaling(pixmapMask, uXHot, uYHot);
     647        m_cursor = QCursor(pixmapShape, pixmapMask, uXHot, uYHot);
     648    }
     649
     650    /* Let the listeners know: */
     651    emit sigMousePointerShapeChange();
     652}
     653
    622654UIMachineView::UIMachineView(  UIMachineWindow *pMachineWindow
    623655                             , ulong uScreenId
     
    837869    connect(uisession(), &UISession::sigMachineStateChange, this, &UIMachineView::sltMachineStateChanged);
    838870    /* Mouse pointer shape updater: */
    839     connect(uisession(), &UISession::sigMousePointerShapeChange, this, &UIMachineView::sigMousePointerShapeChange);
     871    connect(uisession(), &UISession::sigMousePointerShapeChange, this, &UIMachineView::sltMousePointerShapeChange);
    840872}
    841873
     
    19101942    return size;
    19111943}
     1944
     1945void UIMachineView::updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot)
     1946{
     1947#if defined(VBOX_WS_MAC)
     1948
     1949    /* Take into account scale-factor if necessary: */
     1950    const double dScaleFactor = frameBuffer()->scaleFactor();
     1951    //printf("Scale-factor: %f\n", dScaleFactor);
     1952    if (dScaleFactor > 1.0)
     1953    {
     1954        /* Scale the pixmap up: */
     1955        pixmap = pixmap.scaled(pixmap.width() * dScaleFactor, pixmap.height() * dScaleFactor,
     1956                               Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     1957        uXHot *= dScaleFactor;
     1958        uYHot *= dScaleFactor;
     1959    }
     1960
     1961    /* Take into account device-pixel-ratio if necessary: */
     1962    const double dDevicePixelRatio = frameBuffer()->devicePixelRatio();
     1963    const bool fUseUnscaledHiDPIOutput = frameBuffer()->useUnscaledHiDPIOutput();
     1964    //printf("Device-pixel-ratio: %f, Unscaled HiDPI Output: %d\n",
     1965    //       dDevicePixelRatio, fUseUnscaledHiDPIOutput);
     1966    if (dDevicePixelRatio > 1.0 && fUseUnscaledHiDPIOutput)
     1967    {
     1968        /* Scale the pixmap down: */
     1969        pixmap.setDevicePixelRatio(dDevicePixelRatio);
     1970        uXHot /= dDevicePixelRatio;
     1971        uYHot /= dDevicePixelRatio;
     1972    }
     1973
     1974#elif defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
     1975
     1976    /* We want to scale the pixmap just once, so let's prepare cumulative multiplier: */
     1977    double dScaleMultiplier = 1.0;
     1978
     1979    /* Take into account scale-factor if necessary: */
     1980    const double dScaleFactor = frameBuffer()->scaleFactor();
     1981    //printf("Scale-factor: %f\n", dScaleFactor);
     1982    if (dScaleFactor > 1.0)
     1983        dScaleMultiplier *= dScaleFactor;
     1984
     1985    /* Take into account device-pixel-ratio if necessary: */
     1986# ifdef VBOX_WS_WIN
     1987    const double dDevicePixelRatio = frameBuffer()->devicePixelRatio();
     1988# endif
     1989    const double dDevicePixelRatioActual = frameBuffer()->devicePixelRatioActual();
     1990    const bool fUseUnscaledHiDPIOutput = frameBuffer()->useUnscaledHiDPIOutput();
     1991    //printf("Device-pixel-ratio/actual: %f/%f, Unscaled HiDPI Output: %d\n",
     1992    //       dDevicePixelRatio, dDevicePixelRatioActual, fUseUnscaledHiDPIOutput);
     1993    if (dDevicePixelRatioActual > 1.0 && !fUseUnscaledHiDPIOutput)
     1994        dScaleMultiplier *= dDevicePixelRatioActual;
     1995
     1996    /* If scale multiplier was set: */
     1997    if (dScaleMultiplier > 1.0)
     1998    {
     1999        /* Scale the pixmap up: */
     2000        pixmap = pixmap.scaled(pixmap.width() * dScaleMultiplier, pixmap.height() * dScaleMultiplier,
     2001                               Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     2002        uXHot *= dScaleMultiplier;
     2003        uYHot *= dScaleMultiplier;
     2004    }
     2005
     2006# ifdef VBOX_WS_WIN
     2007    /* If device pixel ratio was set: */
     2008    if (dDevicePixelRatio > 1.0)
     2009    {
     2010        /* Scale the pixmap down: */
     2011        pixmap.setDevicePixelRatio(dDevicePixelRatio);
     2012        uXHot /= dDevicePixelRatio;
     2013        uYHot /= dDevicePixelRatio;
     2014    }
     2015# endif
     2016
     2017#else
     2018
     2019    Q_UNUSED(pixmap);
     2020    Q_UNUSED(uXHot);
     2021    Q_UNUSED(uYHot);
     2022
     2023#endif
     2024}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r82030 r82032  
    139139    /* Console callback handlers: */
    140140    virtual void sltMachineStateChanged();
     141    /** Handles guest request to change the mouse pointer shape. */
     142    void sltMousePointerShapeChange();
    141143
    142144protected:
     
    234236    void updateScaledPausePixmap();
    235237
     238    /** Returns cached mouse cursor. */
     239    QCursor cursor() const { return m_cursor; }
     240
    236241    /** The available area on the current screen for application windows. */
    237242    virtual QRect workingArea() const = 0;
     
    340345    QSize scaledBackward(QSize size) const;
    341346
     347    /** Updates mouse pointer @a pixmap, @a uXHot and @a uYHot according to scaling attributes. */
     348    void updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot);
     349
    342350    /* Protected members: */
    343351    UIMachineWindow *m_pMachineWindow;
     
    378386    QPixmap m_pausePixmapScaled;
    379387
     388    /** Holds cached mouse cursor. */
     389    QCursor  m_cursor;
     390
    380391#ifdef VBOX_WITH_DRAG_AND_DROP
    381392    /** Pointer to drag and drop handler instance. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp

    r82030 r82032  
    477477        QList<ulong> screenIds = m_viewports.keys();
    478478        for (int i = 0; i < screenIds.size(); ++i)
    479             UICommon::setCursor(m_viewports[screenIds[i]], uisession()->cursor());
     479            UICommon::setCursor(m_viewports[screenIds[i]], m_views[screenIds[i]]->cursor());
    480480    }
    481481
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r82029 r82032  
    16581658    /* Fetch incoming shape data: */
    16591659    const bool fHasAlpha = m_shapeData.hasAlpha();
    1660     uint uXHot = m_shapeData.hotSpot().x();
    1661     uint uYHot = m_shapeData.hotSpot().y();
    16621660    const uint uWidth = m_shapeData.shapeSize().width();
    16631661    const uint uHeight = m_shapeData.shapeSize().height();
     
    16741672    const uint uAndMaskSize = (uWidth + 7) / 8 * uHeight;
    16751673    const uchar *pSrcShapePtr = pShapeData + ((uAndMaskSize + 3) & ~3);
    1676 
    1677     /* Remember initial cursor hotspot: */
    1678     m_cursorHotspot = QPoint(uXHot, uYHot);
    16791674
    16801675#if defined (VBOX_WS_WIN)
     
    16981693
    16991694        m_cursorShapePixmap = QPixmap::fromImage(image);
    1700         updateMousePointerPixmapScaling(m_cursorShapePixmap, uXHot, uYHot);
    1701         m_cursor = QCursor(m_cursorShapePixmap, uXHot, uYHot);
    17021695    }
    17031696    else
     
    17901783            m_cursorShapePixmap = QBitmap::fromImage(bitmap);
    17911784            m_cursorMaskPixmap = QBitmap::fromImage(mask);
    1792             updateMousePointerPixmapScaling(m_cursorShapePixmap, uXHot, uYHot);
    1793             updateMousePointerPixmapScaling(m_cursorMaskPixmap, uXHot, uYHot);
    1794             m_cursor = QCursor(m_cursorShapePixmap, m_cursorMaskPixmap, uXHot, uYHot);
    17951785        }
    17961786        else
     
    18231813
    18241814            m_cursorShapePixmap = QPixmap::fromImage(image);
    1825             updateMousePointerPixmapScaling(m_cursorShapePixmap, uXHot, uYHot);
    1826             m_cursor = QCursor(m_cursorShapePixmap, uXHot, uYHot);
    18271815        }
    18281816    }
     
    18491837    /* Create cursor-pixmap from the image: */
    18501838    m_cursorShapePixmap = QPixmap::fromImage(image);
    1851     updateMousePointerPixmapScaling(m_cursorShapePixmap, uXHot, uYHot);
    1852     m_cursor = QCursor(m_cursorShapePixmap, uXHot, uYHot);
    18531839
    18541840    /* Mark mouse pointer shape valid: */
     
    18611847#endif
    18621848
    1863     /* Cache cursor pixmap size: */
     1849    /* Cache cursor pixmap size and hotspot: */
    18641850    m_cursorSize = m_cursorShapePixmap.size();
    1865 }
    1866 
    1867 void UISession::updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot)
    1868 {
    1869 #if defined(VBOX_WS_MAC)
    1870 
    1871     /* Get screen-id of active machine-window: */
    1872     /// @todo In case of multi-monitor setup check whether parameters are screen specific.
    1873     const ulong uScreenID = activeMachineWindow()->screenId();
    1874 
    1875     /* Take into account scale-factor if necessary: */
    1876     const double dScaleFactor = frameBuffer(uScreenID)->scaleFactor();
    1877     //printf("Scale-factor: %f\n", dScaleFactor);
    1878     if (dScaleFactor > 1.0)
    1879     {
    1880         /* Scale the pixmap up: */
    1881         pixmap = pixmap.scaled(pixmap.width() * dScaleFactor, pixmap.height() * dScaleFactor,
    1882                                Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    1883         uXHot *= dScaleFactor;
    1884         uYHot *= dScaleFactor;
    1885     }
    1886 
    1887     /* Take into account device-pixel-ratio if necessary: */
    1888     const double dDevicePixelRatio = frameBuffer(uScreenID)->devicePixelRatio();
    1889     const bool fUseUnscaledHiDPIOutput = frameBuffer(uScreenID)->useUnscaledHiDPIOutput();
    1890     //printf("Device-pixel-ratio: %f, Unscaled HiDPI Output: %d\n",
    1891     //       dDevicePixelRatio, fUseUnscaledHiDPIOutput);
    1892     if (dDevicePixelRatio > 1.0 && fUseUnscaledHiDPIOutput)
    1893     {
    1894         /* Scale the pixmap down: */
    1895         pixmap.setDevicePixelRatio(dDevicePixelRatio);
    1896         uXHot /= dDevicePixelRatio;
    1897         uYHot /= dDevicePixelRatio;
    1898     }
    1899 
    1900 #elif defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)
    1901 
    1902     /* Get screen-id of active machine-window: */
    1903     /// @todo In case of multi-monitor setup check whether parameters are screen specific.
    1904     const ulong uScreenID = activeMachineWindow()->screenId();
    1905 
    1906     /* We want to scale the pixmap just once, so let's prepare cumulative multiplier: */
    1907     double dScaleMultiplier = 1.0;
    1908 
    1909     /* Take into account scale-factor if necessary: */
    1910     const double dScaleFactor = frameBuffer(uScreenID)->scaleFactor();
    1911     //printf("Scale-factor: %f\n", dScaleFactor);
    1912     if (dScaleFactor > 1.0)
    1913         dScaleMultiplier *= dScaleFactor;
    1914 
    1915     /* Take into account device-pixel-ratio if necessary: */
    1916 # ifdef VBOX_WS_WIN
    1917     const double dDevicePixelRatio = frameBuffer(uScreenID)->devicePixelRatio();
    1918 # endif
    1919     const double dDevicePixelRatioActual = frameBuffer(uScreenID)->devicePixelRatioActual();
    1920     const bool fUseUnscaledHiDPIOutput = frameBuffer(uScreenID)->useUnscaledHiDPIOutput();
    1921     //printf("Device-pixel-ratio/actual: %f/%f, Unscaled HiDPI Output: %d\n",
    1922     //       dDevicePixelRatio, dDevicePixelRatioActual, fUseUnscaledHiDPIOutput);
    1923     if (dDevicePixelRatioActual > 1.0 && !fUseUnscaledHiDPIOutput)
    1924         dScaleMultiplier *= dDevicePixelRatioActual;
    1925 
    1926     /* If scale multiplier was set: */
    1927     if (dScaleMultiplier > 1.0)
    1928     {
    1929         /* Scale the pixmap up: */
    1930         pixmap = pixmap.scaled(pixmap.width() * dScaleMultiplier, pixmap.height() * dScaleMultiplier,
    1931                                Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    1932         uXHot *= dScaleMultiplier;
    1933         uYHot *= dScaleMultiplier;
    1934     }
    1935 
    1936 # ifdef VBOX_WS_WIN
    1937     /* If device pixel ratio was set: */
    1938     if (dDevicePixelRatio > 1.0)
    1939     {
    1940         /* Scale the pixmap down: */
    1941         pixmap.setDevicePixelRatio(dDevicePixelRatio);
    1942         uXHot /= dDevicePixelRatio;
    1943         uYHot /= dDevicePixelRatio;
    1944     }
    1945 # endif
    1946 
    1947 #else
    1948 
    1949     Q_UNUSED(pixmap);
    1950     Q_UNUSED(uXHot);
    1951     Q_UNUSED(uYHot);
    1952 
    1953 #endif
     1851    m_cursorHotspot = m_shapeData.hotSpot();
    19541852}
    19551853
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r82022 r82032  
    135135    UIMachineWindow *activeMachineWindow() const;
    136136
    137     /** Returns currently cached mouse cursor. */
    138     QCursor cursor() const { return m_cursor; }
    139137    /** Returns currently cached mouse cursor shape pixmap. */
    140138    QPixmap cursorShapePixmap() const { return m_cursorShapePixmap; }
     
    448446    /** Updates mouse pointer shape. */
    449447    void updateMousePointerShape();
    450     /** Updates mouse pointer @a pixmap, @a uXHot and @a uYHot according to scaling attributes. */
    451     void updateMousePointerPixmapScaling(QPixmap &pixmap, uint &uXHot, uint &uYHot);
    452448
    453449    /* Common helpers: */
     
    512508    KMachineState m_machineState;
    513509
    514     /** Holds cached mouse cursor. */
    515     QCursor  m_cursor;
    516510    /** Holds cached mouse cursor shape pixmap. */
    517511    QPixmap  m_cursorShapePixmap;
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