Commit e3113e04 authored by Alexander A. Maly's avatar Alexander A. Maly

Astyling Turtle

And cleaning warnings in it.
parent 5a552228
Pipeline #2504 failed with stages
in 2 minutes and 10 seconds
This diff is collapsed.
......@@ -18,89 +18,94 @@
#define TURTLEPULT_H
#include <QWidget>
#include <QDir>
#include "ui_pult.h"
#include "turtle.h"
#include <kumir2-libs/widgets/pultlogger.h>
#include <QtCore>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
#define SCROLL_STEP 10
#define RESP_PANEL 50
#define LOGGER_BUTTONS 140
class pultLogger;
class linkLight;
class MainButton;
#define TEXT_STEP 14
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define TEXTT 5
namespace ActorTurtle {
namespace ActorTurtle
{
class TurtleModule;
}
class TurtleModule;}
class OvenTimer : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
OvenTimer(QWidget *parent = 0);
OvenTimer(QWidget *parent = 0);
void setDuration(int secs);
int duration() const;
void draw(QPainter *painter);
void setDuration(int secs);
int duration() const;
void draw(QPainter *painter);
signals:
void angChange(int value);
void angChange(int value);
public slots:
void setValue(int value);
void setValue(int value);
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent ( QMouseEvent * event );
void mouseReleaseEvent ( QMouseEvent * event );
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
// QDateTime finishTime;
// QTimer *updateTimer;
// QTimer *finishTimer;
bool mouseFlag;
QPointF old_mouse_pos;
int gradValue;
int oldValue;
// QDateTime finishTime;
// QTimer *updateTimer;
// QTimer *finishTimer;
bool mouseFlag;
QPointF old_mouse_pos;
int gradValue;
int oldValue;
};
class TurtlePult : public QWidget, public Ui::TurtlePult
class TurtlePult : public QWidget, public Ui::TurtlePult
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
* @param fl флаги окна
*/
TurtlePult (QDir resDir=QDir(), QWidget* parent = 0, Qt::WindowFlags fl = 0 );
* Конструктор
* @param parent ссыка на объект-владелец
* @param fl флаги окна
*/
TurtlePult(QDir resDir = QDir(), QWidget *parent = 0, Qt::WindowFlags fl = 0);
/**
* Деструктор
*/
inline ~TurtlePult(){};
bool Link(){return link;};
pultLogger * Logger;
pultLogger * pltLogger(){return Logger;};
ActorTurtle::TurtleModule* turtleObj;
* Деструктор
*/
~TurtlePult() {};
bool Link()
{
return link;
}
pultLogger *Logger;
pultLogger *pltLogger()
{
return Logger;
}
void connectTurtle();
void AutoClose()
{
autoClose = true;
}
public:
ActorTurtle::TurtleModule *turtleObj;
bool libMode;
//KNPServer* form_kumir;
void connectTurtle();
void AutoClose(){autoClose=true;};
public
slots:
void noLink();
slots:
void noLink();
void LinkOK();
void newClient(QString);
......@@ -117,44 +122,38 @@ public:
void RadS();
void resetTurtle();
void showMessage(QString message){label->setText(message);};
void showMessage(QString message)
{
label->setText(message);
}
void logToKumir();
signals:
void goUp(qreal step);
void goDown();
void goLeft();
void goRight();
void hasLeftWall();
void hasRightWall();
void noUpWall();
void noDownWall();
void noLeftWall();
void noRightWall();
void Color();
void Clean();
void Rad();
void Temp();
void logToK();
void PultCmd(QString text);
void sendText(QString);
protected:
virtual void closeEvent ( QCloseEvent * event );
void paintEvent(QPaintEvent *event);
virtual void closeEvent(QCloseEvent *event);
void paintEvent(QPaintEvent *event);
private:
bool link;
bool autoClose;
linkLight * greenLight;
MainButton* buttFwd,*buttBack,*turnLeft,*turnRight;
MainButton* askStena,*askFree,*buttRad,*buttTemp;
OvenTimer * GradInput;
bool link;
bool autoClose;
linkLight *greenLight;
MainButton *buttFwd, *buttBack, *turnLeft, *turnRight;
MainButton *askStena, *askFree, *buttRad, *buttTemp;
OvenTimer *GradInput;
};
#endif
......@@ -15,387 +15,440 @@
//****************************************************************************/
#include <QtGui>
#include "turtle.h"
#include "pult.h"
#include <QTextEdit>
#include <QTextStream>
#include <QCloseEvent>
#include <QFileDialog>
#include <QGraphicsSvgItem>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QDebug>
#include <QMessageBox>
#include <math.h>
#define BORDER_SZ 20
static const double Pi = 3.14159265358979323846264338327950288419717;
turtle::turtle(QDir mresd)
{
myresdir=mresd;
FIELD_SX=500;
FIELD_SY=500;
loadIniFile();
myresdir = mresd;
FIELD_SX = 500;
FIELD_SY = 500;
loadIniFile();
autoClose=false;
autoClose = false;
// turtleHeader=new WHeader();
scene = new QGraphicsScene(this);
view=new QGraphicsView(this);
view->setScene(scene);
setContentsMargins(0,0,0,0);
view->resize(FIELD_SX+2*BORDER_SZ+5,FIELD_SY+2*BORDER_SZ+5);
view->setSceneRect(-(FIELD_SX/2+BORDER_SZ),-(FIELD_SY/2+BORDER_SZ),FIELD_SX+2*BORDER_SZ,FIELD_SY+2*BORDER_SZ);
scene = new QGraphicsScene(this);
view = new QGraphicsView(this);
view->setScene(scene);
setContentsMargins(0, 0, 0, 0);
view->resize(FIELD_SX + 2 * BORDER_SZ + 5, FIELD_SY + 2 * BORDER_SZ + 5);
view->setSceneRect(-(FIELD_SX / 2 + BORDER_SZ), -(FIELD_SY / 2 + BORDER_SZ), FIELD_SX + 2 * BORDER_SZ, FIELD_SY + 2 * BORDER_SZ);
// view->move(1,HEADER_SIZE);
view->setFixedSize(FIELD_SX+2*BORDER_SZ+5,FIELD_SY+2*BORDER_SZ+5);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(FIELD_SX+2*BORDER_SZ+5,FIELD_SY+2*BORDER_SZ+5);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
view->setViewportUpdateMode (QGraphicsView::NoViewportUpdate);
view->setFixedSize(FIELD_SX + 2 * BORDER_SZ + 5, FIELD_SY + 2 * BORDER_SZ + 5);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(FIELD_SX + 2 * BORDER_SZ + 5, FIELD_SY + 2 * BORDER_SZ + 5);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
view->setViewportUpdateMode(QGraphicsView::NoViewportUpdate);
// turtleHeader->setChildWidget(this);
setCentralWidget(view);
setCentralWidget(view);
// turtleHeader->setWMTitle(QString::fromUtf8("Черепаха"));
setWindowTitle(QString::fromUtf8("Черепаха"));
setWindowTitle(QString::fromUtf8("Черепаха"));
// connect(turtleHeader,SIGNAL(mousePress(QPoint)),this,SLOT(hideTurtle(QPoint)));
//scene->addLine(0,0,1000,300);
//QPalette PallGrey;
//PallGrey.setBrush(QPalette::Window,QBrush(QColor(140,140,100)));
//mw->setTitle(QString::fromUtf8("Черепаха"));
scene->setBackgroundBrush(QBrush(QColor(180,180,10)));
scene->setBackgroundBrush(QBrush(QColor(180, 180, 10)));
//scene->setPalette (PallGrey);
//desertBorders.append(QLineF(260-delta,260-delta,260-delta,-220+delta));//Правый край
// desertBorders.append(QLineF(-270,280-delta,270,280-delta));//нижний край
// desertBorders.append(QLineF(-225+delta,260-delta,-225+delta,-225+delta));//левый край
// desertBorders.append(QLineF(-250,-220+delta,260,-220+delta));//верхний край
ang=0;
step=30;
tail=true;
curX=0;
curY=0;
curTurtleId=1;
zoom=0.2;
setWindowTitle(QString::fromUtf8("Черепаха"));
delta=100*zoom;
desertBorders.append(QLineF(-FIELD_SX/2,FIELD_SY/2,FIELD_SX/2,FIELD_SY/2));//Низ
desertBorders.append(QLineF(-FIELD_SX/2-10,-FIELD_SY/2,FIELD_SX/2,-FIELD_SY/2));//вверх
desertBorders.append(QLineF(FIELD_SX/2,-FIELD_SY/2,FIELD_SX/2,FIELD_SY/2));
desertBorders.append(QLineF(-FIELD_SX/2,-FIELD_SY/2,-FIELD_SX/2,FIELD_SY/2));//лево
CreateBorders();
// for(int i=0;i<desertBorders.count();i++)
// {
// QGraphicsLineItem* bortLine=new QGraphicsLineItem(desertBorders[i]);
//
// bortLine->setPen(redPen);
// scene->addItem(bortLine);
// };
//desertBorders.append(QLineF(260-delta,260-delta,260-delta,-220+delta));//Правый край
// desertBorders.append(QLineF(-270,280-delta,270,280-delta));//нижний край
// desertBorders.append(QLineF(-225+delta,260-delta,-225+delta,-225+delta));//левый край
// desertBorders.append(QLineF(-250,-220+delta,260,-220+delta));//верхний край
ang = 0;
step = 30;
tail = true;
curX = 0;
curY = 0;
curTurtleId = 1;
zoom = 0.2;
setWindowTitle(QString::fromUtf8("Черепаха"));
delta = 100 * zoom;
desertBorders.append(QLineF(-FIELD_SX / 2, FIELD_SY / 2, FIELD_SX / 2, FIELD_SY / 2)); //Низ
desertBorders.append(QLineF(-FIELD_SX / 2 - 10, -FIELD_SY / 2, FIELD_SX / 2, -FIELD_SY / 2)); //вверх
desertBorders.append(QLineF(FIELD_SX / 2, -FIELD_SY / 2, FIELD_SX / 2, FIELD_SY / 2));
desertBorders.append(QLineF(-FIELD_SX / 2, -FIELD_SY / 2, -FIELD_SX / 2, FIELD_SY / 2)); //лево
CreateBorders();
// for(int i=0;i<desertBorders.count();i++)
// {
// QGraphicsLineItem* bortLine=new QGraphicsLineItem(desertBorders[i]);
//
// bortLine->setPen(redPen);
// scene->addItem(bortLine);
// };
CreateTurtle();
drawTail();
timer.start(50,this);
timer.start(50, this);
}
turtle::~turtle()
{
}
void turtle::AutoClose()
{
autoClose = true;
close();
}
void turtle::Repaint()
{
view->repaint();
scene->update();
}
void turtle::showTurtle()
{
setVisible(true);
t1->show();
Repaint();
}
void turtle::hideTurtle()
{
setVisible(false);
t1->hide();
Repaint();
}
void turtle::loadIniFile()
{
FIELD_SX=500;
FIELD_SY=500;
return;
FIELD_SX = 500;
FIELD_SY = 500;
return;
}
};
void turtle::CreateBorders()
{
//cross1->show();
//cross2->show();
QBrush blueBr(QColor(30,30,250));
blueBr.setStyle(Qt::Dense3Pattern);
QGraphicsRectItem* leftBorder=new QGraphicsRectItem (-(FIELD_SX/2+BORDER_SZ),-(FIELD_SY/2+BORDER_SZ),BORDER_SZ,FIELD_SY+BORDER_SZ);
leftBorder->setBrush(blueBr);
leftBorder->setPen(Qt::NoPen);
leftBorder->setZValue(1);
scene->addItem(leftBorder);
QGraphicsRectItem* downBorder=new QGraphicsRectItem (-(FIELD_SX/2+BORDER_SZ),FIELD_SY/2,FIELD_SX+2*BORDER_SZ,BORDER_SZ);
downBorder->setBrush(blueBr);
downBorder->setPen(Qt::NoPen);
downBorder->setZValue(1);
scene->addItem(downBorder);
QGraphicsRectItem* rightBorder=new QGraphicsRectItem (FIELD_SX/2,-(FIELD_SY/2+BORDER_SZ),BORDER_SZ,FIELD_SY+BORDER_SZ);
rightBorder->setBrush(blueBr);
rightBorder->setZValue(1);
rightBorder->setPen(Qt::NoPen);
scene->addItem(rightBorder);
QGraphicsRectItem* upBorder=new QGraphicsRectItem (-(FIELD_SX/2+BORDER_SZ),-(FIELD_SY/2+BORDER_SZ),FIELD_SX+BORDER_SZ,BORDER_SZ);
upBorder->setBrush(blueBr);
upBorder->setZValue(1);
upBorder->setPen(Qt::NoPen);
scene->addItem(upBorder);
QBrush blueBr(QColor(30, 30, 250));
blueBr.setStyle(Qt::Dense3Pattern);
QGraphicsRectItem *leftBorder = new QGraphicsRectItem(-(FIELD_SX / 2 + BORDER_SZ), -(FIELD_SY / 2 + BORDER_SZ), BORDER_SZ, FIELD_SY + BORDER_SZ);
leftBorder->setBrush(blueBr);
leftBorder->setPen(Qt::NoPen);
leftBorder->setZValue(1);
scene->addItem(leftBorder);
QGraphicsRectItem *downBorder = new QGraphicsRectItem(-(FIELD_SX / 2 + BORDER_SZ), FIELD_SY / 2, FIELD_SX + 2 * BORDER_SZ, BORDER_SZ);
downBorder->setBrush(blueBr);
downBorder->setPen(Qt::NoPen);
downBorder->setZValue(1);
scene->addItem(downBorder);
QGraphicsRectItem *rightBorder = new QGraphicsRectItem(FIELD_SX / 2, -(FIELD_SY / 2 + BORDER_SZ), BORDER_SZ, FIELD_SY + BORDER_SZ);
rightBorder->setBrush(blueBr);
rightBorder->setZValue(1);
rightBorder->setPen(Qt::NoPen);
scene->addItem(rightBorder);
QGraphicsRectItem *upBorder = new QGraphicsRectItem(-(FIELD_SX / 2 + BORDER_SZ), -(FIELD_SY / 2 + BORDER_SZ), FIELD_SX + BORDER_SZ, BORDER_SZ);
upBorder->setBrush(blueBr);
upBorder->setZValue(1);
upBorder->setPen(Qt::NoPen);
scene->addItem(upBorder);
// desertBorders.append(QLineF(-225-delta,260-delta,-225+delta,-225+delta));
}
//-----------------------------------
void turtle::CreateTurtle(void)
void turtle::CreateTurtle()
{
obod=false;
ang=0;
step=30;
tail=true;
curX=0;
curY=0;
t1= new QGraphicsSvgItem(myresdir.absoluteFilePath("Trtl1.svg"));
scene->addItem(t1);
t2= new QGraphicsSvgItem(":/trtl_obod.svg");
//scene->addItem(t2);
t3= new QGraphicsSvgItem(":/img/Trtl1.svg");
obod = false;
ang = 0;
step = 30;
tail = true;
curX = 0;
curY = 0;
t1 = new QGraphicsSvgItem(myresdir.absoluteFilePath("Trtl1.svg"));
scene->addItem(t1);
t2 = new QGraphicsSvgItem(":/trtl_obod.svg");
//scene->addItem(t2);
t3 = new QGraphicsSvgItem(":/img/Trtl1.svg");
//scene->addItem(t3);
//t1->moveBy(100,100);
QPen redPen(QColor(250,10,10));
QPen redPen(QColor(250, 10, 10));
//blackPen.setWidth(3);
//blackPen.setWidth(3);
//curTurtle->moveBy(-curTurtle->sceneBoundingRect().height () /2,
// -curTurtle->sceneBoundingRect().width ()/2);
showCurTurtle();
// -curTurtle->sceneBoundingRect().width ()/2);
showCurTurtle();
//qDebug()<<"moveBy"<<-curTurtle->sceneBoundingRect().width ()/2;
AncX=(curTurtle->sceneBoundingRect().width()/2)-7;
AncY=(curTurtle->sceneBoundingRect().height()/2)+140;
AncX = (curTurtle->sceneBoundingRect().width() / 2) - 7;
AncY = (curTurtle->sceneBoundingRect().height() / 2) + 140;
//qDebug()<<"AncX"<<AncX<<" AncY"<<AncY;
curX=AncX*zoom;curY=AncY*zoom;
t1->moveBy(-curX,-curY);
curX=0;curY=0;
t1->setTransform(QTransform().translate(AncX*zoom, AncY*zoom).rotate(360).translate(-AncX*zoom, -AncY*zoom));
/* t1->scale(zoom ,zoom); */ t1->setScale(zoom);
curX = AncX * zoom;
curY = AncY * zoom;
t1->moveBy(-curX, -curY);
curX = 0;
curY = 0;
t1->setTransform(QTransform().translate(AncX * zoom, AncY * zoom).rotate(360).translate(-AncX * zoom, -AncY * zoom));
/* t1->scale(zoom ,zoom); */ t1->setScale(zoom);
}
//-----------------------------------
void turtle::rotate(void)
{
ang+=grad;
ang += grad;
//qDebug()<<"ang"<<ang;
if(ang<0)ang=360+ang;
if(ang>360)ang=ang-360;
if (ang < 0) {
ang = 360 + ang;
}
if (ang > 360) {
ang = ang - 360;
}
rotateImages();
/* Tail->rotate(grad); */ Tail->setRotation(grad);
showCurTurtle();
rotateImages();
/* Tail->rotate(grad); */ Tail->setRotation(grad);
showCurTurtle();
}
void turtle::rotateImages()
{
//qDebug()<<"Ang"<<ang;
if ( ang!=60 && ang!=120 && ang!=240 && ang!=320 ) {
t1->setTransform(QTransform().translate(AncX*zoom, AncY*zoom).rotate(ang).translate(-AncX*zoom, -AncY*zoom));
// t1->setRotation(ang);
}else
{
//qDebug()<<"Ang bugfix"<<ang;
t1->setTransform(QTransform().translate(AncX*zoom, AncY*zoom).rotate(ang-1).translate(-AncX*zoom, -AncY*zoom));
// t1->setRotation(ang);
};
/* t1->scale(zoom,zoom); */ t1->setScale(zoom);
//qDebug()<<"Ang"<<ang;
if (ang != 60 && ang != 120 && ang != 240 && ang != 320) {
t1->setTransform(QTransform().translate(AncX * zoom, AncY * zoom).rotate(ang).translate(-AncX * zoom, -AncY * zoom));
// t1->setRotation(ang);
} else {
//qDebug()<<"Ang bugfix"<<ang;
t1->setTransform(QTransform().translate(AncX * zoom, AncY * zoom).rotate(ang - 1).translate(-AncX * zoom, -AncY * zoom));
// t1->setRotation(ang);
};
/* t1->scale(zoom,zoom); */ t1->setScale(zoom);
//view->update();
};
}
bool turtle::moveT(void)
{
bool toret=true;
qreal oldX=curX;