- Timestamp:
- May 17, 2018 8:11:13 AM (7 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r72220 r72227 1178 1178 src/widgets/UIPortForwardingTable.cpp \ 1179 1179 src/widgets/UIProgressDialog.cpp \ 1180 src/widgets/UIStatusBarEditorWindow.cpp 1180 src/widgets/UIStatusBarEditorWindow.cpp \ 1181 src/widgets/UIVMNamePathSelector.cpp 1181 1182 1182 1183 ifdef VBOX_GUI_WITH_NETWORK_MANAGER -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.cpp
r72226 r72227 21 21 22 22 /* Qt includes: */ 23 # include <QFontMetrics> 23 24 # include <QDir> 24 25 # include <QHBoxLayout> … … 40 41 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 41 42 43 const float UIVMNamePathSelector::s_fPathLabelWidthWeight = 0.65; 44 45 class UIPathLabel : public QLabel 46 { 47 48 Q_OBJECT; 49 50 public: 51 52 UIPathLabel(QWidget *parent = 0); 53 54 int maxWidth() const; 55 void setMaxWidth(int width); 56 void setText(const QString &text); 57 58 private: 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 67 UIPathLabel::UIPathLabel(QWidget *parent /* = 0*/) 68 :QLabel(parent) 69 , m_maxWidth(0) 70 { 71 } 72 73 void 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 80 int UIPathLabel::maxWidth() const 81 { 82 return m_maxWidth; 83 } 84 85 void UIPathLabel::setMaxWidth(int width) 86 { 87 if (m_maxWidth == width) 88 return; 89 m_maxWidth = width; 90 compactText(); 91 } 92 93 void UIPathLabel::setText(const QString &text) 94 { 95 if (m_strOriginalText == text) 96 return; 97 98 m_strOriginalText = text; 99 compactText(); 100 } 101 102 42 103 UIVMNamePathSelector::UIVMNamePathSelector(QWidget *pParent /* = 0 */) 43 104 : QIWithRetranslateUI<QWidget>(pParent) … … 45 106 , m_pPath(0) 46 107 , m_pName(0) 47 , m_pSeparator(0)48 108 ,m_pFileDialogButton(0) 49 109 { … … 85 145 } 86 146 87 m_pPath = new QILineEdit;147 m_pPath = new UIPathLabel; 88 148 if (m_pPath) 89 149 { 90 150 m_pMainLayout->addWidget(m_pPath); 91 m_pPath->setReadOnly(true);92 151 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); 99 153 } 100 154 … … 121 175 return; 122 176 m_strNonNativePath = path; 177 123 178 if (m_pPath) 124 179 { 125 180 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("/"); 126 184 m_pPath->setText(nativePath); 127 m_pPath->setFixedWidthByText(nativePath);128 185 } 129 186 emit sigPathChanged(m_strNonNativePath); … … 155 212 } 156 213 214 void UIVMNamePathSelector::resizeEvent(QResizeEvent *pEvent) 215 { 216 QWidget::resizeEvent(pEvent); 217 218 if (m_pPath) 219 m_pPath->setMaxWidth(s_fPathLabelWidthWeight * width()); 220 } 221 157 222 void UIVMNamePathSelector::sltOpenPathSelector() 158 223 { … … 184 249 return m_strToolTipText; 185 250 } 251 252 #include "UIVMNamePathSelector.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.h
r72226 r72227 27 27 /* Forward declarations: */ 28 28 class QHBoxLayout; 29 class QILabel;30 29 class QILineEdit; 31 30 class QIToolButton; 31 class UIPathLabel; 32 32 33 33 class SHARED_LIBRARY_STUFF UIVMNamePathSelector : public QIWithRetranslateUI<QWidget> … … 59 59 60 60 void retranslateUi() /* override */; 61 virtual void resizeEvent(QResizeEvent *pEvent) /* override */; 61 62 62 63 private slots: … … 70 71 71 72 QHBoxLayout *m_pMainLayout; 72 QILineEdit*m_pPath;73 UIPathLabel *m_pPath; 73 74 QILineEdit *m_pName; 74 QILabel *m_pSeparator;75 75 QIToolButton *m_pFileDialogButton; 76 76 /** Tooltip set is set by clients of this widget. */ … … 78 78 /** Path string whose separators are not converted to native ones. */ 79 79 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; 80 83 }; 81 84
Note:
See TracChangeset
for help on using the changeset viewer.