summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Rusin <zack@kde.org>2011-09-24 19:39:59 -0400
committerZack Rusin <zack@kde.org>2011-09-24 19:39:59 -0400
commitab347b0a2d3d70a4524494cf14130cf3ed10947e (patch)
tree1bbf9f5a1f0a96f6cb2ad12ff4915cdb9a88228b
parent101c49423726ec6700b9a28cdcefc559400b5aee (diff)
Add an option to indent the glsl code in the shader viewer.
Requires 'astyle' but works very well and makes reading wonky shaders a /lot/ easier.
-rw-r--r--gui/glsledit.cpp40
-rw-r--r--gui/glsledit.h7
2 files changed, 45 insertions, 2 deletions
diff --git a/gui/glsledit.cpp b/gui/glsledit.cpp
index 5c77882..f0e4613 100644
--- a/gui/glsledit.cpp
+++ b/gui/glsledit.cpp
@@ -961,4 +961,44 @@ void GLSLEdit::mark(const QString &str, Qt::CaseSensitivity sens)
d_ptr->highlighter->mark(str, sens);
}
+void GLSLEdit::indent()
+{
+ QTemporaryFile file(QLatin1String("shader.glsl"));
+ if (!file.open()) {
+ qDebug()<<"Couldn't create temporary file "<<file.fileName();
+ return;
+ }
+ file.write(toPlainText().toUtf8());
+ file.flush();
+
+ QString tempFileName =
+ QDir::toNativeSeparators(QFileInfo(file).canonicalFilePath());
+
+ QProcess astyle;
+ astyle.setStandardInputFile(tempFileName);
+ astyle.start("astyle");
+ if (!astyle.waitForStarted()) {
+ qDebug()<<"Couldn't start the 'astyle' process!";
+ return;
+ }
+
+ if (!astyle.waitForFinished()) {
+ qDebug()<<"Couldn't finish the 'astyle' process";
+ return;
+ }
+
+ QByteArray result = astyle.readAll();
+ setPlainText(QString::fromUtf8(result));
+}
+
+void GLSLEdit::contextMenuEvent(QContextMenuEvent *e)
+{
+ QMenu *menu = createStandardContextMenu();
+
+ menu->addAction(tr("Indent Code"), this, SLOT(indent()));
+
+ menu->exec(e->globalPos());
+ delete menu;
+}
+
#include "glsledit.moc"
diff --git a/gui/glsledit.h b/gui/glsledit.h
index e4412a2..1fc452a 100644
--- a/gui/glsledit.h
+++ b/gui/glsledit.h
@@ -89,10 +89,13 @@ public slots:
void fold(int line);
void unfold(int line);
void toggleFold(int line);
+ void indent();
protected:
- void resizeEvent(QResizeEvent *e);
- void wheelEvent(QWheelEvent *e);
+ virtual void resizeEvent(QResizeEvent *e);
+ virtual void wheelEvent(QWheelEvent *e);
+ virtual void contextMenuEvent(QContextMenuEvent *e);
+
private slots:
void updateCursor();