Changeset 78921 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 3, 2019 8:36:10 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131041
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78891 r78921 36 36 #include "CEventSource.h" 37 37 38 38 /* Forward declarations: */ 39 class UISoftKeyboardWidget; 39 40 40 41 enum UIKeyState … … 48 49 enum UIKeyType 49 50 { 51 /** Can be in UIKeyState_NotPressed and UIKeyState_Pressed states. */ 50 52 UIKeyType_Ordinary, 51 /** e.g. CapsLock. Can be only in UIKeyState_NotPressed, UIKeyState_Locked ,*/53 /** e.g. CapsLock. Can be only in UIKeyState_NotPressed, UIKeyState_Locked */ 52 54 UIKeyType_Toggleable, 53 55 /** e.g. Shift Can be in all 3 states*/ … … 126 128 void setCutout(int iCorner, int iWidth, int iHeight); 127 129 130 void setParentWidget(UISoftKeyboardWidget* pParent); 128 131 UIKeyState state() const; 129 132 QVector<LONG> scanCodeWithPrefix() const; 130 133 131 134 void release(); 135 void press(); 132 136 133 137 void setPolygon(const QPolygon &polygon); … … 163 167 /** Key's position in the layout. */ 164 168 int m_iPosition; 169 UISoftKeyboardWidget *m_pParentWidget; 165 170 }; 166 171 … … 172 177 Q_OBJECT; 173 178 179 signals: 180 181 void sigPutKeyboardSequence(QVector<LONG> sequence); 182 174 183 public: 175 184 176 185 UISoftKeyboardWidget(QWidget *pParent = 0); 186 177 187 virtual QSize minimumSizeHint() const; 178 188 virtual QSize sizeHint() const; 179 189 void setNewMinimumSize(const QSize &size); 180 QVector<UISoftKeyboardRow> m_rows; 190 191 QVector<UISoftKeyboardRow> &rows(); 192 const QVector<UISoftKeyboardRow> &rows() const; 193 181 194 void setInitialSize(int iWidth, int iHeight); 195 void keyStateChange(UISoftKeyboardKey* pKey); 182 196 183 197 protected: 184 198 185 199 void paintEvent(QPaintEvent *pEvent) /* override */; 186 void mousePressEvent(QMouseEvent *pEvent); 200 void mousePressEvent(QMouseEvent *pEvent) /* override */; 201 void mouseReleaseEvent(QMouseEvent *pEvent) /* override */; 187 202 void mouseMoveEvent(QMouseEvent *pEvent); 188 203 … … 190 205 191 206 UISoftKeyboardKey *keyUnderMouse(QMouseEvent *pEvent); 192 207 void handleKeyPress(UISoftKeyboardKey *pKey); 208 void handleKeyRelease(UISoftKeyboardKey *pKey); 193 209 QSize m_minimumSize; 194 210 int m_iInitialHeight; … … 197 213 float m_fMultiplierY; 198 214 UISoftKeyboardKey *m_pKeyUnderMouse; 215 UISoftKeyboardKey *m_pKeyPressed; 199 216 QColor m_keyDefaultColor; 200 217 QColor m_keyHoverColor; 201 QColor m_keyPressColor;202 218 QColor m_textDefaultColor; 219 QColor m_textPressedColor; 220 QVector<UISoftKeyboardKey*> m_pressedModifiers; 221 QVector<UISoftKeyboardRow> m_rows; 203 222 }; 204 223 … … 294 313 , m_iCutoutCorner(-1) 295 314 , m_iPosition(0) 315 , m_pParentWidget(0) 296 316 { 297 317 } … … 402 422 } 403 423 424 void UISoftKeyboardKey::setParentWidget(UISoftKeyboardWidget* pParent) 425 { 426 m_pParentWidget = pParent; 427 } 428 404 429 void UISoftKeyboardKey::release() 405 430 { 406 431 updateState(false); 432 } 433 434 void UISoftKeyboardKey::press() 435 { 436 updateState(true); 407 437 } 408 438 … … 441 471 void UISoftKeyboardKey::updateState(bool fPressed) 442 472 { 443 if (m_enmType == UIKeyType_Ordinary) 444 return; 473 UIKeyState enmPreviousState = state(); 445 474 if (m_enmType == UIKeyType_Modifier) 446 475 { … … 470 499 } 471 500 } 501 else if (m_enmType == UIKeyType_Ordinary) 502 { 503 if (m_enmState == UIKeyState_NotPressed) 504 m_enmState = UIKeyState_Pressed; 505 else 506 m_enmState = UIKeyState_NotPressed; 507 } 508 if (enmPreviousState != state() && m_pParentWidget) 509 m_pParentWidget->keyStateChange(this); 472 510 } 473 511 … … 479 517 :QWidget(pParent) 480 518 , 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)) 519 , m_pKeyPressed(0) 520 , m_keyDefaultColor(QColor(103, 128, 159)) 521 , m_keyHoverColor(QColor(108, 122, 137)) 522 , m_textDefaultColor(QColor(46, 49, 49)) 523 , m_textPressedColor(QColor(149, 165, 166)) 485 524 { 486 525 setMouseTracking(true); … … 507 546 m_iInitialWidth = iWidth; 508 547 m_iInitialHeight = iHeight; 548 } 549 550 QVector<UISoftKeyboardRow> &UISoftKeyboardWidget::rows() 551 { 552 return m_rows; 553 } 554 555 const QVector<UISoftKeyboardRow> &UISoftKeyboardWidget::rows() const 556 { 557 return m_rows; 509 558 } 510 559 … … 524 573 painter.setFont(painterFont); 525 574 painter.setRenderHint(QPainter::Antialiasing); 526 painter.setPen(QPen(QColor(m_textDefaultColor), 2));527 painter.setBrush(QBrush(m_keyDefaultColor));528 575 painter.scale(m_fMultiplierX, m_fMultiplierY); 576 int unitSize = qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing); 577 float fLedRadius = 1.5 * unitSize; 578 float fLedMargin = unitSize; 579 529 580 for (int i = 0; i < m_rows.size(); ++i) 530 581 { … … 534 585 UISoftKeyboardKey &key = keys[j]; 535 586 painter.translate(key.keyGeometry().x(), key.keyGeometry().y()); 587 if (&key == m_pKeyUnderMouse) 588 painter.setBrush(QBrush(m_keyHoverColor)); 589 else 590 painter.setBrush(QBrush(m_keyDefaultColor)); 591 592 if (&key == m_pKeyPressed) 593 painter.setPen(QPen(QColor(m_textPressedColor), 2)); 594 else 595 painter.setPen(QPen(QColor(m_textDefaultColor), 2)); 596 536 597 painter.drawPolygon(key.polygon()); 537 QRect textRect(5, 5, key.keyGeometry().width(), key.keyGeometry().height()); 598 599 QRect textRect(0.8 * unitSize, 2 * unitSize 600 , key.keyGeometry().width(), key.keyGeometry().height()); 538 601 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 602 603 if (key.type() != UIKeyType_Ordinary) 604 { 605 QColor ledColor; 606 if (key.state() == UIKeyState_NotPressed) 607 ledColor = m_textDefaultColor; 608 else if (key.state() == UIKeyState_Pressed) 609 ledColor = QColor(0, 255, 0); 610 else 611 ledColor = QColor(255, 0, 0); 612 painter.setBrush(ledColor); 613 painter.setPen(ledColor); 614 QRectF rectangle(key.keyGeometry().width() - 2 * fLedMargin, fLedMargin, fLedRadius, fLedRadius); 615 painter.drawEllipse(rectangle); 616 } 539 617 painter.translate(-key.keyGeometry().x(), -key.keyGeometry().y()); 618 540 619 } 541 620 } 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 621 } 553 622 554 623 void UISoftKeyboardWidget::mousePressEvent(QMouseEvent *pEvent) 555 624 { 556 keyUnderMouse(pEvent); 625 m_pKeyPressed = keyUnderMouse(pEvent); 626 handleKeyPress(m_pKeyPressed); 627 update(); 628 } 629 630 void UISoftKeyboardWidget::mouseReleaseEvent(QMouseEvent *) 631 { 632 if (!m_pKeyPressed) 633 return; 634 handleKeyRelease(m_pKeyPressed); 635 m_pKeyPressed = 0; 636 update(); 557 637 } 558 638 … … 585 665 } 586 666 return 0; 667 } 668 669 void UISoftKeyboardWidget::handleKeyPress(UISoftKeyboardKey *pKey) 670 { 671 if (!pKey) 672 return; 673 pKey->press(); 674 675 if (pKey->type() == UIKeyType_Modifier) 676 return; 677 678 QVector<LONG> sequence; 679 680 /* Add the pressed modifiers first: */ 681 for (int i = 0; i < m_pressedModifiers.size(); ++i) 682 { 683 UISoftKeyboardKey *pModifier = m_pressedModifiers[i]; 684 if (pModifier->scanCodePrefix() != 0) 685 sequence << pModifier->scanCodePrefix(); 686 sequence << pModifier->scanCode(); 687 } 688 689 if (pKey->scanCodePrefix() != 0) 690 sequence << pKey->scanCodePrefix(); 691 sequence << pKey->scanCode(); 692 emit sigPutKeyboardSequence(sequence); 693 } 694 695 void UISoftKeyboardWidget::keyStateChange(UISoftKeyboardKey* pKey) 696 { 697 if (!pKey) 698 return; 699 if (pKey->type() == UIKeyType_Modifier) 700 { 701 if (pKey->state() == UIKeyState_NotPressed) 702 m_pressedModifiers.removeOne(pKey); 703 else 704 if (!m_pressedModifiers.contains(pKey)) 705 m_pressedModifiers.append(pKey); 706 } 707 } 708 709 void UISoftKeyboardWidget::handleKeyRelease(UISoftKeyboardKey *pKey) 710 { 711 if (!pKey) 712 return; 713 if (pKey->type() == UIKeyType_Ordinary) 714 pKey->release(); 715 /* We only send the scan codes of Ordinary keys: */ 716 if (pKey->type() == UIKeyType_Modifier) 717 return; 718 719 QVector<LONG> sequence; 720 if (pKey->scanCodePrefix() != 0) 721 sequence << pKey->scanCodePrefix(); 722 sequence << (pKey->scanCode() | 0x80); 723 724 /* Add the pressed modifiers in the reverse order: */ 725 for (int i = m_pressedModifiers.size() - 1; i >= 0; --i) 726 { 727 UISoftKeyboardKey *pModifier = m_pressedModifiers[i]; 728 if (pModifier->scanCodePrefix() != 0) 729 sequence << pModifier->scanCodePrefix(); 730 sequence << (pModifier->scanCode() | 0x80); 731 /* Release the pressed modifiers (if there are not locked): */ 732 pModifier->release(); 733 } 734 emit sigPutKeyboardSequence(sequence); 587 735 } 588 736 … … 693 841 else if (m_xmlReader.name() == "position") 694 842 key.setPosition(m_xmlReader.readElementText().toInt()); 695 //else if (m_xmlReader.name() == "type")696 //{697 //QString strType = m_xmlReader.readElementText();698 //if (strType == "modifier")699 // pKey->setType(UIKeyType_Modifier);700 //else if (strType == "toggleable")701 // pKey->setType(UIKeyType_Toggleable);702 //}843 else if (m_xmlReader.name() == "type") 844 { 845 QString strType = m_xmlReader.readElementText(); 846 if (strType == "modifier") 847 key.setType(UIKeyType_Modifier); 848 else if (strType == "toggleable") 849 key.setType(UIKeyType_Toggleable); 850 } 703 851 else 704 852 m_xmlReader.skipCurrentElement(); … … 812 960 , m_pContainerWidget(0) 813 961 , m_strMachineName(strMachineName) 814 815 , m_fKeepAspectRatio(false)816 962 , m_iXSpacing(5) 817 963 , m_iYSpacing(5) … … 823 969 setAttribute(Qt::WA_DeleteOnClose); 824 970 prepareObjects(); 825 parseLayout();971 createKeyboard(); 826 972 prepareConnections(); 827 973 prepareToolBar(); … … 839 985 } 840 986 841 void UISoftKeyboard::sltHandleKeyPress()842 {843 // UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());844 // if (!pKey)845 // return;846 // if (pKey->type() == UIKeyType_Modifier)847 // return;848 849 // QVector<LONG> sequence;850 851 // /* Add the pressed modifiers first: */852 // for (int i = 0; i < m_pressedModifiers.size(); ++i)853 // {854 // UISoftKeyboardKey *pModifier = m_pressedModifiers[i];855 // if (pModifier->scanCodePrefix() != 0)856 // sequence << pModifier->scanCodePrefix();857 // sequence << pModifier->scanCode();858 // }859 860 // if (pKey->scanCodePrefix() != 0)861 // sequence << pKey->scanCodePrefix();862 // sequence << pKey->scanCode();863 // keyboard().PutScancodes(sequence);864 }865 866 void UISoftKeyboard::sltHandleKeyRelease()867 {868 //UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());869 // if (!pKey)870 // return;871 // /* We only send the scan codes of Ordinary keys: */872 // if (pKey->type() == UIKeyType_Modifier)873 // return;874 875 // QVector<LONG> sequence;876 // if (pKey->scanCodePrefix() != 0)877 // sequence << pKey->scanCodePrefix();878 // sequence << (pKey->scanCode() | 0x80);879 880 // /* Add the pressed modifiers in the reverse order: */881 // for (int i = m_pressedModifiers.size() - 1; i >= 0; --i)882 // {883 // UISoftKeyboardKey *pModifier = m_pressedModifiers[i];884 // if (pModifier->scanCodePrefix() != 0)885 // sequence << pModifier->scanCodePrefix();886 // sequence << (pModifier->scanCode() | 0x80);887 // /* Release the pressed modifiers (if there are not locked): */888 // pModifier->release();889 // }890 // keyboard().PutScancodes(sequence);891 }892 893 void UISoftKeyboard::sltHandleModifierStateChange()894 {895 // UISoftKeyboardKey *pKey = qobject_cast<UISoftKeyboardKey*>(sender());896 // if (!pKey)897 // return;898 // if (pKey->type() != UIKeyType_Modifier)899 // return;900 // if (pKey->state() == UIKeyState_NotPressed)901 // {902 // m_pressedModifiers.removeOne(pKey);903 // }904 // else905 // {906 // if (!m_pressedModifiers.contains(pKey))907 // m_pressedModifiers.append(pKey);908 // }909 }910 911 987 void UISoftKeyboard::sltHandleKeyboardLedsChange() 912 988 { 913 989 // bool fNumLockLed = m_pSession->isNumLock(); 914 990 // bool fCapsLockLed = m_pSession->isCapsLock(); 915 // bool fScrollLock = m_pSession->isScrollLock(); 991 // bool fScrollLockLed = m_pSession->isScrollLock(); 992 } 993 994 void UISoftKeyboard::sltHandlePutKeyboardSequence(QVector<LONG> sequence) 995 { 996 keyboard().PutScancodes(sequence); 916 997 } 917 998 … … 929 1010 { 930 1011 connect(m_pSession, &UISession::sigKeyboardLedsChange, this, &UISoftKeyboard::sltHandleKeyboardLedsChange); 1012 connect(m_pContainerWidget, &UISoftKeyboardWidget::sigPutKeyboardSequence, this, &UISoftKeyboard::sltHandlePutKeyboardSequence); 931 1013 } 932 1014 … … 943 1025 } 944 1026 945 void UISoftKeyboard:: parseLayout()1027 void UISoftKeyboard::createKeyboard() 946 1028 { 947 1029 if (!m_pContainerWidget) 948 1030 return; 949 1031 UIKeyboardLayoutReader reader; 950 QVector<UISoftKeyboardRow> &rows = m_pContainerWidget-> m_rows;1032 QVector<UISoftKeyboardRow> &rows = m_pContainerWidget->rows(); 951 1033 if (!reader.parseXMLFile(":/102_iso.xml", rows)) 952 1034 return; 953 1035 int iY = m_iTopMargin; 954 1036 int iMaxWidth = 0; 1037 955 1038 for (int i = 0; i < rows.size(); ++i) 956 1039 { … … 963 1046 key.setKeyGeometry(QRect(iX, iY, key.width(), key.height())); 964 1047 key.setPolygon(QPolygon(UIKeyboardLayoutReader::computeKeyVertices(key))); 1048 key.setParentWidget(m_pContainerWidget); 965 1049 iX += key.width(); 966 1050 if (j < row.keys().size() - 1) -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78891 r78921 59 59 private slots: 60 60 61 void sltHandleKeyPress();62 void sltHandleKeyRelease();63 void sltHandleModifierStateChange();64 61 void sltHandleKeyboardLedsChange(); 62 void sltHandlePutKeyboardSequence(QVector<LONG> sequence); 65 63 66 64 private: … … 71 69 void saveSettings(); 72 70 void loadSettings(); 73 void parseLayout();71 void createKeyboard(); 74 72 CKeyboard& keyboard() const; 75 73 … … 78 76 UISoftKeyboardWidget *m_pContainerWidget; 79 77 QString m_strMachineName; 80 QVector<UISoftKeyboardKey*> m_pressedModifiers;81 bool m_fKeepAspectRatio;82 78 83 79 int m_iXSpacing; -
trunk/src/VBox/Frontends/VirtualBox/xml/102_iso.xml
r78884 r78921 81 81 </space> 82 82 <key> 83 <keycap>PrtScn</keycap> 83 <keycap>Prt</keycap> 84 <keycap>Scn</keycap> 84 85 <position>124</position> 85 86 <scancodeprefix>0xe0</scancodeprefix> … … 294 295 </space> 295 296 <key> 296 <keycap>Del ete</keycap>297 <keycap>Del</keycap> 297 298 <position>76</position> 298 299 <scancode>0x53</scancode>
Note:
See TracChangeset
for help on using the changeset viewer.