Changeset 79103 in vbox
- Timestamp:
- Jun 12, 2019 9:18:13 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131265
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r79089 r79103 19 19 #include <QApplication> 20 20 #include <QFile> 21 #include <QGroupBox> 21 22 #include <QLabel> 22 23 #include <QLineEdit> 23 24 #include <QMenu> 24 25 #include <QPainter> 26 #include <QPushButton> 25 27 #include <QStatusBar> 26 28 #include <QStyle> … … 70 72 *********************************************************************************************************************************/ 71 73 72 class UISoftKeyEditor : public QIWithRetranslateUI<Q MainWindow>74 class UISoftKeyEditor : public QIWithRetranslateUI<QWidget> 73 75 { 74 76 Q_OBJECT; 75 77 78 signals: 79 80 void sigKeyCaptionEdited(); 81 76 82 public: 77 83 78 84 UISoftKeyEditor(QWidget *pParent = 0); 85 void setKey(UISoftKeyboardKey *pKey); 79 86 80 87 protected: 81 88 82 89 virtual void retranslateUi() /* override */; 90 91 private slots: 92 93 void sltHandleOkButton(); 83 94 84 95 private: … … 86 97 void prepareObjects(); 87 98 void prepareConnections(); 88 89 QGridLayout *m_pEditorLayout; 90 99 QWidget *prepareKeyCaptionEditWidgets(); 100 101 QVBoxLayout *m_pMainLayout; 102 QGridLayout *m_pCaptionEditorLayout; 103 QGroupBox *m_pSelectedKeyGroupBox; 104 QGroupBox *m_pCaptionEditGroupBox; 105 106 QLabel *m_pScanCodeLabel; 107 QLabel *m_pPositionLabel; 91 108 QLabel *m_pBaseCaptionLabel; 92 109 QLabel *m_pShiftCaptionLabel; 93 110 QLabel *m_pAltGrCaptionLabel; 94 111 112 QLineEdit *m_pScanCodeEdit; 113 QLineEdit *m_pPositionEdit; 95 114 QLineEdit *m_pBaseCaptionEdit; 96 115 QLineEdit *m_pShiftCaptionEdit; … … 99 118 QPushButton *m_pOkButton; 100 119 QPushButton *m_pCancelButton; 120 /** The key which is being currently edited. Might be Null. */ 121 UISoftKeyboardKey *m_pKey; 101 122 }; 102 123 … … 147 168 void setKeyGeometry(const QRect &rect); 148 169 149 const QString &staticKeyCap() const; 150 void setStaticKeyCap(const QString &strKeyCap); 151 152 const QString &keyCap() const; 153 void setKeyCap(const QString &strKeyCap); 170 const QString baseCaption() const; 171 void setBaseCaption(const QString &strBaseCaption); 172 173 const QString shiftCaption() const; 174 void setShiftCaption(const QString &strShiftCaption); 175 176 const QString altGrCaption() const; 177 void setAltGrCaption(const QString &strAltGrCaption); 178 179 const QString text() const; 154 180 155 181 void setWidth(int iWidth); … … 195 221 196 222 void updateState(bool fPressed); 223 void updateText(); 197 224 198 225 QRect m_keyGeometry; 199 /** Static keycaps are what is obtained from the layout file, as opposed to the keycaps file. 200 * normally they are the captions of modifier keys (Shift, etc) whose meaning stays the same across the layouts. */ 201 QString m_strStaticKeyCap; 202 /** Key caps are loaded from a keycap file and preferred over the static keycaps if they are not empty. */ 203 QString m_strKeyCap; 226 227 QString m_strBaseCaption; 228 QString m_strShiftCaption; 229 QString m_strAltGrCaption; 230 /** m_strText is concatenation of base, shift, and altgr captions. */ 231 QString m_strText; 204 232 205 233 /** Stores the key polygon in local coordinates. */ … … 267 295 268 296 void sltHandleContextMenuRequest(const QPoint &point); 269 void sltHandleLoadLayout(QAction *pSenderAction);270 297 void sltHandleSaveKeyCapFile(); 271 298 void sltHandleLoadKeyCapFile(); 272 299 void sltHandleUnloadKeyCaps(); 273 300 void sltHandleKepCapEditModeToggle(bool fToggle); 301 void sltHandleKeyCaptionEdited(); 274 302 275 303 private: … … 287 315 void prepareObjects(); 288 316 void enableDisableKeyCapEditMode(bool fEnable); 317 /** Sets m_pKeyBeingEdited. */ 318 void setKeyBeingEdited(UISoftKeyboardKey* pKey); 289 319 290 320 UISoftKeyboardKey *m_pKeyUnderMouse; … … 296 326 QColor m_textDefaultColor; 297 327 QColor m_textPressedColor; 328 QColor m_keyEditColor; 298 329 QVector<UISoftKeyboardKey*> m_pressedModifiers; 299 330 QVector<UISoftKeyboardRow> m_rows; 300 QStringList defaultLayouts;331 QStringList m_defaultLayouts; 301 332 302 333 QSize m_minimumSize; … … 314 345 315 346 QMenu *m_pContextMenu; 316 QActionGroup *m_pLayoutActionGroup;317 347 QAction *m_pShowPositionsAction; 318 QAction *m_pLoadLayoutFileAction;319 QAction *m_pLastSelectedLayout;320 348 QAction *m_pKeyCapEditModeToggleAction; 321 QLineEdit*m_pKeyCapEditor;349 UISoftKeyEditor *m_pKeyCapEditor; 322 350 Mode m_enmMode; 323 351 }; … … 373 401 374 402 UISoftKeyEditor::UISoftKeyEditor(QWidget *pParent /* = 0 */) 375 :QIWithRetranslateUI<QMainWindow>(pParent) 376 , m_pEditorLayout(0) 403 :QIWithRetranslateUI<QWidget>(pParent) 404 , m_pMainLayout(0) 405 , m_pCaptionEditorLayout(0) 406 , m_pSelectedKeyGroupBox(0) 407 , m_pCaptionEditGroupBox(0) 408 , m_pScanCodeLabel(0) 409 , m_pPositionLabel(0) 377 410 , m_pBaseCaptionLabel(0) 378 411 , m_pShiftCaptionLabel(0) 379 412 , m_pAltGrCaptionLabel(0) 413 , m_pScanCodeEdit(0) 414 , m_pPositionEdit(0) 380 415 , m_pBaseCaptionEdit(0) 381 416 , m_pShiftCaptionEdit(0) … … 383 418 , m_pOkButton(0) 384 419 , m_pCancelButton(0) 385 { 420 , m_pKey(0) 421 { 422 setAutoFillBackground(true); 386 423 prepareObjects(); 387 424 } 388 425 426 void UISoftKeyEditor::setKey(UISoftKeyboardKey *pKey) 427 { 428 if (m_pKey == pKey) 429 return; 430 m_pKey = pKey; 431 if (m_pSelectedKeyGroupBox) 432 m_pSelectedKeyGroupBox->setEnabled(m_pKey); 433 if (!m_pKey) 434 return; 435 if (m_pScanCodeEdit) 436 m_pScanCodeEdit->setText(QString::number(m_pKey->scanCode(), 16)); 437 if (m_pPositionEdit) 438 m_pPositionEdit->setText(QString::number(m_pKey->position())); 439 if (m_pBaseCaptionEdit) 440 m_pBaseCaptionEdit->setText(m_pKey->baseCaption()); 441 if (m_pShiftCaptionEdit) 442 m_pShiftCaptionEdit->setText(m_pKey->shiftCaption()); 443 if (m_pAltGrCaptionEdit) 444 m_pAltGrCaptionEdit->setText(m_pKey->altGrCaption()); 445 } 446 389 447 void UISoftKeyEditor::retranslateUi() 390 448 { 449 if (m_pScanCodeLabel) 450 m_pScanCodeLabel->setText(UISoftKeyboard::tr("Scan Code")); 451 if (m_pPositionLabel) 452 m_pPositionLabel->setText(UISoftKeyboard::tr("Position")); 391 453 if (m_pBaseCaptionLabel) 392 m_pBaseCaptionLabel->setText(UISoftKeyboard::tr("Base Caption")); 393 394 454 m_pBaseCaptionLabel->setText(UISoftKeyboard::tr("Base")); 395 455 if (m_pShiftCaptionLabel) 396 m_pShiftCaptionLabel->setText(UISoftKeyboard::tr("Shift Caption")); 397 456 m_pShiftCaptionLabel->setText(UISoftKeyboard::tr("Shift")); 398 457 if (m_pAltGrCaptionLabel) 399 m_pAltGrCaptionLabel->setText(UISoftKeyboard::tr("AltGr Caption")); 458 m_pAltGrCaptionLabel->setText(UISoftKeyboard::tr("AltGr")); 459 if (m_pOkButton) 460 m_pOkButton->setText(UISoftKeyboard::tr("Ok")); 461 if (m_pCancelButton) 462 m_pCancelButton->setText(UISoftKeyboard::tr("Cancel")); 463 if (m_pCaptionEditGroupBox) 464 m_pCaptionEditGroupBox->setTitle(UISoftKeyboard::tr("Captions")); 465 if (m_pSelectedKeyGroupBox) 466 m_pSelectedKeyGroupBox->setTitle(UISoftKeyboard::tr("Selected Key")); 467 } 468 469 void UISoftKeyEditor::sltHandleOkButton() 470 { 471 if (!m_pKey) 472 return; 473 m_pKey->setBaseCaption(m_pBaseCaptionEdit->text()); 474 m_pKey->setShiftCaption(m_pShiftCaptionEdit->text()); 475 m_pKey->setAltGrCaption(m_pAltGrCaptionEdit->text()); 476 emit sigKeyCaptionEdited(); 400 477 } 401 478 402 479 void UISoftKeyEditor::prepareObjects() 403 480 { 404 m_pEditorLayout = new QGridLayout; 405 406 if (!m_pEditorLayout) 407 return; 481 m_pMainLayout = new QVBoxLayout; 482 if (!m_pMainLayout) 483 return; 484 setLayout(m_pMainLayout); 485 486 m_pSelectedKeyGroupBox = new QGroupBox; 487 m_pSelectedKeyGroupBox->setEnabled(false); 488 489 m_pMainLayout->addWidget(m_pSelectedKeyGroupBox); 490 QGridLayout *pSelectedKeyLayout = new QGridLayout(m_pSelectedKeyGroupBox); 491 pSelectedKeyLayout->setSpacing(0); 492 pSelectedKeyLayout->setContentsMargins(0, 0, 0, 0); 493 494 m_pScanCodeLabel = new QLabel; 495 m_pScanCodeEdit = new QLineEdit; 496 m_pScanCodeLabel->setBuddy(m_pScanCodeEdit); 497 m_pScanCodeEdit->setReadOnly(true); 498 pSelectedKeyLayout->addWidget(m_pScanCodeLabel, 0, 0); 499 pSelectedKeyLayout->addWidget(m_pScanCodeEdit, 0, 1); 500 501 m_pPositionLabel= new QLabel; 502 m_pPositionEdit = new QLineEdit; 503 m_pPositionLabel->setBuddy(m_pPositionEdit); 504 m_pPositionEdit->setReadOnly(true); 505 pSelectedKeyLayout->addWidget(m_pPositionLabel, 1, 0); 506 pSelectedKeyLayout->addWidget(m_pPositionEdit, 1, 1); 507 508 QWidget *pCaptionEditor = prepareKeyCaptionEditWidgets(); 509 if (pCaptionEditor) 510 pSelectedKeyLayout->addWidget(pCaptionEditor, 2, 0, 2, 2); 511 512 QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); 513 if (pSpacer) 514 pSelectedKeyLayout->addItem(pSpacer, 4, 1); 515 516 retranslateUi(); 517 } 518 519 QWidget *UISoftKeyEditor::prepareKeyCaptionEditWidgets() 520 { 521 m_pCaptionEditGroupBox = new QGroupBox; 522 if (!m_pCaptionEditGroupBox) 523 return 0; 524 m_pCaptionEditGroupBox->setFlat(false); 525 QGridLayout *pCaptionEditorLayout = new QGridLayout(m_pCaptionEditGroupBox); 526 pCaptionEditorLayout->setSpacing(0); 527 pCaptionEditorLayout->setContentsMargins(0, 0, 0, 0); 528 529 if (!pCaptionEditorLayout) 530 return 0; 408 531 409 532 m_pBaseCaptionLabel = new QLabel; 410 533 m_pBaseCaptionEdit = new QLineEdit; 411 534 m_pBaseCaptionLabel->setBuddy(m_pBaseCaptionEdit); 535 pCaptionEditorLayout->addWidget(m_pBaseCaptionLabel, 0, 0); 536 pCaptionEditorLayout->addWidget(m_pBaseCaptionEdit, 0, 1); 412 537 413 538 m_pShiftCaptionLabel = new QLabel; 414 539 m_pShiftCaptionEdit = new QLineEdit; 415 540 m_pShiftCaptionLabel->setBuddy(m_pShiftCaptionEdit); 541 pCaptionEditorLayout->addWidget(m_pShiftCaptionLabel, 1, 0); 542 pCaptionEditorLayout->addWidget(m_pShiftCaptionEdit, 1, 1); 416 543 417 544 m_pAltGrCaptionLabel = new QLabel; 418 545 m_pAltGrCaptionEdit = new QLineEdit; 419 546 m_pAltGrCaptionLabel->setBuddy(m_pAltGrCaptionEdit); 420 421 setLayout(m_pEditorLayout); 422 423 retranslateUi(); 547 pCaptionEditorLayout->addWidget(m_pAltGrCaptionLabel, 2, 0); 548 pCaptionEditorLayout->addWidget(m_pAltGrCaptionEdit, 2, 1); 549 550 551 m_pOkButton = new QPushButton; 552 pCaptionEditorLayout->addWidget(m_pOkButton, 3, 0); 553 connect(m_pOkButton, &QPushButton::pressed, this, &UISoftKeyEditor::sltHandleOkButton); 554 m_pCancelButton = new QPushButton; 555 pCaptionEditorLayout->addWidget(m_pCancelButton, 3, 1); 556 557 QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding); 558 if (pSpacer) 559 pCaptionEditorLayout->addItem(pSpacer, 4, 1); 560 return m_pCaptionEditGroupBox; 424 561 } 425 562 … … 505 642 } 506 643 507 const QString &UISoftKeyboardKey::staticKeyCap() const 508 { 509 return m_strStaticKeyCap; 510 } 511 512 void UISoftKeyboardKey::setStaticKeyCap(const QString &strStaticKeyCap) 513 { 514 m_strStaticKeyCap = strStaticKeyCap; 515 } 516 517 const QString &UISoftKeyboardKey::keyCap() const 518 { 519 return m_strKeyCap; 520 } 521 522 void UISoftKeyboardKey::setKeyCap(const QString &strKeyCap) 523 { 524 m_strKeyCap = strKeyCap; 644 const QString UISoftKeyboardKey::baseCaption() const 645 { 646 return m_strBaseCaption; 647 } 648 649 void UISoftKeyboardKey::setBaseCaption(const QString &strBaseCaption) 650 { 651 m_strBaseCaption = strBaseCaption; 652 updateText(); 653 } 654 655 const QString UISoftKeyboardKey::shiftCaption() const 656 { 657 return m_strShiftCaption; 658 } 659 660 void UISoftKeyboardKey::setShiftCaption(const QString &strShiftCaption) 661 { 662 m_strShiftCaption = strShiftCaption; 663 updateText(); 664 } 665 666 const QString UISoftKeyboardKey::altGrCaption() const 667 { 668 return m_strAltGrCaption; 669 } 670 671 void UISoftKeyboardKey::setAltGrCaption(const QString &strAltGrCaption) 672 { 673 m_strAltGrCaption = strAltGrCaption; 674 updateText(); 675 } 676 677 const QString UISoftKeyboardKey::text() const 678 { 679 return m_strText; 525 680 } 526 681 … … 695 850 } 696 851 852 void UISoftKeyboardKey::updateText() 853 { 854 m_strText.clear(); 855 if (!m_strShiftCaption.isEmpty()) 856 m_strText += QString("%1\n").arg(m_strShiftCaption); 857 if (!m_strBaseCaption.isEmpty()) 858 m_strText += QString("%1\n").arg(m_strBaseCaption); 859 if (!m_strAltGrCaption.isEmpty()) 860 m_strText += QString("%1\n").arg(m_strAltGrCaption); 861 } 862 697 863 /********************************************************************************************************************************* 698 864 * UISoftKeyboardWidget implementation. * … … 708 874 , m_textDefaultColor(QColor(46, 49, 49)) 709 875 , m_textPressedColor(QColor(149, 165, 166)) 876 , m_keyEditColor(QColor(249, 165, 166)) 710 877 , m_iInitialHeight(0) 711 878 , m_iInitialWidth(0) … … 719 886 , m_pContextMenu(0) 720 887 , m_pShowPositionsAction(0) 721 , m_pLoadLayoutFileAction(0)722 , m_pLastSelectedLayout(0)723 888 , m_pKeyCapEditModeToggleAction(0) 724 889 , m_enmMode(Mode_Keyboard) … … 745 910 return; 746 911 747 m_fScaleFactorX = width() / (float) m_iInitialWidth; 912 int iEditDialogWidth = 0; 913 if (m_enmMode == Mode_KeyCapEdit) 914 iEditDialogWidth = 34 * QApplication::fontMetrics().width('x'); 915 m_fScaleFactorX = (width() - iEditDialogWidth) / (float) m_iInitialWidth; 748 916 m_fScaleFactorY = height() / (float) m_iInitialHeight; 749 917 … … 758 926 float fLedRadius = 0.8 * unitSize; 759 927 float fLedMargin = 0.6 * unitSize; 760 if (!m_pKeyBeingEdited && m_pKeyCapEditor) 928 929 if (m_enmMode == Mode_KeyCapEdit) 930 { 931 m_pKeyCapEditor->setGeometry(width() - iEditDialogWidth, 0, 932 iEditDialogWidth, height()); 933 m_pKeyCapEditor->show(); 934 m_pKeyCapEditor->setFocus(); 935 } 936 else 761 937 m_pKeyCapEditor->hide(); 938 762 939 for (int i = 0; i < m_rows.size(); ++i) 763 940 { … … 767 944 UISoftKeyboardKey &key = keys[j]; 768 945 painter.translate(key.keyGeometry().x(), key.keyGeometry().y()); 769 if (&key == m_pKeyUnderMouse) 946 947 if(&key == m_pKeyBeingEdited) 948 painter.setBrush(QBrush(m_keyEditColor)); 949 else if (&key == m_pKeyUnderMouse) 770 950 painter.setBrush(QBrush(m_keyHoverColor)); 771 951 else 772 952 painter.setBrush(QBrush(m_keyDefaultColor)); 773 774 if (m_enmMode == Mode_KeyCapEdit && &key == m_pKeyBeingEdited)775 {776 m_pKeyCapEditor->setFont(painterFont);777 m_pKeyCapEditor->setGeometry(m_fScaleFactorX * key.keyGeometry().x(), m_fScaleFactorY * key.keyGeometry().y(),778 m_fScaleFactorX * key.keyGeometry().width(), m_fScaleFactorY * key.keyGeometry().height());779 m_pKeyCapEditor->show();780 m_pKeyCapEditor->setFocus();781 }782 953 783 954 if (&key == m_pKeyPressed) … … 794 965 painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position())); 795 966 else 796 painter.drawText(textRect, Qt::TextWordWrap, 797 !key.keyCap().isEmpty() ? key.keyCap() : key.staticKeyCap()); 967 painter.drawText(textRect, Qt::TextWordWrap, key.text()); 798 968 799 969 if (key.type() != UIKeyType_Ordinary) … … 831 1001 if (m_pKeyBeingEdited && m_pKeyBeingEdited != m_pKeyUnderMouse) 832 1002 { 833 printf("farkli %p\n", m_pKeyBeingEdited);1003 //printf("farkli %p\n", m_pKeyBeingEdited); 834 1004 } 835 m_pKeyBeingEdited = m_pKeyUnderMouse;836 if (m_pKeyBeingEdited && m_pKeyCapEditor)837 m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap());1005 setKeyBeingEdited(m_pKeyUnderMouse); 1006 // if (m_pKeyBeingEdited && m_pKeyCapEditor) 1007 // m_pKeyCapEditor->setText(m_pKeyBeingEdited->keyCap()); 838 1008 } 839 1009 update(); … … 873 1043 if (pKeyEvent && pKeyEvent->key() == Qt::Key_Escape) 874 1044 { 875 m_pKeyBeingEdited = 0;1045 setKeyBeingEdited(0); 876 1046 update(); 877 1047 return true; … … 879 1049 else if (pKeyEvent && (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return)) 880 1050 { 881 if (m_pKeyBeingEdited)882 m_pKeyBeingEdited->setStaticKeyCap(m_pKeyCapEditor->text());883 m_pKeyBeingEdited = 0;1051 // if (m_pKeyBeingEdited) 1052 // m_pKeyBeingEdited->setStaticKeyCap(m_pKeyCapEditor->text()); 1053 setKeyBeingEdited(0); 884 1054 update(); 885 1055 return true; … … 904 1074 } 905 1075 906 void UISoftKeyboardWidget::sltHandleLoadLayout(QAction *pSenderAction)907 {908 if (!pSenderAction)909 return;910 if (pSenderAction == m_pLoadLayoutFileAction)911 {912 const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this,913 UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));914 if (!strFileName.isEmpty() && createKeyboard(strFileName))915 {916 m_pLastSelectedLayout = pSenderAction;917 m_pLoadLayoutFileAction->setData(strFileName);918 emit sigLayoutChange(strFileName);919 return;920 }921 }922 else923 {924 QString strLayout = pSenderAction->data().toString();925 if (!strLayout.isEmpty() && createKeyboard(strLayout))926 {927 m_pLastSelectedLayout = pSenderAction;928 emit sigLayoutChange(strLayout);929 return;930 }931 }932 /* In case something went wrong try to restore the previous layout: */933 if (m_pLastSelectedLayout)934 {935 QString strLayout = m_pLastSelectedLayout->data().toString();936 createKeyboard(strLayout);937 emit sigLayoutChange(strLayout);938 m_pLastSelectedLayout->setChecked(true);939 }940 }1076 // void UISoftKeyboardWidget::sltHandleLoadLayout(QAction *pSenderAction) 1077 // { 1078 // if (!pSenderAction) 1079 // return; 1080 // if (pSenderAction == m_pLoadLayoutFileAction) 1081 // { 1082 // const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this, 1083 // UISoftKeyboard::tr("Choose file to load physical keyboard layout..")); 1084 // if (!strFileName.isEmpty() && createKeyboard(strFileName)) 1085 // { 1086 // m_pLastSelectedLayout = pSenderAction; 1087 // m_pLoadLayoutFileAction->setData(strFileName); 1088 // emit sigLayoutChange(strFileName); 1089 // return; 1090 // } 1091 // } 1092 // else 1093 // { 1094 // QString strLayout = pSenderAction->data().toString(); 1095 // if (!strLayout.isEmpty() && createKeyboard(strLayout)) 1096 // { 1097 // m_pLastSelectedLayout = pSenderAction; 1098 // emit sigLayoutChange(strLayout); 1099 // return; 1100 // } 1101 // } 1102 // /* In case something went wrong try to restore the previous layout: */ 1103 // if (m_pLastSelectedLayout) 1104 // { 1105 // QString strLayout = m_pLastSelectedLayout->data().toString(); 1106 // createKeyboard(strLayout); 1107 // emit sigLayoutChange(strLayout); 1108 // m_pLastSelectedLayout->setChecked(true); 1109 // } 1110 // } 941 1111 942 1112 void UISoftKeyboardWidget::sltHandleSaveKeyCapFile() … … 970 1140 UISoftKeyboardKey &key = keys[j]; 971 1141 xmlWriter.writeTextElement("position", QString::number(key.position())); 972 if (!key.keyCap().isEmpty()) 973 xmlWriter.writeTextElement("keycap", key.keyCap()); 974 else 975 xmlWriter.writeTextElement("keycap", key.staticKeyCap()); 1142 xmlWriter.writeTextElement("basecaption", key.baseCaption()); 1143 xmlWriter.writeTextElement("shiftcaption", key.shiftCaption()); 1144 xmlWriter.writeTextElement("altgrcaption", key.altGrCaption()); 1145 1146 // if (!key.keyCap().isEmpty()) 1147 // xmlWriter.writeTextElement("keycap", key.keyCap()); 1148 // else 1149 // xmlWriter.writeTextElement("keycap", key.staticKeyCap()); 976 1150 xmlWriter.writeEndElement(); 977 1151 } … … 990 1164 return; 991 1165 UIKeyboardKeyCapReader keyCapReader(strFileName); 992 const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap();1166 //const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap(); 993 1167 994 1168 for (int i = 0; i < m_rows.size(); ++i) 995 1169 { 996 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();997 for (int j = 0; j < keys.size(); ++j)998 {999 UISoftKeyboardKey &key = keys[j];1000 if (keyCapMap.contains(key.position()))1001 key.setKeyCap(keyCapMap[key.position()]);1002 }1170 //QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 1171 // for (int j = 0; j < keys.size(); ++j) 1172 // { 1173 // UISoftKeyboardKey &key = keys[j]; 1174 // if (keyCapMap.contains(key.position())) 1175 // key.setKeyCap(keyCapMap[key.position()]); 1176 // } 1003 1177 } 1004 1178 emit sigKeyCapChange(strFileName); … … 1007 1181 void UISoftKeyboardWidget::sltHandleUnloadKeyCaps() 1008 1182 { 1009 for (int i = 0; i < m_rows.size(); ++i)1010 {1011 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys();1012 for (int j = 0; j < keys.size(); ++j)1013 keys[j].setKeyCap(QString());1014 }1183 // for (int i = 0; i < m_rows.size(); ++i) 1184 // { 1185 // QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 1186 // for (int j = 0; j < keys.size(); ++j) 1187 // keys[j].setKeyCap(QString()); 1188 // } 1015 1189 emit sigKeyCapChange(QString()); 1016 1190 } … … 1021 1195 m_enmMode = Mode_KeyCapEdit; 1022 1196 else 1197 { 1023 1198 m_enmMode = Mode_Keyboard; 1199 m_pKeyBeingEdited = 0; 1200 } 1201 } 1202 1203 void UISoftKeyboardWidget::sltHandleKeyCaptionEdited() 1204 { 1205 update(); 1024 1206 } 1025 1207 … … 1108 1290 { 1109 1291 /* Choose the first layout action's data as the default layout: */ 1110 if (!m_pLayoutActionGroup->actions().empty()) 1111 { 1112 QAction *pAction = m_pLayoutActionGroup->actions().at(0); 1113 if (pAction) 1114 { 1115 QString strLayout = pAction->data().toString(); 1116 if (!strLayout.isEmpty()) 1117 { 1118 if (createKeyboard(strLayout)) 1119 { 1120 emit sigLayoutChange(strLayout); 1121 m_pLastSelectedLayout = pAction; 1122 pAction->setChecked(true); 1123 } 1124 } 1125 } 1126 } 1292 if (m_defaultLayouts.isEmpty()) 1293 return; 1294 const QString &strLayout = m_defaultLayouts.at(0); 1295 if (createKeyboard(strLayout)) 1296 emit sigLayoutChange(strLayout); 1127 1297 } 1128 1298 … … 1217 1387 void UISoftKeyboardWidget::configure() 1218 1388 { 1219 defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml";1389 m_defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml"; 1220 1390 setMouseTracking(true); 1221 1391 setContextMenuPolicy(Qt::CustomContextMenu); … … 1226 1396 void UISoftKeyboardWidget::prepareObjects() 1227 1397 { 1228 m_pKeyCapEditor = new QLineEdit(this);1398 m_pKeyCapEditor = new UISoftKeyEditor(this); 1229 1399 if (m_pKeyCapEditor) 1230 1400 { 1231 1401 m_pKeyCapEditor->hide(); 1232 1402 m_pKeyCapEditor->installEventFilter(this); 1403 connect(m_pKeyCapEditor, &UISoftKeyEditor::sigKeyCaptionEdited, this, &UISoftKeyboardWidget::sltHandleKeyCaptionEdited); 1233 1404 } 1234 1405 m_pContextMenu = new QMenu(this); 1235 /* Layout menu: */1236 m_pLayoutActionGroup = new QActionGroup(this);1237 m_pLayoutActionGroup->setExclusive(true);1238 connect(m_pLayoutActionGroup, &QActionGroup::triggered, this, &UISoftKeyboardWidget::sltHandleLoadLayout);1239 1240 foreach (const QString &strLayout, defaultLayouts)1241 {1242 QString strName = strLayout.left(strLayout.indexOf('.'));1243 QAction *pAction = m_pLayoutActionGroup->addAction(QString("%1 %2").arg(UISoftKeyboard::tr("Load Layout ")).arg(strName.remove(":/")));1244 pAction->setData(strLayout);1245 pAction->setCheckable(true);1246 }1247 m_pLoadLayoutFileAction = m_pLayoutActionGroup->addAction(UISoftKeyboard::tr("Load Layout File..."));1248 m_pLoadLayoutFileAction->setCheckable(true);1249 m_pContextMenu->addActions(m_pLayoutActionGroup->actions());1250 1406 1251 1407 /* Keycaps menu: */ … … 1274 1430 return; 1275 1431 m_enmMode = Mode_KeyCapEdit; 1432 } 1433 1434 void UISoftKeyboardWidget::setKeyBeingEdited(UISoftKeyboardKey* pKey) 1435 { 1436 if (m_pKeyBeingEdited == pKey) 1437 return; 1438 m_pKeyBeingEdited = pKey; 1439 if (m_pKeyCapEditor) 1440 m_pKeyCapEditor->setKey(pKey); 1276 1441 } 1277 1442 … … 1399 1564 m_xmlReader.skipCurrentElement(); 1400 1565 } 1401 key.setStaticKeyCap(strKeyCap);1566 //key.setStaticKeyCap(strKeyCap); 1402 1567 } 1403 1568 … … 1532 1697 m_xmlReader.skipCurrentElement(); 1533 1698 } 1534 1535 1699 return true; 1536 1700 } … … 1542 1706 while (m_xmlReader.readNextStartElement()) 1543 1707 { 1544 if (m_xmlReader.name() == "keycap") 1708 if (m_xmlReader.name() == "basecaption") 1709 strKeyCap = m_xmlReader.readElementText(); 1710 if (m_xmlReader.name() == "shiftcaption") 1711 strKeyCap = m_xmlReader.readElementText(); 1712 if (m_xmlReader.name() == "altgrcaption") 1545 1713 strKeyCap = m_xmlReader.readElementText(); 1546 1714 else if (m_xmlReader.name() == "position") … … 1657 1825 1658 1826 statusBar()->setStyleSheet( "QStatusBar::item { border: 0px}" ); 1659 // QWidget *pStatusBarWidget = new QWidget;1660 // QHBoxLayout *pStatusBarLayout = new QHBoxLayout(pStatusBarWidget);1661 // pStatusBarLayout->setSpacing(0);1662 // pStatusBarLayout->setContentsMargins(0, 0, 0, 0);1663 1827 1664 1828 m_pSettingsButton = new QToolButton; … … 1670 1834 statusBar()->addPermanentWidget(m_pSettingsButton); 1671 1835 1672 QToolButton *pButton = new QToolButton;1673 pButton->setIcon(UIIconPool::iconSet(":/hd_modify_16px.png"));1674 pButton->setStyleSheet("QToolButton { border: 0px none black; margin: 0px 0px 0px 0px; } QToolButton::menu-indicator {image: none;}");1675 statusBar()->addPermanentWidget(pButton);1676 1677 1678 1679 1836 retranslateUi(); 1680 1837 }
Note:
See TracChangeset
for help on using the changeset viewer.