Changeset 77702 in vbox
- Timestamp:
- Mar 14, 2019 2:02:18 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r77677 r77702 891 891 src/widgets/UISpecialControls.h \ 892 892 src/widgets/UIStatusBarEditorWindow.h \ 893 src/widgets/UISearchLineEdit.h \ 893 894 src/widgets/UIToolBar.h \ 894 895 src/widgets/UIWarningPane.h \ … … 978 979 src/logviewer/UIVMLogViewerTextEdit.cpp \ 979 980 src/medium/UIMediumEnumerator.cpp \ 980 src/medium/UIMediumSearchWidget.cpp \981 981 src/medium/viso/UIVisoContentBrowser.cpp \ 982 982 src/medium/viso/UIVisoHostBrowser.cpp \ … … 1366 1366 src/widgets/UIProgressDialog.cpp \ 1367 1367 src/widgets/UIScaleFactorEditor.cpp \ 1368 src/widgets/UISearchLineEdit.cpp \ 1368 1369 src/widgets/UISlidingToolBar.cpp \ 1369 1370 src/widgets/UISpecialControls.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp
r77261 r77702 29 29 #include "UIMediumItem.h" 30 30 #include "UIMediumSearchWidget.h" 31 31 #include "UISearchLineEdit.h" 32 32 33 33 #ifdef VBOX_WS_MAC … … 73 73 QString m_strSearchTerm; 74 74 }; 75 76 77 /*********************************************************************************************************************************78 * UISearchLineEdit definition . *79 *********************************************************************************************************************************/80 81 class UISearchLineEdit : public QLineEdit82 {83 84 Q_OBJECT;85 86 public:87 88 UISearchLineEdit(QWidget *pParent = 0);89 void setMatchCount(int iMatchCount);90 void setScroolToIndex(int iScrollToIndex);91 92 protected:93 94 virtual void paintEvent(QPaintEvent *pEvent) /* override */;95 96 private:97 98 int m_iMatchCount;99 int m_iScrollToIndex;100 };101 102 103 /*********************************************************************************************************************************104 * UISearchLineEdit implementation . *105 *********************************************************************************************************************************/106 107 UISearchLineEdit::UISearchLineEdit(QWidget *pParent /* = 0 */)108 :QLineEdit(pParent)109 , m_iMatchCount(0)110 , m_iScrollToIndex(-1)111 {112 }113 114 void UISearchLineEdit::paintEvent(QPaintEvent *pEvent)115 {116 QLineEdit::paintEvent(pEvent);117 118 /* No search terms. no search. nothing to show here. mone along please: */119 if (text().isEmpty())120 return;121 122 QPainter painter(this);123 QFont pfont = font();124 QString strText = QString("%1/%2").arg(QString::number(m_iScrollToIndex + 1)).arg(QString::number(m_iMatchCount));125 QSize textSize(QApplication::fontMetrics().width(strText),126 QApplication::fontMetrics().height());127 128 /* Dont draw anything if we dont have enough space: */129 if (textSize.width() > 0.5 * width())130 return;131 int iTopMargin = (height() - textSize.height()) / 2;132 int iRightMargin = iTopMargin;133 134 135 QColor fontColor(Qt::darkGray);136 painter.setPen(fontColor);137 painter.setFont(pfont);138 139 painter.drawText(QRect(width() - textSize.width() - iRightMargin, iTopMargin, textSize.width(), textSize.height()),140 Qt::AlignCenter | Qt::AlignVCenter, strText);141 }142 143 void UISearchLineEdit::setMatchCount(int iMatchCount)144 {145 if (m_iMatchCount == iMatchCount)146 return;147 m_iMatchCount = iMatchCount;148 repaint();149 }150 151 void UISearchLineEdit::setScroolToIndex(int iScrollToIndex)152 {153 if (m_iScrollToIndex == iScrollToIndex)154 return;155 m_iScrollToIndex = iScrollToIndex;156 repaint();157 }158 159 75 160 76 /********************************************************************************************************************************* … … 348 264 m_pSearchTermLineEdit->setScroolToIndex(iScrollToIndex); 349 265 } 350 351 #include "UIMediumSearchWidget.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.h
r77261 r77702 31 31 class QITreeWidget; 32 32 class UISearchLineEdit; 33 34 33 35 34 /** QWidget extension providing a simple way to enter a earch term and search type for medium searching -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp
r77701 r77702 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI LineTextEdit class definitions.3 * VBox Qt GUI - UIsearchLineEdit class definitions. 4 4 */ 5 5 … … 16 16 */ 17 17 18 /* Qt includes: */ 19 #include <QDialogButtonBox> 20 #include <QFile> 21 #include <QLineEdit> 22 #include <QPushButton> 23 #include <QTextEdit> 24 #include <QTextStream> 25 #include <QVBoxLayout> 18 /* Qt includes */ 19 #include <QApplication> 20 #include <QPainter> 26 21 27 22 /* GUI includes: */ 28 #include "QIFileDialog.h" 29 #include "VBoxGlobal.h" 30 #include "UILineTextEdit.h" 23 #include "UISearchLineEdit.h" 24 25 UISearchLineEdit::UISearchLineEdit(QWidget *pParent /* = 0 */) 26 :QLineEdit(pParent) 27 , m_iMatchCount(0) 28 , m_iScrollToIndex(-1) 29 { 30 } 31 32 void UISearchLineEdit::paintEvent(QPaintEvent *pEvent) 33 { 34 QLineEdit::paintEvent(pEvent); 35 36 /* No search terms. no search. nothing to show here. mone along please: */ 37 if (text().isEmpty()) 38 return; 39 40 QPainter painter(this); 41 QFont pfont = font(); 42 QString strText = QString("%1/%2").arg(QString::number(m_iScrollToIndex + 1)).arg(QString::number(m_iMatchCount)); 43 QSize textSize(QApplication::fontMetrics().width(strText), 44 QApplication::fontMetrics().height()); 45 46 /* Dont draw anything if we dont have enough space: */ 47 if (textSize.width() > 0.5 * width()) 48 return; 49 int iTopMargin = (height() - textSize.height()) / 2; 50 int iRightMargin = iTopMargin; 31 51 32 52 33 //////////////////////////////////////////////////////////////////////////////// 34 // UITextEditor 53 QColor fontColor(Qt::darkGray); 54 painter.setPen(fontColor); 55 painter.setFont(pfont); 35 56 36 UITextEditor::UITextEditor(QWidget *pParent /* = NULL */) 37 : QIWithRetranslateUI<QIDialog>(pParent) 38 { 39 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 40 pMainLayout->setMargin(12); 41 42 /* We need a text editor */ 43 m_pTextEdit = new QTextEdit(this); 44 pMainLayout->addWidget(m_pTextEdit); 45 /* and some buttons to interact with */ 46 m_pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 47 m_pOpenButton = new QPushButton(this); 48 m_pButtonBox->addButton(m_pOpenButton, QDialogButtonBox::ActionRole); 49 pMainLayout->addWidget(m_pButtonBox); 50 /* Connect the buttons so that they are useful */ 51 connect(m_pButtonBox, SIGNAL(accepted()), 52 this, SLOT(accept())); 53 connect(m_pButtonBox, SIGNAL(rejected()), 54 this, SLOT(reject())); 55 connect(m_pOpenButton, SIGNAL(clicked()), 56 this, SLOT(open())); 57 58 /* Applying language settings */ 59 retranslateUi(); 57 painter.drawText(QRect(width() - textSize.width() - iRightMargin, iTopMargin, textSize.width(), textSize.height()), 58 Qt::AlignCenter | Qt::AlignVCenter, strText); 60 59 } 61 60 62 void UI TextEditor::setText(const QString& strText)61 void UISearchLineEdit::setMatchCount(int iMatchCount) 63 62 { 64 m_pTextEdit->setText(strText); 63 if (m_iMatchCount == iMatchCount) 64 return; 65 m_iMatchCount = iMatchCount; 66 repaint(); 65 67 } 66 68 67 QString UITextEditor::text() const 69 void UISearchLineEdit::setScroolToIndex(int iScrollToIndex) 68 70 { 69 return m_pTextEdit->toPlainText(); 71 if (m_iScrollToIndex == iScrollToIndex) 72 return; 73 m_iScrollToIndex = iScrollToIndex; 74 repaint(); 70 75 } 71 72 void UITextEditor::retranslateUi()73 {74 setWindowTitle(tr("Edit text"));75 m_pOpenButton->setText(tr("&Replace..."));76 m_pOpenButton->setToolTip(tr("Replaces the current text with the content of a file."));77 }78 79 void UITextEditor::open()80 {81 QString fileName = QIFileDialog::getOpenFileName(vboxGlobal().documentsPath(), tr("Text (*.txt);;All (*.*)"), this, tr("Select a file to open..."));82 if (!fileName.isEmpty())83 {84 QFile file(fileName);85 if (file.open(QFile::ReadOnly))86 {87 QTextStream in(&file);88 m_pTextEdit->setPlainText(in.readAll());89 }90 }91 92 }93 94 ////////////////////////////////////////////////////////////////////////////////95 // UILineTextEdit96 97 UILineTextEdit::UILineTextEdit(QWidget *pParent /* = NULL */)98 : QIWithRetranslateUI<QPushButton>(pParent)99 {100 connect(this, SIGNAL(clicked()),101 this, SLOT(edit()));102 103 /* Don't interpret the Enter Key. */104 setAutoDefault(false);105 setDefault(false);106 107 setFocusPolicy(Qt::StrongFocus);108 retranslateUi();109 }110 111 void UILineTextEdit::retranslateUi()112 {113 QPushButton::setText(tr("&Edit"));114 }115 116 void UILineTextEdit::edit()117 {118 UITextEditor te(this);119 te.setText(m_strText);120 if (te.exec() == QDialog::Accepted)121 {122 m_strText = te.text();123 /* Notify listener(s) about we finished: */124 emit sigFinished(this);125 }126 }127 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.h
r77701 r77702 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox Qt GUI - UI LineTextEdit class declaration.3 * VBox Qt GUI - UISearchLineEdit class declaration. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef FEQT_INCLUDED_SRC_widgets_UI LineTextEdit_h19 #define FEQT_INCLUDED_SRC_widgets_UI LineTextEdit_h18 #ifndef FEQT_INCLUDED_SRC_widgets_UISearchLineEdit_h 19 #define FEQT_INCLUDED_SRC_widgets_UISearchLineEdit_h 20 20 #ifndef RT_WITHOUT_PRAGMA_ONCE 21 21 # pragma once 22 22 #endif 23 23 24 /* VBox includes */25 #include "QIDialog.h"26 #include "QIWithRetranslateUI.h"27 24 28 25 /* Qt includes */ 29 #include <Q PushButton>26 #include <QLineEdit> 30 27 31 /* Qt forward declarations */ 32 class QTextEdit; 33 class QDialogButtonBox; 28 /* GUI includes: */ 29 #include "UILibraryDefs.h" 34 30 35 //////////////////////////////////////////////////////////////////////////////// 36 // UITextEditor 31 /** A QLineEdit extension with an overlay label drawn on the right hand side of it. 32 * mostly used for entering a search term and then label show total number of matched items 33 * and currently selected, scrolled item. */ 34 class SHARED_LIBRARY_STUFF 35 UISearchLineEdit : public QLineEdit 36 { 37 37 38 class UITextEditor: public QIWithRetranslateUI<QIDialog>39 {40 38 Q_OBJECT; 41 39 42 40 public: 43 UITextEditor(QWidget *pParent = NULL);44 41 45 void setText(const QString& strText); 46 QString text() const; 42 UISearchLineEdit(QWidget *pParent = 0); 43 void setMatchCount(int iMatchCount); 44 void setScroolToIndex(int iScrollToIndex); 47 45 48 46 protected: 49 void retranslateUi();50 47 51 private slots: 52 void open(); 48 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 53 49 54 50 private: 55 /* Private member vars */ 56 QTextEdit *m_pTextEdit; 57 QDialogButtonBox *m_pButtonBox; 58 QPushButton *m_pOpenButton; 51 52 int m_iMatchCount; 53 int m_iScrollToIndex; 59 54 }; 60 55 61 //////////////////////////////////////////////////////////////////////////////// 62 // UILineTextEdit 63 64 class UILineTextEdit: public QIWithRetranslateUI<QPushButton> 65 { 66 Q_OBJECT; 67 68 signals: 69 70 /* Notifier: Editing stuff: */ 71 void sigFinished(QWidget *pThis); 72 73 public: 74 UILineTextEdit(QWidget *pParent = NULL); 75 76 void setText(const QString& strText) { m_strText = strText; } 77 QString text() const { return m_strText; } 78 79 protected: 80 void retranslateUi(); 81 82 private slots: 83 void edit(); 84 85 private: 86 /* Private member vars */ 87 QString m_strText; 88 }; 89 90 #endif /* !FEQT_INCLUDED_SRC_widgets_UILineTextEdit_h */ 91 56 #endif /* !FEQT_INCLUDED_SRC_widgets_UISearchLineEdit_h */
Note:
See TracChangeset
for help on using the changeset viewer.