VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerBookmarksWidget.cpp@ 103977

Last change on this file since 103977 was 103923, checked in by vboxsync, 9 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in log viewer classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1/* $Id: UIVMLogViewerBookmarksWidget.cpp 103923 2024-03-19 17:01:11Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIVMLogViewer class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QApplication>
30#include <QComboBox>
31#include <QHBoxLayout>
32#include <QStyle>
33#ifdef RT_OS_SOLARIS
34# include <QFontDatabase>
35#endif
36
37/* GUI includes: */
38#include "QIToolButton.h"
39#include "UIIconPool.h"
40#include "UITranslationEventListener.h"
41#include "UIVMLogViewerBookmarksWidget.h"
42#include "UIVMLogViewerWidget.h"
43
44/* Other VBox includes: */
45#include <iprt/assert.h>
46
47UIVMLogViewerBookmarksWidget::UIVMLogViewerBookmarksWidget(QWidget *pParent, UIVMLogViewerWidget *pViewer)
48 : UIVMLogViewerPane(pParent, pViewer)
49 , m_iMaxBookmarkTextLength(60)
50 , m_pBookmarksComboBox(0)
51 , m_pGotoSelectedBookmark(0)
52 , m_pDeleteAllButton(0)
53 , m_pDeleteCurrentButton(0)
54 , m_pNextButton(0)
55 , m_pPreviousButton(0)
56{
57 prepareWidgets();
58 prepareConnections();
59 sltRetranslateUI();
60 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
61 this, &UIVMLogViewerBookmarksWidget::sltRetranslateUI);
62}
63
64void UIVMLogViewerBookmarksWidget::updateBookmarkList(const QVector<UIVMLogBookmark>& bookmarkList)
65{
66 if (!m_pBookmarksComboBox || !viewer())
67 return;
68
69 m_pBookmarksComboBox->clear();
70 QStringList bList;
71 bList << "";
72 for (int i = 0; i < bookmarkList.size(); ++i)
73 {
74 QString strItem = QString("BookMark %1 at Line %2: %3").arg(QString::number(i)).
75 arg(QString::number(bookmarkList[i].m_iLineNumber)).arg(bookmarkList[i].m_strBlockText);
76
77 if (strItem.length() > m_iMaxBookmarkTextLength)
78 {
79 strItem.resize(m_iMaxBookmarkTextLength);
80 strItem.replace(m_iMaxBookmarkTextLength, 3, QString("..."));
81 }
82 bList << strItem;
83 }
84 m_pBookmarksComboBox->addItems(bList);
85 /* Goto last item of the combobox. Avoid emitting sigBookmarkSelected since we dont want text edit to scroll to there: */
86 m_pBookmarksComboBox->blockSignals(true);
87 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->count()-1);
88 m_pBookmarksComboBox->blockSignals(false);
89}
90
91void UIVMLogViewerBookmarksWidget::disableEnableBookmarking(bool flag)
92{
93 m_pBookmarksComboBox->setEnabled(flag);
94 m_pGotoSelectedBookmark->setEnabled(flag);
95 m_pDeleteAllButton->setEnabled(flag);
96 m_pDeleteCurrentButton->setEnabled(flag);
97 m_pNextButton->setEnabled(flag);
98 m_pPreviousButton->setEnabled(flag);
99}
100
101void UIVMLogViewerBookmarksWidget::setBookmarkIndex(int index)
102{
103 if (!m_pBookmarksComboBox)
104 return;
105 /* If there is only Title of the combo, then goto that item: */
106 if (m_pBookmarksComboBox->count() == 1 || index >= m_pBookmarksComboBox->count())
107 {
108 m_pBookmarksComboBox->setCurrentIndex(0);
109 return;
110 }
111 /* index+1 since we always have a 0th item in our combo-box. */
112 m_pBookmarksComboBox->setCurrentIndex(index+1);
113}
114
115void UIVMLogViewerBookmarksWidget::prepareWidgets()
116{
117 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
118 AssertReturnVoid(pMainLayout);
119 /* Create bookmark combo/button layout: */
120 QHBoxLayout *pComboButtonLayout = new QHBoxLayout;
121 AssertReturnVoid(pComboButtonLayout);
122
123 pComboButtonLayout->setContentsMargins(0, 0, 0, 0);
124#ifdef VBOX_WS_MAC
125 pComboButtonLayout->setSpacing(5);
126#else
127 pComboButtonLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);
128#endif
129
130 /* Create bookmark combo-box: */
131 m_pBookmarksComboBox = new QComboBox;
132 AssertReturnVoid(m_pBookmarksComboBox);
133 m_pBookmarksComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
134 /* Make sure we have 0th item in our combo-box. */
135 m_pBookmarksComboBox->insertItem(0, "");
136 pComboButtonLayout->addWidget(m_pBookmarksComboBox);
137
138 /* Create bookmark button layout 1: */
139 QHBoxLayout *pButtonLayout1 = new QHBoxLayout;
140 AssertReturnVoid(pButtonLayout1);
141 pButtonLayout1->setContentsMargins(0, 0, 0, 0);
142 pButtonLayout1->setSpacing(0);
143
144 /* Create goto selected bookmark button: */
145 m_pGotoSelectedBookmark = new QIToolButton;
146 AssertReturnVoid(m_pGotoSelectedBookmark);
147 m_pGotoSelectedBookmark->setIcon(UIIconPool::iconSet(":/log_viewer_goto_selected_bookmark_16px.png"));
148 pButtonLayout1->addWidget(m_pGotoSelectedBookmark);
149
150 /* Create goto previous bookmark button: */
151 m_pPreviousButton = new QIToolButton;
152 AssertReturnVoid(m_pPreviousButton);
153 m_pPreviousButton->setIcon(UIIconPool::iconSet(":/log_viewer_goto_previous_bookmark_16px.png"));
154 pButtonLayout1->addWidget(m_pPreviousButton);
155
156 /* Create goto next bookmark button: */
157 m_pNextButton = new QIToolButton;
158 AssertReturnVoid(m_pNextButton);
159 m_pNextButton->setIcon(UIIconPool::iconSet(":/log_viewer_goto_next_bookmark_16px.png"));
160 pButtonLayout1->addWidget(m_pNextButton);
161
162 pComboButtonLayout->addLayout(pButtonLayout1);
163
164 /* Create bookmark button layout 2: */
165 QHBoxLayout *pButtonLayout2 = new QHBoxLayout;
166 AssertReturnVoid(pButtonLayout2);
167 pButtonLayout2->setContentsMargins(0, 0, 0, 0);
168 pButtonLayout2->setSpacing(0);
169
170 /* Create delete current bookmark button: */
171 m_pDeleteCurrentButton = new QIToolButton;
172 AssertReturnVoid(m_pDeleteCurrentButton);
173 m_pDeleteCurrentButton->setIcon(UIIconPool::iconSet(":/log_viewer_delete_current_bookmark_16px.png"));
174 pButtonLayout2->addWidget(m_pDeleteCurrentButton);
175
176 /* Create delete all bookmarks button: */
177 m_pDeleteAllButton = new QIToolButton;
178 AssertReturnVoid(m_pDeleteAllButton);
179 m_pDeleteAllButton->setIcon(UIIconPool::iconSet(":/log_viewer_delete_all_bookmarks_16px.png"));
180 pButtonLayout2->addWidget(m_pDeleteAllButton);
181 pComboButtonLayout->addLayout(pButtonLayout2);
182
183 pMainLayout->addLayout(pComboButtonLayout);
184
185 pMainLayout->addStretch(1);
186}
187
188void UIVMLogViewerBookmarksWidget::prepareConnections()
189{
190 connect(m_pBookmarksComboBox, &QComboBox::currentIndexChanged, this, &UIVMLogViewerBookmarksWidget::sltBookmarkSelected);
191
192 connect(m_pGotoSelectedBookmark, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoSelectedBookmark);
193 connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoNextBookmark);
194 connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoPreviousBookmark);
195
196 connect(m_pDeleteAllButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sigDeleteAllBookmarks);
197 connect(m_pDeleteCurrentButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltDeleteCurrentBookmark);
198}
199
200
201void UIVMLogViewerBookmarksWidget::sltRetranslateUI()
202{
203 m_pDeleteCurrentButton->setToolTip(UIVMLogViewerWidget::tr("Delete the current bookmark"));
204 m_pDeleteAllButton->setToolTip(UIVMLogViewerWidget::tr("Delete all bookmarks"));
205 m_pNextButton->setToolTip(UIVMLogViewerWidget::tr("Go to the next bookmark"));
206 m_pPreviousButton->setToolTip(UIVMLogViewerWidget::tr("Go to the previous bookmark"));
207 m_pGotoSelectedBookmark->setToolTip(UIVMLogViewerWidget::tr("Go to selected bookmark"));
208}
209
210void UIVMLogViewerBookmarksWidget::sltDeleteCurrentBookmark()
211{
212 if (!m_pBookmarksComboBox)
213 return;
214
215 if (m_pBookmarksComboBox->currentIndex() == 0)
216 return;
217 emit sigDeleteBookmarkByIndex(m_pBookmarksComboBox->currentIndex() - 1);
218}
219
220void UIVMLogViewerBookmarksWidget::sltBookmarkSelected(int index)
221{
222 /* Do nothing if the index is 0, that is combo-box title item: */
223 if (index <= 0)
224 return;
225 emit sigBookmarkSelected(index - 1);
226}
227
228
229void UIVMLogViewerBookmarksWidget::sltGotoNextBookmark()
230{
231 /* go to next bookmark or wrap around to the beginning of the list: */
232 if (m_pBookmarksComboBox->currentIndex() == m_pBookmarksComboBox->count()-1)
233 m_pBookmarksComboBox->setCurrentIndex(1);
234 else
235 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->currentIndex() + 1);
236}
237
238
239void UIVMLogViewerBookmarksWidget::sltGotoPreviousBookmark()
240{
241 /* go to previous bookmark or wrap around to the end of the list: */
242 if (m_pBookmarksComboBox->currentIndex() <= 1)
243 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->count() - 1);
244 else
245 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->currentIndex() - 1);
246}
247
248void UIVMLogViewerBookmarksWidget::sltGotoSelectedBookmark()
249{
250 if (!m_pBookmarksComboBox || m_pBookmarksComboBox->count() <= 1)
251 return;
252 emit sigBookmarkSelected(m_pBookmarksComboBox->currentIndex() - 1);
253}
Note: See TracBrowser for help on using the repository browser.

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