1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "command.h" |
6 | |
7 | #include <QAction> |
8 | |
9 | class ActionPrivate |
10 | { |
11 | public: |
12 | ActionPrivate(); |
13 | virtual ~ActionPrivate(); |
14 | |
15 | private: |
16 | QString id; |
17 | QKeySequence shortcutKey; |
18 | QString description; |
19 | QAction *action; |
20 | |
21 | friend class Action; |
22 | }; |
23 | |
24 | ActionPrivate::ActionPrivate() |
25 | : action(nullptr) |
26 | { |
27 | |
28 | } |
29 | |
30 | ActionPrivate::~ActionPrivate() |
31 | { |
32 | |
33 | } |
34 | |
35 | Action::Action(QString id, QAction *action) |
36 | : d(new ActionPrivate()) |
37 | { |
38 | d->id = id; |
39 | d->action = action; |
40 | } |
41 | |
42 | Action::~Action() |
43 | { |
44 | if (d) { |
45 | delete d; |
46 | } |
47 | } |
48 | |
49 | QString Action::id() const |
50 | { |
51 | return d->id; |
52 | } |
53 | |
54 | QAction *Action::action() const |
55 | { |
56 | return d->action; |
57 | } |
58 | |
59 | void Action::setKeySequence(const QKeySequence &key) |
60 | { |
61 | d->shortcutKey = key; |
62 | if (d->action) |
63 | d->action->setShortcut(key); |
64 | } |
65 | |
66 | QKeySequence Action::keySequence() const |
67 | { |
68 | return d->shortcutKey; |
69 | } |
70 | |
71 | void Action::setDescription(const QString &text) |
72 | { |
73 | d->description = text; |
74 | if (d->action) |
75 | d->action->setText(text); |
76 | } |
77 | |
78 | QString Action::description() const |
79 | { |
80 | return d->description; |
81 | } |
82 | |
83 | |
84 | |
85 |