Commit 7922d144 authored by Isaak Lim's avatar Isaak Lim

implemented code-folding for the renderer object widget

closes #1772

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17693 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0e1875c9
This diff is collapsed.
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 12438 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-09-22 17:16:17 +0200 (Thu, 22 Sep 2011) $ *
* *
\*===========================================================================*/
#ifndef TEXTBROWSERWIDGET_HH
#define TEXTBROWSERWIDGET_HH
#include <QPlainTextEdit>
#include <QObject>
#include <vector>
class TextBrowserSideArea;
class TextBrowserWidget : public QPlainTextEdit
{
Q_OBJECT
private:
enum FoldType {
SHADER,
RENDEROBJECT
};
struct Fold {
Fold() :
start(-1),
end(-1),
folded(false),
type(SHADER)
{}
Fold(int _start, int _end, FoldType _type) :
start(_start),
end(_end),
folded(false),
type(_type)
{}
bool contains (int n) const {
return (start <= n) && (n <= end);
}
// start positition in the document
int start;
// end positition in the document
int end;
bool folded;
FoldType type;
};
public:
TextBrowserWidget(QWidget *parent = 0);
void sideAreaPaintEvent(QPaintEvent *event);
int sideAreaWidth();
protected:
void resizeEvent(QResizeEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent* e);
private slots:
void updateTextBrowserSideAreaWidth();
void updateTextBrowserSideArea(const QRect &, int);
void foldAll();
void unfoldAll();
void fold(Fold& _fold);
void unfold(Fold& _fold);
void toggleFold(int _position);
void updateFolds();
/** \brief get the _fold corresponding to the document _position
* @param _position position in the document
* @param _fold fold in folds_ at the position if found
*
* \return true if fold was found (otherwise false is returned)
*/
bool getFold(int _position, Fold& _fold);
private:
TextBrowserSideArea* sideArea_;
static QString const startRenderObjectTag_;
static QString const startVertexShaderTag_;
static QString const endVertexShaderTag_;
static QString const startGeometryShaderTag_;
static QString const endGeometryShaderTag_;
static QString const startFragmentShaderTag_;
static QString const endFragmentShaderTag_;
std::vector<Fold> folds_;
/// maps positions in the document to indices in folds_
std::map<int, size_t> blockPosToFold_;
};
class TextBrowserSideArea : public QWidget
{
public:
TextBrowserSideArea(TextBrowserWidget* _textBrowser) :
QWidget(_textBrowser),
textBrowser_(_textBrowser)
{}
QSize sizeHint() const {
return QSize(textBrowser_->sideAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) {
textBrowser_->sideAreaPaintEvent(event);
}
private:
TextBrowserWidget* textBrowser_;
};
#endif // TEXTBROWSERWIDGET_HH
......@@ -42,7 +42,7 @@
#include "rendererObjectWidget.hh"
#if QT_VERSION >= 0x050000
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
......@@ -57,7 +57,8 @@
RendererObjectWidget::RendererObjectWidget(QWidget *parent)
: QDialog(parent),
highlighter_(0)
highlighter_(0),
textBrowser_(0)
{
setupUi(this);
......@@ -68,7 +69,10 @@ RendererObjectWidget::RendererObjectWidget(QWidget *parent)
closeButton->setIcon( QIcon(iconPath + "window-close.png"));
highlighter_ = new RenderObjectHighlighter( textBrowser->document() );
textBrowser_ = new TextBrowserWidget(this);
textBrowserLayout->addWidget(textBrowser_);
highlighter_ = new RenderObjectHighlighter( textBrowser_->document() );
connect(showShadersBox,SIGNAL(clicked()),this,SLOT(update()));
}
......@@ -88,22 +92,20 @@ void RendererObjectWidget::update()
{
RendererInfo* renderer = renderManager().active(PluginFunctions::activeExaminer());
textBrowser->clear();
textBrowser_->clear();
if ( renderer ) {
textBrowser->insertPlainText(tr("Current renderer: ") + renderer->name +"\n");
textBrowser->insertPlainText(tr("Description: ") + renderer->description +"\n");
textBrowser->insertPlainText(tr("Version: ") + renderer->version + "\n" );
textBrowser->insertPlainText("\n" );
textBrowser_->insertPlainText(tr("Current renderer: ") + renderer->name +"\n");
textBrowser_->insertPlainText(tr("Description: ") + renderer->description +"\n");
textBrowser_->insertPlainText(tr("Version: ") + renderer->version + "\n" );
textBrowser_->insertPlainText("\n" );
//TODO: Flag for shader output activate/deactivate
if ( renderManager().activeId(PluginFunctions::activeExaminer()) != 0 )
textBrowser->insertPlainText(renderer->plugin->renderObjectsInfo(showShadersBox->isChecked()));
textBrowser_->insertPlainText(renderer->plugin->renderObjectsInfo(showShadersBox->isChecked()));
} else {
textBrowser->setText("Unable to get renderer!");
textBrowser_->insertPlainText("Unable to get renderer!");
}
}
......@@ -45,6 +45,7 @@
#include <OpenFlipper/common/RendererInfo.hh>
#include "renderObjectHighLighter.hh"
#include "TextBrowserWidget.hh"
class RendererObjectWidget : public QDialog, public Ui::RendererObjectWidget
{
......@@ -64,6 +65,6 @@ class RendererObjectWidget : public QDialog, public Ui::RendererObjectWidget
private:
RenderObjectHighlighter* highlighter_;
TextBrowserWidget* textBrowser_;
};
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>939</width>
<height>527</height>
<height>513</height>
</rect>
</property>
<property name="windowTitle">
......@@ -62,7 +62,7 @@
</widget>
</item>
<item>
<widget class="QTextBrowser" name="textBrowser"/>
<layout class="QVBoxLayout" name="textBrowserLayout"/>
</item>
<item>
<widget class="QCheckBox" name="showShadersBox">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment