VirtualBox

Ignore:
Timestamp:
May 4, 2016 1:47:14 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: ​​​​​​​​​bugref:6769: Rework/cleanup file-path selector widget (part 05): Refactoring.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.cpp

    r60828 r60829  
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    22 /* GUI includes: */
    23 # include "QIFileDialog.h"
    24 # include "QIToolButton.h"
    25 # include "QILabel.h"
    26 # include "QILineEdit.h"
    27 # include "UIIconPool.h"
    28 # include "UIFilePathSelector.h"
    29 # include "VBoxGlobal.h"
    30 
    31 /* Other VBox includes: */
    32 # include <iprt/assert.h>
    33 
    3422/* Qt includes: */
    3523# include <QAction>
     
    4230# include <QTimer>
    4331
     32/* GUI includes: */
     33# include "QIFileDialog.h"
     34# include "QILabel.h"
     35# include "QILineEdit.h"
     36# include "QIToolButton.h"
     37# include "UIIconPool.h"
     38# include "UIFilePathSelector.h"
     39# include "VBoxGlobal.h"
     40
     41/* Other VBox includes: */
     42# include <iprt/assert.h>
     43
    4444#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4545
     
    6868UIFilePathSelector::UIFilePathSelector(QWidget *pParent /* = 0 */)
    6969    : QIWithRetranslateUI<QComboBox>(pParent)
    70     , m_pCopyAction(new QAction(this))
    7170    , m_enmMode(Mode_Folder)
    7271    , m_strHomeDir(QDir::current().absolutePath())
    7372    , m_fEditable(true)
     73    , m_fModified(false)
    7474    , m_fEditableMode(false)
    7575    , m_fMouseAwaited(false)
    76     , m_fModified(false)
     76    , m_pCopyAction(new QAction(this))
    7777{
    7878    /* Populate items: */
     
    106106}
    107107
    108 UIFilePathSelector::~UIFilePathSelector()
    109 {
    110 }
    111 
    112 void UIFilePathSelector::setMode(Mode enmMode)
    113 {
    114     m_enmMode = enmMode;
    115 }
    116 
    117 UIFilePathSelector::Mode UIFilePathSelector::mode() const
    118 {
    119     return m_enmMode;
    120 }
    121 
    122108void UIFilePathSelector::setEditable(bool fEditable)
    123109{
     
    169155}
    170156
    171 void UIFilePathSelector::resetModified()
    172 {
    173     m_fModified = false;
    174 }
    175 
    176 bool UIFilePathSelector::isModified() const
    177 {
    178     return m_fModified;
    179 }
    180 
    181 void UIFilePathSelector::setFileDialogTitle(const QString& strTitle)
    182 {
    183     m_strFileDialogTitle = strTitle;
    184 }
    185 
    186 QString UIFilePathSelector::fileDialogTitle() const
    187 {
    188     return m_strFileDialogTitle;
    189 }
    190 
    191 void UIFilePathSelector::setFileDialogFilters(const QString& strFilters)
    192 {
    193     m_strFileDialogFilters = strFilters;
    194 }
    195 
    196 QString UIFilePathSelector::fileDialogFilters() const
    197 {
    198     return m_strFileDialogFilters;
    199 }
    200 
    201 void UIFilePathSelector::setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension)
    202 {
    203     m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension;
    204 }
    205 
    206 QString UIFilePathSelector::fileDialogDefaultSaveExtension() const
    207 {
    208     return m_strFileDialogDefaultSaveExtension;
    209 }
    210 
    211157bool UIFilePathSelector::isPathSelected() const
    212158{
     
    230176{
    231177    m_strHomeDir = strHomeDir;
     178}
     179
     180bool UIFilePathSelector::eventFilter(QObject *pObject, QEvent *pEvent)
     181{
     182    if (m_fMouseAwaited && (pEvent->type() == QEvent::MouseButtonPress))
     183        QTimer::singleShot(0, this, SLOT(refreshText()));
     184
     185    return QIWithRetranslateUI<QComboBox>::eventFilter(pObject, pEvent);
    232186}
    233187
     
    260214    }
    261215    QIWithRetranslateUI<QComboBox>::focusOutEvent(pEvent);
    262 }
    263 
    264 bool UIFilePathSelector::eventFilter(QObject *pObject, QEvent *pEvent)
    265 {
    266     if (m_fMouseAwaited && (pEvent->type() == QEvent::MouseButtonPress))
    267         QTimer::singleShot(0, this, SLOT(refreshText()));
    268 
    269     return QIWithRetranslateUI<QComboBox>::eventFilter(pObject, pEvent);
    270216}
    271217
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIFilePathSelector.h

    r60828 r60829  
    1919#define ___UIFilePathSelector_h___
    2020
     21/* Qt includes: */
     22#include <QComboBox>
     23
    2124/* GUI includes: */
    2225#include "QIWithRetranslateUI.h"
    2326
    24 /* Qt includes: */
    25 #include <QComboBox>
    26 
    2727/* Forward declarations: */
     28class QAction;
     29class QHBoxLayout;
    2830class QILabel;
    2931class QILineEdit;
    30 class QHBoxLayout;
    31 class QAction;
    3232class QIToolButton;
    3333
     
    3838{
    3939    Q_OBJECT;
     40
     41signals:
     42
     43    /** Notify listeners about @a strPath changed. */
     44    void pathChanged(const QString &strPath);
    4045
    4146public:
     
    5156    /** Constructs file-path selector passing @a pParent to QComboBox base-class. */
    5257    UIFilePathSelector(QWidget *pParent = 0);
    53     /** Destructs file-path selector. */
    54     ~UIFilePathSelector();
    5558
    5659    /** Defines the @a enmMode to operate in. */
    57     void setMode(Mode enmMode);
     60    void setMode(Mode enmMode) { m_enmMode = enmMode; }
    5861    /** Returns the mode to operate in. */
    59     Mode mode() const;
     62    Mode mode() const { return m_enmMode; }
    6063
    6164    /** Defines whether the path is @a fEditable. */
     
    7073
    7174    /** Defines the file-dialog @a strTitle. */
    72     void setFileDialogTitle(const QString &strTitle);
     75    void setFileDialogTitle(const QString &strTitle) { m_strFileDialogTitle = strTitle; }
    7376    /** Returns the file-dialog title. */
    74     QString fileDialogTitle() const;
     77    QString fileDialogTitle() const { return m_strFileDialogTitle; }
    7578
    7679    /** Defines the file-dialog @a strFilters. */
    77     void setFileDialogFilters(const QString &strFilters);
     80    void setFileDialogFilters(const QString &strFilters) { m_strFileDialogFilters = strFilters; }
    7881    /** Returns the file-dialog filters. */
    79     QString fileDialogFilters() const;
     82    QString fileDialogFilters() const { return m_strFileDialogFilters; }
    8083
    8184    /** Defines the file-dialog @a strDefaultSaveExtension. */
    82     void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension);
     85    void setFileDialogDefaultSaveExtension(const QString &strDefaultSaveExtension) { m_strFileDialogDefaultSaveExtension = strDefaultSaveExtension; }
    8386    /** Returns the file-dialog default save extension. */
    84     QString fileDialogDefaultSaveExtension() const;
     87    QString fileDialogDefaultSaveExtension() const { return m_strFileDialogDefaultSaveExtension; }
    8588
    8689    /** Resets path modified state to false. */
    87     void resetModified();
     90    void resetModified() { m_fModified = false; }
    8891    /** Returns whether the path is modified. */
    89     bool isModified() const;
     92    bool isModified() const { return m_fModified; }
    9093    /** Returns whether the path is selected. */
    9194    bool isPathSelected() const;
     
    9396    /** Returns the path. */
    9497    QString path() const;
    95 
    96 signals:
    97 
    98     /** Notify listeners about @a strPath changed. */
    99     void pathChanged(const QString &strPath);
    10098
    10199public slots:
     
    109107protected:
    110108
     109    /** Preprocesses every @a pEvent sent to @a pObject. */
     110    bool eventFilter(QObject *pObject, QEvent *pEvent);
     111
    111112    /** Handles resize @a pEvent. */
    112113    void resizeEvent(QResizeEvent *pEvent);
     
    116117    /** Handles focus-out @a pEvent. */
    117118    void focusOutEvent(QFocusEvent *pEvent);
    118 
    119     /** Preprocesses every @a pEvent sent to @a pObject. */
    120     bool eventFilter(QObject *pObject, QEvent *pEvent);
    121119
    122120    /** Handles translation event. */
     
    154152    QString shrinkText(int iWidth) const;
    155153
    156     /** Holds the copy action instance. */
    157     QAction *m_pCopyAction;
    158 
    159154    /** Holds the mode to operate in. */
    160155    Mode     m_enmMode;
     
    165160    QString  m_strHomeDir;
    166161
     162    /** Holds the file-dialog title. */
     163    QString  m_strFileDialogTitle;
    167164    /** Holds the file-dialog filters. */
    168165    QString  m_strFileDialogFilters;
    169166    /** Holds the file-dialog default save extension. */
    170167    QString  m_strFileDialogDefaultSaveExtension;
    171     /** Holds the file-dialog title. */
    172     QString  m_strFileDialogTitle;
    173168
    174169    /** Holds the cached text for empty path. */
     
    179174    /** Holds whether the path is editable. */
    180175    bool     m_fEditable;
     176    /** Holds whether the path is modified. */
     177    bool     m_fModified;
    181178
    182179    /** Holds whether we are in editable mode. */
     
    185182    bool     m_fMouseAwaited;
    186183
    187     /** Holds whether the path is modified. */
    188     bool     m_fModified;
     184    /** Holds the copy action instance. */
     185    QAction *m_pCopyAction;
    189186};
    190187
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