Commit 1e93a57e authored by Victor Yacovlev's avatar Victor Yacovlev

Merge branch 'master' of gitorious.org:kumir2/kumir2

parents 7ae51709 8680575c
......@@ -72,121 +72,121 @@ void linkLight::paintEvent ( QPaintEvent * event )
MainButton::MainButton ( QWidget* parent):QWidget(parent)
{direction=UP;
posX=1;
posY=1;
buttonImageUp.load(":/1.png");
buttonImageDown.load(":/1.png");
downFlag=false;
Parent=parent;
int mid=buttonImageUp.width()/2;
// upArrow.append(QLine(mid,30,mid-15,40));
// upArrow.append(QLine(mid,30,mid+15,40));
// downArrow.append(QLine(mid,40,mid-15,30));
// downArrow.append(QLine(mid,40,mid+15,30));
// leftArrow.append(QLine(30,mid,40,mid-15));
// leftArrow.append(QLine(30,mid,40,mid+15));
// rightArrow.append(QLine(40,mid,30,mid-15));
// rightArrow.append(QLine(40,mid,30,mid+15));
text="";
checked=false;
checkable=false;
mouseOver=false;
icon=false;
resize(71,71);
};
void MainButton::paintEvent ( QPaintEvent * event )
{
QPainter painter(this);
painter.setRenderHint (QPainter::Antialiasing,true );
if(!downFlag)
{
painter.drawImage(QPoint(posX,posY),buttonImageUp);
if(icon)painter.drawImage(1,1,buttonIcon);
QPen blackPen(QColor(40,40,40));
blackPen.setWidth(3);
painter.setPen(blackPen);
drawAddons(&painter);
if(mouseOver)
{
QLinearGradient grad( 1, 1, 5, 65);
grad.setColorAt(0.7,QColor(200,190,222));
grad.setColorAt(0.3,QColor(191,208,208));
QBrush solidBrush(grad);
painter.setBrush(solidBrush);
painter.setOpacity(0.1);
painter.drawRect(3,3,155,50);
};
}
else {
painter.drawImage(QPoint(posX,posY),buttonImageDown);
if(icon){
//buttonIcon.invertPixels();
painter.drawImage(3,3,buttonIcon);
//buttonIcon.invertPixels();
};
QPen whitePen(QColor(170,170,170));
whitePen.setWidth(3);
painter.setPen(whitePen);
//drawAddons(&painter);
};
};
void MainButton::drawAddons(QPainter* painter)
{
if(direction==UP)painter->drawLines(upArrow);
if(direction==DOWN)painter->drawLines(downArrow);
if(direction==LEFT)painter->drawLines(leftArrow);
if(direction==RIGHT)painter->drawLines(rightArrow);
if(direction==TEXTT)
{
if(!downFlag)painter->setPen(QColor(10,10,10));
QFont font("FreeSans");
font.setBold(true);
painter->setFont(font);
QStringList textLines=text.split("|");
int start_pos=42-7*textLines.count();
for(int i=0;i<textLines.count();i++)painter->drawText(7,start_pos+TEXT_STEP*i,textLines[i]);
};
};
bool MainButton::loadIcon(QString iconFile)
{
icon=true;
return buttonIcon.load(iconFile);
};
void MainButton::mousePressEvent ( QMouseEvent * event )
{
qWarning("MousePress1");
emit pressed();
if(checkable)checked=!checked;
downFlag=true;
repaint();
};
void MainButton::mouseReleaseEvent ( QMouseEvent * event )
{
if(checkable){if(!checked)downFlag=false;}else downFlag=false;
if(mouseOver)emit clicked();
repaint();
};
void MainButton::enterEvent ( QEvent * event )
{
if(!mouseOver){mouseOver=true;repaint();};
};
void MainButton::leaveEvent ( QEvent * event )
{
if(mouseOver){mouseOver=false;repaint();};
};
// MainButton::MainButton ( QWidget* parent):QWidget(parent)
// {direction=UP;
// posX=1;
// posY=1;
// buttonImageUp.load(":/1.png");
// buttonImageDown.load(":/1.png");
// downFlag=false;
// Parent=parent;
// int mid=buttonImageUp.width()/2;
// // upArrow.append(QLine(mid,30,mid-15,40));
// // upArrow.append(QLine(mid,30,mid+15,40));
// // downArrow.append(QLine(mid,40,mid-15,30));
// // downArrow.append(QLine(mid,40,mid+15,30));
// // leftArrow.append(QLine(30,mid,40,mid-15));
// // leftArrow.append(QLine(30,mid,40,mid+15));
// // rightArrow.append(QLine(40,mid,30,mid-15));
// // rightArrow.append(QLine(40,mid,30,mid+15));
// text="";
// checked=false;
// checkable=false;
// mouseOver=false;
// icon=false;
// resize(71,71);
// };
//
// void MainButton::paintEvent ( QPaintEvent * event )
// {
// QPainter painter(this);
// painter.setRenderHint (QPainter::Antialiasing,true );
// if(!downFlag)
// {
// painter.drawImage(QPoint(posX,posY),buttonImageUp);
// if(icon)painter.drawImage(1,1,buttonIcon);
// QPen blackPen(QColor(40,40,40));
// blackPen.setWidth(3);
// painter.setPen(blackPen);
// drawAddons(&painter);
// if(mouseOver)
// {
// QLinearGradient grad( 1, 1, 5, 65);
// grad.setColorAt(0.7,QColor(200,190,222));
// grad.setColorAt(0.3,QColor(191,208,208));
//
// QBrush solidBrush(grad);
// painter.setBrush(solidBrush);
// painter.setOpacity(0.1);
// painter.drawRect(3,3,155,50);
// };
//
// }
// else {
// painter.drawImage(QPoint(posX,posY),buttonImageDown);
// if(icon){
// //buttonIcon.invertPixels();
// painter.drawImage(3,3,buttonIcon);
// //buttonIcon.invertPixels();
// };
// QPen whitePen(QColor(170,170,170));
// whitePen.setWidth(3);
// painter.setPen(whitePen);
// //drawAddons(&painter);
//
// };
// };
//
// void MainButton::drawAddons(QPainter* painter)
// {
// if(direction==UP)painter->drawLines(upArrow);
// if(direction==DOWN)painter->drawLines(downArrow);
// if(direction==LEFT)painter->drawLines(leftArrow);
// if(direction==RIGHT)painter->drawLines(rightArrow);
// if(direction==TEXTT)
// {
// if(!downFlag)painter->setPen(QColor(10,10,10));
// QFont font("FreeSans");
// font.setBold(true);
// painter->setFont(font);
// QStringList textLines=text.split("|");
// int start_pos=42-7*textLines.count();
// for(int i=0;i<textLines.count();i++)painter->drawText(7,start_pos+TEXT_STEP*i,textLines[i]);
// };
//
// };
// bool MainButton::loadIcon(QString iconFile)
// {
// icon=true;
// return buttonIcon.load(iconFile);
// };
// void MainButton::mousePressEvent ( QMouseEvent * event )
// {
// qWarning("MousePress1");
// emit pressed();
// if(checkable)checked=!checked;
// downFlag=true;
// repaint();
// };
// void MainButton::mouseReleaseEvent ( QMouseEvent * event )
// {
// if(checkable){if(!checked)downFlag=false;}else downFlag=false;
// if(mouseOver)emit clicked();
// repaint();
// };
//
//
// void MainButton::enterEvent ( QEvent * event )
// {
// if(!mouseOver){mouseOver=true;repaint();};
//
//
// };
// void MainButton::leaveEvent ( QEvent * event )
// {
// if(mouseOver){mouseOver=false;repaint();};
// };
//
GrasshopperPult::GrasshopperPult( QDir resdir,QWidget* parent, Qt::WindowFlags fl )
......@@ -210,17 +210,17 @@ GrasshopperPult::GrasshopperPult( QDir resdir,QWidget* parent, Qt::WindowFlags f
LeftB->hide();
turnLeft=new MainButton(this);
turnLeft=new MainButton(resdir,this);
turnLeft->setGeometry(LeftB->geometry());
turnLeft->loadIcon(resdir.absoluteFilePath("160_55l.png"));
// RightB->hide();
turnRight=new MainButton(this);
turnRight=new MainButton(resdir,this);
turnRight->setGeometry(RightB->geometry());
turnRight->loadIcon(resdir.absoluteFilePath("160_55r.png"));
// StenaB->hide();
askStena=new MainButton(this);
askStena=new MainButton(resdir,this);
// askStena->move(StenaB->pos());
askStena->setCheckable(true);
askStena->setText(trUtf8(" "));
......@@ -228,7 +228,7 @@ GrasshopperPult::GrasshopperPult( QDir resdir,QWidget* parent, Qt::WindowFlags f
askStena->setCheckable(true);
askStena->hide();
// SvobodnoB->hide();
askFree=new MainButton(this);
askFree=new MainButton(resdir,this);
// askFree->move(SvobodnoB->pos());
askFree->setCheckable(true);
askFree->setText(trUtf8(" "));
......@@ -237,7 +237,7 @@ GrasshopperPult::GrasshopperPult( QDir resdir,QWidget* parent, Qt::WindowFlags f
askFree->hide();
recolorB=new MainButton(this);
recolorB=new MainButton(resdir,this);
recolorB->setGeometry(colorB->geometry());
recolorB->setText(trUtf8(" "));
recolorB->loadIcon(resdir.absoluteFilePath("recolor.png"));
......
......@@ -40,81 +40,9 @@
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(){};
void setDirection(int d){direction=d;};
void setText(QString t){text=t;direction=TEXTT;};
bool isChecked(){return checked;};
void setCheckable(bool flag){checkable=true;};
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;
};
......
......@@ -23,12 +23,17 @@ include(../../kumir2_plugin.cmake)
set(SOURCES
robotmodule.cpp
pult.cpp
)
set(MOC_HEADERS
robotmodule.h
pult.h
)
set(FORMS
pult.ui
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/robotmodulebase.cpp ${CMAKE_CURRENT_BINARY_DIR}/robotmodulebase.h ${CMAKE_CURRENT_BINARY_DIR}/robotplugin.cpp ${CMAKE_CURRENT_BINARY_DIR}/robotplugin.h ${CMAKE_CURRENT_BINARY_DIR}/ActorRobot.pluginspec
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py --update ${CMAKE_CURRENT_SOURCE_DIR}/robot.json
......@@ -63,13 +68,15 @@ set(MOC_SOURCES2
if(${USE_QT} GREATER 4)
qt5_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})
qt5_wrap_ui(UI_SOURCES ${FORMS})
else()
qt4_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})
qt4_wrap_ui(UI_SOURCES ${FORMS})
endif()
install(FILES ${PLUGIN_OUTPUT_PATH}/ActorRobot.pluginspec DESTINATION ${PLUGINS_DIR})
handleTranslation(ActorRobot)
add_library(ActorRobot SHARED ${MOC_SOURCES} ${SOURCES} ${MOC_SOURCES2} ${SOURCES2})
add_library(ActorRobot SHARED ${MOC_SOURCES} ${SOURCES} ${MOC_SOURCES2} ${SOURCES2} ${UI_SOURCES})
target_link_libraries(ActorRobot ${QT_LIBRARIES} ExtensionSystem Widgets ${STDCXX_LIB} ${STDMATH_LIB})
copyResources(actors/robot)
install(TARGETS ActorRobot DESTINATION ${PLUGINS_DIR})
......
/****************************************************************************
**
** 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 "pult.h"
#include "robotmodule.h"
RoboPult::RoboPult ( QWidget* parent, Qt::WFlags fl )
: QWidget ( parent, fl ), Ui::RoboPult()
{
setupUi ( this );
Logger=new pultLogger(ActorRobot::RobotModule::self->myResourcesDir(),this);
Logger->setSizes(164,150);
Logger->Move(40,5);
greenLight=new linkLight(this);
greenLight->move(15,29);
greenLight->resize(12,104);
ClearLog->setIcon(QIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("edit-delete.png")));
ToKumir->setIcon(QIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("kumir.png")));
UpB->hide();
buttUp=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttUp->move(90,170);
DownB->hide();
buttDown=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttDown->move(DownB->pos());
buttDown->setDirection(DOWN);
LeftB->hide();
buttLeft=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttLeft->move(LeftB->pos());
buttLeft->setDirection(LEFT);
RightB->hide();
buttRight=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttRight->move(RightB->pos());
buttRight->setDirection(RIGHT);
StenaB->hide();
askStena=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
askStena->move(StenaB->pos());
askStena->setCheckable(true);
askStena->setText(trUtf8(" "));
askStena->loadIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("stena.png"));
askStena->setCheckable(true);
SvobodnoB->hide();
askFree=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
askFree->move(SvobodnoB->pos());
askFree->setCheckable(true);
askFree->setText(trUtf8(" "));
askFree->loadIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("svobodno.png"));
askFree->setIconOffset(10);
askFree->setCheckable(true);
RadB->hide();
buttRad=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttRad->move(RadB->pos());
buttRad->setText(trUtf8(" "));
buttRad->setIconOffset(10);
if(!buttRad->loadIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("radiation.png")))qWarning("Image not loaded!");
TempB->hide();
buttTemp=new MainButton(ActorRobot::RobotModule::self->myResourcesDir(),this);
buttTemp->move(TempB->pos());
buttTemp->setText(" ");
buttTemp->setIconOffset(10);
buttTemp->loadIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("tC.png"));
CenterB->setIcon(QIcon(ActorRobot::RobotModule::self->myResourcesDir().absoluteFilePath("robo_field.png")));
connect(buttUp,SIGNAL(clicked()),this,SLOT(Up()));
connect(buttDown,SIGNAL(clicked()),this,SLOT(Down()));
connect(buttLeft,SIGNAL(clicked()),this,SLOT(Left()));
connect(buttRight,SIGNAL(clicked()),this,SLOT(Right()));
connect(buttRad,SIGNAL(clicked()),this,SLOT(RadS()));
connect(buttTemp,SIGNAL(clicked()),this,SLOT(TempS()));
connect(askStena,SIGNAL(clicked()),this,SLOT(SwStena()));
connect(askFree,SIGNAL(clicked()),this,SLOT(SwSvobodno()));
connect(CenterB,SIGNAL(clicked()),this,SLOT(CenterButton()));
connect(ClearLog,SIGNAL(clicked()),Logger,SLOT(ClearLog()));
connect(ToKumir,SIGNAL(clicked()),Logger,SLOT(CopyLog()));
link=true;
};
void RoboPult::paintEvent(QPaintEvent *event)
{
QPainter p(this);
p.save();
p.setPen(Qt::NoPen);
p.setBrush(QColor("#8C877E"));
p.drawRect(0,0,width(),height());
p.restore();
QWidget::paintEvent(event);
}
void RoboPult::noLink(){
link=false;
greenLight->setLink(link);greenLight->repaint();qWarning("NoLINK");};
void RoboPult::LinkOK(){link=true;greenLight->setLink(link);greenLight->repaint();};
void RoboPult::Up()
{
if(askStena->isChecked () ){emit hasUpWall(); askStena->setChecked(false);qWarning("Up Stena");;return;};
if(askFree->isChecked () ){emit noUpWall(); askFree->setChecked(false);return;};
emit goUp();
};
void RoboPult::Down()
{
if(askStena->isChecked () ){emit hasDownWall(); askStena->setChecked(false);return;};
if(askFree->isChecked () ){emit noDownWall(); askFree->setChecked(false);return;};
emit goDown();
};
void RoboPult::Left()
{
if(askStena->isChecked () ){emit hasLeftWall(); askStena->setChecked(false);return;};
if(askFree->isChecked () ){emit noLeftWall(); askFree->setChecked(false);return;};
emit goLeft();
};
void RoboPult::Right()
{
if(askStena->isChecked () ){emit hasRightWall(); askStena->setChecked(false);return;};
if(askFree->isChecked () ){emit noRightWall(); askFree->setChecked(false);return;};
emit goRight();
};
void RoboPult::SwStena()
{
if(askFree->isChecked () ) askFree->setChecked(false);
};
void RoboPult::SwSvobodno()
{
if(askStena->isChecked () )askStena->setChecked(false);
};
void RoboPult::TempS()
{
askStena->setChecked(false);
askFree->setChecked(false);
emit Temp();
};
void RoboPult::RadS()
{
askStena->setChecked(false);
askFree->setChecked(false);
emit Rad();
};
void RoboPult::CenterButton()
{
if(askStena->isChecked () ){emit Colored(); askStena->setChecked(false);return;};
if(askFree->isChecked () ){emit Clean(); askFree->setChecked(false);return;};
emit Color();
};
/****************************************************************************
**
** Copyright (C) 2004-2008 NIISI RAS. All rights reserved.
**