VirtualBox

Changeset 81208 in vbox


Ignore:
Timestamp:
Oct 10, 2019 11:16:51 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6699. Caching the font sizes rather than computing them at each re-draw

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r81171 r81208  
    107107};
    108108
    109 struct KeyCaptions
    110 {
     109struct UIKeyCaptions
     110{
     111    UIKeyCaptions(const QString &strBase, const QString &strShift,
     112                const QString &strAltGr, const QString &strShiftAltGr)
     113        : m_strBase(strBase)
     114        , m_strShift(strShift)
     115        , m_strAltGr(strAltGr)
     116        , m_strShiftAltGr(strShiftAltGr)
     117    {
     118        m_strBase.replace("\\n", "\n");
     119        m_strShift.replace("\\n", "\n");
     120        m_strAltGr.replace("\\n", "\n");
     121        m_strShiftAltGr.replace("\\n", "\n");
     122    }
     123    UIKeyCaptions(){}
     124    bool operator==(const UIKeyCaptions &other) const
     125    {
     126        return (m_strBase == other.m_strBase &&
     127                m_strShift == other.m_strShift &&
     128                m_strAltGr == other.m_strAltGr &&
     129                m_strShiftAltGr == other.m_strShiftAltGr);
     130    }
    111131    QString m_strBase;
    112132    QString m_strShift;
     
    175195
    176196    void sigLayoutEdited();
    177     void sigKeyCaptionsEdited(UISoftKeyboardKey* pKey);
     197    void sigUIKeyCaptionsEdited(UISoftKeyboardKey* pKey);
    178198    void sigGoBackButton();
    179199
     
    192212private slots:
    193213
    194     void sltKeyBaseCaptionChange(const QString &strCaption);
    195     void sltKeyShiftCaptionChange(const QString &strCaption);
    196     void sltKeyAltGrCaptionChange(const QString &strCaption);
    197     void sltKeyShiftAltGrCaptionChange(const QString &strCaption);
     214    void sltCaptionsUpdate();
    198215    void sltPhysicalLayoutChanged();
    199216    void sltLayoutNameChanged(const QString &strCaption);
     
    327344/** UISoftKeyboardKey is a place holder for a keyboard key. Graphical key represantations are drawn according to this class.
    328345  * The position of a key within the physical layout is read from the layout file. Note that UISoftKeyboardKey does not have
    329   * caption field(s). */
     346  * caption field(s). Captions are kept by UISoftKeyboardLayout since same keys may (and usually do) have different captions in
     347  * different layouts. */
    330348class UISoftKeyboardKey
    331349{
     
    450468    bool isFromResources() const;
    451469
    452     void updateKeyCaptions(int iKeyPosition, KeyCaptions &newCaptions);
     470    void updateUIKeyCaptions(int iKeyPosition, UIKeyCaptions &newCaptions);
    453471
    454472    void setEditable(bool fEditable);
     
    458476    const QUuid &physicalLayoutUuid() const;
    459477
    460     void setKeyCapMap(const QMap<int, KeyCaptions> &keyCapMap);
    461     QMap<int, KeyCaptions> &keyCapMap();
    462     const QMap<int, KeyCaptions> &keyCapMap() const;
     478    void setKeyCapMap(const QMap<int, UIKeyCaptions> &keyCaptionsMap);
     479    void addOrUpdateUIKeyCaptions(int iKeyPosition, const UIKeyCaptions &keyCaptions);
     480    UIKeyCaptions keyCaptions(int iKeyPosition);
     481
    463482    bool operator==(const UISoftKeyboardLayout &otherLayout);
    464483
    465     const QString baseCaption(int iKeyPosition) const;
    466     void setBaseCaption(int iKeyPosition, const QString &strBaseCaption);
    467 
    468     const QString shiftCaption(int iKeyPosition) const;
    469     void setShiftCaption(int iKeyPosition, const QString &strShiftCaption);
    470 
    471     const QString altGrCaption(int iKeyPosition) const;
    472     void  setAltGrCaption(int iKeyPosition, const QString &strAltGrCaption);
    473 
    474     const QString shiftAltGrCaption(int iKeyPosition) const;
    475     void  setShiftAltGrCaption(int iKeyPosition, const QString &strAltGrCaption);
    476 
    477     const KeyCaptions keyCaptions(int iKeyPosition) const;
     484    QString baseCaption(int iKeyPosition) const;
     485    QString shiftCaption(int iKeyPosition) const;
     486    QString altGrCaption(int iKeyPosition) const;
     487    QString shiftAltGrCaption(int iKeyPosition) const;
    478488
    479489    void setUid(const QUuid &uid);
     
    485495private:
    486496
    487     QMap<int, KeyCaptions> m_keyCapMap;
    488     QMap<int, QPicture>    m_pictureMap;
    489 
     497    QMap<int, UIKeyCaptions> m_keyCaptionsMap;
     498    /** Caching the font sizes we used for font rendering since it is not a very cheap process to compute these. */
     499    QMap<int, int>         m_keyCaptionsFontSizeMap;
    490500    /** The UUID of the physical layout used by this layout. */
    491501    QUuid   m_physicalLayoutUuid;
     
    693703private:
    694704
    695     void  parseKey(QMap<int, KeyCaptions> &keyCapMap);
     705    void  parseKey(UISoftKeyboardLayout &layout);
    696706    QXmlStreamReader m_xmlReader;
    697707    /** Map key is the key position and the value is the captions of the key. */
     
    897907    if (m_pKey)
    898908    {
    899         KeyCaptions captions = m_pLayout->keyCaptions(m_pKey->position());
    900         if (captions.m_strBase != m_pBaseCaptionEdit->text())
    901             m_pLayout->setBaseCaption(m_pKey->position(), m_pBaseCaptionEdit->text());
    902         if (captions.m_strShift != m_pShiftCaptionEdit->text())
    903             m_pLayout->setShiftCaption(m_pKey->position(), m_pShiftCaptionEdit->text());
    904         if (captions.m_strAltGr != m_pAltGrCaptionEdit->text())
    905             m_pLayout->setAltGrCaption(m_pKey->position(), m_pAltGrCaptionEdit->text());
    906         if (captions.m_strShiftAltGr != m_pShiftAltGrCaptionEdit->text())
    907             m_pLayout->setShiftAltGrCaption(m_pKey->position(), m_pShiftAltGrCaptionEdit->text());
     909        UIKeyCaptions captions = m_pLayout->keyCaptions(m_pKey->position());
     910        if (captions.m_strBase != m_pBaseCaptionEdit->text() ||
     911            captions.m_strShift != m_pShiftCaptionEdit->text() ||
     912            captions.m_strAltGr != m_pAltGrCaptionEdit->text() ||
     913            captions.m_strShiftAltGr != m_pShiftAltGrCaptionEdit->text())
     914            m_pLayout->addOrUpdateUIKeyCaptions(m_pKey->position(),
     915                                              UIKeyCaptions(m_pBaseCaptionEdit->text(),
     916                                                          m_pShiftCaptionEdit->text(),
     917                                                          m_pAltGrCaptionEdit->text(),
     918                                                          m_pShiftAltGrCaptionEdit->text()));
    908919    }
    909920    m_pKey = pKey;
     
    919930    if (m_pPositionEdit)
    920931        m_pPositionEdit->setText(QString::number(m_pKey->position()));
    921     KeyCaptions captions = m_pLayout->keyCaptions(m_pKey->position());
     932    UIKeyCaptions captions = m_pLayout->keyCaptions(m_pKey->position());
    922933    if (m_pBaseCaptionEdit)
    923934        m_pBaseCaptionEdit->setText(captions.m_strBase);
     
    10051016}
    10061017
    1007 void UIKeyboardLayoutEditor::sltKeyBaseCaptionChange(const QString &strCaption)
     1018void UIKeyboardLayoutEditor::sltCaptionsUpdate()
    10081019{
    10091020    if (!m_pKey || !m_pLayout)
    10101021        return;
    1011     if (m_pLayout->baseCaption(m_pKey->position()) == strCaption)
    1012         return;
    1013     m_pLayout->setBaseCaption(m_pKey->position(), strCaption);
    1014     emit sigKeyCaptionsEdited(m_pKey);
    1015 }
    1016 
    1017 void UIKeyboardLayoutEditor::sltKeyShiftCaptionChange(const QString &strCaption)
    1018 {
    1019     if (!m_pKey || !m_pLayout)
    1020         return;
    1021     if (m_pLayout->shiftCaption(m_pKey->position()) == strCaption)
    1022         return;
    1023     m_pLayout->setShiftCaption(m_pKey->position(), strCaption);
    1024     emit sigKeyCaptionsEdited(m_pKey);
    1025 }
    1026 
    1027 void UIKeyboardLayoutEditor::sltKeyAltGrCaptionChange(const QString &strCaption)
    1028 {
    1029     if (!m_pKey || !m_pLayout)
    1030         return;
    1031     if (m_pLayout->altGrCaption(m_pKey->position()) == strCaption)
    1032         return;
    1033     m_pLayout->setAltGrCaption(m_pKey->position(), strCaption);
    1034     emit sigKeyCaptionsEdited(m_pKey);
    1035 }
    1036 
    1037 void UIKeyboardLayoutEditor::sltKeyShiftAltGrCaptionChange(const QString &strCaption)
    1038 {
    1039     if (!m_pKey || !m_pLayout)
    1040         return;
    1041     if (m_pLayout->shiftAltGrCaption(m_pKey->position()) == strCaption)
    1042         return;
    1043     m_pLayout->setShiftAltGrCaption(m_pKey->position(), strCaption);
    1044     emit sigKeyCaptionsEdited(m_pKey);
     1022    m_pLayout->addOrUpdateUIKeyCaptions(m_pKey->position(),
     1023                                      UIKeyCaptions(m_pBaseCaptionEdit->text(),
     1024                                                  m_pShiftCaptionEdit->text(),
     1025                                                  m_pAltGrCaptionEdit->text(),
     1026                                                  m_pShiftAltGrCaptionEdit->text()));
     1027    emit sigUIKeyCaptionsEdited(m_pKey);
    10451028}
    10461029
     
    11661149    pCaptionEditorLayout->addWidget(m_pBaseCaptionLabel, 0, 0);
    11671150    pCaptionEditorLayout->addWidget(m_pBaseCaptionEdit, 0, 1);
    1168     connect(m_pBaseCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltKeyBaseCaptionChange);
     1151    connect(m_pBaseCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltCaptionsUpdate);
    11691152
    11701153    m_pShiftCaptionLabel = new QLabel;
     
    11731156    pCaptionEditorLayout->addWidget(m_pShiftCaptionLabel, 1, 0);
    11741157    pCaptionEditorLayout->addWidget(m_pShiftCaptionEdit, 1, 1);
    1175     connect(m_pShiftCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltKeyShiftCaptionChange);
     1158    connect(m_pShiftCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltCaptionsUpdate);
    11761159
    11771160    m_pAltGrCaptionLabel = new QLabel;
     
    11801163    pCaptionEditorLayout->addWidget(m_pAltGrCaptionLabel, 2, 0);
    11811164    pCaptionEditorLayout->addWidget(m_pAltGrCaptionEdit, 2, 1);
    1182     connect(m_pAltGrCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltKeyAltGrCaptionChange);
     1165    connect(m_pAltGrCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltCaptionsUpdate);
    11831166
    11841167    m_pShiftAltGrCaptionLabel = new QLabel;
     
    11871170    pCaptionEditorLayout->addWidget(m_pShiftAltGrCaptionLabel, 3, 0);
    11881171    pCaptionEditorLayout->addWidget(m_pShiftAltGrCaptionEdit, 3, 1);
    1189     connect(m_pShiftAltGrCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltKeyShiftAltGrCaptionChange);
     1172    connect(m_pShiftAltGrCaptionEdit, &QLineEdit::textChanged, this, &UIKeyboardLayoutEditor::sltCaptionsUpdate);
    11901173
    11911174
     
    16851668}
    16861669
    1687 void UISoftKeyboardLayout::updateKeyCaptions(int iKeyPosition, KeyCaptions &newCaptions)
    1688 {
    1689     if (!m_keyCapMap.contains(iKeyPosition))
    1690         return;
    1691     m_keyCapMap[iKeyPosition] = newCaptions;
     1670void UISoftKeyboardLayout::updateUIKeyCaptions(int iKeyPosition, UIKeyCaptions &newCaptions)
     1671{
     1672    if (!m_keyCaptionsMap.contains(iKeyPosition))
     1673        return;
     1674    m_keyCaptionsMap[iKeyPosition] = newCaptions;
    16921675}
    16931676
     
    17641747}
    17651748
    1766 void UISoftKeyboardLayout::setKeyCapMap(const QMap<int, KeyCaptions> &keyCapMap)
    1767 {
    1768     m_keyCapMap = keyCapMap;
    1769 }
    1770 
    1771 QMap<int, KeyCaptions> &UISoftKeyboardLayout::keyCapMap()
    1772 {
    1773     return m_keyCapMap;
    1774 }
    1775 
    1776 const QMap<int, KeyCaptions> &UISoftKeyboardLayout::keyCapMap() const
    1777 {
    1778     return m_keyCapMap;
     1749void UISoftKeyboardLayout::setKeyCapMap(const QMap<int, UIKeyCaptions> &keyCaptionsMap)
     1750{
     1751    m_keyCaptionsMap = keyCaptionsMap;
     1752}
     1753
     1754void UISoftKeyboardLayout::addOrUpdateUIKeyCaptions(int iKeyPosition, const UIKeyCaptions &keyCaptions)
     1755{
     1756    if (m_keyCaptionsMap[iKeyPosition] == keyCaptions)
     1757        return;
     1758    m_keyCaptionsMap[iKeyPosition] = keyCaptions;
     1759    /* Updating the captions invalidates the cached font size. We set it to 0, thereby forcing its recomputaion: */
     1760    m_keyCaptionsFontSizeMap[iKeyPosition] = 0;
     1761}
     1762
     1763UIKeyCaptions UISoftKeyboardLayout::keyCaptions(int iKeyPosition)
     1764{
     1765    return m_keyCaptionsMap[iKeyPosition];
    17791766}
    17801767
     
    17961783}
    17971784
    1798 const QString UISoftKeyboardLayout::baseCaption(int iKeyPosition) const
    1799 {
    1800     return m_keyCapMap.value(iKeyPosition, KeyCaptions()).m_strBase;
    1801 }
    1802 
    1803 void UISoftKeyboardLayout::setBaseCaption(int iKeyPosition, const QString &strBaseCaption)
    1804 {
    1805     m_keyCapMap[iKeyPosition].m_strBase = strBaseCaption;
    1806     m_keyCapMap[iKeyPosition].m_strBase.replace("\\n", "\n");
    1807 }
    1808 
    1809 const QString UISoftKeyboardLayout::shiftCaption(int iKeyPosition) const
    1810 {
    1811     if (!m_keyCapMap.contains(iKeyPosition))
     1785QString UISoftKeyboardLayout::baseCaption(int iKeyPosition) const
     1786{
     1787    return m_keyCaptionsMap.value(iKeyPosition, UIKeyCaptions()).m_strBase;
     1788}
     1789
     1790QString UISoftKeyboardLayout::shiftCaption(int iKeyPosition) const
     1791{
     1792    if (!m_keyCaptionsMap.contains(iKeyPosition))
    18121793        return QString();
    1813     return m_keyCapMap[iKeyPosition].m_strShift;
    1814 }
    1815 
    1816 void UISoftKeyboardLayout::setShiftCaption(int iKeyPosition, const QString &strShiftCaption)
    1817 {
    1818     m_keyCapMap[iKeyPosition].m_strShift = strShiftCaption;
    1819     m_keyCapMap[iKeyPosition].m_strShift.replace("\\n", "\n");
    1820 }
    1821 
    1822 const QString UISoftKeyboardLayout::altGrCaption(int iKeyPosition) const
    1823 {
    1824     if (!m_keyCapMap.contains(iKeyPosition))
     1794    return m_keyCaptionsMap[iKeyPosition].m_strShift;
     1795}
     1796
     1797QString UISoftKeyboardLayout::altGrCaption(int iKeyPosition) const
     1798{
     1799    if (!m_keyCaptionsMap.contains(iKeyPosition))
    18251800        return QString();
    1826     return m_keyCapMap[iKeyPosition].m_strAltGr;
    1827 }
    1828 
    1829 void UISoftKeyboardLayout::setAltGrCaption(int iKeyPosition, const QString &strAltGrCaption)
    1830 {
    1831     m_keyCapMap[iKeyPosition].m_strAltGr = strAltGrCaption;
    1832     m_keyCapMap[iKeyPosition].m_strAltGr.replace("\\n", "\n");
    1833 }
    1834 
    1835 const QString UISoftKeyboardLayout::shiftAltGrCaption(int iKeyPosition) const
    1836 {
    1837     if (!m_keyCapMap.contains(iKeyPosition))
     1801    return m_keyCaptionsMap[iKeyPosition].m_strAltGr;
     1802}
     1803
     1804QString UISoftKeyboardLayout::shiftAltGrCaption(int iKeyPosition) const
     1805{
     1806    if (!m_keyCaptionsMap.contains(iKeyPosition))
    18381807        return QString();
    1839     return m_keyCapMap[iKeyPosition].m_strShiftAltGr;
    1840 }
    1841 
    1842 void UISoftKeyboardLayout::setShiftAltGrCaption(int iKeyPosition, const QString &strShiftAltGrCaption)
    1843 {
    1844     m_keyCapMap[iKeyPosition].m_strShiftAltGr = strShiftAltGrCaption;
    1845     m_keyCapMap[iKeyPosition].m_strShiftAltGr.replace("\\n", "\n");
    1846 }
    1847 
    1848 const KeyCaptions UISoftKeyboardLayout::keyCaptions(int iKeyPosition) const
    1849 {
    1850     if (!m_keyCapMap.contains(iKeyPosition))
    1851         return KeyCaptions();
    1852     return m_keyCapMap[iKeyPosition];
     1808    return m_keyCaptionsMap[iKeyPosition].m_strShiftAltGr;
    18531809}
    18541810
     
    18651821void UISoftKeyboardLayout::drawTextInRect(const UISoftKeyboardKey &key, QPainter &painter)
    18661822{
    1867     int iKeyPosition = key.position();
    1868     const QRect &keyGeometry = key.keyGeometry();
    1869     QFont painterFont(painter.font());
    1870     int iFontSize = 30;
    1871 
    1872     const QString &strBaseCaption = baseCaption(iKeyPosition);
    1873     const QString &strShiftCaption = shiftCaption(iKeyPosition);
    1874 
    1875     const QString &strShiftAltGrCaption = shiftAltGrCaption(iKeyPosition);
    1876     const QString &strAltGrCaption = altGrCaption(iKeyPosition);
    1877 
    1878     const QString &strTopleftString = !strShiftCaption.isEmpty() ? strShiftCaption : strBaseCaption;
    1879     const QString &strBottomleftString = !strShiftCaption.isEmpty() ? strBaseCaption : QString();
    1880 
    1881     do
    1882     {
    1883         painterFont.setPixelSize(iFontSize);
    1884         painterFont.setBold(true);
    1885         painter.setFont(painterFont);
    1886         QFontMetrics fontMetrics = painter.fontMetrics();
    1887         int iMargin = 0.25 * fontMetrics.width('X');
    1888 
    1889         int iTopWidth = 0;
    1890 
    1891         QStringList strList;
    1892         strList << strTopleftString.split("\n", QString::SkipEmptyParts)
    1893                 << strShiftAltGrCaption.split("\n", QString::SkipEmptyParts);
    1894         foreach (const QString &strPart, strList)
    1895             iTopWidth = qMax(iTopWidth, fontMetrics.width(strPart));
    1896         strList.clear();
    1897         strList << strBottomleftString.split("\n", QString::SkipEmptyParts)
    1898                 << strAltGrCaption.split("\n", QString::SkipEmptyParts);
    1899 
    1900         int iBottomWidth = 0;
    1901         foreach (const QString &strPart, strList)
    1902             iBottomWidth = qMax(iBottomWidth, fontMetrics.width(strPart));
    1903         int iTextWidth =  2 * iMargin + qMax(iTopWidth, iBottomWidth);
    1904         int iTextHeight = 0;
    1905 
    1906         if (key.keyboardRegion() == KeyboardRegion_MultimediaKeys)
    1907             iTextHeight = 2 * iMargin + fontMetrics.height();
    1908         else
    1909             iTextHeight = 2 * iMargin + 2 * fontMetrics.height();
    1910 
    1911         if (iTextWidth >= keyGeometry.width() || iTextHeight >= keyGeometry.height())
    1912             --iFontSize;
    1913         else
    1914             break;
    1915 
    1916     }while(iFontSize > 1);
    1917 
    1918 
    1919     QFontMetrics fontMetrics = painter.fontMetrics();
    1920     int iMargin = 0.25 * fontMetrics.width('X');
    1921 #if 0
    1922     painter.drawText(iMargin, iMargin + fontMetrics.height(), QString::number(iKeyPosition));
    1923 #else
    1924     QRect textRect;
    1925     if (key.keyboardRegion() == KeyboardRegion_MultimediaKeys)
    1926         textRect = QRect(2 * iMargin, iMargin,
    1927                          keyGeometry.width() - 2 * iMargin,
    1928                          keyGeometry.height() - 2 * iMargin);
    1929     else
    1930         textRect = QRect(iMargin, iMargin,
    1931                          keyGeometry.width() - 2 * iMargin,
    1932                          keyGeometry.height() - 2 * iMargin);
    1933 
    1934     painter.drawText(textRect, Qt::AlignLeft | Qt::AlignTop, strTopleftString);
    1935     painter.drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, strBottomleftString);
    1936     painter.drawText(textRect, Qt::AlignRight | Qt::AlignTop, strShiftAltGrCaption);
    1937     painter.drawText(textRect, Qt::AlignRight | Qt::AlignBottom, strAltGrCaption);
    1938 
    1939 #endif
     1823     int iKeyPosition = key.position();
     1824     const QRect &keyGeometry = key.keyGeometry();
     1825     QFont painterFont(painter.font());
     1826
     1827     const QString &strBaseCaption = baseCaption(iKeyPosition);
     1828     const QString &strShiftCaption = shiftCaption(iKeyPosition);
     1829
     1830     const QString &strShiftAltGrCaption = shiftAltGrCaption(iKeyPosition);
     1831     const QString &strAltGrCaption = altGrCaption(iKeyPosition);
     1832
     1833     const QString &strTopleftString = !strShiftCaption.isEmpty() ? strShiftCaption : strBaseCaption;
     1834     const QString &strBottomleftString = !strShiftCaption.isEmpty() ? strBaseCaption : QString();
     1835
     1836     int iFontSize = 30;
     1837     if (!m_keyCaptionsFontSizeMap.contains(iKeyPosition) || m_keyCaptionsFontSizeMap.value(iKeyPosition) == 0)
     1838     {
     1839         do
     1840         {
     1841             painterFont.setPixelSize(iFontSize);
     1842             painterFont.setBold(true);
     1843             painter.setFont(painterFont);
     1844             QFontMetrics fontMetrics = painter.fontMetrics();
     1845             int iMargin = 0.25 * fontMetrics.width('X');
     1846
     1847             int iTopWidth = 0;
     1848             /* Some captions are multi line using \n as separator: */
     1849             QStringList strList;
     1850             strList << strTopleftString.split("\n", QString::SkipEmptyParts)
     1851                     << strShiftAltGrCaption.split("\n", QString::SkipEmptyParts);
     1852             foreach (const QString &strPart, strList)
     1853                 iTopWidth = qMax(iTopWidth, fontMetrics.width(strPart));
     1854             strList.clear();
     1855             strList << strBottomleftString.split("\n", QString::SkipEmptyParts)
     1856                     << strAltGrCaption.split("\n", QString::SkipEmptyParts);
     1857
     1858             int iBottomWidth = 0;
     1859             foreach (const QString &strPart, strList)
     1860                 iBottomWidth = qMax(iBottomWidth, fontMetrics.width(strPart));
     1861             int iTextWidth =  2 * iMargin + qMax(iTopWidth, iBottomWidth);
     1862             int iTextHeight = 0;
     1863
     1864             if (key.keyboardRegion() == KeyboardRegion_MultimediaKeys)
     1865                 iTextHeight = 2 * iMargin + fontMetrics.height();
     1866             else
     1867                 iTextHeight = 2 * iMargin + 2 * fontMetrics.height();
     1868
     1869             if (iTextWidth >= keyGeometry.width() || iTextHeight >= keyGeometry.height())
     1870                 --iFontSize;
     1871             else
     1872                 break;
     1873
     1874         }while(iFontSize > 1);
     1875         m_keyCaptionsFontSizeMap[iKeyPosition] = iFontSize;
     1876     }
     1877     else
     1878     {
     1879         iFontSize = m_keyCaptionsFontSizeMap[iKeyPosition];
     1880         painterFont.setPixelSize(iFontSize);
     1881         painterFont.setBold(true);
     1882         painter.setFont(painterFont);
     1883     }
     1884
     1885     QFontMetrics fontMetrics = painter.fontMetrics();
     1886     int iMargin = 0.25 * fontMetrics.width('X');
     1887     QRect textRect;
     1888     if (key.keyboardRegion() == KeyboardRegion_MultimediaKeys)
     1889         textRect = QRect(2 * iMargin, iMargin,
     1890                          keyGeometry.width() - 2 * iMargin,
     1891                          keyGeometry.height() - 2 * iMargin);
     1892     else
     1893         textRect = QRect(iMargin, iMargin,
     1894                          keyGeometry.width() - 2 * iMargin,
     1895                          keyGeometry.height() - 2 * iMargin);
     1896
     1897     painter.drawText(textRect, Qt::AlignLeft | Qt::AlignTop, strTopleftString);
     1898     painter.drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, strBottomleftString);
     1899     painter.drawText(textRect, Qt::AlignRight | Qt::AlignTop, strShiftAltGrCaption);
     1900     painter.drawText(textRect, Qt::AlignRight | Qt::AlignBottom, strAltGrCaption);
    19401901}
    19411902
     
    32133174    {
    32143175        if (m_xmlReader.name() == "key")
    3215             parseKey(layout.keyCapMap());
     3176            parseKey(layout);
    32163177        else if (m_xmlReader.name() == "name")
    32173178            layout.setName(m_xmlReader.readElementText());
     
    32283189}
    32293190
    3230 void  UIKeyboardLayoutReader::parseKey(QMap<int, KeyCaptions> &keyCapMap)
    3231 {
    3232     KeyCaptions keyCaptions;
     3191void  UIKeyboardLayoutReader::parseKey(UISoftKeyboardLayout &layout)
     3192{
     3193    UIKeyCaptions keyCaptions;
    32333194    int iKeyPosition = 0;
    32343195    while (m_xmlReader.readNextStartElement())
     
    32593220            m_xmlReader.skipCurrentElement();
    32603221    }
    3261     keyCapMap.insert(iKeyPosition, keyCaptions);
     3222    layout.addOrUpdateUIKeyCaptions(iKeyPosition, keyCaptions);
    32623223}
    32633224
     
    37873748    connect(m_pLayoutEditor, &UIKeyboardLayoutEditor::sigGoBackButton, this, &UISoftKeyboard::sltShowLayoutSelector);
    37883749    connect(m_pLayoutEditor, &UIKeyboardLayoutEditor::sigLayoutEdited, this, &UISoftKeyboard::sltLayoutEdited);
    3789     connect(m_pLayoutEditor, &UIKeyboardLayoutEditor::sigKeyCaptionsEdited, this, &UISoftKeyboard::sltKeyCaptionsEdited);
     3750    connect(m_pLayoutEditor, &UIKeyboardLayoutEditor::sigUIKeyCaptionsEdited, this, &UISoftKeyboard::sltKeyCaptionsEdited);
    37903751
    37913752    connect(m_pStatusBarWidget, &UISoftKeyboardStatusBarWidget::sigShowHideSidePanel, this, &UISoftKeyboard::sltShowHideSidePanel);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette