VirtualBox

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


Ignore:
Timestamp:
Sep 15, 2023 4:45:07 PM (16 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: UIAdvancedSettingsDialog: More convenient filter editor; A bit of animation.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.cpp

    r101118 r101136  
    4747#include "QIDialogButtonBox.h"
    4848#include "QILineEdit.h"
     49#include "QIToolButton.h"
    4950#include "UIAdvancedSettingsDialog.h"
     51#include "UIAnimationFramework.h"
    5052#include "UICommon.h"
    5153#include "UIDesktopWidgetWatchdog.h"
     54#include "UIIconPool.h"
    5255#include "UIMessageCenter.h"
    5356#include "UIModalWindowManager.h"
     
    7174
    7275
     76/** QWidget reimplementation
     77  * wrapping custom QILineEdit and
     78  * representing filter editor for advanced settings dialog. */
     79class UIFilterEditor : public QWidget
     80{
     81    Q_OBJECT;
     82    Q_PROPERTY(int editorWidth READ editorWidth WRITE setEditorWidth);
     83    Q_PROPERTY(int unfocusedEditorWidth READ unfocusedEditorWidth);
     84    Q_PROPERTY(int focusedEditorWidth READ focusedEditorWidth);
     85
     86signals:
     87
     88    /** Notifies listeners about @a strText changed. */
     89    void sigTextChanged(const QString &strText);
     90
     91    /** Notifies listeners about editor focused. */
     92    void sigFocused();
     93    /** Notifies listeners about editor unfocused. */
     94    void sigUnfocused();
     95
     96public:
     97
     98    /** Constructs filter editor passing @a pParent to the base-class. */
     99    UIFilterEditor(QWidget *pParent);
     100    /** Destructs filter editor. */
     101    virtual ~UIFilterEditor() RT_OVERRIDE;
     102
     103protected:
     104
     105    /** Returns the minimum widget size. */
     106    virtual QSize minimumSizeHint() const RT_OVERRIDE;
     107
     108    /** Handles resize @a pEvent. */
     109    virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
     110
     111    /** Preprocesses Qt @a pEvent for passed @a pObject. */
     112    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
     113
     114private:
     115
     116    /** Prepares all. */
     117    void prepare();
     118    /** Cleanups all. */
     119    void cleanup();
     120
     121    /** Adjusts editor geometry. */
     122    void adjustEditorGeometry();
     123
     124    /** Defines internal widget @a iWidth. */
     125    void setEditorWidth(int iWidth);
     126    /** Returns internal widget width. */
     127    int editorWidth() const;
     128    /** Returns internal widget width when it's unfocused. */
     129    int unfocusedEditorWidth() const { return m_iUnfocusedEditorWidth; }
     130    /** Returns internal widget width when it's focused. */
     131    int focusedEditorWidth() const { return m_iFocusedEditorWidth; }
     132
     133    /** Holds the filter editor instance. */
     134    QILineEdit   *m_pLineEdit;
     135#if 0
     136    /** Holds the filter reset button instance. */
     137    QIToolButton *m_pToolButton;
     138#endif
     139
     140    /** Holds whether filter editor focused. */
     141    bool         m_fFocused;
     142    /** Holds unfocused filter editor width. */
     143    int          m_iUnfocusedEditorWidth;
     144    /** Holds focused filter editor width. */
     145    int          m_iFocusedEditorWidth;
     146    /** Holds the animation framework object. */
     147    UIAnimation *m_pAnimation;
     148};
     149
     150
    73151/** QScrollArea extension to be used for
    74152  * advanced settings dialog. The idea is to make
     
    89167    virtual QSize minimumSizeHint() const RT_OVERRIDE;
    90168};
     169
     170
     171/*********************************************************************************************************************************
     172*   Class UIFilterEditor implementation.                                                                                         *
     173*********************************************************************************************************************************/
     174
     175UIFilterEditor::UIFilterEditor(QWidget *pParent)
     176    : QWidget(pParent)
     177    , m_pLineEdit(0)
     178#if 0
     179    , m_pToolButton(0)
     180#endif
     181    , m_fFocused(false)
     182    , m_iUnfocusedEditorWidth(0)
     183    , m_iFocusedEditorWidth(0)
     184    , m_pAnimation(0)
     185{
     186    prepare();
     187}
     188
     189UIFilterEditor::~UIFilterEditor()
     190{
     191    cleanup();
     192}
     193
     194QSize UIFilterEditor::minimumSizeHint() const
     195{
     196    return m_pLineEdit ? m_pLineEdit->minimumSizeHint() : QWidget::minimumSizeHint();
     197}
     198
     199void UIFilterEditor::resizeEvent(QResizeEvent *pEvent)
     200{
     201    /* Call to base-class: */
     202    QWidget::resizeEvent(pEvent);
     203
     204    /* Adjust filter editor geometry on each parent resize: */
     205    adjustEditorGeometry();
     206}
     207
     208bool UIFilterEditor::eventFilter(QObject *pObject, QEvent *pEvent)
     209{
     210    /* Preprocess events for m_pLineEdit only: */
     211    if (pObject != m_pLineEdit)
     212        return QWidget::eventFilter(pObject, pEvent);
     213
     214    /* Handles various event types: */
     215    switch (pEvent->type())
     216    {
     217        /* Foreard animation on focus-in: */
     218        case QEvent::FocusIn:
     219            m_fFocused = true;
     220            emit sigFocused();
     221            break;
     222        /* Backward animation on focus-out: */
     223        case QEvent::FocusOut:
     224            m_fFocused = false;
     225            emit sigUnfocused();
     226            break;
     227        default:
     228            break;
     229    }
     230
     231    /* Call to base-class: */
     232    return QWidget::eventFilter(pObject, pEvent);
     233}
     234
     235void UIFilterEditor::prepare()
     236{
     237    /* Prepare filter editor: */
     238    m_pLineEdit = new QILineEdit(this);
     239    if (m_pLineEdit)
     240    {
     241        m_pLineEdit->installEventFilter(this);
     242        connect(m_pLineEdit, &QILineEdit::textChanged,
     243                this, &UIFilterEditor::sigTextChanged);
     244    }
     245
     246#if 0
     247    /* Prepare filter reset button: */
     248    m_pToolButton = new QIToolButton(this);
     249    if (m_pToolButton)
     250        m_pToolButton->setIcon(UIIconPool::iconSet(":/search_16px.png"));
     251#endif
     252
     253    /* Install 'unfocus/focus' animation to 'editorWidth' property: */
     254    m_pAnimation = UIAnimation::installPropertyAnimation(this,
     255                                                         "editorWidth",
     256                                                         "unfocusedEditorWidth", "focusedEditorWidth",
     257                                                         SIGNAL(sigFocused()), SIGNAL(sigUnfocused()));
     258
     259    /* Adjust filter editor geometry initially: */
     260    adjustEditorGeometry();
     261}
     262
     263void UIFilterEditor::cleanup()
     264{
     265    /* Cleanup 'unfocus/focus' animation: */
     266    delete m_pAnimation;
     267    m_pAnimation = 0;
     268}
     269
     270void UIFilterEditor::adjustEditorGeometry()
     271{
     272    /* Update minimum/maximum filter editor width: */
     273    const int iWidth = width();
     274    const int iMinimumWidth = m_pLineEdit->minimumSizeHint().width();
     275    m_iUnfocusedEditorWidth = qMax(iWidth / 2, iMinimumWidth);
     276    m_iFocusedEditorWidth = qMax(iWidth, iMinimumWidth);;
     277    m_pAnimation->update();
     278
     279    /* Update filter editor geometry: */
     280    setEditorWidth(m_fFocused ? m_iFocusedEditorWidth : m_iUnfocusedEditorWidth);
     281}
     282
     283void UIFilterEditor::setEditorWidth(int iWidth)
     284{
     285    /* Align filter editor right: */
     286    const int iX = width() - iWidth;
     287    const int iY = 0;
     288    const int iHeight = m_pLineEdit->minimumSizeHint().height();
     289    m_pLineEdit->setGeometry(iX, iY, iWidth, iHeight);
     290}
     291
     292int UIFilterEditor::editorWidth() const
     293{
     294    return m_pLineEdit->width();
     295}
    91296
    92297
     
    635840
    636841    /* Prepare filter editor: */
    637     m_pEditorFilter = new QILineEdit(centralWidget());
     842    m_pEditorFilter = new UIFilterEditor(centralWidget());
    638843    if (m_pEditorFilter)
    639844    {
    640         connect(m_pEditorFilter, &QILineEdit::textChanged,
     845        connect(m_pEditorFilter, &UIFilterEditor::sigTextChanged,
    641846                this, &UIAdvancedSettingsDialog::sltHandleFilterTextChanged);
    642847        m_pLayoutMain->addWidget(m_pEditorFilter, 0, 1);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.h

    r101118 r101136  
    4848class QVariant;
    4949class QIDialogButtonBox;
    50 class QILineEdit;
     50class UIFilterEditor;
    5151class UISettingsPage;
    5252class UISettingsPageFrame;
     
    252252
    253253        /** Holds the filter editor instance. */
    254         QILineEdit *m_pEditorFilter;
     254        UIFilterEditor *m_pEditorFilter;
    255255
    256256        /** Holds the scroll-area instance. */
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