Changeset 81476 in vbox for trunk/src/VBox
- Timestamp:
- Oct 23, 2019 8:13:40 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
r81456 r81476 617 617 void loadLayouts(); 618 618 619 void setCurrentLayout(const QString &strLayoutName);620 619 void setCurrentLayout(const QUuid &layoutUid); 621 620 UISoftKeyboardLayout *currentLayout(); … … 656 655 void parentDialogDeactivated(); 657 656 bool isColorThemeEditable() const; 658 657 /** Returns a list of layout names that have been edited but not yet saved to a file. */ 659 658 QStringList unsavedLayoutsNameList() const; 660 659 … … 687 686 /** Sets m_pKeyBeingEdited. */ 688 687 void setKeyBeingEdited(UISoftKeyboardKey *pKey); 689 void setCurrentLayout(UISoftKeyboardLayout *pLayout); 690 UISoftKeyboardLayout *findLayoutByName(const QString &strName); 691 UISoftKeyboardLayout *findLayoutByUid(const QUuid &uid); 688 bool layoutByNameExists(const QString &strName) const; 689 692 690 /** Looks under the default keyboard layout folder and add the file names to the fileList. */ 693 691 void lookAtDefaultLayoutFolder(QStringList &fileList); … … 703 701 QVector<UISoftKeyboardKey*> m_pressedModifiers; 704 702 QVector<UISoftKeyboardPhysicalLayout> m_physicalLayouts; 705 UISoftKeyboardPhysicalLayout 706 UISoftKeyboardPhysicalLayout 707 Q Vector<UISoftKeyboardLayout>m_layouts;708 UISoftKeyboardLayout *m_pCurrentKeyboardLayout;703 UISoftKeyboardPhysicalLayout m_numPadLayout; 704 UISoftKeyboardPhysicalLayout m_multiMediaKeysLayout; 705 QMap<QUuid, UISoftKeyboardLayout> m_layouts; 706 QUuid m_uCurrentLayoutId; 709 707 /** Key is the key position as read from the layout and value is the message we show as mouse hovers over the key. */ 710 708 QMap<int, QString> m_keyTooltips; … … 2133 2131 , m_pKeyPressed(0) 2134 2132 , m_currentColorTheme(0) 2135 , m_pCurrentKeyboardLayout(0)2136 2133 , m_iInitialHeight(0) 2137 2134 , m_iInitialWidth(0) … … 2168 2165 { 2169 2166 Q_UNUSED(pEvent); 2170 if (!m_pCurrentKeyboardLayout || m_iInitialWidth == 0 || m_iInitialWidthNoNumPad == 0 || m_iInitialHeight == 0) 2167 if (!m_layouts.contains(m_uCurrentLayoutId)) 2168 return; 2169 2170 UISoftKeyboardLayout ¤tLayout = m_layouts[m_uCurrentLayoutId]; 2171 2172 if (m_iInitialWidth == 0 || m_iInitialWidthNoNumPad == 0 || m_iInitialHeight == 0) 2171 2173 return; 2172 2174 … … 2192 2194 float fLedMargin = 0.6 * unitSize; 2193 2195 2194 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout( m_pCurrentKeyboardLayout->physicalLayoutUuid());2196 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid()); 2195 2197 if (!pPhysicalLayout) 2196 2198 return; … … 2232 2234 painter.drawPolygon(key.polygon()); 2233 2235 2234 m_pCurrentKeyboardLayout->drawTextInRect(key, painter);2236 currentLayout.drawTextInRect(key, painter); 2235 2237 /* Draw small LED like circles on the modifier/lock keys: */ 2236 2238 if (key.type() != KeyType_Ordinary) … … 2339 2341 void UISoftKeyboardWidget::saveCurentLayoutToFile() 2340 2342 { 2341 if (!m_ pCurrentKeyboardLayout)2342 return; 2343 2343 if (!m_layouts.contains(m_uCurrentLayoutId)) 2344 return; 2345 UISoftKeyboardLayout ¤tLayout = m_layouts[m_uCurrentLayoutId]; 2344 2346 QString strHomeFolder = uiCommon().homeFolder(); 2345 2347 QDir dir(strHomeFolder); … … 2358 2360 dialog.setWindowModality(Qt::WindowModal); 2359 2361 dialog.setWindowTitle(UISoftKeyboard::tr("Provide a file name")); 2360 dialog.setTextValue( m_pCurrentKeyboardLayout->name());2362 dialog.setTextValue(currentLayout.name()); 2361 2363 dialog.setLabelText(QString("%1 %2").arg(UISoftKeyboard::tr("The file will be saved under:\n")).arg(strHomeFolder)); 2362 2364 if (dialog.exec() == QDialog::Rejected) … … 2369 2371 } 2370 2372 2371 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout( m_pCurrentKeyboardLayout->physicalLayoutUuid());2373 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid()); 2372 2374 if (!pPhysicalLayout) 2373 2375 { … … 2393 2395 xmlWriter.writeStartDocument("1.0"); 2394 2396 xmlWriter.writeStartElement("layout"); 2395 xmlWriter.writeTextElement("name", m_pCurrentKeyboardLayout->name());2396 xmlWriter.writeTextElement("nativename", m_pCurrentKeyboardLayout->nativeName());2397 xmlWriter.writeTextElement("name", currentLayout.name()); 2398 xmlWriter.writeTextElement("nativename", currentLayout.nativeName()); 2397 2399 xmlWriter.writeTextElement("physicallayoutid", pPhysicalLayout->uid().toString()); 2398 xmlWriter.writeTextElement("id", m_pCurrentKeyboardLayout->uid().toString());2400 xmlWriter.writeTextElement("id", currentLayout.uid().toString()); 2399 2401 2400 2402 QVector<UISoftKeyboardRow> &rows = pPhysicalLayout->rows(); … … 2409 2411 UISoftKeyboardKey &key = keys[j]; 2410 2412 xmlWriter.writeTextElement("position", QString::number(key.position())); 2411 xmlWriter.writeTextElement("basecaption", m_pCurrentKeyboardLayout->baseCaption(key.position()));2412 xmlWriter.writeTextElement("shiftcaption", m_pCurrentKeyboardLayout->shiftCaption(key.position()));2413 xmlWriter.writeTextElement("altgrcaption", m_pCurrentKeyboardLayout->altGrCaption(key.position()));2414 xmlWriter.writeTextElement("shiftaltgrcaption", m_pCurrentKeyboardLayout->shiftAltGrCaption(key.position()));2413 xmlWriter.writeTextElement("basecaption", currentLayout.baseCaption(key.position())); 2414 xmlWriter.writeTextElement("shiftcaption", currentLayout.shiftCaption(key.position())); 2415 xmlWriter.writeTextElement("altgrcaption", currentLayout.altGrCaption(key.position())); 2416 xmlWriter.writeTextElement("shiftaltgrcaption", currentLayout.shiftAltGrCaption(key.position())); 2415 2417 xmlWriter.writeEndElement(); 2416 2418 } … … 2420 2422 2421 2423 xmlFile.close(); 2422 m_pCurrentKeyboardLayout->setSourceFilePath(strFileName);2423 m_pCurrentKeyboardLayout->setEditedBuNotSaved(false);2424 currentLayout.setSourceFilePath(strFileName); 2425 currentLayout.setEditedBuNotSaved(false); 2424 2426 sigStatusBarMessage(QString("%1 %2").arg(strFileName).arg(UISoftKeyboard::tr(" is saved"))); 2425 2427 } … … 2427 2429 void UISoftKeyboardWidget::copyCurentLayout() 2428 2430 { 2429 2430 UISoftKeyboardLayout newLayout(*(m_pCurrentKeyboardLayout)); 2431 UISoftKeyboardLayout newLayout(m_layouts[m_uCurrentLayoutId]); 2431 2432 2432 2433 QString strNewName = QString("%1-%2").arg(newLayout.name()).arg(UISoftKeyboard::tr("Copy")); 2433 2434 int iCount = 1; 2434 while ( findLayoutByName(strNewName))2435 while (layoutByNameExists(strNewName)) 2435 2436 { 2436 2437 strNewName = QString("%1-%2-%3").arg(newLayout.name()).arg(UISoftKeyboard::tr("Copy")).arg(QString::number(iCount)); … … 2588 2589 } 2589 2590 2590 2591 2591 void UISoftKeyboardWidget::deleteCurrentLayout() 2592 2592 { 2593 if (!m_pCurrentKeyboardLayout || !m_pCurrentKeyboardLayout->editable() || m_pCurrentKeyboardLayout->isFromResources()) 2594 return; 2595 /* Make sure we have at least one layout. */ 2593 if (!m_layouts.contains(m_uCurrentLayoutId)) 2594 return; 2595 2596 /* Make sure we will have at least one layout remaining. */ 2596 2597 if (m_layouts.size() <= 1) 2597 2598 return; 2598 2599 2599 int iIndex = m_layouts.indexOf(*(m_pCurrentKeyboardLayout)); 2600 if (iIndex == -1) 2601 return; 2600 const UISoftKeyboardLayout &layout = m_layouts.value(m_uCurrentLayoutId); 2601 if (!layout.editable() || layout.isFromResources()) 2602 return; 2603 2604 m_layouts.remove(m_uCurrentLayoutId); 2605 setCurrentLayout(m_layouts.firstKey()); 2602 2606 2603 2607 QDir fileToDelete; 2604 QString strFilePath(m_pCurrentKeyboardLayout->sourceFilePath()); 2608 QString strFilePath(layout.sourceFilePath()); 2609 2605 2610 bool fFileExists = false; 2606 2611 if (!strFilePath.isEmpty()) 2607 2612 fFileExists = fileToDelete.exists(strFilePath); 2608 2613 /* It might be that the layout copied but not yet saved into a file: */ 2609 2614 if (fFileExists) 2610 2615 { … … 2616 2621 false /* ok button by default? */)) 2617 2622 return; 2618 } 2619 2620 m_layouts.removeAt(iIndex); 2621 setCurrentLayout(&(m_layouts[0])); 2622 /* It might be that the layout copied but not yet saved into a file: */ 2623 if (fFileExists) 2624 { 2623 2625 2624 if (fileToDelete.remove(strFilePath)) 2626 2625 sigStatusBarMessage(QString("%1 %2 %3").arg(UISoftKeyboard::tr("The file ")).arg(strFilePath).arg(UISoftKeyboard::tr(" has been deleted"))); … … 2644 2643 void UISoftKeyboardWidget::addLayout(const UISoftKeyboardLayout &newLayout) 2645 2644 { 2646 m_layouts.append(newLayout); 2645 if (m_layouts.contains(newLayout.uid())) 2646 return; 2647 m_layouts[newLayout.uid()] = newLayout; 2647 2648 } 2648 2649 … … 2667 2668 UISoftKeyboardKey *UISoftKeyboardWidget::keyUnderMouse(const QPoint &eventPosition) 2668 2669 { 2669 if (!m_pCurrentKeyboardLayout)2670 return 0; 2671 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout( m_pCurrentKeyboardLayout->physicalLayoutUuid());2670 const UISoftKeyboardLayout ¤tLayout = m_layouts.value(m_uCurrentLayoutId); 2671 2672 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(currentLayout.physicalLayoutUuid()); 2672 2673 if (!pPhysicalLayout) 2673 2674 return 0; … … 2813 2814 } 2814 2815 2815 void UISoftKeyboardWidget::setCurrentLayout(const QString &strLayoutName)2816 {2817 UISoftKeyboardLayout *pLayout = findLayoutByName(strLayoutName);2818 if (!pLayout)2819 return;2820 setCurrentLayout(pLayout);2821 }2822 2823 2816 void UISoftKeyboardWidget::setCurrentLayout(const QUuid &layoutUid) 2824 2817 { 2825 UISoftKeyboardLayout *pLayout = findLayoutByUid(layoutUid); 2826 if (!pLayout) 2827 return; 2828 setCurrentLayout(pLayout); 2818 if (m_uCurrentLayoutId == layoutUid || !m_layouts.contains(layoutUid)) 2819 return; 2820 2821 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_layouts[layoutUid].physicalLayoutUuid()); 2822 if (!pPhysicalLayout) 2823 return; 2824 2825 m_uCurrentLayoutId = layoutUid; 2826 emit sigCurrentLayoutChange(); 2827 update(); 2829 2828 } 2830 2829 2831 2830 UISoftKeyboardLayout *UISoftKeyboardWidget::currentLayout() 2832 2831 { 2833 return m_pCurrentKeyboardLayout; 2832 if (!m_layouts.contains(m_uCurrentLayoutId)) 2833 return 0; 2834 return &(m_layouts[m_uCurrentLayoutId]); 2834 2835 } 2835 2836 … … 3026 3027 loadKeyboardLayout(strName); 3027 3028 /* Mark the layouts we load from the resources as non-editable: */ 3028 for ( int i = 0; i < m_layouts.size(); ++i)3029 { 3030 m_layouts[i].setEditable(false);3031 m_layouts[i].setIsFromResources(true);3029 for (QMap<QUuid, UISoftKeyboardLayout>::iterator iterator = m_layouts.begin(); iterator != m_layouts.end(); ++iterator) 3030 { 3031 iterator.value().setEditable(false); 3032 iterator.value().setIsFromResources(true); 3032 3033 } 3033 3034 keyboardLayoutNames.clear(); … … 3039 3040 if (m_layouts.isEmpty()) 3040 3041 return; 3041 for ( int i = 0; i < m_layouts.size(); ++i)3042 m_layouts[i].setEditedBuNotSaved(false);3043 setCurrentLayout( &(m_layouts[0]));3042 for (QMap<QUuid, UISoftKeyboardLayout>::iterator iterator = m_layouts.begin(); iterator != m_layouts.end(); ++iterator) 3043 iterator.value().setEditedBuNotSaved(false); 3044 setCurrentLayout(m_layouts.firstKey()); 3044 3045 } 3045 3046 … … 3078 3079 } 3079 3080 3080 void UISoftKeyboardWidget::setCurrentLayout(UISoftKeyboardLayout *pLayout) 3081 { 3082 if (m_pCurrentKeyboardLayout == pLayout) 3083 return; 3084 m_pCurrentKeyboardLayout = pLayout; 3085 if (!m_pCurrentKeyboardLayout) 3086 { 3087 emit sigCurrentLayoutChange(); 3088 return; 3089 } 3090 emit sigCurrentLayoutChange(); 3091 3092 UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid()); 3093 if (!pPhysicalLayout) 3094 return; 3095 3096 update(); 3097 } 3098 3099 UISoftKeyboardLayout *UISoftKeyboardWidget::findLayoutByName(const QString &strName) 3100 { 3101 for (int i = 0; i < m_layouts.size(); ++i) 3102 { 3103 if (m_layouts[i].name() == strName) 3104 return &(m_layouts[i]); 3105 } 3106 return 0; 3107 } 3108 3109 UISoftKeyboardLayout *UISoftKeyboardWidget::findLayoutByUid(const QUuid &uid) 3110 { 3111 if (uid.isNull()) 3112 return 0; 3113 for (int i = 0; i < m_layouts.size(); ++i) 3114 { 3115 if (m_layouts[i].uid() == uid) 3116 return &(m_layouts[i]); 3117 } 3118 return 0; 3081 bool UISoftKeyboardWidget::layoutByNameExists(const QString &strName) const 3082 { 3083 foreach (const UISoftKeyboardLayout &layout, m_layouts) 3084 { 3085 if (layout.name() == strName) 3086 return true; 3087 } 3088 return false; 3119 3089 } 3120 3090
Note:
See TracChangeset
for help on using the changeset viewer.