Sine Striker
2024-05-08 ea8d13724433cab8ccf53e76f9b8b553d76141ff
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
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
 
#include "windowbutton.h"
#include "windowbutton_p.h"
 
#include <QtCore/QDebug>
#include <QtGui/QtEvents>
 
namespace QWK {
 
    WindowButtonPrivate::WindowButtonPrivate() = default;
 
    WindowButtonPrivate::~WindowButtonPrivate() = default;
 
    void WindowButtonPrivate::init() {
    }
 
    void WindowButtonPrivate::reloadIcon() {
        Q_Q(WindowButton);
 
        if (!q->isEnabled() && !iconDisabled.isNull()) {
            q->setIcon(iconDisabled);
            return;
        }
 
        if (q->isChecked() && !iconChecked.isNull()) {
            q->setIcon(iconChecked);
            return;
        }
 
        if (!iconNormal.isNull()) {
            q->setIcon(iconNormal);
        }
    }
 
    WindowButton::WindowButton(QWidget *parent) : WindowButton(*new WindowButtonPrivate(), parent) {
    }
 
    WindowButton::~WindowButton() = default;
 
    QIcon WindowButton::iconNormal() const {
        Q_D(const WindowButton);
        return d->iconNormal;
    }
 
    void WindowButton::setIconNormal(const QIcon &icon) {
        Q_D(WindowButton);
        d->iconNormal = icon;
        d->reloadIcon();
    }
 
    QIcon WindowButton::iconChecked() const {
        Q_D(const WindowButton);
        return d->iconChecked;
    }
 
    void WindowButton::setIconChecked(const QIcon &icon) {
        Q_D(WindowButton);
        d->iconChecked = icon;
        d->reloadIcon();
    }
 
    QIcon WindowButton::iconDisabled() const {
        Q_D(const WindowButton);
        return d->iconDisabled;
    }
 
    void WindowButton::setIconDisabled(const QIcon &icon) {
        Q_D(WindowButton);
        d->iconDisabled = icon;
        d->reloadIcon();
    }
 
    void WindowButton::checkStateSet() {
        Q_D(WindowButton);
        d->reloadIcon();
    }
 
    void WindowButton::mouseDoubleClickEvent(QMouseEvent *event) {
        if (event->button() == Qt::LeftButton) {
            Q_EMIT doubleClicked();
        }
    }
 
    WindowButton::WindowButton(WindowButtonPrivate &d, QWidget *parent)
        : QPushButton(parent), d_ptr(&d) {
        d.q_ptr = this;
 
        d.init();
    }
 
}