on 551c708 help sign in
unity8/plugins/Unity/Indicators/menucontentactivator.h
117 lines 3.3 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Nick Dedekind <nick.dedekind@canonical.com>
17 */
19#ifndef MENUCONTENTACTIVATOR_H
20#define MENUCONTENTACTIVATOR_H
22#include "unityindicatorsglobal.h"
24#include <QObject>
25#include <QTimer>
26#include <QQmlListProperty>
29namespace UnityIndicators {
30/* Defines an interface for a Timer. */
31class UNITYINDICATORS_EXPORT AbstractTimer : public QObject {
32 Q_OBJECT
33public:
34 AbstractTimer(QObject *parent) : QObject(parent), m_isRunning(false) {}
35 virtual int interval() const = 0;
36 virtual void setInterval(int msecs) = 0;
37 virtual void start() { m_isRunning = true; };
38 virtual void stop() { m_isRunning = false; }
39 bool isRunning() const { return m_isRunning; }
40Q_SIGNALS:
41 void timeout();
42private:
43 bool m_isRunning;
44};
47/* Defines a object to express the active state of a menu. */
48class UNITYINDICATORS_EXPORT MenuContentState : public QObject
50 Q_OBJECT
51 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
52public:
53 MenuContentState(bool active);
55 bool isActive() const;
56 void setActive(bool active);
58Q_SIGNALS:
59 void activeChanged();
60private:
61 bool m_active;
62};
64class MenuContentActivatorPrivate;
66class UNITYINDICATORS_EXPORT MenuContentActivator : public QObject
68 Q_OBJECT
69 Q_PROPERTY(int baseIndex READ baseIndex WRITE setBaseIndex NOTIFY baseIndexChanged)
70 Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
71 Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
72 Q_PROPERTY(QQmlListProperty<MenuContentState> content READ content NOTIFY contentChanged DESIGNABLE false)
73public:
74 MenuContentActivator(QObject* parent = NULL);
75 ~MenuContentActivator();
77 Q_INVOKABLE void restart();
78 Q_INVOKABLE void stop();
79 Q_INVOKABLE void clear();
80 Q_INVOKABLE bool isMenuContentActive(int index) const;
82 void setRunning(bool running);
83 bool isRunning() const;
85 void setBaseIndex(int index);
86 int baseIndex() const;
88 void setCount(int index);
89 int count() const;
91 void setDelta(int index);
92 int delta() const;
94 QQmlListProperty<MenuContentState> content();
96 // Replaces the existing Timer with the given one.
97 //
98 // Useful for providing a fake timer when testing.
99 void setContentTimer(UnityIndicators::AbstractTimer *timer);
100 void setMenuContentState(int index, bool active);
102Q_SIGNALS:
103 void baseIndexChanged(int baseIndex);
104 void deltaChanged(int delta);
105 void runningChanged(bool running);
106 void countChanged(int count);
107 void contentChanged();
109private Q_SLOTS:
110 void onTimeout();
112private:
113 MenuContentActivatorPrivate* d;
114 friend class MenuContentActivatorPrivate;
115};
117#endif // MENUCONTENTACTIVATOR_H