VirtualBox

Changeset 78682 in vbox for trunk/src/VBox


Ignore:
Timestamp:
May 23, 2019 9:30:36 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
130758
Message:

FE/Qt: bugref:6143. Making keeping the aspect ratio optional.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard
Files:
2 edited

Legend:

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

    r78680 r78682  
    169169    UISoftKeyboardRow(QWidget *pParent = 0);
    170170    void updateLayout();
     171    void setKeepAspectRatio(bool fKeepAspectRatio);
     172
     173    void setUnscaledWidth(int iWidth);
     174    int unscaledWidth() const;
     175
     176    void setUnscaledHeight(int iWidth);
     177    int unscaledHeight() const;
     178
     179    void addKey(UISoftKeyboardKey *pKey);
     180
     181private:
     182
    171183    int m_iWidth;
    172184    int m_iHeight;
    173185    QVector<UISoftKeyboardKey*> m_keys;
     186    bool m_fKeepAspectRatio;
    174187};
    175188
     
    491504    , m_iWidth(0)
    492505    , m_iHeight(0)
    493 
    494 {
     506    , m_fKeepAspectRatio(false)
     507{
     508}
     509
     510void UISoftKeyboardRow::setKeepAspectRatio(bool fKeepAspectRatio)
     511{
     512    m_fKeepAspectRatio = fKeepAspectRatio;
     513}
     514
     515void UISoftKeyboardRow::setUnscaledWidth(int iWidth)
     516{
     517    m_iWidth = iWidth;
     518}
     519
     520int UISoftKeyboardRow::unscaledWidth() const
     521{
     522    return m_iWidth;
     523}
     524
     525void UISoftKeyboardRow::setUnscaledHeight(int iHeight)
     526{
     527    m_iHeight = iHeight;
     528}
     529
     530int UISoftKeyboardRow::unscaledHeight() const
     531{
     532    return m_iHeight;
     533}
     534
     535void UISoftKeyboardRow::addKey(UISoftKeyboardKey *pKey)
     536{
     537    m_keys.append(pKey);
    495538}
    496539
     
    500543        return;
    501544
    502     float fMultiplier = height() / (float)m_iHeight;
     545
     546    float fMultiplier = 1;
     547    if (m_fKeepAspectRatio)
     548        fMultiplier = height() / (float)m_iHeight;
     549    else
     550        fMultiplier = width() / (float)m_iWidth;
    503551    int iX = 0;
    504552    for (int i = 0; i < m_keys.size(); ++i)
     
    538586    , m_iTotalRowHeight(0)
    539587    , m_iMaxRowWidth(0)
     588    , m_fKeepAspectRatio(false)
    540589{
    541590    prepareObjects();
     
    678727        UISoftKeyboardRow *pNewRow = new UISoftKeyboardRow(m_pContainerWidget);
    679728        m_rows.push_back(pNewRow);
    680         pNewRow->m_iHeight = layout.m_rows[i].m_iHeight;
     729        pNewRow->setUnscaledHeight(layout.m_rows[i].m_iHeight);
     730        pNewRow->setKeepAspectRatio(m_fKeepAspectRatio);
    681731        m_iTotalRowHeight += layout.m_rows[i].m_iHeight;
    682         pNewRow->m_iWidth = 0;
     732        int iRowWidth = 0;
    683733        for (int j = 0; j < layout.m_rows[i].m_keys.size(); ++j)
    684734        {
    685735            const SoftKeyboardKey &key = layout.m_rows[i].m_keys[j];
    686             pNewRow->m_iWidth += key.m_iWidth;
    687             pNewRow->m_iWidth += key.m_iSpaceAfter;
     736            iRowWidth += key.m_iWidth;
     737            iRowWidth += key.m_iSpaceAfter;
    688738            UISoftKeyboardKey *pKey = new UISoftKeyboardKey(pNewRow);
    689739            if (!pKey)
     
    692742            connect(pKey, &UISoftKeyboardKey::released, this, &UISoftKeyboard::sltHandleKeyRelease);
    693743            connect(pKey, &UISoftKeyboardKey::sigStateChanged, this, &UISoftKeyboard::sltHandleModifierStateChange);
    694             pNewRow->m_keys.append(pKey);
     744            pNewRow->addKey(pKey);
    695745            pKey->setText(key.m_strLabel);
    696746            pKey->setWidth(key.m_iWidth);
     
    701751            pKey->hide();
    702752        }
    703         m_iMaxRowWidth = qMax(m_iMaxRowWidth, pNewRow->m_iWidth);
     753        pNewRow->setUnscaledWidth(iRowWidth);
     754        m_iMaxRowWidth = qMax(m_iMaxRowWidth, pNewRow->unscaledWidth());
    704755    }
    705756}
     
    713764    if (containerSize.width() == 0 || containerSize.height() == 0)
    714765        return;
    715     float fMultiplier = containerSize.width() / (float) m_iMaxRowWidth;
     766
     767    float fMultiplierX = containerSize.width() / (float) m_iMaxRowWidth;
     768    float fMultiplierY = containerSize.height() / (float) m_iTotalRowHeight;
     769    float fMultiplier = fMultiplierX;
    716770
    717771    if (fMultiplier * m_iTotalRowHeight > containerSize.height())
    718         fMultiplier = containerSize.height() / (float) m_iTotalRowHeight;
     772        fMultiplier = fMultiplierY;
    719773
    720774    int y = 0;
     
    726780        if (!pRow)
    727781            continue;
    728         pRow->setGeometry(0, y, fMultiplier * pRow->m_iWidth, fMultiplier * pRow->m_iHeight);
    729         pRow->setVisible(true);
    730         y += fMultiplier * pRow->m_iHeight;
    731         totalWidth += fMultiplier * pRow->m_iWidth;
    732         totalHeight += fMultiplier * pRow->m_iHeight;
     782        if(m_fKeepAspectRatio)
     783        {
     784            pRow->setGeometry(0, y, fMultiplier * pRow->unscaledWidth(), fMultiplier * pRow->unscaledHeight());
     785            pRow->setVisible(true);
     786            y += fMultiplier * pRow->unscaledHeight();
     787            totalWidth += fMultiplier * pRow->unscaledWidth();
     788            totalHeight += fMultiplier * pRow->unscaledHeight();
     789        }
     790        else
     791        {
     792            pRow->setGeometry(0, y, fMultiplierX * pRow->unscaledWidth(), fMultiplierY * pRow->unscaledHeight());
     793            pRow->setVisible(true);
     794            y += fMultiplierY * pRow->unscaledHeight();
     795            totalWidth += fMultiplierX * pRow->unscaledWidth();
     796            totalHeight += fMultiplierY * pRow->unscaledHeight();
     797        }
    733798        pRow->updateLayout();
    734799    }
     800    if (m_rows.size() > 0)
     801        printf("row 0 width %d\n", m_rows[0]->size().width());
    735802}
    736803
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h

    r78661 r78682  
    8585    int           m_iMaxRowWidth;
    8686    QVector<UISoftKeyboardKey*> m_pressedModifiers;
     87    bool          m_fKeepAspectRatio;
    8788};
    8889
Note: See TracChangeset for help on using the changeset viewer.

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