VirtualBox

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


Ignore:
Timestamp:
Nov 15, 2019 8:34:43 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134657
Message:

FE/Qt: bugref:6143

  • Checking if extradata is there before trying to use it. This was crashing very nicely,
  • Drawing key shapes with rounded corners.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r81507 r81863  
    144144};
    145145
     146QPointF linearInterpolation(qreal t, const QPointF &p0, const QPointF &p1)
     147{
     148    if (t < 0)
     149        return p0;
     150    if (t> 1)
     151        return p1;
     152    return QPointF((1 - t) * p0 + t * p1);
     153}
    146154
    147155/*********************************************************************************************************************************
     
    425433    void press();
    426434
    427     void setPolygon(const QPolygon &polygon);
    428     const QPolygon &polygon() const;
    429 
    430     QPolygon polygonInGlobal() const;
     435    void setPoints(const QVector<QPointF> &points);
     436    const QVector<QPointF> &points() const;
     437    const QPainterPath &painterPath() const;
     438
     439    QPolygonF polygonInGlobal() const;
    431440
    432441    int cutoutCorner() const;
     
    440449
    441450    void updateState(bool fPressed);
     451    void computePainterPath();
    442452
    443453    QRect    m_keyGeometry;
    444     /** Stores the key polygon in local coordinates. */
    445     QPolygon m_polygon;
     454    /** Stores the key points (vertices) in local coordinates. */
     455    QVector<QPointF> m_points;
     456    /** We cache the path since re-computing that at each draw is meaningless. */
     457    QPainterPath m_painterPath;
    446458    KeyType  m_enmType;
    447459    KeyState m_enmState;
     
    736748
    737749    bool parseXMLFile(const QString &strFileName, UISoftKeyboardPhysicalLayout &physicalLayout);
    738     static QVector<QPoint> computeKeyVertices(const UISoftKeyboardKey &key);
     750    static QVector<QPointF> computeKeyVertices(const UISoftKeyboardKey &key);
    739751
    740752private:
     
    16801692}
    16811693
    1682 void UISoftKeyboardKey::setPolygon(const QPolygon &polygon)
    1683 {
    1684     m_polygon = polygon;
    1685 }
    1686 
    1687 const QPolygon &UISoftKeyboardKey::polygon() const
    1688 {
    1689     return m_polygon;
    1690 }
    1691 
    1692 QPolygon UISoftKeyboardKey::polygonInGlobal() const
    1693 {
    1694     QPolygon globalPolygon(m_polygon);
     1694void UISoftKeyboardKey::setPoints(const QVector<QPointF> &points)
     1695{
     1696    m_points = points;
     1697    computePainterPath();
     1698}
     1699
     1700const QVector<QPointF> &UISoftKeyboardKey::points() const
     1701{
     1702    return m_points;
     1703}
     1704
     1705const QPainterPath &UISoftKeyboardKey::painterPath() const
     1706{
     1707    return m_painterPath;
     1708}
     1709
     1710void UISoftKeyboardKey::computePainterPath()
     1711{
     1712    if (m_points.size() < 3)
     1713        return;
     1714    double d = 0.1;
     1715    m_painterPath = QPainterPath(linearInterpolation(d, m_points[0], m_points[1]));
     1716    for (int i = 0; i < m_points.size(); ++i)
     1717    {
     1718        QPointF p0 = linearInterpolation(1-d, m_points[i], m_points[(i+1)%m_points.size()]);
     1719        QPointF p1 = linearInterpolation(d, m_points[(i+1)%m_points.size()], m_points[(i+2)%m_points.size()]);
     1720        m_painterPath.lineTo(p0);
     1721        m_painterPath.quadTo(m_points[(i+1)%m_points.size()], p1);
     1722    }
     1723}
     1724
     1725QPolygonF UISoftKeyboardKey::polygonInGlobal() const
     1726{
     1727    QPolygonF globalPolygon(m_points);
    16951728    globalPolygon.translate(m_keyGeometry.x(), m_keyGeometry.y());
    16961729    return globalPolygon;
     
    22342267                painter.setPen(QPen(color(KeyboardColorType_Font), 2));
    22352268
    2236             painter.drawPolygon(key.polygon());
     2269            /* Draw the key shape: */
     2270            painter.drawPath(key.painterPath());
    22372271
    22382272            currentLayout.drawTextInRect(key, painter);
     
    25522586void UISoftKeyboardWidget::setColorThemeByName(const QString &strColorThemeName)
    25532587{
     2588    if (strColorThemeName.isEmpty())
     2589        return;
    25542590    if (m_currentColorTheme && m_currentColorTheme->name() == strColorThemeName)
    25552591        return;
     
    29102946
    29112947            key.setKeyGeometry(QRect(iX, iY, key.width(), key.height()));
    2912             key.setPolygon(QPolygon(UIPhysicalLayoutReader::computeKeyVertices(key)));
     2948            key.setPoints(UIPhysicalLayoutReader::computeKeyVertices(key));
    29132949            key.setParentWidget(this);
    29142950            iX += key.width();
     
    33323368}
    33333369
    3334 QVector<QPoint> UIPhysicalLayoutReader::computeKeyVertices(const UISoftKeyboardKey &key)
    3335 {
    3336     QVector<QPoint> vertices;
     3370QVector<QPointF> UIPhysicalLayoutReader::computeKeyVertices(const UISoftKeyboardKey &key)
     3371{
     3372    QVector<QPointF> vertices;
    33373373
    33383374    if (key.cutoutCorner() == -1 || key.width() <= key.cutoutWidth() || key.height() <= key.cutoutHeight())
     
    41334169    {
    41344170        QStringList colorTheme = gEDataManager->softKeyboardColorTheme();
    4135         /* The fist item is the theme name and the rest are color codes: */
    4136         QString strThemeName = colorTheme[0];
    4137         colorTheme.removeFirst();
    4138         m_pKeyboardWidget->colorsFromStringList(strThemeName, colorTheme);
     4171        if (!colorTheme.empty())
     4172        {
     4173            /* The fist item is the theme name and the rest are color codes: */
     4174            QString strThemeName = colorTheme[0];
     4175            colorTheme.removeFirst();
     4176            m_pKeyboardWidget->colorsFromStringList(strThemeName, colorTheme);
     4177        }
    41394178        m_pKeyboardWidget->setColorThemeByName(gEDataManager->softKeyboardSelectedColorTheme());
    41404179        m_pKeyboardWidget->setCurrentLayout(gEDataManager->softKeyboardSelectedLayout());
     4180
    41414181        /* Load other options from exra data: */
    41424182        bool fHideNumPad = false;
     
    41464186        m_pKeyboardWidget->setHideNumPad(fHideNumPad);
    41474187        m_pKeyboardWidget->setHideOSMenuKeys(fHideOSMenuKeys);
    4148        m_pKeyboardWidget->setHideMultimediaKeys(fHideMultimediaKeys);
     4188        m_pKeyboardWidget->setHideMultimediaKeys(fHideMultimediaKeys);
    41494189    }
    41504190}
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