[112] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[112] | 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 |
|
---|
| 22 | MyAction::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 |
|
---|
| 31 | MyAction::MyAction( QObject * parent, bool autoadd )
|
---|
| 32 | : QAction(parent)
|
---|
| 33 | {
|
---|
| 34 | //qDebug("MyAction::MyAction: QObject, bool");
|
---|
| 35 | if (autoadd) addActionToParent();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | MyAction::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 |
|
---|
| 48 | MyAction::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 |
|
---|
| 57 | MyAction::~MyAction() {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[165] | 60 | void MyAction::addShortcut(QKeySequence key) {
|
---|
| 61 | setShortcuts( shortcuts() << key);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[112] | 64 | void 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 |
|
---|
| 73 | void MyAction::change(const QIcon & icon, const QString & text) {
|
---|
| 74 | setIcon( icon );
|
---|
| 75 | change(text);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void 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 |
|
---|