Changeset 79212 in vbox
- Timestamp:
- Jun 18, 2019 2:06:54 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 131389
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r79206 r79212 21 21 #include <QFile> 22 22 #include <QGroupBox> 23 #include <QInputDialog> 23 24 #include <QLabel> 24 25 #include <QLineEdit> … … 40 41 #include "UIExtraDataManager.h" 41 42 #include "UIIconPool.h" 43 #include "UIModalWindowManager.h" 42 44 #include "UISession.h" 43 45 #include "UISoftKeyboard.h" … … 53 55 class UISoftKeyboardLayout; 54 56 class UISoftKeyboardRow; 57 58 const int iMessageTimeout = 3000; 59 const QString strSubDirectorName("keyboardLayouts"); 55 60 56 61 enum UIKeyState … … 407 412 signals: 408 413 414 void sigStatusBarMessage(const QString &strMessage); 409 415 void sigPutKeyboardSequence(QVector<LONG> sequence); 410 416 void sigCurrentLayoutChange(); … … 432 438 void updateKeyCaptionsInLayout(UISoftKeyboardKey *pKey); 433 439 void addLayout(const UISoftKeyboardLayout &newLayout); 440 void saveCurentLayoutToFile(); 434 441 435 442 protected: … … 444 451 445 452 void sltContextMenuRequest(const QPoint &point); 446 void sltSaveLayout();447 453 void sltPhysicalLayoutForLayoutChanged(int iIndex); 448 454 … … 465 471 void setCurrentLayout(UISoftKeyboardLayout *pLayout); 466 472 UISoftKeyboardLayout *findLayoutByName(const QString &strName); 467 473 /** Looks under the default keyboard layout folder and add the file names to the fileList. */ 474 void lookAtDefaultLayoutFolder(QStringList &fileList); 468 475 UISoftKeyboardKey *m_pKeyUnderMouse; 469 476 UISoftKeyboardKey *m_pKeyBeingEdited; … … 476 483 QColor m_keyEditColor; 477 484 QVector<UISoftKeyboardKey*> m_pressedModifiers; 478 //QVector<UISoftKeyboardRow> m_rows;479 485 QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts; 480 486 QVector<UISoftKeyboardLayout> m_layouts; … … 1291 1297 { 1292 1298 return QSize(0.5 * m_minimumSize.width(), 0.5 * m_minimumSize.height()); 1293 //return m_minimumSize;1294 1299 } 1295 1300 … … 1414 1419 } 1415 1420 1416 // bool UISoftKeyboardWidget::eventFilter(QObject *pWatched, QEvent *pEvent)1417 // {1418 // if (pWatched != m_pLayoutEditor)1419 // return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent);1420 1421 // switch (pEvent->type())1422 // {1423 // case QEvent::KeyPress:1424 // {1425 // QKeyEvent *pKeyEvent = dynamic_cast<QKeyEvent*>(pEvent);1426 // if (pKeyEvent && pKeyEvent->key() == Qt::Key_Escape)1427 // {1428 // setKeyBeingEdited(0);1429 // update();1430 // return true;1431 // }1432 // else if (pKeyEvent && (pKeyEvent->key() == Qt::Key_Enter || pKeyEvent->key() == Qt::Key_Return))1433 // {1434 // // if (m_pKeyBeingEdited)1435 // // m_pKeyBeingEdited->setStaticKeyCap(m_pLayoutEditor->text());1436 // setKeyBeingEdited(0);1437 // update();1438 // return true;1439 // }1440 // break;1441 // }1442 // default:1443 // break;1444 // }1445 1446 // return QIWithRetranslateUI<QWidget>::eventFilter(pWatched, pEvent);1447 // }1448 1449 1450 1421 void UISoftKeyboardWidget::retranslateUi() 1451 1422 { … … 1457 1428 } 1458 1429 1459 // void UISoftKeyboardWidget::sltLoadLayout(QAction *pSenderAction) 1460 // { 1461 // if (!pSenderAction) 1462 // return; 1463 // if (pSenderAction == m_pLoadLayoutFileAction) 1464 // { 1465 // const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this, 1466 // UISoftKeyboard::tr("Choose file to load physical keyboard layout..")); 1467 // if (!strFileName.isEmpty() && loadPhysicalLayout(strFileName)) 1468 // { 1469 // m_pLastSelectedLayout = pSenderAction; 1470 // m_pLoadLayoutFileAction->setData(strFileName); 1471 // 1472 // return; 1473 // } 1474 // } 1475 // else 1476 // { 1477 // QString strLayout = pSenderAction->data().toString(); 1478 // if (!strLayout.isEmpty() && loadPhysicalLayout(strLayout)) 1479 // { 1480 // m_pLastSelectedLayout = pSenderAction; 1481 // emit sigCurrentLayoutChange(strLayout); 1482 // return; 1483 // } 1484 // } 1485 // /* In case something went wrong try to restore the previous layout: */ 1486 // if (m_pLastSelectedLayout) 1487 // { 1488 // QString strLayout = m_pLastSelectedLayout->data().toString(); 1489 // loadPhysicalLayout(strLayout); 1490 // emit sigCurrentLayoutChange(strLayout); 1491 // m_pLastSelectedLayout->setChecked(true); 1492 // } 1493 // } 1494 1495 void UISoftKeyboardWidget::sltSaveLayout() 1496 { 1497 QString strFileName = QIFileDialog::getSaveFileName(vboxGlobal().documentsPath(), UISoftKeyboard::tr("XML files (*.xml)"), 1498 this, tr("Save layout to a file...")); 1499 if (strFileName.isEmpty()) 1500 return; 1430 void UISoftKeyboardWidget::saveCurentLayoutToFile() 1431 { 1432 QString strHomeFolder = vboxGlobal().homeFolder(); 1433 QDir dir(strHomeFolder); 1434 if (!dir.exists(strSubDirectorName)) 1435 { 1436 if (!dir.mkdir(strSubDirectorName)) 1437 { 1438 sigStatusBarMessage(QString("%1 %2").arg(UISoftKeyboard::tr("Error! Could not create folder under").arg(strHomeFolder))); 1439 return; 1440 } 1441 } 1442 1443 strHomeFolder += QString(QDir::separator()) + strSubDirectorName; 1444 QInputDialog dialog(this); 1445 dialog.setInputMode(QInputDialog::TextInput); 1446 dialog.setWindowModality(Qt::WindowModal); 1447 dialog.setWindowTitle(UISoftKeyboard::tr("Provide a file name")); 1448 dialog.setLabelText(QString("%1 %2").arg(UISoftKeyboard::tr("The File will be saved under:\n")).arg(strHomeFolder)); 1449 if (dialog.exec() == QDialog::Rejected) 1450 return; 1451 QString strFileName(dialog.textValue()); 1452 if (strFileName.isEmpty() || strFileName.contains("..") || strFileName.contains(QDir::separator())) 1453 { 1454 sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is an invalid file name"))); 1455 return; 1456 } 1457 1501 1458 if (!m_pCurrentKeyboardLayout) 1502 1459 return; … … 1504 1461 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->m_physicalLayoutUuid); 1505 1462 if (!pPhysicalLayout) 1506 return; 1463 { 1464 sigStatusBarMessage("The layout file could not be saved"); 1465 return; 1466 } 1507 1467 1508 1468 QFileInfo fileInfo(strFileName); 1509 1469 if (fileInfo.suffix().compare("xml", Qt::CaseInsensitive) != 0) 1510 1470 strFileName += ".xml"; 1511 1471 strFileName = strHomeFolder + QString(QDir::separator()) + strFileName; 1512 1472 QFile xmlFile(strFileName); 1513 1473 if (!xmlFile.open(QIODevice::WriteOnly)) 1514 return; 1474 { 1475 sigStatusBarMessage("The layout file could not be saved"); 1476 return; 1477 } 1478 1515 1479 QXmlStreamWriter xmlWriter; 1516 1480 xmlWriter.setDevice(&xmlFile); … … 1536 1500 xmlWriter.writeTextElement("shiftcaption", key.shiftCaption()); 1537 1501 xmlWriter.writeTextElement("altgrcaption", key.altGrCaption()); 1538 1539 // if (!key.keyCap().isEmpty())1540 // xmlWriter.writeTextElement("keycap", key.keyCap());1541 // else1542 // xmlWriter.writeTextElement("keycap", key.staticKeyCap());1543 1502 xmlWriter.writeEndElement(); 1544 1503 } … … 1548 1507 1549 1508 xmlFile.close(); 1550 } 1551 1552 // void UISoftKeyboardWidget::sltLoadKeyCapFile() 1553 // { 1554 // const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this, 1555 // UISoftKeyboard::tr("Choose file to load key captions..")); 1556 // if (strFileName.isEmpty()) 1557 // return; 1558 // UIKeyboardLayoutReader keyCapReader(strFileName); 1559 // //const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap(); 1560 1561 // //for (int i = 0; i < m_rows.size(); ++i) 1562 // { 1563 // //QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 1564 // // for (int j = 0; j < keys.size(); ++j) 1565 // // { 1566 // // UISoftKeyboardKey &key = keys[j]; 1567 // // if (keyCapMap.contains(key.position())) 1568 // // key.setKeyCap(keyCapMap[key.position()]); 1569 // // } 1570 // } 1571 // emit sigKeyCapChange(strFileName); 1572 // } 1509 1510 sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is saved"))); 1511 } 1573 1512 1574 1513 void UISoftKeyboardWidget::toggleEditMode(bool fIsEditMode) … … 1834 1773 { 1835 1774 m_pressedModifiers.clear(); 1836 //m_rows.clear();1837 1775 } 1838 1776 … … 1845 1783 loadPhysicalLayout(strName); 1846 1784 1847 /* Load keyboard layouts from resources: */1785 /* Add keyboard layouts from resources: */ 1848 1786 QStringList keyboardLayoutNames; 1849 1787 keyboardLayoutNames << ":/us_international.xml" 1850 1788 <<":/german.xml"; 1789 /* Add keyboard layouts from the defalt keyboard layout folder: */ 1790 lookAtDefaultLayoutFolder(keyboardLayoutNames); 1851 1791 foreach (const QString &strName, keyboardLayoutNames) 1852 1792 loadKeyboardLayout(strName); … … 1926 1866 } 1927 1867 return 0; 1868 } 1869 1870 void UISoftKeyboardWidget::lookAtDefaultLayoutFolder(QStringList &fileList) 1871 { 1872 QString strFolder = QString("%1%2%3").arg(vboxGlobal().homeFolder()).arg(QDir::separator()).arg(strSubDirectorName); 1873 QDir dir(strFolder); 1874 if (!dir.exists()) 1875 return; 1876 QStringList filters; 1877 filters << "*.xml"; 1878 dir.setNameFilters(filters); 1879 QFileInfoList fileInfoList = dir.entryInfoList(); 1880 foreach (const QFileInfo &fileInfo, fileInfoList) 1881 fileList << fileInfo.absoluteFilePath(); 1928 1882 } 1929 1883 … … 2319 2273 } 2320 2274 2321 bool UISoftKeyboard::eventFilter(QObject *pWatched, QEvent *pEvent)2322 {2323 Q_UNUSED(pWatched);2324 Q_UNUSED(pEvent);2325 // if (pWatched != m_pLayoutListButton)2326 // return QIWithRetranslateUI<QMainWindow>::eventFilter(pWatched, pEvent);2327 2328 // if (pEvent->type() == QEvent::MouseButtonPress)2329 // {2330 // QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);2331 // if (pMouseEvent && pMouseEvent->button() == Qt::LeftButton)2332 // {2333 // if (m_pKeyboardWidget)2334 // m_pKeyboardWidget->showContextMenu(m_pLayoutListButton->mapToGlobal(pMouseEvent->pos()));2335 // return true;2336 // }2337 // }2338 2339 return QIWithRetranslateUI<QMainWindow>::eventFilter(pWatched, pEvent);2340 }2341 2342 2275 void UISoftKeyboard::sltKeyboardLedsChange() 2343 2276 { … … 2437 2370 void UISoftKeyboard::sltSaveLayout() 2438 2371 { 2372 if (m_pKeyboardWidget) 2373 m_pKeyboardWidget->saveCurentLayoutToFile(); 2374 } 2375 2376 void UISoftKeyboard::sltStatusBarMessage(const QString &strMessage) 2377 { 2378 statusBar()->showMessage(strMessage, iMessageTimeout); 2439 2379 } 2440 2380 … … 2452 2392 m_pSidePanelWidget->hide(); 2453 2393 2454 m_pSplitter->addWidget(m_pSidePanelWidget);2455 m_pSplitter->setCollapsible(0, false);2456 2457 2394 m_pLayoutSelector = new UILayoutSelector; 2458 2395 if (m_pLayoutSelector) … … 2469 2406 m_pKeyboardWidget->updateGeometry(); 2470 2407 m_pSplitter->addWidget(m_pKeyboardWidget); 2408 m_pSplitter->addWidget(m_pSidePanelWidget); 2409 m_pSplitter->setCollapsible(0, false); 2410 m_pSplitter->setCollapsible(1, false); 2471 2411 2472 2412 statusBar()->setStyleSheet( "QStatusBar::item { border: 0px}" ); 2473 2413 m_pStatusBarWidget = new UISoftKeyboardStatusBarWidget; 2474 statusBar()->add Widget(m_pStatusBarWidget);2414 statusBar()->addPermanentWidget(m_pStatusBarWidget); 2475 2415 2476 2416 retranslateUi(); … … 2483 2423 connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigCurrentLayoutChange, this, &UISoftKeyboard::sltCurentLayoutChanged); 2484 2424 connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigKeyToEdit, this, &UISoftKeyboard::sltKeyToEditChanged); 2425 connect(m_pKeyboardWidget, &UISoftKeyboardWidget::sigStatusBarMessage, this, &UISoftKeyboard::sltStatusBarMessage); 2485 2426 2486 2427 connect(m_pLayoutSelector, &UILayoutSelector::sigLayoutSelectionChanged, this, &UISoftKeyboard::sltLayoutSelectionChanged); -
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
r79206 r79212 61 61 62 62 virtual void retranslateUi() /* override */; 63 bool eventFilter(QObject *pWatched, QEvent *pEvent)/* override */;64 63 65 64 private slots: … … 82 81 void sltCopyLayout(); 83 82 void sltSaveLayout(); 83 void sltStatusBarMessage(const QString &strMessage); 84 84 85 85 private:
Note:
See TracChangeset
for help on using the changeset viewer.