Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TextBrowserWidget.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision: 12438 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2011-09-22 17:16:17 +0200 (Thu, 22 Sep 2011) $ *
47 * *
48 \*===========================================================================*/
49 
50 #ifndef TEXTBROWSERWIDGET_HH
51 #define TEXTBROWSERWIDGET_HH
52 
53 #include <QPlainTextEdit>
54 #include <QObject>
55 
56 #include <vector>
57 
59 
60 
61 class TextBrowserWidget : public QPlainTextEdit
62 {
63  Q_OBJECT
64 
65  private:
66  enum FoldType {
67  SHADER,
68  RENDEROBJECT
69  };
70 
71  struct Fold {
72  Fold() :
73  start(-1),
74  end(-1),
75  folded(false),
76  type(SHADER)
77  {}
78 
79  Fold(int _start, int _end, FoldType _type) :
80  start(_start),
81  end(_end),
82  folded(false),
83  type(_type)
84  {}
85 
86  bool contains (int n) const {
87  return (start <= n) && (n <= end);
88  }
89 
90  // start positition in the document
91  int start;
92  // end positition in the document
93  int end;
94  bool folded;
95  FoldType type;
96  };
97 
98 
99  public:
100  TextBrowserWidget(QWidget *parent = 0);
101 
102  void sideAreaPaintEvent(QPaintEvent *event);
103  int sideAreaWidth();
104 
105  protected:
106  void resizeEvent(QResizeEvent *event);
107  virtual void mouseDoubleClickEvent(QMouseEvent* e);
108 
109  private slots:
110  void updateTextBrowserSideAreaWidth();
111  void updateTextBrowserSideArea(const QRect &, int);
112  void foldAll();
113  void unfoldAll();
114  void fold(Fold& _fold);
115  void unfold(Fold& _fold);
116  void toggleFold(int _position);
117  void updateFolds();
118 
125  bool getFold(int _position, Fold& _fold);
126 
127  private:
128  TextBrowserSideArea* sideArea_;
129  static QString const startRenderObjectTag_;
130  static QString const startVertexShaderTag_;
131  static QString const endVertexShaderTag_;
132  static QString const startTessControlShaderTag_;
133  static QString const endTessControlShaderTag_;
134  static QString const startTessEvalShaderTag_;
135  static QString const endTessEvalShaderTag_;
136  static QString const startGeometryShaderTag_;
137  static QString const endGeometryShaderTag_;
138  static QString const startFragmentShaderTag_;
139  static QString const endFragmentShaderTag_;
140 
141  std::vector<Fold> folds_;
143  std::map<int, size_t> blockPosToFold_;
144 };
145 
146 
147 class TextBrowserSideArea : public QWidget
148 {
149  public:
150  TextBrowserSideArea(TextBrowserWidget* _textBrowser) :
151  QWidget(_textBrowser),
152  textBrowser_(_textBrowser)
153  {}
154 
155  QSize sizeHint() const {
156  return QSize(textBrowser_->sideAreaWidth(), 0);
157  }
158 
159  protected:
160  void paintEvent(QPaintEvent *event) {
161  textBrowser_->sideAreaPaintEvent(event);
162  }
163 
164  private:
165  TextBrowserWidget* textBrowser_;
166 };
167 
168 
169 #endif // TEXTBROWSERWIDGET_HH
bool getFold(int _position, Fold &_fold)
get the _fold corresponding to the document _position
std::map< int, size_t > blockPosToFold_
maps positions in the document to indices in folds_