VirtualBox

Changeset 101107 in vbox


Ignore:
Timestamp:
Sep 13, 2023 2:01:58 PM (15 months ago)
Author:
vboxsync
Message:

VBoxDbg: Rewrote the automatic window positioning to make it more flexible and to try keep the console window wide enough for at least 80 columns of text.

Location:
trunk/src/VBox/Debugger
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/VBoxDbgBase.cpp

    r101093 r101107  
    186186VBoxDbgBaseWindow::VBoxDbgBaseWindow(VBoxDbgGui *a_pDbgGui, QWidget *a_pParent, const char *a_pszTitle)
    187187    : QWidget(a_pParent, Qt::Window), VBoxDbgBase(a_pDbgGui), m_pszTitle(a_pszTitle), m_fPolished(false)
    188     , m_x(INT_MAX), m_y(INT_MAX), m_cx(0), m_cy(0)
     188    , m_x(INT_MAX), m_y(INT_MAX), m_cx(0), m_cy(0), m_cxMinHint(0), m_enmAttraction(VBoxDbgBaseWindow::kAttractionVmNone)
    189189{
    190190    /* Set the title, using the parent one as prefix when possible: */
     
    237237            m_cy = a_cy;
    238238
    239             QSize BorderSize = frameSize() - size();
    240             if (BorderSize == QSize(0,0))
    241                 BorderSize = vGuessBorderSizes();
    242 
     239            QSize const BorderSize = vGetBorderSize();
    243240            resize(a_cx - BorderSize.width(), a_cy - BorderSize.height());
    244241        }
     
    248245        move(a_x, a_y);
    249246    }
     247}
     248
     249
     250QSize
     251VBoxDbgBaseWindow::vGetBorderSize()
     252{
     253    QSize BorderSize = frameSize() - size();
     254
     255#ifdef Q_WS_X11 /* (from the qt gui) */
     256    /*
     257     * On X11, there is no way to determine frame geometry (including WM
     258     * decorations) before the widget is shown for the first time.  Stupidly
     259     * enumerate other top level widgets to find the thickest frame.
     260     */
     261    if (BorderSize == QSize(0, 0))
     262    {
     263        if (!m_cxBorder && !m_cyBorder) /* (only till we're successful) */
     264        {
     265            int cxExtra = 0;
     266            int cyExtra = 0;
     267
     268            QWidgetList WidgetList = QApplication::topLevelWidgets();
     269            for (QListIterator<QWidget *> it(WidgetList); it.hasNext(); )
     270            {
     271                QWidget *pCurWidget = it.next();
     272                if (pCurWidget->isVisible())
     273                {
     274                    int const cxFrame = pCurWidget->frameGeometry().width()  - pCurWidget->width();
     275                    cxExtra = qMax(cxExtra, cxFrame);
     276                    int const cyFrame = pCurWidget->frameGeometry().height() - pCurWidget->height();
     277                    cyExtra = qMax(cyExtra, cyFrame);
     278                    if (cyExtra && cxExtra)
     279                        break;
     280                }
     281            }
     282
     283            if (cxExtra || cyExtra)
     284            {
     285                m_cxBorder = cxExtra;
     286                m_cyBorder = cyExtra;
     287            }
     288        }
     289        BorderSize.setWidth(m_cxBorder);
     290        BorderSize.setHeight(m_cyBorder);
     291    }
     292#endif /* X11 */
     293
     294    return BorderSize;
    250295}
    251296
     
    283328        return;
    284329
    285     QSize BorderSize = frameSize() - size();
    286     if (BorderSize != QSize(0,0))
     330    if (!m_fPolished && VBoxDbgBaseWindow::vGetBorderSize() != QSize(0,0))
    287331        m_fPolished = true;
    288332
     
    290334}
    291335
    292 
    293 QSize
    294 VBoxDbgBaseWindow::vGuessBorderSizes()
    295 {
    296 #ifdef Q_WS_X11 /* (from the qt gui) */
    297     /*
    298      * On X11, there is no way to determine frame geometry (including WM
    299      * decorations) before the widget is shown for the first time.  Stupidly
    300      * enumerate other top level widgets to find the thickest frame.
    301      */
    302     if (!m_cxBorder && !m_cyBorder) /* (only till we're successful) */
    303     {
    304         int cxExtra = 0;
    305         int cyExtra = 0;
    306 
    307         QWidgetList WidgetList = QApplication::topLevelWidgets();
    308         for (QListIterator<QWidget *> it(WidgetList); it.hasNext(); )
    309         {
    310             QWidget *pCurWidget = it.next();
    311             if (pCurWidget->isVisible())
    312             {
    313                 int const cxFrame = pCurWidget->frameGeometry().width()  - pCurWidget->width();
    314                 cxExtra = qMax(cxExtra, cxFrame);
    315                 int const cyFrame = pCurWidget->frameGeometry().height() - pCurWidget->height();
    316                 cyExtra = qMax(cyExtra, cyFrame);
    317                 if (cyExtra && cxExtra)
    318                     break;
    319             }
    320         }
    321 
    322         if (cxExtra || cyExtra)
    323         {
    324             m_cxBorder = cxExtra;
    325             m_cyBorder = cyExtra;
    326         }
    327     }
    328 #endif /* X11 */
    329     return QSize(m_cxBorder, m_cyBorder);
    330 }
    331 
  • trunk/src/VBox/Debugger/VBoxDbgBase.h

    r98103 r101107  
    172172    void vReposition(int a_x, int a_y, unsigned a_cx, unsigned a_cy, bool a_fResize);
    173173
     174    /**
     175     * Gets the minimum client area width hint.
     176     */
     177    unsigned vGetMinWidthHint(void) const RT_NOEXCEPT
     178    {
     179        return m_cxMinHint;
     180    }
     181
     182protected:
     183    /**
     184     * Sets the minimum client area width hint (without frame).
     185     */
     186    void vSetMinWidthHint(unsigned a_cxMin)
     187    {
     188        m_cxMinHint = a_cxMin;
     189    }
     190
     191
     192public:
     193    /** VM window magnetic attraction. */
     194    typedef enum
     195    { kAttractionVmLeft, kAttractionVmRight, kAttractionVmTop, kAttractionVmBottom, kAttractionVmNone } VBoxDbgAttractionType;
     196
     197    /**
     198     * Gets the window attraction.
     199     */
     200    VBoxDbgAttractionType vGetWindowAttraction(void) const RT_NOEXCEPT
     201    {
     202        return m_enmAttraction;
     203    }
     204
     205    /**
     206     * Sets the window attraction.
     207     */
     208    void vSetWindowAttraction(VBoxDbgAttractionType a_enmAttraction) RT_NOEXCEPT
     209    {
     210        m_enmAttraction = a_enmAttraction;
     211    }
     212
     213    /**
     214     * Get the border size for the window.
     215     *
     216     * This may return different values after the window has been shown,
     217     * at least on X11.
     218     */
     219    QSize vGetBorderSize();
     220
    174221protected:
    175222    /**
     
    193240     */
    194241    void vPolishSizeAndPos();
    195 
    196     /**
    197      * Internal worker that guesses the border sizes.
    198      */
    199     QSize vGuessBorderSizes();
    200242
    201243private:
     
    212254    /** The desired height. */
    213255    unsigned m_cy;
     256    /** Minimum client area width hint (for the console window, etc). */
     257    unsigned m_cxMinHint;
     258    /** The window attraction. */
     259    VBoxDbgAttractionType m_enmAttraction;
    214260
    215261    /** Best effort x border size (for X11). */
  • trunk/src/VBox/Debugger/VBoxDbgConsole.cpp

    r99835 r101107  
    4242#include <QContextMenuEvent>
    4343#include <QMenu>
     44#include <QScrollBar>
    4445
    4546#include <VBox/dbg.h>
     
    508509    m_pOutput = new VBoxDbgConsoleOutput(this, a_pVirtualBox);
    509510
    510     /* try figure a suitable size */
    511     QLabel *pLabel = new QLabel(      "11111111111111111111111111111111111111111111111111111111111111111111111111111112222222222", this);
     511    /* try figure a suitable size and tell the parent class. */
     512    QLabel *pLabel = new QLabel("8888888888888888888888888888888888888888888888888888888888888888888888888888888", this);
    512513    pLabel->setFont(m_pOutput->font());
    513514    QSize Size = pLabel->sizeHint();
    514515    delete pLabel;
    515     Size.setWidth((int)(Size.width() * 1.10));
    516     Size.setHeight(Size.width() / 2);
    517     resize(Size);
     516    QSize SizeScrollBar(0,0);
     517    QScrollBar *pScrollBar = m_pOutput->verticalScrollBar();
     518    if (pScrollBar)
     519        SizeScrollBar = pScrollBar->sizeHint();
     520    vSetMinWidthHint(Size.width() + SizeScrollBar.width() + 1);
    518521
    519522    /*
  • trunk/src/VBox/Debugger/VBoxDbgGui.cpp

    r101094 r101107  
    191191                                       2, m_pParent);
    192192        connect(m_pDbgStats, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
    193         repositionStatistics();
     193        repositionWindowInitial(m_pDbgStats, "DbgStats", VBoxDbgBaseWindow::kAttractionVmRight);
    194194    }
    195195
    196196    m_pDbgStats->vShow();
    197197    return VINF_SUCCESS;
    198 }
    199 
    200 
    201 void
    202 VBoxDbgGui::repositionStatistics(bool fResize/* = true*/)
    203 {
    204     /*
    205      * Move it to the right side of the VBox console,
    206      * and resize it to cover all the space to the left side of the desktop.
    207      */
    208     if (m_pDbgStats)
    209         m_pDbgStats->vReposition(m_x + m_cx, m_y,
    210                                  m_cxDesktop - m_cx - m_x + m_xDesktop, m_cyDesktop - m_y + m_yDesktop,
    211                                  fResize);
    212198}
    213199
     
    222208        m_pDbgConsole = new VBoxDbgConsole(this, m_pParent, pVirtualBox);
    223209        connect(m_pDbgConsole, SIGNAL(destroyed(QObject *)), this, SLOT(notifyChildDestroyed(QObject *)));
    224         repositionConsole();
     210        repositionWindowInitial(m_pDbgConsole, "DbgConsole", VBoxDbgBaseWindow::kAttractionVmBottom);
    225211    }
    226212
    227213    m_pDbgConsole->vShow();
    228214    return VINF_SUCCESS;
    229 }
    230 
    231 
    232 void
    233 VBoxDbgGui::repositionConsole(bool fResize/* = true*/)
    234 {
    235     /*
    236      * Move it to the bottom of the VBox console,
    237      * and resize it to cover the space down to the bottom of the desktop.
    238      */
    239     if (m_pDbgConsole)
    240         m_pDbgConsole->vReposition(m_x, m_y + m_cy,
    241                                    RT_MAX(m_cx, 32), m_cyDesktop - m_cy - m_y + m_yDesktop,
    242                                    fResize);
    243215}
    244216
     
    265237
    266238void
     239VBoxDbgGui::repositionWindow(VBoxDbgBaseWindow *a_pWindow, bool a_fResize /*=true*/)
     240{
     241    if (a_pWindow)
     242    {
     243        VBoxDbgBaseWindow::VBoxDbgAttractionType const enmAttraction = a_pWindow->vGetWindowAttraction();
     244        QSize const     BorderSize = a_pWindow->vGetBorderSize();
     245        unsigned const  cxMinHint  = RT_MAX(32, a_pWindow->vGetMinWidthHint()) + BorderSize.width();
     246        int             x,  y;
     247        unsigned        cx, cy;
     248        /** @todo take the x,y screen into account rather than the one of the VM
     249         *        window. also generally consider adjacent screens. */
     250        switch (enmAttraction)
     251        {
     252            case VBoxDbgBaseWindow::kAttractionVmRight:
     253                x  = m_x + m_cx;
     254                y  = m_y;
     255                cx = m_cxDesktop - m_cx - m_x + m_xDesktop;
     256                if (cx > m_cxDesktop || cx < cxMinHint)
     257                    cx = cxMinHint;
     258                cy = m_cyDesktop - m_y + m_yDesktop;
     259                break;
     260
     261            case VBoxDbgBaseWindow::kAttractionVmBottom:
     262                x  = m_x;
     263                y  = m_y + m_cy;
     264                cx = m_cx;
     265                if (cx < cxMinHint)
     266                {
     267                    if (cxMinHint - cx <= unsigned(m_x - m_xDesktop)) /* move it to the left if we have sufficient room. */
     268                        x -= cxMinHint - cx;
     269                    else
     270                        x = m_xDesktop;
     271                    cx = cxMinHint;
     272                }
     273                cy = m_cyDesktop - m_cy - m_y + m_yDesktop;
     274                break;
     275
     276            /** @todo implement the other placements when they become selectable. */
     277
     278            default:
     279                return;
     280        }
     281
     282        a_pWindow->vReposition(x, y, cx, cy, a_fResize);
     283    }
     284}
     285
     286
     287void
     288VBoxDbgGui::repositionWindowInitial(VBoxDbgBaseWindow *a_pWindow, const char *a_pszSettings,
     289                                    VBoxDbgBaseWindow::VBoxDbgAttractionType a_enmDefaultAttraction)
     290{
     291    a_pWindow->vSetWindowAttraction(a_enmDefaultAttraction);
     292
     293    /** @todo save/restore the attachment type. */
     294    RT_NOREF(a_pszSettings);
     295
     296    repositionWindow(a_pWindow, true /*fResize*/);
     297}
     298
     299
     300void
    267301VBoxDbgGui::adjustRelativePos(int x, int y, unsigned cx, unsigned cy)
    268302{
    269303    /* Disregard a width less than 640 since it will mess up the console,
    270        but only if previous width was already initialized.. */
     304       but only if previous width was already initialized. */
    271305    if (cx < 640 && m_cx > 0)
    272306        cx = m_cx;
     
    282316    if (fMoved)
    283317        updateDesktopSize();
    284     repositionConsole(fResize);
    285     repositionStatistics(fResize);
     318    repositionWindow(m_pDbgConsole, fResize);
     319    repositionWindow(m_pDbgStats, fResize);
    286320}
    287321
  • trunk/src/VBox/Debugger/VBoxDbgGui.h

    r98103 r101107  
    109109
    110110    /**
    111      * Repositions and resizes (optionally) the statistics to its defaults
    112      *
    113      * @param   fResize     If set (default) the size of window is also changed.
    114      */
    115     void repositionStatistics(bool fResize = true);
    116 
    117     /**
    118111     * Show the console window (aka. command line), creating it if necessary.
    119112     *
     
    121114     */
    122115    int showConsole();
    123 
    124     /**
    125      * Repositions and resizes (optionally) the console to its defaults
    126      *
    127      * @param   fResize     If set (default) the size of window is also changed.
    128      */
    129     void repositionConsole(bool fResize = true);
    130116
    131117    /**
     
    134120     */
    135121    void updateDesktopSize();
     122
     123    /**
     124     * Repositions and maybe resizes a window according to the VM window.
     125     *
     126     * @param   a_pWindow   The window.  Ignored if NULL.
     127     * @param   a_fResize   If set (default) the size of window is also changed.
     128     */
     129    void repositionWindow(VBoxDbgBaseWindow *a_pWindow, bool a_fResize = true);
     130
     131    /**
     132     * Does the initial repositioning and sizing of a window.
     133     *
     134     * This may get preferences from extra data.
     135     *
     136     * @param   a_pWindow               The window.
     137     * @param   a_pszSettings           The 'section' name in the settings.
     138     * @param   a_enmDefaultAttraction  The default attraction of the window.
     139     */
     140    void repositionWindowInitial(VBoxDbgBaseWindow *a_pWindow, const char *a_pszSettings,
     141                                 VBoxDbgBaseWindow::VBoxDbgAttractionType a_enmDefaultAttraction);
    136142
    137143    /**
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