2
* Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
17
#include "hudtoolbarmodel.h"
19
#include "hudclient.h"
21
static const int ActionRole = Qt::UserRole;
22
static const int EnabledRole = Qt::UserRole + 1;
24
static QString iconForAction(int action)
27
case HUD_CLIENT_QUERY_TOOLBAR_UNDO:
28
return "graphics/undo.png";
29
case HUD_CLIENT_QUERY_TOOLBAR_HELP:
30
return "graphics/help.png";
31
case HUD_CLIENT_QUERY_TOOLBAR_FULLSCREEN:
32
return "graphics/view-fullscreen.png";
33
case HUD_CLIENT_QUERY_TOOLBAR_PREFERENCES:
34
return "graphics/settings.png";
39
HudToolBarModel::HudToolBarModel(HudClientQuery *query)
42
m_actions << HUD_CLIENT_QUERY_TOOLBAR_UNDO
43
<< HUD_CLIENT_QUERY_TOOLBAR_HELP
44
<< HUD_CLIENT_QUERY_TOOLBAR_FULLSCREEN
45
<< HUD_CLIENT_QUERY_TOOLBAR_PREFERENCES;
48
HudToolBarModel::~HudToolBarModel()
52
int HudToolBarModel::rowCount(const QModelIndex &parent) const
57
return m_actions.count();
60
QVariant HudToolBarModel::data(const QModelIndex &index, int role) const
62
const int row = index.row();
63
if (row >= m_actions.count())
66
const HudClientQueryToolbarItems action = m_actions[row];
69
case Qt::DecorationRole:
70
return iconForAction(action);
78
return hud_client_query_toolbar_item_active(m_query, action);
84
QHash<int,QByteArray> HudToolBarModel::roleNames() const
86
static QHash<int,QByteArray> roles;
87
if (roles.isEmpty()) {
88
roles[Qt::DecorationRole] = "iconPath";
89
roles[ActionRole] = "action";
90
roles[EnabledRole] = "enabled";
95
void HudToolBarModel::updatedByBackend()
97
Q_EMIT dataChanged(index(0, 0), index(rowCount() - 1, 0), QVector<int>() << EnabledRole);