QCodeEdit  2.2
lib/qeditorinputbinding.h
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
00004 **
00005 ** This file is part of the Edyuk project <http://edyuk.org>
00006 ** 
00007 ** This file may be used under the terms of the GNU General Public License
00008 ** version 3 as published by the Free Software Foundation and appearing in the
00009 ** file GPL.txt included in the packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ****************************************************************************/
00015 
00016 #ifndef _QEDITOR_INPUT_BINDING_H_
00017 #define _QEDITOR_INPUT_BINDING_H_
00018 
00019 #include "qeditorinputbindinginterface.h"
00020 
00021 #include "qdocumentcursor.h"
00022 
00023 #include <QList>
00024 #include <QVector>
00025 #include <QString>
00026 #include <QKeySequence>
00027 
00028 class QCE_EXPORT QEditorInputBinding : public QEditorInputBindingInterface
00029 {
00030     public:
00031         class Command
00032         {
00033             public:
00034                 virtual ~Command() {}
00035                 
00036                 virtual void exec(QEditor *e) = 0;
00037         };
00038         
00039         class MotionCommand : public Command
00040         {
00041             public:
00042                 MotionCommand(QDocumentCursor::MoveOperation op, QDocumentCursor::MoveMode m, int n = 1);
00043                 
00044                 virtual void exec(QEditor *e);
00045                 
00046             private:
00047                 int count;
00048                 QDocumentCursor::MoveMode mode;
00049                 QDocumentCursor::MoveOperation operation;
00050         };
00051         
00052         class EditCommand : public Command
00053         {
00054             public:
00055                 enum Operation
00056                 {
00057                     ClearSelection,
00058                     SelectWord,
00059                     SelectLine,
00060                     SelectDocument,
00061                     
00062                     DeleteChar,
00063                     DeletePreviousChar,
00064                     DeleteSelection,
00065                     DeleteLine,
00066                     
00067                     InsertLine,
00068                     InsertClipBoard,
00069                 };
00070                 
00071                 EditCommand(Operation op);
00072                 
00073                 virtual void exec(QEditor *e);
00074                 
00075             private:
00076                 Operation operation;
00077         };
00078         
00079         class WriteCommand : public Command
00080         {
00081             public:
00082                 WriteCommand(const QString& t);
00083                 
00084                 virtual void exec(QEditor *e);
00085                 
00086             private:
00087                 QString text;
00088         };
00089         
00090         class GroupCommand : public Command
00091         {
00092             public:
00093                 void addCommand(Command *c);
00094                 
00095                 virtual void exec(QEditor *e);
00096                 
00097             private:
00098                 QList<Command*> commands;
00099         };
00100         
00101         QEditorInputBinding();
00102         ~QEditorInputBinding();
00103         
00104         void setMapping(const QKeySequence& ks, Command *cmd);
00105         
00106         virtual bool isExclusive() const;
00107         
00108         virtual bool keyPressEvent(QKeyEvent *event, QEditor *editor);
00109         virtual void postKeyPressEvent(QKeyEvent *event, QEditor *editor);
00110         
00111         virtual bool inputMethodEvent(QInputMethodEvent* event, QEditor *editor);
00112         virtual void postInputMethodEvent(QInputMethodEvent *event, QEditor *editor);
00113         
00114         virtual bool mouseMoveEvent(QMouseEvent *event, QEditor *editor);
00115         virtual void postMouseMoveEvent(QMouseEvent *event, QEditor *editor);
00116         
00117         virtual bool mousePressEvent(QMouseEvent *event, QEditor *editor);
00118         virtual void postMousePressEvent(QMouseEvent *event, QEditor *editor);
00119         
00120         virtual bool mouseReleaseEvent(QMouseEvent *event, QEditor *editor);
00121         virtual void postMouseReleaseEvent(QMouseEvent *event, QEditor *editor);
00122         
00123         virtual bool mouseDoubleClickEvent(QMouseEvent *event, QEditor *editor);
00124         virtual void postMouseDoubleClickEvent(QMouseEvent *event, QEditor *editor);
00125         
00126         virtual bool contextMenuEvent(QContextMenuEvent *event, QEditor *editor);
00127         
00128     private:
00129         QVector<int> m_index;
00130         QVector<Command*> m_actions;
00131         QVector<QKeySequence> m_keys;
00132 };
00133 
00134 #endif // _QEDITOR_INPUT_BINDING_H_