Changeset 81863 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 15, 2019 8:34:43 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 134657
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r81507 r81863 144 144 }; 145 145 146 QPointF 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 } 146 154 147 155 /********************************************************************************************************************************* … … 425 433 void press(); 426 434 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; 431 440 432 441 int cutoutCorner() const; … … 440 449 441 450 void updateState(bool fPressed); 451 void computePainterPath(); 442 452 443 453 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; 446 458 KeyType m_enmType; 447 459 KeyState m_enmState; … … 736 748 737 749 bool parseXMLFile(const QString &strFileName, UISoftKeyboardPhysicalLayout &physicalLayout); 738 static QVector<QPoint > computeKeyVertices(const UISoftKeyboardKey &key);750 static QVector<QPointF> computeKeyVertices(const UISoftKeyboardKey &key); 739 751 740 752 private: … … 1680 1692 } 1681 1693 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); 1694 void UISoftKeyboardKey::setPoints(const QVector<QPointF> &points) 1695 { 1696 m_points = points; 1697 computePainterPath(); 1698 } 1699 1700 const QVector<QPointF> &UISoftKeyboardKey::points() const 1701 { 1702 return m_points; 1703 } 1704 1705 const QPainterPath &UISoftKeyboardKey::painterPath() const 1706 { 1707 return m_painterPath; 1708 } 1709 1710 void 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 1725 QPolygonF UISoftKeyboardKey::polygonInGlobal() const 1726 { 1727 QPolygonF globalPolygon(m_points); 1695 1728 globalPolygon.translate(m_keyGeometry.x(), m_keyGeometry.y()); 1696 1729 return globalPolygon; … … 2234 2267 painter.setPen(QPen(color(KeyboardColorType_Font), 2)); 2235 2268 2236 painter.drawPolygon(key.polygon()); 2269 /* Draw the key shape: */ 2270 painter.drawPath(key.painterPath()); 2237 2271 2238 2272 currentLayout.drawTextInRect(key, painter); … … 2552 2586 void UISoftKeyboardWidget::setColorThemeByName(const QString &strColorThemeName) 2553 2587 { 2588 if (strColorThemeName.isEmpty()) 2589 return; 2554 2590 if (m_currentColorTheme && m_currentColorTheme->name() == strColorThemeName) 2555 2591 return; … … 2910 2946 2911 2947 key.setKeyGeometry(QRect(iX, iY, key.width(), key.height())); 2912 key.setPo lygon(QPolygon(UIPhysicalLayoutReader::computeKeyVertices(key)));2948 key.setPoints(UIPhysicalLayoutReader::computeKeyVertices(key)); 2913 2949 key.setParentWidget(this); 2914 2950 iX += key.width(); … … 3332 3368 } 3333 3369 3334 QVector<QPoint > UIPhysicalLayoutReader::computeKeyVertices(const UISoftKeyboardKey &key)3335 { 3336 QVector<QPoint > vertices;3370 QVector<QPointF> UIPhysicalLayoutReader::computeKeyVertices(const UISoftKeyboardKey &key) 3371 { 3372 QVector<QPointF> vertices; 3337 3373 3338 3374 if (key.cutoutCorner() == -1 || key.width() <= key.cutoutWidth() || key.height() <= key.cutoutHeight()) … … 4133 4169 { 4134 4170 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 } 4139 4178 m_pKeyboardWidget->setColorThemeByName(gEDataManager->softKeyboardSelectedColorTheme()); 4140 4179 m_pKeyboardWidget->setCurrentLayout(gEDataManager->softKeyboardSelectedLayout()); 4180 4141 4181 /* Load other options from exra data: */ 4142 4182 bool fHideNumPad = false; … … 4146 4186 m_pKeyboardWidget->setHideNumPad(fHideNumPad); 4147 4187 m_pKeyboardWidget->setHideOSMenuKeys(fHideOSMenuKeys); 4148 m_pKeyboardWidget->setHideMultimediaKeys(fHideMultimediaKeys);4188 m_pKeyboardWidget->setHideMultimediaKeys(fHideMultimediaKeys); 4149 4189 } 4150 4190 }
Note:
See TracChangeset
for help on using the changeset viewer.