Changeset 78975 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 4, 2019 6:29:55 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131102
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78964 r78975 19 19 #include <QApplication> 20 20 #include <QFile> 21 #include <QLineEdit> 21 22 #include <QMenu> 22 23 #include <QPainter> … … 63 64 * UISoftKeyboardRow definition. * 64 65 *********************************************************************************************************************************/ 66 65 67 /** UISoftKeyboardRow represents a row in the physical keyboard. */ 66 68 class UISoftKeyboardRow … … 94 96 * UISoftKeyboardKey definition. * 95 97 *********************************************************************************************************************************/ 98 96 99 /** UISoftKeyboardKey is a place holder for a keyboard key. Graphical key represantations are drawn according to this class. */ 97 100 class UISoftKeyboardKey … … 199 202 void mouseReleaseEvent(QMouseEvent *pEvent) /* override */; 200 203 void mouseMoveEvent(QMouseEvent *pEvent) /* override */; 204 bool eventFilter(QObject *pWatched, QEvent *pEvent)/* override */; 201 205 202 206 virtual void retranslateUi() /* override */; … … 206 210 void sltHandleMenuBarContextMenuRequest(const QPoint &point); 207 211 void sltHandleLoadLayout(QAction *pSenderAction); 208 void sltHandle ShowKeyPositions();212 void sltHandleKeyCapEdit(); 209 213 210 214 private: … … 214 218 /** Searches for the key which contains the position of the @p pEvent and returns it if found. */ 215 219 UISoftKeyboardKey *keyUnderMouse(QMouseEvent *pEvent); 220 UISoftKeyboardKey *keyUnderMouse(const QPoint &point); 216 221 void handleKeyPress(UISoftKeyboardKey *pKey); 217 222 void handleKeyRelease(UISoftKeyboardKey *pKey); … … 222 227 223 228 UISoftKeyboardKey *m_pKeyUnderMouse; 229 UISoftKeyboardKey *m_pKeyBeingEdited; 230 224 231 UISoftKeyboardKey *m_pKeyPressed; 225 232 QColor m_keyDefaultColor; … … 248 255 QAction *m_pLoadLayoutFileAction; 249 256 QAction *m_pLastSelectedLayout; 257 QAction *m_pChangeKeyCapAction; 258 QLineEdit *m_pKeyCapEditor; 250 259 }; 251 260 … … 362 371 void UISoftKeyboardKey::setKeyCap(const QString &strKeyCap) 363 372 { 364 if (m_strKeyCap.isEmpty()) 365 m_strKeyCap = strKeyCap; 366 else 367 m_strKeyCap += "\n" + strKeyCap; 373 m_strKeyCap = strKeyCap; 368 374 } 369 375 … … 545 551 :QIWithRetranslateUI<QWidget>(pParent) 546 552 , m_pKeyUnderMouse(0) 553 , m_pKeyBeingEdited(0) 547 554 , m_pKeyPressed(0) 548 555 , m_keyDefaultColor(QColor(103, 128, 159)) … … 562 569 , m_pLoadLayoutFileAction(0) 563 570 , m_pLastSelectedLayout(0) 571 , m_pChangeKeyCapAction(0) 564 572 { 565 573 … … 597 605 float fLedRadius = 0.8 * unitSize; 598 606 float fLedMargin = 0.6 * unitSize; 599 607 if (!m_pKeyBeingEdited && m_pKeyCapEditor) 608 m_pKeyCapEditor->hide(); 600 609 for (int i = 0; i < m_rows.size(); ++i) 601 610 { … … 609 618 else 610 619 painter.setBrush(QBrush(m_keyDefaultColor)); 620 621 if (&key == m_pKeyBeingEdited) 622 { 623 //m_pKeyCapEditor->setText(key.keyCap()); 624 m_pKeyCapEditor->setFont(painterFont); 625 m_pKeyCapEditor->setGeometry(m_fScaleFactorX * key.keyGeometry().x(), m_fScaleFactorY * key.keyGeometry().y(), 626 m_fScaleFactorX * key.keyGeometry().width(), m_fScaleFactorY * key.keyGeometry().height()); 627 m_pKeyCapEditor->show(); 628 629 } 611 630 612 631 if (&key == m_pKeyPressed) … … 647 666 void UISoftKeyboardWidget::mousePressEvent(QMouseEvent *pEvent) 648 667 { 668 QWidget::mousePressEvent(pEvent); 649 669 if (pEvent->button() != Qt::LeftButton) 650 670 return; … … 656 676 void UISoftKeyboardWidget::mouseReleaseEvent(QMouseEvent *pEvent) 657 677 { 678 QWidget::mouseReleaseEvent(pEvent); 658 679 if (pEvent->button() != Qt::LeftButton) 659 680 return; … … 667 688 void UISoftKeyboardWidget::mouseMoveEvent(QMouseEvent *pEvent) 668 689 { 690 QWidget::mouseMoveEvent(pEvent); 669 691 keyUnderMouse(pEvent); 670 692 } 671 693 672 void UISoftKeyboard::focusOutEvent(QFocusEvent *pEvent) 673 { 674 QIWithRetranslateUI<QMainWindow>::focusOutEvent(pEvent); 675 printf("booo\n"); 676 } 694 bool UISoftKeyboardWidget::eventFilter(QObject *pWatched, QEvent *pEvent) 695 { 696 if (pWatched != m_pKeyCapEditor) 697 return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent); 698 699 switch (pEvent->type()) 700 { 701 /* Process key press only: */ 702 case QEvent::KeyPress: 703 { 704 /* Cast to corresponding key press event: */ 705 QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent); 706 707 /* Handle Ctrl+T key combination as a shortcut to focus search field: */ 708 if (pKeyEvent->key() == Qt::Key_Escape) 709 { 710 m_pKeyBeingEdited = 0; 711 update(); 712 return true; 713 } 714 else if (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return) 715 { 716 if (m_pKeyBeingEdited) 717 m_pKeyBeingEdited->setKeyCap(m_pKeyCapEditor->text()); 718 m_pKeyBeingEdited = 0; 719 update(); 720 return true; 721 } 722 break; 723 } 724 default: 725 break; 726 } 727 728 return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent); 729 } 730 677 731 678 732 void UISoftKeyboardWidget::retranslateUi() … … 682 736 void UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest(const QPoint &point) 683 737 { 738 m_pChangeKeyCapAction->setEnabled(m_pKeyUnderMouse); 684 739 m_pContextMenu->exec(mapToGlobal(point)); 685 740 update(); … … 719 774 } 720 775 721 void UISoftKeyboardWidget::sltHandleShowKeyPositions() 722 { 723 776 void UISoftKeyboardWidget::sltHandleKeyCapEdit() 777 { 778 m_pKeyBeingEdited = m_pKeyUnderMouse; 779 if (m_pKeyBeingEdited && m_pKeyCapEditor) 780 m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap()); 724 781 } 725 782 … … 739 796 { 740 797 QPoint eventPosition(pEvent->pos().x() / m_fScaleFactorX, pEvent->pos().y() / m_fScaleFactorY); 741 QWidget::mousePressEvent(pEvent); 798 return keyUnderMouse(eventPosition); 799 } 800 801 UISoftKeyboardKey *UISoftKeyboardWidget::keyUnderMouse(const QPoint &eventPosition) 802 { 803 UISoftKeyboardKey *pKey = 0; 742 804 for (int i = 0; i < m_rows.size(); ++i) 743 805 { … … 748 810 if (key.polygonInGlobal().containsPoint(eventPosition, Qt::OddEvenFill)) 749 811 { 750 if (&key != m_pKeyUnderMouse) 751 { 752 m_pKeyUnderMouse = &key; 753 update(); 754 } 755 return &key; 812 pKey = &key; 756 813 break; 757 814 } 758 815 } 759 816 } 760 return 0; 817 if (m_pKeyUnderMouse != pKey) 818 { 819 m_pKeyUnderMouse = pKey; 820 update(); 821 } 822 return pKey; 761 823 } 762 824 … … 894 956 void UISoftKeyboardWidget::prepareObjects() 895 957 { 958 m_pKeyCapEditor = new QLineEdit(this); 959 if (m_pKeyCapEditor) 960 { 961 m_pKeyCapEditor->hide(); 962 m_pKeyCapEditor->installEventFilter(this); 963 } 896 964 m_pContextMenu = new QMenu(this); 897 //m_pShowPositionsAction = m_pContextMenu->addAction("898 965 m_pLayoutActionGroup = new QActionGroup(this); 899 966 m_pLayoutActionGroup->setExclusive(true); … … 914 981 915 982 m_pShowPositionsAction = m_pContextMenu->addAction(UISoftKeyboard::tr("Show key positions instead of key caps")); 916 connect(m_pLayoutActionGroup, &QActionGroup::triggered, this, &UISoftKeyboardWidget::sltHandleShowKeyPositions); 983 917 984 m_pShowPositionsAction->setCheckable(true); 918 985 m_pShowPositionsAction->setChecked(false); 986 987 m_pChangeKeyCapAction = m_pContextMenu->addAction(UISoftKeyboard::tr("Add/change key cap")); 988 connect(m_pChangeKeyCapAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleKeyCapEdit); 989 QAction *pSaveKepCapFile = m_pContextMenu->addAction(UISoftKeyboard::tr("Save key caps to file")); 990 Q_UNUSED(pSaveKepCapFile); 919 991 920 992 /* Choose the first layput action's data as the defaults one: */ … … 1018 1090 key.setWidth(row.defaultWidth()); 1019 1091 key.setHeight(row.defaultHeight()); 1020 1092 QString strKeyCap; 1021 1093 while (m_xmlReader.readNextStartElement()) 1022 1094 { … … 1038 1110 } 1039 1111 else if (m_xmlReader.name() == "keycap") 1040 key.setKeyCap(m_xmlReader.readElementText()); 1112 { 1113 QString strCap = m_xmlReader.readElementText(); 1114 if (strKeyCap.isEmpty()) 1115 strKeyCap = strCap; 1116 else 1117 strKeyCap += "\n" + strCap; 1118 } 1041 1119 else if (m_xmlReader.name() == "cutout") 1042 1120 parseCutout(key); 1043 else if (m_xmlReader.name() == "position")1121 else if (m_xmlReader.name() == "position") 1044 1122 key.setPosition(m_xmlReader.readElementText().toInt()); 1045 1123 else if (m_xmlReader.name() == "type") … … 1054 1132 m_xmlReader.skipCurrentElement(); 1055 1133 } 1134 key.setKeyCap(strKeyCap); 1056 1135 } 1057 1136 -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78964 r78975 56 56 57 57 virtual void retranslateUi() /* override */; 58 void focusOutEvent(QFocusEvent *pEvent) /* override */;59 58 60 59 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.