VirtualBox

Ignore:
Timestamp:
Dec 20, 2010 2:19:48 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
69094
Message:

FE/Qt: 3635: Scale mode: Keep aspect-ratio during manual window resize (win-host only).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r33579 r35247  
    141141}
    142142
     143double UIMachineView::aspectRatio() const
     144{
     145    return frameBuffer() ? (double)(frameBuffer()->width()) / frameBuffer()->height() : 0;
     146}
     147
    143148void UIMachineView::sltMachineStateChanged()
    144149{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r31698 r35247  
    6363    /* Public members: */
    6464    virtual void normalizeGeometry(bool /* bAdjustPosition = false */) = 0;
     65
     66    /* Framebuffer aspect ratio: */
     67    double aspectRatio() const;
    6568
    6669signals:
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp

    r31321 r35247  
    150150    return QIWithRetranslateUI2<QMainWindow>::event(pEvent);
    151151}
     152
     153#ifdef Q_WS_WIN
     154bool UIMachineWindowScale::winEvent(MSG *pMessage, long *pResult)
     155{
     156    /* Try to keep aspect ratio during window resize if:
     157     * 1. machine view exists and 2. event-type is WM_SIZING and 3. shift key is NOT pressed: */
     158    if (machineView() && pMessage->message == WM_SIZING && !(QApplication::keyboardModifiers() & Qt::ShiftModifier))
     159    {
     160        if (double dAspectRatio = machineView()->aspectRatio())
     161        {
     162            RECT *pRect = reinterpret_cast<RECT*>(pMessage->lParam);
     163            switch (pMessage->wParam)
     164            {
     165                case WMSZ_LEFT:
     166                case WMSZ_RIGHT:
     167                {
     168                    pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio;
     169                    break;
     170                }
     171                case WMSZ_TOP:
     172                case WMSZ_BOTTOM:
     173                {
     174                    pRect->right = pRect->left + (double)(pRect->bottom - pRect->top) * dAspectRatio;
     175                    break;
     176                }
     177                case WMSZ_BOTTOMLEFT:
     178                case WMSZ_BOTTOMRIGHT:
     179                {
     180                    pRect->bottom = pRect->top + (double)(pRect->right - pRect->left) / dAspectRatio;
     181                    break;
     182                }
     183                case WMSZ_TOPLEFT:
     184                case WMSZ_TOPRIGHT:
     185                {
     186                    pRect->top = pRect->bottom - (double)(pRect->right - pRect->left) / dAspectRatio;
     187                    break;
     188                }
     189                default:
     190                    break;
     191            }
     192        }
     193    }
     194    /* Pass event to base-class: */
     195    return QMainWindow::winEvent(pMessage, pResult);
     196}
     197#endif /* Q_WS_WIN */
    152198
    153199#ifdef Q_WS_X11
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.h

    r30848 r35247  
    5555    /* Event handlers: */
    5656    bool event(QEvent *pEvent);
     57#ifdef Q_WS_WIN
     58    bool winEvent(MSG *pMessage, long *pResult);
     59#endif
    5760#ifdef Q_WS_X11
    5861    bool x11Event(XEvent *pEvent);
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