VirtualBox

Changeset 72227 in vbox for trunk


Ignore:
Timestamp:
May 17, 2018 8:11:13 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:6769: Replacing the path line edit with a label UIVMNamePathSelector

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r72220 r72227  
    11781178        src/widgets/UIPortForwardingTable.cpp \
    11791179        src/widgets/UIProgressDialog.cpp \
    1180         src/widgets/UIStatusBarEditorWindow.cpp
     1180        src/widgets/UIStatusBarEditorWindow.cpp \
     1181        src/widgets/UIVMNamePathSelector.cpp
    11811182
    11821183 ifdef VBOX_GUI_WITH_NETWORK_MANAGER
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.cpp

    r72226 r72227  
    2121
    2222/* Qt includes: */
     23# include <QFontMetrics>
    2324# include <QDir>
    2425# include <QHBoxLayout>
     
    4041#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4142
     43const float UIVMNamePathSelector::s_fPathLabelWidthWeight = 0.65;
     44
     45class UIPathLabel : public QLabel
     46{
     47
     48    Q_OBJECT;
     49
     50public:
     51
     52    UIPathLabel(QWidget *parent = 0);
     53
     54    int maxWidth() const;
     55    void setMaxWidth(int width);
     56    void setText(const QString &text);
     57
     58private:
     59
     60    /** Compact the text this is not wider than maxWidth */
     61    void compactText();
     62
     63    int m_maxWidth;
     64    QString m_strOriginalText;
     65};
     66
     67UIPathLabel::UIPathLabel(QWidget *parent /* = 0*/)
     68    :QLabel(parent)
     69    , m_maxWidth(0)
     70{
     71}
     72
     73void UIPathLabel::compactText()
     74{
     75    QFontMetrics fontMetrics = this->fontMetrics();
     76    QString strCompactedText = fontMetrics.elidedText(m_strOriginalText, Qt::ElideMiddle, m_maxWidth);
     77    QLabel::setText(strCompactedText);
     78}
     79
     80int UIPathLabel::maxWidth() const
     81{
     82    return m_maxWidth;
     83}
     84
     85void UIPathLabel::setMaxWidth(int width)
     86{
     87    if (m_maxWidth == width)
     88        return;
     89    m_maxWidth = width;
     90    compactText();
     91}
     92
     93void UIPathLabel::setText(const QString &text)
     94{
     95    if (m_strOriginalText == text)
     96        return;
     97
     98    m_strOriginalText = text;
     99    compactText();
     100}
     101
     102
    42103UIVMNamePathSelector::UIVMNamePathSelector(QWidget *pParent /* = 0 */)
    43104    : QIWithRetranslateUI<QWidget>(pParent)
     
    45106    , m_pPath(0)
    46107    , m_pName(0)
    47     , m_pSeparator(0)
    48108    ,m_pFileDialogButton(0)
    49109{
     
    85145    }
    86146
    87     m_pPath = new QILineEdit;
     147    m_pPath = new UIPathLabel;
    88148    if (m_pPath)
    89149    {
    90150        m_pMainLayout->addWidget(m_pPath);
    91         m_pPath->setReadOnly(true);
    92151        setPath(defaultMachineFolder());
    93     }
    94     m_pSeparator = new QILabel;
    95     if (m_pSeparator)
    96     {
    97         m_pSeparator->setText(QDir::separator());
    98         m_pMainLayout->addWidget(m_pSeparator);
     152        m_pPath->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    99153    }
    100154
     
    121175        return;
    122176    m_strNonNativePath = path;
     177
    123178    if (m_pPath)
    124179    {
    125180        QString nativePath(QDir::toNativeSeparators(path));
     181        /** make sure we have a trailing seperator */
     182        if (!nativePath.isEmpty() && !nativePath.endsWith(QDir::toNativeSeparators("/")))
     183            nativePath += QDir::toNativeSeparators("/");
    126184        m_pPath->setText(nativePath);
    127         m_pPath->setFixedWidthByText(nativePath);
    128185    }
    129186    emit sigPathChanged(m_strNonNativePath);
     
    155212}
    156213
     214void UIVMNamePathSelector::resizeEvent(QResizeEvent *pEvent)
     215{
     216    QWidget::resizeEvent(pEvent);
     217
     218    if (m_pPath)
     219        m_pPath->setMaxWidth(s_fPathLabelWidthWeight * width());
     220}
     221
    157222void UIVMNamePathSelector::sltOpenPathSelector()
    158223{
     
    184249    return m_strToolTipText;
    185250}
     251
     252#include "UIVMNamePathSelector.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.h

    r72226 r72227  
    2727/* Forward declarations: */
    2828class QHBoxLayout;
    29 class QILabel;
    3029class QILineEdit;
    3130class QIToolButton;
     31class UIPathLabel;
    3232
    3333class SHARED_LIBRARY_STUFF UIVMNamePathSelector : public QIWithRetranslateUI<QWidget>
     
    5959
    6060    void retranslateUi() /* override */;
     61    virtual void resizeEvent(QResizeEvent *pEvent) /* override */;
    6162
    6263private slots:
     
    7071
    7172    QHBoxLayout  *m_pMainLayout;
    72     QILineEdit   *m_pPath;
     73    UIPathLabel  *m_pPath;
    7374    QILineEdit   *m_pName;
    74     QILabel      *m_pSeparator;
    7575    QIToolButton *m_pFileDialogButton;
    7676    /** Tooltip set is set by clients of this widget. */
     
    7878    /** Path string whose separators are not converted to native ones. */
    7979    QString       m_strNonNativePath;
     80    /** This widget's width is multiplied with this weight to compute max.
     81     * width the path label can have */
     82    static const float s_fPathLabelWidthWeight;
    8083};
    8184
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