Commit 8c4e8513 authored by Denis Khachko's avatar Denis Khachko

Merge branch 'master' of ssh://git.lpm.org.ru:7999/niisi/kumir2

parents 4ab83ce5 a4160de3
......@@ -1493,10 +1493,15 @@ private:
, asyncRunThread_(nullptr)
, settingsPage_(nullptr)
{
bool hasGuiThread = true;
#ifdef Q_OS_LINUX
hasGuiThread = getenv("DISPLAY") != 0;
#endif
QObject::connect(
this, SIGNAL(asyncRun(quint32,QVariantList)),
this, SLOT(asyncEvaluate(quint32,QVariantList)),
Qt::QueuedConnection
//hasGuiThread? Qt::QueuedConnection :
Qt::DirectConnection
);
}
""" % (self.class_name, self.class_name)
......
......@@ -39,6 +39,7 @@ set(SOURCES
robot25dwindow.cpp
robotitem.cpp
remotecontrol.cpp
robotmodel.cpp
)
set(MOC_HEADERS
......@@ -47,6 +48,7 @@ set(MOC_HEADERS
robot25dwindow.h
robotitem.h
remotecontrol.h
robotmodel.h
)
set(FORMS
......
......@@ -24,20 +24,11 @@ CellGraphicsItem::CellGraphicsItem(const QPolygonF &poly,
, p_east(polyEast)
, p_north(polyNorth)
, p_west(polyWest)
, b_editable(editable)
, i_cellX(cellX)
, i_cellY(cellY)
, m_view(view)
, b_hoveredCell(false)
, b_pressed(false)
{
if (i_cellX<0 || i_cellY<0)
b_editable = false;
if (i_cellX>=m_view->m_field[0].size())
b_editable = false;
if (i_cellY>=m_view->m_field.size())
b_editable = false;
setAcceptHoverEvents(b_editable);
}
......@@ -46,50 +37,7 @@ CellGraphicsItem::CellGraphicsItem(const QPolygonF &poly,
void CellGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QGraphicsPolygonItem::paint(painter, option, widget);
if (b_hoveredCell) {
painter->save();
painter->setBrush(QColor(0,0,0,128));
painter->drawPolygon(polygon());
painter->restore();
}
// if (i_hoveredWall) {
// painter->save();
// painter->setBrush(QColor(0,0,0,128));
// if (i_hoveredWall==DOWN_WALL) {
// painter->drawPolygon(p_south);
// }
// else if (i_hoveredWall==RIGHT_WALL) {
// painter->drawPolygon(p_east);
// }
// else if (i_hoveredWall==UP_WALL) {
// painter->drawPolygon(p_north);
// }
// else if (i_hoveredWall==LEFT_WALL) {
// painter->drawPolygon(p_west);
// }
// painter->restore();
// }
}
int CellGraphicsItem::whichWall(const QPointF &p) const
{
qDebug() << "Which wall at " << p << " ?";
Qt::FillRule rule = Qt::WindingFill;
int result = 0;
if (p_south.containsPoint(p, rule)) {
result = DOWN_WALL;
}
else if (p_east.containsPoint(p, rule)) {
result = RIGHT_WALL;
}
else if (p_north.containsPoint(p, rule)) {
result = UP_WALL;
}
else if (p_west.containsPoint(p, rule)) {
result = LEFT_WALL;
}
qDebug() << "Result is : " << result;
return result;
}
......
......@@ -39,9 +39,7 @@ private:
int i_cellX;
int i_cellY;
RobotView *m_view;
bool b_hoveredCell;
bool b_pressed;
};
......
......@@ -4,16 +4,16 @@
namespace Robot25D {
GraphicsImageItem::GraphicsImageItem()
{
mutex_image = new QMutex;
_mutex_image = new QMutex;
}
QRectF GraphicsImageItem::boundingRect() const
{
mutex_image->lock();
_mutex_image->lock();
QRectF result;
if (!m_image.isNull())
result = QRectF(QPointF(0.0, 0.0), m_image.size()).adjusted(-0.5, -0.5, 0.5, 0.5);
mutex_image->unlock();
if (!_image.isNull())
result = QRectF(QPointF(0.0, 0.0), _image.size()).adjusted(-0.5, -0.5, 0.5, 0.5);
_mutex_image->unlock();
return result;
}
......@@ -21,34 +21,34 @@ void GraphicsImageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
{
Q_UNUSED(option);
Q_UNUSED(widget);
mutex_image->lock();
_mutex_image->lock();
// painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
// bool antialiasing = scene()->views()[0]->renderHints().testFlag(QPainter::Antialiasing);
painter->drawImage(0,0,m_image);
painter->drawImage(0,0,_image);
// painter->setPen(QColor("blue"));
// painter->drawRect(0,0,m_image.width(),m_image.height());
mutex_image->unlock();
_mutex_image->unlock();
}
QImage GraphicsImageItem::image() const
{
mutex_image->lock();
QImage result = m_image;
mutex_image->unlock();
_mutex_image->lock();
QImage result = _image;
_mutex_image->unlock();
return result;
}
void GraphicsImageItem::setImage(const QImage &image)
{
mutex_image->lock();
m_image = image;
mutex_image->unlock();
_mutex_image->lock();
_image = image;
_mutex_image->unlock();
// update();
}
GraphicsImageItem::~GraphicsImageItem()
{
delete mutex_image;
delete _mutex_image;
}
}
......@@ -21,8 +21,8 @@ public:
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
QImage m_image;
QMutex *mutex_image;
QImage _image;
QMutex *_mutex_image;
};
}
......
......@@ -73,6 +73,7 @@
],
"gui": {
"optional": true,
"windows": [
{ "role": "main", "icon": "robot25d" }
],
......
......@@ -11,6 +11,7 @@ You should change it corresponding to functionality.
#include <iostream>
#include "isometricrobotmodule.h"
#include "sch_environment.h"
#include "sch_game.h"
#include "remotecontrol.h"
namespace ActorIsometricRobot {
......@@ -18,36 +19,96 @@ namespace ActorIsometricRobot {
IsometricRobotModule::IsometricRobotModule(ExtensionSystem::KPlugin * parent)
: IsometricRobotModuleBase(parent)
, window_(0)
, robotView_(0)
, parentObject_(parent)
, remoteControl_(0)
, remoteControlWidget_(0)
, _window(0)
, _robotView(0)
, _parentObject(parent)
, _remoteControl(0)
, _remoteControlWidget(0)
{
}
void IsometricRobotModule::createGui()
{
window_ = new Robot25DWindow(parentObject_->myResourcesDir(), 0);
remoteControlWidget_ = new QWidget(0);
_window = new Robot25DWindow(_model, _parentObject->myResourcesDir(), 0);
_remoteControlWidget = new QWidget(0);
QVBoxLayout* rcLayout = new QVBoxLayout;
remoteControlWidget_->setLayout(rcLayout);
const QString rcFileName = parentObject_->myResourcesDir().absoluteFilePath("robot25d-rc.svg");
remoteControl_ = new SvgRemoteControl(parentObject_, this, rcFileName, remoteControlWidget_);
rcLayout->addWidget(remoteControl_);
_remoteControlWidget->setLayout(rcLayout);
const QString rcFileName = _parentObject->myResourcesDir().absoluteFilePath("robot25d-rc.svg");
_remoteControl = new SvgRemoteControl(_parentObject, this, rcFileName, _remoteControlWidget);
rcLayout->addWidget(_remoteControl);
robotView_ = window_->robotView();
_robotView = _window->robotView();
connect(m_actionRobot25DLoadEnvironment, SIGNAL(triggered()),
window_, SLOT(handleLoadAction()));
_window, SLOT(handleLoadAction()));
connect(m_actionRobot25DResetEnvironment, SIGNAL(triggered()),
this, SLOT(reset()));
}
QString IsometricRobotModule::initialize(const QStringList &configurationParameters, const ExtensionSystem::CommandLine &)
QString IsometricRobotModule::loadEnvironmentFromFile(const QString &fileName)
{
QString message;
QFile f(fileName);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
QString script = "a = ";
script += QString::fromUtf8(f.readAll());
f.close();
Schema::Environment env;
QScriptEngine engine;
QScriptValue v = engine.evaluate(script);
if (Schema::parceJSON(v, env)) {
_model->loadEnvironment(env);
}
else {
message = QString::fromUtf8("Невозможно загрузить %1: это не обстановка Вертуна").arg(QFileInfo(fileName).fileName());
}
}
else {
message = QString::fromUtf8("Невозможно загрузить %1: файл не читается").arg(QFileInfo(fileName).fileName());
}
return message;
}
void IsometricRobotModule::loadDefaultEnvironment()
{
static const QString DefaultGameFileName = myResourcesDir().absoluteFilePath("default.pm.json");
QFile f(DefaultGameFileName);
if (f.open(QIODevice::ReadOnly|QIODevice::Text)) {
QString script = "a = ";
script += QString::fromUtf8(f.readAll());
f.close();
Schema::Game g;
QScriptEngine engine;
QScriptValue v = engine.evaluate(script);
if (Schema::parceJSON(v, g)) {
Schema::Environment env = g.tasks.first().environment;
_model->loadEnvironment(env);
}
}
}
QString IsometricRobotModule::initialize(const QStringList &configurationParameters, const ExtensionSystem::CommandLine &cmdLine)
{
if (!configurationParameters.contains("tablesOnly")) {
createGui();
_model = new Robot25D::RobotModel;
#ifdef Q_OS_LINUX
bool hasGui = 0 != getenv("DISPLAY");
#endif
if (hasGui) {
createGui();
}
else {
const QString envFileName = cmdLine.value('e').toString();
if (envFileName.isEmpty()) {
loadDefaultEnvironment();
}
else {
loadEnvironmentFromFile(envFileName);
}
}
}
return "";
}
......@@ -59,9 +120,12 @@ QList<ExtensionSystem::CommandLineParameter> IsometricRobotModule::acceptableCom
void IsometricRobotModule::reset()
{
bool wasAnimated = robotView_->isAnimated();
robotView_->reset();
robotView_->setAnimated(wasAnimated);
_model->reset();
if (_robotView) {
bool wasAnimated = _robotView->isAnimated();
_robotView->reset();
_robotView->setAnimated(wasAnimated);
}
}
void IsometricRobotModule::loadActorData(QIODevice *source)
......@@ -72,125 +136,131 @@ void IsometricRobotModule::loadActorData(QIODevice *source)
const QString data = ts.readAll();
Schema::Environment env;
Schema::parceJSON(data, env);
robotView_->loadEnvironment(env);
_model->loadEnvironment(env);
}
void IsometricRobotModule::setAnimationEnabled(bool enabled)
{
robotView_->setAnimated(enabled);
if (_robotView) {
_robotView->setAnimated(enabled);
}
}
QWidget* IsometricRobotModule::mainWidget() const
{
return window_;
return _window;
}
void IsometricRobotModule::runGoForward()
{
setError("");
// window_->statusMessage(__FUNCTION__);
if (!robotView_->goForward()) {
setError(robotView_->lastError(QLocale::Russian));
if (!_model->goForward()) {
setError(_model->lastError(QLocale::Russian));
}
if (_robotView) {
_robotView->waitForAnimated();
}
robotView_->waitForAnimated();
}
void IsometricRobotModule::runTurnRight()
{
setError("");
// window_->statusMessage(__FUNCTION__);
robotView_->turnRight();
robotView_->waitForAnimated();
_model->turnRight();
if (_robotView) {
_robotView->waitForAnimated();
}
}
void IsometricRobotModule::runTurnLeft()
{
setError("");
// window_->statusMessage(__FUNCTION__);
robotView_->turnLeft();
robotView_->waitForAnimated();
_model->turnLeft();
if (_robotView) {
_robotView->waitForAnimated();
}
}
void IsometricRobotModule::runDoPaint()
{
setError("");
// window_->statusMessage(__FUNCTION__);
robotView_->doPaint();
robotView_->waitForAnimated();
_model->doPaint();
if (_robotView) {
_robotView->waitForAnimated();
}
}
bool IsometricRobotModule::runIsCellPainted()
{
setError("");
return robotView_->isPainted();
return _model->isPainted();
}
bool IsometricRobotModule::runIsFlagged(int x, int y)
{
setError("");
return robotView_->isFlagged(x - 1, y - 1);
return _model->isFlagged(x - 1, y - 1);
}
bool IsometricRobotModule::runIsCellClean()
{
setError("");
return ! robotView_->isPainted();
return ! _model->isPainted();
}
bool IsometricRobotModule::runIsWallAhead()
{
setError("");
return robotView_->isWall();
return _model->isWall();
}
bool IsometricRobotModule::runIsFreeAhead()
{
setError("");
return ! robotView_->isWall();
return ! _model->isWall();
}
bool IsometricRobotModule::runIsPainted(const int x, const int y)
{
setError("");
return robotView_->isPainted(x - 1, y - 1);
return _model->isPainted(x - 1, y - 1);
}
bool IsometricRobotModule::runIsMarked(const int x, const int y)
{
setError("");
return robotView_->isPointed(x - 1, y - 1);
return _model->isPointed(x - 1, y - 1);
}
int IsometricRobotModule::runPositionX()
{
setError("");
return robotView_->positionX() + 1;
return _model->positionX() + 1;
}
int IsometricRobotModule::runPositionY()
{
setError("");
return robotView_->positionY() + 1;
return _model->positionY() + 1;
}
int IsometricRobotModule::runSizeX()
{
setError("");
return robotView_->sizeX();
return _model->sizeX();
}
int IsometricRobotModule::runSizeY()
{
setError("");
return robotView_->sizeY();
return _model->sizeY();
}
......
......@@ -14,6 +14,7 @@ You should change it corresponding to functionality.
#include "extensionsystem/kplugin.h"
#include "isometricrobotmodulebase.h"
#include "robot25dwindow.h"
#include "robotmodel.h"
namespace ActorIsometricRobot {
......@@ -59,16 +60,20 @@ public slots:
public:
// GUI access methods
QWidget* mainWidget() const;
inline QWidget* pultWidget() const { return remoteControlWidget_; }
inline QWidget* pultWidget() const { return _remoteControlWidget; }
QString initialize(const QStringList &configurationParameters, const ExtensionSystem::CommandLine &runtimeParameters);
private:
void createGui();
Robot25DWindow * window_;
Robot25D::RobotView * robotView_;
ExtensionSystem::KPlugin* parentObject_;
SvgRemoteControl * remoteControl_;
QWidget* remoteControlWidget_;
QString loadEnvironmentFromFile(const QString & fileName);
void loadDefaultEnvironment();
Robot25D::RobotModel * _model;
Robot25DWindow * _window;
Robot25D::RobotView * _robotView;
ExtensionSystem::KPlugin* _parentObject;
SvgRemoteControl * _remoteControl;
QWidget* _remoteControlWidget;
}; // IsometricRobotModule
......
......@@ -21,8 +21,8 @@ SvgRemoteControl::SvgRemoteControl(ExtensionSystem::KPlugin * plugin,
: QSvgWidget(rcFileName, parent)
, plugin_(plugin)
, module_(module)
, linkEnabled_(true)
, loggerOffset_(0)
, _linkEnabled(true)
, _loggerOffset(0)
{
setupButtons();
setupLabels();
......@@ -46,26 +46,26 @@ void SvgRemoteControl::handleSvgButtonPressed(const QString &svgId)
}
else if ("btn_scroll_up" == svgId) {
if (btnScrollUpEnabled()) {
loggerOffset_ --;
_loggerOffset --;
update();
}
}
else if ("btn_scroll_down" == svgId) {
if (btnScrollDownEnabled()) {
loggerOffset_ ++;
_loggerOffset ++;
update();
}
}
else if ("btn_clear" == svgId) {
loggerOffset_ = 0;
loggerText_.clear();
_loggerOffset = 0;
_loggerText.clear();
module_->reset();
update();
}
else if ("btn_copy" == svgId) {
QStringList text;
for (int i=0; i<loggerText_.size(); i++) {
text.append(loggerText_[i].first);
for (int i=0; i<_loggerText.size(); i++) {
text.append(_loggerText[i].first);
}
QClipboard * clp = QApplication::clipboard();
clp->setText(text.join("\n"));
......@@ -105,9 +105,9 @@ void SvgRemoteControl::appendCommandToLog(const QString &svgId)
{
TextLine line;
line.first = commandNameBySvgId(svgId);
loggerText_.append(line);
_loggerText.append(line);
if (btnScrollDownEnabled()) {
loggerOffset_ ++;
_loggerOffset ++;
}
}
......@@ -117,7 +117,7 @@ void SvgRemoteControl::appendStatusToLog()
ActorInterface * actor = qobject_cast<ActorInterface*>(plugin_);
bool error = actor->errorText().length() > 0;
const QString status = error? tr("Error") : tr("OK");
loggerText_.last().second = status;
_loggerText.last().second = status;
update();
}
......@@ -141,7 +141,7 @@ void SvgRemoteControl::appendResultToLog(bool result)
msg = result ? QString::fromUtf8("да") : QString::fromUtf8("нет");
}