source: smplayer/trunk/src/myaction.cpp@ 176

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

smplayer: update trunk to version 16.4

  • Property svn:eol-style set to LF
File size: 2.6 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 "myaction.h"
20#include <QWidget>
21
22MyAction::MyAction ( QObject * parent, const char * name, bool autoadd )
23 : QAction(parent)
24{
25 //qDebug("MyAction::MyAction: name: '%s'", name);
26 setObjectName(name);
27 if (autoadd) addActionToParent();
28}
29
30
31MyAction::MyAction( QObject * parent, bool autoadd )
32 : QAction(parent)
33{
34 //qDebug("MyAction::MyAction: QObject, bool");
35 if (autoadd) addActionToParent();
36}
37
38MyAction::MyAction(const QString & text, QKeySequence accel,
39 QObject * parent, const char * name, bool autoadd )
40 : QAction(parent)
41{
42 setObjectName(name);
43 setText(text);
44 setShortcut(accel);
45 if (autoadd) addActionToParent();
46}
47
48MyAction::MyAction(QKeySequence accel, QObject * parent, const char * name,
49 bool autoadd )
50 : QAction(parent)
51{
52 setObjectName(name);
53 setShortcut(accel);
54 if (autoadd) addActionToParent();
55}
56
57MyAction::~MyAction() {
58}
59
60void MyAction::addShortcut(QKeySequence key) {
61 setShortcuts( shortcuts() << key);
62}
63
64void MyAction::addActionToParent() {
65 if (parent()) {
66 if (parent()->inherits("QWidget")) {
67 QWidget *w = static_cast<QWidget*> (parent());
68 w->addAction(this);
69 }
70 }
71}
72
73void MyAction::change(const QIcon & icon, const QString & text) {
74 setIcon( icon );
75 change(text);
76}
77
78void MyAction::change(const QString & text ) {
79 setText( text );
80
81 QString accel_text = shortcut().toString();
82
83 QString s = text;
84 s.replace("&","");
85 if (!accel_text.isEmpty()) {
86 setToolTip( s + " ("+ accel_text +")");
87 setIconText( s );
88 }
89
90 /*
91 if (text.isEmpty()) {
92 QString s = menuText;
93 s = s.replace("&","");
94 setText( s );
95
96 if (!accel_text.isEmpty())
97 setToolTip( s + " ("+ accel_text +")");
98 } else {
99 setText( text );
100 if (!accel_text.isEmpty())
101 setToolTip( text + " ("+ accel_text +")");
102 }
103 */
104}
105
Note: See TracBrowser for help on using the repository browser.