VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPaneContainer.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: 4.6 KB
Line 
1/* $Id: UIPaneContainer.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 <QAbstractButton>
30#include <QComboBox>
31#include <QLabel>
32#include <QPlainTextEdit>
33#include <QPushButton>
34#include <QTextCursor>
35#include <QToolButton>
36#include <QVBoxLayout>
37
38/* GUI includes: */
39#include "QIDialogButtonBox.h"
40#include "UIIconPool.h"
41#include "UIPaneContainer.h"
42#include "UITranslationEventListener.h"
43#ifdef VBOX_WS_MAC
44# include "VBoxUtils-darwin.h"
45#endif
46
47/* Other VBox includes: */
48#include <iprt/assert.h>
49
50UIPaneContainer::UIPaneContainer(QWidget *pParent, EmbedTo enmEmbedTo /* = EmbedTo_Stack */, bool fDetachAllowed /* = false */)
51 : QWidget(pParent)
52 , m_enmEmbedTo(enmEmbedTo)
53 , m_fDetachAllowed(fDetachAllowed)
54 , m_pTabWidget(0)
55 , m_pButtonBox(0)
56{
57 prepare();
58 sltRetranslateUI();
59 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
60 this, &UIPaneContainer::sltRetranslateUI);
61}
62
63void UIPaneContainer::sltRetranslateUI()
64{
65 if (m_pButtonBox)
66 {
67 m_pButtonBox->button(QDialogButtonBox::Cancel)->setText(tr("Detach"));
68 m_pButtonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Open the tool in separate window"));
69 m_pButtonBox->button(QDialogButtonBox::Cancel)->setToolTip(tr("Open in Separate Window"));
70 }
71}
72
73void UIPaneContainer::prepare()
74{
75 QVBoxLayout *pLayout = new QVBoxLayout(this);
76 AssertReturnVoid(pLayout);
77 pLayout->setContentsMargins(0, 0, 0, 0);
78
79 /* Add the tab widget: */
80 m_pTabWidget = new QTabWidget;
81 AssertReturnVoid(m_pTabWidget);
82 connect(m_pTabWidget, &QTabWidget::currentChanged, this, &UIPaneContainer::sigCurrentTabChanged);
83 pLayout->addWidget(m_pTabWidget);
84
85 /* If parent embedded into stack: */
86 if (m_enmEmbedTo == EmbedTo_Stack && m_fDetachAllowed)
87 {
88 /* Add the button-box: */
89 QWidget *pContainer = new QWidget;
90 AssertReturnVoid(pContainer);
91 QHBoxLayout *pSubLayout = new QHBoxLayout(pContainer);
92 AssertReturnVoid(pSubLayout);
93 const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
94 const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin);
95 const int iB = qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin);
96 pSubLayout->setContentsMargins(iL, 0, iR, iB);
97 m_pButtonBox = new QIDialogButtonBox;
98 AssertReturnVoid(m_pButtonBox);
99 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
100 connect(m_pButtonBox, &QIDialogButtonBox::clicked, this, &UIPaneContainer::sltHandleButtonBoxClick);
101 pSubLayout->addWidget(m_pButtonBox);
102 pLayout->addWidget(pContainer);
103 }
104}
105
106void UIPaneContainer::sltHide()
107{
108 hide();
109 emit sigHidden();
110}
111
112void UIPaneContainer::sltHandleButtonBoxClick(QAbstractButton *pButton)
113{
114 /* Make sure button-box exists: */
115 AssertPtrReturnVoid(m_pButtonBox);
116
117 /* Disable buttons first of all: */
118 m_pButtonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
119
120 /* Compare with known buttons: */
121 if (pButton == m_pButtonBox->button(QDialogButtonBox::Cancel))
122 emit sigDetach();
123}
124
125void UIPaneContainer::insertTab(int iIndex, QWidget *pPage, const QString &strLabel /* = QString() */)
126{
127 if (m_pTabWidget)
128 m_pTabWidget->insertTab(iIndex, pPage, strLabel);
129}
130
131void UIPaneContainer::setTabText(int iIndex, const QString &strText)
132{
133 if (!m_pTabWidget || iIndex < 0 || iIndex >= m_pTabWidget->count())
134 return;
135 m_pTabWidget->setTabText(iIndex, strText);
136}
137
138void UIPaneContainer::setCurrentIndex(int iIndex)
139{
140 if (!m_pTabWidget || iIndex >= m_pTabWidget->count() || iIndex < 0)
141 return;
142 m_pTabWidget->setCurrentIndex(iIndex);
143}
144
145int UIPaneContainer::currentIndex() const
146{
147 if (!m_pTabWidget)
148 return -1;
149 return m_pTabWidget->currentIndex();
150}
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