Parent: [c4ba14] (diff)

Child: [81cc60] (diff)

Download this file

ContextMenu.cpp    113 lines (98 with data), 4.0 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
/* 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 "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);
_sort_tno_action = new QAction(tr("Sort by track number"), this);
}
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, SIGNAL(sig_info_clicked()));
disconnect(_edit_action, SIGNAL(triggered()),
this, SIGNAL(sig_edit_clicked()));
disconnect(_remove_action, SIGNAL(triggered()), this,
SIGNAL(sig_remove_clicked()));
disconnect(_delete_action, SIGNAL(triggered()), this,
SIGNAL(sig_delete_clicked()));
disconnect(_play_next_action, SIGNAL(triggered()), this,
SIGNAL(sig_play_next_clicked()));
disconnect(_sort_tno_action, SIGNAL(triggered()), this,
SIGNAL(sig_sort_tno_clicked()));
}
void ContextMenu::setup_entries(int entries)
{
clear_actions();
if (entries & ENTRY_INFO) {
this->addAction(_info_action);
connect(_info_action, SIGNAL(triggered()),
this, SIGNAL(sig_info_clicked()));
}
if (entries & ENTRY_EDIT) {
this->addAction(_edit_action);
connect(_edit_action, SIGNAL(triggered()),
this, SIGNAL(sig_edit_clicked()));
}
if (entries & ENTRY_REMOVE) {
this->addAction(_remove_action);
connect(_remove_action, SIGNAL(triggered()),
this, SIGNAL(sig_remove_clicked()));
}
if (entries & ENTRY_DELETE) {
this->addAction(_delete_action);
connect(_delete_action, SIGNAL(triggered()),
this, SIGNAL(sig_delete_clicked()));
}
if (entries & ENTRY_PLAY_NEXT) {
this->addAction(_play_next_action);
connect(_play_next_action, SIGNAL(triggered()),
this, SIGNAL(sig_play_next_clicked()));
}
if (entries & ENTRY_APPEND) {
this->addAction(_append_action);
connect(_append_action, SIGNAL(triggered()),
this, SIGNAL(sig_append_clicked()));
}
if (entries & ENTRY_SORT_TNO) {
this->addAction(_sort_tno_action);
connect(_sort_tno_action, SIGNAL(triggered()),
this, SIGNAL(sig_sort_tno_clicked()));
}
}