Canorus  0.0
actionseditor.h
Go to the documentation of this file.
1 
14 #ifndef _CAACTIONSEDITOR_H_
15 #define _CAACTIONSEDITOR_H_
16 
17 #include <QDialog>
18 #include <QList>
19 #include <QStringList>
20 #include "ui/singleaction.h"
21 
22 class QTableWidget;
23 class QTableWidgetItem;
24 class CASingleAction;
25 class QSettings;
26 class QLineEdit;
27 class QPushButton;
28 
29 class CAActionsEditor : public QWidget
30 {
31  Q_OBJECT
32 
33 public:
34 
35  // Definition of file type
36  enum fileType
37  {
38  //FT_COMPLETE = 0, // All together like when stored in settings
39  FT_SHORTCUT = 1, // Keyboard shortcut
40  FT_MIDI = 2, // Midi command
41  FT_MIDISCUT = 3 // Requires Midi and Shortcut at one time to be used
42  };
43 
44  // Constructor
45  // Parameters are standard QWidget parameters
46  CAActionsEditor( QWidget * parent = 0, Qt::WindowFlags f = 0 );
47  // Destructor
49 
50  // Clear the actionlist
51  void clear();
52 
53  // There are no actions yet?
54  bool isEmpty();
55 
56  // See QWidget documentation
57  void addActions(const QList<CASingleAction *> &actionList);
58 
59  // Static functions
60  static CASingleAction * findAction(QWidget *widget, const QString & name);
61  static QStringList actionsNames(QWidget *widget);
62 
63  static void saveToConfig(QWidget *widget, QSettings *set);
64  static void loadFromConfig(QWidget *widget, QSettings *set);
65 
66 //#if USE_MULTIPLE_SHORTCUTS
67 // static QString shortcutsToString(QList <QKeySequence> shortcuts_list);
68 // static QList <QKeySequence> stringToShortcuts(QString shortcuts);
69 //#endif
70 
71 public slots:
72  // save changes from editing (shortcut or midi command)
73  void applyChanges();
74  // Get file type from suffix
75  enum fileType getFType(const QString &suffix);
76  // save action profile (shortcuts or midi commands) separately to disc
77  void saveActionsTable();
78  bool saveActionsTable(const QString & filename, enum fileType type = FT_SHORTCUT);
79  // load action profile (shortcuts or midi commands) separately from disc
80  void loadActionsTable();
81  bool loadActionsTable(const QString & filename, enum fileType type = FT_SHORTCUT);
82 
83  // Add all actions to the table widget
84  void updateView();
85 
86 protected:
87  // Translate strings dynamically
88  // Adapts save buttons according to column focus
89  virtual void retranslateStrings();
90  virtual void changeEvent ( QEvent * event ) ;
91 
92  // Find in table, not in actionslist (command, shortcut or midi)
93  int findActionCommand(const QString & name);
94  int findActionAccel(const QString & accel, int ignoreRow = -1);
95  int findActionMidi(const QString & midi, int ignoreRow = -1);
96  // Check for Conflicts of shortcut or midi command
97  bool hasConflicts(bool bMidi = false);
98 
99 protected slots:
100 //#if !USE_SHORTCUTGETTER
101  // Start recording (save current Text)
102  void recordAction(QTableWidgetItem*);
103  // Easy check of edited shortcut / midi command
104  void validateAction(QTableWidgetItem*);
105 //#else
106  void editShortcut();
107 //#endif
108 
109 private:
110  QTableWidget *actionsTable;
111  QList<CASingleAction *> m_actionsList;
112  QPushButton *saveButton;
113  QPushButton *loadButton;
114  QString latest_dir;
115 
116 //#if USE_SHORTCUTGETTER
117  QPushButton *editButton;
118 //#else
119  QString oldAccelText;
120  QString oldMidiText;
121  bool dont_validate; // Lock validate during update
122 //#endif
123 };
124 
125 class ShortcutGetter : public QDialog
126 {
127  Q_OBJECT
128 
129 public:
130  ShortcutGetter(QWidget *parent = 0);
131 
132  QString exec(const QString& s);
133 
134 protected slots:
135  void setCaptureKeyboard(bool b);
136 
137 protected:
138  bool captureKeyboard() { return capture; }
139 
140  bool event(QEvent *e);
141  bool eventFilter(QObject *o, QEvent *e);
142  void setText();
143 
144 private:
145  bool bStop;
147  QStringList lKeys;
148  bool capture;
149 };
150 
151 
152 #endif
QString exec(const QString &s)
Definition: actionseditor.cpp:788
virtual void changeEvent(QEvent *event)
Definition: actionseditor.cpp:698
enum fileType getFType(const QString &suffix)
Definition: actionseditor.cpp:302
bool hasConflicts(bool bMidi=false)
Definition: actionseditor.cpp:413
static CASingleAction * findAction(QWidget *widget, const QString &name)
Definition: actionseditor.cpp:661
void updateView()
Definition: actionseditor.cpp:209
bool isEmpty()
Definition: actionseditor.cpp:182
void setText()
Definition: actionseditor.cpp:873
void editShortcut()
Definition: actionseditor.cpp:368
ShortcutGetter(QWidget *parent=0)
Definition: actionseditor.cpp:738
virtual void retranslateStrings()
Definition: actionseditor.cpp:165
bool event(QEvent *e)
Definition: actionseditor.cpp:799
void addActions(const QList< CASingleAction * > &actionList)
Definition: actionseditor.cpp:190
bool capture
Definition: actionseditor.h:148
bool eventFilter(QObject *o, QEvent *e)
Definition: actionseditor.cpp:862
QPushButton * saveButton
Definition: actionseditor.h:112
static void saveToConfig(QWidget *widget, QSettings *set)
Definition: actionseditor.cpp:598
void loadActionsTable()
Definition: actionseditor.cpp:509
QStringList lKeys
Definition: actionseditor.h:147
Definition: actionseditor.h:40
CAActionsEditor(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: actionseditor.cpp:98
Definition: actionseditor.h:125
void applyChanges()
Definition: actionseditor.cpp:285
QString latest_dir
Definition: actionseditor.h:114
int findActionCommand(const QString &name)
Definition: actionseditor.cpp:382
static void loadFromConfig(QWidget *widget, QSettings *set)
Definition: actionseditor.cpp:628
~CAActionsEditor()
Definition: actionseditor.cpp:162
QTableWidget * actionsTable
Definition: actionseditor.h:110
static QStringList actionsNames(QWidget *widget)
Definition: actionseditor.cpp:676
QString oldMidiText
Definition: actionseditor.h:120
int findActionMidi(const QString &midi, int ignoreRow=-1)
Definition: actionseditor.cpp:401
Definition: actionseditor.h:29
QList< CASingleAction * > m_actionsList
Definition: actionseditor.h:111
QPushButton * editButton
Definition: actionseditor.h:117
void recordAction(QTableWidgetItem *)
Definition: actionseditor.cpp:315
fileType
Definition: actionseditor.h:36
bool dont_validate
Definition: actionseditor.h:121
void saveActionsTable()
Definition: actionseditor.cpp:441
bool captureKeyboard()
Definition: actionseditor.h:138
bool bStop
Definition: actionseditor.h:145
int findActionAccel(const QString &accel, int ignoreRow=-1)
Definition: actionseditor.cpp:389
Definition: actionseditor.h:39
Definition: actionseditor.h:41
QPushButton * loadButton
Definition: actionseditor.h:113
QLineEdit * leKey
Definition: actionseditor.h:146
void clear()
Definition: actionseditor.cpp:186
void validateAction(QTableWidgetItem *)
Definition: actionseditor.cpp:328
void setCaptureKeyboard(bool b)
Definition: actionseditor.cpp:781
QString oldAccelText
Definition: actionseditor.h:119
Definition: singleaction.h:18