Warning, file /office/calligra/libs/kross/KoScriptingDocker.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /*************************************************************************** 0002 * KoScriptingDocker.cpp 0003 * This file is part of the KDE project 0004 * copyright (C) 2006-2007 Sebastian Sauer <mail@dipe.org> 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this program; see the file COPYING. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 ***************************************************************************/ 0021 0022 #include "KoScriptingDocker.h" 0023 0024 #include "KoScriptingModule.h" 0025 #include "KoScriptManager.h" 0026 #include "KoKrossDebug.h" 0027 0028 #include <KoIcon.h> 0029 0030 #include <QToolBar> 0031 #include <QBoxLayout> 0032 0033 #include <klocalizedstring.h> 0034 #include <kactioncollection.h> 0035 0036 #include <kross/core/action.h> 0037 #include <kross/ui/model.h> 0038 #include <kross/ui/view.h> 0039 0040 /*********************************************************************** 0041 * KoScriptingDockerFactory 0042 */ 0043 0044 KoScriptingDockerFactory::KoScriptingDockerFactory(QWidget *parent, KoScriptingModule *module, Kross::Action *action) 0045 : KoDockFactoryBase(), 0046 m_parent(parent), 0047 m_module(module), 0048 m_action(action) 0049 { 0050 } 0051 0052 QString KoScriptingDockerFactory::id() const 0053 { 0054 return m_action ? m_action->name() : "Scripting"; 0055 } 0056 0057 KoDockFactoryBase::DockPosition KoScriptingDockerFactory::defaultDockPosition() const 0058 { 0059 return DockMinimized; 0060 } 0061 0062 QDockWidget *KoScriptingDockerFactory::createDockWidget() 0063 { 0064 QDockWidget *dw = 0; 0065 if (m_action) 0066 dw = new KoScriptingActionDocker(m_module, m_action, m_parent); 0067 else 0068 dw = new KoScriptingDocker(m_parent); 0069 dw->setObjectName(id()); 0070 return dw; 0071 } 0072 0073 /*********************************************************************** 0074 * KoScriptingDocker 0075 */ 0076 0077 KoScriptingDocker::KoScriptingDocker(QWidget *parent) 0078 : QDockWidget(i18n("Scripts"), parent) 0079 { 0080 QWidget *widget = new QWidget(this); 0081 QBoxLayout *layout = new QVBoxLayout(widget); 0082 layout->setMargin(0); 0083 widget->setLayout(layout); 0084 0085 m_view = new Kross::ActionCollectionView(widget); 0086 m_view->setRootIsDecorated(false); 0087 0088 //Kross::ActionCollectionModel::Mode modelmode = Kross::ActionCollectionModel::Mode(Kross::ActionCollectionModel::ToolTips); 0089 //d->model = new Kross::ActionCollectionProxyModel(this, new Kross::ActionCollectionModel(this, 0, modelmode)); 0090 Kross::ActionCollectionProxyModel *model = new Kross::ActionCollectionProxyModel(this); 0091 0092 m_view->setModel(model); 0093 layout->addWidget(m_view, 1); 0094 m_view->expandAll(); 0095 0096 QToolBar *tb = new QToolBar(widget); 0097 layout->addWidget(tb); 0098 tb->setMovable(false); 0099 //tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 0100 0101 KActionCollection *collection = m_view->actionCollection(); 0102 if (QAction *a = collection->action("run")) { 0103 a = tb->addAction(a->icon(), a->text(), a, SLOT(trigger())); 0104 a->setEnabled(false); 0105 m_actions.insert("run", a); 0106 } 0107 if (QAction *a = collection->action("stop")) { 0108 a = tb->addAction(a->icon(), a->text(), a, SLOT(trigger())); 0109 a->setEnabled(false); 0110 m_actions.insert("stop", a); 0111 } 0112 0113 tb->addAction(koIcon("configure"), i18n("Script Manager"), this, SLOT(slotShowScriptManager())); 0114 0115 /* 0116 d->tb->addSeparator(); 0117 QLineEdit *filter = new QLineEdit(tb); 0118 d->tb->addWidget(filter); 0119 connect(filter, SIGNAL(textChanged(QString)), model, SLOT(setFilterRegExp(QString))); 0120 */ 0121 0122 setWidget(widget); 0123 0124 connect(m_view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotDoubleClicked())); 0125 connect(m_view, SIGNAL(enabledChanged(QString)), this, SLOT(slotEnabledChanged(QString))); 0126 } 0127 0128 void KoScriptingDocker::slotShowScriptManager() 0129 { 0130 KoScriptManagerDialog *dialog = new KoScriptManagerDialog(); 0131 dialog->exec(); 0132 dialog->delayedDestruct(); 0133 } 0134 0135 void KoScriptingDocker::slotEnabledChanged(const QString &actionname) 0136 { 0137 if (m_actions.contains(actionname)) 0138 if (QAction *a = m_view->actionCollection()->action(actionname)) 0139 m_actions[actionname]->setEnabled(a->isEnabled()); 0140 } 0141 0142 void KoScriptingDocker::slotDoubleClicked() 0143 { 0144 //debugKoKross<<"KoScriptingDocker::slotDoubleClicked()"; 0145 m_view->slotRun(); 0146 } 0147 0148 /*********************************************************************** 0149 * KoScriptingDocker 0150 */ 0151 0152 KoScriptingActionDocker::KoScriptingActionDocker(KoScriptingModule *module, Kross::Action *action, QWidget *parent) 0153 : QDockWidget(action->text(), parent), 0154 m_module(module), 0155 m_action(action) 0156 { 0157 debugKoKross; 0158 m_action->addObject(this, "KoDocker", Kross::ChildrenInterface::AutoConnectSignals); 0159 //connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(slotVisibilityChanged(bool))); 0160 } 0161 0162 KoScriptingActionDocker::~KoScriptingActionDocker() 0163 { 0164 debugKoKross; 0165 m_action->finalize(); 0166 } 0167 0168 void KoScriptingActionDocker::slotVisibilityChanged(bool visible) 0169 { 0170 debugKoKross<<"visible="<<visible; 0171 if (visible) { 0172 if (m_module && m_action->isFinalized()) { 0173 //KoView *view = m_module->view(); 0174 //KoMainWindow *mainwindow = view ? view->mainWindow() : 0; 0175 m_action->trigger(); 0176 } 0177 } else { 0178 //m_action->finalize(); 0179 } 0180 } 0181 0182 QWidget *KoScriptingActionDocker::widget() 0183 { 0184 return QDockWidget::widget(); 0185 } 0186 0187 void KoScriptingActionDocker::setWidget(QWidget *widget) 0188 { 0189 QDockWidget::setWidget(widget); 0190 }