Changeset 78953 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 4, 2019 8:10:48 AM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 deleted
- 5 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r78724 r78953 759 759 src/runtime/seamless/UIMachineWindowSeamless.h \ 760 760 src/softkeyboard/UISoftKeyboard.h \ 761 src/softkeyboard/UISoftKeyboardDialog.h \762 761 src/widgets/UIMiniToolBar.h \ 763 762 src/wizards/firstrun/UIWizardFirstRun.h \ … … 1213 1212 src/runtime/seamless/UIMachineWindowSeamless.cpp \ 1214 1213 src/softkeyboard/UISoftKeyboard.cpp \ 1215 src/softkeyboard/UISoftKeyboardDialog.cpp \1216 1214 src/widgets/UIMiniToolBar.cpp \ 1217 1215 src/wizards/firstrun/UIWizardFirstRun.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox_xml.qrc
r78812 r78953 1 1 <RCC> 2 2 <qresource suffix="/"> 3 <file alias=" us_layout.xml">xml/us_layout.xml</file>3 <file alias="101_ansi.xml">xml/101_ansi.xml</file> 4 4 <file alias="102_iso.xml">xml/102_iso.xml</file> 5 5 </qresource> -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78925 r78953 19 19 #include <QApplication> 20 20 #include <QFile> 21 #include <QMenu> 21 22 #include <QPainter> 22 23 #include <QStyle> … … 27 28 /* GUI includes: */ 28 29 #include "QIDialogButtonBox.h" 30 #include "QIFileDialog.h" 29 31 #include "UIExtraDataManager.h" 30 32 #include "UISession.h" … … 61 63 * UISoftKeyboardRow definition. * 62 64 *********************************************************************************************************************************/ 63 65 /** UISoftKeyboardRow represents a row in the physical keyboard. */ 64 66 class UISoftKeyboardRow 65 67 { … … 92 94 * UISoftKeyboardKey definition. * 93 95 *********************************************************************************************************************************/ 94 96 /** UISoftKeyboardKey is a place holder for a keyboard key. Graphical key represantations are drawn according to this class. */ 95 97 class UISoftKeyboardKey 96 98 { … … 173 175 * UISoftKeyboardWidget definition. * 174 176 *********************************************************************************************************************************/ 175 class UISoftKeyboardWidget : public QWidget 177 178 /** The container widget for keyboard keys. It also handles all the keyboard related events. */ 179 class UISoftKeyboardWidget : public QIWithRetranslateUI<QWidget> 176 180 { 177 181 Q_OBJECT; … … 187 191 virtual QSize minimumSizeHint() const; 188 192 virtual QSize sizeHint() const; 189 void setNewMinimumSize(const QSize &size);190 191 QVector<UISoftKeyboardRow> &rows();192 const QVector<UISoftKeyboardRow> &rows() const;193 194 void setInitialSize(int iWidth, int iHeight);195 193 void keyStateChange(UISoftKeyboardKey* pKey); 196 194 … … 200 198 void mousePressEvent(QMouseEvent *pEvent) /* override */; 201 199 void mouseReleaseEvent(QMouseEvent *pEvent) /* override */; 202 void mouseMoveEvent(QMouseEvent *pEvent); 200 void mouseMoveEvent(QMouseEvent *pEvent) /* override */; 201 virtual void retranslateUi() /* override */; 202 203 private slots: 204 205 void sltHandleMenuBarContextMenuRequest(const QPoint &point); 206 void sltHandleLoadLayoutFile(); 207 void sltHandleLoadDefaultLayout(); 203 208 204 209 private: 205 210 211 void setNewMinimumSize(const QSize &size); 212 void setInitialSize(int iWidth, int iHeight); 213 /** Searches for the key which contains the position of the @p pEvent and returns it if found. */ 206 214 UISoftKeyboardKey *keyUnderMouse(QMouseEvent *pEvent); 207 215 void handleKeyPress(UISoftKeyboardKey *pKey); 208 216 void handleKeyRelease(UISoftKeyboardKey *pKey); 209 QSize m_minimumSize; 210 int m_iInitialHeight; 211 int m_iInitialWidth; 212 float m_fMultiplierX; 213 float m_fMultiplierY; 217 void createKeyboard(const QString &strLayoutFileName = QString()); 218 void reset(); 219 214 220 UISoftKeyboardKey *m_pKeyUnderMouse; 215 221 UISoftKeyboardKey *m_pKeyPressed; … … 219 225 QColor m_textPressedColor; 220 226 QVector<UISoftKeyboardKey*> m_pressedModifiers; 221 QVector<UISoftKeyboardRow> m_rows; 227 QVector<UISoftKeyboardRow> m_rows; 228 QStringList defaultLayouts; 229 230 QSize m_minimumSize; 231 float m_fScaleFactorX; 232 float m_fScaleFactorY; 233 int m_iInitialHeight; 234 int m_iInitialWidth; 235 int m_iXSpacing; 236 int m_iYSpacing; 237 int m_iLeftMargin; 238 int m_iTopMargin; 239 int m_iRightMargin; 240 int m_iBottomMargin; 222 241 }; 223 242 … … 515 534 516 535 UISoftKeyboardWidget::UISoftKeyboardWidget(QWidget *pParent /* = 0 */) 517 :Q Widget(pParent)536 :QIWithRetranslateUI<QWidget>(pParent) 518 537 , m_pKeyUnderMouse(0) 519 538 , m_pKeyPressed(0) … … 522 541 , m_textDefaultColor(QColor(46, 49, 49)) 523 542 , m_textPressedColor(QColor(149, 165, 166)) 524 { 543 , m_iInitialHeight(0) 544 , m_iInitialWidth(0) 545 , m_iXSpacing(5) 546 , m_iYSpacing(5) 547 , m_iLeftMargin(10) 548 , m_iTopMargin(10) 549 , m_iRightMargin(10) 550 , m_iBottomMargin(10) 551 { 552 defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml"; 525 553 setMouseTracking(true); 554 setContextMenuPolicy(Qt::CustomContextMenu); 555 createKeyboard(); 556 connect(this, &UISoftKeyboardWidget::customContextMenuRequested, 557 this, &UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest); 526 558 } 527 559 … … 534 566 { 535 567 return m_minimumSize; 536 }537 538 void UISoftKeyboardWidget::setNewMinimumSize(const QSize &size)539 {540 m_minimumSize = size;541 updateGeometry();542 }543 544 void UISoftKeyboardWidget::setInitialSize(int iWidth, int iHeight)545 {546 m_iInitialWidth = iWidth;547 m_iInitialHeight = iHeight;548 }549 550 QVector<UISoftKeyboardRow> &UISoftKeyboardWidget::rows()551 {552 return m_rows;553 }554 555 const QVector<UISoftKeyboardRow> &UISoftKeyboardWidget::rows() const556 {557 return m_rows;558 568 } 559 569 … … 564 574 return; 565 575 566 m_f MultiplierX = width() / (float) m_iInitialWidth;567 m_f MultiplierY = height() / (float) m_iInitialHeight;576 m_fScaleFactorX = width() / (float) m_iInitialWidth; 577 m_fScaleFactorY = height() / (float) m_iInitialHeight; 568 578 569 579 QPainter painter(this); … … 573 583 painter.setFont(painterFont); 574 584 painter.setRenderHint(QPainter::Antialiasing); 575 painter.scale(m_f MultiplierX, m_fMultiplierY);585 painter.scale(m_fScaleFactorX, m_fScaleFactorY); 576 586 int unitSize = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin); 577 587 float fLedRadius = 0.8 * unitSize; … … 597 607 painter.drawPolygon(key.polygon()); 598 608 599 QRect textRect(0. 8* unitSize, 1 * unitSize609 QRect textRect(0.55 * unitSize, 1 * unitSize 600 610 , key.keyGeometry().width(), key.keyGeometry().height()); 601 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 611 //painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 612 painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position())); 602 613 603 614 if (key.type() != UIKeyType_Ordinary) … … 623 634 void UISoftKeyboardWidget::mousePressEvent(QMouseEvent *pEvent) 624 635 { 636 if (pEvent->button() != Qt::LeftButton) 637 return; 625 638 m_pKeyPressed = keyUnderMouse(pEvent); 626 639 handleKeyPress(m_pKeyPressed); … … 628 641 } 629 642 630 void UISoftKeyboardWidget::mouseReleaseEvent(QMouseEvent *) 631 { 643 void UISoftKeyboardWidget::mouseReleaseEvent(QMouseEvent *pEvent) 644 { 645 if (pEvent->button() != Qt::LeftButton) 646 return; 632 647 if (!m_pKeyPressed) 633 648 return; … … 642 657 } 643 658 659 void UISoftKeyboardWidget::retranslateUi() 660 { 661 } 662 663 void UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest(const QPoint &point) 664 { 665 QMenu menu; 666 foreach (const QString &strLayout, defaultLayouts) 667 { 668 QString strName = strLayout.left(strLayout.indexOf('.')); 669 QAction *pAction = menu.addAction(QString("%1 %2").arg(UISoftKeyboard::tr("Load Layout ")).arg(strName.remove(":/"))); 670 pAction->setData(strLayout); 671 connect(pAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadDefaultLayout); 672 } 673 QAction *pAction = menu.addAction(UISoftKeyboard::tr("Load Layout File")); 674 connect(pAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadLayoutFile); 675 menu.exec(mapToGlobal(point)); 676 } 677 678 void UISoftKeyboardWidget::sltHandleLoadLayoutFile() 679 { 680 const QString strFileName = QIFileDialog::getOpenFileName(QString(), "XML files (*.xml)", this, 681 UISoftKeyboard::tr("Choose file to load physical keyboard layout..")); 682 if (strFileName.isEmpty()) 683 return; 684 createKeyboard(strFileName); 685 } 686 687 void UISoftKeyboardWidget::sltHandleLoadDefaultLayout() 688 { 689 QAction *pSender = qobject_cast<QAction*>(sender()); 690 if (!pSender) 691 return; 692 QString strLayout = pSender->data().toString(); 693 if (strLayout.isEmpty()) 694 return; 695 createKeyboard(strLayout); 696 } 697 698 699 void UISoftKeyboardWidget::setNewMinimumSize(const QSize &size) 700 { 701 m_minimumSize = size; 702 updateGeometry(); 703 } 704 705 void UISoftKeyboardWidget::setInitialSize(int iWidth, int iHeight) 706 { 707 m_iInitialWidth = iWidth; 708 m_iInitialHeight = iHeight; 709 } 710 644 711 UISoftKeyboardKey *UISoftKeyboardWidget::keyUnderMouse(QMouseEvent *pEvent) 645 712 { 646 QPoint eventPosition(pEvent->pos().x() / m_f MultiplierX, pEvent->pos().y() / m_fMultiplierY);713 QPoint eventPosition(pEvent->pos().x() / m_fScaleFactorX, pEvent->pos().y() / m_fScaleFactorY); 647 714 QWidget::mousePressEvent(pEvent); 648 715 for (int i = 0; i < m_rows.size(); ++i) … … 733 800 } 734 801 emit sigPutKeyboardSequence(sequence); 802 } 803 804 void UISoftKeyboardWidget::createKeyboard(const QString &strLayoutFileName /* = QString() */) 805 { 806 UIKeyboardLayoutReader reader; 807 QVector<UISoftKeyboardRow> &rows = m_rows; 808 reset(); 809 bool fParseSuccess = false; 810 if (strLayoutFileName.isEmpty()) 811 fParseSuccess = reader.parseXMLFile(":/101_ansi.xml", rows); 812 else 813 fParseSuccess = reader.parseXMLFile(strLayoutFileName, rows); 814 815 if (!fParseSuccess) 816 return; 817 818 int iY = m_iTopMargin; 819 int iMaxWidth = 0; 820 821 for (int i = 0; i < rows.size(); ++i) 822 { 823 UISoftKeyboardRow &row = rows[i]; 824 int iX = m_iLeftMargin; 825 int iRowHeight = row.defaultHeight(); 826 for (int j = 0; j < row.keys().size(); ++j) 827 { 828 UISoftKeyboardKey &key = (row.keys())[j]; 829 key.setKeyGeometry(QRect(iX, iY, key.width(), key.height())); 830 key.setPolygon(QPolygon(UIKeyboardLayoutReader::computeKeyVertices(key))); 831 key.setParentWidget(this); 832 iX += key.width(); 833 if (j < row.keys().size() - 1) 834 iX += m_iXSpacing; 835 if (key.spaceWidthAfter() != 0) 836 iX += (m_iXSpacing + key.spaceWidthAfter()); 837 } 838 if (row.spaceHeightAfter() != 0) 839 iY += row.spaceHeightAfter() + m_iYSpacing; 840 iMaxWidth = qMax(iMaxWidth, iX); 841 iY += iRowHeight; 842 if (i < rows.size() - 1) 843 iY += m_iYSpacing; 844 } 845 int iInitialWidth = iMaxWidth + m_iRightMargin; 846 int iInitialHeight = iY + m_iBottomMargin; 847 float fScale = 1.0f; 848 setNewMinimumSize(QSize(fScale * iInitialWidth, fScale * iInitialHeight)); 849 setInitialSize(fScale * iInitialWidth, fScale * iInitialHeight); 850 update(); 851 } 852 853 void UISoftKeyboardWidget::reset() 854 { 855 m_pressedModifiers.clear(); 856 m_rows.clear(); 735 857 } 736 858 … … 960 1082 , m_pContainerWidget(0) 961 1083 , m_strMachineName(strMachineName) 962 , m_iXSpacing(5) 963 , m_iYSpacing(5) 964 , m_iLeftMargin(10) 965 , m_iTopMargin(10) 966 , m_iRightMargin(10) 967 , m_iBottomMargin(10) 968 { 1084 { 1085 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Soft Keyboard"))); 969 1086 setAttribute(Qt::WA_DeleteOnClose); 970 1087 prepareObjects(); 971 createKeyboard();972 1088 prepareConnections(); 973 1089 prepareToolBar(); … … 1025 1141 } 1026 1142 1027 void UISoftKeyboard::createKeyboard()1028 {1029 if (!m_pContainerWidget)1030 return;1031 UIKeyboardLayoutReader reader;1032 QVector<UISoftKeyboardRow> &rows = m_pContainerWidget->rows();1033 if (!reader.parseXMLFile(":/102_iso.xml", rows))1034 return;1035 int iY = m_iTopMargin;1036 int iMaxWidth = 0;1037 1038 for (int i = 0; i < rows.size(); ++i)1039 {1040 UISoftKeyboardRow &row = rows[i];1041 int iX = m_iLeftMargin;1042 int iRowHeight = row.defaultHeight();1043 for (int j = 0; j < row.keys().size(); ++j)1044 {1045 UISoftKeyboardKey &key = (row.keys())[j];1046 key.setKeyGeometry(QRect(iX, iY, key.width(), key.height()));1047 key.setPolygon(QPolygon(UIKeyboardLayoutReader::computeKeyVertices(key)));1048 key.setParentWidget(m_pContainerWidget);1049 iX += key.width();1050 if (j < row.keys().size() - 1)1051 iX += m_iXSpacing;1052 if (key.spaceWidthAfter() != 0)1053 iX += (m_iXSpacing + key.spaceWidthAfter());1054 }1055 if (row.spaceHeightAfter() != 0)1056 iY += row.spaceHeightAfter() + m_iYSpacing;1057 iMaxWidth = qMax(iMaxWidth, iX);1058 iY += iRowHeight;1059 if (i < rows.size() - 1)1060 iY += m_iYSpacing;1061 }1062 int iInitialWidth = iMaxWidth + m_iRightMargin;1063 int iInitialHeight = iY + m_iBottomMargin;1064 m_pContainerWidget->setNewMinimumSize(QSize(iInitialWidth, iInitialHeight));1065 m_pContainerWidget->setInitialSize(iInitialWidth, iInitialHeight);1066 }1067 1068 1143 CKeyboard& UISoftKeyboard::keyboard() const 1069 1144 { -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r78921 r78953 55 55 protected: 56 56 57 virtual void retranslateUi() ;57 virtual void retranslateUi() /* override */; 58 58 59 59 private slots: … … 76 76 UISoftKeyboardWidget *m_pContainerWidget; 77 77 QString m_strMachineName; 78 79 int m_iXSpacing;80 int m_iYSpacing;81 int m_iLeftMargin;82 int m_iTopMargin;83 int m_iRightMargin;84 int m_iBottomMargin;85 78 }; 86 79 -
trunk/src/VBox/Frontends/VirtualBox/xml/101_ansi.xml
r78933 r78953 240 240 </key> 241 241 <key> 242 <position>29</position> 243 <scancode>0x2b</scancode> 242 244 <width>85</width> 243 <height>105</height>244 <keycap>Enter</keycap>245 <position>43</position>246 <scancode>0x1c</scancode>247 <cutout>248 <width>25</width>249 <height>55</height>250 <corner>bottomLeft</corner>251 </cutout>252 245 </key> 253 246 <space> … … 326 319 </key> 327 320 <key> 328 <position>42</position> 329 <scancode>0xff</scancode> 330 </key> 331 </row> 332 <row> 333 <key> 334 <width>75</width> 321 <width>115</width> 322 <keycap>Enter</keycap> 323 <position>43</position> 324 <scancode>0x1c</scancode> 325 </key> 326 </row> 327 <row> 328 <key> 329 <width>125</width> 335 330 <keycap>Shift</keycap> 336 331 <type>modifier</type> … … 339 334 </key> 340 335 <key> 341 <position>45</position>342 <scancode>0x35</scancode>343 </key>344 <key>345 336 <position>46</position> 346 337 <scancode>0x2c</scancode> … … 383 374 </key> 384 375 <key> 385 <width>14 0</width>376 <width>145</width> 386 377 <keycap>Shift</keycap> 387 378 <type>modifier</type> … … 401 392 <row> 402 393 <key> 403 <width> 105</width>394 <width>90</width> 404 395 <keycap>Ctrl</keycap> 405 396 <type>modifier</type> … … 409 400 <key> 410 401 <keycap>Win</keycap> 402 <width>75</width> 411 403 <type>modifier</type> 412 404 <scancodeprefix>0xe0</scancodeprefix> … … 416 408 <position>60</position> 417 409 <keycap>Alt</keycap> 410 <width>75</width> 418 411 <type>modifier</type> 419 412 <scancode>0x38</scancode> 420 413 </key> 421 414 <key> 422 <width> 330</width>415 <width>235</width> 423 416 <position>61</position> 424 417 <scancode>0x39</scancode> … … 426 419 <key> 427 420 <keycap>AltGr</keycap> 421 <width>75</width> 428 422 <type>modifier</type> 429 423 <position>62</position> … … 433 427 <key> 434 428 <keycap>Win</keycap> 429 <width>75</width> 435 430 <type>modifier</type> 436 431 <scancodeprefix>0xe0</scancodeprefix> … … 439 434 <key> 440 435 <keycap>Menu</keycap> 436 <width>75</width> 441 437 <scancodeprefix>0xe0</scancodeprefix> 442 438 <scancode>0x5d</scancode> … … 444 440 <key> 445 441 <keycap>Ctrl</keycap> 446 <width> 105</width>442 <width>90</width> 447 443 <position>64</position> 448 444 <type>modifier</type> -
trunk/src/VBox/Frontends/VirtualBox/xml/102_iso.xml
r78933 r78953 401 401 <row> 402 402 <key> 403 <width> 105</width>403 <width>90</width> 404 404 <keycap>Ctrl</keycap> 405 405 <type>modifier</type> … … 409 409 <key> 410 410 <keycap>Win</keycap> 411 <width>75</width> 411 412 <type>modifier</type> 412 413 <scancodeprefix>0xe0</scancodeprefix> … … 416 417 <position>60</position> 417 418 <keycap>Alt</keycap> 419 <width>75</width> 418 420 <type>modifier</type> 419 421 <scancode>0x38</scancode> 420 422 </key> 421 423 <key> 422 <width> 330</width>424 <width>235</width> 423 425 <position>61</position> 424 426 <scancode>0x39</scancode> … … 426 428 <key> 427 429 <keycap>AltGr</keycap> 430 <width>75</width> 428 431 <type>modifier</type> 429 432 <position>62</position> … … 433 436 <key> 434 437 <keycap>Win</keycap> 438 <width>75</width> 435 439 <type>modifier</type> 436 440 <scancodeprefix>0xe0</scancodeprefix> … … 439 443 <key> 440 444 <keycap>Menu</keycap> 445 <width>75</width> 441 446 <scancodeprefix>0xe0</scancodeprefix> 442 447 <scancode>0x5d</scancode> … … 444 449 <key> 445 450 <keycap>Ctrl</keycap> 446 <width> 105</width>451 <width>90</width> 447 452 <position>64</position> 448 453 <type>modifier</type>
Note:
See TracChangeset
for help on using the changeset viewer.