1 | /* $Id: UIErrorPane.cpp 76606 2019-01-02 05:40:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIErrorPane class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QAction>
|
---|
20 | #include <QHBoxLayout>
|
---|
21 | #include <QLabel>
|
---|
22 | #include <QStyle>
|
---|
23 | #include <QTextBrowser>
|
---|
24 | #include <QToolButton>
|
---|
25 | #include <QVBoxLayout>
|
---|
26 |
|
---|
27 | /* GUI includes */
|
---|
28 | #include "QIWithRetranslateUI.h"
|
---|
29 | #include "UIErrorPane.h"
|
---|
30 |
|
---|
31 | /* Other VBox includes: */
|
---|
32 | #include <iprt/assert.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | UIErrorPane::UIErrorPane(QAction *pRefreshAction /* = 0 */, QWidget *pParent /* = 0 */)
|
---|
36 | : QIWithRetranslateUI<QWidget>(pParent)
|
---|
37 | , m_pActionRefresh(pRefreshAction)
|
---|
38 | , m_pButtonRefresh(0)
|
---|
39 | , m_pLabel(0)
|
---|
40 | , m_pBrowserDetails(0)
|
---|
41 | {
|
---|
42 | /* Prepare: */
|
---|
43 | prepare();
|
---|
44 | }
|
---|
45 |
|
---|
46 | void UIErrorPane::setErrorDetails(const QString &strDetails)
|
---|
47 | {
|
---|
48 | /* Define error details: */
|
---|
49 | m_pBrowserDetails->setText(strDetails);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void UIErrorPane::retranslateUi()
|
---|
53 | {
|
---|
54 | /* Translate label: */
|
---|
55 | if (m_pLabel)
|
---|
56 | m_pLabel->setText(tr("The selected virtual machine is <i>inaccessible</i>. "
|
---|
57 | "Please inspect the error message shown below and press the "
|
---|
58 | "<b>Refresh</b> button if you want to repeat the accessibility check:"));
|
---|
59 |
|
---|
60 | /* Translate refresh button: */
|
---|
61 | if (m_pActionRefresh && m_pButtonRefresh)
|
---|
62 | {
|
---|
63 | m_pButtonRefresh->setText(m_pActionRefresh->text());
|
---|
64 | m_pButtonRefresh->setIcon(m_pActionRefresh->icon());
|
---|
65 | m_pButtonRefresh->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | void UIErrorPane::prepare()
|
---|
70 | {
|
---|
71 | /* Create main layout: */
|
---|
72 | QVBoxLayout *pMainLayout = new QVBoxLayout(this);
|
---|
73 | if (pMainLayout)
|
---|
74 | {
|
---|
75 | /* Configure layout: */
|
---|
76 | #ifdef VBOX_WS_MAC
|
---|
77 | pMainLayout->setContentsMargins(4, 5, 5, 5);
|
---|
78 | #else
|
---|
79 | const int iL = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 3;
|
---|
80 | const int iT = qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin) / 3;
|
---|
81 | const int iR = qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin) / 3;
|
---|
82 | pMainLayout->setContentsMargins(iL, iT, iR, 0);
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | /* Create label: */
|
---|
86 | m_pLabel = new QLabel;
|
---|
87 | if (m_pLabel)
|
---|
88 | {
|
---|
89 | /* Configure label: */
|
---|
90 | m_pLabel->setWordWrap(true);
|
---|
91 | m_pLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
---|
92 |
|
---|
93 | /* Add into layout: */
|
---|
94 | pMainLayout->addWidget(m_pLabel);
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* Create details browser: */
|
---|
98 | m_pBrowserDetails = new QTextBrowser;
|
---|
99 | if (m_pBrowserDetails)
|
---|
100 | {
|
---|
101 | /* Configure browser: */
|
---|
102 | m_pBrowserDetails->setFocusPolicy(Qt::StrongFocus);
|
---|
103 | m_pBrowserDetails->document()->setDefaultStyleSheet("a { text-decoration: none; }");
|
---|
104 |
|
---|
105 | /* Add into layout: */
|
---|
106 | pMainLayout->addWidget(m_pBrowserDetails);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* If refresh action was set: */
|
---|
110 | if (m_pActionRefresh)
|
---|
111 | {
|
---|
112 | /* Create Refresh button layout: */
|
---|
113 | QHBoxLayout *pButtonLayout = new QHBoxLayout;
|
---|
114 | if (pButtonLayout)
|
---|
115 | {
|
---|
116 | /* Add stretch first: */
|
---|
117 | pButtonLayout->addStretch();
|
---|
118 |
|
---|
119 | /* Create refresh button: */
|
---|
120 | m_pButtonRefresh = new QToolButton;
|
---|
121 | if (m_pButtonRefresh)
|
---|
122 | {
|
---|
123 | /* Configure button: */
|
---|
124 | m_pButtonRefresh->setFocusPolicy(Qt::StrongFocus);
|
---|
125 | connect(m_pButtonRefresh, &QToolButton::clicked,
|
---|
126 | m_pActionRefresh, &QAction::triggered);
|
---|
127 |
|
---|
128 | /* Add into layout: */
|
---|
129 | pButtonLayout->addWidget(m_pButtonRefresh);
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /* Add into layout: */
|
---|
134 | pMainLayout->addLayout(pButtonLayout);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /* Add stretch finally: */
|
---|
138 | pMainLayout->addStretch();
|
---|
139 | }
|
---|
140 |
|
---|
141 | /* Retranslate finally: */
|
---|
142 | retranslateUi();
|
---|
143 | }
|
---|