Commit 0afc2d84 authored by Denis Khachko's avatar Denis Khachko

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

parents 45bf6ecd 29eb6b50
......@@ -3,7 +3,7 @@ find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui REQUIRED)
include (${QT_USE_FILE})
set(CONFIGURATION_TEMPLATE
"Editor,Browser,Actor*,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI\(notabs,icon=classic,nostartpage,nosessions\)"
"CourseManager,Editor,Browser,Actor*,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI\(notabs,icon=classic,nostartpage,nosessions\)"
)
set(SPLASHSCREEN
"coregui/splashscreens/classic.png"
......
......@@ -3,7 +3,7 @@ find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui REQUIRED)
include (${QT_USE_FILE})
set(CONFIGURATION_TEMPLATE
"Editor,Browser,Actor*,KumirAnalizer\(preload=Files,preload=Strings\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(notabs,icon=classic,nostartpage,nosessions\)"
"CourseManager,Editor,Browser,Actor*,KumirAnalizer\(preload=Files,preload=Strings\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(notabs,icon=classic,nostartpage,nosessions\)"
)
set(SPLASHSCREEN
"coregui/splashscreens/classic.png"
......
......@@ -3,7 +3,7 @@ find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui REQUIRED)
include (${QT_USE_FILE})
set(CONFIGURATION_TEMPLATE
"Editor,Actor*,Browser,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI"
"CourseManager,Editor,Actor*,Browser,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI"
)
set(SPLASHSCREEN
......
......@@ -4,7 +4,7 @@ include (${QT_USE_FILE})
set(CONFIGURATION_TEMPLATE
"Editor,Browser,Actor*,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI"
"CourseManager,Editor,Browser,Actor*,KumirAnalizer,KumirCodeGenerator,KumirCodeRun,!CoreGUI"
)
set(SPLASHSCREEN
......
......@@ -4,7 +4,7 @@ include (${QT_USE_FILE})
set(
CONFIGURATION_TEMPLATE
"Editor\(teacher\),Browser,Actor*,KumirAnalizer\(teacher\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(icon=teacher\)"
"CourseManager,Editor\(teacher\),Browser,Actor*,KumirAnalizer\(teacher\),KumirCodeGenerator,KumirCodeRun,!CoreGUI\(icon=teacher\)"
)
set(
SPLASHSCREEN
......
......@@ -7,5 +7,6 @@ add_subdirectory(kumirbcompiler)
add_subdirectory(browser)
add_subdirectory(editor)
add_subdirectory(coregui)
add_subdirectory(coursemanager)
# add_subdirectory(pascalanalizer)
# add_subdirectory(python3language)
......@@ -10,6 +10,8 @@
namespace CoreGUI {
using namespace Shared;
Plugin::Plugin() :
KPlugin()
{
......@@ -464,6 +466,23 @@ Plugin::~Plugin()
startPage_.widget->deleteLater();
}
void Plugin::setProgramSource(const ProgramSourceText &source)
{
}
GuiInterface::ProgramSourceText Plugin::programSource() const
{
GuiInterface::ProgramSourceText result;
return result;
}
void Plugin::startTesting()
{
}
} // namespace CoreGUI
Q_EXPORT_PLUGIN2(CoreGui, CoreGUI::Plugin)
......@@ -9,6 +9,7 @@
#include "interfaces/generatorinterface.h"
#include "interfaces/actorinterface.h"
#include "interfaces/runinterface.h"
#include "interfaces/guiinterface.h"
#include "widgets/secondarywindow.h"
#include "docbookviewer/docbookview.h"
#include "terminal.h"
......@@ -23,9 +24,11 @@ using namespace Shared;
class Plugin
: public ExtensionSystem::KPlugin
, public Shared::GuiInterface
{
friend class MainWindow;
Q_OBJECT
Q_INTERFACES(Shared::GuiInterface)
public:
explicit Plugin();
~Plugin();
......@@ -41,6 +44,13 @@ public:
static QString DockFloatingKey;
static QString DockGeometryKey;
static QString DockSideKey;
public slots:
void setProgramSource(const ProgramSourceText &source);
ProgramSourceText programSource() const;
void startTesting();
protected slots:
void prepareKumirProgramToRun();
......
name = CourseManager
gui = true
requires= CoreGUI
#include "coursemanager_plugin.h"
namespace CourseManager {
Plugin::Plugin()
: ExtensionSystem::KPlugin()
, mainWindow_(nullptr)
, actionPerformCheck_(nullptr)
, settingsEditorPage_(nullptr)
{
}
QWidget* Plugin::mainWindow() const
{
return mainWindow_;
}
QAction* Plugin::actionPerformCheck() const
{
return actionPerformCheck_;
}
QWidget* Plugin::settingsEditorPage()
{
if (!settingsEditorPage_) {
typedef ExtensionSystem::DeclarativeSettingsPage::Entry Entry;
typedef QMap<QString,Entry> EntryMap;
EntryMap entries; // TODO implement me
settingsEditorPage_ = new ExtensionSystem::DeclarativeSettingsPage(
pluginSpec().name, // Plugin name
tr("Course Manager"), // Title in setting window
mySettings(), // Settings object
entries // A map of configurable items
);
}
return settingsEditorPage_;
}
void Plugin::setEnabled(bool value)
{
}
void Plugin::setTestingResult(ProgramRunStatus status, int value)
{
}
void Plugin::saveSession() const
{
}
void Plugin::restoreSession()
{
}
void Plugin::changeCurrentDirectory(const QString &path)
{
}
void Plugin::changeGlobalState(ExtensionSystem::GlobalState old,
ExtensionSystem::GlobalState current)
{
}
QString Plugin::initialize(const QStringList &arguments)
{
qRegisterMetaType<Shared::CoursesInterface::ProgramRunStatus>
("CourseManager.ProgramRunStatus");
QString error;
return error;
}
void Plugin::updateSettings()
{
if (settingsEditorPage_) {
settingsEditorPage_->setSettingsObject(mySettings());
}
}
} // namespace CourseManager
Q_EXPORT_PLUGIN2(CourseManager, CourseManager::Plugin)
#ifndef COURSEMANAGER_COURSEMANAGER_PLUGIN_H
#define COURSEMANAGER_COURSEMANAGER_PLUGIN_H
#include <QtGlobal>
#include <QObject>
#include <extensionsystem/kplugin.h>
#include <interfaces/coursesinterface.h>
#include <extensionsystem/declarativesettingspage.h>
namespace CourseManager {
class Plugin
: public ExtensionSystem::KPlugin
, public Shared::CoursesInterface
{
Q_OBJECT
Q_INTERFACES(Shared::CoursesInterface)
public:
explicit Plugin();
QWidget* mainWindow() const;
QAction* actionPerformCheck() const;
QWidget* settingsEditorPage();
public slots:
void setEnabled(bool value);
void setTestingResult(ProgramRunStatus status, int value);
private /*methods*/:
void saveSession() const;
void restoreSession();
void changeCurrentDirectory(const QString & path);
void changeGlobalState(ExtensionSystem::GlobalState old,
ExtensionSystem::GlobalState current);
QString initialize(const QStringList &arguments);
void updateSettings();
private /*fields*/:
QWidget* mainWindow_;
QAction* actionPerformCheck_;
ExtensionSystem::DeclarativeSettingsPage* settingsEditorPage_;
};
} // namespace CourseManager
#endif // COURSEMANAGER_COURSEMANAGER_PLUGIN_H
......@@ -13,7 +13,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(QT_USE_QTMAIN 1)
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml REQUIRED)
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml QtSvg REQUIRED)
include (${QT_USE_FILE})
if(NOT MSVC)
......@@ -75,4 +75,4 @@ else()
add_executable(DocBookViewerApp ${APP_SOURCES} ${APP_MOC_SOURCES} ${APP_UI_SOURCES})
target_link_libraries(DocBookViewerApp ${QT_LIBRARIES} DocBookViewer)
endif()
\ No newline at end of file
endif()
......@@ -124,6 +124,9 @@ QString ContentView::renderElement(ModelPtr data) const
else if (data->modelType() == DocBookModel::ProgramListing) {
return renderProgramListing(data);
}
else if (data->modelType() == DocBookModel::Code) {
return renderCode(data);
}
else if (data->modelType() == DocBookModel::Xref) {
return renderXref(data);
}
......@@ -133,6 +136,30 @@ QString ContentView::renderElement(ModelPtr data) const
else if (data->modelType() == DocBookModel::KeySym) {
return renderKeySym(data);
}
else if (data->modelType() == DocBookModel::InformalTable) {
return renderInformalTable(data);
}
else if (data->modelType() == DocBookModel::Table) {
return renderTable(data);
}
else if (data->modelType() == DocBookModel::THead) {
return renderTHead(data);
}
else if (data->modelType() == DocBookModel::TBody) {
return renderTBody(data);
}
else if (data->modelType() == DocBookModel::Row) {
return renderRow(data);
}
else if (data->modelType() == DocBookModel::Entry) {
return renderEntry(data);
}
else if (data->modelType() == DocBookModel::InlineMediaObject) {
return renderInlineMediaObject(data);
}
else if (data->modelType() == DocBookModel::ImageObject) {
return renderImageObject(data);
}
else {
return "";
}
......@@ -169,13 +196,175 @@ QString ContentView::renderKeySym(ModelPtr data) const
return result;
}
QString ContentView::programTextForLanguage(const QString &source,
const QString &language)
{
QStringList keywordsList;
QString inlineCommentSymbol;
QString multilineCommentStartSymbol;
QString multilineCommentEndSymbol;
if (language.toLower() == "kumir") {
keywordsList = QString::fromUtf8("алг,нач,кон,нц,кц,кц_при,если,"
"то,иначе,все,выбор,при,утв,"
"дано,надо,ввод,вывод,пауза,"
"использовать,исп,кон_исп,"
"цел,вещ,лит,сим,лог,таб,"
"целтаб,вещтаб,"
"литтаб,симтаб,логтаб,"
"арг,рез,аргрез,пока,для,от,до,знач,"
"да,нет,не,и,или,раз,нс,файл"
).split(",");
inlineCommentSymbol = "|";
}
else if (language.toLower() == "pascal") {
keywordsList = QString::fromAscii("begin,end,program,unit,uses,for,from,"
"to,if,then,else,"
"integer,real,string,char,boolean,"
"array,of"
).split(",");
inlineCommentSymbol = "//";
multilineCommentStartSymbol = "{";
multilineCommentEndSymbol = "}";
}
return formatProgramSourceText(
source.trimmed(),
keywordsList,
inlineCommentSymbol,
multilineCommentStartSymbol,
multilineCommentEndSymbol
).trimmed();
}
QString ContentView::renderProgramListing(ModelPtr data) const
{
QString result = "<table width='100%' border='1'><tr><td>";
result += "<pre align='left'>" + renderChilds(data);
result = result.trimmed();
result += "</pre>\n";
result += "</td></tr></table>\n";
QString result = "<pre align='left'><font face='monospace'>";
const QString programText = renderChilds(data);
result += programTextForLanguage(programText, data->role());
result += "</font></pre>\n";
return result;
}
QString ContentView::renderCode(ModelPtr data) const
{
QString result = "<font face='monospace'>";
const QString programText = renderChilds(data);
result += programTextForLanguage(programText, data->role());
result += "</font>";
return result;
}
QString ContentView::renderTableContent(ModelPtr data) const
{
QString result;
result += "<table border='1' bordercolor='black' cellspacing='0' cellpadding='0' width='100%'>\n";
result += "<tr><td>\n";
result += "<table border='0' cellspacing='0' cellpadding='10' width='100%'>\n";
result += renderChilds(data);
result += "</table>\n";
result += "</td></tr>\n";
result += "</table>\n";
return result;
}
QString ContentView::renderTHead(ModelPtr data) const
{
QString result;
result += "<thead>\n";
result += renderChilds(data);
result += "</thead>\n";
return result;
}
QString ContentView::renderTBody(ModelPtr data) const
{
QString result;
result += "<tbody>\n";
result += renderChilds(data);
result += "</tbody>\n";
return result;
}
QString ContentView::renderRow(ModelPtr data) const
{
ModelPtr parent = data->parent();
bool inTableHead = false;
bool inTableBody = false;
while (parent) {
if (parent->modelType()==DocBookModel::THead) {
inTableHead = true;
break;
}
if (parent->modelType()==DocBookModel::TBody) {
inTableBody = true;
break;
}
parent = parent->parent();
}
QString result;
if (inTableHead) {
result += "<tr valign='center' bgcolor='lightgray'>\n";
}
else {
result += "<tr valign='center'>\n";
}
result += renderChilds(data);
result += "</tr>\n";
return result;
}
QString ContentView::renderEntry(ModelPtr data) const
{
ModelPtr parent = data->parent();
bool inTableHead = false;
bool inTableBody = false;
while (parent) {
if (parent->modelType()==DocBookModel::THead) {
inTableHead = true;
break;
}
if (parent->modelType()==DocBookModel::TBody) {
inTableBody = true;
break;
}
parent = parent->parent();
}
QString result;
result += "<td align='center' valign='center'>\n";
if (inTableHead) {
result += "<b>";
}
result += renderChilds(data);
if (inTableHead) {
result += "</b>";
}
result += "</td>\n";
return result;
}
QString ContentView::renderTable(ModelPtr data) const
{
QString result;
const QString & title = data->title();
counters_.table ++;
result += "<table width='100%'>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "<tr><td align='left'><b>";
result += tr("Table&nbsp;%1. ").arg(counters_.table);
result += "</b>" + title + "</td></tr>\n";
result += "<tr><td>\n";
result += renderTableContent(data);
result += "</td></tr>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "</table>\n";
return result;
}
QString ContentView::renderInformalTable(ModelPtr data) const
{
QString result;
result += renderTableContent(data);
return result;
}
......@@ -187,7 +376,10 @@ QString ContentView::renderExample(ModelPtr data) const
result += "<table width='100%'>\n";
result += "<tr><td height='10'>&nbsp;</td></tr>\n";
result += "<tr><td align='center'>\n";
result += "<table border='1' bordercolor='gray' cellspacing='0' cellpadding='10' width='100%'>";
result += "<tr><td>\n";
result += renderChilds(data);
result += "</td></tr></table>\n";
result += "</td></tr>\n";
result += "<tr><td align='center'>\n";
result += "<b>" + tr("Example&nbsp;%1. ").arg(counters_.example) + "</b>";
......@@ -239,6 +431,60 @@ QString ContentView::renderParagraph(ModelPtr data) const
return result;
}
QString ContentView::renderInlineMediaObject(ModelPtr data) const
{
QString result;
ModelPtr mediaObject = findImageData(data);
if (mediaObject) {
result += renderElement(mediaObject);
}
return result;
}
QString ContentView::renderImageObject(ModelPtr data) const
{
QString result;
ModelPtr imageData;
foreach (ModelPtr child, data->children()) {
if (child->modelType() == DocBookModel::ImageData) {
imageData = child;
break;
}
}
result += "<img src='model_ptr:"+modelToLink(imageData)+"'>";
return result;
}
QVariant ContentView::loadResource(int type, const QUrl &name)
{
QVariant result;
bool ignore = true;
if (type == QTextDocument::ImageResource) {
const QString link = name.toString();
if (link.startsWith("model_ptr:")) {
ignore = false;
QByteArray linkPtr = QByteArray::fromHex(link.toAscii().mid(10));
QDataStream ds(linkPtr);
quintptr rawPointer = 0;
ds >> rawPointer;
if (rawPointer) {
DocBookModel * model =
reinterpret_cast<DocBookModel*>(rawPointer);
if (model->modelType() == DocBookModel::ImageData) {
const QImage & image = model->imageData();
result = image;
}
}
}
}
if (ignore) {
return QTextBrowser::loadResource(type, name);
}
else {
return result;
}
}
QString ContentView::normalizeText(QString textData) const
{
static QMap<QString,QString> replacements;
......@@ -271,7 +517,10 @@ QString ContentView::renderText(ModelPtr data) const
ModelPtr parent = data->parent();
bool isPreformat = false;
while (parent) {
if (parent->modelType() == DocBookModel::ProgramListing) {
if (parent->modelType() == DocBookModel::ProgramListing
||
parent->modelType() == DocBookModel::Code
) {
isPreformat = true;
break;
}
......@@ -411,6 +660,26 @@ bool ContentView::hasChild(ModelPtr who, ModelPtr childToFind) const
return false;
}
ModelPtr ContentView::findImageData(ModelPtr parent) const
{
ModelPtr svgChild;
ModelPtr pngChild;
foreach (ModelPtr child, parent->children()) {
if (child->modelType()==DocBookModel::ImageObject) {
foreach (ModelPtr childChild, child->children()) {
if (childChild->modelType()==DocBookModel::ImageData) {
if (childChild->format() == "svg") {