| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
|
|---|
| 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 "toolbareditor.h"
|
|---|
| 20 |
|
|---|
| 21 | #include <QToolBar>
|
|---|
| 22 | #include <QToolButton>
|
|---|
| 23 |
|
|---|
| 24 | QStringList ToolbarEditor::save(QWidget * w) {
|
|---|
| 25 | qDebug("ToolbarEditor::save: '%s'", w->objectName().toUtf8().data());
|
|---|
| 26 |
|
|---|
| 27 | QList<QAction *> list = w->actions();
|
|---|
| 28 | QStringList o;
|
|---|
| 29 | QAction * action;
|
|---|
| 30 |
|
|---|
| 31 | for (int n = 0; n < list.count(); n++) {
|
|---|
| 32 | action = static_cast<QAction*> (list[n]);
|
|---|
| 33 | if (action->isSeparator()) {
|
|---|
| 34 | o << "separator";
|
|---|
| 35 | }
|
|---|
| 36 | else
|
|---|
| 37 | if (!action->objectName().isEmpty()) {
|
|---|
| 38 | o << action->objectName();
|
|---|
| 39 | }
|
|---|
| 40 | else
|
|---|
| 41 | qWarning("ToolbarEditor::save: unknown action at pos %d", n);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | return o;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void ToolbarEditor::load(QWidget *w, QStringList l, QList<QAction *> actions_list)
|
|---|
| 48 | {
|
|---|
| 49 | qDebug("ToolbarEditor::load: '%s'", w->objectName().toUtf8().data());
|
|---|
| 50 |
|
|---|
| 51 | QAction * action;
|
|---|
| 52 |
|
|---|
| 53 | for (int n = 0; n < l.count(); n++) {
|
|---|
| 54 | qDebug("ToolbarEditor::load: loading action %s", l[n].toUtf8().data());
|
|---|
| 55 |
|
|---|
| 56 | if (l[n] == "separator") {
|
|---|
| 57 | qDebug("ToolbarEditor::load: adding separator");
|
|---|
| 58 | QAction * sep = new QAction(w);
|
|---|
| 59 | sep->setSeparator(true);
|
|---|
| 60 | w->addAction(sep);
|
|---|
| 61 | } else {
|
|---|
| 62 | action = findAction(l[n], actions_list);
|
|---|
| 63 | if (action) {
|
|---|
| 64 | w->addAction(action);
|
|---|
| 65 | if (action->objectName().endsWith("_menu")) {
|
|---|
| 66 | // If the action is a menu and is in a toolbar, as a toolbutton, change some of its properties
|
|---|
| 67 | QToolBar * toolbar = qobject_cast<QToolBar *>(w);
|
|---|
| 68 | if (toolbar) {
|
|---|
| 69 | QToolButton * button = qobject_cast<QToolButton *>(toolbar->widgetForAction(action));
|
|---|
| 70 | if (button) {
|
|---|
| 71 | //qDebug("ToolbarEditor::load: action %s is a toolbutton", action->objectName().toUtf8().constData());
|
|---|
| 72 | button->setPopupMode(QToolButton::InstantPopup);
|
|---|
| 73 | //button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | } else {
|
|---|
| 78 | qWarning("ToolbarEditor::load: action %s not found", l[n].toUtf8().data());
|
|---|
| 79 | }
|
|---|
| 80 | }
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | QAction * ToolbarEditor::findAction(QString s, QList<QAction *> actions_list) {
|
|---|
| 85 | QAction * action;
|
|---|
| 86 |
|
|---|
| 87 | for (int n = 0; n < actions_list.count(); n++) {
|
|---|
| 88 | action = static_cast<QAction*> (actions_list[n]);
|
|---|
| 89 | if (action->objectName() == s) return action;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | return 0;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|