VirtualBox

Changeset 70500 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 10, 2018 9:36:36 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt bugref:9072 Derive logviewer's panel widgets from the same base

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

Legend:

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

    r70487 r70500  
    338338        src/logviewer/UIVMLogViewerDialog.h \
    339339        src/logviewer/UIVMLogViewerFilterPanel.h \
     340        src/logviewer/UIVMLogViewerPanel.h \
    340341        src/logviewer/UIVMLogViewerSearchPanel.h \
    341342        src/logviewer/UIVMLogViewerWidget.h \
     
    655656        src/logviewer/UIVMLogViewerDialog.cpp \
    656657        src/logviewer/UIVMLogViewerFilterPanel.cpp \
     658        src/logviewer/UIVMLogViewerPanel.cpp \
    657659        src/logviewer/UIVMLogViewerSearchPanel.cpp \
    658660        src/logviewer/UIVMLogViewerWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.cpp

    r70495 r70500  
    4646
    4747UIVMLogViewerBookmarksPanel::UIVMLogViewerBookmarksPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer)
    48     : QIWithRetranslateUI<QWidget>(pParent)
     48: UIVMLogViewerPanel(pParent, pViewer)
    4949    , m_iMaxBookmarkTextLength(60)
    50     , m_pViewer(pViewer)
    51     , m_pMainLayout(0)
    52     , m_pCloseButton(0)
    5350    , m_pBookmarksComboBox(0)
    5451    , m_clearAllButton(0)
     
    5855}
    5956
    60 void UIVMLogViewerBookmarksPanel::update()
     57void UIVMLogViewerBookmarksPanel::updateBookmarkList()
    6158{
    62     if(!m_pBookmarksComboBox)
     59    if (!m_pBookmarksComboBox || !viewer())
    6360        return;
    64     const QVector<QPair<int, QString> > *bookmarkVector = m_pViewer->currentBookmarkVector();
    65     if(!bookmarkVector)
     61    const QVector<QPair<int, QString> > *bookmarkVector = viewer()->currentBookmarkVector();
     62    if (!bookmarkVector)
    6663        return;
    6764
     
    7370            arg(QString::number(bookmarkVector->at(i).first)).arg(bookmarkVector->at(i).second);
    7471
    75         if(strItem.length() > m_iMaxBookmarkTextLength)
     72        if (strItem.length() > m_iMaxBookmarkTextLength)
    7673        {
    7774            strItem.resize(m_iMaxBookmarkTextLength);
     
    9289}
    9390
    94 void UIVMLogViewerBookmarksPanel::prepare()
    95 {
    96     prepareWidgets();
    97     prepareConnections();
    98     retranslateUi();
    99 }
    100 
    10191void UIVMLogViewerBookmarksPanel::prepareWidgets()
    10292{
    103     m_pMainLayout = new QHBoxLayout(this);
    104     AssertPtrReturnVoid(m_pMainLayout);
    105     m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    106     m_pMainLayout->setSpacing(4);
    107 
    108     m_pCloseButton = new UIMiniCancelButton(this);
    109     AssertPtrReturnVoid(m_pCloseButton);
    110     m_pMainLayout->addWidget(m_pCloseButton, 0, Qt::AlignLeft);
     93    if (!mainLayout())
     94        return;
    11195
    11296    m_pBookmarksComboBox = new QComboBox(this);
     
    11599    m_pBookmarksComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
    116100    m_pBookmarksComboBox->setMaximumWidth(fontMetrics.width('a') * (m_iMaxBookmarkTextLength + 2));
    117     m_pMainLayout->addWidget(m_pBookmarksComboBox, 2, Qt::AlignLeft);
     101    mainLayout()->addWidget(m_pBookmarksComboBox, 2, Qt::AlignLeft);
    118102}
    119103
    120104void UIVMLogViewerBookmarksPanel::prepareConnections()
    121105{
    122     connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerBookmarksPanel::hide);
    123 
    124106}
    125107
     
    127109void UIVMLogViewerBookmarksPanel::retranslateUi()
    128110{
    129     m_pCloseButton->setToolTip(UIVMLogViewerWidget::tr("Close the search panel."));
     111    UIVMLogViewerPanel::retranslateUi();
    130112}
    131 
    132 bool UIVMLogViewerBookmarksPanel::eventFilter(QObject *pObject, QEvent *pEvent)
    133 {
    134     /* Depending on event-type: */
    135     switch (pEvent->type())
    136     {
    137         /* Process key press only: */
    138     case QEvent::KeyPress:
    139         {
    140             break;
    141         }
    142     default:
    143         break;
    144     }
    145     /* Call to base-class: */
    146     return QWidget::eventFilter(pObject, pEvent);
    147 }
    148 
    149 /** Handles the Qt show @a pEvent. */
    150 void UIVMLogViewerBookmarksPanel::showEvent(QShowEvent *pEvent)
    151 {
    152     /* Call to base-class: */
    153     QWidget::showEvent(pEvent);
    154 }
    155 
    156 /** Handles the Qt hide @a pEvent. */
    157 void UIVMLogViewerBookmarksPanel::hideEvent(QHideEvent *pEvent)
    158 {
    159     /* Get focused widget: */
    160     QWidget *pFocus = QApplication::focusWidget();
    161     /* If focus-widget is valid and child-widget of search-panel,
    162      * focus next child-widget in line: */
    163     if (pFocus && pFocus->parent() == this)
    164         focusNextPrevChild(true);
    165     /* Call to base-class: */
    166     QWidget::hideEvent(pEvent);
    167 }
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.h

    r70495 r70500  
    1919#define ___UIVMLogViewerBookmarksPanel_h___
    2020
    21 /* Qt includes: */
    22 #include <QWidget>
    23 
    2421/* GUI includes: */
    25 #include "QIWithRetranslateUI.h"
     22#include "UIVMLogViewerPanel.h"
    2623
    2724/* Forward declarations: */
    2825class QComboBox;
    29 class QHBoxLayout;
    30 class QLabel;
    31 class QLineEdit;
    3226class QPushButton;
    33 class UIVMFilterLineEdit;
    34 class UIMiniCancelButton;
    35 class UIVMLogViewerWidget;
    3627
    3728
    38 /** QWidget extension
    39   * providing GUI for bookmark management. Show a list of bookmarks currently set
     29
     30
     31/** UIVMLogViewerPanel extension providing GUI for bookmark management. Show a list of bookmarks currently set
    4032  for displayed log page. It has controls to navigate and clear bookmarks. */
    41 class UIVMLogViewerBookmarksPanel : public QIWithRetranslateUI<QWidget>
     33class UIVMLogViewerBookmarksPanel : public UIVMLogViewerPanel
    4234{
    4335    Q_OBJECT;
     
    5547       user switches to another log page tab etc. */
    5648    void setBookmarksList(const QVector<QPair<int, QString> > &bookmarkList);
    57     void update();
     49    void updateBookmarkList();
    5850    /* @a index is the index of the curent bookmark. */
    5951    void setBookmarkIndex(int index);
     
    6153public slots:
    6254
     55protected:
    6356
    64 private slots:
    65 
    66 
    67 private:
    68 
    69     void prepare();
    70     void prepareWidgets();
    71     void prepareConnections();
     57    virtual void prepareWidgets() /* override */;
     58    virtual void prepareConnections() /* override */;
    7259
    7360    /** Handles the translation event. */
    7461    void retranslateUi();
    7562
    76     /** Handles Qt @a pEvent, used for keyboard processing. */
    77     bool eventFilter(QObject *pObject, QEvent *pEvent);
    78     /** Handles the Qt show @a pEvent. */
    79     void showEvent(QShowEvent *pEvent);
    80     /** Handles the Qt hide @a pEvent. */
    81     void hideEvent(QHideEvent *pEvent);
     63private slots:
    8264
    83     const int m_iMaxBookmarkTextLength;
    84     /** Holds the reference to VM Log-Viewer this panel belongs to. */
    85     UIVMLogViewerWidget *m_pViewer;
    86     /** Holds the instance of main-layout we create. */
    87     QHBoxLayout         *m_pMainLayout;
    88     /** Holds the instance of close-button we create. */
    89     UIMiniCancelButton  *m_pCloseButton;
    90     QComboBox           *m_pBookmarksComboBox;
    91     QPushButton         *m_clearAllButton;
    92     QPushButton         *m_clearCurrentButton;
     65private:
     66
     67    const int     m_iMaxBookmarkTextLength;
     68    QComboBox    *m_pBookmarksComboBox;
     69    QPushButton  *m_clearAllButton;
     70    QPushButton  *m_clearCurrentButton;
    9371};
    9472
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.cpp

    r70487 r70500  
    173173
    174174UIVMLogViewerFilterPanel::UIVMLogViewerFilterPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer)
    175     : QIWithRetranslateUI<QWidget>(pParent)
    176     , m_pViewer(pViewer)
    177     , m_pMainLayout(0)
    178     , m_pCloseButton(0)
     175    : UIVMLogViewerPanel(pParent, pViewer)
    179176    , m_pFilterLabel(0)
    180177    , m_pFilterComboBox(0)
     
    202199void UIVMLogViewerFilterPanel::filter()
    203200{
    204     QPlainTextEdit *pCurrentPage = m_pViewer->currentLogPage();
     201    QPlainTextEdit *pCurrentPage = viewer()->currentLogPage();
    205202    AssertReturnVoid(pCurrentPage);
    206     const QString* strInputText = m_pViewer->currentLog();
     203    const QString* strInputText = viewer()->currentLog();
    207204    m_iUnfilteredLineCount = 0;
    208205    m_iFilteredLineCount = 0;
     
    331328}
    332329
    333 void UIVMLogViewerFilterPanel::prepare()
    334 {
    335     prepareWidgets();
    336     prepareConnections();
    337     retranslateUi();
    338 }
    339 
    340330void UIVMLogViewerFilterPanel::prepareWidgets()
    341331{
    342     m_pMainLayout = new QHBoxLayout(this);
    343     AssertPtrReturnVoid(m_pMainLayout);
    344     m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    345     m_pMainLayout->setSpacing(4);
    346 
    347     m_pCloseButton = new UIMiniCancelButton(this);
    348     AssertPtrReturnVoid(m_pCloseButton);
    349     m_pMainLayout->addWidget(m_pCloseButton);
     332    if (!mainLayout())
     333        return;
    350334
    351335    prepareRadioButtonGroup();
     
    360344        strFilterPresets.sort();
    361345        m_pFilterComboBox->addItems(strFilterPresets);
    362         m_pMainLayout->addWidget(m_pFilterComboBox,1);
     346        mainLayout()->addWidget(m_pFilterComboBox,1);
    363347    }
    364348
     
    367351    {
    368352        m_pAddFilterTermButton->setIcon(UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowForward, this));
    369         m_pMainLayout->addWidget(m_pAddFilterTermButton,0);
     353        mainLayout()->addWidget(m_pAddFilterTermButton,0);
    370354    }
    371355
     
    373357    AssertPtrReturnVoid(m_pFilterTermsLineEdit);
    374358    {
    375         m_pMainLayout->addWidget(m_pFilterTermsLineEdit, 4);
     359        mainLayout()->addWidget(m_pFilterTermsLineEdit, 4);
    376360        m_pFilterTermsLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum /*vertical */);
    377361    }
     
    380364    AssertPtrReturnVoid(m_pResultLabel);
    381365    {
    382         m_pMainLayout->addWidget(m_pResultLabel,0);
     366        mainLayout()->addWidget(m_pResultLabel,0);
    383367    }
    384368        /* Create filter-label: */
     
    394378// #endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    395379//             /* Add filter-label to main-layout: */
    396 //             m_pMainLayout->addWidget(m_pFilterLabel);
     380//             mainLayout()->addWidget(m_pFilterLabel);
    397381//         }
    398382}
     
    426410    containerLayout->addWidget(m_pOrRadioButton);
    427411    containerLayout->addWidget(m_pAndRadioButton);
    428     m_pMainLayout->addWidget(m_pRadioButtonContainer);
     412    mainLayout()->addWidget(m_pRadioButtonContainer);
    429413}
    430414
    431415void UIVMLogViewerFilterPanel::prepareConnections()
    432416{
    433     connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerFilterPanel::hide);
    434417    connect(m_pAddFilterTermButton, &QPushButton::clicked, this,  &UIVMLogViewerFilterPanel::sltAddFilterTerm);
    435418    connect(m_pButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked),
     
    446429void UIVMLogViewerFilterPanel::retranslateUi()
    447430{
    448     m_pCloseButton->setToolTip(UIVMLogViewerWidget::tr("Close the search panel."));
     431    UIVMLogViewerPanel::retranslateUi();
    449432    m_pFilterComboBox->setToolTip(UIVMLogViewerWidget::tr("Enter filtering string here."));
    450433    m_pAddFilterTermButton->setToolTip(UIVMLogViewerWidget::tr("Add filter term."));
     
    469452                pKeyEvent->key() == Qt::Key_T)
    470453            {
    471                 if (m_pViewer->currentLogPage())
     454                if (viewer()->currentLogPage())
    472455                {
    473456                    if (isHidden())
     
    486469    }
    487470    /* Call to base-class: */
    488     return QWidget::eventFilter(pObject, pEvent);
     471    return UIVMLogViewerPanel::eventFilter(pObject, pEvent);
    489472}
    490473
     
    492475void UIVMLogViewerFilterPanel::showEvent(QShowEvent *pEvent)
    493476{
    494     /* Call to base-class: */
    495     QWidget::showEvent(pEvent);
     477    UIVMLogViewerPanel::showEvent(pEvent);
    496478    /* Set focus to combo-box: */
    497479    m_pFilterComboBox->setFocus();
    498480}
    499481
    500 /** Handles the Qt hide @a pEvent. */
    501 void UIVMLogViewerFilterPanel::hideEvent(QHideEvent *pEvent)
    502 {
    503     /* Get focused widget: */
    504     QWidget *pFocus = QApplication::focusWidget();
    505     /* If focus-widget is valid and child-widget of search-panel,
    506      * focus next child-widget in line: */
    507     if (pFocus && pFocus->parent() == this)
    508         focusNextPrevChild(true);
    509     /* Call to base-class: */
    510     QWidget::hideEvent(pEvent);
    511 }
    512 
    513482#include "UIVMLogViewerFilterPanel.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerFilterPanel.h

    r70474 r70500  
    1919#define ___UIVMLogViewerFilterPanel_h___
    2020
    21 /* Qt includes: */
    22 #include <QWidget>
    2321
    2422/* GUI includes: */
    25 #include "QIWithRetranslateUI.h"
     23#include "UIVMLogViewerPanel.h"
    2624
    2725/* Forward declarations: */
     
    2927class QComboBox;
    3028class QFrame;
    31 class QHBoxLayout;
    3229class QLabel;
    3330class QLineEdit;
     
    3532class QRadioButton;
    3633class UIVMFilterLineEdit;
    37 class UIMiniCancelButton;
    38 class UIVMLogViewerWidget;
    3934
    4035
    4136/** QWidget extension
    4237  * providing GUI for filter panel in VM Log Viewer. */
    43 class UIVMLogViewerFilterPanel : public QIWithRetranslateUI<QWidget>
     38class UIVMLogViewerFilterPanel : public UIVMLogViewerPanel
    4439{
    4540    Q_OBJECT;
     
    6257    void applyFilter(const int iCurrentIndex = 0);
    6358
     59protected:
     60
     61    virtual void prepareWidgets() /* override */;
     62    virtual void prepareConnections() /* override */;
     63
     64    /** Handles the translation event. */
     65    void retranslateUi() /* override */;
     66    /** Handles Qt @a pEvent, used for keyboard processing. */
     67    bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     68    /** Handles the Qt show @a pEvent. */
     69    void showEvent(QShowEvent *pEvent) /* override */;
     70
    6471private slots:
    6572
     
    8087    };
    8188
    82     /** Prepares filter-panel. */
    83     void prepare();
    84     void prepareWidgets();
    8589    void prepareRadioButtonGroup();
    86     void prepareConnections();
    87 
    88     /** Handles the translation event. */
    89     void retranslateUi();
    90 
    91     /** Handles Qt @a pEvent, used for keyboard processing. */
    92     bool eventFilter(QObject *pObject, QEvent *pEvent);
    93     /** Handles the Qt show @a pEvent. */
    94     void showEvent(QShowEvent *pEvent);
    95     /** Handles the Qt hide @a pEvent. */
    96     void hideEvent(QHideEvent *pEvent);
    9790
    9891    bool applyFilterTermsToString(const QString& string);
    9992    void filter();
    10093
    101     /** Holds the reference to VM Log-Viewer this filter-panel belongs to. */
    102     UIVMLogViewerWidget *m_pViewer;
    103     /** Holds the instance of main-layout we create. */
    104     QHBoxLayout         *m_pMainLayout;
    105     /** Holds the instance of close-button we create. */
    106     UIMiniCancelButton  *m_pCloseButton;
    107     /** Holds the instance of filter-label we create. */
    10894    QLabel              *m_pFilterLabel;
    109     /** Holds instance of filter combo-box we create. */
    11095    QComboBox           *m_pFilterComboBox;
    111 
    11296    QButtonGroup        *m_pButtonGroup;
    11397    QRadioButton        *m_pAndRadioButton;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.cpp

    r70495 r70500  
    3737# include "UIIconPool.h"
    3838# include "UISpecialControls.h"
    39 # include "UIVMLogViewerBookmarksPanel.h"
     39# include "UIVMLogViewerPanel.h"
    4040# include "UIVMLogViewerWidget.h"
    4141# ifdef VBOX_WS_MAC
     
    4545
    4646
    47 UIVMLogViewerBookmarksPanel::UIVMLogViewerBookmarksPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer)
     47UIVMLogViewerPanel::UIVMLogViewerPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer)
    4848    : QIWithRetranslateUI<QWidget>(pParent)
    49     , m_iMaxBookmarkTextLength(60)
    5049    , m_pViewer(pViewer)
    5150    , m_pMainLayout(0)
    5251    , m_pCloseButton(0)
    53     , m_pBookmarksComboBox(0)
    54     , m_clearAllButton(0)
    55     , m_clearCurrentButton(0)
    5652{
    5753    prepare();
    5854}
    5955
    60 void UIVMLogViewerBookmarksPanel::update()
     56UIVMLogViewerWidget* UIVMLogViewerPanel::viewer()
    6157{
    62     if(!m_pBookmarksComboBox)
    63         return;
    64     const QVector<QPair<int, QString> > *bookmarkVector = m_pViewer->currentBookmarkVector();
    65     if(!bookmarkVector)
    66         return;
    67 
    68     m_pBookmarksComboBox->clear();
    69     QStringList bList;
    70     for(int i = 0; i < bookmarkVector->size(); ++i)
    71     {
    72         QString strItem = QString("BookMark %1 at Line %2: %3").arg(QString::number(i)).
    73             arg(QString::number(bookmarkVector->at(i).first)).arg(bookmarkVector->at(i).second);
    74 
    75         if(strItem.length() > m_iMaxBookmarkTextLength)
    76         {
    77             strItem.resize(m_iMaxBookmarkTextLength);
    78             strItem.replace(m_iMaxBookmarkTextLength, 3, QString("..."));
    79         }
    80         bList << strItem;
    81     }
    82     m_pBookmarksComboBox->addItems(bList);
     58    return m_pViewer;
    8359}
    8460
    85 void UIVMLogViewerBookmarksPanel::setBookmarkIndex(int index)
     61const UIVMLogViewerWidget* UIVMLogViewerPanel::viewer() const
    8662{
    87     if (!m_pBookmarksComboBox)
    88         return;
    89     if (index >= m_pBookmarksComboBox->count())
    90         return;
    91     m_pBookmarksComboBox->setCurrentIndex(index);
     63    return m_pViewer;
    9264}
    9365
    94 void UIVMLogViewerBookmarksPanel::prepare()
     66QHBoxLayout* UIVMLogViewerPanel::mainLayout()
     67{
     68    return m_pMainLayout;
     69}
     70
     71void UIVMLogViewerPanel::prepare()
    9572{
    9673    prepareWidgets();
     
    9976}
    10077
    101 void UIVMLogViewerBookmarksPanel::prepareWidgets()
     78void UIVMLogViewerPanel::prepareWidgets()
    10279{
    10380    m_pMainLayout = new QHBoxLayout(this);
    10481    AssertPtrReturnVoid(m_pMainLayout);
    10582    m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    106     m_pMainLayout->setSpacing(4);
     83    m_pMainLayout->setSpacing(2);
    10784
    10885    m_pCloseButton = new UIMiniCancelButton(this);
    10986    AssertPtrReturnVoid(m_pCloseButton);
    11087    m_pMainLayout->addWidget(m_pCloseButton, 0, Qt::AlignLeft);
    111 
    112     m_pBookmarksComboBox = new QComboBox(this);
    113     QFontMetrics fontMetrics = m_pBookmarksComboBox->fontMetrics();
    114     AssertPtrReturnVoid(m_pBookmarksComboBox);
    115     m_pBookmarksComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
    116     m_pBookmarksComboBox->setMaximumWidth(fontMetrics.width('a') * (m_iMaxBookmarkTextLength + 2));
    117     m_pMainLayout->addWidget(m_pBookmarksComboBox, 2, Qt::AlignLeft);
    11888}
    11989
    120 void UIVMLogViewerBookmarksPanel::prepareConnections()
     90void UIVMLogViewerPanel::prepareConnections()
    12191{
    122     connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerBookmarksPanel::hide);
     92    if (m_pCloseButton)
     93        connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerPanel::hide);
    12394
    12495}
    12596
    12697
    127 void UIVMLogViewerBookmarksPanel::retranslateUi()
     98void UIVMLogViewerPanel::retranslateUi()
    12899{
    129     m_pCloseButton->setToolTip(UIVMLogViewerWidget::tr("Close the search panel."));
     100    if (m_pCloseButton)
     101        m_pCloseButton->setToolTip(UIVMLogViewerWidget::tr("Close the search panel."));
    130102}
    131103
    132 bool UIVMLogViewerBookmarksPanel::eventFilter(QObject *pObject, QEvent *pEvent)
     104bool UIVMLogViewerPanel::eventFilter(QObject *pObject, QEvent *pEvent)
    133105{
    134     /* Depending on event-type: */
    135     switch (pEvent->type())
    136     {
    137         /* Process key press only: */
    138     case QEvent::KeyPress:
    139         {
    140             break;
    141         }
    142     default:
    143         break;
    144     }
    145     /* Call to base-class: */
    146106    return QWidget::eventFilter(pObject, pEvent);
    147107}
    148108
    149 /** Handles the Qt show @a pEvent. */
    150 void UIVMLogViewerBookmarksPanel::showEvent(QShowEvent *pEvent)
     109void UIVMLogViewerPanel::showEvent(QShowEvent *pEvent)
    151110{
    152     /* Call to base-class: */
    153111    QWidget::showEvent(pEvent);
    154112}
    155113
    156 /** Handles the Qt hide @a pEvent. */
    157 void UIVMLogViewerBookmarksPanel::hideEvent(QHideEvent *pEvent)
     114void UIVMLogViewerPanel::hideEvent(QHideEvent *pEvent)
    158115{
    159116    /* Get focused widget: */
     
    163120    if (pFocus && pFocus->parent() == this)
    164121        focusNextPrevChild(true);
    165     /* Call to base-class: */
     122
    166123    QWidget::hideEvent(pEvent);
     124    emit sigHide();
    167125}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.h

    r70495 r70500  
    1616 */
    1717
    18 #ifndef ___UIVMLogViewerBookmarksPanel_h___
    19 #define ___UIVMLogViewerBookmarksPanel_h___
     18#ifndef ___UIVMLogViewerPanel_h___
     19#define ___UIVMLogViewerPanel_h___
    2020
    2121/* Qt includes: */
     
    3636
    3737
    38 /** QWidget extension
    39   * providing GUI for bookmark management. Show a list of bookmarks currently set
    40   for displayed log page. It has controls to navigate and clear bookmarks. */
    41 class UIVMLogViewerBookmarksPanel : public QIWithRetranslateUI<QWidget>
     38/** QWidget extension acting as the base class for UIVMLogViewerXXXPanel widgets. */
     39class UIVMLogViewerPanel : public QIWithRetranslateUI<QWidget>
    4240{
    4341    Q_OBJECT;
     
    4543signals:
    4644
     45    void sigHide();
     46
    4747public:
    4848
    49     UIVMLogViewerBookmarksPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer);
     49    UIVMLogViewerPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer);
    5050
    51     /* Adds a single bookmark to an existing list of bookmarks. Possibly called
    52        by UIVMLogViewerWidget when user adds a bookmark thru context menu etc. */
    53     void addBookmark(const QPair<int, QString> &newBookmark);
    54     /* Clear the bookmark list and show this list instead. Probably done after
    55        user switches to another log page tab etc. */
    56     void setBookmarksList(const QVector<QPair<int, QString> > &bookmarkList);
    57     void update();
    58     /* @a index is the index of the curent bookmark. */
    59     void setBookmarkIndex(int index);
    6051
    6152public slots:
    6253
     54protected:
    6355
    64 private slots:
     56    virtual void prepare();
     57    virtual void prepareWidgets();
     58    virtual void prepareConnections();
    6559
    66 
    67 private:
    68 
    69     void prepare();
    70     void prepareWidgets();
    71     void prepareConnections();
     60    /* Access functions for children classes. */
     61    UIVMLogViewerWidget*       viewer();
     62    const UIVMLogViewerWidget* viewer() const;
     63    QHBoxLayout*               mainLayout();
    7264
    7365    /** Handles the translation event. */
     
    8173    void hideEvent(QHideEvent *pEvent);
    8274
    83     const int m_iMaxBookmarkTextLength;
     75private slots:
     76
     77
     78private:
     79
     80
    8481    /** Holds the reference to VM Log-Viewer this panel belongs to. */
    8582    UIVMLogViewerWidget *m_pViewer;
     
    8885    /** Holds the instance of close-button we create. */
    8986    UIMiniCancelButton  *m_pCloseButton;
    90     QComboBox           *m_pBookmarksComboBox;
    91     QPushButton         *m_clearAllButton;
    92     QPushButton         *m_clearCurrentButton;
    9387};
    9488
    95 #endif /* !___UIVMLogViewerBookmarksPanel_h___ */
     89#endif /* !___UIVMLogViewerPanel!_h___ */
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp

    r70476 r70500  
    4444
    4545UIVMLogViewerSearchPanel::UIVMLogViewerSearchPanel(QWidget *pParent, UIVMLogViewerWidget *pViewer)
    46 : QIWithRetranslateUI<QWidget>(pParent)
    47     , m_pViewer(pViewer)
    48     , m_pMainLayout(0)
    49     , m_pCloseButton(0)
    50     , m_pSearchLabel(0), m_pSearchEditor(0)
     46    : UIVMLogViewerPanel(pParent, pViewer)
     47    , m_pSearchLabel(0)
     48    , m_pSearchEditor(0)
    5149    , m_pNextPrevButtons(0)
    5250    , m_pCaseSensitiveCheckBox(0)
     
    9694        focusNextPrevChild(true);
    9795    /* Call to base-class: */
    98     QWidget::hideEvent(pEvent);
     96    UIVMLogViewerPanel::hideEvent(pEvent);
    9997    reset();
    10098}
     
    127125    else
    128126    {
    129         /* Get current log-page: */
    130         QPlainTextEdit *pBrowser = m_pViewer->currentLogPage();
    131         /* If current log-page is valid and cursor has selection: */
    132         if (pBrowser && pBrowser->textCursor().hasSelection())
     127        if (viewer())
    133128        {
    134             /* Get cursor and reset position: */
    135             QTextCursor cursor = pBrowser->textCursor();
    136             cursor.setPosition(cursor.anchor());
    137             pBrowser->setTextCursor(cursor);
     129            /* Get current log-page: */
     130            QPlainTextEdit *pBrowser = viewer()->currentLogPage();
     131            /* If current log-page is valid and cursor has selection: */
     132            if (pBrowser && pBrowser->textCursor().hasSelection())
     133            {
     134                /* Get cursor and reset position: */
     135                QTextCursor cursor = pBrowser->textCursor();
     136                cursor.setPosition(cursor.anchor());
     137                pBrowser->setTextCursor(cursor);
     138            }
     139            m_iSearchPosition = -1;
     140            clearHighlighting(-1);
    138141        }
    139         m_iSearchPosition = -1;
    140         clearHighlighting(-1);
    141142    }
    142143}
     
    144145void UIVMLogViewerSearchPanel::sltHighlightAllCheckBox()
    145146{
    146     QPlainTextEdit *pTextEdit = m_pViewer->currentLogPage();
     147    if (!viewer())
     148        return;
     149    QPlainTextEdit *pTextEdit = viewer()->currentLogPage();
    147150    if (!pTextEdit)
    148151        return;
     
    181184}
    182185
    183 void UIVMLogViewerSearchPanel::prepare()
    184 {
    185     /* Prepare widgets: */
    186     prepareWidgets();
    187 
    188     /* Prepare connections: */
    189     prepareConnections();
    190 
    191     /* Retranslate finally: */
    192     retranslateUi();
    193 }
    194 
    195186void UIVMLogViewerSearchPanel::prepareWidgets()
    196187{
    197     /* Create main-layout: */
    198     m_pMainLayout = new QHBoxLayout(this);
    199     AssertPtrReturnVoid(m_pMainLayout);
    200     {
    201         /* Configure main-layout: */
    202         m_pMainLayout->setContentsMargins(0, 0, 0, 0);
    203         m_pMainLayout->setSpacing(4);
    204 
    205         /* Create close-button: */
    206         m_pCloseButton = new UIMiniCancelButton(this);
    207         AssertPtrReturnVoid(m_pCloseButton);
    208         {
    209             /* Add close-button to main-layout: */
    210             m_pMainLayout->addWidget(m_pCloseButton);
    211         }
    212 
    213         /* Create search-editor: */
    214         m_pSearchEditor = new UISearchField(this);
    215         AssertPtrReturnVoid(m_pSearchEditor);
    216         {
    217             /* Configure search-editor: */
    218             m_pSearchEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    219             /* Add search-editor to main-layout: */
    220             m_pMainLayout->addWidget(m_pSearchEditor);
    221         }
    222 
    223         /* Create search-label: */
    224         m_pSearchLabel = new QLabel(this);
    225         AssertPtrReturnVoid(m_pSearchLabel);
    226         {
    227             /* Configure search-label: */
    228             m_pSearchLabel->setBuddy(m_pSearchEditor);
    229             /* Prepare font: */
     188    if (!mainLayout())
     189        return;
     190
     191    /* Create search-editor: */
     192    m_pSearchEditor = new UISearchField(this);
     193    AssertPtrReturnVoid(m_pSearchEditor);
     194    {
     195        /* Configure search-editor: */
     196        m_pSearchEditor->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
     197        /* Add search-editor to main-layout: */
     198        mainLayout()->addWidget(m_pSearchEditor);
     199    }
     200
     201    /* Create search-label: */
     202    m_pSearchLabel = new QLabel(this);
     203    AssertPtrReturnVoid(m_pSearchLabel);
     204    {
     205        /* Configure search-label: */
     206        m_pSearchLabel->setBuddy(m_pSearchEditor);
     207        /* Prepare font: */
    230208#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    231             QFont font = m_pSearchLabel->font();
    232             font.setPointSize(::darwinSmallFontSize());
    233             m_pSearchLabel->setFont(font);
     209        QFont font = m_pSearchLabel->font();
     210        font.setPointSize(::darwinSmallFontSize());
     211        m_pSearchLabel->setFont(font);
    234212#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    235             /* Add search-label to main-layout: */
    236             m_pMainLayout->addWidget(m_pSearchLabel);
    237         }
    238 
    239         /* Create Next/Prev button-box: */
    240         m_pNextPrevButtons = new UIRoundRectSegmentedButton(this, 2);
    241         AssertPtrReturnVoid(m_pNextPrevButtons);
    242         {
    243             /* Configure Next/Prev button-box: */
    244             m_pNextPrevButtons->setEnabled(0, false);
    245             m_pNextPrevButtons->setEnabled(1, false);
     213        /* Add search-label to main-layout: */
     214        mainLayout()->addWidget(m_pSearchLabel);
     215    }
     216
     217    /* Create Next/Prev button-box: */
     218    m_pNextPrevButtons = new UIRoundRectSegmentedButton(this, 2);
     219    AssertPtrReturnVoid(m_pNextPrevButtons);
     220    {
     221        /* Configure Next/Prev button-box: */
     222        m_pNextPrevButtons->setEnabled(0, false);
     223        m_pNextPrevButtons->setEnabled(1, false);
    246224#ifndef VBOX_WS_MAC
    247             /* No icons on the Mac: */
    248             m_pNextPrevButtons->setIcon(0, UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowBack, this));
    249             m_pNextPrevButtons->setIcon(1, UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowForward, this));
     225        /* No icons on the Mac: */
     226        m_pNextPrevButtons->setIcon(0, UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowBack, this));
     227        m_pNextPrevButtons->setIcon(1, UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_ArrowForward, this));
    250228#endif /* !VBOX_WS_MAC */
    251             /* Add Next/Prev button-box to main-layout: */
    252             m_pMainLayout->addWidget(m_pNextPrevButtons);
    253         }
    254 
    255         /* Create case-sensitive checkbox: */
    256         m_pCaseSensitiveCheckBox = new QCheckBox;
    257         AssertPtrReturnVoid(m_pCaseSensitiveCheckBox);
    258         {
    259             /* Configure font: */
     229        /* Add Next/Prev button-box to main-layout: */
     230        mainLayout()->addWidget(m_pNextPrevButtons);
     231    }
     232
     233    /* Create case-sensitive checkbox: */
     234    m_pCaseSensitiveCheckBox = new QCheckBox;
     235    AssertPtrReturnVoid(m_pCaseSensitiveCheckBox);
     236    {
     237        /* Configure font: */
    260238#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    261             QFont font = m_pCaseSensitiveCheckBox->font();
    262             font.setPointSize(::darwinSmallFontSize());
    263             m_pCaseSensitiveCheckBox->setFont(font);
     239        QFont font = m_pCaseSensitiveCheckBox->font();
     240        font.setPointSize(::darwinSmallFontSize());
     241        m_pCaseSensitiveCheckBox->setFont(font);
    264242#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    265             /* Add case-sensitive checkbox to main-layout: */
    266             m_pMainLayout->addWidget(m_pCaseSensitiveCheckBox);
    267         }
    268 
    269         m_pMatchWholeWordCheckBox = new QCheckBox(this);
    270         AssertPtrReturnVoid(m_pMatchWholeWordCheckBox);
    271         {
    272             /* Configure focus for case-sensitive checkbox: */
    273             setFocusProxy(m_pMatchWholeWordCheckBox);
    274             /* Configure font: */
     243        /* Add case-sensitive checkbox to main-layout: */
     244        mainLayout()->addWidget(m_pCaseSensitiveCheckBox);
     245    }
     246
     247    m_pMatchWholeWordCheckBox = new QCheckBox(this);
     248    AssertPtrReturnVoid(m_pMatchWholeWordCheckBox);
     249    {
     250        /* Configure focus for case-sensitive checkbox: */
     251        setFocusProxy(m_pMatchWholeWordCheckBox);
     252        /* Configure font: */
    275253#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    276             QFont font = m_pMatchWholeWordCheckBox->font();
    277             font.setPointSize(::darwinSmallFontSize());
    278             m_pMatchWholeWordCheckBox->setFont(font);
     254        QFont font = m_pMatchWholeWordCheckBox->font();
     255        font.setPointSize(::darwinSmallFontSize());
     256        m_pMatchWholeWordCheckBox->setFont(font);
    279257#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    280             m_pMainLayout->addWidget(m_pMatchWholeWordCheckBox);
    281         }
    282 
    283         m_pHighlightAllCheckBox = new QCheckBox(this);
    284         AssertPtrReturnVoid(m_pHighlightAllCheckBox);
    285         {
    286             /* Configure font: */
     258        mainLayout()->addWidget(m_pMatchWholeWordCheckBox);
     259    }
     260
     261    m_pHighlightAllCheckBox = new QCheckBox(this);
     262    AssertPtrReturnVoid(m_pHighlightAllCheckBox);
     263    {
     264        /* Configure font: */
    287265#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    288             QFont font = m_pHighlightAllCheckBox->font();
    289             font.setPointSize(::darwinSmallFontSize());
    290             m_pHighlightAllCheckBox->setFont(font);
     266        QFont font = m_pHighlightAllCheckBox->font();
     267        font.setPointSize(::darwinSmallFontSize());
     268        m_pHighlightAllCheckBox->setFont(font);
    291269#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    292             /* Add case-sensitive checkbox to main-layout: */
    293             m_pMainLayout->addWidget(m_pHighlightAllCheckBox);
    294         }
    295 
    296         /* Create warning-spacer: */
    297         m_pWarningSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Minimum);
    298         AssertPtrReturnVoid(m_pWarningSpacer);
    299         {
    300             /* Add warning-spacer to main-layout: */
    301             m_pMainLayout->addItem(m_pWarningSpacer);
    302         }
    303 
    304         /* Create warning-icon: */
    305         m_pWarningIcon = new QLabel(this);
    306         AssertPtrReturnVoid(m_pWarningIcon);
    307         {
    308             /* Confifure warning-icon: */
    309             m_pWarningIcon->hide();
    310             QIcon icon = UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_MessageBoxWarning, this);
    311             if (!icon.isNull())
    312                 m_pWarningIcon->setPixmap(icon.pixmap(16, 16));
    313             /* Add warning-icon to main-layout: */
    314             m_pMainLayout->addWidget(m_pWarningIcon);
    315         }
    316 
    317         /* Create warning-label: */
    318         m_pInfoLabel = new QLabel(this);
    319         AssertPtrReturnVoid(m_pInfoLabel);
    320         {
    321             /* Configure warning-label: */
    322             m_pInfoLabel->hide();
    323             /* Prepare font: */
     270        /* Add case-sensitive checkbox to main-layout: */
     271        mainLayout()->addWidget(m_pHighlightAllCheckBox);
     272    }
     273
     274    /* Create warning-spacer: */
     275    m_pWarningSpacer = new QSpacerItem(0, 0, QSizePolicy::Fixed, QSizePolicy::Minimum);
     276    AssertPtrReturnVoid(m_pWarningSpacer);
     277    {
     278        /* Add warning-spacer to main-layout: */
     279        mainLayout()->addItem(m_pWarningSpacer);
     280    }
     281
     282    /* Create warning-icon: */
     283    m_pWarningIcon = new QLabel(this);
     284    AssertPtrReturnVoid(m_pWarningIcon);
     285    {
     286        /* Confifure warning-icon: */
     287        m_pWarningIcon->hide();
     288        QIcon icon = UIIconPool::defaultIcon(UIIconPool::UIDefaultIconType_MessageBoxWarning, this);
     289        if (!icon.isNull())
     290            m_pWarningIcon->setPixmap(icon.pixmap(16, 16));
     291        /* Add warning-icon to main-layout: */
     292        mainLayout()->addWidget(m_pWarningIcon);
     293    }
     294
     295    /* Create warning-label: */
     296    m_pInfoLabel = new QLabel(this);
     297    AssertPtrReturnVoid(m_pInfoLabel);
     298    {
     299        /* Configure warning-label: */
     300        m_pInfoLabel->hide();
     301        /* Prepare font: */
    324302#ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS
    325             QFont font = m_pInfoLabel->font();
    326             font.setPointSize(::darwinSmallFontSize());
    327             m_pInfoLabel->setFont(font);
     303        QFont font = m_pInfoLabel->font();
     304        font.setPointSize(::darwinSmallFontSize());
     305        m_pInfoLabel->setFont(font);
    328306#endif /* VBOX_DARWIN_USE_NATIVE_CONTROLS */
    329             /* Add warning-label to main-layout: */
    330             m_pMainLayout->addWidget(m_pInfoLabel);
    331         }
    332 
    333         /* Create spacer-item: */
    334         m_pSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
    335         AssertPtrReturnVoid(m_pSpacerItem);
    336         {
    337             /* Add spacer-item to main-layout: */
    338             m_pMainLayout->addItem(m_pSpacerItem);
    339         }
     307        /* Add warning-label to main-layout: */
     308        mainLayout()->addWidget(m_pInfoLabel);
     309    }
     310
     311    m_pSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
     312    AssertPtrReturnVoid(m_pSpacerItem);
     313    {
     314        mainLayout()->addItem(m_pSpacerItem);
    340315    }
    341316}
     
    343318void UIVMLogViewerSearchPanel::prepareConnections()
    344319{
    345     /* Prepare connections: */
    346     connect(m_pCloseButton, &UIMiniCancelButton::clicked, this, &UIVMLogViewerSearchPanel::hide);
    347320    connect(m_pSearchEditor, &UISearchField::textChanged, this, &UIVMLogViewerSearchPanel::sltSearchTextChanged);
    348321    connect(m_pNextPrevButtons, &UIRoundRectSegmentedButton::clicked, this, &UIVMLogViewerSearchPanel::find);
     
    357330void UIVMLogViewerSearchPanel::retranslateUi()
    358331{
    359     m_pCloseButton->setToolTip(UIVMLogViewerWidget::tr("Close the search panel"));
    360 
    361332    m_pSearchLabel->setText(QString("%1 ").arg(UIVMLogViewerWidget::tr("&Find")));
    362333    m_pSearchEditor->setToolTip(UIVMLogViewerWidget::tr("Enter a search string here"));
     
    402373    }
    403374    /* Call to base-class: */
    404     QWidget::keyPressEvent(pEvent);
     375    UIVMLogViewerPanel::keyPressEvent(pEvent);
    405376}
    406377
     
    439410                     pKeyEvent->key() == Qt::Key_F)
    440411            {
    441                 if (m_pViewer->currentLogPage())
     412                if (viewer() && viewer()->currentLogPage())
    442413                {
    443414                    /* Make sure current log-page is visible: */
     
    454425            {
    455426                /* Make sure current log-page is visible: */
    456                 if (m_pViewer->currentLogPage())
     427                if (viewer() && viewer()->currentLogPage())
    457428                {
    458429                    if (isHidden())
     
    471442    }
    472443    /* Call to base-class: */
    473     return QWidget::eventFilter(pObject, pEvent);
     444    return UIVMLogViewerPanel::eventFilter(pObject, pEvent);
    474445}
    475446
     
    477448{
    478449    /* Call to base-class: */
    479     QWidget::showEvent(pEvent);
     450    UIVMLogViewerPanel::showEvent(pEvent);
    480451    /* Set focus on search-editor: */
    481452    m_pSearchEditor->setFocus();
     
    486457void UIVMLogViewerSearchPanel::search(SearchDirection direction, bool highlight)
    487458{
    488    QPlainTextEdit *pTextEdit = m_pViewer->currentLogPage();
    489    if (!pTextEdit) return;
    490    QTextDocument *pDocument = pTextEdit->document();
    491    if (!pDocument)
    492        return;
    493 
    494    const QString &searchString = m_pSearchEditor->text();
    495    if (searchString.isEmpty())
    496        return;
    497 
    498    QTextCursor endCursor(pDocument);
    499    endCursor.movePosition(QTextCursor::End);
    500    QTextCursor startCursor(pDocument);
    501 
    502    if (m_pHighlightAllCheckBox->isChecked())
    503    {
    504        if (highlight)
    505            highlightAll(pDocument, searchString);
    506    }
    507    else
    508    {
    509        m_iMatchCount = -1;
    510        m_matchLocationVector.clear();
    511    }
    512 
    513    QTextCursor resultCursor(pDocument);
    514    int startPosition = m_iSearchPosition;
    515    if (direction == BackwardSearch)
    516        startPosition -= searchString.length();
    517    resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction));
    518 
    519    /* Decide whether to wrap around or to end the search */
    520    if (resultCursor.isNull())
    521    {
    522        /* End the search if we search the whole document with no find: */
    523        if ((direction == ForwardSearch && startPosition == startCursor.position()) ||
    524            (direction == BackwardSearch && startPosition == endCursor.position()))
    525        {
    526            /* Set the match count 0 here since we did not call highLightAll function: */
    527            if (!m_pHighlightAllCheckBox->isChecked())
    528                m_iMatchCount = 0;
    529            configureInfoLabels();
    530            return;
    531        }
    532        /* Wrap the search */
    533        if (direction == ForwardSearch)
    534        {
    535            m_iSearchPosition = startCursor.position();
    536            search(ForwardSearch, false);
    537            return;
    538        }
    539        else
    540        {
    541            /* Set the search position away from the end position to be
    542               able to find the string at the end of the document: */
    543            m_iSearchPosition = endCursor.position() + searchString.length();
    544            search(BackwardSearch, false);
    545            return;
    546        }
    547    }
    548    pTextEdit->setTextCursor(resultCursor);
    549    m_iSearchPosition = resultCursor.position();
    550    configureInfoLabels();
     459    if (!viewer())
     460        return;
     461    QPlainTextEdit *pTextEdit = viewer()->currentLogPage();
     462    if (!pTextEdit) return;
     463    QTextDocument *pDocument = pTextEdit->document();
     464    if (!pDocument)
     465        return;
     466
     467    const QString &searchString = m_pSearchEditor->text();
     468    if (searchString.isEmpty())
     469        return;
     470
     471    QTextCursor endCursor(pDocument);
     472    endCursor.movePosition(QTextCursor::End);
     473    QTextCursor startCursor(pDocument);
     474
     475    if (m_pHighlightAllCheckBox->isChecked())
     476    {
     477        if (highlight)
     478            highlightAll(pDocument, searchString);
     479    }
     480    else
     481    {
     482        m_iMatchCount = -1;
     483        m_matchLocationVector.clear();
     484    }
     485
     486    QTextCursor resultCursor(pDocument);
     487    int startPosition = m_iSearchPosition;
     488    if (direction == BackwardSearch)
     489        startPosition -= searchString.length();
     490    resultCursor = pDocument->find(searchString, startPosition, constructFindFlags(direction));
     491
     492    /* Decide whether to wrap around or to end the search */
     493    if (resultCursor.isNull())
     494    {
     495        /* End the search if we search the whole document with no find: */
     496        if ((direction == ForwardSearch && startPosition == startCursor.position()) ||
     497            (direction == BackwardSearch && startPosition == endCursor.position()))
     498        {
     499            /* Set the match count 0 here since we did not call highLightAll function: */
     500            if (!m_pHighlightAllCheckBox->isChecked())
     501                m_iMatchCount = 0;
     502            configureInfoLabels();
     503            return;
     504        }
     505        /* Wrap the search */
     506        if (direction == ForwardSearch)
     507        {
     508            m_iSearchPosition = startCursor.position();
     509            search(ForwardSearch, false);
     510            return;
     511        }
     512        else
     513        {
     514            /* Set the search position away from the end position to be
     515               able to find the string at the end of the document: */
     516            m_iSearchPosition = endCursor.position() + searchString.length();
     517            search(BackwardSearch, false);
     518            return;
     519        }
     520    }
     521    pTextEdit->setTextCursor(resultCursor);
     522    m_iSearchPosition = resultCursor.position();
     523    configureInfoLabels();
    551524}
    552525
     
    563536void UIVMLogViewerSearchPanel::clearHighlighting(int count)
    564537{
     538    if (!viewer())
     539        return;
    565540    m_iMatchCount = count;
    566541    m_matchLocationVector.clear();
    567542
    568     QPlainTextEdit *pBrowser = m_pViewer->currentLogPage();
    569     if(pBrowser)
     543    QPlainTextEdit *pBrowser = viewer()->currentLogPage();
     544    if (pBrowser)
    570545    {
    571546        QTextDocument* pDocument = pBrowser->document();
    572         if(pDocument)
     547        if (pDocument)
    573548            pDocument->undo();
    574549    }
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.h

    r70476 r70500  
    2121/* Qt includes: */
    2222#include <QTextDocument>
    23 #include <QWidget>
    2423
    2524/* GUI includes: */
    26 #include "QIWithRetranslateUI.h"
     25#include "UIVMLogViewerPanel.h"
    2726
    2827/* Forward declarations: */
     
    3837/** QWidget extension
    3938  * providing GUI for search-panel in VM Log-Viewer. */
    40 class UIVMLogViewerSearchPanel : public QIWithRetranslateUI<QWidget>
     39class UIVMLogViewerSearchPanel : public UIVMLogViewerPanel
    4140{
    4241    Q_OBJECT;
     
    5857protected:
    5958
     59
     60    /** Prepares widgets. */
     61    virtual void prepareWidgets() /* override */;
     62    virtual void prepareConnections() /* override */;
     63    /** Handles translation event. */
     64    virtual void retranslateUi() /* override */;
     65    /** Handles Qt key-press @a pEevent. */
     66    virtual void keyPressEvent(QKeyEvent *pEvent) /* override */;
     67    /** Handles Qt @a pEvent, used for keyboard processing. */
     68    virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
     69    /** Handles Qt show @a pEvent. */
     70    virtual void showEvent(QShowEvent *pEvent) /* override */;
    6071    virtual void hideEvent(QHideEvent* pEvent) /* override */;
    6172
     
    7586
    7687    enum SearchDirection { ForwardSearch, BackwardSearch };
    77     /** Prepares search-panel. */
    78     void prepare();
    79     /** Prepares widgets. */
    80     void prepareWidgets();
    81     void prepareConnections();
    8288
    83     /** Handles translation event. */
    84     void retranslateUi();
    85 
    86     /** Handles Qt key-press @a pEevent. */
    87     void keyPressEvent(QKeyEvent *pEvent);
    88     /** Handles Qt @a pEvent, used for keyboard processing. */
    89     bool eventFilter(QObject *pObject, QEvent *pEvent);
    90     /** Handles Qt show @a pEvent. */
    91     void showEvent(QShowEvent *pEvent);
    9289    /** Clear the result of highlight */
    9390    void clearHighlight();
     
    110107    QTextDocument::FindFlags constructFindFlags(SearchDirection eDirection);
    111108
    112     /** Holds the reference to the VM Log-Viewer this search-panel belongs to. */
    113     UIVMLogViewerWidget *m_pViewer;
    114     /** Holds the instance of main-layout we create. */
    115     QHBoxLayout *m_pMainLayout;
    116     /** Holds the instance of close-button we create. */
    117     UIMiniCancelButton *m_pCloseButton;
    118109    /** Holds the instance of search-label we create. */
    119110    QLabel *m_pSearchLabel;
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70487 r70500  
    151151        m_iContextMenuBookmark.second = block.text();
    152152
    153         if(pAction)
     153        if (pAction)
    154154            connect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark);
    155155
    156156        menu->exec(pEvent->globalPos());
    157157
    158         if(pAction)
     158        if (pAction)
    159159            disconnect(pAction, &QAction::triggered, this, &UIVMLogViewerTextEdit::sltBookmark);
    160160
     
    236236}
    237237
     238void UIVMLogViewerWidget::sltPanelActionTriggered(bool checked)
     239{
     240    QAction *pSenderAction = qobject_cast<QAction*>(sender());
     241    if(!pSenderAction)
     242        return;
     243    /* Look for the sender() within the m_panelActionMap's values: */
     244    for(QMap<UIVMLogViewerPanel**, QAction**>::const_iterator iterator = m_panelActionMap.begin();
     245        iterator != m_panelActionMap.end(); ++iterator)
     246    {
     247        if(iterator.value() == &pSenderAction)
     248            continue;
     249    }
     250}
     251
    238252void UIVMLogViewerWidget::sltShowHideSearchPanel()
    239253{
    240     if(!m_pSearchPanel)
     254    if (!m_pSearchPanel)
    241255        return;
    242256    /* Show/hide search-panel: */
     
    296310
    297311    /* Apply the filter settings: */
    298     if(m_pFilterPanel)
     312    if (m_pFilterPanel)
    299313        m_pFilterPanel->applyFilter();
    300314
     
    321335        return;
    322336    UIVMLogViewerTextEdit *logPage = qobject_cast<UIVMLogViewerTextEdit*>(currentLogPage());
    323     if(!logPage)
     337    if (!logPage)
    324338        return;
    325339    /* Prepare "save as" dialog: */
     
    351365void UIVMLogViewerWidget::sltShowHideFilterPanel()
    352366{
    353     if(!m_pFilterPanel)
     367    if (!m_pFilterPanel)
    354368        return;
    355369    /* Show/hide filter-panel: */
     
    391405void UIVMLogViewerWidget::sltShowHideBookmarkPanel()
    392406{
    393     if(!m_pBookmarksPanel)
     407    if (!m_pBookmarksPanel)
    394408        return;
    395409    m_pBookmarksPanel->isHidden() ? m_pBookmarksPanel->show() : m_pBookmarksPanel->hide();
     
    398412void UIVMLogViewerWidget::sltCreateBookmarkAtCurrent()
    399413{
    400     if(!currentLogPage())
     414    if (!currentLogPage())
    401415        return;
    402416    QWidget* viewport = currentLogPage()->viewport();
     
    414428{
    415429    QVector<LogBookmark> *pBookmarkVector = currentBookmarkVector();
    416     if(!pBookmarkVector)
     430    if (!pBookmarkVector)
    417431        return;
    418432    pBookmarkVector->push_back(bookmark);
    419     if(m_pBookmarksPanel)
    420     {
    421         m_pBookmarksPanel->update();
     433    if (m_pBookmarksPanel)
     434    {
     435        m_pBookmarksPanel->updateBookmarkList();
    422436        m_pBookmarksPanel->setBookmarkIndex(pBookmarkVector->size() - 1);
    423437    }
     
    499513    AssertPtrReturnVoid(m_pBookmarksPanel);
    500514    {
     515        //QMap<UIVMLogViewerPanel*&, QAction*&> m_panelActionMap;
     516        m_panelActionMap.insert(reinterpret_cast<UIVMLogViewerPanel**>(&m_pBookmarksPanel), &m_pActionBookmark);
     517        //connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigHide, this, &UIVMLogViewerWidget::sltHidePanel);
    501518        installEventFilter(m_pBookmarksPanel);
    502519        m_pBookmarksPanel->hide();
     
    764781const QString* UIVMLogViewerWidget::currentLog()
    765782{
    766     if(!currentLogPage())
     783    if (!currentLogPage())
    767784        return 0;
    768785    return &(m_logMap[currentLogPage()]);
     
    787804{
    788805    UIVMLogViewerTextEdit *logPage = qobject_cast<UIVMLogViewerTextEdit*>(currentLogPage());
    789     if(!logPage)
     806    if (!logPage)
    790807        return 0;
    791808    QString logFileName = logPage->logFileName();
    792     if(logFileName.isEmpty())
     809    if (logFileName.isEmpty())
    793810        return 0;
    794811
     
    799816{
    800817    UIVMLogViewerTextEdit *logPage = qobject_cast<UIVMLogViewerTextEdit*>(currentLogPage());
    801     if(!logPage)
     818    if (!logPage)
    802819        return 0;
    803820    QString logFileName = logPage->logFileName();
    804     if(logFileName.isEmpty())
     821    if (logFileName.isEmpty())
    805822        return 0;
    806823
     
    808825}
    809826
     827void UIVMLogViewerWidget::hidePanel(UIVMLogViewerPanel* panel)
     828{
     829    if (!panel || panel->isHidden())
     830        return;
     831    panel->setVisible(false);
     832}
     833
     834void UIVMLogViewerWidget::showPanel(UIVMLogViewerPanel* panel)
     835{
     836    if (!panel || panel->isVisible())
     837        return;
     838    panel->setVisible(true);
     839}
    810840
    811841QPlainTextEdit* UIVMLogViewerWidget::logPage(int pIndex) const
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70487 r70500  
    3939class UIVMLogViewerBookmarksPanel;
    4040class UIVMLogViewerFilterPanel;
     41class UIVMLogViewerPanel;
    4142class UIVMLogViewerSearchPanel;
    4243
     
    8889    void sltSave();
    8990
     91    void sltPanelActionTriggered(bool checked);
    9092    void sltShowHideFilterPanel();
    9193    void sltShowHideSearchPanel();
    9294    void sltShowHideBookmarkPanel();
     95    /* Handles QAction sync. when a panel is closed (hidden) by panel's own close button */
     96    //void sltPanelCloseButton();
    9397
    9498    /** Handles the search result highlight changes. */
     
    150154    const QVector<LogBookmark>* currentBookmarkVector() const;
    151155
     156    void hidePanel(UIVMLogViewerPanel* panel);
     157    void showPanel(UIVMLogViewerPanel* panel);
     158
    152159    /** Holds whether the dialog is polished. */
    153160    bool m_fIsPolished;
     
    163170
    164171    /** Holds the instance of search-panel. */
    165     UIVMLogViewerSearchPanel *m_pSearchPanel;
     172    UIVMLogViewerSearchPanel    *m_pSearchPanel;
    166173    /** Holds the instance of filter panel. */
    167     UIVMLogViewerFilterPanel *m_pFilterPanel;
     174    UIVMLogViewerFilterPanel    *m_pFilterPanel;
    168175    UIVMLogViewerBookmarksPanel *m_pBookmarksPanel;
     176    QMap<UIVMLogViewerPanel**, QAction**> m_panelActionMap;
    169177
    170178    /** Holds the list of log file content. */
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