Changeset 78891 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- May 31, 2019 10:20:17 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78884 r78891 93 93 class UISoftKeyboardKey 94 94 { 95 96 95 public: 97 96 … … 167 166 168 167 /********************************************************************************************************************************* 168 * UISoftKeyboardWidget definition. * 169 *********************************************************************************************************************************/ 170 class UISoftKeyboardWidget : public QWidget 171 { 172 Q_OBJECT; 173 174 public: 175 176 UISoftKeyboardWidget(QWidget *pParent = 0); 177 virtual QSize minimumSizeHint() const; 178 virtual QSize sizeHint() const; 179 void setNewMinimumSize(const QSize &size); 180 QVector<UISoftKeyboardRow> m_rows; 181 void setInitialSize(int iWidth, int iHeight); 182 183 protected: 184 185 void paintEvent(QPaintEvent *pEvent) /* override */; 186 void mousePressEvent(QMouseEvent *pEvent); 187 void mouseMoveEvent(QMouseEvent *pEvent); 188 189 private: 190 191 UISoftKeyboardKey *keyUnderMouse(QMouseEvent *pEvent); 192 193 QSize m_minimumSize; 194 int m_iInitialHeight; 195 int m_iInitialWidth; 196 float m_fMultiplierX; 197 float m_fMultiplierY; 198 UISoftKeyboardKey *m_pKeyUnderMouse; 199 QColor m_keyDefaultColor; 200 QColor m_keyHoverColor; 201 QColor m_keyPressColor; 202 QColor m_textDefaultColor; 203 }; 204 205 /********************************************************************************************************************************* 169 206 * UIKeyboardLayoutReader definition. * 170 207 *********************************************************************************************************************************/ … … 433 470 } 434 471 } 472 } 473 474 /********************************************************************************************************************************* 475 * UISoftKeyboardWidget implementation. * 476 *********************************************************************************************************************************/ 477 478 UISoftKeyboardWidget::UISoftKeyboardWidget(QWidget *pParent /* = 0 */) 479 :QWidget(pParent) 480 , m_pKeyUnderMouse(0) 481 , m_keyDefaultColor(QColor(255, 228, 192)) 482 , m_keyHoverColor(QColor(238, 208, 169)) 483 , m_keyPressColor(QColor(248, 218, 179)) 484 , m_textDefaultColor(QColor(0, 0, 0)) 485 { 486 setMouseTracking(true); 487 } 488 489 QSize UISoftKeyboardWidget::minimumSizeHint() const 490 { 491 return m_minimumSize; 492 } 493 494 QSize UISoftKeyboardWidget::sizeHint() const 495 { 496 return m_minimumSize; 497 } 498 499 void UISoftKeyboardWidget::setNewMinimumSize(const QSize &size) 500 { 501 m_minimumSize = size; 502 updateGeometry(); 503 } 504 505 void UISoftKeyboardWidget::setInitialSize(int iWidth, int iHeight) 506 { 507 m_iInitialWidth = iWidth; 508 m_iInitialHeight = iHeight; 509 } 510 511 void UISoftKeyboardWidget::paintEvent(QPaintEvent *pEvent) /* override */ 512 { 513 Q_UNUSED(pEvent); 514 if (m_iInitialWidth == 0 || m_iInitialHeight == 0) 515 return; 516 517 m_fMultiplierX = width() / (float) m_iInitialWidth; 518 m_fMultiplierY = height() / (float) m_iInitialHeight; 519 520 QPainter painter(this); 521 QFont painterFont(font()); 522 painterFont.setPixelSize(15); 523 painterFont.setBold(false); 524 painter.setFont(painterFont); 525 painter.setRenderHint(QPainter::Antialiasing); 526 painter.setPen(QPen(QColor(m_textDefaultColor), 2)); 527 painter.setBrush(QBrush(m_keyDefaultColor)); 528 painter.scale(m_fMultiplierX, m_fMultiplierY); 529 for (int i = 0; i < m_rows.size(); ++i) 530 { 531 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 532 for (int j = 0; j < keys.size(); ++j) 533 { 534 UISoftKeyboardKey &key = keys[j]; 535 painter.translate(key.keyGeometry().x(), key.keyGeometry().y()); 536 painter.drawPolygon(key.polygon()); 537 QRect textRect(5, 5, key.keyGeometry().width(), key.keyGeometry().height()); 538 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 539 painter.translate(-key.keyGeometry().x(), -key.keyGeometry().y()); 540 } 541 } 542 543 if (m_pKeyUnderMouse) 544 { 545 painter.setBrush(QBrush(m_keyHoverColor)); 546 painter.translate(m_pKeyUnderMouse->keyGeometry().x(), m_pKeyUnderMouse->keyGeometry().y()); 547 painter.drawPolygon(m_pKeyUnderMouse->polygon()); 548 QRect textRect(5, 5, m_pKeyUnderMouse->keyGeometry().width(), m_pKeyUnderMouse->keyGeometry().height()); 549 painter.drawText(textRect, Qt::TextWordWrap, m_pKeyUnderMouse->keyCap()); 550 painter.translate(-m_pKeyUnderMouse->keyGeometry().x(), -m_pKeyUnderMouse->keyGeometry().y()); 551 } 552 } 553 554 void UISoftKeyboardWidget::mousePressEvent(QMouseEvent *pEvent) 555 { 556 keyUnderMouse(pEvent); 557 } 558 559 void UISoftKeyboardWidget::mouseMoveEvent(QMouseEvent *pEvent) 560 { 561 keyUnderMouse(pEvent); 562 } 563 564 UISoftKeyboardKey *UISoftKeyboardWidget::keyUnderMouse(QMouseEvent *pEvent) 565 { 566 QPoint eventPosition(pEvent->pos().x() / m_fMultiplierX, pEvent->pos().y() / m_fMultiplierY); 567 QWidget::mousePressEvent(pEvent); 568 for (int i = 0; i < m_rows.size(); ++i) 569 { 570 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 571 for (int j = 0; j < keys.size(); ++j) 572 { 573 UISoftKeyboardKey &key = keys[j]; 574 if (key.polygonInGlobal().containsPoint(eventPosition, Qt::OddEvenFill)) 575 { 576 if (&key != m_pKeyUnderMouse) 577 { 578 m_pKeyUnderMouse = &key; 579 update(); 580 } 581 return &key; 582 break; 583 } 584 } 585 } 586 return 0; 435 587 } 436 588 … … 649 801 } 650 802 651 class UISoftKeyboardWidget : public QWidget652 {653 Q_OBJECT;654 public:655 656 virtual QSize minimumSizeHint() const657 {658 return m_minimumSize;659 }660 661 virtual QSize sizeHint() const662 {663 return m_minimumSize;664 }665 666 void setNewMinimumSize(const QSize &size)667 {668 m_minimumSize = size;669 updateGeometry();670 }671 QVector<UISoftKeyboardRow> m_rows;672 673 void setInitialSize(int iWidth, int iHeight)674 {675 m_iInitialWidth = iWidth;676 m_iInitialHeight = iHeight;677 }678 679 protected:680 681 void paintEvent(QPaintEvent *pEvent) /* override */682 {683 Q_UNUSED(pEvent);684 if (m_iInitialWidth == 0 || m_iInitialHeight == 0)685 return;686 687 m_fMultiplierX = width() / (float) m_iInitialWidth;688 m_fMultiplierY = height() / (float) m_iInitialHeight;689 690 QPainter painter(this);691 QFont painterFont(font());692 painterFont.setPixelSize(15);693 painter.setFont(painterFont);694 painter.setRenderHint(QPainter::Antialiasing);695 painter.setPen(QPen(QColor(0, 0,0), 2));696 painter.setBrush(QBrush(QColor(255, 0,0)));697 painter.scale(m_fMultiplierX, m_fMultiplierY);698 for (int i = 0; i < m_rows.size(); ++i)699 {700 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();701 for (int j = 0; j < keys.size(); ++j)702 {703 UISoftKeyboardKey &key = keys[j];704 painter.translate(key.keyGeometry().x(), key.keyGeometry().y());705 painter.drawPolygon(key.polygon());706 QRect textRect(5, 5, key.keyGeometry().width(), key.keyGeometry().height());707 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap());708 painter.translate(-key.keyGeometry().x(), -key.keyGeometry().y());709 }710 }711 }712 713 void mousePressEvent(QMouseEvent *pEvent)714 {715 QPoint eventPosition(pEvent->pos().x() / m_fMultiplierX, pEvent->pos().y() / m_fMultiplierY);716 QWidget::mousePressEvent(pEvent);717 for (int i = 0; i < m_rows.size(); ++i)718 {719 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();720 for (int j = 0; j < keys.size(); ++j)721 {722 UISoftKeyboardKey &key = keys[j];723 if (key.polygonInGlobal().containsPoint(eventPosition, Qt::OddEvenFill))724 {725 break;726 }727 }728 }729 }730 731 private:732 733 QSize m_minimumSize;734 int m_iInitialHeight;735 int m_iInitialWidth;736 float m_fMultiplierX;737 float m_fMultiplierY;738 739 };740 741 742 803 /********************************************************************************************************************************* 743 804 * UISoftKeyboard implementation. * … … 848 909 } 849 910 911 void UISoftKeyboard::sltHandleKeyboardLedsChange() 912 { 913 // bool fNumLockLed = m_pSession->isNumLock(); 914 // bool fCapsLockLed = m_pSession->isCapsLock(); 915 // bool fScrollLock = m_pSession->isScrollLock(); 916 } 917 850 918 void UISoftKeyboard::prepareObjects() 851 919 { … … 860 928 void UISoftKeyboard::prepareConnections() 861 929 { 930 connect(m_pSession, &UISession::sigKeyboardLedsChange, this, &UISoftKeyboard::sltHandleKeyboardLedsChange); 862 931 } 863 932 -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78845 r78891 62 62 void sltHandleKeyRelease(); 63 63 void sltHandleModifierStateChange(); 64 void sltHandleKeyboardLedsChange(); 64 65 65 66 private:
Note:
See TracChangeset
for help on using the changeset viewer.