Commit d8ed1474 authored by jhammen's avatar jhammen

formatting only: {BasedOnStyle: llvm, IndentWidth: 4, ColumnLimit: 100}

parent e0cf386e
......@@ -17,18 +17,14 @@
#include "editorwidget.h"
#include "synhighlighter.h"
#include <Qt>
#include <QApplication>
#include <QTextStream>
#include <QMessageBox>
#include <QPainter>
#include <QTextBlock>
#include <QTextStream>
#include <Qt>
EditorWidget::EditorWidget(NamedFile &file)
: mfile(file),
undoable(false),
redoable(false)
{
EditorWidget::EditorWidget(NamedFile &file) : mfile(file), undoable(false), redoable(false) {
setLineWrapMode(QPlainTextEdit::NoWrap);
// font
......@@ -42,14 +38,10 @@ EditorWidget::EditorWidget(NamedFile &file)
setTabStopWidth(metrics.width('0') * 4);
setFont(font);
connect(this, SIGNAL(undoAvailable(bool)),
this, SLOT(setUndoable(bool)));
connect(this, SIGNAL(redoAvailable(bool)),
this, SLOT(setRedoable(bool)));
connect(this, SIGNAL(updateRequest(QRect,int)),
this, SLOT(updateInfoStrip(QRect,int)));
connect(document(), SIGNAL(modificationChanged(bool)),
this, SLOT(contentsModified(bool)));
connect(this, SIGNAL(undoAvailable(bool)), this, SLOT(setUndoable(bool)));
connect(this, SIGNAL(redoAvailable(bool)), this, SLOT(setRedoable(bool)));
connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateInfoStrip(QRect, int)));
connect(document(), SIGNAL(modificationChanged(bool)), this, SLOT(contentsModified(bool)));
// info-strip for line numbers + markers
infoStrip = new InfoStrip(this);
......@@ -59,12 +51,11 @@ EditorWidget::EditorWidget(NamedFile &file)
new SynHighlighter(document());
}
bool EditorWidget::load()
{
bool EditorWidget::load() {
QFile file(mfile.path);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Bipscript IDE"), tr("Error opening %1:\n%2")
.arg(mfile.path), file.errorString());
QMessageBox::warning(this, tr("Bipscript IDE"), tr("Error opening %1:\n%2").arg(mfile.path),
file.errorString());
return false;
}
......@@ -75,12 +66,11 @@ bool EditorWidget::load()
return true;
}
bool EditorWidget::save()
{
bool EditorWidget::save() {
QFile file(mfile.path);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Bipscript IDE"), tr("Error saving %1:\n%2.")
.arg(mfile.path), file.errorString());
QMessageBox::warning(this, tr("Bipscript IDE"), tr("Error saving %1:\n%2.").arg(mfile.path),
file.errorString());
return false;
}
QTextStream out(&file);
......@@ -91,12 +81,11 @@ bool EditorWidget::save()
return true;
}
void EditorWidget::focusLine(int line, int column)
{
void EditorWidget::focusLine(int line, int column) {
QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, line - 1);
if(column >= document()->findBlock(line).length()) {
if (column >= document()->findBlock(line).length()) {
cursor.movePosition(QTextCursor::EndOfLine);
} else {
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, column - 1);
......@@ -105,41 +94,39 @@ void EditorWidget::focusLine(int line, int column)
setFocus();
}
void EditorWidget::commentSelection()
{
void EditorWidget::commentSelection() {
Selection sel = currentSelection();
// uncomment if all lines currently commented
bool comment = false;
for(int i = sel.start; i <= sel.end; i++) {
if(!document()->findBlockByNumber(i).text().startsWith("//")) {
for (int i = sel.start; i <= sel.end; i++) {
if (!document()->findBlockByNumber(i).text().startsWith("//")) {
comment = true;
}
}
if(comment) {
if (comment) {
prefixLines(sel, "//");
} else {
chopLines(sel, 2);
}
}
void EditorWidget::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Tab) {
void EditorWidget::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Tab) {
Selection sel = currentSelection();
if(sel.multiline) {
if (sel.multiline) {
prefixLines(currentSelection(), "\t");
} else {
QPlainTextEdit::keyPressEvent(event);
}
} else if(event->key() == Qt::Key_Backtab) {
} else if (event->key() == Qt::Key_Backtab) {
Selection sel = currentSelection();
bool tab = true;
for(int i = sel.start; i <= sel.end; i++) {
if(!document()->findBlockByNumber(i).text().startsWith("\t")) {
for (int i = sel.start; i <= sel.end; i++) {
if (!document()->findBlockByNumber(i).text().startsWith("\t")) {
tab = false;
}
}
if(tab) {
if (tab) {
chopLines(currentSelection(), 1);
}
} else {
......@@ -147,8 +134,7 @@ void EditorWidget::keyPressEvent(QKeyEvent *event)
}
}
Selection EditorWidget::currentSelection()
{
Selection EditorWidget::currentSelection() {
Selection ret;
QTextCursor cursor = textCursor();
QTextBlock startBlock = document()->findBlock(cursor.selectionStart());
......@@ -156,21 +142,20 @@ Selection EditorWidget::currentSelection()
QTextBlock endBlock = document()->findBlock(cursor.selectionEnd());
ret.end = endBlock.blockNumber();
ret.multiline = false;
if(ret.start != ret.end) {
if (ret.start != ret.end) {
ret.multiline = true;
// don't include line below selection
if(cursor.selectionEnd() == endBlock.position()) {
if (cursor.selectionEnd() == endBlock.position()) {
ret.end--;
}
}
return ret;
}
void EditorWidget::prefixLines(Selection sel, QString prefix)
{
void EditorWidget::prefixLines(Selection sel, QString prefix) {
QTextCursor editCursor(document());
editCursor.beginEditBlock();
for(int i = sel.start; i <= sel.end; i++) {
for (int i = sel.start; i <= sel.end; i++) {
QTextBlock block = document()->findBlockByNumber(i);
editCursor.setPosition(block.position());
editCursor.insertText(prefix);
......@@ -186,11 +171,10 @@ void EditorWidget::prefixLines(Selection sel, QString prefix)
setTextCursor(cursor);
}
void EditorWidget::chopLines(Selection sel, int amount)
{
void EditorWidget::chopLines(Selection sel, int amount) {
QTextCursor editCursor(document());
editCursor.beginEditBlock();
for(int i = sel.start; i <= sel.end; i++) {
for (int i = sel.start; i <= sel.end; i++) {
QTextBlock block = document()->findBlockByNumber(i);
editCursor.setPosition(block.position());
editCursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, amount);
......@@ -199,8 +183,7 @@ void EditorWidget::chopLines(Selection sel, int amount)
editCursor.endEditBlock();
}
BlockInfo EditorWidget::topBlock()
{
BlockInfo EditorWidget::topBlock() {
BlockInfo ret;
QTextBlock block = firstVisibleBlock();
ret.index = block.blockNumber();
......@@ -208,15 +191,13 @@ BlockInfo EditorWidget::topBlock()
return ret;
}
void EditorWidget::resizeEvent(QResizeEvent *e)
{
void EditorWidget::resizeEvent(QResizeEvent *e) {
QPlainTextEdit::resizeEvent(e);
QRect rect = contentsRect();
infoStrip->setGeometry(rect.left(), rect.top(), infoStrip->stripWidth(), rect.height());
}
void EditorWidget::updateInfoStrip(const QRect &rect, int dy)
{
void EditorWidget::updateInfoStrip(const QRect &rect, int dy) {
if (dy > 0) {
infoStrip->scroll(0, dy);
} else {
......@@ -224,8 +205,7 @@ void EditorWidget::updateInfoStrip(const QRect &rect, int dy)
}
}
void InfoStrip::paintEvent(QPaintEvent *event)
{
void InfoStrip::paintEvent(QPaintEvent *event) {
QPainter painter(this);
int lineHeight = fontMetrics().height();
BlockInfo blockInfo = editor.topBlock();
......@@ -236,7 +216,9 @@ void InfoStrip::paintEvent(QPaintEvent *event)
QRect lineRect(paddingSide, top, width() - paddingSide * 2, lineHeight);
// markers
painter.setPen(Qt::red);
if(errorLines.contains(line)) { painter.drawRect(lineRect); }
if (errorLines.contains(line)) {
painter.drawRect(lineRect);
}
// line number
QString number = QString::number(line++);
painter.setPen(Qt::black);
......
......@@ -23,21 +23,18 @@
class InfoStrip;
struct BlockInfo
{
struct BlockInfo {
int index;
int top;
};
struct Selection
{
struct Selection {
int start;
int end;
bool multiline;
};
class EditorWidget : public QPlainTextEdit
{
class EditorWidget : public QPlainTextEdit {
Q_OBJECT
NamedFile mfile;
bool undoable;
......@@ -47,7 +44,8 @@ class EditorWidget : public QPlainTextEdit
Selection currentSelection();
void chopLines(Selection sel, int amount);
void prefixLines(Selection sel, QString prefix);
public:
public:
EditorWidget(NamedFile &file);
const QString &path() { return mfile.path; }
const QString &name() { return mfile.name; }
......@@ -66,32 +64,28 @@ public:
// for info strip
BlockInfo topBlock();
void keyPressEvent(QKeyEvent *e) override;
public slots:
public slots:
void setUndoable(bool b) { undoable = b; }
void setRedoable(bool b) { redoable = b; }
protected:
protected:
void resizeEvent(QResizeEvent *e) override;
private slots:
private slots:
void updateInfoStrip(const QRect &rect, int dy);
void contentsModified(bool) { errorLines.clear(); }
};
class InfoStrip : public QWidget
{
class InfoStrip : public QWidget {
int paddingSide = 5;
EditorWidget &editor;
protected:
protected:
void paintEvent(QPaintEvent *event) override;
public:
InfoStrip(EditorWidget *parent) :
QWidget(parent),
editor(*parent) {}
QSize sizeHint() const override {
return QSize(stripWidth(), 0);
}
int stripWidth() const {
return fontMetrics().width(QLatin1String("999")) + paddingSide * 2;
}
public:
InfoStrip(EditorWidget *parent) : QWidget(parent), editor(*parent) {}
QSize sizeHint() const override { return QSize(stripWidth(), 0); }
int stripWidth() const { return fontMetrics().width(QLatin1String("999")) + paddingSide * 2; }
};
#endif // EDITORWIDGET_H
......@@ -21,14 +21,13 @@
#include <QTreeWidgetItem>
class FolderTreeItem : public QTreeWidgetItem
{
class FolderTreeItem : public QTreeWidgetItem {
NamedFile mfile;
public:
FolderTreeItem(QTreeWidgetItem *parent, QString name, QString path) :
QTreeWidgetItem(parent, QStringList(name), QTreeWidgetItem::UserType),
mfile(name, path)
{}
public:
FolderTreeItem(QTreeWidgetItem *parent, QString name, QString path)
: QTreeWidgetItem(parent, QStringList(name), QTreeWidgetItem::UserType), mfile(name, path) {
}
NamedFile &file() { return mfile; }
};
......
......@@ -17,8 +17,7 @@
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("bipscript");
QCoreApplication::setApplicationName("Bipscript IDE");
......
This diff is collapsed.
......@@ -17,37 +17,36 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "projectlist.h"
#include "foldertreeitem.h"
#include "audioengine.h"
#include "editorwidget.h"
#include "foldertreeitem.h"
#include "outputwidget.h"
#include "audioengine.h"
#include "position.h"
#include "projectlist.h"
#include <QFileInfo>
#include <QLabel>
#include <QMainWindow>
#include <QMessageBox>
#include <QLabel>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
class MainWindow : public QMainWindow {
Q_OBJECT
public:
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *event);
private slots:
private slots:
void changeProject();
void closeOutputTab(int index);
void closeEditorTab(int index);
void codeError(const QString &, int);
void engineDisconnect();
void folderTreeClicked(QTreeWidgetItem *item, int col);
void handleLink(const QUrl&);
void handleLink(const QUrl &);
void markDirty(bool unsaved);
void showTime(Position pos);
void tabChanged(int index);
......@@ -79,7 +78,8 @@ private slots:
void on_actionUndo_triggered();
void on_actionWebsite_triggered();
void on_tabWidget_customContextMenuRequested(const QPoint &pos);
private:
private:
QString *selectedFolder;
AudioEngine &audioEngine;
AudioTimerService *atimer;
......
......@@ -19,13 +19,10 @@
#include <QString>
struct NamedFile
{
struct NamedFile {
QString name;
QString path;
NamedFile(const QString &n, const QString &p) :
name(n),
path(p) {}
NamedFile(const QString &n, const QString &p) : name(n), path(p) {}
NamedFile() {}
};
......
......@@ -15,30 +15,22 @@
* along with Bipscript-IDE. If not, see <http://www.gnu.org/licenses/>.
*/
#include "outputwidget.h"
#include "ui_outputwidget.h"
#include "style.h"
#include "ui_outputwidget.h"
#include <QMessageBox>
#include <signal.h>
OutputWidget::OutputWidget(QWidget *parent) :
QWidget(parent),
mpid(0),
ui(new Ui::OutputWidget)
{
OutputWidget::OutputWidget(QWidget *parent) : QWidget(parent), mpid(0), ui(new Ui::OutputWidget) {
ui->setupUi(this);
connect(ui->killButton, SIGNAL(clicked(bool)), this, SLOT(killScript(bool)));
connect(ui->stdoutBrowser, SIGNAL(anchorClicked(const QUrl &)),
this, SLOT(stdoutLink(const QUrl &)));
connect(ui->stdoutBrowser, SIGNAL(anchorClicked(const QUrl &)), this,
SLOT(stdoutLink(const QUrl &)));
}
OutputWidget::~OutputWidget()
{
delete ui;
}
OutputWidget::~OutputWidget() { delete ui; }
void OutputWidget::running(int pid)
{
void OutputWidget::running(int pid) {
QString base = tr("process ID ");
QString mesg = base + QString::number(pid);
ui->statusLabel->setText(mesg);
......@@ -47,8 +39,7 @@ void OutputWidget::running(int pid)
this->mpid = pid;
}
void OutputWidget::write(QString chunk)
{
void OutputWidget::write(QString chunk) {
QTextCursor cursor(ui->stdoutBrowser->document());
cursor.movePosition(QTextCursor::End);
int chunkStart = cursor.position();
......@@ -66,8 +57,7 @@ void OutputWidget::write(QString chunk)
lineBuffer.append(chunk);
}
void OutputWidget::parseLine(int pos)
{
void OutputWidget::parseLine(int pos) {
// format for links
QTextCharFormat anchorFormat;
anchorFormat.setAnchor(true);
......@@ -76,7 +66,7 @@ void OutputWidget::parseLine(int pos)
// parse error
// [path].bip line = (2) column = (9) : error end of statement expected (; or lf)
QRegExp perrorExp("(.*) line = \\(([0-9]+)\\) column = \\(([0-9]+)\\) : (.*)");
if(perrorExp.indexIn(lineBuffer) > -1) {
if (perrorExp.indexIn(lineBuffer) > -1) {
// make link
QUrl href;
href.setScheme("bipsrc");
......@@ -95,7 +85,7 @@ void OutputWidget::parseLine(int pos)
}
// runtime error
QRegExp errorExp("\\*FUNCTION \\[([^\\(]+)\\(\\)\\] (.*) line \\[([0-9]+)\\]");
if(errorExp.indexIn(lineBuffer) > -1) {
if (errorExp.indexIn(lineBuffer) > -1) {
// make link
QUrl href;
href.setScheme("bipsrc");
......@@ -110,11 +100,10 @@ void OutputWidget::parseLine(int pos)
cursor.setCharFormat(anchorFormat);
// emit error
emit codeError(href.path(), href.port());
}
}
}
void OutputWidget::writeError(QString chunk)
{
void OutputWidget::writeError(QString chunk) {
QTextCharFormat errorFormat;
errorFormat.setForeground(QColor(BIPIDE_COLOR_ERROR));
QTextCursor cursor(ui->stderrBrowser->document());
......@@ -122,15 +111,13 @@ void OutputWidget::writeError(QString chunk)
cursor.insertText(chunk, errorFormat);
}
void OutputWidget::killScript(bool)
{
if(mpid != 0) {
void OutputWidget::killScript(bool) {
if (mpid != 0) {
kill(mpid, 15);
}
}
void OutputWidget::completed(int status)
{
void OutputWidget::completed(int status) {
// disable kill button
ui->killButton->setEnabled(false);
// show message
......@@ -139,12 +126,11 @@ void OutputWidget::completed(int status)
mesg.append("with code ");
int code = WEXITSTATUS(status);
mesg.append(QString::number(code));
if(WIFSIGNALED(status)) {
if (WIFSIGNALED(status)) {
mesg.append(" and signal ");
mesg.append(QString::number(WTERMSIG(status)));
color = BIPIDE_COLOR_ERROR;
}
else if(code != 0) {
} else if (code != 0) {
color = BIPIDE_COLOR_ERROR;
}
ui->statusLabel->setStyleSheet("color: " + color);
......
......@@ -17,39 +17,39 @@
#ifndef OUTPUTWIDGET_H
#define OUTPUTWIDGET_H
#include <QWidget>
#include <QUrl>
#include <QWidget>
namespace Ui {
class OutputWidget;
}
class OutputWidget : public QWidget
{
class OutputWidget : public QWidget {
Q_OBJECT
int mpid;
QString lineBuffer;
public:
public:
explicit OutputWidget(QWidget *parent = nullptr);
~OutputWidget();
int pid() { return mpid; }
public slots:
public slots:
void running(int);
void write(QString);
void writeError(QString);
void killScript(bool);
void completed(int);
private slots:
private slots:
void stdoutLink(const QUrl &url) { emit linkClicked(url); }
signals:
signals:
void linkClicked(const QUrl &);
void codeError(const QString &path, int line);
private:
private:
Ui::OutputWidget *ui;
void parseLine(int start);
};
......
......@@ -19,8 +19,7 @@
#include <stdint.h>
struct Position
{
struct Position {
unsigned int frame;
uint32_t msec;
int bar;
......
......@@ -16,27 +16,22 @@
*/
#include "projectlist.h"
#include <QSettings>
#include <QDir>
#include <QSettings>
Project::Project()
{
this->executable("/usr/bin/bipscript");
}
Project::Project() { this->executable("/usr/bin/bipscript"); }
bool Project::exists()
{
for(int i = 0; i < folders.size(); i++) {
bool Project::exists() {
for (int i = 0; i < folders.size(); i++) {
QDir dir(folders[i].path);
if(!dir.exists()) {
if (!dir.exists()) {
return false;
}