VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIWarningPane.cpp@ 82781

Last change on this file since 82781 was 76606, checked in by vboxsync, 5 years ago

FE/Qt: Cleaning out old precompiled header experiment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1/* $Id: UIWarningPane.cpp 76606 2019-01-02 05:40:39Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWarningPane class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-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 <QHBoxLayout>
20#include <QEvent>
21#include <QLabel>
22#include <QTimer>
23
24/* GUI includes: */
25#include "QIWidgetValidator.h"
26#include "UIWarningPane.h"
27
28/* Other VBox includes: */
29#include <iprt/assert.h>
30
31
32UIWarningPane::UIWarningPane(QWidget *pParent)
33 : QWidget(pParent)
34 , m_pIconLayout(0)
35 , m_pTextLabel(0)
36 , m_pHoverTimer(0)
37 , m_iHoveredIconLabelPosition(-1)
38{
39 /* Prepare: */
40 prepare();
41}
42
43void UIWarningPane::setWarningLabel(const QString &strWarningLabel)
44{
45 /* Assign passed text directly to warning-label: */
46 m_pTextLabel->setText(strWarningLabel);
47}
48
49void UIWarningPane::registerValidator(UIPageValidator *pValidator)
50{
51 /* Make sure validator exists: */
52 AssertPtrReturnVoid(pValidator);
53
54 /* Make sure validator is not registered yet: */
55 if (m_validators.contains(pValidator))
56 {
57 AssertMsgFailed(("Validator is registered already!\n"));
58 return;
59 }
60
61 /* Register validator: */
62 m_validators << pValidator;
63
64 /* Create icon-label for newly registered validator: */
65 QLabel *pIconLabel = new QLabel;
66 {
67 /* Configure icon-label: */
68 pIconLabel->setMouseTracking(true);
69 pIconLabel->installEventFilter(this);
70 pIconLabel->setPixmap(pValidator->warningPixmap());
71 connect(pValidator, &UIPageValidator::sigShowWarningIcon, pIconLabel, &QLabel::show);
72 connect(pValidator, &UIPageValidator::sigHideWarningIcon, pIconLabel, &QLabel::hide);
73
74 /* Add icon-label into list: */
75 m_icons << pIconLabel;
76 /* Add icon-label into layout: */
77 m_pIconLayout->addWidget(pIconLabel);
78 }
79
80 /* Mark icon as 'unhovered': */
81 m_hovered << false;
82}
83
84bool UIWarningPane::eventFilter(QObject *pObject, QEvent *pEvent)
85{
86 /* Depending on event-type: */
87 switch (pEvent->type())
88 {
89 /* One of icons hovered: */
90 case QEvent::MouseMove:
91 {
92 /* Cast object to label: */
93 if (QLabel *pIconLabel = qobject_cast<QLabel*>(pObject))
94 {
95 /* Search for the corresponding icon: */
96 if (m_icons.contains(pIconLabel))
97 {
98 /* Mark icon-label hovered if not yet: */
99 int iIconLabelPosition = m_icons.indexOf(pIconLabel);
100 if (!m_hovered[iIconLabelPosition])
101 {
102 m_hovered[iIconLabelPosition] = true;
103 m_iHoveredIconLabelPosition = iIconLabelPosition;
104 m_pHoverTimer->start();
105 }
106 }
107 }
108 break;
109 }
110
111 /* One of icons unhovered: */
112 case QEvent::Leave:
113 {
114 /* Cast object to label: */
115 if (QLabel *pIconLabel = qobject_cast<QLabel*>(pObject))
116 {
117 /* Search for the corresponding icon: */
118 if (m_icons.contains(pIconLabel))
119 {
120 /* Mark icon-label unhovered if not yet: */
121 int iIconLabelPosition = m_icons.indexOf(pIconLabel);
122 if (m_hovered[iIconLabelPosition])
123 {
124 m_hovered[iIconLabelPosition] = false;
125 if (m_pHoverTimer->isActive())
126 {
127 m_pHoverTimer->stop();
128 m_iHoveredIconLabelPosition = -1;
129 }
130 else
131 emit sigHoverLeave(m_validators[iIconLabelPosition]);
132 }
133 }
134 }
135 break;
136 }
137
138 /* Default case: */
139 default:
140 break;
141 }
142
143 /* Call to base-class: */
144 return QWidget::eventFilter(pObject, pEvent);
145}
146
147void UIWarningPane::sltHandleHoverTimer()
148{
149 /* Notify listeners about hovering: */
150 if (m_iHoveredIconLabelPosition >= 0 && m_iHoveredIconLabelPosition < m_validators.size())
151 emit sigHoverEnter(m_validators[m_iHoveredIconLabelPosition]);
152}
153
154void UIWarningPane::prepare()
155{
156 /* Create main-layout: */
157 QHBoxLayout *pMainLayout = new QHBoxLayout(this);
158 {
159 /* Configure layout: */
160 pMainLayout->setContentsMargins(0, 0, 0, 0);
161
162 /* Add left stretch: */
163 pMainLayout->addStretch();
164
165 /* Create text-label: */
166 m_pTextLabel = new QLabel;
167 {
168 /* Add into layout: */
169 pMainLayout->addWidget(m_pTextLabel);
170 }
171
172 /* Create layout: */
173 m_pIconLayout = new QHBoxLayout;
174 {
175 /* Configure layout: */
176 m_pIconLayout->setContentsMargins(0, 0, 0, 0);
177
178 /* Add into layout: */
179 pMainLayout->addLayout(m_pIconLayout);
180 }
181
182 /* Create hover-timer: */
183 m_pHoverTimer = new QTimer(this);
184 {
185 /* Configure timer: */
186 m_pHoverTimer->setInterval(200);
187 m_pHoverTimer->setSingleShot(true);
188 connect(m_pHoverTimer, &QTimer::timeout, this, &UIWarningPane::sltHandleHoverTimer);
189 }
190
191 /* Add right stretch: */
192 pMainLayout->addStretch();
193 }
194}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use