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
|
/*
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Nick Dedekind <nick.dedekind@canonical.com>
*/
#ifndef MENUCONTENTACTIVATOR_H
#define MENUCONTENTACTIVATOR_H
#include "unityindicatorsglobal.h"
#include <QObject>
#include <QTimer>
#include <QQmlListProperty>
namespace UnityIndicators {
/* Defines an interface for a Timer. */
class UNITYINDICATORS_EXPORT AbstractTimer : public QObject {
Q_OBJECT
public:
AbstractTimer(QObject *parent) : QObject(parent), m_isRunning(false) {}
virtual int interval() const = 0;
virtual void setInterval(int msecs) = 0;
virtual void start() { m_isRunning = true; };
virtual void stop() { m_isRunning = false; }
bool isRunning() const { return m_isRunning; }
Q_SIGNALS:
void timeout();
private:
bool m_isRunning;
};
}
/* Defines a object to express the active state of a menu. */
class UNITYINDICATORS_EXPORT MenuContentState : public QObject
{
Q_OBJECT
Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
public:
MenuContentState(bool active);
bool isActive() const;
void setActive(bool active);
Q_SIGNALS:
void activeChanged();
private:
bool m_active;
};
class MenuContentActivatorPrivate;
class UNITYINDICATORS_EXPORT MenuContentActivator : public QObject
{
Q_OBJECT
Q_PROPERTY(int baseIndex READ baseIndex WRITE setBaseIndex NOTIFY baseIndexChanged)
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
Q_PROPERTY(QQmlListProperty<MenuContentState> content READ content NOTIFY contentChanged DESIGNABLE false)
public:
MenuContentActivator(QObject* parent = NULL);
~MenuContentActivator();
Q_INVOKABLE void restart();
Q_INVOKABLE void stop();
Q_INVOKABLE void clear();
Q_INVOKABLE bool isMenuContentActive(int index) const;
void setRunning(bool running);
bool isRunning() const;
void setBaseIndex(int index);
int baseIndex() const;
void setCount(int index);
int count() const;
void setDelta(int index);
int delta() const;
QQmlListProperty<MenuContentState> content();
// Replaces the existing Timer with the given one.
//
// Useful for providing a fake timer when testing.
void setContentTimer(UnityIndicators::AbstractTimer *timer);
void setMenuContentState(int index, bool active);
Q_SIGNALS:
void baseIndexChanged(int baseIndex);
void deltaChanged(int delta);
void runningChanged(bool running);
void countChanged(int count);
void contentChanged();
private Q_SLOTS:
void onTimeout();
private:
MenuContentActivatorPrivate* d;
friend class MenuContentActivatorPrivate;
};
#endif // MENUCONTENTACTIVATOR_H
|