Perceptual Color

multispinbox_p.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef MULTISPINBOX_P_H
5#define MULTISPINBOX_P_H
6
7// Include the header of the public class of this private implementation.
8// #include "multispinbox.h"
9
10#include "constpropagatingrawpointer.h"
11#include "helperqttypes.h"
12#include "multispinboxsection.h"
13#include <qaccessiblewidget.h>
14#include <qglobal.h>
15#include <qlist.h>
16#include <qobject.h>
17#include <qpointer.h>
18#include <qstring.h>
20
21#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22#include <qtmetamacros.h>
23#else
24#include <qobjectdefs.h>
25#endif
26
27namespace PerceptualColor
28{
29class ExtendedDoubleValidator;
30class MultiSpinBox;
31
32/** @internal
33 *
34 * @brief Private implementation within the <em>Pointer to
35 * implementation</em> idiom */
36class MultiSpinBoxPrivate final : public QObject
37{
39
40public:
41 explicit MultiSpinBoxPrivate(MultiSpinBox *backLink);
42 /** @brief Default destructor
43 *
44 * The destructor is non-<tt>virtual</tt> because
45 * the class as a whole is <tt>final</tt>. */
46 virtual ~MultiSpinBoxPrivate() noexcept override = default;
47
48 /** @brief Only for unit tests. */
49 friend class TestMultiSpinBox;
50
51 // constexpr
52 /** @brief Default value of a section */
53 static constexpr double defaultSectionValue = 0;
54
55 /** @brief Counter for all actions added
56 * by @ref MultiSpinBox::addActionButton. */
57 int m_actionButtonCount = 0;
58 /** @brief Holds the index of the currently selected section.
59 * @sa @ref setCurrentIndexAndUpdateTextAndSelectValue
60 * @sa @ref setCurrentIndexWithoutUpdatingText */
61 QListSizeType m_currentIndex = 0;
62 /** @brief Holds the data for the sections.
63 *
64 * This list is guaranteed to contain at least <em>one</em> section.
65 *
66 * @sa @ref MultiSpinBox::sectionConfigurations()
67 * @sa @ref MultiSpinBox::setSectionConfigurations() */
68 QList<MultiSpinBoxSection> m_sectionConfigurations;
69 /** @brief Internal storage for
70 * property @ref MultiSpinBox::sectionValues. */
71 QList<double> m_sectionValues = QList<double>{MultiSpinBoxPrivate::defaultSectionValue};
72 /** @brief The string of everything <em>after</em> the value of the
73 * current section.
74 *
75 * This includes the suffix of the current section and everything
76 * (prefixes, values and suffixes) of all sections that come after
77 * the current sections. */
78 QString m_textAfterCurrentValue;
79 /** @brief The string of everything <em>before</em> the value of the
80 * current section.
81 *
82 * This includes everything (prefixes, values and suffixes) of all
83 * sections that come before the current section, and the prefix
84 * of the current section. */
85 QString m_textBeforeCurrentValue;
86 /** @brief The string of the value of the current section. */
87 QString m_textOfCurrentValue;
88 /** @brief The validator for the <tt>QLineEdit</tt>.
89 *
90 * This validator allows changes only to the <em>current</em> section.
91 *
92 * If the current section changes, also this validator’s configuration
93 * will be adapted to cover the new current section.
94 *
95 * @note It is <em>not</em> possible to change various values at the
96 * same time, for example by marking all the current text and use
97 * Ctrl-V to past a complete new value from the clipboard. This would
98 * be impossible to parse reliably, because the prefixes and suffixes
99 * of each section might contain (localized) digits that would be
100 * difficult to differentiate from the actual value. */
102
103 // Functions
104 [[nodiscard]] QString formattedValue(QListSizeType index) const;
105 [[nodiscard]] bool isCursorTouchingCurrentSectionValue() const;
106 void setCurrentIndexAndUpdateTextAndSelectValue(QListSizeType newIndex);
107 void setCurrentIndexToZeroAndUpdateTextAndSelectValue();
108 void setCurrentIndexWithoutUpdatingText(QListSizeType newIndex);
109 void setSectionValuesWithoutFurtherUpdating(const QList<double> &newSectionValues);
110 void updatePrefixValueSuffixText();
111
112public Q_SLOTS:
113 void reactOnCursorPositionChange(const int oldPos, const int newPos);
114 void updateCurrentValueFromText(const QString &lineEditText);
115
116private:
117 Q_DISABLE_COPY(MultiSpinBoxPrivate)
118
119 /** @brief Pointer to the object from which <em>this</em> object
120 * is the private implementation. */
121 ConstPropagatingRawPointer<MultiSpinBox> q_pointer;
122};
123
124/** @internal
125 *
126 * @brief Interface for accessible objects. */
127class AccessibleMultiSpinBox : public QAccessibleWidget
128{
129public:
130 explicit AccessibleMultiSpinBox(MultiSpinBox *w);
131 virtual ~AccessibleMultiSpinBox() override;
132 [[nodiscard]] static QAccessibleInterface *factory(const QString &classname, QObject *object);
133};
134
135} // namespace PerceptualColor
136
137#endif // MULTISPINBOX_P_H
The namespace of this library.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:00:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.