VirtualBox

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

Last change on this file since 102493 was 101563, checked in by vboxsync, 11 months ago

FE/Qt: bugref:10450: Get rid of Qt5 stuff; This one is about signal connection ambiguity stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: UIVMLogViewerBookmarksWidget.cpp 101563 2023-10-23 23:36:38Z 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 <QComboBox>
30#include <QHBoxLayout>
31#include <QStyle>
32#ifdef RT_OS_SOLARIS
33# include <QFontDatabase>
34#endif
35
36/* GUI includes: */
37#include "QIToolButton.h"
38#include "UIIconPool.h"
39#include "UIVMLogViewerBookmarksWidget.h"
40#include "UIVMLogViewerWidget.h"
41
42/* Other VBox includes: */
43#include <iprt/assert.h>
44
45UIVMLogViewerBookmarksWidget::UIVMLogViewerBookmarksWidget(QWidget *pParent, UIVMLogViewerWidget *pViewer)
46 : UIVMLogViewerPane(pParent, pViewer)
47 , m_iMaxBookmarkTextLength(60)
48 , m_pBookmarksComboBox(0)
49 , m_pGotoSelectedBookmark(0)
50 , m_pDeleteAllButton(0)
51 , m_pDeleteCurrentButton(0)
52 , m_pNextButton(0)
53 , m_pPreviousButton(0)
54{
55 prepareWidgets();
56 prepareConnections();
57 retranslateUi();
58}
59
60void UIVMLogViewerBookmarksWidget::updateBookmarkList(const QVector<UIVMLogBookmark>& bookmarkList)
61{
62 if (!m_pBookmarksComboBox || !viewer())
63 return;
64
65 m_pBookmarksComboBox->clear();
66 QStringList bList;
67 bList << "";
68 for (int i = 0; i < bookmarkList.size(); ++i)
69 {
70 QString strItem = QString("BookMark %1 at Line %2: %3").arg(QString::number(i)).
71 arg(QString::number(bookmarkList[i].m_iLineNumber)).arg(bookmarkList[i].m_strBlockText);
72
73 if (strItem.length() > m_iMaxBookmarkTextLength)
74 {
75 strItem.resize(m_iMaxBookmarkTextLength);
76 strItem.replace(m_iMaxBookmarkTextLength, 3, QString("..."));
77 }
78 bList << strItem;
79 }
80 m_pBookmarksComboBox->addItems(bList);
81 /* Goto last item of the combobox. Avoid emitting sigBookmarkSelected since we dont want text edit to scroll to there: */
82 m_pBookmarksComboBox->blockSignals(true);
83 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->count()-1);
84 m_pBookmarksComboBox->blockSignals(false);
85}
86
87void UIVMLogViewerBookmarksWidget::disableEnableBookmarking(bool flag)
88{
89 m_pBookmarksComboBox->setEnabled(flag);
90 m_pGotoSelectedBookmark->setEnabled(flag);
91 m_pDeleteAllButton->setEnabled(flag);
92 m_pDeleteCurrentButton->setEnabled(flag);
93 m_pNextButton->setEnabled(flag);
94 m_pPreviousButton->setEnabled(flag);
95}
96
97void UIVMLogViewerBookmarksWidget::setBookmarkIndex(int index)
98{
99 if (!m_pBookmarksComboBox)
100 return;
101 /* If there is only Title of the combo, then goto that item: */
102 if (m_pBookmarksComboBox->count() == 1 || index >= m_pBookmarksComboBox->count())
103 {
104 m_pBookmarksComboBox->setCurrentIndex(0);
105 return;
106 }
107 /* index+1 since we always have a 0th item in our combo-box. */
108 m_pBookmarksComboBox->setCurrentIndex(index+1);
109}
110
111void UIVMLogViewerBookmarksWidget::prepareWidgets()
112{
113 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
114 AssertReturnVoid(pMainLayout);
115 /* Create bookmark combo/button layout: */
116 QHBoxLayout *pComboButtonLayout = new QHBoxLayout;
117 AssertReturnVoid(pComboButtonLayout);
118
119 pComboButtonLayout->setContentsMargins(0, 0, 0, 0);
120#ifdef VBOX_WS_MAC
121 pComboButtonLayout->setSpacing(5);
122#else
123 pComboButtonLayout->setSpacing(qApp->style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing) / 2);
124#endif
125
126 /* Create bookmark combo-box: */
127 m_pBookmarksComboBox = new QComboBox;
128 AssertReturnVoid(m_pBookmarksComboBox);
129 m_pBookmarksComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
130 /* Make sure we have 0th item in our combo-box. */
131 m_pBookmarksComboBox->insertItem(0, "");
132 pComboButtonLayout->addWidget(m_pBookmarksComboBox);
133
134 /* Create bookmark button layout 1: */
135 QHBoxLayout *pButtonLayout1 = new QHBoxLayout;
136 AssertReturnVoid(pButtonLayout1);
137 pButtonLayout1->setContentsMargins(0, 0, 0, 0);
138 pButtonLayout1->setSpacing(0);
139
140 /* Create goto selected bookmark button: */
141 m_pGotoSelectedBookmark = new QIToolButton;
142 AssertReturnVoid(m_pGotoSelectedBookmark);
143 m_pGotoSelectedBookmark->setIcon(UIIconPool::iconSet(":/log_viewer_goto_selected_bookmark_16px.png"));
144 pButtonLayout1->addWidget(m_pGotoSelectedBookmark);
145
146 /* Create goto previous bookmark button: */
147 m_pPreviousButton = new QIToolButton;
148 AssertReturnVoid(m_pPreviousButton);
149 m_pPreviousButton->setIcon(UIIconPool::iconSet(":/log_viewer_goto_previous_bookmark_16px.png"));
150 pButtonLayout1->addWidget(m_pPreviousButton);
151
152 /* Create goto next bookmark button: */
153 m_pNextButton = new QIToolButton;
154 AssertReturnVoid(m_pNextButton);
155 m_pNextButton->setIcon(UIIconPool::iconSet(":/log_viewer_goto_next_bookmark_16px.png"));
156 pButtonLayout1->addWidget(m_pNextButton);
157
158 pComboButtonLayout->addLayout(pButtonLayout1);
159
160 /* Create bookmark button layout 2: */
161 QHBoxLayout *pButtonLayout2 = new QHBoxLayout;
162 AssertReturnVoid(pButtonLayout2);
163 pButtonLayout2->setContentsMargins(0, 0, 0, 0);
164 pButtonLayout2->setSpacing(0);
165
166 /* Create delete current bookmark button: */
167 m_pDeleteCurrentButton = new QIToolButton;
168 AssertReturnVoid(m_pDeleteCurrentButton);
169 m_pDeleteCurrentButton->setIcon(UIIconPool::iconSet(":/log_viewer_delete_current_bookmark_16px.png"));
170 pButtonLayout2->addWidget(m_pDeleteCurrentButton);
171
172 /* Create delete all bookmarks button: */
173 m_pDeleteAllButton = new QIToolButton;
174 AssertReturnVoid(m_pDeleteAllButton);
175 m_pDeleteAllButton->setIcon(UIIconPool::iconSet(":/log_viewer_delete_all_bookmarks_16px.png"));
176 pButtonLayout2->addWidget(m_pDeleteAllButton);
177 pComboButtonLayout->addLayout(pButtonLayout2);
178
179 pMainLayout->addLayout(pComboButtonLayout);
180
181 pMainLayout->addStretch(1);
182}
183
184void UIVMLogViewerBookmarksWidget::prepareConnections()
185{
186 connect(m_pBookmarksComboBox, &QComboBox::currentIndexChanged, this, &UIVMLogViewerBookmarksWidget::sltBookmarkSelected);
187
188 connect(m_pGotoSelectedBookmark, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoSelectedBookmark);
189 connect(m_pNextButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoNextBookmark);
190 connect(m_pPreviousButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltGotoPreviousBookmark);
191
192 connect(m_pDeleteAllButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sigDeleteAllBookmarks);
193 connect(m_pDeleteCurrentButton, &QIToolButton::clicked, this, &UIVMLogViewerBookmarksWidget::sltDeleteCurrentBookmark);
194}
195
196
197void UIVMLogViewerBookmarksWidget::retranslateUi()
198{
199 UIVMLogViewerPane::retranslateUi();
200
201 m_pDeleteCurrentButton->setToolTip(UIVMLogViewerWidget::tr("Delete the current bookmark"));
202 m_pDeleteAllButton->setToolTip(UIVMLogViewerWidget::tr("Delete all bookmarks"));
203 m_pNextButton->setToolTip(UIVMLogViewerWidget::tr("Go to the next bookmark"));
204 m_pPreviousButton->setToolTip(UIVMLogViewerWidget::tr("Go to the previous bookmark"));
205 m_pGotoSelectedBookmark->setToolTip(UIVMLogViewerWidget::tr("Go to selected bookmark"));
206}
207
208void UIVMLogViewerBookmarksWidget::sltDeleteCurrentBookmark()
209{
210 if (!m_pBookmarksComboBox)
211 return;
212
213 if (m_pBookmarksComboBox->currentIndex() == 0)
214 return;
215 emit sigDeleteBookmarkByIndex(m_pBookmarksComboBox->currentIndex() - 1);
216}
217
218void UIVMLogViewerBookmarksWidget::sltBookmarkSelected(int index)
219{
220 /* Do nothing if the index is 0, that is combo-box title item: */
221 if (index <= 0)
222 return;
223 emit sigBookmarkSelected(index - 1);
224}
225
226
227void UIVMLogViewerBookmarksWidget::sltGotoNextBookmark()
228{
229 /* go to next bookmark or wrap around to the beginning of the list: */
230 if (m_pBookmarksComboBox->currentIndex() == m_pBookmarksComboBox->count()-1)
231 m_pBookmarksComboBox->setCurrentIndex(1);
232 else
233 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->currentIndex() + 1);
234}
235
236
237void UIVMLogViewerBookmarksWidget::sltGotoPreviousBookmark()
238{
239 /* go to previous bookmark or wrap around to the end of the list: */
240 if (m_pBookmarksComboBox->currentIndex() <= 1)
241 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->count() - 1);
242 else
243 m_pBookmarksComboBox->setCurrentIndex(m_pBookmarksComboBox->currentIndex() - 1);
244}
245
246void UIVMLogViewerBookmarksWidget::sltGotoSelectedBookmark()
247{
248 if (!m_pBookmarksComboBox || m_pBookmarksComboBox->count() <= 1)
249 return;
250 emit sigBookmarkSelected(m_pBookmarksComboBox->currentIndex() - 1);
251}
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