VirtualBox

Changeset 11845 in vbox for trunk/src


Ignore:
Timestamp:
Aug 29, 2008 6:50:53 PM (16 years ago)
Author:
vboxsync
Message:

Fe/Qt4: File/Folder path selector I-Beam cursor positioning fix for entering edit-mode.

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

Legend:

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

    r11511 r11845  
    6868    void focusInEvent (QFocusEvent *aEvent);
    6969    void focusOutEvent (QFocusEvent *aEvent);
     70    bool eventFilter (QObject *aObj, QEvent *aEv);
    7071    void retranslateUi();
    7172
     
    7475    void onActivated (int aIndex);
    7576    void copyToClipboard();
     77    void refreshText();
    7678
    7779private:
     
    8183    QString fullPath (bool aAbsolute = true) const;
    8284    QString shrinkText (int aWidth) const;
    83     void refreshText();
    8485
    8586    /* Private member vars */
     
    9293    QString mNoneTip;
    9394    bool mIsEditableMode;
     95    bool mIsMouseAwaited;
    9496};
    9597
  • trunk/src/VBox/Frontends/VirtualBox4/src/VBoxFilePathSelectorWidget.cpp

    r11653 r11845  
    3131#include <QFileIconProvider>
    3232#include <QLineEdit>
     33#include <QTimer>
    3334
    3435enum
     
    3839    ResetId
    3940};
     41
     42/**
     43 * Returns first position of difference between passed strings.
     44 */
     45static int differFrom (const QString &aS1, const QString &aS2)
     46{
     47    if (aS1 == aS2)
     48        return -1;
     49
     50    int minLength = qMin (aS1.size(), aS2.size());
     51    int index = 0;
     52    for (index = 0; index < minLength ; ++ index)
     53        if (aS1 [index] != aS2 [index])
     54            break;
     55    return index;
     56}
    4057
    4158VBoxFilePathSelectorWidget::VBoxFilePathSelectorWidget (QWidget *aParent)
     
    4663    , mHomeDir (QDir::current().absolutePath())
    4764    , mIsEditableMode (false)
     65    , mIsMouseAwaited (false)
    4866{
    4967    /* Populate items */
     
    7694    /* Applying language settings */
    7795    retranslateUi();
     96
     97    /* Installing necessary event filters */
     98    lineEdit()->installEventFilter (this);
    7899}
    79100
     
    156177    {
    157178        mIsEditableMode = true;
    158         refreshText();
     179        if (aEvent->reason() == Qt::MouseFocusReason)
     180            mIsMouseAwaited = true;
     181        else
     182            refreshText();
    159183    }
    160184    QIWithRetranslateUI<QComboBox>::focusInEvent (aEvent);
     
    169193    }
    170194    QIWithRetranslateUI<QComboBox>::focusOutEvent (aEvent);
     195}
     196
     197bool VBoxFilePathSelectorWidget::eventFilter (QObject *aObj, QEvent *aEv)
     198{
     199    if (mIsMouseAwaited && (aEv->type() == QEvent::MouseButtonPress))
     200        QTimer::singleShot (0, this, SLOT (refreshText()));
     201
     202    return QIWithRetranslateUI<QComboBox>::eventFilter (aObj, aEv);
    171203}
    172204
     
    353385    if (mIsEditableMode)
    354386    {
     387        /* Cursor positioning variables */
     388        int curPos = -1;
     389        int diffPos = -1;
     390        int fromRight = -1;
     391
     392        if (mIsMouseAwaited)
     393        {
     394            /* Store the cursor position */
     395            curPos = lineEdit()->cursorPosition();
     396            diffPos = differFrom (lineEdit()->text(), mPath);
     397            fromRight = lineEdit()->text().size() - curPos;
     398        }
     399
    355400        /* In editable mode there should be no any icon
    356401         * and text have be corresponding real stored path
     
    361406            tr ("Please type the desired folder path here.") :
    362407            tr ("Please type the desired file path here."));
     408
     409        if (mIsMouseAwaited)
     410        {
     411            mIsMouseAwaited = false;
     412
     413            /* Restore the position to the right of dots */
     414            if (diffPos != -1 && curPos >= diffPos + 3)
     415                lineEdit()->setCursorPosition (lineEdit()->text().size() -
     416                                               fromRight);
     417            /* Restore the position to the center of text */
     418            else if (diffPos != -1 && curPos > diffPos)
     419                lineEdit()->setCursorPosition (lineEdit()->text().size() / 2);
     420            /* Restore the position to the left of dots */
     421            else
     422                lineEdit()->setCursorPosition (curPos);
     423        }
    363424    }
    364425    else if (mPath.isNull())
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