VirtualBox

Changeset 11497 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 19, 2008 6:16:55 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34998
Message:

Fe/Qt4: 'File/Folder Path Selector' widget updated. It becomes editable combo-box. In editable (focused) mode it contains no any icon and allows user to edit contained path as simple non-compressed text. Select Path function become encapsulated. Focus loosing bug (after selecting 'Other...' path) fixed.

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

Legend:

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

    r11427 r11497  
    5454
    5555    bool isModified() const;
     56    bool isPathLineChosen() const;
     57
     58    QString path() const;
     59
     60public slots:
    5661
    5762    void setPath (const QString &aPath);
    58     QString path() const;
    59 
    60 signals:
    61 
    62     void selectPath();
     63    void setHomeDir (const QString &aHomeDir);
    6364
    6465protected:
    6566
    6667    void resizeEvent (QResizeEvent *aEvent);
     68    void focusInEvent (QFocusEvent *aEvent);
     69    void focusOutEvent (QFocusEvent *aEvent);
    6770    void retranslateUi();
    6871
     
    7477private:
    7578
     79    void selectPath();
    7680    QIcon defaultIcon() const;
    7781    QString fullPath (bool aAbsolute = true) const;
     
    8488    Mode mMode;
    8589    QString mPath;
     90    QString mHomeDir;
    8691    QString mNoneStr;
    8792    QString mNoneTip;
     93    bool mIsEditableMode;
    8894};
    8995
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxGLSettingsGeneral.h

    r11427 r11497  
    4646
    4747    void retranslateUi();
    48 
    49 private slots:
    50 
    51     void onSelectFolderClicked();
    5248};
    5349
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsGeneral.h

    r11427 r11497  
    6363                                   QTreeWidgetItem *aPrev = 0);
    6464
    65     void selectSnapshotFolder();
    66 
    6765private:
    6866
  • trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsSFDetails.h

    r10742 r11497  
    6262
    6363    void retranslateUi();
    64    
     64
    6565private slots:
    6666
    67     void selectPath();
     67    void onSelectPath();
    6868    void validate();
    6969
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFilePathSelectorWidget.cpp

    r11427 r11497  
    3030#include <QDir>
    3131#include <QFileIconProvider>
     32#include <QLineEdit>
    3233
    3334enum
     
    4344    , mCopyAction (new QAction (this))
    4445    , mMode (Mode_Folder)
     46    , mHomeDir (QDir::current().absolutePath())
     47    , mIsEditableMode (false)
    4548{
    4649    /* Populate items */
     
    5861    mCopyAction->setShortcutContext (Qt::WidgetShortcut);
    5962
     63    /* Initial Setup */
     64    setEditable (true);
     65    Assert (lineEdit());
     66    setInsertPolicy (QComboBox::NoInsert);
     67    setContextMenuPolicy (Qt::ActionsContextMenu);
     68    setMinimumWidth (200);
     69
    6070    /* Setup connections */
     71    connect (lineEdit(), SIGNAL (textEdited (const QString &)),
     72             this, SLOT (setPath (const QString &)));
    6173    connect (this, SIGNAL (activated (int)), this, SLOT (onActivated (int)));
    6274    connect (mCopyAction, SIGNAL (triggered (bool)), this, SLOT (copyToClipboard()));
     
    6476    /* Applying language settings */
    6577    retranslateUi();
    66 
    67     /* Initial Setup */
    68     setContextMenuPolicy (Qt::ActionsContextMenu);
    69     setMinimumWidth (200);
    7078}
    7179
     
    107115}
    108116
     117bool VBoxFilePathSelectorWidget::isPathLineChosen() const
     118{
     119    return (currentIndex() == PathId);
     120}
     121
     122QString VBoxFilePathSelectorWidget::path() const
     123{
     124    return mPath;
     125}
     126
    109127void VBoxFilePathSelectorWidget::setPath (const QString &aPath)
    110128{
    111     mPath = aPath.isEmpty() ? QString::null : aPath;
     129    mPath = aPath.isEmpty() ? QString::null :
     130            QDir::toNativeSeparators (aPath);
    112131    refreshText();
    113132}
    114133
    115 QString VBoxFilePathSelectorWidget::path() const
    116 {
    117     return mPath;
     134void VBoxFilePathSelectorWidget::setHomeDir (const QString &aHomeDir)
     135{
     136    mHomeDir = aHomeDir;
    118137}
    119138
     
    122141    QIWithRetranslateUI<QComboBox>::resizeEvent (aEvent);
    123142    refreshText();
     143}
     144
     145void VBoxFilePathSelectorWidget::focusInEvent (QFocusEvent *aEvent)
     146{
     147    if (isPathLineChosen())
     148    {
     149        mIsEditableMode = true;
     150        refreshText();
     151    }
     152    QIWithRetranslateUI<QComboBox>::focusInEvent (aEvent);
     153}
     154
     155void VBoxFilePathSelectorWidget::focusOutEvent (QFocusEvent *aEvent)
     156{
     157    if (isPathLineChosen())
     158    {
     159        mIsEditableMode = false;
     160        refreshText();
     161    }
     162    QIWithRetranslateUI<QComboBox>::focusOutEvent (aEvent);
    124163}
    125164
     
    188227        case SelectId:
    189228        {
    190             emit selectPath();
     229            selectPath();
    191230            break;
    192231        }
     
    200239    }
    201240    setCurrentIndex (PathId);
     241    setFocus();
    202242}
    203243
     
    211251}
    212252
     253void VBoxFilePathSelectorWidget::selectPath()
     254{
     255    /* Preparing initial directory. */
     256    QString initDir = mPath.isNull() ? mHomeDir :
     257        VBoxGlobal::getFirstExistingDir (mPath);
     258    if (initDir.isNull())
     259        initDir = mHomeDir;
     260
     261    /* Open existing file or directory. */
     262    QString path = mMode == Mode_File ?
     263        VBoxGlobal::getOpenFileName (initDir, QString::null, parentWidget(), QString::null) :
     264        VBoxGlobal::getExistingDirectory (initDir, parentWidget());
     265    if (path.isNull())
     266        return;
     267
     268    path.remove (QRegExp ("[\\\\/]$"));
     269    setPath (path);
     270}
     271
    213272QIcon VBoxFilePathSelectorWidget::defaultIcon() const
    214273{
     
    219278}
    220279
    221 QString VBoxFilePathSelectorWidget::fullPath (bool aAbsolute) const
    222 {
    223     if (!mPath.isNull())
    224     {
    225         switch (mMode)
    226         {
    227             case Mode_Folder:
    228                 return aAbsolute ? QDir (mPath).absolutePath() :
    229                                    QDir (mPath).path();
    230             case Mode_File:
    231                 return aAbsolute ? QFileInfo (mPath).absoluteFilePath() :
    232                                    QFileInfo (mPath).filePath();
    233             default:
    234                 AssertFailedBreak();
    235         }
    236     }
    237     return QString::null;
     280QString VBoxFilePathSelectorWidget::fullPath (bool aAbsolute /* = true */) const
     281{
     282    if (mPath.isNull())
     283        return mPath;
     284
     285    QString result;
     286    switch (mMode)
     287    {
     288        case Mode_Folder:
     289            result = aAbsolute ? QDir (mPath).absolutePath() :
     290                                 QDir (mPath).path();
     291            break;
     292        case Mode_File:
     293            result = aAbsolute ? QFileInfo (mPath).absoluteFilePath() :
     294                                 QFileInfo (mPath).filePath();
     295            break;
     296        default:
     297            AssertFailedBreak();
     298    }
     299    return QDir::toNativeSeparators (result);
    238300}
    239301
     
    245307
    246308    int oldSize = fontMetrics().width (fullText);
    247     int indentSize = fontMetrics().width ("...x");
     309    int indentSize = fontMetrics().width ("x...x");
    248310
    249311    /* Compress text */
     
    281343void VBoxFilePathSelectorWidget::refreshText()
    282344{
    283     if (mPath.isNull())
    284     {
     345    if (mIsEditableMode)
     346    {
     347        /* In editable mode there should be no any icon
     348         * and text have be corresponding real stored path
     349         * which can be absolute or relative. */
     350        setItemText (PathId, mPath);
     351        setItemIcon (PathId, QIcon());
     352    }
     353    else if (mPath.isNull())
     354    {
     355        /* If we are not in editable mode and no path is
     356         * stored here - show the translated 'none' string. */
    285357        if (itemText (PathId) != mNoneStr)
    286358        {
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxGLSettingsGeneral.cpp

    r11427 r11497  
    3131    Ui::VBoxGLSettingsGeneral::setupUi (this);
    3232
     33    mPsVdi->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
     34    mPsMach->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
     35    mPsVRDP->setHomeDir (vboxGlobal().virtualBox().GetHomeFolder());
    3336    mPsVRDP->setMode (VBoxFilePathSelectorWidget::Mode_File);
    34 
    35     /* Setup connections */
    36     connect (mPsVdi,  SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));
    37     connect (mPsMach, SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));
    38     connect (mPsVRDP, SIGNAL (selectPath()), this, SLOT (onSelectFolderClicked()));
    3937
    4038    /* Applying language settings */
     
    8684}
    8785
    88 void VBoxGLSettingsGeneral::onSelectFolderClicked()
    89 {
    90     VBoxFilePathSelectorWidget *ps = qobject_cast<VBoxFilePathSelectorWidget*> (sender());
    91     Assert (ps);
    92 
    93     QString initDir = VBoxGlobal::getFirstExistingDir (ps->path());
    94     if (initDir.isNull())
    95         initDir = vboxGlobal().virtualBox().GetHomeFolder();
    96 
    97 
    98     QString path = ps == mPsVRDP ?
    99         VBoxGlobal::getOpenFileName (initDir, QString::null, this, QString::null) :
    100         VBoxGlobal::getExistingDirectory (initDir, this);
    101     if (path.isNull())
    102         return;
    103 
    104     path = QDir::convertSeparators (path);
    105     /* remove trailing slash if any */
    106     path.remove (QRegExp ("[\\\\/]$"));
    107 
    108     ps->setPath (path);
    109 }
    110 
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsGeneral.cpp

    r11427 r11497  
    7575    connect (mLeVideo, SIGNAL (textChanged (const QString&)),
    7676             this, SLOT (textChangedVRAM (const QString&)));
    77     connect (mPsSnapshot, SIGNAL (selectPath()),
    78              this, SLOT (selectSnapshotFolder()));
    7977    connect (mTbBootItemUp, SIGNAL (clicked()),
    8078             this, SLOT (moveBootItemUp()));
     
    215213    /* Snapshot folder */
    216214    mPsSnapshot->setPath (aMachine.GetSnapshotFolder());
     215    mPsSnapshot->setHomeDir (QFileInfo (mMachine.GetSettingsFilePath()).absolutePath());
    217216
    218217    /* Description */
     
    446445    mTbBootItemUp->setEnabled (upEnabled);
    447446    mTbBootItemDown->setEnabled (downEnabled);
    448 }
    449 
    450 void VBoxVMSettingsGeneral::selectSnapshotFolder()
    451 {
    452     QString settingsFolder = VBoxGlobal::getFirstExistingDir (mPsSnapshot->path());
    453     if (settingsFolder.isNull())
    454         settingsFolder = QFileInfo (mMachine.GetSettingsFilePath()).absolutePath();
    455 
    456     QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
    457     if (folder.isNull())
    458         return;
    459 
    460     folder = QDir::convertSeparators (folder);
    461     /* Remove trailing slash if any */
    462     folder.remove (QRegExp ("[\\\\/]$"));
    463 
    464     mPsSnapshot->setPath (folder);
    465447}
    466448
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsSFDetails.cpp

    r11361 r11497  
    4444    /* No reset button */
    4545    mPsPath->setResetEnabled (false);
    46     connect (mPsPath, SIGNAL (selectPath()),
    47              this, SLOT (selectPath()));
     46    connect (mPsPath, SIGNAL (currentIndexChanged (int)),
     47             this, SLOT (onSelectPath()));
    4848
    4949    connect (mLeName, SIGNAL (textChanged (const QString &)),
     
    141141}
    142142
    143 void VBoxVMSettingsSFDetails::selectPath()
     143void VBoxVMSettingsSFDetails::onSelectPath()
    144144{
    145     QString folderName = vboxGlobal()
    146         .getExistingDirectory (mPsPath->path().isEmpty() ? QDir::homePath() : mPsPath->path(),
    147                                this,
    148                                tr ("Select a folder to share"));
    149     if (folderName.isNull())
     145    if (!mPsPath->isPathLineChosen())
    150146        return;
    151147
     148    QString folderName (mPsPath->path());
    152149    QDir folder (folderName);
    153     mPsPath->setPath (QDir::toNativeSeparators (folder.absolutePath()));
    154150    if (!folder.isRoot())
    155         /* processing non-root folder */
     151        /* Processing non-root folder */
    156152        mLeName->setText (folder.dirName());
    157153    else
    158154    {
    159         /* processing root folder */
     155        /* Processing root folder */
    160156#if defined (Q_OS_WIN) || defined (Q_OS_OS2)
    161157        mLeName->setText (folderName.toUpper()[0] + "_DRIVE");
     
    166162    /* Validate the fields */
    167163    validate();
    168 
    169164}
    170165
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