File: status.hpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (154 lines) | stat: -rw-r--r-- 5,880 bytes parent folder | download | duplicates (3)
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
/************************************************************************
 *
 * Copyright (C) 2023-2024 IRCAD France
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#pragma once

#include <ui/__/editor.hpp>

#include <QPointer>
#include <QToolButton>

namespace sight::module::ui::qt
{

/**
 * @brief Shows a colored circle (red, orange, green) representing a status.
 *
 * @note To change the status color, you should call the slots 'changeToGreen', * 'changeToOrange', 'changeToRed'
 * or 'toggleGreenRed'.
 *
 * @brief Configures the status tooltip
 *
 * @section XML XML Configuration
 * @code{.xml}
   <service uid="..." type="sight::module::ui::qt::status">
       <layout>horizontal|vertical</layout>
       <labels display="under|beside">
           <name>SCP Server</name>
           <name>TCP Server</name>
       </labels>
       <red>Stopped</red>
       <green>Tracking</green>
       <orange>Started</orange>
   </service>
   @endcode
 * - \b count (optional, '1' by default): the number of status
 * - \b layout(optional, 'horizontal' by default): orientation of the layout
 * - \b labels (optional): the description associated to the indicators when count > 1
 *   - \b display (optional, 'under' by default): location of the label display
 *   - \b name (optional): the description associated to each indicator
 * - \b name (optional): the description associated to the indicator when count = 1 or is missing
 * - \b red (optional): the description associated to the red status
 * - \b green (optional): the description associated to the green status
 * - \b orange (optional): the description associated to the orange status
 *
 * @section Slots Slots
 * - \b change_to_green(): This slot allows to change the indicator color to green. If there is more than one status, it
 * changes them all.
 * - \b change_to_red(): This slot allows to change the indicator color to red. If there is more than one status, it
 * changes them all.
 * - \b change_to_orange(): This slot allows to change the indicator color to orange. If there is more than one status,
 * it
 * changes them all.
 * - \b toggle_green_red(bool): This slot allows to change the indicator color to green or red. If there is more than
 * one,
 * it toggle them all.
 * - \b change_nth_to_green(int): This slot allows to change the indicator color to green for the ith status.
 * - \b change_nth_to_red(int): This slot allows to change the indicator color to red for the ith status.
 * - \b change_nth_to_orange(int): This slot allows to change the indicator color to orange for the ith status.
 * - \b toggle_nth_green_red(int,bool): This slot allows to change the indicator color to green or red for the ith
 * status.
 */
class status : public QObject,
               public sight::ui::editor
{
public:

    SIGHT_DECLARE_SERVICE(status, sight::ui::editor);

    /// Constructor. Do nothing.
    status() noexcept;

    /// Destructor. Do nothing.
    ~status() noexcept override = default;

    struct slots
    {
        static inline const core::com::slots::key_t CHANGE_TO_GREEN_SLOT      = "change_to_green";
        static inline const core::com::slots::key_t CHANGE_TO_RED_SLOT        = "change_to_red";
        static inline const core::com::slots::key_t CHANGE_TO_ORANGE_SLOT     = "change_to_orange";
        static inline const core::com::slots::key_t TOGGLE_GREEN_RED_SLOT     = "toggle_green_red";
        static inline const core::com::slots::key_t CHANGE_NTH_TO_GREEN_SLOT  = "change_nth_to_green";
        static inline const core::com::slots::key_t CHANGE_NTH_TO_RED_SLOT    = "change_nth_to_red";
        static inline const core::com::slots::key_t CHANGE_NTH_TO_ORANGE_SLOT = "change_nth_to_orange";
        static inline const core::com::slots::key_t TOGGLE_NTH_GREEN_RED_SLOT = "toggle_nth_green_red";
    };

protected:

    void configuring(const config_t& _config) override;
    void starting() override;
    void stopping() override;

    /// Does nothing
    void updating() override;

    /// SLOT : change label color to green
    void change_to_green();

    /// SLOT : change label color to red
    void change_to_red();

    /// SLOT : change label color to orange
    void change_to_orange();

    /// SLOT : change label color (true = green, false = red)
    void toggle_green_red(bool _green);

    /// SLOT : change nth label color to green
    void change_nth_to_green(int _index);

    /// SLOT : change nth label color to red
    void change_nth_to_red(int _index);

    /// SLOT : change nth label color to orange
    void change_nth_to_orange(int _index);

    /// SLOT : change nth label color (true = green, false = red)
    void toggle_nth_green_red(int _index, bool _green);

private:

    QVector<QPointer<QToolButton> > m_label_status;

    std::string m_green_tooltip;  ///< Tooltip for green status
    std::string m_red_tooltip;    ///< Tooltip for red status
    std::string m_orange_tooltip; ///< Tooltip for orange status
    std::string m_orientation;    ///< Layout orientation

    enum class label_display
    {
        UNDER,
        BESIDE
    } m_label_display {label_display::UNDER};
};

} // namespace sight::module::ui::qt