source: smplayer/vendor/current/src/myactiongroup.cpp@ 175

Last change on this file since 175 was 175, checked in by Silvan Scherrer, 9 years ago

smplayer: update vendor to version 16.4

File size: 3.1 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
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; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "myactiongroup.h"
20#include <QAction>
21#include <QList>
22#include <QWidget>
23
24MyActionGroupItem::MyActionGroupItem(QObject * parent, MyActionGroup *group,
25 const char * name,
26 int data, bool autoadd)
27 : MyAction(parent, name, autoadd)
28{
29 setData(data);
30 setCheckable(true);
31 if (group) group->addAction(this);
32}
33
34MyActionGroupItem::MyActionGroupItem(QObject * parent, MyActionGroup *group,
35 const QString & text,
36 const char * name,
37 int data, bool autoadd)
38 : MyAction(parent, name, autoadd)
39{
40 setData(data);
41 setText(text);
42 setCheckable(true);
43 if (group) group->addAction(this);
44}
45
46
47MyActionGroup::MyActionGroup( QObject * parent ) : QActionGroup(parent)
48{
49 setExclusive(true);
50 connect( this, SIGNAL(triggered(QAction *)),
51 this, SLOT(itemTriggered(QAction *)) );
52}
53
54void MyActionGroup::setChecked(int ID) {
55 //qDebug("MyActionGroup::setChecked: ID: %d", ID);
56
57 QList <QAction *> l = actions();
58 for (int n=0; n < l.count(); n++) {
59 if ( (!l[n]->isSeparator()) && (l[n]->data().toInt() == ID) ) {
60 l[n]->setChecked(true);
61 return;
62 }
63 }
64}
65
66int MyActionGroup::checked() {
67 QAction * a = checkedAction();
68 if (a)
69 return a->data().toInt();
70 else
71 return -1;
72}
73
74void MyActionGroup::uncheckAll() {
75 QList <QAction *> l = actions();
76 for (int n=0; n < l.count(); n++) {
77 l[n]->setChecked(false);
78 }
79}
80
81void MyActionGroup::setActionsEnabled(bool b) {
82 QList <QAction *> l = actions();
83 for (int n=0; n < l.count(); n++) {
84 l[n]->setEnabled(b);
85 }
86}
87
88void MyActionGroup::clear(bool remove) {
89 while (actions().count() > 0) {
90 QAction * a = actions()[0];
91 if (a) {
92 removeAction(a);
93 if (remove) a->deleteLater();
94 }
95 }
96}
97
98void MyActionGroup::itemTriggered(QAction *a) {
99 qDebug("MyActionGroup::itemTriggered: '%s'", a->objectName().toUtf8().data());
100 int value = a->data().toInt();
101
102 qDebug("MyActionGroup::itemTriggered: ID: %d", value);
103
104 emit activated(value);
105}
106
107void MyActionGroup::addTo(QWidget *w) {
108 w->addActions( actions() );
109}
110
111void MyActionGroup::removeFrom(QWidget *w) {
112 for (int n=0; n < actions().count(); n++) {
113 w->removeAction( actions()[n] );
114 }
115}
116
117#include "moc_myactiongroup.cpp"
Note: See TracBrowser for help on using the repository browser.