VirtualBox

Changeset 86821 in vbox


Ignore:
Timestamp:
Nov 6, 2020 12:19:28 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141265
Message:

FE/Qt: bugref:9831. Some fixes

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r86816 r86821  
    8686    void sigDragging(const QPoint &delta);
    8787    void sigSearchTextChanged(const QString &strSearchText);
     88    void sigSelectNextMatch();
     89    void sigSelectPreviousMatch();
    8890
    8991public:
    9092
    9193    UIFindInPageWidget(QWidget *pParent = 0);
     94    void setMatchCountAndCurrentIndex(int iTotalMatchCount, int iCurrentlyScrolledIndex);
     95    void clearSearchField();
    9296
    9397protected:
     
    100104    void retranslateUi();
    101105    UISearchLineEdit  *m_pSearchLineEdit;
    102     QIToolButton      *m_pDownButton;
    103     QIToolButton      *m_pUpButton;
     106    QIToolButton      *m_pNextButton;
     107    QIToolButton      *m_pPreviousButton;
    104108    QLabel            *m_pDragMoveLabel;
    105109    QPoint m_previousMousePosition;
     
    140144    void sltHandleFindWidgetDrag(const QPoint &delta);
    141145    void sltHandleFindInPageSearchTextChange(const QString &strSearchText);
     146    void sltSelectPreviousMatch();
     147    void sltSelectNextMatch();
    142148
    143149private:
     
    146152    bool isRectInside(const QRect &rect, int iMargin) const;
    147153    void moveFindWidgetIn(int iMargin);
     154    void findAllMatches(const QString &searchString);
     155    void highlightFinds(int iSearchTermLength);
     156    void selectMatch(int iMatchIndex, int iSearchStringLength);
    148157    const QHelpEngine* m_pHelpEngine;
    149 
    150158    UIFindInPageWidget *m_pFindInPageWidget;
    151159    /* Initilized as false and set to true once the find widget is positioned during first resize. */
    152160    bool m_fFindWidgetPositioned;
    153161    const int m_iMarginForFindWidget;
     162    /** Document positions of the cursors within the document for all matches. */
     163    QVector<int>   m_matchedCursorPosition;
     164    int m_iSelectedMatchIndex;
     165    int m_iSearchTermLength;
    154166};
    155167
     
    255267};
    256268
     269
    257270/*********************************************************************************************************************************
    258 *   UIFindInPageWidget implementation.                                                                                        *
     271*   UIFindInPageWidget implementation.                                                                                           *
    259272*********************************************************************************************************************************/
    260273UIFindInPageWidget::UIFindInPageWidget(QWidget *pParent /* = 0 */)
    261274    : QIWithRetranslateUI<QWidget>(pParent)
    262275    , m_pSearchLineEdit(0)
    263     , m_pDownButton(0)
    264     , m_pUpButton(0)
     276    , m_pNextButton(0)
     277    , m_pPreviousButton(0)
    265278    , m_previousMousePosition(-1, -1)
    266279{
    267280    prepare();
     281}
     282
     283void UIFindInPageWidget::setMatchCountAndCurrentIndex(int iTotalMatchCount, int iCurrentlyScrolledIndex)
     284{
     285    if (!m_pSearchLineEdit)
     286        return;
     287    m_pSearchLineEdit->setMatchCount(iTotalMatchCount);
     288    m_pSearchLineEdit->setScrollToIndex(iCurrentlyScrolledIndex);
     289}
     290
     291void UIFindInPageWidget::clearSearchField()
     292{
     293    if (!m_pSearchLineEdit)
     294        return;
     295    m_pSearchLineEdit->blockSignals(true);
     296    m_pSearchLineEdit->reset();
     297    m_pSearchLineEdit->blockSignals(false);
    268298}
    269299
     
    296326    m_pSearchLineEdit = new UISearchLineEdit;
    297327    AssertReturnVoid(pLayout && m_pSearchLineEdit);
    298 
     328    setFocusProxy(m_pSearchLineEdit);
    299329    QFontMetrics fontMetric(m_pSearchLineEdit->font());
    300330    setMinimumSize(40 * fontMetric.width("x"),
     
    316346    pLayout->addWidget(m_pSearchLineEdit);
    317347
    318     m_pUpButton = new QIToolButton;
    319     m_pDownButton = new QIToolButton;
    320 
    321     pLayout->addWidget(m_pUpButton);
    322     pLayout->addWidget(m_pDownButton);
    323 
    324     m_pUpButton->setIcon(UIIconPool::iconSet(":/arrow_up_10px.png"));
    325     m_pDownButton->setIcon(UIIconPool::iconSet(":/arrow_down_10px.png"));
    326 
     348    m_pPreviousButton = new QIToolButton;
     349    m_pNextButton = new QIToolButton;
     350
     351    pLayout->addWidget(m_pPreviousButton);
     352    pLayout->addWidget(m_pNextButton);
     353
     354    m_pPreviousButton->setIcon(UIIconPool::iconSet(":/arrow_up_10px.png"));
     355    m_pNextButton->setIcon(UIIconPool::iconSet(":/arrow_down_10px.png"));
     356
     357    connect(m_pPreviousButton, &QIToolButton::pressed, this, &UIFindInPageWidget::sigSelectPreviousMatch);
     358    connect(m_pNextButton, &QIToolButton::pressed, this, &UIFindInPageWidget::sigSelectNextMatch);
    327359}
    328360
     
    581613    , m_fFindWidgetPositioned(false)
    582614    , m_iMarginForFindWidget(qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin))
    583 {
     615    , m_iSelectedMatchIndex(0)
     616    , m_iSearchTermLength(0)
     617{
     618    setUndoRedoEnabled(true);
    584619    connect(m_pFindInPageWidget, &UIFindInPageWidget::sigDragging,
    585620            this, &UIHelpBrowserViewer::sltHandleFindWidgetDrag);
    586621    connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSearchTextChanged,
    587622            this, &UIHelpBrowserViewer::sltHandleFindInPageSearchTextChange);
     623
     624    connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSelectPreviousMatch,
     625            this, &UIHelpBrowserViewer::sltSelectPreviousMatch);
     626    connect(m_pFindInPageWidget, &UIFindInPageWidget::sigSelectNextMatch,
     627            this, &UIHelpBrowserViewer::sltSelectNextMatch);
     628
    588629    m_pFindInPageWidget->setVisible(false);
    589630    retranslateUi();
     
    614655void UIHelpBrowserViewer::toggleFindInPageWidget(bool fVisible)
    615656{
    616     if (m_pFindInPageWidget)
    617     {
    618         m_pFindInPageWidget->setVisible(fVisible);
    619         update();
    620     }
     657    if (!m_pFindInPageWidget)
     658        return;
     659    m_pFindInPageWidget->setVisible(fVisible);
     660
     661    if (!fVisible)
     662    {
     663        document()->undo();
     664        m_pFindInPageWidget->clearSearchField();
     665    }
     666    else
     667        m_pFindInPageWidget->setFocus();
    621668}
    622669
     
    684731}
    685732
    686  bool UIHelpBrowserViewer::isRectInside(const QRect &rect, int iMargin) const
     733bool UIHelpBrowserViewer::isRectInside(const QRect &rect, int iMargin) const
    687734{
    688735    if (rect.left() < iMargin || rect.top() < iMargin)
     
    693740}
    694741
     742void UIHelpBrowserViewer::findAllMatches(const QString &searchString)
     743{
     744    QTextDocument *pDocument = document();
     745    AssertReturnVoid(pDocument);
     746
     747    m_matchedCursorPosition.clear();
     748    if (searchString.isEmpty())
     749        return;
     750    QTextCursor cursor(pDocument);
     751    QTextDocument::FindFlags flags;
     752    int iMatchCount = 0;
     753    while (!cursor.isNull() && !cursor.atEnd())
     754    {
     755        cursor = pDocument->find(searchString, cursor, flags);
     756        if (!cursor.isNull())
     757        {
     758            m_matchedCursorPosition << cursor.position() - searchString.length();
     759            ++iMatchCount;
     760        }
     761    }
     762}
     763
     764void UIHelpBrowserViewer::highlightFinds(int iSearchTermLength)
     765{
     766    QTextDocument* pDocument = document();
     767    AssertReturnVoid(pDocument);
     768    /* Clear previous highlight: */
     769    pDocument->undo();
     770
     771    QTextCursor highlightCursor(pDocument);
     772    QTextCharFormat colorFormat(highlightCursor.charFormat());
     773    QTextCursor cursor(pDocument);
     774    cursor.beginEditBlock();
     775    colorFormat.setBackground(Qt::yellow);
     776    for (int i = 0; i < m_matchedCursorPosition.size(); ++i)
     777    {
     778        highlightCursor.setPosition(m_matchedCursorPosition[i]);
     779        highlightCursor.setPosition(m_matchedCursorPosition[i] + iSearchTermLength, QTextCursor::KeepAnchor);
     780        if (!highlightCursor.isNull())
     781            highlightCursor.mergeCharFormat(colorFormat);
     782    }
     783    cursor.endEditBlock();
     784}
     785
     786void UIHelpBrowserViewer::selectMatch(int iMatchIndex, int iSearchStringLength)
     787{
     788    QTextCursor cursor = textCursor();
     789    /* Move the cursor to the beginning of the matched string: */
     790    cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex), QTextCursor::MoveAnchor);
     791    /* Move the cursor to the end of the matched string while keeping the anchor at the begining thus selecting the text: */
     792    cursor.setPosition(m_matchedCursorPosition.at(iMatchIndex) + iSearchStringLength, QTextCursor::KeepAnchor);
     793    ensureCursorVisible();
     794    setTextCursor(cursor);
     795}
     796
    695797void UIHelpBrowserViewer::sltHandleOpenInNewTab()
    696798{
     
    718820void UIHelpBrowserViewer::sltHandleFindInPageSearchTextChange(const QString &strSearchText)
    719821{
    720     printf("%s\n", qPrintable(strSearchText));
    721 }
     822    m_iSearchTermLength = strSearchText.length();
     823    findAllMatches(strSearchText);
     824    highlightFinds(m_iSearchTermLength);
     825    //scrollToMatch(int iMatchIndex);
     826    selectMatch(0, m_iSearchTermLength);
     827    if (m_pFindInPageWidget)
     828        m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), 0);
     829}
     830
     831void UIHelpBrowserViewer::sltSelectPreviousMatch()
     832{
     833    m_iSelectedMatchIndex = m_iSelectedMatchIndex <= 0 ? m_matchedCursorPosition.size() - 1 : (m_iSelectedMatchIndex - 1);
     834    selectMatch(m_iSelectedMatchIndex, m_iSearchTermLength);
     835    if (m_pFindInPageWidget)
     836        m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), m_iSelectedMatchIndex);
     837}
     838
     839void UIHelpBrowserViewer::sltSelectNextMatch()
     840{
     841    m_iSelectedMatchIndex = m_iSelectedMatchIndex >= m_matchedCursorPosition.size() - 1 ? 0 : (m_iSelectedMatchIndex + 1);
     842    selectMatch(m_iSelectedMatchIndex, m_iSearchTermLength);
     843    if (m_pFindInPageWidget)
     844        m_pFindInPageWidget->setMatchCountAndCurrentIndex(m_matchedCursorPosition.size(), m_iSelectedMatchIndex);
     845}
     846
    722847
    723848/*********************************************************************************************************************************
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerSearchPanel.cpp

    r86814 r86821  
    409409    {
    410410        m_pSearchEditor->setMatchCount(m_matchedCursorPosition.size());
    411         m_pSearchEditor->setScroolToIndex(m_matchedCursorPosition.empty() ? -1 : 0);
     411        m_pSearchEditor->setScrollToIndex(m_matchedCursorPosition.empty() ? -1 : 0);
    412412    }
    413413    if (m_pHighlightAllCheckBox->isChecked())
     
    494494    textEdit()->ensureCursorVisible();
    495495    textEdit()->setTextCursor(cursor);
    496     return;
    497496}
    498497
     
    505504    selectMatch(m_iSelectedMatchIndex, m_pSearchEditor->text());
    506505    if (m_pSearchEditor)
    507         m_pSearchEditor->setScroolToIndex(m_iSelectedMatchIndex);
     506        m_pSearchEditor->setScrollToIndex(m_iSelectedMatchIndex);
    508507}
    509508
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserSearchWidget.cpp

    r84587 r86821  
    5454    if (!m_pLineEdit)
    5555        return;
    56     m_pLineEdit->setScroolToIndex(iScrollToIndex);
     56    m_pLineEdit->setScrollToIndex(iScrollToIndex);
    5757}
    5858
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSearchWidget.cpp

    r82968 r86821  
    262262        return;
    263263    m_pSearchTermLineEdit->setMatchCount(iMatchCount);
    264     m_pSearchTermLineEdit->setScroolToIndex(iScrollToIndex);
    265 }
     264    m_pSearchTermLineEdit->setScrollToIndex(iScrollToIndex);
     265}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.cpp

    r86816 r86821  
    7575}
    7676
    77 void UISearchLineEdit::setScroolToIndex(int iScrollToIndex)
     77void UISearchLineEdit::setScrollToIndex(int iScrollToIndex)
    7878{
    7979    if (m_iScrollToIndex == iScrollToIndex)
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UISearchLineEdit.h

    r82968 r86821  
    4141    UISearchLineEdit(QWidget *pParent = 0);
    4242    void setMatchCount(int iMatchCount);
    43     void setScroolToIndex(int iScrollToIndex);
     43    void setScrollToIndex(int iScrollToIndex);
    4444    void reset();
    4545
Note: See TracChangeset for help on using the changeset viewer.

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