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 SCRIPTEDITORWIDGET_H 00024 #define SCRIPTEDITORWIDGET_H 00025 00026 #include "../models/breakPointModel.h" 00027 00028 #include "abstractPyScintillaWidget.h" 00029 00030 #include <qfilesystemwatcher.h> 00031 #include <qmutex.h> 00032 #include <qwidget.h> 00033 #include <qstring.h> 00034 #include <qmenu.h> 00035 #include <qevent.h> 00036 #include <qmetaobject.h> 00037 00038 #if QT_VERSION >= 0x050000 00039 #include <QtPrintSupport/qprinter.h> 00040 #else 00041 #include <qprinter.h> 00042 #endif 00043 00044 #include <Qsci/qsciprinter.h> 00045 00046 QT_BEGIN_NAMESPACE 00047 00048 QT_END_NAMESPACE 00049 00050 00051 00052 namespace ito 00053 { 00054 00055 struct ScriptEditorStorage 00056 { 00057 QByteArray filename; 00058 int firstVisibleLine; 00059 QList<int> bookmarkLines; 00060 }; 00061 00062 } 00063 00064 Q_DECLARE_METATYPE(ito::ScriptEditorStorage) //must be outside of namespace 00065 Q_DECLARE_METATYPE(QList<ito::ScriptEditorStorage>) //must be outside of namespace 00066 00067 namespace ito 00068 { 00069 00070 class ScriptEditorWidget : public AbstractPyScintillaWidget 00071 { 00072 Q_OBJECT 00073 00074 public: 00075 ScriptEditorWidget(QWidget* parent = NULL); 00076 ~ScriptEditorWidget(); 00077 00078 RetVal saveFile(bool askFirst = true); 00079 RetVal saveAsFile(bool askFirst = true); 00080 00081 RetVal openFile(QString file, bool ignorePresentDocument = false); 00082 00083 inline QString getFilename() const {return m_filename; } 00084 inline bool hasNoFilename() const { return m_filename.isNull(); } 00085 inline bool getCanCopy() const { return canCopy; } 00086 inline bool isBookmarked() const { return !bookmarkErrorHandles.empty(); } 00087 inline QString getUntitledName() const { return tr("Untitled%1").arg(unnamedNumber); } 00088 00089 RetVal setCursorPosAndEnsureVisible(int line); 00090 00091 const ScriptEditorStorage saveState() const; 00092 RetVal restoreState(const ScriptEditorStorage &data); 00093 00094 protected: 00095 //void keyPressEvent (QKeyEvent *event); 00096 bool canInsertFromMimeData(const QMimeData *source) const; 00097 void autoAdaptLineNumberColumnWidth(); 00098 // void dragEnterEvent(QDragEnterEvent *event); 00099 void dropEvent(QDropEvent *event); 00100 virtual void loadSettings(); 00101 bool event (QEvent * event); 00102 00103 private: 00104 enum msgType 00105 { 00106 msgReturnInfo, 00107 msgReturnWarning, 00108 msgReturnError, 00109 msgTextInfo, 00110 msgTextWarning, 00111 msgTextError 00112 }; 00113 00114 enum markerType 00115 { 00116 markerBookmark = 1, 00117 markerPyBug = 2, 00118 markerBookmarkAndPyBug = markerBookmark | markerPyBug 00119 }; 00120 00121 RetVal initEditor(); 00122 00123 void contextMenuEvent (QContextMenuEvent * event); 00124 00125 int getMarginNumber(int xPos); 00126 00127 RetVal initMenus(); 00128 00129 RetVal toggleBookmark(int line); 00130 RetVal clearAllBookmarks(); 00131 RetVal gotoNextBookmark(); 00132 RetVal gotoPreviousBookmark(); 00133 00134 RetVal toggleBreakpoint(int line); 00135 RetVal toggleEnableBreakpoint(int line); 00136 RetVal editBreakpoint(int line); 00137 RetVal clearAllBreakpoints(); 00138 RetVal gotoNextBreakPoint(); 00139 RetVal gotoPreviousBreakPoint(); 00140 00141 bool lineAcceptsBPs(int line); 00142 00143 RetVal changeFilename(const QString &newFilename); 00144 00145 QFileSystemWatcher *m_pFileSysWatcher; 00146 QMutex fileSystemWatcherMutex; 00147 00149 struct BookmarkErrorEntry 00150 { 00151 int handle; 00152 int type; 00153 QString errorMessage; 00154 QString errorComment; 00155 int errorPos; 00156 }; 00157 QList<BookmarkErrorEntry> bookmarkErrorHandles; 00158 int syntaxErrorHandle; 00159 00160 bool m_syntaxCheckerEnabled; 00161 int m_syntaxCheckerIntervall; 00162 QTimer *m_syntaxTimer; 00163 int m_lastTipLine; 00164 00165 struct BPMarker 00166 { 00167 int bpHandle; 00168 int lineNo; 00169 bool markedForDeletion; 00170 }; 00171 00172 QList<BPMarker> m_breakPointMap; 00173 00174 unsigned int markBreakPoint; 00175 unsigned int markCBreakPoint; 00176 unsigned int markBreakPointDisabled; 00177 unsigned int markCBreakPointDisabled; 00178 unsigned int markBookmark; 00179 unsigned int markSyntaxError; 00180 unsigned int markBookmarkSyntaxError; 00181 00182 unsigned int markCurrentLine; 00183 int markCurrentLineHandle; 00184 00185 unsigned int markMask1; 00186 unsigned int markMask2; 00187 unsigned int markMaskBreakpoints; 00188 00189 //QsciLexerPython* qSciLex; 00190 //QsciAPIs* qSciApi; 00191 00193 QMenu *bookmarkMenu; 00194 QMenu *syntaxErrorMenu; 00195 QMenu *breakpointMenu; 00196 QMenu *editorMenu; 00197 00198 std::map<QString,QAction*> bookmarkMenuActions; 00199 std::map<QString,QAction*> breakpointMenuActions; 00200 std::map<QString,QAction*> editorMenuActions; 00201 00202 int contextMenuLine; 00203 00204 QString m_filename; 00205 int unnamedNumber; 00206 00207 bool pythonBusy; 00208 bool m_pythonExecutable; 00209 00210 bool canCopy; 00211 00212 static const QString lineBreak; 00213 static int unnamedAutoIncrement; 00214 00215 signals: 00216 void pythonRunFile(QString filename); 00217 void pythonRunSelection(QString selectionText); 00218 void pythonDebugFile(QString filename); 00219 void closeRequest(ScriptEditorWidget* sew, bool ignoreModifications); //signal emitted if this tab should be closed without considering any save-state 00220 void marginChanged(); 00221 00222 public slots: 00223 void menuToggleBookmark(); 00224 void checkSyntax(); 00225 void syntaxCheckResult(QString a, QString b); 00226 void errorListChange(const QStringList &errorList); 00227 void menuClearAllBookmarks(); 00228 void menuGotoNextBookmark(); 00229 void menuGotoPreviousBookmark(); 00230 00231 void menuToggleBreakpoint(); 00232 void menuToggleEnableBreakpoint(); 00233 void menuEditBreakpoint(); 00234 void menuClearAllBreakpoints(); 00235 void menuGotoNextBreakPoint(); 00236 void menuGotoPreviousBreakPoint(); 00237 00238 void menuCut(); 00239 void menuCopy(); 00240 void menuPaste(); 00241 void menuIndent(); 00242 void menuUnindent(); 00243 void menuComment(); 00244 void menuUncomment(); 00245 00246 void menuRunScript(); 00247 void menuRunSelection(); 00248 void menuDebugScript(); 00249 void menuStopScript(); 00250 00251 void pythonStateChanged(tPythonTransitions pyTransition); 00252 void pythonDebugPositionChanged(QString filename, int lineno); 00253 00254 void breakPointAdd(BreakPointItem bp, int row); 00255 void breakPointDelete(QString filename, int lineNo, int pyBpNumber); 00256 void breakPointChange(BreakPointItem oldBp, BreakPointItem newBp); 00257 00258 void updateSyntaxCheck(); 00259 00260 void print(); 00261 00262 00263 private slots: 00264 void marginClicked(int margin, int line, Qt::KeyboardModifiers state); 00265 void copyAvailable(bool yes); 00266 00267 void nrOfLinesChanged(); 00268 00269 RetVal preShowContextMenuMargin(); 00270 RetVal preShowContextMenuEditor(); 00271 00272 void fileSysWatcherFileChanged ( const QString & path ); 00273 void printPreviewRequested(QPrinter *printer); 00274 }; 00275 00276 00277 class ItomQsciPrinter : public QsciPrinter 00278 { 00279 public: 00280 ItomQsciPrinter(QPrinter::PrinterMode mode=QPrinter::ScreenResolution) : QsciPrinter(mode) {} 00281 virtual void formatPage( QPainter &painter, bool drawing, QRect &area, int pagenr ); 00282 }; 00283 00284 } //end namespace ito 00285 00286 #endif