Commit dbb0e92a authored by Victor Yacovlev's avatar Victor Yacovlev

Everywhere: Updated plugin system to be used outside of Kumir app

parent 2be1f46e
......@@ -2500,13 +2500,22 @@ class ModuleBaseCppClass(CppClassBase):
:return: implementation of ExtensionSystem::SettingsPtr mySettings() const
"""
return """
/* protected */ ExtensionSystem::SettingsPtr %s::mySettings() const
/* public */ ExtensionSystem::SettingsPtr %s::mySettings() const
{
%s* plugin = qobject_cast<%s*>(parent());
return plugin->mySettings();
}
""" % (self.className, self._module.pluginClassName(), self._module.pluginClassName())
def myResourcesDirCppImplementation(self):
return """
/* public */ QDir %s::myResourcesDir() const
{
%s* plugin = qobject_cast<%s*>(parent());
return plugin->myResourcesDir();
}
""" % (self.className, self._module.pluginClassName(), self._module.pluginClassName())
def sleepCppImplementation(self):
"""
Creates sleep implementation
......
......@@ -2,6 +2,6 @@ add_subdirectory(_colorer)
add_subdirectory(painter)
add_subdirectory(robot)
add_subdirectory(complexnumbers)
add_subdirectory(robot25d)
add_subdirectory(isometricrobot)
add_subdirectory(draw)
add_subdirectory(vodoley)
......@@ -34,8 +34,8 @@ set(FORMS
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/isometricrobotmodulebase.cpp ${CMAKE_CURRENT_BINARY_DIR}/isometricrobotmodulebase.h ${CMAKE_CURRENT_BINARY_DIR}/isometricrobotplugin.cpp ${CMAKE_CURRENT_BINARY_DIR}/isometricrobotplugin.h ${CMAKE_CURRENT_BINARY_DIR}/ActorIsometricRobot.pluginspec
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py --update ${CMAKE_CURRENT_SOURCE_DIR}/robot25d.json
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/robot25d.json ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py --update ${CMAKE_CURRENT_SOURCE_DIR}/isometricrobot.json
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/isometricrobot.json ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/gen_actor_source.py
)
add_custom_target(ActorIsometricRobotPluginSpec ALL ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/ActorIsometricRobot.pluginspec ${PLUGIN_OUTPUT_PATH}
......@@ -71,6 +71,6 @@ install(FILES ${PLUGIN_OUTPUT_PATH}/ActorIsometricRobot.pluginspec DESTINATION $
handleTranslation(ActorIsometricRobot)
add_library(ActorIsometricRobot SHARED ${MOC_SOURCES} ${SOURCES} ${MOC_SOURCES2} ${SOURCES2} ${UI_SOURCES})
target_link_libraries(ActorIsometricRobot ${QT_LIBRARIES} ExtensionSystem Widgets)
copyResources(actors/robot25d)
copyResources(actors/isometricrobot)
install(TARGETS ActorIsometricRobot DESTINATION ${PLUGINS_DIR})
......@@ -17,7 +17,7 @@ namespace ActorIsometricRobot {
IsometricRobotModule::IsometricRobotModule(ExtensionSystem::KPlugin * parent)
: IsometricRobotModuleBase(parent)
, window_(new Robot25DWindow(0))
, window_(new Robot25DWindow(parent->myResourcesDir(), 0))
, robotView_(window_->robotView())
{
connect(m_actionRobot25DLoadEnvironment, SIGNAL(triggered()),
......
......@@ -2,14 +2,14 @@
#include <QtScript>
Robot25DWindow::Robot25DWindow(QWidget *parent) :
Robot25DWindow::Robot25DWindow(const QDir & imagesDir, QWidget *parent) :
QGraphicsView(parent)
{
setAttribute(Qt::WA_Hover);
setMouseTracking(true);
mousePressPosition_ = QPoint(-1, -1);
setScene(new QGraphicsScene);
const QString resPath = qApp->property("sharePath").toString()+"/actors/robot25d/";
const QString resPath = imagesDir.absolutePath();
QImage bgImg = QImage(resPath+"grass_0.png");
QBrush bgBrush = QBrush(bgImg);
// QBrush bgBrush = QBrush(QColor(Qt::black));
......@@ -17,7 +17,7 @@ Robot25DWindow::Robot25DWindow(QWidget *parent) :
setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_robotView = new Robot25D::RobotView(false, true, false, QSize(400,300));
m_robotView = new Robot25D::RobotView(imagesDir, false, true, false, QSize(400,300));
scene()->addItem(m_robotView);
loadGame(resPath+"/default.pm.json");
......
......@@ -13,7 +13,7 @@ class Robot25DWindow :
Q_OBJECT
public:
explicit Robot25DWindow(QWidget *parent = 0);
explicit Robot25DWindow(const QDir & imagesDir, QWidget *parent = 0);
~Robot25DWindow();
inline Robot25D::RobotView * robotView() { return m_robotView; }
inline void lock() { group_lockedActionsDuringEvaluate->setEnabled(false); }
......
......@@ -7,7 +7,7 @@
namespace Robot25D {
RobotItem::RobotItem(RobotView *view)
RobotItem::RobotItem(const QDir & imagesDir, RobotView *view)
: QThread(NULL)
, m_view(view)
, i_timerId(0)
......@@ -17,8 +17,7 @@ RobotItem::RobotItem(RobotView *view)
i_currentStep = 0;
b_animated = false;
b_broken = false;
const QString imagesRoot =
qApp->property("sharePath").toString()+"/actors/robot25d/";
const QString imagesRoot = imagesDir.absolutePath() + "/";
i_framesPerTurn = 4;
qint16 framesCount = i_framesPerTurn * 4;
for ( int i=1; i<=framesCount; i++ ) {
......
......@@ -33,7 +33,7 @@ class RobotItem :
Q_PROPERTY(qreal pulse READ pulse WRITE setPulse);
Q_PROPERTY(int speed READ speed WRITE setSpeed);
public:
RobotItem(class RobotView *view);
RobotItem(const QDir & imagesDir, class RobotView *view);
enum Direction { South, North, West, East };
Point3Dr position() const;
Point2Di scenePosition() const;
......
......@@ -23,7 +23,7 @@ qreal RobotView::m_wallHeight = 10.0;
RobotView::RobotView(bool with_controls, bool with_bachground,
RobotView::RobotView(const QDir & imagesDir, bool with_controls, bool with_bachground,
bool teacherMode,
const QSize &minSize, QGraphicsItem *parent)
: QObject(0)
......@@ -34,6 +34,7 @@ RobotView::RobotView(bool with_controls, bool with_bachground,
Q_UNUSED(with_bachground);
Q_UNUSED(minSize);
setPen(Qt::NoPen);
imagesDir_ = imagesDir;
b_loadingMode = false;
r_loadingState = 0.0;
......@@ -49,7 +50,7 @@ RobotView::RobotView(bool with_controls, bool with_bachground,
// setRenderHint(QPainter::Antialiasing, true);
// setScene(m_scene)
m_robotItem = NULL;
const QString imagesRoot = qApp->property("sharePath").toString()+"/actors/robot25d/";
const QString imagesRoot = imagesDir.absolutePath();
//#ifdef Q_OS_WINCE
// with_bachground = false;
//#endif
......@@ -685,7 +686,7 @@ void RobotView::createRobot(int x, int y, RobotItem::Direction direction)
m_robotItem->prepareForDelete();
m_robotItem->deleteLater();
}
m_robotItem = new RobotItem(this);
m_robotItem = new RobotItem(imagesDir_, this);
connect(m_robotItem, SIGNAL(evaluationFinished()), this, SLOT(handleRobotEvaluationFinised()));
m_robotItem->setAnimated(false);
m_robotItem->setDirection(direction);
......
......@@ -34,7 +34,7 @@ public:
Paint,
Points
};
RobotView(bool withConrols, bool withBackground,
RobotView(const QDir & imagesDir, bool withConrols, bool withBackground,
bool teacherMode,
const QSize &minSize, QGraphicsItem *parent=NULL);
inline void waitForAnimated() { m_robotItem->waitForAnimated(); }
......@@ -108,6 +108,7 @@ protected:
bool b_loadingMode;
qreal r_loadingState;
QDir imagesDir_;
......
......@@ -42,8 +42,8 @@ QString PainterNewImageDialog::color() const
int PainterNewImageDialog::exec()
{
static const QString resourcesRoot = QApplication::instance()->property("sharePath").toString();
static const QString templatesDir = resourcesRoot+"/actors/painter/";
static const QString resourcesRoot = m_module->myResourcesDir().absolutePath();
static const QString templatesDir = resourcesRoot;
QDir dir(templatesDir);
sl_templateFiles = dir.entryList(QStringList() << "*.png");
const QString directory_ini = dir.absoluteFilePath("templates.ini");
......@@ -111,8 +111,8 @@ void PainterNewImageDialog::handleTemplateClicked(QListWidgetItem *item)
if (item) {
int index = ui->listWidget->currentRow();
const QString baseName = sl_templateFiles[index];
static const QString resourcesRoot = QApplication::instance()->property("sharePath").toString();
static const QString templatesDir = resourcesRoot+"/actors/painter/";
static const QString resourcesRoot = m_module->myResourcesDir().absolutePath();
static const QString templatesDir = resourcesRoot;
QDir dir(templatesDir);
const QString fileName = dir.absoluteFilePath(baseName);
if (QFile::exists(fileName)) {
......
......@@ -70,8 +70,7 @@ PainterWindow::PainterWindow(PainterModule * module, QWidget *parent) :
handleCursorMoved(-1,-1,"");
ui->zoomLabel->setText(QString::number(int(ui->view->zoom()*100))+"%");
static const QString resourcesRoot = QApplication::instance()->property("sharePath").toString()+
"/actors/painter/";
static const QString resourcesRoot = m_module->myResourcesDir().absolutePath();
QSettings templates(QDir(resourcesRoot).absoluteFilePath("templates.ini"), QSettings::IniFormat);
templates.setIniCodec("UTF-8");
const QString defName = templates.value("Names/default.png", "new page").toString();
......@@ -189,8 +188,7 @@ void PainterWindow::newImage()
int h = m_newImageDialog->h();
s_fileName = "";
s_templateName = m_newImageDialog->templateFileName();
static const QString resourcesRoot = QApplication::instance()->property("sharePath").toString()+
"/actors/painter/";
static const QString resourcesRoot = m_module->myResourcesDir().absolutePath();
if (m_newImageDialog->isTemplate()) {
m_module->runLoadPage(resourcesRoot+s_templateName);
}
......
......@@ -20,9 +20,10 @@ namespace ActorRobot {
ExtensionSystem::SettingsPtr RobotModule::robotSettings()
{
ExtensionSystem::PluginManager * pluginManager = ExtensionSystem::PluginManager::instance();
ExtensionSystem::KPlugin * plugin = pluginManager->loadedPlugins("ActorRobot")[0];
return pluginManager->settingsByObject(plugin);
return RobotModule::self->mySettings();
// ExtensionSystem::PluginManager * pluginManager = ExtensionSystem::PluginManager::instance();
// ExtensionSystem::KPlugin * plugin = pluginManager->loadedPlugins("ActorRobot")[0];
// return pluginManager->settingsByObject(plugin);
}
FieldItm::FieldItm(QWidget *parent, QGraphicsScene *scene)
......@@ -3136,9 +3137,8 @@ namespace ActorRobot {
{
Value=0;
istemp=false;
iconPath=QUrl::fromLocalFile(
qApp->property("sharePath").toString()+
"/actors/robot/btn_radiation.png"
iconPath=QUrl::fromLocalFile(RobotModule::self->myResourcesDir()
.absoluteFilePath("btn_radiation.png")
);
rad=QImage(iconPath.toLocalFile ());
......@@ -3288,12 +3288,13 @@ namespace ActorRobot {
}
RobotModule* RobotModule::self = 0;
RobotModule::RobotModule(ExtensionSystem::KPlugin * parent)
: RobotModuleBase(parent)
{
self = this;
/* TODO
implement class Constructor
*/
......@@ -3308,8 +3309,7 @@ RobotModule::RobotModule(ExtensionSystem::KPlugin * parent)
view=new RobotView(field);
m_mainWidget = view;
const QUrl rcUrl = QUrl::fromLocalFile(
qApp->property("sharePath").toString()+
"/actors/robot/rc.qml"
myResourcesDir().absoluteFilePath("rc.qml")
);
m_pultWidget = new QDeclarativeView(rcUrl);
m_pultWidget->setRenderHints(QPainter::Antialiasing|QPainter::TextAntialiasing);
......@@ -3415,8 +3415,9 @@ void RobotModule::reset()
}
void RobotModule::changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current){
using Shared::PluginInterface;
qDebug()<<"RobotModuleBase::changeGlobalState";
if(current==ExtensionSystem::GS_Running)
if(current==PluginInterface::GS_Running)
{
m_actionRobotRevertEnvironment->setEnabled(false);
m_actionRobotLoadEnvironment->setEnabled(false);
......@@ -3426,7 +3427,7 @@ void RobotModule::reset()
m_actionRobotEditEnvironment->setEnabled(false);
m_actionRobotNewEnvironment->setEnabled(false);
}
if(current==ExtensionSystem::GS_Unlocked || current==ExtensionSystem::GS_Observe)
if(current==PluginInterface::GS_Unlocked || current==PluginInterface::GS_Observe)
{
m_actionRobotRevertEnvironment->setEnabled(true);
m_actionRobotLoadEnvironment->setEnabled(true);
......@@ -4139,11 +4140,12 @@ void RobotModule::setWindowSize()
textEditBtn=new QToolButton(this);
textEditBtn->hide();
textEditBtn->setCheckable ( true );
textEditBtn->setIcon(QIcon(qApp->property("sharePath").toString()+
"/actors/robot/text.png"));
textEditBtn->setIcon(QIcon(RobotModule::self->myResourcesDir()
.absoluteFilePath("text.png")));
radEditBtn=new QToolButton(this);
radEditBtn->setIcon(QIcon(qApp->property("sharePath").toString()+
"/actors/robot/btn_radiation.png"));
radEditBtn->setIcon(QIcon(RobotModule::self->myResourcesDir()
.absoluteFilePath("btn_radiation.png")));
radEditBtn->hide();
radEditBtn->setCheckable ( true );
......@@ -4151,8 +4153,8 @@ void RobotModule::setWindowSize()
tmpEditBtn=new QToolButton(this);
tmpEditBtn->hide();
tmpEditBtn->setCheckable ( true );
tmpEditBtn->setIcon(QIcon(qApp->property("sharePath").toString()+
"/actors/robot/btn_temperature.png"));
tmpEditBtn->setIcon(QIcon(RobotModule::self->myResourcesDir()
.absoluteFilePath("btn_temperature.png")));
tmpEditBtn->move(textEditBtn->height()*2+2,0);
connect(textEditBtn,SIGNAL(toggled(bool)),this,SLOT(changeEditMode(bool)));
......
......@@ -68,59 +68,9 @@ namespace ActorRobot {
#define MAX_COLUMNS 255
#define MAX_ROWS 128
class EditLine;
class EditLine:public QGraphicsObject
{
Q_OBJECT;
public:
EditLine(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
bool isTemp()
{
return istemp;
}
bool isRad()
{
return !istemp;
}
void setRad()
{
istemp=false;
iconPath=QUrl::fromLocalFile(
qApp->property("sharePath").toString()+
"/actors/robot/btn_radiation.png"
);
// rad=QImage(iconPath.toLocalFile ());
// rad.load(iconPath.toLocalFile ());
}
void setTemp()
{
istemp=true;
iconPath=QUrl::fromLocalFile(
qApp->property("sharePath").toString()+
"/actors/robot/temp.png"
);
rad=QImage(iconPath.toLocalFile ());
// rad.load(iconPath.toLocalFile ());
}
void setValue(float value)
{
Value=value;
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
QUrl iconPath;
float Value;
bool istemp;
QImage rad;
QPicture radiation,temp;
};
class SimpleRobot:
public QGraphicsObject
......@@ -467,7 +417,7 @@ namespace ActorRobot {
......@@ -515,6 +465,7 @@ namespace ActorRobot {
public:
// Constructor
RobotModule(ExtensionSystem::KPlugin * parent);
static RobotModule * self;
QSize minimumSize()const;
public slots:
// Reset actor state before program starts
......@@ -596,6 +547,56 @@ namespace ActorRobot {
}; // RobotModule
class EditLine:public QGraphicsObject
{
Q_OBJECT;
public:
EditLine(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
bool isTemp()
{
return istemp;
}
bool isRad()
{
return !istemp;
}
void setRad()
{
istemp=false;
iconPath=QUrl::fromLocalFile(RobotModule::self->myResourcesDir()
.absoluteFilePath("btn_radiation.png")
);
// rad=QImage(iconPath.toLocalFile ());
// rad.load(iconPath.toLocalFile ());
}
void setTemp()
{
istemp=true;
iconPath=QUrl::fromLocalFile(RobotModule::self->myResourcesDir()
.absoluteFilePath("temp.png")
);
rad=QImage(iconPath.toLocalFile ());
// rad.load(iconPath.toLocalFile ());
}
void setValue(float value)
{
Value=value;
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
private:
QUrl iconPath;
float Value;
bool istemp;
QImage rad;
QPicture radiation,temp;
};
} // ActorRobot
#endif // ROBOTMODULE_H
......@@ -14,6 +14,9 @@
**
****************************************************************************/
#include "pult.h"
#include "vodoleymodule.h"
const double DegreesPerMinute = 7.0;
const double DegreesPerSecond = DegreesPerMinute / 60;
const int MaxMinutes = 45;
......@@ -341,8 +344,8 @@ loggerButton::loggerButton ( QWidget* parent) :