Commit 18ff93ce authored by Denis Khachko's avatar Denis Khachko

no message

parent b3941399
set(QT_USE_QTMAIN 1)
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtSvg REQUIRED)
find_package(PythonInterp 2.6 REQUIRED)
include (${QT_USE_FILE})
include(../../kumir2_plugin.cmake)
set(SOURCES
turtlemodule.cpp
turtle.cpp
pult.cpp
)
set(FORMS
pult.ui
)
set(MOC_HEADERS
turtlemodule.h
turtle.h
pult.h
)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.cpp
${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.h
${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.cpp
${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.h
${CMAKE_CURRENT_BINARY_DIR}/ActorTurtle.pluginspec
COMMAND ${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py
--update
${CMAKE_CURRENT_SOURCE_DIR}/turtle.json
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/turtle.json
${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py
)
add_custom_target(
ActorTurtlePluginSpec
ALL
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/ActorTurtle.pluginspec ${PLUGIN_OUTPUT_PATH}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ActorTurtle.pluginspec
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.moc.cpp
COMMAND ${QT_MOC_EXECUTABLE}
-I${CMAKE_SOURCE_DIR}/src/shared
-o${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.moc.cpp
${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.h
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/turtlemodulebase.h
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.moc.cpp
COMMAND ${QT_MOC_EXECUTABLE}
-I${CMAKE_SOURCE_DIR}/src/shared
-o${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.moc.cpp
${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.h
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/turtleplugin.h
)
set(SOURCES_GENERATED
turtlemodulebase.cpp
turtleplugin.cpp
)
set(MOC_SOURCES_GENERATED
turtlemodulebase.moc.cpp
turtleplugin.moc.cpp
)
qt4_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})
qt4_wrap_ui(UI_SOURCES ${FORMS})
install(
FILES ${PLUGIN_OUTPUT_PATH}/ActorTurtle.pluginspec
DESTINATION ${PLUGINS_DIR}
)
handleTranslation(ActorTurtle)
add_library(
ActorTurtle
SHARED
${MOC_SOURCES} ${SOURCES} ${UI_SOURCES}
${MOC_SOURCES_GENERATED} ${SOURCES_GENERATED}
)
target_link_libraries(
ActorTurtle
${QT_LIBRARIES}
ExtensionSystem
Widgets
${STDCXX_LIB} ${STDMATH_LIB}
)
copyResources(actors/turtle)
install(
TARGETS ActorTurtle
DESTINATION ${PLUGINS_DIR}
)
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2004-2008 NIISI RAS. All rights reserved.
**
** This file is part of the KuMir.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <QWidget>
#include "ui_pult.h"
#include "turtle.h"
#include <QtCore>
#include <QtGui>
#define SCROLL_STEP 10
#define RESP_PANEL 50
#define LOGGER_BUTTONS 140
#define TEXT_STEP 14
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define TEXT 5
class OvenTimer : public QWidget
{
Q_OBJECT
public:
OvenTimer(QWidget *parent = 0);
void setDuration(int secs);
int duration() const;
void draw(QPainter *painter);
signals:
void angChange(int value);
public slots:
void setValue(int value);
protected:
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;
};
class linkLight : public QWidget
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
*
*/
linkLight ( QWidget* parent =0);
/**
* Деструктор
*/
~linkLight(){};
void setLink(bool b){onLine=b;};
bool link(){return onLine;};
QString text;
signals:
//void pressed();
protected:
void paintEvent ( QPaintEvent * event );
// void mousePressEvent ( QMouseEvent * event );
//void mouseReleaseEvent ( QMouseEvent * event );
private:
int posX,posY;
bool onLine;
};
class MainButton : public QWidget
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
*
*/
MainButton ( QWidget* parent =0);
/**
* Деструктор
*/
~MainButton(){};
inline void setDirection(int d){direction=d;}
inline void setText(const QString &t){text=t;direction=TEXT;}
inline bool isChecked() const {return checked;}
inline void setCheckable(bool flag){Q_UNUSED(flag);checkable=true;}
inline void setChecked(bool flag)
{
checked=flag;
downFlag=flag;
repaint();
}
bool loadIcon(QString icon);
signals:
void pressed();
void clicked();
protected:
void paintEvent ( QPaintEvent * event );
void mousePressEvent ( QMouseEvent * event );
void mouseReleaseEvent ( QMouseEvent * event );
void enterEvent ( QEvent * event );
void leaveEvent ( QEvent * event );
private:
void drawAddons(QPainter* painter);
int posX,posY;
uint direction;
QImage buttonImageUp,buttonImageDown,buttonIcon;
bool downFlag,checked,checkable,mouseOver,icon;
QWidget* Parent;
QVector<QLine> upArrow,downArrow,leftArrow,rightArrow;
QString text;
};
class loggerButton : public QWidget
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
*
*/
loggerButton ( QWidget* parent =0);
/**
* Деструктор
*/
~loggerButton(){};
void upArrowType(bool b){isUpArrow=b;};
signals:
void pressed();
protected:
void paintEvent ( QPaintEvent * event );
void mousePressEvent ( QMouseEvent * event );
void mouseReleaseEvent ( QMouseEvent * event );
private:
int posX,posY;
bool isUpArrow;
QImage buttonImageUp,buttonImageDown;
bool downFlag;
QWidget* Parent;
QVector<QLine> upArrow,downArrow;
};
class logLine
{
public:
inline logLine(QString KumCommand,
QString LogCommand,
QString React,QFrame* frame,QFrame* respFrame,uint pos)
{
kumCommand=KumCommand;
logCommand=LogCommand;
react=React;
textLabel=new QLabel(frame);
textLabel->setText(logCommand);
textLabel->move(4,pos);
textLabel->resize(120,20);
textLabel->show();
respLabel=new QLabel(respFrame);
respLabel->setText(React);
respLabel->move(4,pos);
respLabel->resize(RESP_PANEL,20);
respLabel->show();
}
inline void moveUp()
{
textLabel->move(textLabel->x(),textLabel->y()-SCROLL_STEP);
respLabel->move(respLabel->x(),respLabel->y()-SCROLL_STEP);
}
inline void moveDown()
{
textLabel->move(textLabel->x(),textLabel->y()+SCROLL_STEP);
respLabel->move(respLabel->x(),respLabel->y()+SCROLL_STEP);
}
inline int pos()
{
return textLabel->y();
}
inline void removeLabels()
{
if(textLabel)delete textLabel;
if(respLabel)delete respLabel;
}
inline QString KumCommand() const {return kumCommand;}
private:
QString kumCommand;
QString logCommand;
QString react;
QLabel * textLabel;
QLabel * respLabel;
};
class pultLogger : public QWidget
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
* @param fl флаги окна
*/
pultLogger ( QWidget* parent = 0);
/**
* Деструктор
*/
~pultLogger();
void setSizes(uint w,uint h);
void Move(uint x,uint y);
inline void Show()
{
//mainFrame->show();
//downButton->show();
//upButton->show();
//show();
}
inline void appendText(QString kumCommand,QString text,QString replay);
QString log()
{
QString toret;
for(int i=0;i<lines.count();i++)toret+=lines[i].KumCommand();
return toret;
}
public slots:
void upBtnPressed();
void downBtnPressed();
void ClearLog();
void CopyLog();
private:
QFrame * mainFrame;
QFrame * dummyFrame;
QFrame * respFrame;
int W,H;
int pos;
//QLabel * testLabel;
//QFrame * mainFrame;
QList<logLine> lines;
int buttonSize;
loggerButton* downButton;
loggerButton* upButton;
};
class TurtlePult : public QWidget, public Ui::TurtlePult
{
Q_OBJECT
public:
/**
* Конструктор
* @param parent ссыка на объект-владелец
* @param fl флаги окна
*/
TurtlePult ( QWidget* parent = 0, Qt::WFlags fl = 0 );
/**
* Деструктор
*/
inline ~TurtlePult(){};
bool Link(){return link;};
pultLogger * Logger;
pultLogger * pltLogger(){return Logger;};
turtle* turtleObj;
bool libMode;
//KNPServer* form_kumir;
void AutoClose(){autoClose=true;};
public
slots:
void noLink();
void LinkOK();
void newClient(QString);
void clientDisconnect();
void Up();
void Down();
void Left();
void Right();
void SwStena();
void SwSvobodno();
void TempS();
void RadS();
void resetTurtle();
void showMessage(QString message){label->setText(message);};
void logToKumir();
signals:
void goUp();
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);
private:
bool link;
bool autoClose;
linkLight * greenLight;
MainButton* buttFwd,*buttBack,*turnLeft,*turnRight;
MainButton* askStena,*askFree,*buttRad,*buttTemp;
OvenTimer * GradInput;
};
This diff is collapsed.
//****************************************************************************
//**
//** Copyright (C) 2004-2008 IMPB RAS. All rights reserved.
//**
//** This file is part of the KuMir.
//**
//** This file may be used under the terms of the GNU General Public
//** License version 2.0 as published by the Free Software Foundation
//** and appearing in the file LICENSE.GPL included in the packaging of
//** this file.
//**
//** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
//** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//**
//****************************************************************************/
#include <QtGui>
#include "turtle.h"
#include "pult.h"
#include <QTextEdit>
#include <QTextStream>
#include <QCloseEvent>
#include <QFileDialog>
static const double Pi = 3.14159265358979323846264338327950288419717;
turtle::turtle()
{
FIELD_SX=500;
FIELD_SY=500;
loadIniFile();
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);
// 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);
// turtleHeader->setChildWidget(this);
setCentralWidget(view);
// turtleHeader->setWMTitle(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->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);
// };
CreateTurtle();
drawTail();
}
void turtle::loadIniFile()
{
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);
// desertBorders.append(QLineF(-225-delta,260-delta,-225+delta,-225+delta));
}
//-----------------------------------
void turtle::CreateTurtle(void)
{
obod=false;
ang=0;
step=30;
tail=true;
curX=0;
curY=0;
t1= new QGraphicsSvgItem(":/img/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));