-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathdquickwindow.cpp
More file actions
1103 lines (911 loc) · 32.2 KB
/
dquickwindow.cpp
File metadata and controls
1103 lines (911 loc) · 32.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "dquickwindow.h"
#include "dapploader.h"
#include "private/dquickwindow_p.h"
#include "private/dquickbehindwindowblur_p.h"
#include "private/dquickbehindwindowblur_p_p.h"
#include <private/dquickapploaderitem_p.h>
#include <private/qquickpath_p.h>
#include <private/qquickpath_p_p.h>
#include <private/qquicktransition_p.h>
#include <private/qquickwindow_p.h>
#include <QPlatformSurfaceEvent>
DQUICK_BEGIN_NAMESPACE
DQuickWindowPrivate::DQuickWindowPrivate(DQuickWindow *qq)
: DTK_CORE_NAMESPACE::DObjectPrivate(qq)
, attached(new DQuickWindowAttached(qq))
{
}
DQuickWindow::DQuickWindow(QWindow *parent)
: QQuickWindow(parent)
, DObject(*new DQuickWindowPrivate(this))
{
}
DQuickWindow::~DQuickWindow()
{
}
/*!
* \~chinese \brief DQuickWindow::windowAttached 用于获取窗口的附加属性对象,
* \~chinese 可以设置通过这个对象设置窗口的圆角、边框等属性值。
*/
DQuickWindowAttached *DQuickWindow::attached() const
{
D_DC(DQuickWindow);
return d->attached;
}
/*!
* \~chinese \brief DQuickWindow::qmlAttachedProperties 用于创建窗口的附加属性对象,
* \~chinese 在 QML 中使用附加属性时,会自动调用此函数。
*/
DQuickWindowAttached *DQuickWindow::qmlAttachedProperties(QObject *object)
{
QQuickWindow *window = qobject_cast<QQuickWindow *>(object);
if (window) {
return new DQuickWindowAttached(window);
}
// Support QQuickPopup with popupType == Window
if (object && object->inherits("QQuickPopup")) {
return new DQuickWindowAttached(object);
}
return nullptr;
}
DQuickWindowAttachedPrivate::DQuickWindowAttachedPrivate(QWindow *window, DQuickWindowAttached *qq)
: DObjectPrivate(qq)
, window(window)
, wmWindowTypes(DWindowManagerHelper::UnknowWindowType)
, appLoaderItem(nullptr)
{
}
DQuickWindowAttachedPrivate::~DQuickWindowAttachedPrivate()
{
if (handle) {
delete handle;
}
}
template<class Func>
inline static void updateValue(DQuickWindowAttachedPrivate::BoolOptional &value, Func call)
{
if (value != DQuickWindowAttachedPrivate::Invalid) {
call(value == DQuickWindowAttachedPrivate::True);
value = DQuickWindowAttachedPrivate::Invalid;
}
}
template<class Func>
inline static void updateValue(qint8 &value, Func call)
{
if (value >= 0) {
call(value);
value = -1;
}
}
template<class Func>
inline static void updateValue(QColor &value, Func call)
{
if (value.isValid()) {
call(value);
value = QColor();
}
}
template<class Func>
inline static void updateValue(QPoint &value, Func call)
{
if (!value.isNull()) {
call(value);
value = QPoint();
}
}
template<class Func>
inline static void updateValue(DTK_GUI_NAMESPACE::DPlatformHandle::EffectScenes &value, Func call)
{
if (value != DTK_GUI_NAMESPACE::DPlatformHandle::EffectScene(0)) {
call(value);
value = DTK_GUI_NAMESPACE::DPlatformHandle::EffectScene(0);
}
}
template<class Func>
inline static void updateValue(DTK_GUI_NAMESPACE::DPlatformHandle::EffectTypes &value, Func call)
{
if (value != DTK_GUI_NAMESPACE::DPlatformHandle::EffectType(0)) {
call(value);
value = DTK_GUI_NAMESPACE::DPlatformHandle::EffectType(0);
}
}
bool DQuickWindowAttachedPrivate::ensurePlatformHandle()
{
if (handle)
return true;
if (!window) {
return false;
}
if (!DPlatformHandle::setEnabledNoTitlebarForWindow(window, true)) {
qWarning() << "Failed to enable NoTitlebar for the window:" << window;
return false;
}
Q_ASSERT(DPlatformHandle::isEnabledNoTitlebar(window));
explicitEnable = Invalid;
D_Q(DQuickWindowAttached);
handle = new DPlatformHandle(window);
updateValue(explicitWindowRadius, std::bind(&DPlatformHandle::setWindowRadius, handle, std::placeholders::_1));
updateValue(explicitBorderWidth, std::bind(&DPlatformHandle::setBorderWidth, handle, std::placeholders::_1));
updateValue(explicitBorderColor, std::bind(&DPlatformHandle::setBorderColor, handle, std::placeholders::_1));
updateValue(explicitShadowRadius, std::bind(&DPlatformHandle::setShadowRadius, handle, std::placeholders::_1));
updateValue(explicitShadowOffset, std::bind(&DPlatformHandle::setShadowOffset, handle, std::placeholders::_1));
updateValue(explicitShadowColor, std::bind(&DPlatformHandle::setShadowColor, handle, std::placeholders::_1));
updateValue(explicitTranslucentBackground, std::bind(&DPlatformHandle::setTranslucentBackground, handle, std::placeholders::_1));
updateValue(explicitEnableSystemResize, std::bind(&DPlatformHandle::setEnableSystemResize, handle, std::placeholders::_1));
updateValue(explicitEnableSystemMove, std::bind(&DPlatformHandle::setEnableSystemMove, handle, std::placeholders::_1));
updateValue(explicitEnableBlurWindow, std::bind(&DPlatformHandle::setEnableBlurWindow, handle, std::placeholders::_1));
updateValue(explicitEffectScene, std::bind(&DPlatformHandle::setWindowEffect, handle, std::placeholders::_1));
updateValue(explicitEffectType, std::bind(&DPlatformHandle::setWindowStartUpEffect, handle, std::placeholders::_1));
QObject::connect(handle, &DPlatformHandle::borderColorChanged, q, &DQuickWindowAttached::borderColorChanged);
QObject::connect(handle, &DPlatformHandle::borderWidthChanged, q, &DQuickWindowAttached::borderWidthChanged);
QObject::connect(handle, &DPlatformHandle::shadowColorChanged, q, &DQuickWindowAttached::shadowColorChanged);
QObject::connect(handle, &DPlatformHandle::shadowOffsetChanged, q, &DQuickWindowAttached::shadowOffsetChanged);
QObject::connect(handle, &DPlatformHandle::shadowRadiusChanged, q, &DQuickWindowAttached::shadowRadiusChanged);
QObject::connect(handle, &DPlatformHandle::windowRadiusChanged, q, &DQuickWindowAttached::windowRadiusChanged);
QObject::connect(handle, &DPlatformHandle::translucentBackgroundChanged, q, &DQuickWindowAttached::translucentBackgroundChanged);
QObject::connect(handle, &DPlatformHandle::enableSystemMoveChanged, q, &DQuickWindowAttached::enableSystemMoveChanged);
QObject::connect(handle, &DPlatformHandle::enableSystemResizeChanged, q, &DQuickWindowAttached::enableSystemResizeChanged);
QObject::connect(handle, &DPlatformHandle::enableBlurWindowChanged, q, &DQuickWindowAttached::enableBlurWindowChanged);
QObject::connect(handle, SIGNAL(enableBlurWindowChanged()), q, SLOT(_q_updateBlurAreaForWindow()));
QObject::connect(handle, &DPlatformHandle::windowEffectChanged, q, &DQuickWindowAttached::windowEffectChanged);
QObject::connect(handle, &DPlatformHandle::windowStartUpEffectChanged, q, &DQuickWindowAttached::windowStartUpEffectChanged);
Q_EMIT q->enabledChanged();
return true;
}
void DQuickWindowAttachedPrivate::destoryPlatformHandle()
{
if (window)
handle->setEnabledNoTitlebarForWindow(window, false);
delete handle;
handle = nullptr;
}
void DQuickWindowAttachedPrivate::setWindow(QWindow *newWindow)
{
Q_Q(DQuickWindowAttached);
if (window == newWindow)
return;
window = newWindow;
if (newWindow) {
newWindow->installEventFilter(q);
QObject::connect(DWindowManagerHelper::instance(), SIGNAL(windowMotifWMHintsChanged(quint32)),
q, SLOT(_q_onWindowMotifHintsChanged(quint32)), Qt::UniqueConnection);
if (explicitEnable == True) {
ensurePlatformHandle();
}
}
}
void DQuickWindowAttachedPrivate::_q_onWindowMotifHintsChanged(quint32 winId)
{
D_Q(DQuickWindowAttached);
if (!q->window())
return;
if (q->window()->winId() != winId)
return;
auto functions_hints = DWindowManagerHelper::getMotifFunctions(q->window());
if (functions_hints != motifFunctions) {
motifFunctions = functions_hints;
Q_EMIT q->motifFunctionsChanged();
}
auto decorations_hints = DWindowManagerHelper::getMotifDecorations(q->window());
if (decorations_hints != motifDecorations) {
motifDecorations = decorations_hints;
Q_EMIT q->motifDecorationsChanged();
}
}
void DQuickWindowAttachedPrivate::addBlur(DQuickBehindWindowBlur *blur)
{
Q_ASSERT(!blurList.contains(blur));
blurList.append(blur);
_q_updateBlurAreaForWindow();
}
void DQuickWindowAttachedPrivate::removeBlur(DQuickBehindWindowBlur *blur)
{
if (blurList.removeOne(blur))
_q_updateBlurAreaForWindow();
}
void DQuickWindowAttachedPrivate::updateBlurAreaFor(DQuickBehindWindowBlur *blur)
{
Q_ASSERT(blurList.contains(blur));
_q_updateBlurAreaForWindow();
}
void DQuickWindowAttachedPrivate::_q_updateBlurAreaForWindow()
{
D_Q(DQuickWindowAttached);
if (q->enableBlurWindow())
return;
QList<QPainterPath> blurPathList;
QVector<DPlatformHandle::WMBlurArea> blurAreaList;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
for (const DQuickBehindWindowBlur *blur : std::as_const(blurList)) {
#else
for (const DQuickBehindWindowBlur *blur : qAsConst(blurList)) {
#endif
if (!blur->d_func()->isValidBlur())
continue;
if (blur->d_func()->blurPath.isEmpty()) {
blurAreaList.append(blur->d_func()->blurArea);
} else {
blurPathList.append(blur->d_func()->blurPath);
}
}
bool blurSuc = false;
if (blurPathList.isEmpty()) {
blurSuc = q->setWindowBlurAreaByWM(blurPathList);
blurSuc = q->setWindowBlurAreaByWM(blurAreaList);
} else {
// convert to QPainterPath
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
for (const DPlatformHandle::WMBlurArea &area : std::as_const(blurAreaList)) {
#else
for (const DPlatformHandle::WMBlurArea &area : qAsConst(blurAreaList)) {
#endif
QPainterPath path;
path.addRoundedRect(area.x, area.y, area.width, area.height, area.xRadius, area.yRaduis);
blurPathList << path;
}
blurSuc = q->setWindowBlurAreaByWM(QVector<DPlatformHandle::WMBlurArea>{});
blurSuc = q->setWindowBlurAreaByWM(blurPathList);
}
if (!blurSuc) {
q->setEnableBlurWindow(true);
}
}
void DQuickWindowAttachedPrivate::_q_updateClipPath()
{
Q_Q(DQuickWindowAttached);
Q_ASSERT(clipPath);
q->setClipPathByWM(clipPath->path());
}
void DQuickWindowAttachedPrivate::_q_ensurePlatformHandle()
{
if (explicitEnable == True && DWindowManagerHelper::instance()->hasNoTitlebar())
ensurePlatformHandle();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void DQuickWindowAttachedPrivate::ensurePalette()
{
Q_Q(DQuickWindowAttached);
if (paletteInit)
return;
paletteInit = true;
quickPalette = new QQuickPalette(q);
inactiveQuickPalette = new QQuickPalette(q);
paletteConnections = std::array<QMetaObject::Connection, 2> {
QObject::connect(DGuiApplicationHelper::instance(), SIGNAL(applicationPaletteChanged()),
q, SLOT(_q_onPaletteChanged())),
QObject::connect(window, SIGNAL(activeChanged()), q, SLOT(_q_updateWindowPalette()))
};
}
void DQuickWindowAttachedPrivate::_q_onPaletteChanged()
{
DPalette palette = DGuiApplicationHelper::instance()->applicationPalette(themeType);
DPalette inactivePalette;
for (int i = 0; i < QPalette::NColorRoles; ++i) {
QPalette::ColorRole role = static_cast<QPalette::ColorRole>(i);
inactivePalette.setBrush(QPalette::All, role, palette.brush(QPalette::Inactive, role));
// The QML control will set the opacity property to 0.4 on the disabled state
// The palette don't need set color for the QPalette::Disabled group.
palette.setBrush(QPalette::All, role, palette.brush(QPalette::Active, role));
}
quickPalette->fromQPalette(palette);
inactiveQuickPalette->fromQPalette(inactivePalette);
_q_updateWindowPalette();
}
void DQuickWindowAttachedPrivate::_q_updateWindowPalette()
{
Q_Q(DQuickWindowAttached);
auto pt = window->isActive() ? quickPalette : inactiveQuickPalette;
// Write qml property to cancle any binding on palette.
// NOTE: this is not recoverable, i.e. setting DWindow.themeType will invalidate binding on palette.
QQmlProperty::write(q->window(), "palette", QVariant::fromValue(pt));
}
#endif
DQuickWindowAttached::DQuickWindowAttached(QWindow *window)
: QObject(window)
, DObject(*new DQuickWindowAttachedPrivate(window, this))
{
window->installEventFilter(this);
QObject::connect(DWindowManagerHelper::instance(), SIGNAL(windowMotifWMHintsChanged(quint32)),
this, SLOT(_q_onWindowMotifHintsChanged(quint32)));
}
DQuickWindowAttached::DQuickWindowAttached(QObject *popupObject)
: QObject(popupObject)
, DObject(*new DQuickWindowAttachedPrivate(nullptr, this))
{
}
QQuickWindow *DQuickWindowAttached::window() const
{
D_DC(DQuickWindowAttached);
return qobject_cast<QQuickWindow *>(d->window);
}
void DQuickWindowAttached::setWindow(QQuickWindow *window)
{
D_D(DQuickWindowAttached);
d->setWindow(window);
}
/*!
* \~chinese \property DQuickWindowAttached::isEnabled
* \~chinese \brief 这个属性用于判定是否使用了 DTK 风格的窗口。
*/
bool DQuickWindowAttached::isEnabled() const
{
D_DC(DQuickWindowAttached);
return d->handle && (DPlatformHandle::isEnabledDXcb(window())
|| DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform));
}
/*!
* \~chinese \property DQuickWindowAttached::windowRadius
* \~chinese \brief 这个属性保存着窗口圆角值。
*/
int DQuickWindowAttached::windowRadius() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return 0;
}
return d->handle->windowRadius();
}
/*!
* \~chinese \property DQuickWindowAttached::borderWidth
* \~chinese \brief 这个属性保存着窗口边框的宽度。
*/
int DQuickWindowAttached::borderWidth() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return 0;
}
return d->handle->borderWidth();
}
/*!
* \~chinese \property DQuickWindowAttached::borderColor
* \~chinese \brief 这个属性保存这窗口边框的颜色。
*/
QColor DQuickWindowAttached::borderColor() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return QColor();
}
return d->handle->borderColor();
}
/*!
* \~chinese \property DQuickWindowAttached::shadowRadius
* \~chinese \brief 这个属性保存着窗口阴影半径。
*/
int DQuickWindowAttached::shadowRadius() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return 0;
}
return d->handle->shadowRadius();
}
/*!
* \~chinese \property DQuickWindowAttached::shadowOffset
* \~chinese \brief 这个属性保存着窗口阴影偏移量。
*/
QPoint DQuickWindowAttached::shadowOffset() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return QPoint();
}
return d->handle->shadowOffset();
}
/*!
* \~chinese \property DQuickWindowAttached::shadowColor
* \~chinese \brief 这个属性保存着窗口阴影颜色。
*/
QColor DQuickWindowAttached::shadowColor() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return QColor();
}
return d->handle->shadowColor();
}
/*!
* \~chinese \property DQuickWindowAttached::frameMask
* \~chinese \brief 设置 Frame Window 的遮罩,和 \a clipPath 不同的是,它的裁剪包括阴影部分。
* \~chinese \note 由于实现机制限制,使用此属性裁剪 Frame Window 时,无法去除边缘产生的锯齿。
*/
QRegion DQuickWindowAttached::frameMask() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return QRegion();
}
return d->handle->frameMask();
}
int DQuickWindowAttached::alphaBufferSize() const
{
return window()->format().alphaBufferSize();
}
QQuickPath *DQuickWindowAttached::clipPath() const
{
D_DC(DQuickWindowAttached);
return d->clipPath;
}
QQuickTransition *DQuickWindowAttached::overlayExited() const
{
D_DC(DQuickWindowAttached);
return d->overlayExitedTransition;
}
void DQuickWindowAttached::setOverlayExited(QQuickTransition *trans)
{
D_D(DQuickWindowAttached);
if (d->overlayExitedTransition == trans)
return;
d->overlayExitedTransition = trans;
Q_EMIT overlayExitedChanged();
}
QQmlComponent *DQuickWindowAttached::loadingOverlay() const
{
D_DC(DQuickWindowAttached);
return d->loadingOverlay;
}
DQuickAppLoaderItem *DQuickWindowAttached::appLoader() const
{
D_DC(DQuickWindowAttached);
if (!d->appLoaderItem) {
const_cast<DQuickWindowAttachedPrivate *>(d)->appLoaderItem =
new DQuickAppLoaderItem(window()->contentItem());
}
return d->appLoaderItem;
}
void DQuickWindowAttached::setAppLoader(DQuickAppLoaderItem *item)
{
D_D(DQuickWindowAttached);
if (d->appLoaderItem == item)
return;
// AppLoaderItem 会在窗口加载完毕后进行创建,因此
// 在窗口创建初期,AppLoaderItem 需要指定一个默认
// 值,防止 Qt 在运行时出现警告和报错
if (d->appLoaderItem) {
d->appLoaderItem->deleteLater();
}
d->appLoaderItem = item;
Q_EMIT appLoaderChanged();
}
void DQuickWindowAttached::setLoadingOverlay(QQmlComponent *component)
{
D_D(DQuickWindowAttached);
if (component == d->loadingOverlay)
return;
d->loadingOverlay = component;
Q_EMIT loadingOverlayChanged();
}
void DQuickWindowAttached::setWindowEffect(DTK_GUI_NAMESPACE::DPlatformHandle::EffectScenes effect)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setWindowEffect(effect);
else
d->explicitEffectScene = effect;
}
void DQuickWindowAttached::setWindowStartUpEffect(DTK_GUI_NAMESPACE::DPlatformHandle::EffectTypes type)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setWindowStartUpEffect(type);
else
d->explicitEffectType = type;
}
void DQuickWindowAttached::showMinimized()
{
window()->setWindowStates((window()->windowStates() & ~Qt::WindowActive) | Qt::WindowMinimized);
window()->setVisible(true);
}
void DQuickWindowAttached::showMaximized()
{
window()->setWindowStates((window()->windowStates() & ~(Qt::WindowMinimized | Qt::WindowFullScreen))
| Qt::WindowMaximized);
window()->setVisible(true);
}
void DQuickWindowAttached::showFullScreen()
{
window()->setWindowStates((window()->windowStates() & ~(Qt::WindowMinimized | Qt::WindowMaximized))
| Qt::WindowFullScreen);
window()->setVisible(true);
#if !defined Q_OS_QNX
window()->requestActivate();
#endif
}
void DQuickWindowAttached::showNormal()
{
window()->setWindowStates(window()->windowStates() & ~(Qt::WindowMinimized
| Qt::WindowMaximized
| Qt::WindowFullScreen));
window()->setVisible(true);
}
/*!
* \~chinese \property DQuickWindowAttached::translucentBackground
* \~chinese \brief 如果此属性值为 true,则在更新窗口绘制内容之前会先清空要更新区域内的图像,否则不清空。
*/
bool DQuickWindowAttached::translucentBackground() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return false;
}
return d->handle->translucentBackground();
}
/*!
* \~chinese \brief DQuickWindowAttached::enableSystemResize
* \~chinese \return 如果此属性值为 true,则允许外界改变窗口的大小(如使用鼠标拖拽窗口边框),否则不允许。
* \~chinese \note 此属性仅仅控制 dxcb 中的行为,不会影响窗口管理器的行为。
*/
bool DQuickWindowAttached::enableSystemResize() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return false;
}
return d->handle->enableSystemResize();
}
/*!
* \~chinese \property DQuickWindowAttached::enableSystemMove
* \~chinese \brief 如果此属性值为 ture,则允许外界移动窗口的位置(如使用鼠标拖拽移动窗口),否则不允许。
* \~chinese \note 此属性仅仅控制 dxcb 中的行为,不会影响窗口管理器的行为。
*/
bool DQuickWindowAttached::enableSystemMove() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return false;
}
return d->handle->enableSystemMove();
}
/*!
* \~chinese \property DQuickWindowAttached::enableBlurWindow
* \~chinese \brief 如果此属性为 true,则窗口有效区域内的背景将呈现出模糊效果,否则无特效。
*/
bool DQuickWindowAttached::enableBlurWindow() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return false;
}
return d->handle->enableBlurWindow();
}
/*!
* \~chinese \brief DQuickWindowAttached::wmWindowTypes 返回此窗口在窗口管理器级别的窗口类型
* \~chinese 需要注意的是,此值只是内部状态的记录,只会在调用 \a setWmWindowTypes
* \~chinese 时更新,默认值为 \a DWindowManagerHelper::UnknowWindowType
*/
DWindowManagerHelper::WmWindowTypes DQuickWindowAttached::wmWindowTypes() const
{
D_DC(DQuickWindowAttached);
return d->wmWindowTypes;
}
DWindowManagerHelper::MotifFunctions DQuickWindowAttached::motifFunctions() const
{
D_DC(DQuickWindowAttached);
return d->motifFunctions;
}
DWindowManagerHelper::MotifDecorations DQuickWindowAttached::motifDecorations() const
{
D_DC(DQuickWindowAttached);
return d->motifDecorations;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType DQuickWindowAttached::themeType() const
{
D_DC(DQuickWindowAttached);
return d->themeType;
}
void DQuickWindowAttached::setThemeType(const DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType &newThemeType)
{
D_D(DQuickWindowAttached);
if (d->themeType == newThemeType)
return;
d->themeType = newThemeType;
d->ensurePalette();
d->_q_onPaletteChanged();
emit themeTypeChanged();
}
void DQuickWindowAttached::resetThemeType()
{
D_D(DQuickWindowAttached);
if (!d->paletteInit) {
return;
}
d->paletteInit = false;
for (const QMetaObject::Connection &connection : std::as_const(d->paletteConnections))
disconnect(connection);
d->paletteConnections = {};
delete d->quickPalette;
d->quickPalette = nullptr;
delete d->inactiveQuickPalette;
d->inactiveQuickPalette = nullptr;
if (d->themeType != DGuiApplicationHelper::UnknownType) {
d->themeType = DGuiApplicationHelper::UnknownType;
emit themeTypeChanged();
}
QQuickWindowPrivate::get(window())->resetPalette();
}
#endif
DTK_GUI_NAMESPACE::DPlatformHandle::EffectScene DQuickWindowAttached::windowEffect() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return DTK_GUI_NAMESPACE::DPlatformHandle::EffectScene(0);
}
return d->handle->windowEffect();
}
DTK_GUI_NAMESPACE::DPlatformHandle::EffectType DQuickWindowAttached::windowStartUpEffect() const
{
D_DC(DQuickWindowAttached);
if (!d->handle) {
return DTK_GUI_NAMESPACE::DPlatformHandle::EffectType(0);
}
return d->handle->windowStartUpEffect();
}
/*!
* \~chinese \brief DQuickWindowAttached::setEnabled 设置当前的窗口为 DTK 风格。
* \~chinese \note 只能把默认风格设置为 DTK 风格,不能把 DTK 设置为默认风格。
* \~chinese \param \a true 使用 DTK 风格, \a false 无效。
*/
void DQuickWindowAttached::setEnabled(bool e)
{
D_D(DQuickWindowAttached);
if (e == isEnabled())
return;
if (!e) {
d->destoryPlatformHandle();
Q_EMIT enabledChanged();
return;
}
if (!d->ensurePlatformHandle()) {
d->explicitEnable = static_cast<DQuickWindowAttachedPrivate::BoolOptional>(e);
QObject::connect(DWindowManagerHelper::instance(), SIGNAL(hasNoTitlebarChanged()), this, SLOT(_q_ensurePlatformHandle())
, Qt::UniqueConnection);
}
}
/*!
* \~chinese \brief DQuickWindowAttached::setWindowRadius 设定窗口的圆角
* \~chinese \param windowRadius 窗口的圆角值
*/
void DQuickWindowAttached::setWindowRadius(int windowRadius)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setWindowRadius(windowRadius);
else
d->explicitWindowRadius = windowRadius;
}
/*!
* \~chinese \brief DQuickWindowAttached::setBorderWidth 设定边框的宽度
* \~chinese \param borderWidth 边框的宽度
*/
void DQuickWindowAttached::setBorderWidth(int borderWidth)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setBorderWidth(borderWidth);
else
d->explicitBorderWidth = borderWidth;
}
/*!
* \~chinese \brief DQuickWindowAttached::setBorderColor 设定边框的颜色
* \~chinese \param borderColor 边框的颜色
*/
void DQuickWindowAttached::setBorderColor(const QColor &borderColor)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setBorderColor(borderColor);
else
d->explicitBorderColor = borderColor;
}
/*!
* \~chinese \brief DQuickWindowAttached::setShadowRadius 设定阴影区域的圆角
* \~chinese \param shadowRadius 阴影区域圆角大小
*/
void DQuickWindowAttached::setShadowRadius(int shadowRadius)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setShadowRadius(shadowRadius);
else
d->explicitShadowRadius = shadowRadius;
}
/*!
* \~chinese \brief DQuickWindowAttached::setShadowOffset 设定阴影区域的偏移距离
* \~chinese \param shadowOffset 阴影区域的偏移距离
*/
void DQuickWindowAttached::setShadowOffset(const QPoint &shadowOffset)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setShadowOffset(shadowOffset);
else
d->explicitShadowOffset = shadowOffset;
}
/*!
* \~chinese \brief DQuickWindowAttached::setShadowColor 设定阴影的颜色
* \~chinese \param shadowColor 阴影的颜色
*/
void DQuickWindowAttached::setShadowColor(const QColor &shadowColor)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setShadowColor(shadowColor);
else
d->explicitShadowColor = shadowColor;
}
/*!
* \~chinese \brief DQuickWindowAttached::setTranslucentBackground 设定时候擦除背景
* \~chinese \param translucentBackground true擦除背景 false不擦除背景
*/
void DQuickWindowAttached::setTranslucentBackground(bool translucentBackground)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setTranslucentBackground(translucentBackground);
else
d->explicitTranslucentBackground = static_cast<DQuickWindowAttachedPrivate::BoolOptional>(translucentBackground);
}
/*!
* \~chinese \brief DQuickWindowAttached::setEnableSystemResize 设定是否允许系统调整窗口大小
* \~chinese \param enableSystemResize true允许系统调整 false不允许系统调整
*/
void DQuickWindowAttached::setEnableSystemResize(bool enableSystemResize)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setEnableSystemResize(enableSystemResize);
else
d->explicitEnableSystemResize = static_cast<DQuickWindowAttachedPrivate::BoolOptional>(enableSystemResize);
}
/*!
* \~chinese \brief DQuickWindowAttached::setEnableSystemMove 设定时候允许系统移动窗口
* \~chinese \param enableSystemMove true允许移动 false不允许移动
*/
void DQuickWindowAttached::setEnableSystemMove(bool enableSystemMove)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setEnableSystemMove(enableSystemMove);
else
d->explicitEnableSystemMove = static_cast<DQuickWindowAttachedPrivate::BoolOptional>(enableSystemMove);
}
/*!
* \~chinese \brief DQuickWindowAttached::setEnableBlurWindow 设定窗口有效区域内的背景将呈现出模糊效果。
* \~chinese \param enableBlurWindow true有特效 false无特效。
*/
void DQuickWindowAttached::setEnableBlurWindow(bool enableBlurWindow)
{
D_D(DQuickWindowAttached);
d->ensurePlatformHandle();
if (d->handle)
d->handle->setEnableBlurWindow(enableBlurWindow);
else
d->explicitEnableBlurWindow = static_cast<DQuickWindowAttachedPrivate::BoolOptional>(enableBlurWindow);
}
/*!
* \~chinese \brief DQuickWindowAttached::setWmWindowTypes 为此窗口设置与本地窗口管理器
* \~chinese 息息相关的窗口类型,这些类型不保证在所有平台下都能生效,因此可能会影响程序
* \~chinese 的跨平台行为,请尽量使用 \a QWindow::setFlags 设置所需要的窗口类型。
* \~chinese \param wmWindowTypes 新的窗口类型,此枚举值可组合使用
* \~chinese \note 调用此接口设置的窗口类型会与 \a QWindow::flags 中控制窗口类型的
* \~chinese 部分共同生效
*/
void DQuickWindowAttached::setWmWindowTypes(DWindowManagerHelper::WmWindowTypes wmWindowTypes)
{
D_D(DQuickWindowAttached);
if (d->wmWindowTypes == wmWindowTypes)
return;
d->wmWindowTypes = wmWindowTypes;
DWindowManagerHelper::setWmWindowTypes(window(), wmWindowTypes);
Q_EMIT wmWindowTypesChanged();
}
void DQuickWindowAttached::setMotifFunctions(Gui::DWindowManagerHelper::MotifFunctions motifFunctions)
{
D_D(DQuickWindowAttached);
if (d->motifFunctions == motifFunctions)
return;
d->motifFunctions = motifFunctions;
DWindowManagerHelper::setMotifFunctions(window(), motifFunctions);
Q_EMIT motifFunctionsChanged();
}
void DQuickWindowAttached::setMotifDecorations(DWindowManagerHelper::MotifDecorations motifDecorations)
{
D_D(DQuickWindowAttached);
if (d->motifDecorations == motifDecorations)
return;