itom 2.0.0
D:/git-itom/sources/itom/Qitom/widgets/consoleWidget.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2013, Institut für Technische Optik (ITO),
00005     Universität Stuttgart, Germany
00006 
00007     This file is part of itom.
00008   
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013 
00014     itom is distributed in the hope that it will be useful, but
00015     WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00017     General Public Licence for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with itom. If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************** */
00022 
00023 #ifndef CONSOLEWIDGET_H
00024 #define CONSOLEWIDGET_H
00025 
00026 #include <queue>
00027 
00028 #include "../common/sharedStructures.h"
00029 #include "../python/qDebugStream.h"
00030 
00031 #include "abstractPyScintillaWidget.h"
00032 
00037 //#define QSCINTILLA_DLL  //http://www.riverbankcomputing.com/pipermail/qscintilla/2007-March/000034.html
00038 //
00039 //#include <Qsci/qsciscintilla.h>
00040 //#include <Qsci/qscilexerpython.h>
00041 //#include <Qsci/qsciapis.h>
00042 #include <QKeyEvent>
00043 #include <QDropEvent>
00044 #include <qstring.h>
00045 #include <qstringlist.h>
00046 #include <qdebug.h>
00047 #include <qsettings.h>
00048 
00049 QT_BEGIN_NAMESPACE
00050 
00051 QT_END_NAMESPACE
00052 
00053 namespace ito
00054 {
00055 
00056 class DequeCommandList;
00057 
00058 class ConsoleWidget : public AbstractPyScintillaWidget
00059 {
00060     Q_OBJECT
00061 
00062 
00063 public:
00064 
00065     ConsoleWidget(QWidget* parent = NULL);
00066     ~ConsoleWidget();
00067     
00068     RetVal printMessage(QStringList msg, ito::tMsgType type = msgTextInfo);
00069     RetVal printMessage(QString msg, ito::tMsgType type = msgTextInfo);
00070 
00071 protected:
00072     virtual void loadSettings();
00073     void autoAdaptLineNumberColumnWidth();
00074 
00075 public slots:
00076     virtual void copy();
00077     virtual void paste();
00078     virtual void cut();
00079     void receiveStream(QString text, tMsgType msgType);
00080     void pythonRunSelection(QString selectionText);
00081     void pythonStateChanged(tPythonTransitions pyTransition);
00082     void clearCommandLine();
00083 
00084 signals:
00085     void wantToCopy();
00086     void pythonExecuteString(QString cmd);
00087     void sendToLastCommand(QString cmd);
00088 
00089 
00090 protected:
00091     void keyPressEvent (QKeyEvent *event);
00092     void dropEvent (QDropEvent *event);
00093     void dragEnterEvent (QDragEnterEvent *event);
00094     void dragMoveEvent (QDragMoveEvent *event);
00095 
00096 private slots:
00097     void selChanged(); 
00098     void textDoubleClicked(int position, int line, int modifiers);
00099 
00100 private:
00101     struct cmdQueueStruct
00102     { 
00103         cmdQueueStruct() { singleLine = ""; m_lineBegin = -1; m_nrOfLines = 1; }
00104         cmdQueueStruct(QString text, int lineBegin, int nrOfLines) {singleLine = text; m_lineBegin = lineBegin; m_nrOfLines = nrOfLines; }
00105         QString singleLine;
00106         int m_lineBegin;
00107         int m_nrOfLines;
00108     };
00109 
00110     RetVal initEditor();
00111     RetVal clearEditor();
00112     RetVal startNewCommand(bool clearEditorFirst = false);
00113     RetVal execCommand(int lineBegin, int lineEnd);
00114     RetVal useCmdListCommand(int dir);
00115 
00116     RetVal executeCmdQueue();
00117 
00118     RetVal moveCursorToEnd();
00119 
00120     RetVal moveCursorToValidRegion();
00121 
00122     int checkValidDropRegion(const QPoint &pos);
00123     
00124     int startLineBeginCmd; 
00125     
00126     DequeCommandList *cmdList; 
00127 
00128     std::queue<cmdQueueStruct> cmdQueue; 
00129 
00130     bool canCopy;
00131     bool canCut;
00132 
00133     QDebugStream *qout;
00134     QDebugStream *qerr;
00135 
00136     unsigned int markErrorLine;
00137     unsigned int markCurrentLine;
00138 
00139     bool waitForCmdExecutionDone; 
00140     bool pythonBusy; 
00141 
00142     QString temporaryRemovedCommands; 
00143 
00144     static const QString lineBreak;
00145 
00146 };
00147 
00148 class DequeCommandList
00149 {
00150 public:
00151     DequeCommandList(int maxLength);
00152     ~DequeCommandList();
00153 
00154     RetVal add(QString cmd);
00155     RetVal moveLast();
00156     QString getPrevious();
00157     QString getNext();
00158 
00159 private:
00160     int maxItems;
00161     std::deque<QString> cmdList;
00162     std::deque<QString>::reverse_iterator rit;
00163 };
00164 
00165 } //end namespace ito
00166 
00167 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends