VirtualBox

Changeset 17108 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 25, 2009 1:28:47 AM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: 3627: Shorten error dialogs: 1 - focus rectangle around the text when focused, 2 - clicking over the text toggles related button, 3 - allowing to resize message vertically.

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

Legend:

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

    r16913 r17108  
    4545class QVBoxLayout;
    4646
     47/** @class QIArrowButton
     48 *
     49 *  The QIArrowButton class is an arrow tool-botton with text-label.
     50 *  It is declared here until moved into separate file in case
     51 *  of it will be used somewhere except problem-reporter dialog.
     52 */
     53class QIArrowButton : public QWidget
     54{
     55    Q_OBJECT;
     56
     57public:
     58
     59    QIArrowButton (const QString &aName, QWidget *aParent = 0);
     60
     61    bool isExpanded() const;
     62
     63    void animateClick();
     64
     65signals:
     66
     67    void clicked();
     68
     69private slots:
     70
     71    void buttonClicked();
     72
     73private:
     74
     75    void updateIcon();
     76
     77    bool eventFilter (QObject *aObject, QEvent *aEvent);
     78
     79    void paintEvent (QPaintEvent *aEvent);
     80
     81    bool mIsExpanded;
     82    QToolButton *mButton;
     83    QLabel *mLabel;
     84};
     85
    4786/** @class QIArrowSplitter
    4887 *
     
    5796public:
    5897
    59     enum ToggleType
    60     {
    61         Toggle = 0,
    62         CollapsOnly,
    63         ExpandOnly
    64     };
    65 
    6698    QIArrowSplitter (QWidget *aParent = 0);
    6799
     
    70102public slots:
    71103
    72     void toggleWidget (ToggleType aType = Toggle);
     104    void toggleWidget();
    73105
    74106private:
     
    77109
    78110    QVBoxLayout *mMainLayout;
    79     QList <QToolButton*> mButtonsList;
     111    QList <QIArrowButton*> mButtonsList;
    80112    QList <QWidget*> mWidgetsList;
    81113};
  • trunk/src/VBox/Frontends/VirtualBox/src/QIMessageBox.cpp

    r16956 r17108  
    3535#include <QLabel>
    3636#include <QPushButton>
     37#include <QStyleOptionFocusRect>
     38#include <QStylePainter>
    3739#include <QToolButton>
     40
     41/** @class QIArrowButton
     42 *
     43 *  The QIArrowButton class is an arrow tool-botton with text-label.
     44 */
     45QIArrowButton::QIArrowButton (const QString &aName, QWidget *aParent)
     46    : QWidget (aParent)
     47    , mIsExpanded (false)
     48    , mButton (new QToolButton())
     49    , mLabel (new QLabel (aName))
     50{
     51    /* Setup itself */
     52    setFocusPolicy (Qt::StrongFocus);
     53
     54    /* Setup tool-button */
     55    mButton->setAutoRaise (true);
     56    mButton->setFixedSize (14, 16);
     57    mButton->setFocusPolicy (Qt::NoFocus);
     58    mButton->setStyleSheet ("QToolButton {border: 0px none black;}");
     59    connect (mButton, SIGNAL (clicked (bool)), this, SLOT (buttonClicked()));
     60    updateIcon();
     61
     62    /* Setup text-label */
     63    mLabel->setBuddy (mButton);
     64    mLabel->setStyleSheet ("QLabel {padding: 0px 1px 0px 1px;}");
     65
     66    /* Setup main-layout */
     67    QHBoxLayout *mainLayout = new QHBoxLayout (this);
     68    VBoxGlobal::setLayoutMargin (mainLayout, 0);
     69    mainLayout->addWidget (mButton);
     70    mainLayout->addWidget (mLabel);
     71    mainLayout->addStretch();
     72
     73    /* Install event-filter */
     74    qApp->installEventFilter (this);
     75}
     76
     77bool QIArrowButton::isExpanded() const
     78{
     79    return mIsExpanded;
     80}
     81
     82void QIArrowButton::animateClick()
     83{
     84    mButton->animateClick();
     85}
     86
     87void QIArrowButton::buttonClicked()
     88{
     89    mIsExpanded = !mIsExpanded;
     90    updateIcon();
     91    emit clicked();
     92}
     93
     94void QIArrowButton::updateIcon()
     95{
     96    mButton->setIcon (VBoxGlobal::iconSet (mIsExpanded ?
     97                      ":/arrow_down_10px.png" : ":/arrow_right_10px.png"));
     98}
     99
     100bool QIArrowButton::eventFilter (QObject *aObject, QEvent *aEvent)
     101{
     102    /* Process only QIArrowButton or children */
     103    if (!(aObject == this || children().contains (aObject)))
     104        return QWidget::eventFilter (aObject, aEvent);
     105
     106    /* Process some keyboard events */
     107    if (aEvent->type() == QEvent::KeyPress)
     108    {
     109        QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
     110        switch (kEvent->key())
     111        {
     112            /* "+" as expand */
     113            case Qt::Key_Plus:
     114            {
     115                if (!mIsExpanded)
     116                    mButton->animateClick();
     117                break;
     118            }
     119            /* "-" as collapse */
     120            case Qt::Key_Minus:
     121            {
     122                if (mIsExpanded)
     123                    mButton->animateClick();
     124                break;
     125            }
     126            /* Space as toggle */
     127            case Qt::Key_Space:
     128            {
     129                mButton->animateClick();
     130                break;
     131            }
     132        }
     133    }
     134
     135    /* Process some mouse events */
     136    if ((aEvent->type() == QEvent::MouseButtonPress ||
     137         aEvent->type() == QEvent::MouseButtonDblClick)
     138        && aObject == mLabel)
     139    {
     140        /* Label click as toggle */
     141        mButton->animateClick();
     142    }
     143
     144    /* Default one handler */
     145    return QWidget::eventFilter (aObject, aEvent);
     146}
     147
     148void QIArrowButton::paintEvent (QPaintEvent *aEvent)
     149{
     150    if (hasFocus())
     151    {
     152        QStylePainter painter (this);
     153        QStyleOptionFocusRect option;
     154        option.initFrom (this);
     155        option.rect = mLabel->frameGeometry();
     156        painter.drawPrimitive (QStyle::PE_FrameFocusRect, option);
     157    }
     158    QWidget::paintEvent (aEvent);
     159}
    38160
    39161/** @class QIArrowSplitter
     
    45167    , mMainLayout (new QVBoxLayout (this))
    46168{
     169    /* Setup main-layout */
    47170    VBoxGlobal::setLayoutMargin (mMainLayout, 0);
     171
     172    /* Install event-filter */
    48173    qApp->installEventFilter (this);
    49174}
     
    51176void QIArrowSplitter::addWidget (const QString &aName, QWidget *aWidget)
    52177{
    53     /* Creating arrow tool-button */
    54     QToolButton *arrowButton = new QToolButton();
    55     connect (arrowButton, SIGNAL (clicked (bool)), this, SLOT (toggleWidget()));
    56     arrowButton->setIcon (VBoxGlobal::iconSet (":/arrow_right_10px.png"));
    57     arrowButton->setFocusPolicy (Qt::StrongFocus);
    58     arrowButton->setAutoRaise (true);
    59     arrowButton->setFixedSize (14, 16);
    60     arrowButton->setStyleSheet ("QToolButton { border: 0px none black; }");
    61     mButtonsList.append (arrowButton);
    62 
    63     /* Creating description label */
    64     QLabel *descriptionLabel = new QLabel (aName);
    65     descriptionLabel->setBuddy (arrowButton);
    66 
     178    /* Creating arrow button */
     179    QIArrowButton *button = new QIArrowButton (aName);
     180    connect (button, SIGNAL (clicked()), this, SLOT (toggleWidget()));
     181
     182    /* Append internal lists */
     183    mButtonsList.append (button);
    67184    mWidgetsList.append (aWidget);
    68185
    69     QHBoxLayout *lineLayout = new QHBoxLayout();
    70     lineLayout->addWidget (arrowButton);
    71     lineLayout->addWidget (descriptionLabel);
    72 
    73     mMainLayout->insertWidget (0, aWidget);
    74     mMainLayout->insertLayout (0, lineLayout);
    75 }
    76 
    77 void QIArrowSplitter::toggleWidget (ToggleType aType)
    78 {
    79     QToolButton *arrowButton = qobject_cast <QToolButton*> (sender());
    80 
    81     /* Toggle all or the specified arrow & related widget */
    82     foreach (QToolButton *itemButton, mButtonsList)
    83     {
    84         if ((itemButton == arrowButton) || (!arrowButton))
     186    /* Append layout with children */
     187    mMainLayout->addWidget (button);
     188    mMainLayout->addWidget (aWidget);
     189}
     190
     191void QIArrowSplitter::toggleWidget()
     192{
     193    QIArrowButton *clickedButton = qobject_cast <QIArrowButton*> (sender());
     194
     195    foreach (QIArrowButton *button, mButtonsList)
     196    {
     197        if ((button == clickedButton) || !clickedButton)
    85198        {
    86             QWidget *relatedWidget = mWidgetsList [mButtonsList.indexOf (itemButton)];
     199            QWidget *relatedWidget = mWidgetsList [mButtonsList.indexOf (button)];
    87200            Assert (relatedWidget);
    88             if ((relatedWidget->isVisible() && aType != ExpandOnly) ||
    89                 (!relatedWidget->isVisible() && aType != CollapsOnly))
    90             {
    91                 relatedWidget->setVisible (!relatedWidget->isVisible());
    92                 itemButton->setIcon (VBoxGlobal::iconSet (relatedWidget->isVisible() ?
    93                                      ":/arrow_down_10px.png" : ":/arrow_right_10px.png"));
    94             }
     201            relatedWidget->setVisible (button->isExpanded());
    95202        }
    96203    }
     
    110217    /* Now resize window to minimum possible size */
    111218    window()->resize (window()->minimumSizeHint());
    112     qApp->processEvents();
    113 #ifdef Q_WS_WIN
    114     /* Set fixed size to which one current we have */
    115     window()->setFixedSize (window()->size());
    116 #else
    117     /* Unable to resize on some platforms because it was fixed already */
    118     window()->setFixedSize (window()->minimumSizeHint());
    119 #endif
    120219}
    121220
    122221bool QIArrowSplitter::eventFilter (QObject *aObject, QEvent *aEvent)
    123222{
    124     if (!aObject->isWidgetType())
     223    /* Process only parent window children */
     224    if (!(aObject == window() || window()->children().contains (aObject)))
    125225        return QWidget::eventFilter (aObject, aEvent);
    126226
    127     QWidget *widget = qobject_cast <QWidget*> (aObject);
    128     if (widget->window() != window())
    129         return QWidget::eventFilter (aObject, aEvent);
     227    /* Do not process QIArrowButton children */
     228    foreach (QIArrowButton *button, mButtonsList)
     229        if (button->children().contains (aObject))
     230            return QWidget::eventFilter (aObject, aEvent);
    130231
    131232    /* Process some keyboard events */
     
    133234    {
    134235        QKeyEvent *kEvent = static_cast <QKeyEvent*> (aEvent);
    135         QToolButton *arrowButton = qobject_cast <QToolButton*> (QApplication::focusWidget());
    136         int slot = arrowButton ? mButtonsList.indexOf (arrowButton) : -1;
    137236        switch (kEvent->key())
    138237        {
    139238            case Qt::Key_Plus:
    140239            {
    141                 if (slot != -1 && !mWidgetsList [slot]->isVisible())
    142                     arrowButton->animateClick();
    143                 else
    144                     toggleWidget (ExpandOnly);
     240                foreach (QIArrowButton *button, mButtonsList)
     241                    if (!button->isExpanded())
     242                        button->animateClick();
    145243                break;
    146244            }
    147245            case Qt::Key_Minus:
    148246            {
    149                 if (slot != -1 && mWidgetsList [slot]->isVisible())
    150                     arrowButton->animateClick();
    151                 else
    152                     toggleWidget (CollapsOnly);
     247                foreach (QIArrowButton *button, mButtonsList)
     248                    if (button->isExpanded())
     249                        button->animateClick();
    153250                break;
    154251            }
     
    156253    }
    157254
     255    /* Default one handler */
    158256    return QWidget::eventFilter (aObject, aEvent);
    159257}
     
    510608        mTextLabel->setMinimumWidth (mTextLabel->width());
    511609        mTextLabel->updateSizeHint();
     610        qApp->processEvents();
     611        setFixedWidth (width());
    512612        mDetailsSplitter->toggleWidget();
    513613        mWasPolished = true;
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