itom 1.0.14
|
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 <qprinter.h> 00037 #include <qsciprinter.h> 00038 00039 QT_BEGIN_NAMESPACE 00040 00041 QT_END_NAMESPACE 00042 00043 namespace ito 00044 { 00045 00046 class ScriptEditorWidget : public AbstractPyScintillaWidget 00047 { 00048 Q_OBJECT 00049 00050 00051 public: 00052 ScriptEditorWidget(QWidget* parent = NULL); 00053 ~ScriptEditorWidget(); 00054 00055 RetVal saveFile(bool askFirst = true); 00056 RetVal saveAsFile(bool askFirst = true); 00057 00058 RetVal openFile(QString file, bool ignorePresentDocument = false); 00059 00060 inline QString getFilename() const {return filename; } 00061 inline bool hasNoFilename() const { return filename.isNull(); } 00062 inline bool getCanCopy() const { return canCopy; } 00063 inline bool isBookmarked() const { return bookmarkHandles.size() > 0; } 00064 inline QString getUntitledName() const { return tr("Untitled%1").arg(unnamedNumber); } 00065 00066 RetVal setCursorPosAndEnsureVisible(int line); 00067 00068 protected: 00069 //void keyPressEvent (QKeyEvent *event); 00070 bool canInsertFromMimeData(const QMimeData *source) const; 00071 // void dragEnterEvent(QDragEnterEvent *event); 00072 void dropEvent(QDropEvent *event); 00073 00074 virtual void loadSettings(); 00075 00076 private: 00077 enum msgType 00078 { 00079 msgReturnInfo, 00080 msgReturnWarning, 00081 msgReturnError, 00082 msgTextInfo, 00083 msgTextWarning, 00084 msgTextError 00085 }; 00086 00087 RetVal initEditor(); 00088 00089 void contextMenuEvent (QContextMenuEvent * event); 00090 00091 int getMarginNumber(int xPos); 00092 00093 RetVal initMenus(); 00094 00095 RetVal toggleBookmark(int line); 00096 RetVal clearAllBookmarks(); 00097 RetVal gotoNextBookmark(); 00098 RetVal gotoPreviousBookmark(); 00099 00100 RetVal toggleBreakpoint(int line); 00101 RetVal toggleEnableBreakpoint(int line); 00102 RetVal editBreakpoint(int line); 00103 RetVal clearAllBreakpoints(); 00104 RetVal gotoNextBreakPoint(); 00105 RetVal gotoPreviousBreakPoint(); 00106 00107 RetVal changeFilename(QString newFilename); 00108 00109 QFileSystemWatcher *m_pFileSysWatcher; 00110 QMutex fileSystemWatcherMutex; 00111 00113 std::list<int> bookmarkHandles; 00114 int syntaxErrorHandle; 00115 00116 std::list<QPair<int,int> > breakPointMap; 00117 00118 unsigned int markBreakPoint; 00119 unsigned int markCBreakPoint; 00120 unsigned int markBreakPointDisabled; 00121 unsigned int markCBreakPointDisabled; 00122 unsigned int markBookmark; 00123 unsigned int markSyntaxError; 00124 00125 unsigned int markCurrentLine; 00126 int markCurrentLineHandle; 00127 00128 unsigned int markMask1; 00129 unsigned int markMask2; 00130 unsigned int markMaskBreakpoints; 00131 00132 //QsciLexerPython* qSciLex; 00133 //QsciAPIs* qSciApi; 00134 00136 QMenu *bookmarkMenu; 00137 QMenu *syntaxErrorMenu; 00138 QMenu *breakpointMenu; 00139 QMenu *editorMenu; 00140 00141 std::map<QString,QAction*> bookmarkMenuActions; 00142 std::map<QString,QAction*> breakpointMenuActions; 00143 std::map<QString,QAction*> editorMenuActions; 00144 00145 int contextMenuLine; 00146 00147 QString filename; 00148 int unnamedNumber; 00149 00150 bool pythonBusy; 00151 00152 bool canCopy; 00153 00154 static const QString lineBreak; 00155 static int unnamedAutoIncrement; 00156 00157 signals: 00158 void pythonRunFile(QString filename); 00159 void pythonRunSelection(QString selectionText); 00160 void pythonDebugFile(QString filename); 00161 void closeRequest(ScriptEditorWidget* sew, bool ignoreModifications); //signal emitted if this tab should be closed without considering any save-state 00162 void marginChanged(); 00163 00164 public slots: 00165 void menuToggleBookmark(); 00166 void menuClearAllBookmarks(); 00167 void menuGotoNextBookmark(); 00168 void menuGotoPreviousBookmark(); 00169 00170 void menuToggleBreakpoint(); 00171 void menuToggleEnableBreakpoint(); 00172 void menuEditBreakpoint(); 00173 void menuClearAllBreakpoints(); 00174 void menuGotoNextBreakPoint(); 00175 void menuGotoPreviousBreakPoint(); 00176 00177 void menuCut(); 00178 void menuCopy(); 00179 void menuPaste(); 00180 void menuIndent(); 00181 void menuUnindent(); 00182 void menuComment(); 00183 void menuUncomment(); 00184 00185 void menuRunScript(); 00186 void menuRunSelection(); 00187 void menuDebugScript(); 00188 void menuStopScript(); 00189 00190 void pythonStateChanged(tPythonTransitions pyTransition); 00191 void pythonDebugPositionChanged(QString filename, int lineno); 00192 00193 void breakPointAdd(BreakPointItem bp, int row); 00194 void breakPointDelete(QString filename, int lineNo, int pyBpNumber); 00195 void breakPointChange(BreakPointItem oldBp, BreakPointItem newBp); 00196 00197 void print(); 00198 00199 00200 private slots: 00201 void marginClicked(int margin, int line, Qt::KeyboardModifiers state); 00202 void copyAvailable(bool yes); 00203 00204 void nrOfLinesChanged(); 00205 00206 RetVal preShowContextMenuMargin(); 00207 RetVal preShowContextMenuEditor(); 00208 00209 void fileSysWatcherFileChanged ( const QString & path ); 00210 void printPreviewRequested(QPrinter *printer); 00211 }; 00212 00213 00214 class ItomQsciPrinter : public QsciPrinter 00215 { 00216 public: 00217 ItomQsciPrinter(QPrinter::PrinterMode mode=QPrinter::ScreenResolution) : QsciPrinter(mode) {} 00218 virtual void formatPage( QPainter &painter, bool drawing, QRect &area, int pagenr ); 00219 }; 00220 00221 } //end namespace ito 00222 00223 #endif