SpeedCrunch  0.11
/usr/src/RPM/BUILD/speedcrunch-0.11/src/gui/editor.h
Go to the documentation of this file.
00001 // This file is part of the SpeedCrunch project
00002 // Copyright (C) 2004, 2005, 2007 Ariya Hidayat <ariya@kde.org>
00003 // Copyright (C) 2007-2009, 2013, 2014 Helder Correia <helder.pereira.correia@gmail.com>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; see the file COPYING.  If not, write to
00017 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018 // Boston, MA 02110-1301, USA.
00019 
00020 #ifndef GUI_EDITOR_H
00021 #define GUI_EDITOR_H
00022 
00023 #include <QPlainTextEdit>
00024 
00025 struct Constant;
00026 class ConstantCompletion;
00027 class EditorCompletion;
00028 class Evaluator;
00029 class HNumber;
00030 class SyntaxHighlighter;
00031 
00032 class QEvent;
00033 class QKeyEvent;
00034 class QMimeData;
00035 class QTimeLine;
00036 class QTreeWidget;
00037 class QWheelEvent;
00038 class QWidget;
00039 
00040 class Editor : public QPlainTextEdit {
00041     Q_OBJECT
00042 
00043 public:
00044     explicit Editor(QWidget* parent = 0);
00045 
00046     bool isAutoCalcEnabled() const;
00047     bool isAutoCompletionEnabled() const;
00048     void clearHistory();
00049     int cursorPosition() const;
00050     void doBackspace();
00051     QStringList history() const;
00052     QStringList historyResults() const;
00053     char radixChar() const;
00054     void setAnsAvailable(bool);
00055     void setAutoCalcEnabled(bool);
00056     void setAutoCompletionEnabled(bool);
00057     void setCursorPosition(int pos);
00058     void setText(const QString&);
00059     void setHistory(const QStringList&);
00060     void setHistoryResults(const QStringList&);
00061     QSize sizeHint() const;
00062     void stopAutoCalc();
00063     void stopAutoComplete();
00064     QString text() const;
00065 
00066 signals:
00067     void autoCalcEnabled(const QString&);
00068     void autoCalcDisabled();
00069     void controlPageDownPressed();
00070     void controlPageUpPressed();
00071     void copySequencePressed();
00072     void pageDownPressed();
00073     void pageUpPressed();
00074     void returnPressed();
00075     void shiftDownPressed();
00076     void shiftUpPressed();
00077     void shiftPageDownPressed();
00078     void shiftPageUpPressed();
00079 
00080 public slots:
00081     void appendHistory(const QString& result, const QString& expression);
00082     void appendHistory(const QStringList& expressions, const QStringList& results);
00083     void cancelConstantCompletion();
00084     void evaluate();
00085     void decreaseFontPointSize();
00086     void increaseFontPointSize();
00087     void insert(const QString&);
00088     void insertConstant(const QString&);
00089     void rehighlight();
00090 
00091 protected slots:
00092     virtual void insertFromMimeData(const QMimeData*);
00093     void autoCalc();
00094     void autoCalcSelection();
00095     void autoComplete(const QString&);
00096     void checkAutoCalc();
00097     void checkAutoComplete();
00098     void checkMatching();
00099     void doMatchingLeft();
00100     void doMatchingPar();
00101     void doMatchingRight();
00102     void historyBack();
00103     void historyForward();
00104     void startSelAutoCalcTimer();
00105     void triggerAutoComplete();
00106     void triggerEnter();
00107 
00108 protected:
00109     virtual void changeEvent(QEvent*);
00110     virtual void focusOutEvent(QFocusEvent*);
00111     virtual void keyPressEvent(QKeyEvent*);
00112     virtual void paintEvent(QPaintEvent*);
00113     virtual void wheelEvent(QWheelEvent*);
00114 
00115 private:
00116     Q_DISABLE_COPY(Editor)
00117 
00118     bool m_isAnsAvailable;
00119     bool m_isAutoCalcEnabled;
00120     QTimer* m_autoCalcSelTimer;
00121     QTimer* m_autoCalcTimer;
00122     bool m_isAutoCompletionEnabled;
00123     EditorCompletion* m_completion;
00124     QTimer* m_completionTimer;
00125     ConstantCompletion* m_constantCompletion;
00126     Evaluator* m_evaluator;
00127     SyntaxHighlighter* m_highlighter;
00128     QStringList m_history;
00129     QStringList m_historyResults;
00130     QString m_savedCurrentEditor;
00131     int m_currentHistoryIndex;
00132     QTimer* m_matchingTimer;
00133     bool m_shouldPaintCustomCursor;
00134 };
00135 
00136 class EditorCompletion : public QObject {
00137     Q_OBJECT
00138 
00139 public:
00140     EditorCompletion(Editor*);
00141     ~EditorCompletion();
00142 
00143     bool eventFilter(QObject*, QEvent*);
00144     void showCompletion(const QStringList&);
00145 
00146 signals:
00147     void selectedCompletion(const QString&);
00148 
00149 public slots:
00150     void doneCompletion();
00151     void selectItem(const QString&);
00152 
00153 private:
00154     Q_DISABLE_COPY(EditorCompletion)
00155 
00156     Editor* m_editor;
00157     QTreeWidget* m_popup;
00158 };
00159 
00160 class ConstantCompletion : public QObject {
00161     Q_OBJECT
00162 
00163 public:
00164     ConstantCompletion(Editor*);
00165     ~ConstantCompletion();
00166 
00167     bool eventFilter(QObject*, QEvent*);
00168     void showCompletion();
00169 
00170 signals:
00171     void canceledCompletion();
00172     void selectedCompletion(const QString&);
00173 
00174 public slots:
00175     void doneCompletion();
00176 
00177 protected slots:
00178     void setHorizontalPosition(int);
00179     void showCategory();
00180     void showConstants();
00181 
00182 private:
00183     Q_DISABLE_COPY(ConstantCompletion)
00184 
00185     QTreeWidget* m_categoryWidget;
00186     QList<Constant> m_constantList;
00187     Editor* m_editor;
00188     QString m_lastCategory;
00189     QTreeWidget* m_constantWidget;
00190     QFrame* m_popup;
00191     QTimeLine* m_slider;
00192 };
00193 
00194 #endif