![]() |
TinkerCell Core 1.0
TinkerCell's Core library providing all basic functionalities
|
00001 /**************************************************************************** 00002 This file is a combination of two example programs included in the Qt Toolkit. 00003 A few modifications have been added, but the majority of the code is from Qt's 00004 demo programs 00005 ****************************************************************************/ 00006 #ifndef QT_MODIEIFED_DEMO_COMPLETER_AND_CODEEDITOR_H 00007 #define QT_MODIEIFED_DEMO_COMPLETER_AND_CODEEDITOR_H 00008 00009 #include <QPlainTextEdit> 00010 #include <QDialog> 00011 #include <QLineEdit> 00012 #include <QCompleter> 00013 #include <QKeyEvent> 00014 #include <QAbstractItemView> 00015 00016 class QPaintEvent; 00017 class QResizeEvent; 00018 class QSize; 00019 class QWidget; 00020 00021 #ifndef TINKERCELLCOREEXPORT 00022 #ifdef Q_WS_WIN 00023 # if defined(TC_EXPORTS) || defined(TinkerCellCore_EXPORTS) 00024 # define TINKERCELLCOREEXPORT __declspec(dllexport) 00025 # else 00026 # define TINKERCELLCOREEXPORT __declspec(dllimport) 00027 # endif 00028 #else 00029 # define TINKERCELLCOREEXPORT 00030 #endif 00031 #endif 00032 00033 namespace Tinkercell 00034 { 00035 00036 class LineNumberArea; 00037 00038 class TINKERCELLCOREEXPORT CodeEditor : public QPlainTextEdit 00039 { 00040 Q_OBJECT 00041 00042 public: 00043 CodeEditor(QWidget *parent = 0); 00044 00045 void lineNumberAreaPaintEvent(QPaintEvent *event); 00046 int lineNumberAreaWidth(); 00047 00048 void setCompleter(QCompleter *c); 00049 QCompleter *completer() const; 00050 00051 void zoomIn(int r = 1); 00052 void zoomOut(int r = 1); 00053 QString text() const; 00054 00055 QWidget *lineNumberArea; 00056 00057 QColor lineHighlightColor; 00058 QColor lineNumberBackground; 00059 QColor lineNumberText; 00060 00061 public slots: 00062 void setText(const QString&); 00063 void showFindReplaceDialog(); 00064 bool find(const QString&); 00065 bool replace(const QString&,const QString&); 00066 00067 protected: 00068 void resizeEvent(QResizeEvent *event); 00069 virtual void wheelEvent ( QWheelEvent * wheelEvent ); 00070 void keyPressEvent(QKeyEvent *e); 00071 void focusInEvent(QFocusEvent *e); 00072 00073 private slots: 00074 void updateLineNumberAreaWidth(int newBlockCount); 00075 void highlightCurrentLine(); 00076 void updateLineNumberArea(const QRect &, int); 00077 void insertCompletion(const QString &completion); 00078 void find(); 00079 void replace(); 00080 00081 private: 00082 QString textUnderCursor() const; 00083 QDialog * findReplaceDialog; 00084 QLineEdit * findLineEdit; 00085 QLineEdit * replaceLineEdit; 00086 QCompleter *c; 00087 00088 }; 00089 00090 00091 class TINKERCELLCOREEXPORT LineNumberArea : public QWidget 00092 { 00093 public: 00094 00095 LineNumberArea(CodeEditor *editor) : QWidget(editor) 00096 { 00097 codeEditor = editor; 00098 } 00099 00100 QSize sizeHint() const 00101 { 00102 return QSize(codeEditor->lineNumberAreaWidth(), 0); 00103 } 00104 00105 protected: 00106 void paintEvent(QPaintEvent *event) { 00107 codeEditor->lineNumberAreaPaintEvent(event); 00108 } 00109 00110 private: 00111 CodeEditor * codeEditor; 00112 }; 00113 00114 } 00115 00116 #endif 00117