1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25 
26 #pragma once
27 
28 #include "icontext.h"
29 
30 #include <utils/id.h>
31 
32 #include <QIcon>
33 #include <QMenu>
34 
35 namespace Core {
36 
37 class CORE_EXPORT IMode : public IContext
38 {
39     Q_OBJECT
40     Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName)
41     Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
42     Q_PROPERTY(int priority READ priority WRITE setPriority)
43     Q_PROPERTY(Utils::Id id READ id WRITE setId)
44     Q_PROPERTY(QMenu *menu READ menu WRITE setMenu)
45     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledStateChanged)
46 
47 public:
48     IMode(QObject *parent = nullptr);
49 
displayName()50     QString displayName() const { return m_displayName; }
icon()51     QIcon icon() const { return m_icon; }
priority()52     int priority() const { return m_priority; }
id()53     Utils::Id id() const { return m_id; }
54     bool isEnabled() const;
menu()55     QMenu *menu() const { return m_menu; }
56 
57     void setEnabled(bool enabled);
setDisplayName(const QString & displayName)58     void setDisplayName(const QString &displayName) { m_displayName = displayName; }
setIcon(const QIcon & icon)59     void setIcon(const QIcon &icon) { m_icon = icon; }
setPriority(int priority)60     void setPriority(int priority) { m_priority = priority; }
setId(Utils::Id id)61     void setId(Utils::Id id) { m_id = id; }
setMenu(QMenu * menu)62     void setMenu(QMenu *menu) { m_menu = menu; }
63 
64 signals:
65     void enabledStateChanged(bool enabled);
66 
67 private:
68     QString m_displayName;
69     QIcon m_icon;
70     QMenu *m_menu = nullptr;
71     int m_priority = -1;
72     Utils::Id m_id;
73     bool m_isEnabled = true;
74 };
75 
76 } // namespace Core
77