Changeset 79016 in vbox
- Timestamp:
- Jun 6, 2019 8:13:23 AM (5 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r78990 r79016 107 107 void setKeyGeometry(const QRect &rect); 108 108 109 const QString &staticKeyCap() const; 110 void setStaticKeyCap(const QString &strKeyCap); 111 109 112 const QString &keyCap() const; 110 113 void setKeyCap(const QString &strKeyCap); … … 154 157 155 158 QRect m_keyGeometry; 159 /** Static keycaps are what is obtained from the layout file, as opposed to the keycaps file. 160 * normally they are the captions of modifier keys (Shift, etc) whose meaning stays the same across the layouts. */ 161 QString m_strStaticKeyCap; 162 /** Key caps are loaded from a keycap file and preferred over the static keycaps if they are not empty. */ 156 163 QString m_strKeyCap; 164 157 165 /** Stores the key polygon in local coordinates. */ 158 166 QPolygon m_polygon; … … 168 176 int m_iCutoutWidth; 169 177 int m_iCutoutHeight; 170 /** -1 is no cutout. 0 is the topleft corner. we go clockwise. */178 /** -1 is for no cutout. 0 is the topleft, 2 is the top right and so on. */ 171 179 int m_iCutoutCorner; 172 180 /** Key's position in the layout. */ … … 212 220 void sltHandleKeyCapEdit(); 213 221 void sltHandleSaveKeyCapFile(); 222 void sltHandleLoadKeyCapFile(); 223 void sltHandleUnloadKeyCaps(); 214 224 215 225 private: … … 282 292 283 293 QXmlStreamReader m_xmlReader; 294 }; 295 296 /********************************************************************************************************************************* 297 * UIKeyboardKeyCapReader definition. * 298 *********************************************************************************************************************************/ 299 300 class UIKeyboardKeyCapReader 301 { 302 303 public: 304 305 UIKeyboardKeyCapReader(const QString &strFileName); 306 const QMap<int, QString> &keyCapMap() const; 307 308 private: 309 310 bool parseKeyCapFile(const QString &strFileName); 311 void parseKey(); 312 QXmlStreamReader m_xmlReader; 313 /** Keys are positions and values are keycaps. */ 314 QMap<int, QString> m_keyCapMap; 284 315 }; 285 316 … … 363 394 { 364 395 m_keyGeometry = rect; 396 } 397 398 const QString &UISoftKeyboardKey::staticKeyCap() const 399 { 400 return m_strStaticKeyCap; 401 } 402 403 void UISoftKeyboardKey::setStaticKeyCap(const QString &strStaticKeyCap) 404 { 405 m_strStaticKeyCap = strStaticKeyCap; 365 406 } 366 407 … … 622 663 if (&key == m_pKeyBeingEdited) 623 664 { 624 //m_pKeyCapEditor->setText(key.keyCap());625 665 m_pKeyCapEditor->setFont(painterFont); 626 666 m_pKeyCapEditor->setGeometry(m_fScaleFactorX * key.keyGeometry().x(), m_fScaleFactorY * key.keyGeometry().y(), … … 643 683 painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position())); 644 684 else 645 painter.drawText(textRect, Qt::TextWordWrap, key.keyCap()); 685 painter.drawText(textRect, Qt::TextWordWrap, 686 !key.keyCap().isEmpty() ? key.keyCap() : key.staticKeyCap()); 646 687 647 688 if (key.type() != UIKeyType_Ordinary) … … 713 754 { 714 755 if (m_pKeyBeingEdited) 715 m_pKeyBeingEdited->set KeyCap(m_pKeyCapEditor->text());756 m_pKeyBeingEdited->setStaticKeyCap(m_pKeyCapEditor->text()); 716 757 m_pKeyBeingEdited = 0; 717 758 update(); … … 788 829 QFileInfo fileInfo(strFileName); 789 830 if (fileInfo.suffix().compare("xml", Qt::CaseInsensitive) != 0) 790 {791 831 strFileName += ".xml"; 792 }793 832 794 833 QFile xmlFile(strFileName); … … 811 850 UISoftKeyboardKey &key = keys[j]; 812 851 xmlWriter.writeTextElement("position", QString::number(key.position())); 813 xmlWriter.writeTextElement("keycap", key.keyCap()); 852 if (!key.keyCap().isEmpty()) 853 xmlWriter.writeTextElement("keycap", key.keyCap()); 854 else 855 xmlWriter.writeTextElement("keycap", key.staticKeyCap()); 814 856 xmlWriter.writeEndElement(); 815 816 857 } 817 858 } … … 820 861 821 862 xmlFile.close(); 863 } 864 865 void UISoftKeyboardWidget::sltHandleLoadKeyCapFile() 866 { 867 const QString strFileName = QIFileDialog::getOpenFileName(QString(), UISoftKeyboard::tr("XML files (*.xml)"), this, 868 UISoftKeyboard::tr("Choose file to load key captions..")); 869 if (strFileName.isEmpty()) 870 return; 871 UIKeyboardKeyCapReader keyCapReader(strFileName); 872 const QMap<int, QString> &keyCapMap = keyCapReader.keyCapMap(); 873 874 for (int i = 0; i < m_rows.size(); ++i) 875 { 876 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 877 for (int j = 0; j < keys.size(); ++j) 878 { 879 UISoftKeyboardKey &key = keys[j]; 880 if (keyCapMap.contains(key.position())) 881 key.setKeyCap(keyCapMap[key.position()]); 882 } 883 } 884 } 885 886 void UISoftKeyboardWidget::sltHandleUnloadKeyCaps() 887 { 888 for (int i = 0; i < m_rows.size(); ++i) 889 { 890 QVector<UISoftKeyboardKey> &keys = m_rows[i].keys(); 891 for (int j = 0; j < keys.size(); ++j) 892 keys[j].setKeyCap(QString()); 893 } 822 894 } 823 895 … … 1031 1103 QAction *pSaveKeyCapFile = pKeycapsMenu->addAction(UISoftKeyboard::tr("Save key caps to file...")); 1032 1104 connect(pSaveKeyCapFile, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleSaveKeyCapFile); 1033 1034 /* Choose the first layput action's data as the defaults one: */ 1105 QAction *pLoadKeyCapFile = pKeycapsMenu->addAction(UISoftKeyboard::tr("Load key caps from file...")); 1106 connect(pLoadKeyCapFile, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadKeyCapFile); 1107 QAction *pUnloadKeyCaps = pKeycapsMenu->addAction(UISoftKeyboard::tr("Unload key caps")); 1108 connect(pUnloadKeyCaps, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleUnloadKeyCaps); 1109 1110 /* Choose the first layout action's data as the default layout: */ 1035 1111 if (!m_pLayoutActionGroup->actions().empty()) 1036 1112 { … … 1174 1250 m_xmlReader.skipCurrentElement(); 1175 1251 } 1176 key.set KeyCap(strKeyCap);1252 key.setStaticKeyCap(strKeyCap); 1177 1253 } 1178 1254 … … 1273 1349 1274 1350 /********************************************************************************************************************************* 1351 * UIKeyboardKeyCapReader implementation. * 1352 *********************************************************************************************************************************/ 1353 1354 UIKeyboardKeyCapReader::UIKeyboardKeyCapReader(const QString &strFileName) 1355 { 1356 parseKeyCapFile(strFileName); 1357 } 1358 1359 const QMap<int, QString> &UIKeyboardKeyCapReader::keyCapMap() const 1360 { 1361 return m_keyCapMap; 1362 } 1363 1364 bool UIKeyboardKeyCapReader::parseKeyCapFile(const QString &strFileName) 1365 { 1366 QFile xmlFile(strFileName); 1367 if (!xmlFile.exists()) 1368 return false; 1369 1370 if (!xmlFile.open(QIODevice::ReadOnly)) 1371 return false; 1372 1373 m_xmlReader.setDevice(&xmlFile); 1374 1375 if (!m_xmlReader.readNextStartElement() || m_xmlReader.name() != "keycaps") 1376 return false; 1377 1378 while (m_xmlReader.readNextStartElement()) 1379 { 1380 if (m_xmlReader.name() == "key") 1381 parseKey(); 1382 else 1383 m_xmlReader.skipCurrentElement(); 1384 } 1385 1386 return true; 1387 } 1388 1389 void UIKeyboardKeyCapReader::parseKey() 1390 { 1391 QString strKeyCap; 1392 int iKeyPosition = 0; 1393 while (m_xmlReader.readNextStartElement()) 1394 { 1395 if (m_xmlReader.name() == "keycap") 1396 strKeyCap = m_xmlReader.readElementText(); 1397 else if (m_xmlReader.name() == "position") 1398 iKeyPosition = m_xmlReader.readElementText().toInt(); 1399 else 1400 m_xmlReader.skipCurrentElement(); 1401 } 1402 m_keyCapMap.insert(iKeyPosition, strKeyCap); 1403 } 1404 1405 /********************************************************************************************************************************* 1275 1406 * UISoftKeyboard implementation. * 1276 1407 *********************************************************************************************************************************/ -
trunk/src/VBox/Frontends/VirtualBox/xml/101_ansi.xml
r78953 r79016 1 1 <?xml version="1.0"?> 2 2 <!-- https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.keyboardtechref/doc/kybdtech/Key.htm --> 3 3 <layout defaultHeight="50" defaultWidth="50"> 4 4 <row> … … 399 399 </key> 400 400 <key> 401 <keycap>Win</keycap> 402 <width>75</width> 403 <type>modifier</type> 401 <keycap>OS</keycap> 402 <width>75</width> 403 <type>modifier</type> 404 <position>227</position> 404 405 <scancodeprefix>0xe0</scancodeprefix> 405 406 <scancode>0x5b</scancode> … … 426 427 </key> 427 428 <key> 428 <keycap>Win</keycap> 429 <width>75</width> 430 <type>modifier</type> 429 <keycap>OS</keycap> 430 <width>75</width> 431 <type>modifier</type> 432 <position>231</position> 431 433 <scancodeprefix>0xe0</scancodeprefix> 432 434 <scancode>0x5c</scancode> -
trunk/src/VBox/Frontends/VirtualBox/xml/102_iso.xml
r78953 r79016 1 1 <?xml version="1.0"?> 2 2 <!-- https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.keyboardtechref/doc/kybdtech/Key.htm --> 3 3 <layout defaultHeight="50" defaultWidth="50"> 4 4 <row> … … 408 408 </key> 409 409 <key> 410 <keycap>Win</keycap> 411 <width>75</width> 412 <type>modifier</type> 410 <keycap>OS</keycap> 411 <width>75</width> 412 <type>modifier</type> 413 <position>227</position> 413 414 <scancodeprefix>0xe0</scancodeprefix> 414 415 <scancode>0x5b</scancode> … … 435 436 </key> 436 437 <key> 437 <keycap>Win</keycap> 438 <width>75</width> 439 <type>modifier</type> 438 <keycap>OS</keycap> 439 <width>75</width> 440 <type>modifier</type> 441 <position>231</position> 440 442 <scancodeprefix>0xe0</scancodeprefix> 441 443 <scancode>0x5c</scancode>
Note:
See TracChangeset
for help on using the changeset viewer.