VirtualBox

Changeset 2357 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 26, 2007 4:37:53 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
20750
Message:

1764: Better default size in "Create VDI" wizard when called from "Create VM" wizard.

These changes related both to NewVM and NewHD wizards.

  1. Labels sizeHint calculation based on minimum QLabel width. In case of there is no minimum QLabel width predefined – sizeHint calculation leads to wrong dialog height (dialog could be very tall).
  2. Own QTextEdit implementation with sizeHint based on contained text.
  3. The color of the dialog’s picture background is set to the color of the picture’s last pixel. So it is possible to vertically resize dialog & picture simultaneously.
Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited

Legend:

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

    r2354 r2357  
    3636#include <qpopupmenu.h>
    3737#include <qtooltip.h>
     38#include <qtextedit.h>
    3839
    3940#include <qptrvector.h>
     
    4445
    4546class QAction;
     47class QLabel;
    4648
    4749// Auxiliary types
     
    132134    const QUuid machineId;
    133135    const QUuid snapshotId;
     136};
     137
     138class VBoxTextView : public QTextEdit
     139{
     140Q_OBJECT
     141
     142public:
     143
     144    VBoxTextView (QWidget*);
     145
     146    QSize sizeHint() const;
     147    QSize minimumSizeHint() const;
     148
     149public slots:
     150
     151    void setText (const QString &);
    134152};
    135153
     
    387405
    388406    /* public static stuff */
     407
     408    static void fillPixmapBackGrd (QLabel *);
    389409
    390410    static QString languageId();
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r2354 r2357  
    3434#include <qwidgetlist.h>
    3535#include <qfiledialog.h>
     36#include <qimage.h>
     37#include <qlabel.h>
    3638
    3739#include <qfileinfo.h>
     
    470472
    471473#endif /* Q_WS_WIN */
     474
     475VBoxTextView::VBoxTextView (QWidget *aParent)
     476    : QTextEdit (aParent)
     477{
     478}
     479
     480QSize VBoxTextView::sizeHint() const
     481{
     482    return minimumSizeHint();
     483}
     484
     485QSize VBoxTextView::minimumSizeHint() const
     486{
     487    int wid = 0;
     488    int hei = heightForWidth (wid);
     489    return QSize (wid, hei);
     490}
     491
     492void VBoxTextView::setText (const QString &aText)
     493{
     494    QTextEdit::setText (aText);
     495}
    472496
    473497// VBoxGlobal
     
    18511875};
    18521876
     1877/**
     1878 *  Fills the QLabel picture background with the color of last
     1879 *  pixel in the pixmap.
     1880 */
     1881/* static */
     1882void VBoxGlobal::fillPixmapBackGrd (QLabel *aLabel)
     1883{
     1884    QPixmap *pix = aLabel->pixmap();
     1885    QImage img = pix->convertToImage();
     1886    QRgb rgbPixel = img.pixel (img.width() - 1, img.height() - 1);
     1887    int cRed = qRed (rgbPixel);
     1888    int cGreen = qGreen (rgbPixel);
     1889    int cBlue = qBlue (rgbPixel);
     1890    aLabel->setBackgroundColor (QColor (cRed, cGreen, cBlue));
     1891    aLabel->setFrameShadow (QFrame::Plain);
     1892    aLabel->setFrameShape (QFrame::Box);
     1893    aLabel->setPaletteForegroundColor (QColor (89,121,150));
     1894}
     1895
    18531896static VBoxTranslator *sTranslator = 0;
    18541897static QString sLoadedLangId = gVBoxBuiltInLangName;
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewHDWzd.ui

    r2326 r2357  
    124124                        </property>
    125125                    </spacer>
     126                    <spacer>
     127                        <property name="name">
     128                            <cstring>widthSpacer</cstring>
     129                        </property>
     130                        <property name="orientation">
     131                            <enum>Horizontal</enum>
     132                        </property>
     133                        <property name="sizeType">
     134                            <enum>MinimumExpanding</enum>
     135                        </property>
     136                        <property name="sizeHint">
     137                            <size>
     138                                <width>400</width>
     139                                <height>1</height>
     140                            </size>
     141                        </property>
     142                    </spacer>
    126143                </vbox>
    127144            </widget>
     
    591608            <widget class="QLayoutWidget">
    592609                <property name="name">
    593                     <cstring>layout15</cstring>
     610                    <cstring>summaryLayout</cstring>
    594611                </property>
    595612                <vbox>
     
    617634                        <property name="alignment">
    618635                            <set>WordBreak|AlignTop</set>
    619                         </property>
    620                     </widget>
    621                     <widget class="QTextEdit">
    622                         <property name="name">
    623                             <cstring>teSummary</cstring>
    624                         </property>
    625                         <property name="sizePolicy">
    626                             <sizepolicy>
    627                                 <hsizetype>7</hsizetype>
    628                                 <vsizetype>5</vsizetype>
    629                                 <horstretch>0</horstretch>
    630                                 <verstretch>0</verstretch>
    631                             </sizepolicy>
    632                         </property>
    633                         <property name="frameShape">
    634                             <enum>NoFrame</enum>
    635                         </property>
    636                         <property name="wordWrap">
    637                             <enum>NoWrap</enum>
    638                         </property>
    639                         <property name="readOnly">
    640                             <bool>true</bool>
    641636                        </property>
    642637                    </widget>
     
    720715    <include location="global" impldecl="in implementation">qlocale.h</include>
    721716</includes>
     717<forwards>
     718    <forward>class VBoxTextView</forward>
     719</forwards>
    722720<variables>
    723721    <variable access="private">QIWidgetValidator *wvalNameAndSize;</variable>
     
    726724    <variable access="private">Q_UINT64 maxVDISize;</variable>
    727725    <variable access="private">Q_UINT64 currentSize;</variable>
     726    <variable access="private">VBoxTextView *teSummary;</variable>
    728727</variables>
    729728<slots>
     
    736735<functions>
    737736    <function access="private">init()</function>
     737    <function access="private">showEvent( QShowEvent * )</function>
    738738    <function>setRecommendedFileName( const QString &amp; aName )</function>
    739739    <function>setRecommendedSize( Q_UINT64 aSize )</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewHDWzd.ui.h

    r958 r2357  
    169169     * ---------------------------------------------------------------------- */
    170170
     171    /* setup the pictures background color */
     172    VBoxGlobal::fillPixmapBackGrd (pmWelcome);
     173    VBoxGlobal::fillPixmapBackGrd (pmType);
     174    VBoxGlobal::fillPixmapBackGrd (pmNameAndSize);
     175    VBoxGlobal::fillPixmapBackGrd (pmSummary);
     176
    171177    /* Image type page */
    172178
     
    210216    /* Summary page */
    211217
     218    teSummary = new VBoxTextView (pageSummary);
     219    teSummary->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
     220    teSummary->setFrameShape (QTextEdit::NoFrame);
     221    teSummary->setReadOnly (TRUE);
     222    summaryLayout->insertWidget (1, teSummary);
     223
    212224    /* filter out Enter keys in order to direct them to the default dlg button */
    213225    QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
     
    251263    /* the finish button on the Summary page is always enabled */
    252264    setFinishEnabled (pageSummary, true);
     265
     266    /* setup minimum width for the sizeHint to be calculated correctly */
     267    int wid = widthSpacer->minimumSize().width();
     268    txWelcome->setMinimumWidth (wid);
     269    textLabel1_2->setMinimumWidth (wid);
     270    txNameComment->setMinimumWidth (wid);
     271    txSizeComment->setMinimumWidth (wid);
     272    txSummaryHdr->setMinimumWidth (wid);
     273    txSummaryFtr->setMinimumWidth (wid);
     274}
     275
     276
     277void VBoxNewHDWzd::showEvent (QShowEvent *e)
     278{
     279    QDialog::showEvent (e);
     280
     281    /* one may think that QWidget::polish() is the right place to do things
     282     * below, but apparently, by the time when QWidget::polish() is called,
     283     * the widget style & layout are not fully done, at least the minimum
     284     * size hint is not properly calculated. Since this is sometimes necessary,
     285     * we provide our own "polish" implementation. */
     286
     287    layout()->activate();
     288
     289    /* resize to the miminum possible size */
     290    resize (minimumSize());
     291
     292    VBoxGlobal::centerWidget (this, parentWidget());
    253293}
    254294
     
    398438        teSummary->setFocus();
    399439    }
     440
     441    page->layout()->activate();
    400442}
    401443
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui

    r382 r2357  
    125125                    <spacer>
    126126                        <property name="name">
    127                             <cstring>spacer67</cstring>
     127                            <cstring>widthSpacer</cstring>
    128128                        </property>
    129129                        <property name="orientation">
     
    909909            <widget class="QLayoutWidget">
    910910                <property name="name">
    911                     <cstring>layout37</cstring>
     911                    <cstring>summaryLayout</cstring>
    912912                </property>
    913913                <vbox>
     
    940940                        <property name="alignment">
    941941                            <set>WordBreak|AlignTop</set>
    942                         </property>
    943                     </widget>
    944                     <widget class="QTextEdit">
    945                         <property name="name">
    946                             <cstring>teSummary</cstring>
    947                         </property>
    948                         <property name="sizePolicy">
    949                             <sizepolicy>
    950                                 <hsizetype>7</hsizetype>
    951                                 <vsizetype>5</vsizetype>
    952                                 <horstretch>0</horstretch>
    953                                 <verstretch>0</verstretch>
    954                             </sizepolicy>
    955                         </property>
    956                         <property name="frameShape">
    957                             <enum>NoFrame</enum>
    958                         </property>
    959                         <property name="readOnly">
    960                             <bool>true</bool>
    961942                        </property>
    962943                    </widget>
     
    10651046<forwards>
    10661047    <forward>class VBoxMediaComboBox</forward>
     1048    <forward>class VBoxTextView</forward>
    10671049</forwards>
    10681050<variables>
     
    10741056    <variable access="private">CMachine cmachine;</variable>
    10751057    <variable access="private">VBoxMediaComboBox *mediaCombo;</variable>
     1058    <variable access="private">VBoxTextView *teSummary;</variable>
    10761059</variables>
    10771060<slots>
     
    10881071    <function access="private">init()</function>
    10891072    <function access="private">destroy()</function>
     1073    <function access="private">showEvent( QShowEvent * )</function>
    10901074    <function>showPage( QWidget * page )</function>
    10911075    <function>accept()</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxNewVMWzd.ui.h

    r868 r2357  
    7171     */
    7272
     73    /* setup the pictures colors */
     74    VBoxGlobal::fillPixmapBackGrd (pmWelcome);
     75    VBoxGlobal::fillPixmapBackGrd (pmNameAndOS);
     76    VBoxGlobal::fillPixmapBackGrd (pmMemory);
     77    VBoxGlobal::fillPixmapBackGrd (pmHDD);
     78    VBoxGlobal::fillPixmapBackGrd (pmSummary);
     79
    7380    /* Name and OS page */
    7481
     
    8996
    9097    leRAM->setValidator (new QIntValidator (MinRAM, MaxRAM, this));
    91 
    92     /* filter out Enter keys in order to direct them to the default dlg button */
    93     QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
    94     ef->watchOn (teSummary);
    9598
    9699    wvalMemory = new QIWidgetValidator (pageMemory, this);
     
    117120             this, SLOT (revalidate (QIWidgetValidator *)));
    118121
     122    /* Summary page */
     123
     124    teSummary = new VBoxTextView (pageSummary);
     125    teSummary->setSizePolicy (QSizePolicy::Minimum, QSizePolicy::Minimum);
     126    teSummary->setFrameShape (QTextEdit::NoFrame);
     127    teSummary->setReadOnly (TRUE);
     128    summaryLayout->insertWidget (1, teSummary);
     129
     130    /* filter out Enter keys in order to direct them to the default dlg button */
     131    QIKeyFilter *ef = new QIKeyFilter (this, Key_Enter);
     132    ef->watchOn (teSummary);
     133
    119134    /*
    120135     *  set initial values
     
    164179    /* the finish button on the Summary page is always enabled */
    165180    setFinishEnabled (pageSummary, true);
    166  
    167     resize (sizeHint());
     181
     182    /* setup minimum width for the sizeHint to be calculated correctly */
     183    int wid = widthSpacer->minimumSize().width();
     184    txWelcome->setMinimumWidth (wid);
     185    txNameAndOS->setMinimumWidth (wid);
     186    textLabel1->setMinimumWidth (wid);
     187    txRAMBest2->setMinimumWidth (wid);
     188    textLabel1_3->setMinimumWidth (wid);
     189    txVDIBest->setMinimumWidth (wid);
     190    txSummaryHdr->setMinimumWidth (wid);
     191    txSummaryFtr->setMinimumWidth (wid);
    168192}
    169193
     
    172196{
    173197    ensureNewHardDiskDeleted();
     198}
     199
     200void VBoxNewVMWzd::showEvent (QShowEvent *e)
     201{
     202    QDialog::showEvent (e);
     203
     204    /* one may think that QWidget::polish() is the right place to do things
     205     * below, but apparently, by the time when QWidget::polish() is called,
     206     * the widget style & layout are not fully done, at least the minimum
     207     * size hint is not properly calculated. Since this is sometimes necessary,
     208     * we provide our own "polish" implementation. */
     209
     210    layout()->activate();
     211
     212    /* resize to the miminum possible size */
     213    resize (minimumSize());
     214
     215    VBoxGlobal::centerWidget (this, parentWidget());
    174216}
    175217
     
    244286    else if (page == pageSummary)
    245287        teSummary->setFocus();
     288
     289    page->layout()->activate();
    246290}
    247291
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