itom 1.3.0
|
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 00099 private: 00100 struct cmdQueueStruct 00101 { 00102 cmdQueueStruct() { singleLine = ""; m_lineBegin = -1; m_nrOfLines = 1; } 00103 cmdQueueStruct(QString text, int lineBegin, int nrOfLines) {singleLine = text; m_lineBegin = lineBegin; m_nrOfLines = nrOfLines; } 00104 QString singleLine; 00105 int m_lineBegin; 00106 int m_nrOfLines; 00107 }; 00108 00109 RetVal initEditor(); 00110 RetVal clearEditor(); 00111 RetVal startNewCommand(bool clearEditorFirst = false); 00112 RetVal execCommand(int lineBegin, int lineEnd); 00113 RetVal useCmdListCommand(int dir); 00114 00115 RetVal executeCmdQueue(); 00116 00117 RetVal moveCursorToEnd(); 00118 00119 RetVal moveCursorToValidRegion(); 00120 00121 int checkValidDropRegion(const QPoint &pos); 00122 00123 int startLineBeginCmd; 00124 00125 DequeCommandList *cmdList; 00126 00127 std::queue<cmdQueueStruct> cmdQueue; 00128 00129 bool canCopy; 00130 bool canCut; 00131 00132 QDebugStream *qout; 00133 QDebugStream *qerr; 00134 00135 unsigned int markErrorLine; 00136 unsigned int markCurrentLine; 00137 00138 bool waitForCmdExecutionDone; 00139 bool pythonBusy; 00140 00141 QString temporaryRemovedCommands; 00142 00143 static const QString lineBreak; 00144 00145 }; 00146 00147 class DequeCommandList 00148 { 00149 public: 00150 DequeCommandList(int maxLength); 00151 ~DequeCommandList(); 00152 00153 RetVal add(QString cmd); 00154 RetVal moveLast(); 00155 QString getPrevious(); 00156 QString getNext(); 00157 00158 private: 00159 int maxItems; 00160 std::deque<QString> cmdList; 00161 std::deque<QString>::reverse_iterator rit; 00162 }; 00163 00164 } //end namespace ito 00165 00166 #endif