1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-2021 Ricardo Villalba <ricardo@smplayer.info> 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 #ifndef MYACTIONGROUP_H 20 #define MYACTIONGROUP_H 21 22 #include <QActionGroup> 23 #include <QWidget> 24 #include "myaction.h" 25 26 class MyActionGroup; 27 28 //! This class makes easy to create actions for MyActionGroup 29 30 class MyActionGroupItem : public MyAction 31 { 32 public: 33 //! Creates a new item. 34 /*! \a group is the group where the action will be added, \a data is 35 the ID of the item. If \autoadd is true the action will be added to 36 the parent (if it's a QWidget), so the shortcut could work. */ 37 MyActionGroupItem( QObject * parent, MyActionGroup *group, 38 const char * name, int data, bool autoadd = true ); 39 40 //! Creates a new item. 41 /*! \a text is the text that the item will have. */ 42 MyActionGroupItem( QObject * parent, MyActionGroup *group, 43 const QString & text, const char * name, 44 int data, bool autoadd = true ); 45 }; 46 47 class QAction; 48 49 //! MyActionGroup makes easier to create exclusive menus based on items 50 //! with an integer data. 51 52 53 class MyActionGroup : public QActionGroup 54 { 55 Q_OBJECT 56 57 public: 58 MyActionGroup ( QObject * parent ); 59 60 //! Looks for the item which ID is \a ID and checks it 61 void setChecked(int ID); 62 63 //! Returns the ID of the item checked or -1 if none 64 //! is checked 65 int checked(); 66 67 //! Remove all items. If \a remove is true the actions are also deleted. 68 void clear(bool remove); 69 70 //! Enable or disable all actions in the group 71 void setActionsEnabled(bool); 72 73 //! Adds all actions to the widget 74 void addTo(QWidget *); 75 76 //! Remove all actions from the widget 77 void removeFrom(QWidget *); 78 79 //! unchecks all items 80 void uncheckAll(); 81 82 signals: 83 //! Emitted when an item has been checked 84 void activated(int); 85 86 protected slots: 87 void itemTriggered(QAction *); 88 }; 89 90 #endif 91