Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/tool.h
00001 /**********************************************************************
00002   Tool - Avogadro Tool Interface
00003 
00004   Copyright (C) 2007 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 TOOL_H
00026 #define TOOL_H
00027 
00028 #include <avogadro/global.h>
00029 #include "plugin.h"
00030 
00031 #include <QSettings>
00032 #include <QtPlugin>
00033 #include <QWheelEvent>
00034 
00035 #define AVOGADRO_TOOL(i, t, d, s)                            \
00036   public: \
00037     static QString staticIdentifier() { return i; }          \
00038     QString identifier() const { return i; }                 \
00039     static QString staticName() { return t; }                \
00040     QString name() const { return t; }                       \
00041     static QString staticDescription() { return d; }         \
00042     QString description() const { return d; }                \
00043     QString settingsTitle() const { return s; }
00044 
00045 #define AVOGADRO_TOOL_FACTORY(c)                             \
00046   public: \
00047     Avogadro::Plugin *createInstance(QObject *parent = 0) { return new c(parent); } \
00048     Avogadro::Plugin::Type type() const { return Avogadro::Plugin::ToolType; } \
00049     QString identifier() const { return c::staticIdentifier(); } \
00050     QString name() const { return c::staticName(); }         \
00051     QString description() const { return c::staticDescription(); }
00052 
00053 class QAction;
00054 class QUndoCommand;
00055 class QWidget;
00056 
00057 namespace Avogadro {
00058 
00059   class GLWidget;
00060   class Molecule;
00061 
00071   class ToolPrivate;
00072   class A_EXPORT Tool : public Plugin
00073   {
00074     Q_OBJECT
00075 
00076     public:
00080       Tool(QObject *parent = 0);
00081 
00085       virtual ~Tool();
00086 
00090       Plugin::Type type() const;
00091 
00095       QString typeName() const;
00096 
00100       virtual QAction* activateAction() const;
00101 
00105       virtual QWidget* settingsWidget();
00106 
00110       virtual QString settingsTitle() const = 0;
00111 
00117       virtual QUndoCommand* mousePressEvent(GLWidget *widget, QMouseEvent *event) = 0;
00118 
00124       virtual QUndoCommand* mouseReleaseEvent(GLWidget *widget, QMouseEvent *event) = 0;
00125 
00131       virtual QUndoCommand* mouseMoveEvent(GLWidget *widget, QMouseEvent *event) = 0;
00132 
00139       virtual QUndoCommand* mouseDoubleClickEvent(GLWidget *widget, QMouseEvent *event) = 0;
00140 
00146       virtual QUndoCommand* wheelEvent(GLWidget *widget, QWheelEvent *event);
00147 
00153       virtual QUndoCommand* keyPressEvent(GLWidget *widget, QKeyEvent *event);
00154 
00160       virtual QUndoCommand* keyReleaseEvent(GLWidget *widget, QKeyEvent *event);
00161 
00167       virtual bool paint(GLWidget *widget);
00168 
00175       virtual int usefulness() const;
00176 
00177       bool operator<(const Tool &other) const;
00178 
00182       virtual void writeSettings(QSettings &settings) const;
00183 
00187       virtual void readSettings(QSettings &settings);
00188 
00189     Q_SIGNALS:
00194       void message(const QString &m);
00195 
00196     public Q_SLOTS:
00201       virtual void setMolecule(Molecule *molecule);
00202 
00203     protected:
00204       QAction *m_activateAction;
00205       ToolPrivate *const d;
00206   };
00207 
00208 } // end namespace Avogadro
00209 
00210 #endif