5#ifndef DQUICKCONTROLPALETTE_P_H
6#define DQUICKCONTROLPALETTE_P_H
8#include <dtkdeclarative_global.h>
9#include "dqmlglobalobject_p.h"
13#include <QQmlListProperty>
18#include <private/qqmldata_p.h>
28 friend class DQuickControlPalette;
30 Q_PROPERTY(DTK_QUICK_NAMESPACE::DColor common READ common WRITE setCommon FINAL)
31 Q_PROPERTY(DTK_QUICK_NAMESPACE::DColor crystal READ crystal WRITE setCrystal FINAL)
32#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
40 {data = std::move(other.data); other.data =
nullptr;
41 changed = std::move(other.changed);
42 isSingleColor = std::move(other.isSingleColor);}
44 isSingleColor = other.isSingleColor;
45 if (other.isSingleColor) {
46 data =
new DColor(*other.data);
49 changed = other.changed;
54 if (other.isSingleColor) {
59 isSingleColor =
false;
62 if (other.isSingleColor) {
64 setCommon(*other.data);
66 data =
new DColor(*other.data);
72 changed = other.changed;
76 if (data && isSingleColor) {
80 data = std::move(other.data);
82 changed = other.changed;
83 isSingleColor = other.isSingleColor;
88 const DColor &common()
const;
89 void setCommon(
const DColor &newCommon);
90 const DColor &crystal()
const;
91 void setCrystal(
const DColor &newCrystal);
98 bool isSingleColor =
false;
101Q_DECLARE_METATYPE(DTK_QUICK_NAMESPACE::DQuickControlColor)
103DQUICK_BEGIN_NAMESPACE
105class DQuickControlPalette :
public QObject
109 Q_DISABLE_COPY(DQuickControlPalette)
110 Q_PROPERTY(
bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
111 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor normal READ normal WRITE setNormal NOTIFY normalChanged)
112 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor normalDark READ normalDark WRITE setNormalDark NOTIFY normalDarkChanged)
113 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor hovered READ hovered WRITE setHovered NOTIFY hoveredChanged)
114 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor hoveredDark READ hoveredDark WRITE setHoveredDark NOTIFY hoveredDarkChanged)
115 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor pressed READ pressed WRITE setPressed NOTIFY pressedChanged)
116 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor pressedDark READ pressedDark WRITE setPressedDark NOTIFY pressedDarkChanged)
117 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor disabled READ disabled WRITE setDisabled NOTIFY disabledChanged)
118 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlColor disabledDark READ disabledDark WRITE setDisabledDark NOTIFY disabledDarkChanged)
120#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
133 Dark = 1 * ColorFamilyCount,
137 Hovered = 1 * (ThemeTypeCount + ColorFamilyCount),
138 Pressed = 2 * (ThemeTypeCount + ColorFamilyCount),
139 Disabled = 3 * (ThemeTypeCount + ColorFamilyCount),
143 explicit DQuickControlPalette(QObject *parent =
nullptr);
144 ~DQuickControlPalette();
146 bool enabled()
const;
147 void setEnabled(
bool newEnabled);
149 inline DColor *colorPointer(
int colorPropertyIndex) {
150 return colors.data() + colorPropertyIndex * ColorFamilyCount;
152 inline bool setTo(
const DQuickControlColor &color,
int colorPropertyIndex) {
153 auto colors = colorPointer(colorPropertyIndex);
155 if (color.data == colors)
156 return color.changed;
157 bool changed =
false;
158 const int colorCount = color.isSingleColor ? 1 : ColorFamilyCount;
159 for (
int i = 0; i < colorCount; ++i) {
160 if (color.data[i] == colors[i])
162 colors[i] = color.data[i];
167 void setNormal(
const DQuickControlColor &color) {
168 if (!setTo(color, 0))
170 Q_EMIT normalChanged();
173 DQuickControlColor normal() {
174 return DQuickControlColor(colorPointer(0));
176 void setNormalDark(
const DQuickControlColor &color) {
177 if (!setTo(color, 1))
179 Q_EMIT normalDarkChanged();
182 DQuickControlColor normalDark() {
183 return DQuickControlColor(colorPointer(1));
185 void setHovered(
const DQuickControlColor &color) {
186 if (!setTo(color, 2))
188 Q_EMIT hoveredChanged();
191 DQuickControlColor hovered() {
192 return DQuickControlColor(colorPointer(2));
194 void setHoveredDark(
const DQuickControlColor &color) {
195 if (!setTo(color, 3))
197 Q_EMIT hoveredDarkChanged();
200 DQuickControlColor hoveredDark() {
201 return DQuickControlColor(colorPointer(3));
203 void setPressed(
const DQuickControlColor &color) {
204 if (!setTo(color, 4))
206 Q_EMIT pressedChanged();
209 DQuickControlColor pressed() {
210 return DQuickControlColor(colorPointer(4));
212 void setPressedDark(
const DQuickControlColor &color) {
213 if (!setTo(color, 5))
215 Q_EMIT pressedDarkChanged();
218 DQuickControlColor pressedDark() {
219 return DQuickControlColor(colorPointer(5));
221 void setDisabled(
const DQuickControlColor &color) {
222 if (!setTo(color, 6))
224 Q_EMIT disabledChanged();
227 DQuickControlColor disabled() {
228 return DQuickControlColor(colorPointer(6));
230 void setDisabledDark(
const DQuickControlColor &color) {
231 if (!setTo(color, 7))
233 Q_EMIT disabledDarkChanged();
236 DQuickControlColor disabledDark() {
237 return DQuickControlColor(colorPointer(7));
241 void enabledChanged();
242 void normalChanged();
243 void normalDarkChanged();
244 void hoveredChanged();
245 void hoveredDarkChanged();
246 void pressedChanged();
247 void pressedDarkChanged();
248 void disabledChanged();
249 void disabledDarkChanged();
253 QVector<DColor> colors;
256 bool m_enabled =
true;
259QML_DECLARE_TYPE(DTK_QUICK_NAMESPACE::DQuickControlPalette)
261DQUICK_BEGIN_NAMESPACE
262class CustomMetaObject;
267#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
268 QML_UNCREATABLE(
"ColorSelector is only available as an attached property.")
274 Q_PROPERTY(QQuickItem *control READ control NOTIFY controlChanged)
275 Q_PROPERTY(DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType controlTheme READ controlTheme NOTIFY controlThemeChanged)
276 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQMLGlobalObject::ControlState controlState READ controlState NOTIFY controlStateChanged)
277 Q_PROPERTY(DTK_QUICK_NAMESPACE::DQuickControlPalette::ColorFamily family READ family WRITE setFamily RESET resetFamily NOTIFY familyChanged)
278 Q_PROPERTY(
bool hovered READ hovered WRITE setHovered RESET resetHovered NOTIFY hoveredChanged)
279 Q_PROPERTY(
bool pressed READ pressed WRITE setPressed RESET resetPressed NOTIFY pressedChanged)
280 Q_PROPERTY(
bool disabled READ disabled WRITE setDisabled RESET resetDisabled NOTIFY disabledChanged)
281 Q_PROPERTY(
bool inactived READ inactived WRITE setInactived RESET resetInactived NOTIFY inactivedChanged)
282 Q_CLASSINFO(
"DefaultProperty",
"palettes")
289 QQuickItem *control()
const;
290 void setControl(QQuickItem *newControl);
292 DQMLGlobalObject::ControlState controlState()
const;
293 DGuiApplicationHelper::ColorType controlTheme()
const;
294 Dtk::Quick::DQuickControlPalette::ColorFamily family()
const;
295 void setFamily(
const DQuickControlPalette::ColorFamily &newFamily);
298 bool hovered()
const;
299 void setHovered(
bool newHovered);
302 bool pressed()
const;
303 void setPressed(
bool newPressed);
306 bool disabled()
const;
307 void setDisabled(
bool newDisabled);
308 void resetDisabled();
310 bool inactived()
const;
311 void setInactived(
bool newInactived);
312 void resetInactived();
314 static QStringList specialObjectNameItems();
317 void controlThemeChanged();
318 void controlStateChanged();
319 void controlChanged();
320 void hoveredChanged();
321 void pressedChanged();
322 void disabledChanged();
323 void inactivedChanged();
324 void colorPropertyChanged(
const QByteArray &name);
325 void colorPropertiesChanged();
326 void familyChanged();
329 bool doGetHoveredRecu(
bool *value)
const;
330 bool doGetPressedRecu(
bool *value)
const;
331 bool doGetDisabledRecu(
bool *value)
const;
332 bool doGetInactivedRecu(
bool *value)
const;
333 void doSetHovered(
bool newHovered,
bool isUserSet);
334 void doSetPressed(
bool newPressed,
bool isUserSet);
335 void doSetDisabled(
bool newDisabled,
bool isUserSet);
336 void doSetInactived(
bool newInactived,
bool isUserSet);
338 void ensureMetaObject();
339 void setupMetaPropertyPalettes(QQuickItem *
object);
341 QColor getColorOf(
const DQuickControlPalette *palette,
const PaletteState *state)
const;
342 QColor getColorOf(
const QByteArray &propertyName,
const PaletteState *state)
const;
344 int indexOfPalette(
const QByteArray &name)
const;
345 void setPalette(
const QByteArray &name, DQuickControlPalette *palette);
347 void updatePaletteFromMetaProperty(
const QMetaProperty &mp,
const QObject *obj);
348 void updatePropertyFromName(
const QByteArray &name,
const DQuickControlPalette *palette =
nullptr);
349 void updateFamilyForChildrenRecu(QQuickItem *parent);
351 void findAndSetControlParent();
352 QByteArray findPalettePropertyName(
const DQuickControlPalette *palette)
const;
353 void clearAndInheritParentProperties();
355 Q_SLOT
void updateControlTheme();
356 Q_SLOT
bool updateControlState();
357 Q_SLOT
void updateAllColorProperties();
358 Q_SLOT
void recvPaletteColorChanged();
359 Q_SLOT
void onPaletteDestroyed();
360 Q_SLOT
void updateControlWindow();
361 Q_SLOT
void resolveMetaPropertyChanged();
362 Q_SLOT
void notifyColorPropertyChanged();
364 bool setControlTheme(DGuiApplicationHelper::ColorType theme);
365 bool setControlState(DQMLGlobalObject::ControlState state);
366 bool doSetFamily(DQuickControlPalette::ColorFamily newFamily);
367 void doResetFamily();
369 void tryDestroyPalette(DQuickControlPalette *palette);
373 QQuickItem *m_control =
nullptr;
374 QQuickWindow *m_controlWindow =
nullptr;
375 QPointer<DQuickControlColorSelector> m_superColorSelector;
376 QPointer<DQuickControlColorSelector> m_parentOfFamilyProperty;
377 typedef QPair<QByteArray, DQuickControlPalette*> ControlPaletteData;
378 QList<ControlPaletteData> m_palettes;
380#if QT_VERSION <= QT_VERSION_CHECK(6, 2, 4)
381 QQmlPropertyCache *m_propertyCache =
nullptr;
383 QQmlPropertyCache::ConstPtr m_propertyCache;
385 struct PaletteState {
388 , controlState(DQMLGlobalObject::NormalState)
389 , family(DQuickControlPalette::CommonColor)
390 , familyIsUserSet(
false)
392 , hoveredValueValid(
false)
394 , pressedValueValid(
false)
396 , disabledValueValid(
false)
398 , inactivedValueValid(
false)
400 if (
auto appHelper = DGuiApplicationHelper::instance()) {
401 controlTheme = appHelper->themeType();
403 controlTheme = DGuiApplicationHelper::LightType;
408 DGuiApplicationHelper::ColorType controlTheme;
409 DQMLGlobalObject::ControlState controlState;
410 DQuickControlPalette::ColorFamily family;
411 uint familyIsUserSet:1;
413 uint hoveredValueValid:1;
415 uint pressedValueValid:1;
417 uint disabledValueValid:1;
419 uint inactivedValueValid:1;
421 QScopedPointer<PaletteState> m_state;
422 QList<QMetaObject::Connection> m_itemParentChangeConnections;
426QML_DECLARE_TYPE(DTK_QUICK_NAMESPACE::DQuickControlColorSelector)
427QML_DECLARE_TYPEINFO(DTK_QUICK_NAMESPACE::DQuickControlColorSelector, QML_HAS_ATTACHED_PROPERTIES)
Definition dqmlglobalobject_p.h:34
Definition dquickcontrolpalette_p.h:264
Definition dquickcontrolpalette_p.h:27
DTK 中用于取色器(ColorSelector)使用的统一调色板对象.