Parent: [20f9b9] (diff)

Child: [22256a] (diff)

Download this file

ContextMenu.cpp    142 lines (105 with data), 3.8 kB

  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
/* ContextMenu.cpp */
/* Copyright (C) 2013 Lucio Carreras
*
* This file is part of sayonara player
*
* 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, either version 3 of the License, or
* (at your option) any later version.
* 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/>.
*/
#include "GUI/ContextMenu.h"
#include "HelperStructs/Helper.h"
#include <QAction>
#include <QList>
#include <QDebug>
ContextMenu::ContextMenu(QWidget* parent) :
QMenu(parent)
{
_info_action = new QAction(QIcon(Helper::getIconPath() + "info_small.png"), tr("Info"), this);
_edit_action = new QAction(QIcon(Helper::getIconPath() + "edit.png"), tr("Edit"), this);
_remove_action = new QAction(QIcon(Helper::getIconPath() + "delete.png"), tr("Remove"), this);
_delete_action = new QAction(QIcon(Helper::getIconPath() + "delete.png"), tr("Delete"), this);
_play_next_action = new QAction(QIcon(Helper::getIconPath() + "fwd_orange.png"), tr("Play next"), this);
_append_action = new QAction(QIcon(Helper::getIconPath() + "append.png"), tr("Append"), this);
}
ContextMenu::~ContextMenu()
{
clear_actions();
delete _info_action;
delete _edit_action;
delete _remove_action;
delete _delete_action;
delete _play_next_action;
}
void ContextMenu::clear_actions()
{
QList<QAction*> actions = this->actions();
if (actions.size() > 0) {
foreach(QAction * a, actions)
this->removeAction(a);
}
disconnect(_info_action, SIGNAL(triggered()), this, SLOT(info_clicked()));
disconnect(_edit_action, SIGNAL(triggered()), this, SLOT(edit_clicked()));
disconnect(_remove_action, SIGNAL(triggered()), this, SLOT(remove_clicked()));
disconnect(_delete_action, SIGNAL(triggered()), this, SLOT(delete_clicked()));
disconnect(_play_next_action, SIGNAL(triggered()), this, SLOT(play_next_clicked()));
}
void ContextMenu::setup_entries(int entries)
{
clear_actions();
if (entries & ENTRY_INFO) {
this->addAction(_info_action);
connect(_info_action, SIGNAL(triggered()), this, SLOT(info_clicked()));
}
if (entries & ENTRY_EDIT) {
this->addAction(_edit_action);
connect(_edit_action, SIGNAL(triggered()), this, SLOT(edit_clicked()));
}
if (entries & ENTRY_REMOVE) {
this->addAction(_remove_action);
connect(_remove_action, SIGNAL(triggered()), this, SLOT(remove_clicked()));
}
if (entries & ENTRY_DELETE) {
this->addAction(_delete_action);
connect(_delete_action, SIGNAL(triggered()), this, SLOT(delete_clicked()));
}
if (entries & ENTRY_PLAY_NEXT) {
this->addAction(_play_next_action);
connect(_play_next_action, SIGNAL(triggered()), this, SLOT(play_next_clicked()));
}
if (entries & ENTRY_APPEND) {
this->addAction(_append_action);
connect(_append_action, SIGNAL(triggered()), this, SLOT(append_clicked()));
}
}
void ContextMenu::info_clicked()
{
emit sig_info_clicked();
}
void ContextMenu::edit_clicked()
{
emit sig_edit_clicked();
}
void ContextMenu::remove_clicked()
{
emit sig_remove_clicked();
}
void ContextMenu::delete_clicked()
{
emit sig_delete_clicked();
}
void ContextMenu::play_next_clicked()
{
emit sig_play_next_clicked();
}
void ContextMenu::append_clicked()
{
emit sig_append_clicked();
}