diff --git a/scripts/gen_actor_source.py b/scripts/gen_actor_source.py index 2dca61037dd5a9d77d2e2239bf774f69446464ea..7aeac3599209cdb25a42d0fc310af718f84b8c8f 100755 --- a/scripts/gen_actor_source.py +++ b/scripts/gen_actor_source.py @@ -900,6 +900,9 @@ class MenuItem: else: self.icon = None + def __repr__(self): + return self.title.get_ascii_value() + class Gui: """ diff --git a/src/actors/_colorer/_colorermodule.cpp b/src/actors/_colorer/_colorermodule.cpp index 78211744ff6561f12f1713208d431cb8bd4e5c20..0c4cbc1b730e53943c93734f75e6eae47c0a9116 100644 --- a/src/actors/_colorer/_colorermodule.cpp +++ b/src/actors/_colorer/_colorermodule.cpp @@ -31,6 +31,28 @@ _ColorerModule::_ColorerModule(ExtensionSystem::KPlugin * parent) return QList(); } +const QStringList & _ColorerModule::standardRussianColorNames() +{ + static QStringList validValues; + if (validValues.isEmpty()) { + validValues << QString::fromUtf8("прозрачный"); + validValues << QString::fromUtf8("белый"); + validValues << QString::fromUtf8("черный"); + validValues << QString::fromUtf8("чёрный"); + validValues << QString::fromUtf8("серый"); + validValues << QString::fromUtf8("фиолетовый"); + validValues << QString::fromUtf8("синий"); + validValues << QString::fromUtf8("голубой"); + validValues << QString::fromUtf8("зелёный"); + validValues << QString::fromUtf8("зеленый"); + validValues << QString::fromUtf8("жёлтый"); + validValues << QString::fromUtf8("желтый"); + validValues << QString::fromUtf8("оранжевый"); + validValues << QString::fromUtf8("красный"); + } + return validValues; +} + /* public slot */ void _ColorerModule::changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current) { // Called when changed kumir state. The states are defined as enum ExtensionSystem::GlobalState: @@ -163,21 +185,8 @@ static QColor parseColor(const QString &css) /* public slot */ Color _ColorerModule::runOperatorINPUT(const QString& x, bool& ok) { /* алг цвет ввод(лит x, рез лог ok) */ - QStringList validValues; - validValues << QString::fromUtf8("прозрачный"); - validValues << QString::fromUtf8("белый"); - validValues << QString::fromUtf8("черный"); - validValues << QString::fromUtf8("чёрный"); - validValues << QString::fromUtf8("серый"); - validValues << QString::fromUtf8("фиолетовый"); - validValues << QString::fromUtf8("синий"); - validValues << QString::fromUtf8("голубой"); - validValues << QString::fromUtf8("зелёный"); - validValues << QString::fromUtf8("зеленый"); - validValues << QString::fromUtf8("жёлтый"); - validValues << QString::fromUtf8("желтый"); - validValues << QString::fromUtf8("оранжевый"); - validValues << QString::fromUtf8("красный"); + const QStringList & validValues = standardRussianColorNames(); + ok = validValues.contains(x.trimmed()); Color result; result.r = result.g = result.b = result.a = 0; if (ok) { diff --git a/src/actors/_colorer/_colorermodule.h b/src/actors/_colorer/_colorermodule.h index 0ef06cf76ba7d1ccc3ae3a36582d8e3bf01cf6af..b63d0fab8f0318dbd7f5e2bba76aef5dca9d65b8 100644 --- a/src/actors/_colorer/_colorermodule.h +++ b/src/actors/_colorer/_colorermodule.h @@ -29,6 +29,7 @@ class _ColorerModule public /* methods */: _ColorerModule(ExtensionSystem::KPlugin * parent); static QList acceptableCommandLineParameters(); + static const QStringList & standardRussianColorNames(); public slots: void changeGlobalState(ExtensionSystem::GlobalState old, ExtensionSystem::GlobalState current); void loadActorData(QIODevice * source); diff --git a/src/actors/painter/paintermodule.cpp b/src/actors/painter/paintermodule.cpp index 7a78b277a594ccf5978cd19410c108572ee7c63c..d1a50989bc3c44954b4718cc5a132a980752c27e 100644 --- a/src/actors/painter/paintermodule.cpp +++ b/src/actors/painter/paintermodule.cpp @@ -180,8 +180,10 @@ void PainterModule::runLoadPage(const QString& fileName) setError(tr("File not exists: %s").arg(fileName)); } canvas.reset(new QImage(fileName)); - if (m_window) + if (m_window) { m_window->setCanvasSize(canvas->size()); + m_window->setCanvasName(QFile(fileName).fileName()); + } markViewDirty(); } @@ -287,6 +289,11 @@ void PainterModule::runNewPage(const int width, const int height, const Color& b canvas.reset(new QImage(width,height,QImage::Format_RGB32)); canvas->fill(clr.rgb()); m_window->setCanvasSize(canvas->size()); + QString colorName = findColorName(backgroundColor); + if (colorName.length() > 0 && ! colorName.contains("(") ) { + colorName[0] = colorName[0].toUpper(); + } + m_window->setCanvasName(QString("%1 %2x%3").arg(colorName).arg(width).arg(height)); markViewDirty(); } diff --git a/src/actors/painter/paintertools.cpp b/src/actors/painter/paintertools.cpp index 1bb2bd728e8d8556e4e665cfba45dcac1f6e2b5e..4746610e906d25d8c273ad9f97f707d5bf65daee 100644 --- a/src/actors/painter/paintertools.cpp +++ b/src/actors/painter/paintertools.cpp @@ -256,4 +256,41 @@ extern QString CSS_RGB_toString(const QString &cssRgb) return result; } +const QStringList & standardRussianColorNames() +{ + static QStringList validValues; + if (validValues.isEmpty()) { + validValues << QString::fromUtf8("прозрачный"); + validValues << QString::fromUtf8("белый"); + validValues << QString::fromUtf8("черный"); + validValues << QString::fromUtf8("чёрный"); + validValues << QString::fromUtf8("серый"); + validValues << QString::fromUtf8("фиолетовый"); + validValues << QString::fromUtf8("синий"); + validValues << QString::fromUtf8("голубой"); + validValues << QString::fromUtf8("зелёный"); + validValues << QString::fromUtf8("зеленый"); + validValues << QString::fromUtf8("жёлтый"); + validValues << QString::fromUtf8("желтый"); + validValues << QString::fromUtf8("оранжевый"); + validValues << QString::fromUtf8("красный"); + } + return validValues; +} + +QString findColorName(const Actor_Colorer::Color &color) +{ + const QStringList & validValues = standardRussianColorNames(); + Q_FOREACH(const QString & name, validValues) { + const QColor test = parseColor(name).toRgb(); + bool r = test.red() == color.r; + bool g = test.green() == color.g; + bool b = test.blue() == color.b; + if (r && g && b) { + return name; + } + } + return QString("rgb(%1,%2,%3)").arg(color.r).arg(color.g).arg(color.b); +} + } diff --git a/src/actors/painter/paintertools.h b/src/actors/painter/paintertools.h index 314e5f3bd48b4e6259bfacd8926918b70cf2d2ae..9902c9a8f9350bae39eb6c68ecc268e71346ce22 100644 --- a/src/actors/painter/paintertools.h +++ b/src/actors/painter/paintertools.h @@ -8,10 +8,14 @@ #include #endif +#include "../_colorer/typecolor.h" + namespace ActorPainter { extern QColor parseColor(const QString &css); extern QString CSS_RGB_toString(const QString &cssRgb); + extern QString findColorName(const Actor_Colorer::Color & color); + extern const QStringList & standardRussianColorNames(); } diff --git a/src/actors/painter/painterwindow.cpp b/src/actors/painter/painterwindow.cpp index 4eacc71c019df4d1e81b44b8baddab19f75d2ae9..814414933c5922a242e805752ac2eaaa7a4d84cf 100644 --- a/src/actors/painter/painterwindow.cpp +++ b/src/actors/painter/painterwindow.cpp @@ -95,6 +95,11 @@ void PainterWindow::setCanvasSize(const QSize &size) } +void PainterWindow::setCanvasName(const QString &name) +{ + setWindowTitle(tr("Painter [%1]").arg(name)); +} + PainterView * PainterWindow::view() { return ui->view; @@ -199,7 +204,7 @@ void PainterWindow::newImage() s_templateName = m_newImageDialog->templateFileName(); static const QString resourcesRoot = m_module->myResourcesDir().absolutePath(); if (m_newImageDialog->isTemplate()) { - m_module->runLoadPage(resourcesRoot+s_templateName); + m_module->runLoadPage(resourcesRoot+"/"+s_templateName); } else { Color c = colorFromCss(m_newImageDialog->color()); diff --git a/src/actors/painter/painterwindow.h b/src/actors/painter/painterwindow.h index a407152c9a13ea3509a4a104767de120fc32e3bc..28a7853828cf9f9ce794f874a4e6944f5403e498 100644 --- a/src/actors/painter/painterwindow.h +++ b/src/actors/painter/painterwindow.h @@ -26,6 +26,7 @@ class PainterWindow : public QWidget public: explicit PainterWindow(PainterModule * module, QWidget *parent = 0); void setCanvasSize(const QSize & size); + void setCanvasName(const QString &name); inline QSize minimumSizeHint() const { return QSize(360, 300); } PainterView * view(); ~PainterWindow();