VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPaneContainer.cpp

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use