VirtualBox

Changeset 70529 in vbox


Ignore:
Timestamp:
Jan 11, 2018 7:46:27 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120199
Message:

FE/Qt bugref:9072 Improve bookmarks panel

Location:
trunk/src/VBox/Frontends/VirtualBox/src/logviewer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.cpp

    r70500 r70529  
    2727# endif
    2828# include <QLabel>
    29 # include <QLineEdit>
    30 # include <QPlainTextEdit>
    3129# include <QPushButton>
    32 # include <QTextCursor>
    33 # include <QToolButton>
    34 # include <QScrollArea>
    35 
     30# include <QSpacerItem>
    3631/* GUI includes: */
    37 # include "UIIconPool.h"
    38 # include "UISpecialControls.h"
     32# include "QIToolButton.h"
    3933# include "UIVMLogViewerBookmarksPanel.h"
    4034# include "UIVMLogViewerWidget.h"
    41 # ifdef VBOX_WS_MAC
    42 #  include "VBoxUtils-darwin.h"
    43 # endif
     35
    4436#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4537
     
    4941    , m_iMaxBookmarkTextLength(60)
    5042    , m_pBookmarksComboBox(0)
    51     , m_clearAllButton(0)
    52     , m_clearCurrentButton(0)
     43    , m_pDeleteAllButton(0)
     44    , m_pDeleteCurrentButton(0)
     45    , m_pSpacerItem(0)
    5346{
    5447    prepare();
    5548}
    5649
    57 void UIVMLogViewerBookmarksPanel::updateBookmarkList()
     50void UIVMLogViewerBookmarksPanel::updateBookmarkList(const QVector<QPair<int, QString> > *bookmarkVector)
    5851{
    5952    if (!m_pBookmarksComboBox || !viewer())
    6053        return;
    61     const QVector<QPair<int, QString> > *bookmarkVector = viewer()->currentBookmarkVector();
    6254    if (!bookmarkVector)
    6355        return;
     
    6557    m_pBookmarksComboBox->clear();
    6658    QStringList bList;
     59    bList << "Bookmarks List";
    6760    for(int i = 0; i < bookmarkVector->size(); ++i)
    6861    {
     
    7871    }
    7972    m_pBookmarksComboBox->addItems(bList);
     73    /* Goto last item of the combobox: */
     74    m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->count()-1);
    8075}
    8176
     
    8479    if (!m_pBookmarksComboBox)
    8580        return;
    86     if (index >= m_pBookmarksComboBox->count())
     81    /* If there is only Title of the combo, then goto that item: */
     82    if (m_pBookmarksComboBox->count() == 1 || index >= m_pBookmarksComboBox->count())
     83    {
     84        m_pBookmarksComboBox->setCurrentIndex(0);
    8785        return;
    88     m_pBookmarksComboBox->setCurrentIndex(index);
     86    }
     87    /* index+1 since we always have a 0th item in our combo box. */
     88    m_pBookmarksComboBox->setCurrentIndex(index+1);
    8989}
    9090
     
    9999    m_pBookmarksComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
    100100    m_pBookmarksComboBox->setMaximumWidth(fontMetrics.width('a') * (m_iMaxBookmarkTextLength + 2));
    101     mainLayout()->addWidget(m_pBookmarksComboBox, 2, Qt::AlignLeft);
     101    /* Make sure we have 0th item in our combo box. */
     102    m_pBookmarksComboBox->insertItem(0, "Bookmarks List");
     103
     104
     105    mainLayout()->addWidget(m_pBookmarksComboBox, 2/*, Qt::AlignLeft*/);
     106
     107    m_pDeleteCurrentButton = new QIToolButton(this);
     108    m_pDeleteCurrentButton->setIcon(m_pDeleteCurrentButton->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
     109
     110    AssertPtrReturnVoid(m_pBookmarksComboBox);
     111    mainLayout()->addWidget(m_pDeleteCurrentButton, 0);
     112
     113    m_pDeleteAllButton = new QPushButton(this);
     114    AssertPtrReturnVoid(m_pDeleteAllButton);
     115    mainLayout()->addWidget(m_pDeleteAllButton, 0);
     116
     117
     118    m_pSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
     119    AssertPtrReturnVoid(m_pSpacerItem);
     120    mainLayout()->addItem(m_pSpacerItem);
    102121}
    103122
    104123void UIVMLogViewerBookmarksPanel::prepareConnections()
    105124{
     125    connect(m_pBookmarksComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
     126            this, &UIVMLogViewerBookmarksPanel::sltBookmarkSelected);
     127
     128    connect(m_pDeleteAllButton, &QPushButton::clicked, this, &UIVMLogViewerBookmarksPanel::sigDeleteAllBookmarks);
     129    connect(m_pDeleteCurrentButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksPanel::sltDeleteCurrentBookmark);
    106130}
    107131
     
    109133void UIVMLogViewerBookmarksPanel::retranslateUi()
    110134{
     135    if (m_pDeleteCurrentButton)
     136        m_pDeleteCurrentButton->setToolTip(UIVMLogViewerWidget::tr("Delete the current bookmark."));
     137    if (m_pDeleteAllButton)
     138    {
     139        m_pDeleteAllButton->setToolTip(UIVMLogViewerWidget::tr("Delete all bookmarks."));
     140        m_pDeleteAllButton->setText(UIVMLogViewerWidget::tr("Delete all"));
     141    }
    111142    UIVMLogViewerPanel::retranslateUi();
    112143}
     144
     145void UIVMLogViewerBookmarksPanel::sltDeleteCurrentBookmark()
     146{
     147    if (!m_pBookmarksComboBox)
     148        return;
     149
     150    if (m_pBookmarksComboBox->currentIndex() == 0)
     151        return;
     152    emit sigDeleteBookmark(m_pBookmarksComboBox->currentIndex() - 1);
     153}
     154
     155void UIVMLogViewerBookmarksPanel::sltBookmarkSelected(int index)
     156{
     157    /* Do nothing if the index is 0, that is combo box title item: */
     158    if (index <= 0)
     159        return;
     160   emit sigBookmarkSelected(index - 1);
     161}
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksPanel.h

    r70500 r70529  
    2525class QComboBox;
    2626class QPushButton;
    27 
    28 
    29 
     27class QSpacerItem;
     28class QIToolButton;
    3029
    3130/** UIVMLogViewerPanel extension providing GUI for bookmark management. Show a list of bookmarks currently set
     
    3635
    3736signals:
     37
     38    void sigDeleteBookmark(int bookmarkIndex);
     39    void sigDeleteAllBookmarks();
     40    void sigBookmarkSelected(int index);
    3841
    3942public:
     
    4750       user switches to another log page tab etc. */
    4851    void setBookmarksList(const QVector<QPair<int, QString> > &bookmarkList);
    49     void updateBookmarkList();
    50     /* @a index is the index of the curent bookmark. */
    51     void setBookmarkIndex(int index);
     52    void updateBookmarkList(const QVector<QPair<int, QString> > *bookmarkVector);
    5253
    5354public slots:
     
    6364private slots:
    6465
     66    void sltDeleteCurrentBookmark();
     67    void sltBookmarkSelected(int index);
     68
    6569private:
     70
     71    /* @a index is the index of the curent bookmark. */
     72    void setBookmarkIndex(int index);
    6673
    6774    const int     m_iMaxBookmarkTextLength;
    6875    QComboBox    *m_pBookmarksComboBox;
    69     QPushButton  *m_clearAllButton;
    70     QPushButton  *m_clearCurrentButton;
     76    QPushButton  *m_pDeleteAllButton;
     77    QIToolButton *m_pDeleteCurrentButton;
     78    QSpacerItem  *m_pSpacerItem;
    7179};
    7280
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerPanel.cpp

    r70519 r70529  
    120120    if (pFocus && pFocus->parent() == this)
    121121        focusNextPrevChild(true);
    122     if(m_pViewer)
     122    if (m_pViewer)
    123123        m_pViewer->hidePanel(this);
    124124
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70523 r70529  
    5454/** We use a modified scrollbar style for our QPlainTextEdits to get the
    5555    markings on the scrollbars correctly. The default scrollbarstyle does not
    56     reveal the height of the pushbuttons on the scrollbar to compute the marking
    57     locations correctlt. so we turn them off: */
     56    reveal the height of the pushbuttons on the scrollbar (on either side of it, with arrow on them)
     57    to compute the marking locations correctly. Thus we turn these push buttons off: */
    5858const QString verticalScrollBarStyle("QScrollBar:vertical {"
    5959                                     "border: 1px ridge grey; "
     
    114114
    115115private:
     116
    116117    /* Stores the relative (to scrollbar's height) positions of markings,
    117        where we draw a horizontal line. */
     118       where we draw a horizontal line. Values are in [0.0, 1.0]*/
    118119    QVector<float> m_markingsVector;
    119120};
     
    201202    , m_pActionBookmark(0)
    202203    , m_pMenu(0)
     204    , m_bMarkBookmarkLines(0)
    203205{
    204206    /* Prepare VM Log-Viewer: */
     
    237239}
    238240
     241void UIVMLogViewerWidget::sltDeleteBookmark(int index)
     242{
     243    QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
     244    if(!bookmarkVector || bookmarkVector->size() <= index)
     245        return;
     246    bookmarkVector->remove(index, 1);
     247    if (m_pBookmarksPanel)
     248        m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
     249}
     250
     251void UIVMLogViewerWidget::sltDeleteAllBookmarks()
     252{
     253    QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
     254    if(!bookmarkVector)
     255        return;
     256    bookmarkVector->clear();
     257    if (m_pBookmarksPanel)
     258        m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
     259}
     260
     261void UIVMLogViewerWidget::sltBookmarkSelected(int index)
     262{
     263    QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
     264    if(!bookmarkVector || index >= bookmarkVector->size())
     265        return;
     266    if(!currentLogPage() || !currentLogPage()->document())
     267        return;
     268
     269    int lineNumber = bookmarkVector->at(index).first;
     270    QTextCursor cursor(currentLogPage()->document()->findBlockByLineNumber(lineNumber));
     271    currentLogPage()->setTextCursor(cursor);
     272
     273}
     274
    239275void UIVMLogViewerWidget::sltPanelActionTriggered(bool checked)
    240276{
    241277    QAction *pSenderAction = qobject_cast<QAction*>(sender());
    242     if(!pSenderAction)
     278    if (!pSenderAction)
    243279        return;
    244280    UIVMLogViewerPanel* pPanel = 0;
    245281    /* Look for the sender() within the m_panelActionMap's values: */
    246     for(QMap<UIVMLogViewerPanel*, QAction*>::const_iterator iterator = m_panelActionMap.begin();
     282    for (QMap<UIVMLogViewerPanel*, QAction*>::const_iterator iterator = m_panelActionMap.begin();
    247283        iterator != m_panelActionMap.end(); ++iterator)
    248284    {
    249         if(iterator.value() == pSenderAction)
     285        if (iterator.value() == pSenderAction)
    250286            pPanel = iterator.key();
    251287    }
    252     if(!pPanel)
    253         return;
    254     if(checked)
     288    if (!pPanel)
     289        return;
     290    if (checked)
    255291        showPanel(pPanel);
    256292    else
    257293        hidePanel(pPanel);
    258 }
    259 
    260 void UIVMLogViewerWidget::sltShowHideSearchPanel()
    261 {
    262     if (!m_pSearchPanel)
    263         return;
    264     /* Show/hide search-panel: */
    265     m_pSearchPanel->isHidden() ? m_pSearchPanel->show() : m_pSearchPanel->hide();
    266294}
    267295
     
    371399}
    372400
    373 void UIVMLogViewerWidget::sltShowHideFilterPanel()
    374 {
    375     if (!m_pFilterPanel)
    376         return;
    377     /* Show/hide filter-panel: */
    378     m_pFilterPanel->isHidden() ? m_pFilterPanel->show() : m_pFilterPanel->hide();
    379 }
    380 
    381401void UIVMLogViewerWidget::sltSearchResultHighLigting()
    382402{
     
    402422        m_pSearchPanel->reset();
    403423    m_iCurrentTabIndex = tabIndex;
     424    /* We keep a separate QVector<LogBookmark> for each log page: */
     425    QVector<LogBookmark>* bookmarkVector = currentBookmarkVector();
     426    if(bookmarkVector && m_pBookmarksPanel)
     427        m_pBookmarksPanel->updateBookmarkList(bookmarkVector);
    404428}
    405429
     
    409433    if (m_pSearchPanel && m_pSearchPanel->isVisible())
    410434        m_pSearchPanel->refresh();
    411 }
    412 
    413 void UIVMLogViewerWidget::sltShowHideBookmarkPanel()
    414 {
    415     if (!m_pBookmarksPanel)
    416         return;
    417     m_pBookmarksPanel->isHidden() ? m_pBookmarksPanel->show() : m_pBookmarksPanel->hide();
    418435}
    419436
     
    440457    pBookmarkVector->push_back(bookmark);
    441458    if (m_pBookmarksPanel)
    442     {
    443         m_pBookmarksPanel->updateBookmarkList();
    444         m_pBookmarksPanel->setBookmarkIndex(pBookmarkVector->size() - 1);
    445     }
     459        m_pBookmarksPanel->updateBookmarkList(pBookmarkVector);
    446460}
    447461
     
    528542        m_pBookmarksPanel->hide();
    529543        m_pMainLayout->insertWidget(4, m_pBookmarksPanel);
    530     }
    531 
     544        connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigDeleteBookmark,
     545                this, &UIVMLogViewerWidget::sltDeleteBookmark);
     546        connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigDeleteAllBookmarks,
     547                this, &UIVMLogViewerWidget::sltDeleteAllBookmarks);
     548        connect(m_pBookmarksPanel, &UIVMLogViewerBookmarksPanel::sigBookmarkSelected,
     549                this, &UIVMLogViewerWidget::sltBookmarkSelected);
     550    }
    532551}
    533552
     
    714733    if (m_pActionBookmark)
    715734    {
    716         m_pActionBookmark->setText(tr("&Bookmark..."));
     735        m_pActionBookmark->setText(tr("&Bookmarks"));
    717736        m_pActionBookmark->setToolTip(tr("Bookmark the line"));
    718737        m_pActionBookmark->setStatusTip(tr("Bookmark the line"));
     
    839858        panel->setVisible(false);
    840859    QMap<UIVMLogViewerPanel*, QAction*>::iterator iterator = m_panelActionMap.find(panel);
    841     if(iterator != m_panelActionMap.end())
    842     {
    843         if(iterator.value()->isChecked())
     860    if (iterator != m_panelActionMap.end())
     861    {
     862        if (iterator.value()->isChecked())
    844863            iterator.value()->setChecked(false);
    845864    }
     
    851870        panel->setVisible(true);
    852871    QMap<UIVMLogViewerPanel*, QAction*>::iterator iterator = m_panelActionMap.find(panel);
    853     if(iterator != m_panelActionMap.end())
    854     {
    855         if(!iterator.value()->isChecked())
     872    if (iterator != m_panelActionMap.end())
     873    {
     874        if (!iterator.value()->isChecked())
    856875            iterator.value()->setChecked(true);
    857876    }
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70519 r70529  
    6363    /** Destructs the VM Log-Viewer. */
    6464    ~UIVMLogViewerWidget();
    65     /* Returns the width of the current log page. return 0 if there is no current log page: */
     65    /** Returns the width of the current log page. return 0 if there is no current log page: */
    6666    int defaultLogPageWidth() const;
    6767
     
    8989    void sltSave();
    9090
     91    /** @name Bookmark related slots
     92     * @{ */
     93    /** Deletes the bookmark with @p index from the current logs bookmark list. */
     94        void sltDeleteBookmark(int index);
     95        void sltDeleteAllBookmarks();
     96        /** Scroll the plain text edit to the selected bookmark. */
     97        void sltBookmarkSelected(int index);
     98        /** Creates a bookmark out of line number and block text. */
     99        void sltCreateBookmarkAtLine(QPair<int, QString> bookmark);
     100        /** Determines the (middle) line number of the visible text and calls sltCreateBookmarkAtLine. */
     101        void sltCreateBookmarkAtCurrent();
     102    /** @} */
     103
    91104    void sltPanelActionTriggered(bool checked);
    92     void sltShowHideFilterPanel();
    93     void sltShowHideSearchPanel();
    94     void sltShowHideBookmarkPanel();
    95     /* Handles QAction sync. when a panel is closed (hidden) by panel's own close button */
    96     //void sltPanelCloseButton();
    97 
    98105    /** Handles the search result highlight changes. */
    99106    void sltSearchResultHighLigting();
     
    101108    void sltTabIndexChange(int tabIndex);
    102109    void sltFilterApplied();
    103     /* create a bookmark out of line number and block text. */
    104     void sltCreateBookmarkAtLine(QPair<int, QString> bookmark);
    105     /* Determines the (middle) line number of the visible text and calls sltCreateBookmarkAtLine. */
    106     void sltCreateBookmarkAtCurrent();
    107 
    108110
    109111private:
     
    179181    VMLogMap             m_logMap;
    180182    mutable BookmarkMap  m_bookmarkMap;
    181 
    182     QVBoxLayout      *m_pMainLayout;
    183 
    184     /** Holds the widget embedding type. */
     183    QVBoxLayout         *m_pMainLayout;
     184
     185    /** Holds the widget's embedding type. */
    185186    const EmbedTo m_enmEmbedding;
    186187
     
    199200        /** Holds the Bookmark action instance. */
    200201        QAction   *m_pActionBookmark;
    201 
    202202        /** Holds the menu object instance. */
    203203        QMenu     *m_pMenu;
    204204    /** @} */
    205 
     205    const bool     m_bMarkBookmarkLines;
    206206    friend class UIVMLogViewerBookmarksPanel;
    207207    friend class UIVMLogViewerFilterPanel;
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