1 | /* $Id: UIMediumSizeEditor.h 103320 2024-02-12 16:40:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMediumSizeEditor class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 | #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 <QWidget>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "QIWithRetranslateUI.h"
|
---|
40 | #include "UILibraryDefs.h"
|
---|
41 |
|
---|
42 | /* Forward declarations: */
|
---|
43 | class QLabel;
|
---|
44 | class QSlider;
|
---|
45 | class QString;
|
---|
46 | class QWidget;
|
---|
47 | class QILineEdit;
|
---|
48 |
|
---|
49 | /** Medium size editor widget. */
|
---|
50 | class SHARED_LIBRARY_STUFF UIMediumSizeEditor : public QIWithRetranslateUI<QWidget>
|
---|
51 | {
|
---|
52 | Q_OBJECT;
|
---|
53 |
|
---|
54 | signals:
|
---|
55 |
|
---|
56 | /** Notifies listeners about medium size changed. */
|
---|
57 | void sigSizeChanged(qulonglong uSize);
|
---|
58 |
|
---|
59 | public:
|
---|
60 |
|
---|
61 | /** Constructs medium size editor passing @a pParent to the base-class. */
|
---|
62 | UIMediumSizeEditor(QWidget *pParent = 0, qulonglong uMinimumSize = _4M);
|
---|
63 |
|
---|
64 | /** Returns the medium size. */
|
---|
65 | qulonglong mediumSize() const { return m_uSize; }
|
---|
66 | /** Sets the initial medium size as the widget is created. */
|
---|
67 | void setMediumSize(qulonglong uSize);
|
---|
68 |
|
---|
69 | protected:
|
---|
70 |
|
---|
71 | /** Handles translation event. */
|
---|
72 | virtual void retranslateUi() RT_OVERRIDE;
|
---|
73 |
|
---|
74 | private slots:
|
---|
75 |
|
---|
76 | /** Handles size slider change. */
|
---|
77 | void sltSizeSliderChanged(int iValue);
|
---|
78 | /** Handles size editor text edit finished signal. */
|
---|
79 | void sltSizeEditorTextChanged();
|
---|
80 |
|
---|
81 | private:
|
---|
82 |
|
---|
83 | /** Prepares all. */
|
---|
84 | void prepare();
|
---|
85 |
|
---|
86 | /** Calculates slider scale according to passed @a uMaximumMediumSize. */
|
---|
87 | static int calculateSliderScale(qulonglong uMaximumMediumSize);
|
---|
88 | /** Returns log2 for passed @a uValue. */
|
---|
89 | static int log2i(qulonglong uValue);
|
---|
90 | /** Converts passed bytes @a uValue to slides scaled value using @a iSliderScale. */
|
---|
91 | static int sizeMBToSlider(qulonglong uValue, int iSliderScale);
|
---|
92 | /** Converts passed slider @a uValue to bytes unscaled value using @a iSliderScale. */
|
---|
93 | static qulonglong sliderToSizeMB(int uValue, int iSliderScale);
|
---|
94 | /** Updates slider/editor tool-tips. */
|
---|
95 | void updateSizeToolTips(qulonglong uSize);
|
---|
96 | /** Checks if the uSize is divisible by m_uSectorSize */
|
---|
97 | qulonglong checkSectorSizeAlignment(qulonglong uSize);
|
---|
98 | QString ensureSizeSuffix(const QString &strSizeString);
|
---|
99 |
|
---|
100 | /* Holds the block size. We force m_uSize to be multiple of this number. */
|
---|
101 | static const qulonglong m_uSectorSize;
|
---|
102 | /** Holds the minimum medium size. */
|
---|
103 | const qulonglong m_uSizeMin;
|
---|
104 | /** Holds the maximum medium size. */
|
---|
105 | const qulonglong m_uSizeMax;
|
---|
106 | /** Holds the slider scale. */
|
---|
107 | const int m_iSliderScale;
|
---|
108 | /** Holds the current medium size. */
|
---|
109 | qulonglong m_uSize;
|
---|
110 | /** Holds the size suffix. */
|
---|
111 | QString m_strSizeSuffix;
|
---|
112 |
|
---|
113 | /** Holds the size slider. */
|
---|
114 | QSlider *m_pSlider;
|
---|
115 | /** Holds the minimum size label. */
|
---|
116 | QLabel *m_pLabelMinSize;
|
---|
117 | /** Holds the maximum size label. */
|
---|
118 | QLabel *m_pLabelMaxSize;
|
---|
119 | /** Holds the size editor. */
|
---|
120 | QILineEdit *m_pEditor;
|
---|
121 |
|
---|
122 | /* A regular expression used to remove any character from a QString which is neither a digit nor decimal separator. */
|
---|
123 | QRegularExpression m_regExNonDigitOrSeparator;
|
---|
124 | };
|
---|
125 |
|
---|
126 | #endif /* !FEQT_INCLUDED_SRC_widgets_UIMediumSizeEditor_h */
|
---|