VirtualBox

Changeset 77702 in vbox


Ignore:
Timestamp:
Mar 14, 2019 2:02:18 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: Factoring out UISearchLineEdit as it will be used in vm search widget as well.

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

Legend:

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

    r77677 r77702  
    891891        src/widgets/UISpecialControls.h \
    892892        src/widgets/UIStatusBarEditorWindow.h \
     893        src/widgets/UISearchLineEdit.h \
    893894        src/widgets/UIToolBar.h \
    894895        src/widgets/UIWarningPane.h \
     
    978979        src/logviewer/UIVMLogViewerTextEdit.cpp \
    979980        src/medium/UIMediumEnumerator.cpp \
    980         src/medium/UIMediumSearchWidget.cpp \
    981981        src/medium/viso/UIVisoContentBrowser.cpp \
    982982        src/medium/viso/UIVisoHostBrowser.cpp \
     
    13661366        src/widgets/UIProgressDialog.cpp \
    13671367        src/widgets/UIScaleFactorEditor.cpp \
     1368        src/widgets/UISearchLineEdit.cpp \
    13681369        src/widgets/UISlidingToolBar.cpp \
    13691370        src/widgets/UISpecialControls.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp

    r77261 r77702  
    2929#include "UIMediumItem.h"
    3030#include "UIMediumSearchWidget.h"
    31 
     31#include "UISearchLineEdit.h"
    3232
    3333#ifdef VBOX_WS_MAC
     
    7373    QString m_strSearchTerm;
    7474};
    75 
    76 
    77 /*********************************************************************************************************************************
    78 *   UISearchLineEdit definition             .                                                                                    *
    79 *********************************************************************************************************************************/
    80 
    81 class UISearchLineEdit : public QLineEdit
    82 {
    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 
    15975
    16076/*********************************************************************************************************************************
     
    348264    m_pSearchTermLineEdit->setScroolToIndex(iScrollToIndex);
    349265}
    350 
    351 #include "UIMediumSearchWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.h

    r77261 r77702  
    3131class QITreeWidget;
    3232class UISearchLineEdit;
    33 
    3433
    3534/** 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  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UILineTextEdit class definitions.
     3 * VBox Qt GUI - UIsearchLineEdit class definitions.
    44 */
    55
     
    1616 */
    1717
    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>
    2621
    2722/* GUI includes: */
    28 #include "QIFileDialog.h"
    29 #include "VBoxGlobal.h"
    30 #include "UILineTextEdit.h"
     23#include "UISearchLineEdit.h"
     24
     25UISearchLineEdit::UISearchLineEdit(QWidget *pParent /* = 0 */)
     26    :QLineEdit(pParent)
     27    , m_iMatchCount(0)
     28    , m_iScrollToIndex(-1)
     29{
     30}
     31
     32void 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;
    3151
    3252
    33 ////////////////////////////////////////////////////////////////////////////////
    34 // UITextEditor
     53    QColor fontColor(Qt::darkGray);
     54    painter.setPen(fontColor);
     55    painter.setFont(pfont);
    3556
    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);
    6059}
    6160
    62 void UITextEditor::setText(const QString& strText)
     61void UISearchLineEdit::setMatchCount(int iMatchCount)
    6362{
    64     m_pTextEdit->setText(strText);
     63    if (m_iMatchCount == iMatchCount)
     64        return;
     65    m_iMatchCount = iMatchCount;
     66    repaint();
    6567}
    6668
    67 QString UITextEditor::text() const
     69void UISearchLineEdit::setScroolToIndex(int iScrollToIndex)
    6870{
    69     return m_pTextEdit->toPlainText();
     71    if (m_iScrollToIndex == iScrollToIndex)
     72        return;
     73    m_iScrollToIndex = iScrollToIndex;
     74    repaint();
    7075}
    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 // UILineTextEdit
    96 
    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  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UILineTextEdit class declaration.
     3 * VBox Qt GUI - UISearchLineEdit class declaration.
    44 */
    55
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_widgets_UILineTextEdit_h
    19 #define FEQT_INCLUDED_SRC_widgets_UILineTextEdit_h
     18#ifndef FEQT_INCLUDED_SRC_widgets_UISearchLineEdit_h
     19#define FEQT_INCLUDED_SRC_widgets_UISearchLineEdit_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
    2222#endif
    2323
    24 /* VBox includes */
    25 #include "QIDialog.h"
    26 #include "QIWithRetranslateUI.h"
    2724
    2825/* Qt includes */
    29 #include <QPushButton>
     26#include <QLineEdit>
    3027
    31 /* Qt forward declarations */
    32 class QTextEdit;
    33 class QDialogButtonBox;
     28/* GUI includes: */
     29#include "UILibraryDefs.h"
    3430
    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. */
     34class SHARED_LIBRARY_STUFF
     35UISearchLineEdit : public QLineEdit
     36{
    3737
    38 class UITextEditor: public QIWithRetranslateUI<QIDialog>
    39 {
    4038    Q_OBJECT;
    4139
    4240public:
    43     UITextEditor(QWidget *pParent = NULL);
    4441
    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);
    4745
    4846protected:
    49     void retranslateUi();
    5047
    51 private slots:
    52     void open();
     48    virtual void paintEvent(QPaintEvent *pEvent) /* override */;
    5349
    5450private:
    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;
    5954};
    6055
    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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette