kexi

kexiformeventhandler.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexiformeventhandler.h"
00021 
00022 #include <qwidget.h>
00023 #include <qobjectlist.h>
00024 
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027 #include <kaction.h>
00028 
00029 #include <tableview/kexitableitem.h>
00030 #include <tableview/kexitableviewdata.h>
00031 #include <kexidb/queryschema.h>
00032 #include <keximainwindow.h>
00033 #include <kexidialogbase.h>
00034 #include <kexipart.h>
00035 //#include <kexipartitem.h>
00036 
00037 class KexiFormEventScriptAction : public KAction
00038 {
00039 private:
00040     QString m_scripturi;
00041 public:
00042     KexiFormEventScriptAction(QObject* parent, const QString& scripturi)
00043         : KAction(parent), m_scripturi(scripturi) {}
00044 public slots:
00045     void activate() {
00046         KexiPart::Part* scriptpart = Kexi::partManager().partForMimeType("kexi/script");
00047         if(scriptpart) {
00048             //KAction* action = scriptpart->action(m_scriptaction);
00049             //if(action) action->activate();
00050             scriptpart->action(m_scripturi);
00051         }
00052     }
00053 };
00054 
00055 KexiFormEventHandler::KexiFormEventHandler()
00056  : m_mainWidget(0)
00057 {
00058 }
00059 
00060 KexiFormEventHandler::~KexiFormEventHandler()
00061 {
00062 }
00063 
00064 void KexiFormEventHandler::setMainWidgetForEventHandling(KexiMainWindow *mainWin, QWidget* mainWidget)
00065 {
00066     m_mainWidget = mainWidget;
00067     if (!m_mainWidget)
00068         return;
00069 
00070     //find widgets whose will work as data items
00072     QObjectList *l = m_mainWidget->queryList( "KexiPushButton" );
00073     QObjectListIt it( *l );
00074     QObject *obj;
00075     QDict<char> tmpSources;
00076     for ( ; (obj = it.current()) != 0; ++it ) {
00077         QString actionName = obj->property("onClickAction").toString();
00078         if(actionName.isEmpty())
00079             continue;
00080 
00081         if (actionName.startsWith("kaction:")) {
00082             actionName = actionName.mid(QString("kaction:").length()); //cut prefix
00083             KAction *action = mainWin->actionCollection()->action( actionName.latin1() );
00084             if (!action)
00085                 continue;
00086             QObject::disconnect( obj, SIGNAL(clicked()), action, SLOT(activate()) ); //safety
00087             QObject::connect( obj, SIGNAL(clicked()), action, SLOT(activate()) );
00088         }
00089         else if (actionName.startsWith("script:")) {
00090             actionName = actionName.mid(QString("script:").length()); //cut prefix
00091             KexiFormEventScriptAction* action = new KexiFormEventScriptAction(obj, actionName);
00092             QObject::disconnect( obj, SIGNAL(clicked()), action, SLOT(activate()) );
00093             QObject::connect( obj, SIGNAL(clicked()), action, SLOT(activate()) );
00094         }
00095     }
00096     delete l;
00097 }
00098 
KDE Home | KDE Accessibility Home | Description of Access Keys