Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/extension.h
00001 /**********************************************************************
00002   Extension - Extension Class Interface
00003 
00004   Copyright (C) 2007-2008 Donald Ephraim Curtis
00005 
00006   This file is part of the Avogadro molecular editor project.
00007   For more information, see <http://avogadro.openmolecules.net/>
00008 
00009   Avogadro is free software; you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation; either version 2 of the License, or
00012   (at your option) any later version.
00013 
00014   Avogadro is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with this program; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00022   02110-1301, USA.
00023  **********************************************************************/
00024 
00025 #ifndef EXTENSION_H
00026 #define EXTENSION_H
00027 
00028 #include "plugin.h"
00029 
00030 #include <QVector>
00031 #include <QSettings>
00032 #include <QtPlugin>
00033 
00034 #define AVOGADRO_EXTENSION(i, t, d)          \
00035   public: \
00036     static QString staticIdentifier() { return i; }          \
00037     QString identifier() const { return i; }                 \
00038     static QString staticName() { return t; }                \
00039     QString name() const { return t; }                       \
00040     static QString staticDescription() { return d; }         \
00041     QString description() const { return d; }
00042 
00043 #define AVOGADRO_EXTENSION_FACTORY(c)     \
00044   public: \
00045     Avogadro::Plugin *createInstance(QObject *parent = 0) { return new c(parent); } \
00046     Avogadro::Plugin::Type type() const { return Avogadro::Plugin::ExtensionType; } \
00047     QString identifier() const { return c::staticIdentifier(); } \
00048     QString name() const { return c::staticName(); }         \
00049     QString description() const { return c::staticDescription(); }
00050 
00051 class QDockWidget;
00052 class QUndoCommand;
00053 class QTextEdit;
00054 class QAction;
00055 
00056 namespace Avogadro {
00057 
00058   class DockWidget;
00059   class GLWidget;
00060   class Molecule;
00061 
00084   class A_EXPORT Extension : public Plugin
00085   {
00086 
00087   Q_OBJECT
00088 
00089   public:
00093     Extension(QObject *parent = 0);
00094 
00098     virtual ~Extension();
00099 
00113     enum MoleculeChangedHint
00114     {
00115       KeepOld   = 0x00, 
00116       DeleteOld = 0x01, 
00117       NewWindow = 0x02 
00118     };
00119 
00123     Plugin::Type type() const;
00124 
00128     QString typeName() const;
00129 
00133     virtual QList<QAction *> actions() const = 0;
00134 
00138     virtual QString menuPath(QAction *action) const;
00139 
00143     virtual bool usesNetwork(QAction *action) const;
00144 
00152     virtual QDockWidget * dockWidget();
00153 
00157     virtual QList<DockWidget*> dockWidgets() const;
00158 
00162     virtual int numDockWidgets() const;
00163 
00170     virtual QUndoCommand* performAction(QAction *action, GLWidget *widget) = 0;
00171 
00176     virtual void writeSettings(QSettings &settings) const;
00177 
00182     virtual void readSettings(QSettings &settings);
00183 
00190     virtual int usefulness() const;
00191 
00192   public Q_SLOTS:
00197     virtual void setMolecule(Molecule *molecule);
00198 
00199   Q_SIGNALS:
00204     void message(const QString &m);
00208     void actionsChanged(Extension*);
00209 
00215     void moleculeChanged(Molecule *, int);
00216     
00223     void performCommand(QUndoCommand*);
00224 
00225   protected:
00230     QList<DockWidget*> m_dockWidgets;
00231   };
00232 
00233 } // end namespace Avogadro
00234 
00235 #endif