Line |
Branch |
Exec |
Source |
1 |
|
|
/************************************************************************ |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2018-2024 IRCAD France |
4 |
|
|
* Copyright (C) 2018-2019 IHU Strasbourg |
5 |
|
|
* |
6 |
|
|
* This file is part of Sight. |
7 |
|
|
* |
8 |
|
|
* Sight is free software: you can redistribute it and/or modify it under |
9 |
|
|
* the terms of the GNU Lesser General Public License as published by |
10 |
|
|
* the Free Software Foundation, either version 3 of the License, or |
11 |
|
|
* (at your option) any later version. |
12 |
|
|
* |
13 |
|
|
* Sight is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU Lesser General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU Lesser General Public |
19 |
|
|
* License along with Sight. If not, see <https://www.gnu.org/licenses/>. |
20 |
|
|
* |
21 |
|
|
***********************************************************************/ |
22 |
|
|
|
23 |
|
|
#pragma once |
24 |
|
|
|
25 |
|
|
#include <data/boolean.hpp> |
26 |
|
|
|
27 |
|
|
#include <service/base.hpp> |
28 |
|
|
|
29 |
|
|
#include <QShortcut> |
30 |
|
|
|
31 |
|
|
namespace sight::module::ui::qt::com |
32 |
|
|
{ |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* @brief This service sends a signal when the associated shortcut is activated. |
36 |
|
|
* @section XML XML configuration |
37 |
|
|
* @code{.xml} |
38 |
|
|
<service uid="..." impl="sight::module::ui::qt::com::signal_shortcut" > |
39 |
|
|
<properties enabled="false/true/${property_uid}"/> |
40 |
|
|
<config shortcut="..." sid="..." /> |
41 |
|
|
</service> |
42 |
|
|
@endcode |
43 |
|
|
* |
44 |
|
|
* @subsection Configuration Configuration |
45 |
|
|
* - \b shortcut: associated shortcut |
46 |
|
|
* - \b sid/wid (exclusive): id of the service/window associated to the gui container |
47 |
|
|
* to which the shortcut will be associated |
48 |
|
|
* |
49 |
|
|
* @section Signals Signals |
50 |
|
|
* - \b activated(): This signal is emitted when the shortcut is received. |
51 |
|
|
* - \b is_enabled(bool): This signal is emitted when the service change the enables state (current state is sent as a |
52 |
|
|
* boolean parameter) |
53 |
|
|
* - \b enabled(): This signal is emitted when the service is enabled. |
54 |
|
|
* - \b disabled(): This signal is emitted when the service is disabled. |
55 |
|
|
* |
56 |
|
|
* @section Slots Slots |
57 |
|
|
* - \b set_enabled(bool): Sets whether the service emits "activated" when the key-sequence is triggerd |
58 |
|
|
* - \b set_disabled(bool): Opposite of set_enabled(bool). |
59 |
|
|
* - \b enable(): Make the service active. |
60 |
|
|
* - \b disable(): Make the service not inactive. |
61 |
|
|
*/ |
62 |
|
|
class signal_shortcut : public QObject, |
63 |
|
|
public service::base |
64 |
|
|
{ |
65 |
|
|
Q_OBJECT |
66 |
|
|
|
67 |
|
|
public: |
68 |
|
|
|
69 |
|
|
struct signals |
70 |
|
|
{ |
71 |
|
|
using bool_t = core::com::signal<void (bool)>; |
72 |
|
|
using void_t = core::com::signal<void ()>; |
73 |
|
|
|
74 |
|
|
static inline const core::com::signals::key_t IS_ENABLED = "is_enabled"; |
75 |
|
|
static inline const core::com::signals::key_t ENABLED = "enabled"; |
76 |
|
|
static inline const core::com::signals::key_t DISABLED = "disabled"; |
77 |
|
|
static inline const core::com::signals::key_t ACTIVATED = "activated"; |
78 |
|
|
}; |
79 |
|
|
|
80 |
|
|
struct slots |
81 |
|
|
{ |
82 |
|
|
static inline const core::com::slots::key_t SET_ENABLED = "set_enabled"; |
83 |
|
|
static inline const core::com::slots::key_t SET_DISABLED = "set_disabled"; |
84 |
|
|
static inline const core::com::slots::key_t ENABLE = "enable"; |
85 |
|
|
static inline const core::com::slots::key_t DISABLE = "disable"; |
86 |
|
|
static inline const core::com::slots::key_t APPLY_ENABLED = "apply_enabled"; |
87 |
|
|
}; |
88 |
|
|
|
89 |
|
✗ |
SIGHT_DECLARE_SERVICE(signal_shortcut, service::base); |
90 |
|
|
|
91 |
|
|
/// Constructor. Do nothing. |
92 |
|
|
signal_shortcut() noexcept; |
93 |
|
|
|
94 |
|
|
/// Destructor. Do nothing. |
95 |
|
|
~signal_shortcut() noexcept override; |
96 |
|
|
|
97 |
|
|
/// Enables or disables the shortcut service. |
98 |
|
|
void set_enabled(bool _enabled); |
99 |
|
|
|
100 |
|
|
protected: |
101 |
|
|
|
102 |
|
|
/** @name Service methods ( override from service::base ) |
103 |
|
|
* @{ |
104 |
|
|
*/ |
105 |
|
|
|
106 |
|
|
/// This method configures the service |
107 |
|
|
void configuring() override; |
108 |
|
|
|
109 |
|
|
/** |
110 |
|
|
* @brief This method enables the eventFilter |
111 |
|
|
*/ |
112 |
|
|
void starting() override; |
113 |
|
|
|
114 |
|
|
/** |
115 |
|
|
* @brief This method deletes the eventFilter |
116 |
|
|
*/ |
117 |
|
|
void stopping() override; |
118 |
|
|
|
119 |
|
|
/** |
120 |
|
|
* @brief This method does nothing. |
121 |
|
|
*/ |
122 |
|
|
void updating() override; |
123 |
|
|
|
124 |
|
|
/// Connects the properties |
125 |
|
|
service::connections_t auto_connections() const override; |
126 |
|
|
|
127 |
|
|
private Q_SLOTS: |
128 |
|
|
|
129 |
|
|
void on_activation(); |
130 |
|
|
|
131 |
|
|
private: |
132 |
|
|
|
133 |
|
|
/// string containing the shortcut to trigger |
134 |
|
|
std::string m_shortcut; |
135 |
|
|
|
136 |
|
|
/// Service id used to get the widget of the activity to set up a shortcut in |
137 |
|
|
/// Either this member or m_wid has to be specified |
138 |
|
|
std::string m_sid; |
139 |
|
|
|
140 |
|
|
/// Window id used to get the widget of the activity to set up a shortcut in |
141 |
|
|
/// Either this member or m_sid has to be specified |
142 |
|
|
std::string m_wid; |
143 |
|
|
|
144 |
|
|
/// Qt shortcut object |
145 |
|
|
QShortcut* m_shortcut_object {nullptr}; |
146 |
|
|
|
147 |
|
|
/// Enabled property |
148 |
|
|
/// True: the "activated" signal is triggered when key sequence is detected. |
149 |
|
|
/// False: the key sequence is ignored. |
150 |
|
|
sight::data::property<sight::data::boolean> m_enabled {this, "enabled", true}; |
151 |
|
|
}; |
152 |
|
|
|
153 |
|
|
} // namespace sight::module::ui::qt::com |
154 |
|
|
|