VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMediumSizeEditor.h

Last change on this file was 104929, checked in by vboxsync, 3 months ago

FE/Qt: bugref:10666, bugref:10669: UIMediumSizeSlider: Implementing own accessibility interface; Adjusting tool-tip to have no HTML tags.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/* $Id: UIMediumSizeEditor.h 104929 2024-06-14 16:13:09Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIMediumSizeEditor class declaration.
4 */
5
6/*
7 * Copyright (C) 2006-2024 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#ifndef FEQT_INCLUDED_SRC_widgets_UIMediumSizeEditor_h
29#define FEQT_INCLUDED_SRC_widgets_UIMediumSizeEditor_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34/* Qt includes: */
35#include <QRegularExpression>
36#include <QSlider>
37#include <QWidget>
38
39/* GUI includes: */
40#include "UILibraryDefs.h"
41
42/* Forward declarations: */
43class QLabel;
44class QString;
45class QWidget;
46class QILineEdit;
47
48/** QSlider sub-class used as logarithmic-scaled medium size editor. */
49class UIMediumSizeSlider : public QSlider
50{
51 Q_OBJECT;
52
53signals:
54
55 /** Notifies about scaled @a uValue change. */
56 void sigScaledValueChanged(qulonglong uValue);
57
58public:
59
60 /** Constructs medium size slider passing @a pParent to the base-class.
61 * @param uSizeMax Brings the maximum value to adjust slider scaling accordingly. */
62 UIMediumSizeSlider(qulonglong uSizeMax, QWidget *pParent = 0);
63
64 /** Defines scaled @a uMinimum. */
65 void setScaledMinimum(qulonglong uMinimum);
66 /** Defines scaled @a uMaximum. */
67 void setScaledMaximum(qulonglong uMaximum);
68 /** Defines scaled @a uValue. */
69 void setScaledValue(qulonglong uValue);
70
71 /** Returns scaled value in readable format. */
72 QString scaledValueToString();
73
74private slots:
75
76 /** Handles the signal about @a iValue change. */
77 void sltValueChanged(int iValue);
78
79private:
80
81 /** Calculates slider scale according to passed @a uMaximumMediumSize. */
82 static int calculateSliderScale(qulonglong uMaximumMediumSize);
83 /** Returns log2 for passed @a uValue. */
84 static int log2i(qulonglong uValue);
85
86 /** Converts passed bytes @a uValue to slides scaled value using @a iSliderScale. */
87 static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
88 /** Converts passed slider @a uValue to bytes unscaled value using @a iSliderScale. */
89 static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
90
91 /** Holds the slider scale. */
92 const int m_iSliderScale;
93
94 /** Holds the scaled minimum. */
95 qulonglong m_uScaledMinimum;
96 /** Holds the scaled maximum. */
97 qulonglong m_uScaledMaximum;
98 /** Holds the scaled value. */
99 qulonglong m_uScaledValue;
100};
101
102/** Medium size editor widget. */
103class SHARED_LIBRARY_STUFF UIMediumSizeEditor : public QWidget
104{
105 Q_OBJECT;
106
107signals:
108
109 /** Notifies listeners about medium size changed. */
110 void sigSizeChanged(qulonglong uSize);
111
112public:
113
114 /* Holds the block size. We force m_uSize to be multiple of this number. */
115 static const qulonglong s_uSectorSize;
116
117 /** Constructs medium size editor passing @a pParent to the base-class. */
118 UIMediumSizeEditor(QWidget *pParent = 0, qulonglong uMinimumSize = _4M);
119
120 /** Returns the medium size. */
121 qulonglong mediumSize() const { return m_uSize; }
122 /** Sets the initial medium size as the widget is created. */
123 void setMediumSize(qulonglong uSize);
124
125private slots:
126
127 /** Handles translation event. */
128 void sltRetranslateUI();
129
130 /** Handles size slider change. */
131 void sltSizeSliderChanged(qulonglong uValue);
132 /** Handles size editor text edit finished signal. */
133 void sltSizeEditorTextChanged();
134
135private:
136
137 /** Prepares all. */
138 void prepare();
139
140 /** Updates slider/editor tool-tips. */
141 void updateSizeToolTips(qulonglong uSize);
142 /** Checks if the uSize is divisible by s_uSectorSize */
143 qulonglong checkSectorSizeAlignment(qulonglong uSize);
144 /** Ensures there is only proper size-suffix available. */
145 QString ensureSizeSuffix(const QString &strSizeString);
146
147 /** Holds the minimum medium size. */
148 const qulonglong m_uSizeMin;
149 /** Holds the maximum medium size. */
150 const qulonglong m_uSizeMax;
151 /** Holds the current medium size. */
152 qulonglong m_uSize;
153 /** Holds the size suffix. */
154 QString m_strSizeSuffix;
155
156 /** Holds the size slider. */
157 UIMediumSizeSlider *m_pSlider;
158 /** Holds the minimum size label. */
159 QLabel *m_pLabelMinSize;
160 /** Holds the maximum size label. */
161 QLabel *m_pLabelMaxSize;
162 /** Holds the size editor. */
163 QILineEdit *m_pEditor;
164
165 /* A regular expression used to remove any character from a QString which is neither a digit nor decimal separator. */
166 QRegularExpression m_regExNonDigitOrSeparator;
167};
168
169#endif /* !FEQT_INCLUDED_SRC_widgets_UIMediumSizeEditor_h */
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