diff --git a/UniversalTuringMachine.pro b/UniversalTuringMachine.pro index d01e364..5ac8689 100644 --- a/UniversalTuringMachine.pro +++ b/UniversalTuringMachine.pro @@ -10,10 +10,12 @@ CONFIG += c++11 SOURCES += \ main.cpp \ - mainwindow.cpp + mainwindow.cpp \ + mylabel.cpp HEADERS += \ - mainwindow.h + mainwindow.h \ + mylabel.h FORMS += \ mainwindow.ui diff --git a/UniversalTuringMachine.pro.user b/UniversalTuringMachine.pro.user index 966f713..1e7df8f 100644 --- a/UniversalTuringMachine.pro.user +++ b/UniversalTuringMachine.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/main.cpp b/main.cpp index fd3e533..24911c8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include "mainwindow.h" #include +#include int main(int argc, char *argv[]) { diff --git a/mainwindow.cpp b/mainwindow.cpp index 4f14554..85c2302 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -113,6 +113,14 @@ MainWindow::MainWindow(QWidget *parent) btn_step->setGeometry(930, 390, 50, 40); btn_step->setText("下一步"); + //纸带 + for(int i=0;i<24;i++) + { + label[i]=new MyLabel(this); + label[i]->setPos(30+40*i,500); + label[i]->hide(); + } + QObject::connect(btn_import, SIGNAL(clicked()), this, SLOT(importFile())); QObject::connect(btn_confirm, SIGNAL(clicked()), this, SLOT(startSimulate())); QObject::connect(btn_step, SIGNAL(clicked()), this, SLOT(nextStep())); @@ -177,6 +185,15 @@ void MainWindow::importFile() void MainWindow::startSimulate() { QString str=line_str->text(); + label[2]->setText("B"); + label[2]->show(); + for(int i=0;isetText(str[i]); + label[i+3]->show(); + label[i+4]->setText("B"); + label[i+4]->show(); + } } void MainWindow::nextStep() diff --git a/mainwindow.h b/mainwindow.h index 7e25391..3125283 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -16,6 +16,9 @@ #include #include #include +#include "mylabel.h" +#include + QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -47,5 +50,6 @@ private: QListWidget *list_file,*list_func; QPushButton *btn_import,*btn_confirm,*btn_step; + MyLabel* label[25]; }; #endif // MAINWINDOW_H diff --git a/mylabel.cpp b/mylabel.cpp new file mode 100644 index 0000000..fc84086 --- /dev/null +++ b/mylabel.cpp @@ -0,0 +1,48 @@ +#include "mylabel.h" + +MyLabel::MyLabel(QMainWindow *parent) +{ + label=new QLabel(parent); + QFont font ("Microsoft YaHei",20,75); + label->setFont(font); + label->setFixedSize(40,55); + label->setAlignment(Qt::AlignCenter); + label->setStyleSheet("border-width: 2px;border-style: solid;border-color: rgb(236, 170, 201);background-color: rgb(255, 20, 20);"); +} + +MyLabel::MyLabel(QMainWindow *parent,QString text) +{ + label=new QLabel(parent); + label->setText(text); + +} + +MyLabel::~MyLabel() +{ + delete label; +} + +void MyLabel::setGeometry(int ax,int ay,int aw,int ah) +{ + label->setGeometry(ax,ay,aw,ah); +} + +void MyLabel::setText(QString text) +{ + label->setText(text); +} + +void MyLabel::hide() +{ + label->hide(); +} + +void MyLabel::show() +{ + label->show(); +} + +void MyLabel::setPos(int x,int y) +{ + label->setGeometry(x,y,40,55); +} diff --git a/mylabel.h b/mylabel.h new file mode 100644 index 0000000..59e5e36 --- /dev/null +++ b/mylabel.h @@ -0,0 +1,27 @@ +#ifndef MYLABEL_H +#define MYLABEL_H + +#include +#include +#include +#include +#include + +class MyLabel +{ +public: + MyLabel(QMainWindow *parent); + MyLabel(QMainWindow *parent,QString text); + ~MyLabel(); + void setText(QString text); + void setGeometry(int ax,int ay,int aw,int ah); + void hide(); + void show(); + void setPos(int x,int y); +private: + QLabel *label; + + +}; + +#endif // MYLABEL_H