Skip to content

Commit

Permalink
Syntax highlighter, node and beam counters
Browse files Browse the repository at this point in the history
Fixed bugs in syntax highlighter and added node and beam counters to
statusbar.
  • Loading branch information
RORMasa committed Jun 17, 2015
1 parent 490e5fd commit 7e96ead
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
Binary file modified bin/BNEditor.exe
Binary file not shown.
15 changes: 7 additions & 8 deletions source/NodeBeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,16 +1267,14 @@ int NodeBeam::AddNode(int NodeGroupID)
}
for(int i5=0; i5<Beams.size();i5++)
{
if(Beams[i5].Node1GlobalID >= activenode) Beams[i5].Node1GlobalID++;

if(Beams[i5].Node2GlobalID >= activenode) Beams[i5].Node2GlobalID++;
if(Beams.at(i5).Node1GlobalID >= activenode) Beams[i5].Node1GlobalID++;
if(Beams.at(i5).Node2GlobalID >= activenode) Beams[i5].Node2GlobalID++;

}
}
//else create empty group.
else
{
//qDebug()<<"Creating 1.st node group.";
NodeGroups.resize(NodeGroups.size()+1);
NodeGroups[NodeGroups.size()-1].NodeGroupName = "Node Group 1.";
NodeGroups[NodeGroups.size()-1].NodeGroupID = 0;
Expand All @@ -1287,10 +1285,6 @@ int NodeBeam::AddNode(int NodeGroupID)
TempNode.GlobalID = activenode;
TempNode.GroupID = 0;
Nodes.insert(activenode, TempNode);
//qDebug() << "Adding node " << TempNode.GlobalID << " " << TempNode.locX;
//qDebug() << Nodes[0].locX;


}

if(green<255) green++;
Expand All @@ -1304,6 +1298,7 @@ int NodeBeam::AddNode(int NodeGroupID)
//To be written on JBEAM widget next time it is refreshed
JBEAM_temp.AddNode(TempNode);

emit nodeCountChanged(Nodes.size());
return TempNode.GlobalID;
}

Expand Down Expand Up @@ -1366,6 +1361,8 @@ void NodeBeam::DeleteNode(int NodeGlobalID)
Nodes[i].GlobalID--;
//qDebug() << "Node global ID lowered from " << (Nodes[i].GlobalID+1) << " to " << Nodes[i].GlobalID ;
}

emit nodeCountChanged(Nodes.size());
}

/* Add beam */
Expand Down Expand Up @@ -1414,6 +1411,7 @@ void NodeBeam::AddBeamT(bool jbeamAdd)
}

if(jbeamAdd) JBEAM_temp.AddBeam(TempBeam);
emit beamCountChanged(Beams.size());
}

/* Add empty beam group at the end of the list */
Expand Down Expand Up @@ -1441,6 +1439,7 @@ void NodeBeam::DeleteBeam(int BeamIndex)
//Remove
BeamGroups[Beams[BeamIndex].BeamGroupID].BeamAmount--;
Beams.remove(BeamIndex);
emit beamCountChanged(Beams.size());
}

void NodeBeam::DuplicateNodes()
Expand Down
3 changes: 3 additions & 0 deletions source/NodeBeam.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ class NodeBeam : public QObject
void LUA_setJbeamText(QString text);
void LUA_HtmlInputDialog(QString htmlfile);

void nodeCountChanged(int count);
void beamCountChanged(int count);

private:

/*When parsing a line from a file, in grid_index
Expand Down
2 changes: 1 addition & 1 deletion source/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void GLWidget::drawpicking_triangle()

float conv = 1.0f/255.0f;

for(int i=0; i<NBPointer->ListTypes.at(i2).contaier.size();i++)
for(int i=0; i<NBPointer->ListTypes.at(i2).contaier.size();++i)
{
//Draw each triangle with unique color
int red = (i & 0x0000ff);
Expand Down
39 changes: 23 additions & 16 deletions source/jbeamtextbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,7 @@ bool JBEAM_TextBox::JBEAM_FindOtherContainer(QString JBEAM_box, QString listtype
if(level<1) break;
}
}

End = i;

return true;
}

Expand Down Expand Up @@ -855,21 +853,12 @@ void JBEAM_TextBox::SetFilePath(QString FileName)
Highlighter::Highlighter(QTextDocument * document) :
QSyntaxHighlighter(document)
{
QTextCharFormat commentformat;
commentformat.setForeground(QColor(0,140,0));
commentformat.setFontItalic(1);

//Comment highlight
HighlightingRule temprule;
temprule.pattern = QRegExp("\/\/.*");
temprule.format = commentformat;
rules.append(temprule);


QTextCharFormat strformat;
strformat.setForeground(QColor(40,40,255));

temprule.pattern = QRegExp("\".*\"");
HighlightingRule temprule;
temprule.pattern = QRegExp("\"[^\\\"]*\"");
temprule.format = strformat;
rules.append(temprule);

Expand All @@ -884,21 +873,38 @@ Highlighter::Highlighter(QTextDocument * document) :
rules.append(temprule);

QStringList keywords;
/*
keywords << "\"nodes\"" << "\"beams\"" << "\"triangles\"" << "\"information\""
<< "\"authors\"" << "\"hubWheels\"" << "\"pressureWheels\"";
<< "\"authors\"" << "\"hubWheels\"" << "\"pressureWheels\"" << "\"refNodes\""
<< "\"slots\"" << "\"slotType\"" << "\"name\"" << "\"slots\"" << "\"flexbodies\""
<< "\"scalebeamSpring\"" << "\"scalebeamDamp\"" << "\"scalebeamDeform\""
<< "\"scalebeamStrength\"" << "\"breakGroup\"" << "\"deformGroup\"" << "\"disableMeshBreaking\""
<< "\"beamDeform\"" << "\"beamStrength\""<< "\"beamSpring\"" << "\"beamDamp\"" << "\"beamPrecompression\"";*/

keywords << "\\\"[^\\\"]*\\\"\\s*:";

strformat.setForeground(QColor(200,40,40));
strformat.setFontWeight(QFont::Bold);

foreach(const QString keyword, keywords)
{
temprule.pattern = QRegExp(keyword);
temprule.pattern.setMinimal(true);
temprule.format = strformat;
rules.append(temprule);
}

QTextCharFormat commentformat;
commentformat.setForeground(QColor(0,140,0));
commentformat.setFontItalic(1);

//Comment highlight
temprule.pattern = QRegExp("\/\/.*");
temprule.format = commentformat;
rules.append(temprule);

QStringList BNEkeywords;
BNEkeywords << "//BNEnodes" << "//BNEbeams" << "//BNEtriangles";
BNEkeywords << "//BNE.*";
strformat.setFontWeight(QFont::Bold);
strformat.setForeground(QColor(40,100,40));
strformat.setBackground(QColor(220,220,220));
Expand Down Expand Up @@ -927,9 +933,10 @@ void Highlighter::highlightBlock(const QString &text)
{
QRegExp regex = rule.pattern;
int index = regex.indexIn(text);
if(index >= 0)
while(index >= 0)
{
setFormat(index,regex.matchedLength(),rule.format);
index = regex.indexIn(text,index+regex.matchedLength());
}
}

Expand Down
35 changes: 30 additions & 5 deletions source/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(CurrentNodeBeam,SIGNAL(LUA_getJbeamText()),this,SLOT(LUA_JBEAM_Get()));
QObject::connect(CurrentNodeBeam,SIGNAL(LUA_setJbeamText(QString)),this,SLOT(LUA_JBEAM_Set(QString)));
QObject::connect(CurrentNodeBeam,SIGNAL(LUA_HtmlInputDialog(QString)),this,SLOT(htmlinputdialog(QString)));
QObject::connect(CurrentNodeBeam,SIGNAL(nodeCountChanged(int)),this,SLOT(nodeCountChanged(int)));
QObject::connect(CurrentNodeBeam,SIGNAL(beamCountChanged(int)),this,SLOT(beamCountChanged(int)));

//Link nodebeam to glwidgets
for(int i=0; i<2; i++)
Expand Down Expand Up @@ -239,14 +241,28 @@ MainWindow::MainWindow(QWidget *parent) :
ui->treeWidget->header()->resizeSection(0,75); //Make node ID colum narrower in nodes tree widget

//init StatusBar
StatusBar_nodecount = new QLabel();
StatusBar_nodecount->setToolTip("Node counter");
StatusBar_nodecount = new QLabel("Nodes: 99999");
StatusBar_nodecount->setToolTip("Number of nodes");
StatusBar_nodecount->setMinimumSize(StatusBar_nodecount->sizeHint());
StatusBar_nodecount->setIndent(3);
StatusBar_nodecount->setAlignment(Qt::AlignCenter);

StatusBar_beamcount = new QLabel("Beams : 99999");
StatusBar_beamcount->setToolTip("Number of beams");
StatusBar_beamcount->setMinimumSize(StatusBar_beamcount->sizeHint());
StatusBar_beamcount->setIndent(3);
StatusBar_beamcount->setAlignment(Qt::AlignCenter);


StatusBar_mode = new QLabel();
StatusBar_mode->setToolTip("Coordinate system");
StatusBar_info = new QLabel();
ui->statusBar->addWidget(StatusBar_mode);
ui->statusBar->addWidget(StatusBar_nodecount);
ui->statusBar->addWidget(StatusBar_mode, 1);
ui->statusBar->addWidget(StatusBar_beamcount);
ui->statusBar->addWidget(StatusBar_info);
nodeCountChanged(CurrentNodeBeam->Nodes.size());
beamCountChanged(CurrentNodeBeam->Beams.size());

//Swap editor axises for RoR if necessary
if(AppSettings->readsetting("editor_mode")=="2")
Expand All @@ -262,13 +278,13 @@ MainWindow::MainWindow(QWidget *parent) :
ui->lineEdit_rotatex->move(20,70);
ui->lineEdit_rotatey->move(20,30);
ui->lineEdit_rotatez->move(20,50);
StatusBar_mode->setText("ROR");
StatusBar_mode->setText(" ROR ");
}
else
{
EditorMode = 0;
CurrentNodeBeam->EditorMode = 0;
StatusBar_mode->setText("BeamNG");
StatusBar_mode->setText(" BeamNG ");
}

//Update JBEAM textbox cursor locations
Expand Down Expand Up @@ -3278,3 +3294,12 @@ void MainWindow::on_actionClose_triggered()
}
on_pushButton_3_clicked();
}

void MainWindow::nodeCountChanged(int count)
{
StatusBar_nodecount->setText(tr("Nodes: ") + QString::number(count));
}
void MainWindow::beamCountChanged(int count)
{
StatusBar_beamcount->setText(tr("Beams: ") + QString::number(count));
}
4 changes: 4 additions & 0 deletions source/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MainWindow : public QMainWindow
QLabel * StatusBar_info;
QLabel * StatusBar_mode;
QLabel * StatusBar_nodecount;
QLabel * StatusBar_beamcount;

bool *TexboxOutdated;

Expand All @@ -61,6 +62,9 @@ public slots:
void LUA_JBEAM_Set(QString text);
void htmlinputdialog(QString html);

void nodeCountChanged(int count);
void beamCountChanged(int count);

signals:
void ZoomChanged();

Expand Down

0 comments on commit 7e96ead

Please sign in to comment.