VirtualBox

Ignore:
Timestamp:
Jan 22, 2009 3:36:08 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
41922
Message:

re-applied r41915 which was accidently backed out with r41920

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r15669 r16176  
    900900    static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel);
    901901
    902     static QRect normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
     902    static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
    903903                                    bool aCanResize = true);
     904    static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
     905                                bool aCanResize = true);
     906    static QRegion flip (const QRegion &aRegion);
    904907
    905908    static void centerWidget (QWidget *aWidget, QWidget *aRelative,
  • trunk/src/VBox/Frontends/VirtualBox/src/QIDialog.cpp

    r10916 r16176  
    5858    /* Explicit widget centering relatively to it's parent
    5959     * if any or desktop if parent is missed. */
    60     vboxGlobal().centerWidget (this, parentWidget(), false);
     60    VBoxGlobal::centerWidget (this, parentWidget(), false);
    6161}
    6262
  • trunk/src/VBox/Frontends/VirtualBox/src/QIMainDialog.cpp

    r12764 r16176  
    226226    /* Explicit widget centering relatively to it's centering
    227227     * widget if any or desktop if centering widget is missed. */
    228     vboxGlobal().centerWidget (this, mCenterWidget, false);
     228    VBoxGlobal::centerWidget (this, mCenterWidget, false);
    229229}
    230230
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r15960 r16176  
    973973    if (adjustPosition)
    974974    {
    975         QRect ar = QApplication::desktop()->availableGeometry (tlw->pos());
     975        QRegion ar;
     976        QDesktopWidget *dwt = QApplication::desktop();
     977        if (dwt->isVirtualDesktop())
     978            /* Compose complex available region */
     979            for (int i = 0; i < dwt->numScreens(); ++ i)
     980                ar += dwt->availableGeometry (i);
     981        else
     982            /* Get just a simple available rectangle */
     983            ar = dwt->availableGeometry (tlw->pos());
     984
    976985        fr = VBoxGlobal::normalizeGeometry (
    977986            fr, ar, mode != VBoxDefs::SDLMode /* canResize */);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r16096 r16176  
    793793            max = str.section (',', 4, 4) == VBoxDefs::GUI_LastWindowPosition_Max;
    794794
    795         QRect ar = QApplication::desktop()->availableGeometry (QPoint (x, y));
    796         if (ok)
    797         {
    798             /* Do some position checks */
    799             if (x < ar.left() || x > ar.right())
    800                 x = ar.left();
    801             if (y < ar.top() || y > ar.bottom())
    802                 y = ar.top();
    803 
     795        QRect ar = ok ? QApplication::desktop()->availableGeometry (QPoint (x, y)) :
     796                        QApplication::desktop()->availableGeometry (this);
     797
     798        if (ok /* previous parameters were read correctly */)
     799        {
    804800            mNormalGeo = QRect (x, y, w, h);
    805801            setGeometry (mNormalGeo);
     
    807803            /* Normalize to the optimal size */
    808804            console->normalizeGeometry (true /* adjustPosition */);
     805
     806            if (max)
     807            {
     808                /* Maximize if needed */
     809                setWindowState (windowState() | Qt::WindowMaximized);
     810                was_max = max;
     811            }
    809812        }
    810813        else
     
    819822        }
    820823
    821         /* Maximize if needed */
    822         if (max)
    823             setWindowState (windowState() | Qt::WindowMaximized);
    824         was_max = max;
    825824        show();
    826825
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r16087 r16176  
    4848#include <QThread>
    4949#include <QPainter>
     50
     51#include <math.h>
    5052
    5153#ifdef Q_WS_X11
     
    38153817
    38163818/**
    3817  *  Ensures that the given rectangle \a aRect is fully contained within the
    3818  *  rectangle \a aBoundRect by moving \a aRect if necessary. If \a aRect is
    3819  *  larger than \a aBoundRect, its top left corner is simply aligned with the
    3820  *  top left corner of \a aRect and, if \a aCanResize is true, \a aRect is
    3821  *  shrinked to become fully visible.
     3819 *  Performs direct and flipped search of position for \a aRectangle to make sure
     3820 *  it is fully contained inside \a aBoundRegion region by moving & resizing
     3821 *  \a aRectangle if necessary. Selects the minimum shifted result between direct
     3822 *  and flipped variants.
    38223823 */
    38233824/* static */
    3824 QRect VBoxGlobal::normalizeGeometry (const QRect &aRect, const QRect &aBoundRect,
     3825QRect VBoxGlobal::normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,
    38253826                                     bool aCanResize /* = true */)
    38263827{
    3827     QRect fr = aRect;
    3828 
    3829     /* make the bottom right corner visible */
    3830     int rd = aBoundRect.right() - fr.right();
    3831     int bd = aBoundRect.bottom() - fr.bottom();
    3832     fr.translate (rd < 0 ? rd : 0, bd < 0 ? bd : 0);
    3833 
    3834     /* ensure the top left corner is visible */
    3835     int ld = fr.left() - aBoundRect.left();
    3836     int td = fr.top() - aBoundRect.top();
    3837     fr.translate (ld < 0 ? -ld : 0, td < 0 ? -td : 0);
    3838 
    3839     if (aCanResize)
    3840     {
    3841         /* adjust the size to make the rectangle fully contained */
    3842         rd = aBoundRect.right() - fr.right();
    3843         bd = aBoundRect.bottom() - fr.bottom();
    3844         if (rd < 0)
    3845             fr.setRight (fr.right() + rd);
    3846         if (bd < 0)
    3847             fr.setBottom (fr.bottom() + bd);
    3848     }
    3849 
    3850     return fr;
     3828    /* Direct search for normalized rectangle */
     3829    QRect var1 (getNormalized (aRectangle, aBoundRegion, aCanResize));
     3830
     3831    /* Flipped search for normalized rectangle */
     3832    QRect var2 (flip (getNormalized (flip (aRectangle).boundingRect(),
     3833                                     flip (aBoundRegion), aCanResize)).boundingRect());
     3834
     3835    /* Calculate shift from starting position for both variants */
     3836    double length1 = sqrt (pow (var1.x() - aRectangle.x(), 2) +
     3837                           pow (var1.y() - aRectangle.y(), 2));
     3838    double length2 = sqrt (pow (var2.x() - aRectangle.x(), 2) +
     3839                           pow (var2.y() - aRectangle.y(), 2));
     3840
     3841    /* Return minimum shifted variant */
     3842    return length1 > length2 ? var2 : var1;
     3843}
     3844
     3845/**
     3846 *  Ensures that the given rectangle \a aRectangle is fully contained within the
     3847 *  region \a aBoundRegion by moving \a aRectangle if necessary. If \a aRectangle is
     3848 *  larger than \a aBoundRegion, top left corner of \a aRectangle is aligned with the
     3849 *  top left corner of maximum available rectangle and, if \a aCanResize is true,
     3850 *  \a aRectangle is shrinked to become fully visible.
     3851 */
     3852/* static */
     3853QRect VBoxGlobal::getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,
     3854                                 bool aCanResize /* = true */)
     3855{
     3856    /* Storing available horizontal sub-rectangles & vertical shifts */
     3857    int windowVertical = aRectangle.center().y();
     3858    QVector <QRect> rectanglesVector (aBoundRegion.rects());
     3859    QList <QRect> rectanglesList;
     3860    QList <int> shiftsList;
     3861    foreach (QRect currentItem, rectanglesVector)
     3862    {
     3863        int currentDelta = qAbs (windowVertical - currentItem.center().y());
     3864        int shift2Top = currentItem.top() - aRectangle.top();
     3865        int shift2Bot = currentItem.bottom() - aRectangle.bottom();
     3866
     3867        int itemPosition = 0;
     3868        foreach (QRect item, rectanglesList)
     3869        {
     3870            int delta = qAbs (windowVertical - item.center().y());
     3871            if (delta > currentDelta) break; else ++ itemPosition;
     3872        }
     3873        rectanglesList.insert (itemPosition, currentItem);
     3874
     3875        int shift2TopPos = 0;
     3876        foreach (int shift, shiftsList)
     3877            if (qAbs (shift) > qAbs (shift2Top)) break; else ++ shift2TopPos;
     3878        shiftsList.insert (shift2TopPos, shift2Top);
     3879
     3880        int shift2BotPos = 0;
     3881        foreach (int shift, shiftsList)
     3882            if (qAbs (shift) > qAbs (shift2Bot)) break; else ++ shift2BotPos;
     3883        shiftsList.insert (shift2BotPos, shift2Bot);
     3884    }
     3885
     3886    /* Trying to find the appropriate place for window */
     3887    QRect result;
     3888    for (int i = -1; i < shiftsList.size(); ++ i)
     3889    {
     3890        /* Move to appropriate vertical */
     3891        QRect rectangle (aRectangle);
     3892        if (i >= 0) rectangle.translate (0, shiftsList [i]);
     3893
     3894        /* Search horizontal shift */
     3895        int maxShift = 0;
     3896        foreach (QRect item, rectanglesList)
     3897        {
     3898            QRect trectangle (rectangle.translated (item.left() - rectangle.left(), 0));
     3899            if (!item.intersects (trectangle))
     3900                continue;
     3901
     3902            if (rectangle.left() < item.left())
     3903            {
     3904                int shift = item.left() - rectangle.left();
     3905                maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;
     3906            }
     3907            else if (rectangle.right() > item.right())
     3908            {
     3909                int shift = item.right() - rectangle.right();
     3910                maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;
     3911            }
     3912        }
     3913
     3914        /* Shift across the horizontal direction */
     3915        rectangle.translate (maxShift, 0);
     3916
     3917        /* Check the translated rectangle to feat the rules */
     3918        if (aBoundRegion.united (rectangle) == aBoundRegion)
     3919            result = rectangle;
     3920
     3921        if (!result.isNull()) break;
     3922    }
     3923
     3924    if (result.isNull())
     3925    {
     3926        /* Resize window to feat desirable size
     3927         * using max of available rectangles */
     3928        QRect maxRectangle;
     3929        quint64 maxSquare = 0;
     3930        foreach (QRect item, rectanglesList)
     3931        {
     3932            quint64 square = item.width() * item.height();
     3933            if (square > maxSquare)
     3934            {
     3935                maxSquare = square;
     3936                maxRectangle = item;
     3937            }
     3938        }
     3939
     3940        result = aRectangle;
     3941        result.moveTo (maxRectangle.x(), maxRectangle.y());
     3942        if (maxRectangle.right() < result.right())
     3943            result.setRight (maxRectangle.right());
     3944        if (maxRectangle.bottom() < result.bottom())
     3945            result.setBottom (maxRectangle.bottom());
     3946    }
     3947
     3948    return result;
     3949}
     3950
     3951/**
     3952 *  Returns the flipped (transposed) region.
     3953 */
     3954/* static */
     3955QRegion VBoxGlobal::flip (const QRegion &aRegion)
     3956{
     3957    QRegion result;
     3958    QVector <QRect> rectangles (aRegion.rects());
     3959    foreach (QRect rectangle, rectangles)
     3960        result += QRect (rectangle.y(), rectangle.x(),
     3961                         rectangle.height(), rectangle.width());
     3962    return result;
    38513963}
    38523964
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