[70027] | 1 | /* $Id: UIPaneContainer.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBox Qt GUI - UIVMLogViewer class implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[70027] | 8 | *
|
---|
[96407] | 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
|
---|
[70027] | 26 | */
|
---|
| 27 |
|
---|
| 28 | /* Qt includes: */
|
---|
[104358] | 29 | #include <QApplication>
|
---|
[102729] | 30 | #include <QAbstractButton>
|
---|
[76606] | 31 | #include <QComboBox>
|
---|
| 32 | #include <QLabel>
|
---|
| 33 | #include <QPlainTextEdit>
|
---|
[102727] | 34 | #include <QPushButton>
|
---|
[76606] | 35 | #include <QTextCursor>
|
---|
| 36 | #include <QToolButton>
|
---|
[102726] | 37 | #include <QVBoxLayout>
|
---|
[70027] | 38 |
|
---|
| 39 | /* GUI includes: */
|
---|
[102727] | 40 | #include "QIDialogButtonBox.h"
|
---|
[76606] | 41 | #include "UIIconPool.h"
|
---|
[100956] | 42 | #include "UIPaneContainer.h"
|
---|
[103923] | 43 | #include "UITranslationEventListener.h"
|
---|
[76606] | 44 | #ifdef VBOX_WS_MAC
|
---|
| 45 | # include "VBoxUtils-darwin.h"
|
---|
| 46 | #endif
|
---|
[70027] | 47 |
|
---|
[100906] | 48 | /* Other VBox includes: */
|
---|
| 49 | #include <iprt/assert.h>
|
---|
[70466] | 50 |
|
---|
[102727] | 51 | UIPaneContainer::UIPaneContainer(QWidget *pParent, EmbedTo enmEmbedTo /* = EmbedTo_Stack */, bool fDetachAllowed /* = false */)
|
---|
[103923] | 52 | : QWidget(pParent)
|
---|
[102726] | 53 | , m_enmEmbedTo(enmEmbedTo)
|
---|
[102727] | 54 | , m_fDetachAllowed(fDetachAllowed)
|
---|
[100906] | 55 | , m_pTabWidget(0)
|
---|
[102727] | 56 | , m_pButtonBox(0)
|
---|
[100906] | 57 | {
|
---|
| 58 | prepare();
|
---|
[103923] | 59 | sltRetranslateUI();
|
---|
| 60 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 61 | this, &UIPaneContainer::sltRetranslateUI);
|
---|
[100906] | 62 | }
|
---|
| 63 |
|
---|
[103923] | 64 | void UIPaneContainer::sltRetranslateUI()
|
---|
[100955] | 65 | {
|
---|
[102727] | 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"));
|
---|
[102730] | 70 | m_pButtonBox->button(QDialogButtonBox::Cancel)->setToolTip(tr("Open in Separate Window"));
|
---|
[102727] | 71 | }
|
---|
[100955] | 72 | }
|
---|
[100951] | 73 |
|
---|
[100956] | 74 | void UIPaneContainer::prepare()
|
---|
[100906] | 75 | {
|
---|
[102726] | 76 | QVBoxLayout *pLayout = new QVBoxLayout(this);
|
---|
[100906] | 77 | AssertReturnVoid(pLayout);
|
---|
| 78 | pLayout->setContentsMargins(0, 0, 0, 0);
|
---|
[101015] | 79 |
|
---|
| 80 | /* Add the tab widget: */
|
---|
[102726] | 81 | m_pTabWidget = new QTabWidget;
|
---|
| 82 | AssertReturnVoid(m_pTabWidget);
|
---|
[100956] | 83 | connect(m_pTabWidget, &QTabWidget::currentChanged, this, &UIPaneContainer::sigCurrentTabChanged);
|
---|
[100906] | 84 | pLayout->addWidget(m_pTabWidget);
|
---|
[102727] | 85 |
|
---|
[102729] | 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 | }
|
---|
[100955] | 105 | }
|
---|
[100951] | 106 |
|
---|
[100956] | 107 | void UIPaneContainer::sltHide()
|
---|
[100955] | 108 | {
|
---|
| 109 | hide();
|
---|
| 110 | emit sigHidden();
|
---|
[100906] | 111 | }
|
---|
| 112 |
|
---|
[102729] | 113 | void 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 |
|
---|
[100956] | 126 | void UIPaneContainer::insertTab(int iIndex, QWidget *pPage, const QString &strLabel /* = QString() */)
|
---|
[100906] | 127 | {
|
---|
| 128 | if (m_pTabWidget)
|
---|
| 129 | m_pTabWidget->insertTab(iIndex, pPage, strLabel);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[100956] | 132 | void UIPaneContainer::setTabText(int iIndex, const QString &strText)
|
---|
[100906] | 133 | {
|
---|
| 134 | if (!m_pTabWidget || iIndex < 0 || iIndex >= m_pTabWidget->count())
|
---|
| 135 | return;
|
---|
| 136 | m_pTabWidget->setTabText(iIndex, strText);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[100956] | 139 | void UIPaneContainer::setCurrentIndex(int iIndex)
|
---|
[100906] | 140 | {
|
---|
| 141 | if (!m_pTabWidget || iIndex >= m_pTabWidget->count() || iIndex < 0)
|
---|
| 142 | return;
|
---|
| 143 | m_pTabWidget->setCurrentIndex(iIndex);
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[100956] | 146 | int UIPaneContainer::currentIndex() const
|
---|
[100917] | 147 | {
|
---|
| 148 | if (!m_pTabWidget)
|
---|
| 149 | return -1;
|
---|
| 150 | return m_pTabWidget->currentIndex();
|
---|
| 151 | }
|
---|