Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / sc-ide / widgets / editor_box.hpp
blobc7a25593f6698cd1e75126f03177d63b27f5668e
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef SCIDE_WIDGET_CODE_EDITOR_EDITOR_BOX_HPP
23 #define SCIDE_WIDGET_CODE_EDITOR_EDITOR_BOX_HPP
25 #include <QWidget>
26 #include <QStackedLayout>
27 #include <QPointer>
29 namespace ScIDE {
31 class Document;
32 class ScCodeEditor;
34 class CodeEditorBox : public QWidget
36 Q_OBJECT
38 public:
39 typedef QList< ScCodeEditor * > History;
41 CodeEditorBox(QWidget *parent = 0);
43 void setDocument(Document *, int pos = -1, int selectionLength = 0);
45 ScCodeEditor *currentEditor();
46 Document *currentDocument();
48 const History & history() { return mHistory; }
50 void setActive() {
51 if (isActive())
52 return;
54 CodeEditorBox *lastActiveBox = gActiveBox;
55 gActiveBox = this;
57 if (lastActiveBox)
58 lastActiveBox->update();
60 update();
62 emit activated(this);
65 bool isActive() { return gActiveBox == this; }
67 QSize minimumSizeHint() const { return QSize(100, 100); }
68 QSize sizeHint() const { return QSize(100, 100); }
70 signals:
71 void currentChanged(ScCodeEditor*);
72 void activated( CodeEditorBox *me );
74 private slots:
75 void onDocumentClosed(Document*);
77 private:
78 int historyIndexOf(Document*);
79 ScCodeEditor *editorForDocument(Document*);
80 bool eventFilter( QObject *, QEvent * );
81 void focusInEvent( QFocusEvent * );
82 void paintEvent( QPaintEvent * );
84 QStackedLayout *mLayout;
85 History mHistory;
86 static QPointer<CodeEditorBox> gActiveBox;
89 } // namespace ScIDE
91 #endif // SCIDE_WIDGET_CODE_EDITOR_EDITOR_BOX_HPP