itom 2.2.1
K:/git-itom/sources/itom/Qitom/widgets/consoleWidget.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2016, Institut fuer Technische Optik (ITO),
00005     Universitaet 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 "common/sharedStructuresQt.h"
00030 #include "../python/qDebugStream.h"
00031 #include "../global.h"
00032 
00033 #include "abstractPyScintillaWidget.h"
00034 
00035 #include <QKeyEvent>
00036 #include <QDropEvent>
00037 #include <qevent.h>
00038 #include <qstring.h>
00039 #include <qstringlist.h>
00040 #include <qdebug.h>
00041 #include <qsettings.h>
00042 
00043 QT_BEGIN_NAMESPACE
00044 
00045 QT_END_NAMESPACE
00046 
00047 namespace ito
00048 {
00049 
00050 class DequeCommandList;
00051 
00052 class ConsoleWidget : public AbstractPyScintillaWidget
00053 {
00054     Q_OBJECT
00055 
00056 public:
00057     ConsoleWidget(QWidget* parent = NULL);
00058     ~ConsoleWidget();
00059 
00060     static const QString lineBreak;
00061 
00062 protected:
00063     virtual void loadSettings();
00064     void autoAdaptLineNumberColumnWidth();
00065 
00066 public slots:
00067     virtual void copy();
00068     virtual void paste();
00069     virtual void cut();
00070     void receiveStream(QString text, ito::QDebugStream::MsgStreamType msgType);
00071     void pythonRunSelection(QString selectionText);
00072     void pythonStateChanged(tPythonTransitions pyTransition);
00073     void clearCommandLine();
00074     void startInputCommandLine(QSharedPointer<QByteArray> buffer, ItomSharedSemaphore *inputWaitCond);
00075 
00076 signals:
00077     void wantToCopy();
00078     void pythonExecuteString(QString cmd);
00079     void sendToLastCommand(QString cmd);
00080 
00081 
00082 protected:
00083     void keyPressEvent (QKeyEvent *event);
00084     void dropEvent (QDropEvent *event);
00085     void dragEnterEvent (QDragEnterEvent *event);
00086     void dragMoveEvent (QDragMoveEvent *event);
00087     void wheelEvent(QWheelEvent *event);
00088     void contextMenuEvent(QContextMenuEvent *event);
00089     bool canInsertFromMimeData(const QMimeData *source) const;
00090 
00091 private slots:
00092     void selChanged(); 
00093     void textDoubleClicked(int position, int line, int modifiers);
00094     void clearAndStartNewCommand();
00095 
00096 private:
00097     struct cmdQueueStruct
00098     { 
00099         cmdQueueStruct() { singleLine = ""; m_lineBegin = -1; m_nrOfLines = 1; }
00100         cmdQueueStruct(QString text, int lineBegin, int nrOfLines) {singleLine = text; m_lineBegin = lineBegin; m_nrOfLines = nrOfLines; }
00101         QString singleLine;
00102         int m_lineBegin;
00103         int m_nrOfLines;
00104     };
00105 
00106     RetVal initEditor();
00107     RetVal clearEditor();
00108     RetVal startNewCommand(bool clearEditorFirst = false);
00109     RetVal execCommand(int lineBegin, int lineEnd);
00110     RetVal useCmdListCommand(int dir);
00111 
00112     RetVal executeCmdQueue();
00113 
00114     void moveCursorToEnd();
00115     void moveCursorToValidRegion();
00116 
00117     int checkValidDropRegion(const QPoint &pos);
00118     
00119     int m_startLineBeginCmd; 
00120     
00121     DequeCommandList *m_pCmdList; 
00122 
00123     std::queue<cmdQueueStruct> m_cmdQueue; 
00124 
00125     bool m_canCopy;
00126     bool m_canCut;
00127 
00128     QDebugStream *m_pQout;
00129     QDebugStream *m_pQerr;
00130 
00131     unsigned int m_markErrorLine;
00132     unsigned int m_markCurrentLine;
00133     unsigned int m_markInputLine;
00134 
00135     bool m_waitForCmdExecutionDone; 
00136     bool m_pythonBusy; 
00137 
00138     QString m_temporaryRemovedCommands; 
00139 
00140     ItomSharedSemaphore *m_inputStreamWaitCond; 
00141     QSharedPointer<QByteArray> m_inputStreamBuffer;
00142     int m_inputStartLine;
00143     int m_inputStartCol;
00144     bool m_autoWheel; 
00145 };
00146 
00147 class DequeCommandList
00148 {
00149 public:
00150     DequeCommandList(int maxLength);
00151     ~DequeCommandList();
00152 
00153     RetVal add(const QString &cmd);
00154     RetVal moveLast();
00155     QString getPrevious();
00156     QString getNext();
00157 
00158 private:
00159     int m_maxItems;
00160     std::deque<QString> m_cmdList;
00161     std::deque<QString>::reverse_iterator m_rit;
00162 };
00163 
00164 } //end namespace ito
00165 
00166 #endif
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Friends