1
/* smplayer, GUI front-end for mplayer.
2
Copyright (C) 2007 Ricardo Villalba <rvm@escomposlinux.org>
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.
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.
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
19
/* This is based on qq14-actioneditor-code.zip from Qt */
2
22
#include "actionseditor.h"
24
#if QT_VERSION < 0x040000
25
#define USE_KEYCHOOSER 1
27
#define USE_KEYCHOOSER 0
4
32
#include <qlayout.h>
5
33
#include <qobjectlist.h>
6
34
#include <qpushbutton.h>
18
46
#include "filedialog.h"
20
48
#include "helper.h"
52
#include "keychooser.h"
54
#include <qlineedit.h>
58
class ShortcutItem : public QTableItem
61
ShortcutItem( QTable * table, const QString & text );
63
virtual int alignment () const;
64
virtual QWidget * createEditor () const;
67
ShortcutItem::ShortcutItem( QTable * table, const QString & text )
69
: QTableItem(table, QTableItem::WhenCurrent, text)
71
: QTableItem(table, QTableItem::OnTyping, text)
76
QWidget * ShortcutItem::createEditor () const {
78
KeyChooser * key_chooser = new KeyChooser( table()->viewport() );
79
key_chooser->setText( text() );
82
QLineEdit * edit = new QLineEdit( table()->viewport() );
83
edit->setText( text() );
88
int ShortcutItem::alignment() const {
89
//return Qt::AlignHCenter;
23
94
#define COL_CONFLICTS 0
28
class MyTable : public QTable
31
MyTable( int numRows, int numCols, QWidget * parent = 0, const char * name = 0 );
32
virtual QSize sizeHint () const;
35
MyTable::MyTable(int numRows, int numCols, QWidget * parent, const char * name)
36
: QTable(numRows, numCols, parent, name)
40
QSize MyTable::sizeHint() const {
41
return QSize(100,100);
44
99
ActionsEditor::ActionsEditor(QWidget * parent, const char * name, WFlags f)
45
100
: QWidget(parent, name, f)
47
102
latest_dir = Helper::shortcutsPath();
49
104
actionsTable = new MyTable(0, COL_NAME +1, this);
105
actionsTable->setSizeHint(QSize(100,100));
51
//actionsTable->setColumnReadOnly(COL_ICON, true);
52
107
actionsTable->setColumnReadOnly(COL_NAME, true);
53
108
actionsTable->setColumnReadOnly(COL_DESC, true);
54
109
actionsTable->setColumnReadOnly(COL_CONFLICTS, true);
125
174
action = static_cast<QACTION*>(actions->first());
128
actionsList.append(action);
177
if (!action->inherits("QActionGroup"))
178
actionsList.append(action);
129
179
action = static_cast<QAction*>(actions->next());
132
182
QList<Q3Action *> actions = widget->findChildren<Q3Action *>();
133
183
for (int n=0; n < actions.count(); n++) {
134
184
action = static_cast<QACTION*> (actions[n]);
135
actionsList.append(action);
185
if (!action->inherits("Q3ActionGroup"))
186
actionsList.append(action);
143
194
actionsTable->setNumRows( actionsList.count() );
146
199
for (int n=0; n < actionsList.count(); n++) {
147
200
action = static_cast<QACTION*> (actionsList[n]);
148
201
QPixmap p = action->iconSet().pixmap();
149
202
if (!p.isNull()) p = Images::resize(&p, 16);
203
accelText = QString(action->accel());
150
204
actionsTable->setPixmap(n, COL_DESC, p );
151
205
actionsTable->setText(n, COL_NAME, action->name());
152
206
actionsTable->setText(n, COL_DESC, action->text());
153
actionsTable->setText(n, COL_SHORTCUT, QString(action->accel()));
207
//actionsTable->setText(n, COL_SHORTCUT, QString(action->accel()));
208
actionsTable->setItem( n, COL_SHORTCUT,
209
new ShortcutItem(actionsTable, accelText) );
156
//actionsTable->adjustColumn( COL_ICON );
211
hasConflicts(); // Check for conflicts
157
213
actionsTable->adjustColumn( COL_NAME );
158
214
actionsTable->adjustColumn( COL_DESC );
159
215
actionsTable->adjustColumn( COL_CONFLICTS );
190
246
item->setText(accelText);
197
QACTION * ActionsEditor::findAction(const QString & name) {
200
for (int n=0; n < actionsList.count(); n++) {
201
action = static_cast<QACTION*> (actionsList[n]);
202
if (name == action->name()) return action;
248
if (hasConflicts()) qApp->beep();
208
254
int ActionsEditor::findActionName(const QString & name) {
209
255
for (int row=0; row < actionsTable->numRows(); row++) {
247
if (conflict) qApp->beep();
250
void ActionsEditor::saveToConfig(QObject *o, QSettings *set) {
251
qDebug("ActionsEditor::saveToConfig");
253
set->beginGroup("actions");
256
#if QT_VERSION < 0x040000
257
QObjectList *actions = o->queryList("QAction");
258
action = static_cast<QACTION*>(actions->first());
261
QString accelText = QString(action->accel());
262
set->writeEntry(action->name(), accelText);
263
action = static_cast<QAction*>(actions->next());
266
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
267
for (int n=0; n < actions.count(); n++) {
268
action = static_cast<QACTION*> (actions[n]);
269
QString accelText = QString(action->accel());
270
set->writeEntry(action->name(), accelText);
278
void ActionsEditor::loadFromConfig(QObject *o, QSettings *set) {
279
qDebug("ActionsEditor::loadFromConfig");
281
set->beginGroup("actions");
286
#if QT_VERSION < 0x040000
287
QObjectList *actions = o->queryList("QAction");
288
action = static_cast<QACTION*>(actions->first());
291
accelText = set->readEntry(action->name(), action->accel());
292
action->setAccel(QKeySequence(accelText));
293
action = static_cast<QAction*>(actions->next());
296
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
297
for (int n=0; n < actions.count(); n++) {
298
action = static_cast<QACTION*> (actions[n]);
299
accelText = set->readEntry(action->name(), action->accel());
300
action->setAccel(QKeySequence(accelText));
307
bool ActionsEditor::saveActionsTable() {
292
//if (conflict) qApp->beep();
297
void ActionsEditor::saveActionsTable() {
308
298
QString s = MyFileDialog::getSaveFileName(
310
300
tr("Key files") +" (*.keys)",
327
317
QMessageBox::NoButton);
328
318
if (res == QMessageBox::No ) {
332
322
latest_dir = QFileInfo(s).dirPath(TRUE);
333
return saveActionsTable(s);
323
bool r = saveActionsTable(s);
325
QMessageBox::warning(this, tr("Error"),
326
tr("The file couldn't be saved"),
327
QMessageBox::Ok, QMessageBox::NoButton);
339
332
bool ActionsEditor::saveActionsTable(const QString & filename) {
365
358
if (!s.isEmpty()) {
366
359
latest_dir = QFileInfo(s).dirPath(TRUE);
367
return loadActionsTable(s);
360
bool r = loadActionsTable(s);
362
QMessageBox::warning(this, tr("Error"),
363
tr("The file couldn't be loaded"),
364
QMessageBox::Ok, QMessageBox::NoButton);
372
369
bool ActionsEditor::loadActionsTable(const QString & filename) {
398
hasConflicts(); // Check for conflicts
408
void ActionsEditor::saveToConfig(QObject *o, QSettings *set) {
409
qDebug("ActionsEditor::saveToConfig");
411
set->beginGroup("actions");
414
#if QT_VERSION < 0x040000
415
QObjectList *actions = o->queryList("QAction");
416
action = static_cast<QACTION*>(actions->first());
419
QString accelText = QString(action->accel());
420
set->writeEntry(action->name(), accelText);
421
action = static_cast<QAction*>(actions->next());
424
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
425
for (int n=0; n < actions.count(); n++) {
426
action = static_cast<QACTION*> (actions[n]);
427
QString accelText = QString(action->accel());
428
set->writeEntry(action->name(), accelText);
436
void ActionsEditor::loadFromConfig(QObject *o, QSettings *set) {
437
qDebug("ActionsEditor::loadFromConfig");
439
set->beginGroup("actions");
444
#if QT_VERSION < 0x040000
445
QObjectList *actions = o->queryList("QAction");
446
action = static_cast<QACTION*>(actions->first());
449
accelText = set->readEntry(action->name(), action->accel());
450
action->setAccel(QKeySequence(accelText));
451
action = static_cast<QAction*>(actions->next());
454
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
455
for (int n=0; n < actions.count(); n++) {
456
action = static_cast<QACTION*> (actions[n]);
457
accelText = set->readEntry(action->name(), action->accel());
458
action->setAccel(QKeySequence(accelText));
465
QACTION * ActionsEditor::findAction(QObject *o, const QString & name) {
468
#if QT_VERSION < 0x040000
469
QObjectList *actions = o->queryList("QAction");
470
action = static_cast<QACTION*>(actions->first());
473
if (name == action->name()) return action;
474
action = static_cast<QAction*>(actions->next());
477
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
478
for (int n=0; n < actions.count(); n++) {
479
action = static_cast<QACTION*> (actions[n]);
480
if (name == action->objectName()) return action;
487
QStringList ActionsEditor::actionsNames(QObject *o) {
492
#if QT_VERSION < 0x040000
493
QObjectList *actions = o->queryList("QAction");
494
action = static_cast<QACTION*>(actions->first());
497
l.append( action->name() );
498
action = static_cast<QAction*>(actions->next());
501
QList<Q3Action *> actions = o->findChildren<Q3Action *>();
502
for (int n=0; n < actions.count(); n++) {
503
action = static_cast<QACTION*> (actions[n]);
504
l.append( action->name() );