VirtualBox

Ignore:
Timestamp:
Jul 10, 2008 3:32:33 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: Implemented the Toolbar settings selector. Currently turned on, on the mac only.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialog.h

    r10468 r10474  
    5858    virtual void retranslateUi();
    5959
     60    virtual QString dialogTitle() const = 0;
     61    QString titleExtension() const;
     62
    6063    void setWarning (const QString &aWarning);
    6164
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsDialogSpecific.h

    r10468 r10474  
    5757    void retranslateUi();
    5858
     59    QString dialogTitle() const;
     60
    5961private:
    6062
     
    102104    void retranslateUi();
    103105
     106    QString dialogTitle() const;
     107
    104108private slots:
    105109
     
    111115    void updateAvailability();
    112116    VBoxSettingsPage* attachPage (VBoxSettingsPage *aPage);
    113     QString dialogTitle() const;
    114117
    115118    CMachine mMachine;
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxSettingsSelector.h

    r10468 r10474  
    2828
    2929class QITreeWidget;
     30class VBoxToolBar;
     31class SelectorAction;
    3032
    3133class QTreeWidget;
    3234class QTreeWidgetItem;
    3335class QIcon;
     36class QAction;
     37class QActionGroup;
    3438
    3539class VBoxSettingsSelector: public QObject
     
    5761    virtual void clear() = 0;
    5862
    59     virtual void retranslateUi() = 0;
     63    virtual void polish() {};
     64    virtual int minWidth () const { return 0; }
    6065
    6166signals:
     
    8792    virtual void clear();
    8893
    89     virtual void retranslateUi();
     94    virtual void polish();
    9095
    9196private slots:
     
    103108};
    104109
     110class VBoxSettingsToolBarSelector: public VBoxSettingsSelector
     111{
     112    Q_OBJECT;
     113
     114public:
     115
     116    VBoxSettingsToolBarSelector (QWidget *aParent = NULL);
     117
     118    virtual QWidget *widget() const;
     119
     120    virtual void addItem (const QIcon &aIcon, const QString &aText, int aIndex, const QString &aLink);
     121    virtual QString itemText (int aId) const;
     122
     123    virtual int currentId() const;
     124    virtual int idToIndex (int aId) const;
     125    virtual int indexToId (int aIndex) const;
     126    virtual int linkToId (const QString &aLink) const;
     127    virtual void selectById (int aId);
     128    virtual void setVisibleById (int aId, bool aShow);
     129
     130    virtual void clear();
     131
     132    virtual int minWidth() const;
     133
     134private slots:
     135
     136    void settingsGroupChanged (QAction *aAction);
     137
     138private:
     139
     140    int findId (int aIndex) const;
     141    int findIndex (int aId) const;
     142    int findLink (const QString &aLink) const;
     143    SelectorAction* findAction (int aId) const;
     144
     145    /* Private member vars */
     146    VBoxToolBar *mTbSelector;
     147    QActionGroup *mActionGroup;
     148};
     149
    105150#endif /* __VBoxSettingsSelector_h__ */
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialog.cpp

    r10468 r10474  
    2727#include "QIWidgetValidator.h"
    2828#include "VBoxSettingsSelector.h"
     29#include "VBoxToolBar.h"
    2930
    3031#ifdef Q_WS_MAC
     
    3637#include <QPushButton>
    3738#include <QStackedWidget>
     39
     40
     41#if MAC_LEOPARD_STYLE
     42# define VBOX_GUI_WITH_TOOLBAR_SETTINGS
     43#endif /* MAC_LEOPARD_STYLE */
    3844
    3945VBoxSettingsDialog::VBoxSettingsDialog (QWidget *aParent /* = NULL */)
     
    6167    mLbTitle->setFont (f);
    6268
     69    QGridLayout *mainLayout = static_cast<QGridLayout*> (mAllWidget->layout());
     70#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     71    mSelector = new VBoxSettingsToolBarSelector (this);
     72    setUnifiedTitleAndToolBarOnMac (true);
     73    addToolBar (qobject_cast<QToolBar*> (mSelector->widget()));
     74    /* No title in this mode, we change the title of the window. */
     75    mLbTitle->hide();
     76    mainLayout->setColumnMinimumWidth (0, 0);
     77    mainLayout->setHorizontalSpacing (0);
     78#else
    6379    /* Create the classical tree view selector */
    6480    mSelector = new VBoxSettingsTreeSelector (mAllWidget);
    65     QGridLayout *mainLayout = static_cast<QGridLayout*> (mAllWidget->layout());
    6681    mainLayout->addWidget (mSelector->widget(), 0, 0, 3, 1);
    6782    mSelector->widget()->setFocus();
     83#endif
    6884
    6985    /* Creating stack of pages */
     
    165181}
    166182
     183QString VBoxSettingsDialog::titleExtension() const
     184{
     185#ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     186    return mSelector->itemText (mSelector->currentId());
     187#else
     188    return tr ("Settings");
     189#endif
     190}
     191
    167192void VBoxSettingsDialog::categoryChanged (int aId)
    168193{
    169194//#ifndef Q_WS_MAC
    170195#if 1
    171         mLbTitle->setText (mSelector->itemText (aId));
    172         mStack->setCurrentIndex (aId);
     196# ifdef VBOX_GUI_WITH_TOOLBAR_SETTINGS
     197    setWindowTitle (dialogTitle());
     198# endif
     199    mLbTitle->setText (mSelector->itemText (aId));
     200    mStack->setCurrentIndex (aId);
    173201#else /* Q_WS_MAC */
    174         /* We will update at once later */
    175         setUpdatesEnabled (false);
    176         /* Set all tab size policies to ignored */
    177         for (int i = 0; i < mStack->count(); ++i)
    178             mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored);
    179         /* Set the size policy of the current tab to preferred */
    180         if (mStack->widget (id))
    181             mStack->widget (id)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
    182         /* Set the new current tab */
    183         mLbTitle->setText (::path (aItem));
    184         mStack->setCurrentIndex (id);
    185         /* Activate the new layout */
    186         layout()->activate();
    187         setUpdatesEnabled (true);
    188 //        mAllWidget->hide();
    189         /* Play the resize animation */
    190         ::darwinWindowAnimateResize (this, QRect (x(), y(),
    191                                                   minimumSizeHint().width(), minimumSizeHint().height()));
    192 //        mAllWidget->show();
    193         /* Set the new size to Qt also */
    194         setFixedSize (minimumSizeHint());
     202    int index = mSelector->idToIndex (aId);
     203    /* We will update at once later */
     204    setUpdatesEnabled (false);
     205    /* Set all tab size policies to ignored */
     206    for (int i = 0; i < mStack->count(); ++i)
     207        mStack->widget (i)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Ignored);
     208    /* Set the size policy of the current tab to preferred */
     209    if (mStack->widget (index))
     210        mStack->widget (index)->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Preferred);
     211    /* Set the new current tab */
     212    mLbTitle->setText (::path (aItem));
     213    mStack->setCurrentIndex (index);
     214    /* Activate the new layout */
     215    layout()->activate();
     216    setUpdatesEnabled (true);
     217    //        mAllWidget->hide();
     218    /* Play the resize animation */
     219    ::darwinWindowAnimateResize (this, QRect (x(), y(),
     220                                              minimumSizeHint().width(), minimumSizeHint().height()));
     221    //        mAllWidget->show();
     222    /* Set the new size to Qt also */
     223    setFixedSize (minimumSizeHint());
    195224#endif /* !Q_WS_MAC */
    196225}
     
    303332
    304333    /* Resize to the minimum possible size */
    305     resize (minimumSize());
     334    int minWidth = mSelector->minWidth();
     335    QSize s = minimumSize();
     336    if (minWidth > s.width())
     337        s.setWidth (minWidth);
     338    resize (s);
    306339
    307340    VBoxGlobal::centerWidget (this, parentWidget());
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsDialogSpecific.cpp

    r10468 r10474  
    5555#endif /* Q_WS_MAC */
    5656
    57     /* Applying language settings */
    58     retranslateUi();
    59 
    6057    /* Creating settings pages */
    6158    attachPage (new VBoxGLSettingsGeneral());
     
    7168    /* Update Selector with available items */
    7269    updateAvailability();
     70
     71    /* Applying language settings */
     72    retranslateUi();
    7373}
    7474
     
    107107{
    108108    /* Set dialog's name */
    109     setWindowTitle (tr ("VirtualBox Preferences"));
     109    setWindowTitle (dialogTitle());
    110110
    111111    /* Remember old index */
     
    133133
    134134    /* Translate the selector */
    135     mSelector->retranslateUi();
     135    mSelector->polish();
    136136   
    137137    VBoxSettingsDialog::retranslateUi();
     
    142142    /* Update Selector with available items */
    143143    updateAvailability();
     144}
     145
     146QString VBoxGLSettingsDlg::dialogTitle() const
     147{
     148    return tr ("VirtualBox - %1").arg (titleExtension());
    144149}
    145150
     
    192197    connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
    193198             this, SLOT (onMediaEnumerationDone()));
    194 
    195     /* Applying language settings */
    196     retranslateUi();
    197199
    198200    /* Creating settings pages */
     
    255257        }
    256258    }
     259    /* Applying language settings */
     260    retranslateUi();
    257261}
    258262
     
    376380
    377381    /* Translate the selector */
    378     mSelector->retranslateUi();
     382    mSelector->polish();
    379383   
    380384    VBoxSettingsDialog::retranslateUi();
     
    391395        if (!wval->isValid())
    392396            revalidate (wval);
     397}
     398
     399QString VBoxVMSettingsDlg::dialogTitle() const
     400{
     401    QString dialogTitle;
     402    if (!mMachine.isNull())
     403        dialogTitle = tr ("%1 - %2").arg (mMachine.GetName())
     404                                    .arg (titleExtension());
     405    return dialogTitle;
    393406}
    394407
     
    419432
    420433    return aPage;
    421 }
    422 
    423 QString VBoxVMSettingsDlg::dialogTitle() const
    424 {
    425     QString dialogTitle;
    426     if (!mMachine.isNull())
    427         dialogTitle = tr ("%1 - Settings").arg (mMachine.GetName());
    428     return dialogTitle;
    429434}
    430435
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxSettingsSelector.cpp

    r10468 r10474  
    2424#include "VBoxSettingsUtils.h"
    2525#include "QITreeWidget.h"
     26#include "VBoxToolBar.h"
    2627
    2728enum
     
    9495                                        const QString &aLink)
    9596{
    96     QTreeWidgetItem *item = NULL;
    97 
    98     item = new QTreeWidgetItem (mTwSelector, QStringList() << QString (" %1 ").arg (aText)
    99                                                            << idToString (aId)
    100                                                            << aLink);
     97    QTreeWidgetItem *item = new QTreeWidgetItem (mTwSelector, QStringList() << QString (" %1 ").arg (aText)
     98                                                                            << idToString (aId)
     99                                                                            << aLink);
    101100    item->setIcon (treeWidget_Category, aIcon);
    102101}
     
    163162}
    164163
    165 void VBoxSettingsTreeSelector::retranslateUi()
     164void VBoxSettingsTreeSelector::polish()
    166165{
    167166    mTwSelector->setFixedWidth (static_cast<QAbstractItemView*> (mTwSelector)
     
    217216}
    218217
     218/* VBoxSettingsToolBarSelector */
     219
     220class SelectorAction: public QAction
     221{
     222public:
     223    SelectorAction (const QIcon &aIcon, const QString &aText, int aId, const QString &aLink, QObject *aParent)
     224        : QAction (aIcon, aText, aParent)
     225        , mId (aId)
     226        , mLink (aLink)
     227    {
     228        setCheckable (true);
     229    }
     230
     231    int id() const { return mId; }
     232    QString link() const { return mLink; }
     233
     234private:
     235    int mId;
     236    QString mLink;
     237};
     238
     239VBoxSettingsToolBarSelector::VBoxSettingsToolBarSelector (QWidget *aParent /* = NULL */)
     240    :VBoxSettingsSelector (aParent)
     241{
     242    /* Init the toolbar */
     243    mTbSelector = new VBoxToolBar (aParent);
     244    mTbSelector->setUsesTextLabel (true);
     245    mTbSelector->setUsesBigPixmaps (true);
     246    /* Init the action group for house keeping */
     247    mActionGroup = new QActionGroup (this);
     248    mActionGroup->setExclusive (true);
     249    connect (mActionGroup, SIGNAL (triggered (QAction*)),
     250             this, SLOT (settingsGroupChanged (QAction*)));
     251}
     252
     253QWidget *VBoxSettingsToolBarSelector::widget() const
     254{
     255    return mTbSelector;
     256}
     257
     258void VBoxSettingsToolBarSelector::addItem (const QIcon &aIcon,
     259                                        const QString &aText,
     260                                        int aId,
     261                                        const QString &aLink)
     262{
     263    SelectorAction *action = new SelectorAction (aIcon, aText, aId, aLink, this);
     264
     265    mActionGroup->addAction (action);
     266    mTbSelector->addAction (action);
     267}
     268
     269QString VBoxSettingsToolBarSelector::itemText (int aId) const
     270{
     271    QString result;
     272    SelectorAction *action = findAction (aId);
     273    if (action)
     274        result = action->text();
     275    return result;
     276}
     277
     278int VBoxSettingsToolBarSelector::currentId () const
     279{
     280    SelectorAction *action = static_cast<SelectorAction*> (mActionGroup->checkedAction());
     281    int id = -1;
     282    if (action)
     283        id = action->id();
     284    return id;
     285}
     286
     287int VBoxSettingsToolBarSelector::idToIndex (int aId) const
     288{
     289    return findIndex (aId);
     290}
     291
     292int VBoxSettingsToolBarSelector::indexToId (int aIndex) const
     293{
     294    return findId (aIndex);
     295}
     296
     297int VBoxSettingsToolBarSelector::linkToId (const QString &aLink) const
     298{
     299    return findLink (aLink);
     300}
     301
     302
     303void VBoxSettingsToolBarSelector::selectById (int aId)
     304{
     305    SelectorAction *action = findAction (aId);
     306
     307    if (action)
     308        action->trigger();
     309}
     310
     311void VBoxSettingsToolBarSelector::setVisibleById (int aId, bool aShow)
     312{
     313    SelectorAction *action = findAction (aId);
     314
     315    if (action)
     316        action->setVisible (aShow);
     317}
     318
     319void VBoxSettingsToolBarSelector::clear()
     320{
     321    QList<QAction*> list = mActionGroup->actions();
     322    foreach (QAction *action, list)
     323       delete action;
     324}
     325
     326int VBoxSettingsToolBarSelector::minWidth() const
     327{
     328    return mTbSelector->sizeHint().width() + 2 * 10;
     329}
     330
     331void VBoxSettingsToolBarSelector::settingsGroupChanged (QAction *aAction)
     332{
     333    SelectorAction *action = static_cast<SelectorAction*> (aAction);
     334    if (action)
     335        emit categoryChanged (action->id());
     336}
     337
     338int VBoxSettingsToolBarSelector::findId (int aIndex) const
     339{
     340    int id = -1;
     341    QList<QAction*> list = mActionGroup->actions();
     342    if (aIndex > -1 &&
     343        aIndex < list.count())
     344    {
     345        SelectorAction *sa = static_cast<SelectorAction*> (list.at (aIndex));
     346        if (sa)
     347            id = sa->id();
     348    }
     349    return id;
     350}
     351
     352int VBoxSettingsToolBarSelector::findIndex (int aId) const
     353{
     354    int index = -1;
     355    QList<QAction*> list = mActionGroup->actions();
     356    for (int a = 0; a < list.count(); ++a)
     357    {
     358        SelectorAction *sa = static_cast<SelectorAction*> (list.at(a));
     359        if (sa &&
     360            sa->id() == aId)
     361        {
     362            index = a;
     363            break;
     364        }
     365    }
     366    return index;
     367}
     368
     369int VBoxSettingsToolBarSelector::findLink (const QString &aLink) const
     370{
     371    int id = -1;
     372    QList<QAction*> list = mActionGroup->actions();
     373    for (int a = 0; a < list.count(); ++a)
     374    {
     375        SelectorAction *sa = static_cast<SelectorAction*> (list.at(a));
     376        if (sa &&
     377            sa->link() == aLink)
     378        {
     379            id = sa->id();
     380            break;
     381        }
     382    }
     383    return id;
     384}
     385
     386SelectorAction* VBoxSettingsToolBarSelector::findAction (int aId) const
     387{
     388    int index = findIndex (aId);
     389    SelectorAction *sa = NULL;
     390    QList<QAction*> list = mActionGroup->actions();
     391    if (index > -1 &&
     392        index < list.count())
     393        sa = static_cast<SelectorAction*> (list.at (index));
     394    return sa;
     395}
     396
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