From f65c3d5fd706311b0e5268f033671b5973a560f6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 8 May 2022 22:27:39 +0200 Subject: [PATCH] Enabled edt, ant and img for Qt-less builds, added missing files --- src/ant/ant/ant.pro | 34 +++-- src/ant/ant/antObject.cc | 2 +- src/ant/ant/antPlugin.cc | 56 +++++--- src/ant/ant/antPlugin.h | 6 + src/ant/ant/antService.cc | 22 +-- src/ant/ant/antService.h | 2 + src/ant/ant/antTemplate.cc | 2 +- src/ant/ant/gsiDeclAnt.cc | 2 +- src/edt/edt/edt.pro | 4 +- src/edt/edt/edtMainService.cc | 2 +- src/img/img/gsiDeclImg.cc | 8 +- src/img/img/img.pro | 38 +++-- src/img/img/imgObject.cc | 87 +++++++++++- src/img/img/imgPlugin.cc | 15 +- src/img/img/imgService.cc | 37 +++-- src/img/img/imgService.h | 2 + src/laybasic/laybasic/layColor.h | 8 ++ src/laybasic/laybasic/layDragDropData.cc | 108 ++++++++++++++ src/laybasic/laybasic/layDragDropData.h | 171 +++++++++++++++++++++++ 19 files changed, 518 insertions(+), 88 deletions(-) create mode 100644 src/laybasic/laybasic/layDragDropData.cc create mode 100644 src/laybasic/laybasic/layDragDropData.h diff --git a/src/ant/ant/ant.pro b/src/ant/ant/ant.pro index 033a687ac..6232bc294 100644 --- a/src/ant/ant/ant.pro +++ b/src/ant/ant/ant.pro @@ -6,16 +6,7 @@ include($$PWD/../../lib.pri) DEFINES += MAKE_ANT_LIBRARY -HEADERS = \ - antConfig.h \ - antConfigPage.h \ - antObject.h \ - antPlugin.h \ - antPropertiesPage.h \ - antService.h \ - antTemplate.h \ - antForceLink.h \ - antCommon.h +!equals(HAVE_QT, "0") { FORMS = \ RulerConfigPage.ui \ @@ -24,16 +15,33 @@ FORMS = \ RulerConfigPage4.ui \ RulerPropertiesPage.ui \ +HEADERS = \ + antConfigPage.h \ + antPropertiesPage.h \ + SOURCES = \ - antConfig.cc \ antConfigPage.cc \ + antPropertiesPage.cc \ + +} + +HEADERS += \ + antConfig.h \ + antObject.h \ + antPlugin.h \ + antService.h \ + antTemplate.h \ + antForceLink.h \ + antCommon.h + +SOURCES += \ + antConfig.cc \ antObject.cc \ antPlugin.cc \ - antPropertiesPage.cc \ antService.cc \ antTemplate.cc \ gsiDeclAnt.cc \ - antForceLink.cc + antForceLink.cc INCLUDEPATH += $$TL_INC $$GSI_INC $$LAYBASIC_INC $$DB_INC DEPENDPATH += $$TL_INC $$GSI_INC $$LAYBASIC_INC $$DB_INC diff --git a/src/ant/ant/antObject.cc b/src/ant/ant/antObject.cc index 6f421383b..43bdf736b 100644 --- a/src/ant/ant/antObject.cc +++ b/src/ant/ant/antObject.cc @@ -284,7 +284,7 @@ public: void execute (const tl::ExpressionParserContext &context, tl::Variant &out, const std::vector &vv) const { if (vv.size () != 0) { - throw tl::EvalError (tl::to_string (QObject::tr ("Annotation function must not have arguments")), context); + throw tl::EvalError (tl::to_string (tr ("Annotation function must not have arguments")), context); } const Object &obj = mp_eval->obj (); diff --git a/src/ant/ant/antPlugin.cc b/src/ant/ant/antPlugin.cc index 330442a94..1aecb0792 100644 --- a/src/ant/ant/antPlugin.cc +++ b/src/ant/ant/antPlugin.cc @@ -22,15 +22,22 @@ #include "layPlugin.h" -#include "layAbstractMenu.h" #include "layConverters.h" -#include "layConfigurationDialog.h" #include "layDispatcher.h" -#include "antConfigPage.h" +#include "layColor.h" +#if defined(HAVE_QT) +# include "layConfigurationDialog.h" +# include "layAbstractMenu.h" +#endif #include "antConfig.h" +#if defined(HAVE_QT) +# include "antConfigPage.h" +#endif #include "antPlugin.h" -#include +#if defined(HAVE_QT) +# include +#endif namespace ant { @@ -60,7 +67,7 @@ PluginDeclaration::get_options (std::vector < std::pair (cfg_max_number_of_rulers, "-1")); options.push_back (std::pair (cfg_ruler_snap_range, "8")); - options.push_back (std::pair (cfg_ruler_color, lay::ColorConverter ().to_string (QColor ()))); + options.push_back (std::pair (cfg_ruler_color, lay::ColorConverter ().to_string (lay::Color ()))); options.push_back (std::pair (cfg_ruler_halo, "true")); options.push_back (std::pair (cfg_ruler_snap_mode, ACConverter ().to_string (lay::AC_Any))); options.push_back (std::pair (cfg_ruler_obj_snap, tl::to_string (true))); @@ -70,24 +77,26 @@ PluginDeclaration::get_options (std::vector < std::pair > PluginDeclaration::config_pages (QWidget *parent) const { std::vector > pages; - pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Rulers And Annotations|Snapping")), new ant::ConfigPage (parent))); - pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Rulers And Annotations|Appearance")), new ant::ConfigPage2 (parent))); - pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Rulers And Annotations|Angle")), new ant::ConfigPage3 (parent))); - pages.push_back (std::make_pair (tl::to_string (QObject::tr ("Rulers And Annotations|Templates")), new ant::ConfigPage4 (parent))); + pages.push_back (std::make_pair (tl::to_string (tr ("Rulers And Annotations|Snapping")), new ant::ConfigPage (parent))); + pages.push_back (std::make_pair (tl::to_string (tr ("Rulers And Annotations|Appearance")), new ant::ConfigPage2 (parent))); + pages.push_back (std::make_pair (tl::to_string (tr ("Rulers And Annotations|Angle")), new ant::ConfigPage3 (parent))); + pages.push_back (std::make_pair (tl::to_string (tr ("Rulers And Annotations|Templates")), new ant::ConfigPage4 (parent))); return pages; } +#endif void PluginDeclaration::get_menu_entries (std::vector &menu_entries) const { lay::PluginDeclaration::get_menu_entries (menu_entries); menu_entries.push_back (lay::separator ("rulers_group", "edit_menu.end")); - menu_entries.push_back (lay::menu_item ("ant::clear_all_rulers", "clear_all_rulers:edit", "edit_menu.end", tl::to_string (QObject::tr ("Clear All Rulers And Annotations(Ctrl+K)")))); - menu_entries.push_back (lay::menu_item ("ant::configure", "configure_rulers", "edit_menu.end", tl::to_string (QObject::tr ("Ruler And Annotation Setup")))); + menu_entries.push_back (lay::menu_item ("ant::clear_all_rulers", "clear_all_rulers:edit", "edit_menu.end", tl::to_string (tr ("Clear All Rulers And Annotations(Ctrl+K)")))); + menu_entries.push_back (lay::menu_item ("ant::configure", "configure_rulers", "edit_menu.end", tl::to_string (tr ("Ruler And Annotation Setup")))); } lay::Plugin * @@ -101,9 +110,11 @@ PluginDeclaration::menu_activated (const std::string &symbol) const { if (symbol == "ant::configure") { +#if defined(HAVE_QT) lay::ConfigurationDialog config_dialog (QApplication::activeWindow (), lay::Dispatcher::instance (), "ant::Plugin"); config_dialog.exec (); - +#endif + return true; } else { @@ -114,14 +125,14 @@ PluginDeclaration::menu_activated (const std::string &symbol) const bool PluginDeclaration::implements_editable (std::string &title) const { - title = tl::to_string (QObject::tr ("Rulers And Annotations")); + title = tl::to_string (tr ("Rulers And Annotations")); return true; } bool PluginDeclaration::implements_mouse_mode (std::string &title) const { - title = "ruler:ruler_mode_group:ruler_templates_group\t" + tl::to_string (QObject::tr ("Ruler{Add rulers and annotations}")) + "<:ruler.png>"; + title = "ruler:ruler_mode_group:ruler_templates_group\t" + tl::to_string (tr ("Ruler{Add rulers and annotations}")) + "<:ruler.png>"; return true; } @@ -182,17 +193,17 @@ PluginDeclaration::initialized (lay::Dispatcher *root) // Set up the templates we want to see (plus some non-categorized templates) - m_templates.push_back (ant::Template (tl::to_string (QObject::tr ("Ruler")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_ruler")); + m_templates.push_back (ant::Template (tl::to_string (tr ("Ruler")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_ruler")); - m_templates.push_back (ant::Template (tl::to_string (QObject::tr ("Cross")), "", "", "$U,$V", ant::Object::STY_cross_both, ant::Object::OL_diag, true, lay::AC_Global, "_cross")); + m_templates.push_back (ant::Template (tl::to_string (tr ("Cross")), "", "", "$U,$V", ant::Object::STY_cross_both, ant::Object::OL_diag, true, lay::AC_Global, "_cross")); m_templates.back ().set_mode (ant::Template::RulerSingleClick); - m_templates.push_back (ant::Template (tl::to_string (QObject::tr ("Measure")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure")); + m_templates.push_back (ant::Template (tl::to_string (tr ("Measure")), "$X", "$Y", "$D", ant::Object::STY_ruler, ant::Object::OL_diag, true, lay::AC_Global, "_measure")); m_templates.back ().set_mode (ant::Template::RulerAutoMetric); - m_templates.push_back (ant::Template (tl::to_string (QObject::tr ("Ellipse")), "W=$(abs(X))", "H=$(abs(Y))", "", ant::Object::STY_line, ant::Object::OL_ellipse, true, lay::AC_Global, std::string ())); + m_templates.push_back (ant::Template (tl::to_string (tr ("Ellipse")), "W=$(abs(X))", "H=$(abs(Y))", "", ant::Object::STY_line, ant::Object::OL_ellipse, true, lay::AC_Global, std::string ())); - m_templates.push_back (ant::Template (tl::to_string (QObject::tr ("Box")), "W=$(abs(X))", "H=$(abs(Y))", "", ant::Object::STY_line, ant::Object::OL_box, true, lay::AC_Global, std::string ())); + m_templates.push_back (ant::Template (tl::to_string (tr ("Box")), "W=$(abs(X))", "H=$(abs(Y))", "", ant::Object::STY_line, ant::Object::OL_box, true, lay::AC_Global, std::string ())); root->config_set (cfg_ruler_templates, ant::TemplatesConverter ().to_string (m_templates)); root->config_end (); @@ -203,12 +214,15 @@ PluginDeclaration::initialized (lay::Dispatcher *root) void PluginDeclaration::uninitialize (lay::Dispatcher *) { +#if defined(HAVE_QT) m_actions.clear (); +#endif } void PluginDeclaration::update_current_template () { +#if defined(HAVE_QT) lay::Dispatcher *mp = lay::Dispatcher::instance (); if (! mp || ! mp->has_ui ()) { return; @@ -234,11 +248,13 @@ PluginDeclaration::update_current_template () } } +#endif } void PluginDeclaration::update_menu () { +#if defined(HAVE_QT) lay::Dispatcher *mp = lay::Dispatcher::instance (); if (! mp || ! mp->has_ui ()) { return; @@ -278,7 +294,7 @@ PluginDeclaration::update_menu () } } } - +#endif } void diff --git a/src/ant/ant/antPlugin.h b/src/ant/ant/antPlugin.h index 6d65c03e6..9e7e5e943 100644 --- a/src/ant/ant/antPlugin.h +++ b/src/ant/ant/antPlugin.h @@ -31,6 +31,8 @@ namespace ant { +class Template; + class PluginDeclaration : public lay::PluginDeclaration { @@ -44,7 +46,9 @@ public: virtual bool implements_editable (std::string &title) const; virtual bool implements_mouse_mode (std::string &title) const; virtual bool configure (const std::string &name, const std::string &value); +#if defined(HAVE_QT) virtual std::vector > config_pages (QWidget *parent) const; +#endif virtual void config_finalize (); virtual void initialized (lay::Dispatcher *); virtual void uninitialize (lay::Dispatcher *); @@ -60,7 +64,9 @@ private: std::vector m_templates; int m_current_template; +#if defined(HAVE_QT) tl::weak_collection m_actions; +#endif bool m_current_template_updated; bool m_templates_updated; }; diff --git a/src/ant/ant/antService.cc b/src/ant/ant/antService.cc index 5c6db1ec2..3208df850 100644 --- a/src/ant/ant/antService.cc +++ b/src/ant/ant/antService.cc @@ -32,9 +32,13 @@ #include "laybasicConfig.h" #include "layConverters.h" #include "layLayoutCanvas.h" -#include "layProperties.h" +#if defined(HAVE_QT) +# include "layProperties.h" +#endif #include "antService.h" -#include "antPropertiesPage.h" +#if defined(HAVE_QT) +# include "antPropertiesPage.h" +#endif #include "antConfig.h" namespace ant @@ -1525,7 +1529,7 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio // begin the transaction tl_assert (! manager ()->transacting ()); - manager ()->transaction (tl::to_string (QObject::tr ("Create ruler"))); + manager ()->transaction (tl::to_string (tr ("Create ruler"))); m_current = ant::Object (pt, pt, 0, tpl); show_message (); @@ -1562,7 +1566,7 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio // begin the transaction tl_assert (! manager ()->transacting ()); - manager ()->transaction (tl::to_string (QObject::tr ("Create ruler"))); + manager ()->transaction (tl::to_string (tr ("Create ruler"))); m_current = ant::Object (ee.first, ee.second, 0, tpl); show_message (); @@ -1598,7 +1602,7 @@ Service::mouse_click_event (const db::DPoint &p, unsigned int buttons, bool prio // begin the transaction tl_assert (! manager ()->transacting ()); - manager ()->transaction (tl::to_string (QObject::tr ("Create ruler"))); + manager ()->transaction (tl::to_string (tr ("Create ruler"))); show_message (); @@ -2160,19 +2164,21 @@ Service::display_status (bool transient) std::string msg; if (! transient) { - msg = tl::to_string (QObject::tr ("selected: ")); + msg = tl::to_string (tr ("selected: ")); } - msg += tl::sprintf (tl::to_string (QObject::tr ("annotation(d=%s x=%s y=%s)")), ruler->text (), ruler->text_x (), ruler->text_y ()); + msg += tl::sprintf (tl::to_string (tr ("annotation(d=%s x=%s y=%s)")), ruler->text (), ruler->text_x (), ruler->text_y ()); view ()->message (msg); } } +#if defined(HAVE_QT) lay::PropertiesPage * Service::properties_page (db::Manager *manager, QWidget *parent) { return new PropertiesPage (this, manager, parent); } +#endif void Service::get_selection (std::vector &sel) const @@ -2248,7 +2254,7 @@ Service::menu_activated (const std::string &symbol) if (symbol == "ant::clear_all_rulers_internal") { clear_rulers (); } else if (symbol == "ant::clear_all_rulers") { - manager ()->transaction (tl::to_string (QObject::tr ("Clear all rulers"))); + manager ()->transaction (tl::to_string (tr ("Clear all rulers"))); clear_rulers (); manager ()->commit (); } else { diff --git a/src/ant/ant/antService.h b/src/ant/ant/antService.h index e289800fc..d6b3f30b3 100644 --- a/src/ant/ant/antService.h +++ b/src/ant/ant/antService.h @@ -346,10 +346,12 @@ public: */ virtual void transform (const db::DCplxTrans &trans); +#if defined(HAVE_QT) /** * @brief Create the properties page */ virtual lay::PropertiesPage *properties_page (db::Manager *manager, QWidget *parent); +#endif /** * @brief Get the selection for the properties page diff --git a/src/ant/ant/antTemplate.cc b/src/ant/ant/antTemplate.cc index e47f523c7..390a4b8a9 100644 --- a/src/ant/ant/antTemplate.cc +++ b/src/ant/ant/antTemplate.cc @@ -31,7 +31,7 @@ namespace ant { Template::Template () - : m_title (tl::to_string (QObject::tr ("Ruler"))), + : m_title (tl::to_string (tr ("Ruler"))), m_fmt_x ("$X"), m_fmt_y ("$Y"), m_fmt ("$D"), m_style (ant::Object::STY_ruler), m_outline (ant::Object::OL_diag), m_snap (true), m_angle_constraint (lay::AC_Global), diff --git a/src/ant/ant/gsiDeclAnt.cc b/src/ant/ant/gsiDeclAnt.cc index a6f28c1a9..325867bc0 100644 --- a/src/ant/ant/gsiDeclAnt.cc +++ b/src/ant/ant/gsiDeclAnt.cc @@ -171,7 +171,7 @@ static void clear_annotations (lay::LayoutView *view) static void insert_annotation (lay::LayoutView *view, AnnotationRef *obj) { if (obj->is_valid ()) { - throw tl::Exception (tl::to_string (QObject::tr ("The object is already inserted into a view - detach the object first or create a different object."))); + throw tl::Exception (tl::to_string (tr ("The object is already inserted into a view - detach the object first or create a different object."))); } ant::Service *ant_service = view->get_plugin (); diff --git a/src/edt/edt/edt.pro b/src/edt/edt/edt.pro index 6f2e989af..50ab9a827 100644 --- a/src/edt/edt/edt.pro +++ b/src/edt/edt/edt.pro @@ -49,7 +49,7 @@ DEFINES += MAKE_EDT_LIBRARY } -HEADERS = \ +HEADERS += \ edtConfig.h \ edtMainService.h \ edtPartialService.h \ @@ -60,7 +60,7 @@ HEADERS = \ edtCommon.h \ edtDistribute.h \ -SOURCES = \ +SOURCES += \ edtConfig.cc \ edtMainService.cc \ edtPartialService.cc \ diff --git a/src/edt/edt/edtMainService.cc b/src/edt/edt/edtMainService.cc index 99a39e017..955af10f5 100644 --- a/src/edt/edt/edtMainService.cc +++ b/src/edt/edt/edtMainService.cc @@ -402,7 +402,7 @@ MainService::cm_flatten_insts () #if defined(HAVE_QT) if (! (flatten_inst_options_dialog ()->exec_dialog (m_flatten_insts_levels, m_flatten_prune) && m_flatten_insts_levels != 0)) { - return + return; } #endif diff --git a/src/img/img/gsiDeclImg.cc b/src/img/img/gsiDeclImg.cc index 0033c38ec..13413edfb 100644 --- a/src/img/img/gsiDeclImg.cc +++ b/src/img/img/gsiDeclImg.cc @@ -1103,7 +1103,7 @@ static void show_image (lay::LayoutView *view, size_t id, bool visible) const img::Object *img = img_service->object_by_id (id); if (img == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("The image Id is not valid"))); + throw tl::Exception (tl::to_string (tr ("The image Id is not valid"))); } img::Object new_img (*img); @@ -1121,7 +1121,7 @@ void replace_image_base (lay::LayoutView *view, size_t id, ImageRef &new_obj) const img::Object *img = img_service->object_by_id (id); if (img == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("The image Id is not valid"))); + throw tl::Exception (tl::to_string (tr ("The image Id is not valid"))); } img_service->change_image_by_id (id, new_obj); @@ -1141,7 +1141,7 @@ void erase_image_base (lay::LayoutView *view, size_t id) const img::Object *img = img_service->object_by_id (id); if (img == 0) { - throw tl::Exception (tl::to_string (QObject::tr ("The image Id is not valid"))); + throw tl::Exception (tl::to_string (tr ("The image Id is not valid"))); } img_service->erase_image_by_id (id); @@ -1157,7 +1157,7 @@ static void erase_image (lay::LayoutView *view, size_t id) static void insert_image (lay::LayoutView *view, ImageRef &obj) { if (obj.is_valid ()) { - throw tl::Exception (tl::to_string (QObject::tr ("The object is already inserted into a view - detach the object first or create a different object."))); + throw tl::Exception (tl::to_string (tr ("The object is already inserted into a view - detach the object first or create a different object."))); } img::Service *img_service = view->get_plugin (); diff --git a/src/img/img/img.pro b/src/img/img/img.pro index c5337e156..13eb01db9 100644 --- a/src/img/img/img.pro +++ b/src/img/img/img.pro @@ -6,34 +6,42 @@ include($$PWD/../../lib.pri) DEFINES += MAKE_IMG_LIBRARY -HEADERS = \ - imgLandmarksDialog.h \ - imgNavigator.h \ - imgObject.h \ - imgPlugin.h \ - imgPropertiesPage.h \ - imgService.h \ - imgWidgets.h \ - imgForceLink.h \ - imgCommon.h \ - imgStream.h +!equals(HAVE_QT, "0") { FORMS = \ AddNewImageDialog.ui \ ImageLandmarksDialog.ui \ ImagePropertiesPage.ui \ +HEADERS = \ + imgLandmarksDialog.h \ + imgNavigator.h \ + imgPropertiesPage.h \ + imgWidgets.h \ + SOURCES = \ - gsiDeclImg.cc \ imgLandmarksDialog.cc \ imgNavigator.cc \ + imgPropertiesPage.cc \ + imgWidgets.cc \ + +} + +HEADERS += \ + imgObject.h \ + imgPlugin.h \ + imgService.h \ + imgForceLink.h \ + imgCommon.h \ + imgStream.h + +SOURCES += \ + gsiDeclImg.cc \ imgObject.cc \ imgPlugin.cc \ - imgPropertiesPage.cc \ imgService.cc \ - imgWidgets.cc \ imgForceLink.cc \ - imgStream.cc + imgStream.cc INCLUDEPATH += $$TL_INC $$DB_INC $$GSI_INC $$LAYBASIC_INC $$DB_INC DEPENDPATH += $$TL_INC $$DB_INC $$GSI_INC $$LAYBASIC_INC $$DB_INC diff --git a/src/img/img/imgObject.cc b/src/img/img/imgObject.cc index 7f265252c..333789e86 100644 --- a/src/img/img/imgObject.cc +++ b/src/img/img/imgObject.cc @@ -22,12 +22,12 @@ #include "imgObject.h" -#include "imgWidgets.h" // for interpolate_color() #include "imgStream.h" #include "tlLog.h" #include "tlTimer.h" #include "layPlugin.h" #include "layConverters.h" +#include "layPixelBuffer.h" #include "dbPolygonTools.h" #include "tlFileUtils.h" #include "tlUri.h" @@ -40,7 +40,9 @@ #include #include -#include +#if defined(HAVE_QT) +# include +#endif namespace img { @@ -1557,6 +1559,8 @@ Object::read_file () // continue with other formats ... } +#if defined(HAVE_QT) + QImage qimage (tl::to_qstring (m_filename)); if (! qimage.isNull ()) { @@ -1617,6 +1621,85 @@ Object::read_file () } } + +#elif defined(HAVE_PNG) + + lay::PixelBuffer img; + + { + tl::InputStream stream (m_filename); + img = lay::PixelBuffer::read_png (stream); + } + + bool is_color = false; + for (unsigned int i = 0; i < img.height () && ! is_color; ++i) { + const lay::color_t *d = img.scan_line (i); + const lay::color_t *dd = d + img.width (); + while (! is_color && d != dd) { + lay::color_t c = *d++; + is_color = (((c >> 8) ^ c) & 0xffff) != 0; + } + } + + if (! m_min_value_set) { + m_min_value = 0.0; + } + + if (! m_max_value_set) { + m_max_value = 255.0; + } + + m_min_value_set = true; + m_max_value_set = true; + + unsigned int w = img.width (), h = img.height (); + + mp_data = new DataHeader (w, h, is_color, true); + mp_data->add_ref (); + + if (is_color) { + + unsigned char *red = mp_data->byte_data (0); + unsigned char *green = mp_data->byte_data (1); + unsigned char *blue = mp_data->byte_data (2); + unsigned char *msk = img.transparent () ? mp_data->set_mask () : 0; + + for (unsigned int y = 0; y < h; ++y) { + const lay::color_t *d = img.scan_line (h - y - 1); + const lay::color_t *dd = d + img.width (); + while (d != dd) { + lay::color_t rgb = *d++; + *red++ = lay::red (rgb); + *green++ = lay::green (rgb); + *blue++ = lay::blue (rgb); + if (msk) { + *msk++ = lay::alpha (rgb) > 128; + } + } + } + + } else { + + unsigned char *mono = mp_data->byte_data (); + unsigned char *msk = img.transparent () ? mp_data->set_mask () : 0; + + for (unsigned int y = 0; y < h; ++y) { + const lay::color_t *d = img.scan_line (h - y - 1); + const lay::color_t *dd = d + img.width (); + while (d != dd) { + lay::color_t rgb = *d++; + *mono++ = lay::green (rgb); + if (msk) { + *msk++ = lay::alpha (rgb) > 128; + } + } + } + + } + +#else + throw tl::Exception (tl::to_string ("No PNG support compiled in - cannot load PNG files")); +#endif } void diff --git a/src/img/img/imgPlugin.cc b/src/img/img/imgPlugin.cc index 74d710786..4936406f0 100644 --- a/src/img/img/imgPlugin.cc +++ b/src/img/img/imgPlugin.cc @@ -22,7 +22,6 @@ #include "layPlugin.h" -#include "layAbstractMenu.h" #include "imgService.h" #include "imgPlugin.h" @@ -36,12 +35,12 @@ PluginDeclaration::get_menu_entries (std::vector &menu_entries) { lay::PluginDeclaration::get_menu_entries (menu_entries); menu_entries.push_back (lay::separator ("image_group", "edit_menu.end")); - menu_entries.push_back (lay::menu_item ("img::add_image", "add_image:edit", "edit_menu.end", tl::to_string (QObject::tr ("Add Image")))); - menu_entries.push_back (lay::submenu ("img::image_menu", "image_menu:edit", "edit_menu.end", tl::to_string (QObject::tr ("Images")))); - menu_entries.push_back (lay::menu_item ("img::bring_to_front", "bring_to_front:edit", "edit_menu.image_menu.end", tl::to_string (QObject::tr ("Image Stack: Selected Images to Front")))); - menu_entries.push_back (lay::menu_item ("img::bring_to_back", "bring_to_back:edit", "edit_menu.image_menu.end", tl::to_string (QObject::tr ("Image Stack: Selected Images to Back")))); - menu_entries.push_back (lay::menu_item ("img::clear_all_images", "clear_all_images:edit", "edit_menu.image_menu.end", tl::to_string (QObject::tr ("Clear All Images")))); - menu_entries.push_back (lay::config_menu_item ("show_images", "view_menu.layout_group+", tl::to_string (QObject::tr ("Show Images")), cfg_images_visible, "?")); + menu_entries.push_back (lay::menu_item ("img::add_image", "add_image:edit", "edit_menu.end", tl::to_string (tr ("Add Image")))); + menu_entries.push_back (lay::submenu ("img::image_menu", "image_menu:edit", "edit_menu.end", tl::to_string (tr ("Images")))); + menu_entries.push_back (lay::menu_item ("img::bring_to_front", "bring_to_front:edit", "edit_menu.image_menu.end", tl::to_string (tr ("Image Stack: Selected Images to Front")))); + menu_entries.push_back (lay::menu_item ("img::bring_to_back", "bring_to_back:edit", "edit_menu.image_menu.end", tl::to_string (tr ("Image Stack: Selected Images to Back")))); + menu_entries.push_back (lay::menu_item ("img::clear_all_images", "clear_all_images:edit", "edit_menu.image_menu.end", tl::to_string (tr ("Clear All Images")))); + menu_entries.push_back (lay::config_menu_item ("show_images", "view_menu.layout_group+", tl::to_string (tr ("Show Images")), cfg_images_visible, "?")); } lay::Plugin * @@ -53,7 +52,7 @@ PluginDeclaration::create_plugin (db::Manager *manager, lay::Dispatcher *, lay:: bool PluginDeclaration::implements_editable (std::string &title) const { - title = tl::to_string (QObject::tr ("Images")); + title = tl::to_string (tr ("Images")); return true; } diff --git a/src/img/img/imgService.cc b/src/img/img/imgService.cc index 68fcb1a9f..4ae8ff5ac 100644 --- a/src/img/img/imgService.cc +++ b/src/img/img/imgService.cc @@ -32,22 +32,28 @@ #include "laySnap.h" #include "layLayoutView.h" #include "laybasicConfig.h" -#include "layLayoutCanvas.h" -#include "layProperties.h" -#include "layTipDialog.h" +#if defined(HAVE_QT) +# include "layProperties.h" +# include "layTipDialog.h" +#endif #include "tlExceptions.h" #include "imgService.h" #include "imgPlugin.h" -#include "ui_AddNewImageDialog.h" +#if defined(HAVE_QT) +# include "ui_AddNewImageDialog.h" +#endif -#include +#if defined(HAVE_QT) +# include +#endif namespace img { // ------------------------------------------------------------- -class AddNewImageDialog +#if defined(HAVE_QT) +class AddNewImageDialog : public QDialog, public Ui::AddNewImageDialog { @@ -68,7 +74,7 @@ public: properties_frame->apply (); if (mp_image_object->is_empty ()) { - throw tl::Exception (tl::to_string (QObject::tr ("No data loaded for that image"))); + throw tl::Exception (tl::to_string (tr ("No data loaded for that image"))); } QDialog::accept (); @@ -79,6 +85,7 @@ public: private: img::Object *mp_image_object; }; +#endif // ------------------------------------------------------------- @@ -1361,19 +1368,21 @@ Service::display_status (bool transient) std::string msg; if (! transient) { - msg = tl::to_string (QObject::tr ("selected: ")); + msg = tl::to_string (tr ("selected: ")); } - msg += tl::sprintf (tl::to_string (QObject::tr ("image(%dx%d)")), image->width (), image->height ()); + msg += tl::sprintf (tl::to_string (tr ("image(%dx%d)")), image->width (), image->height ()); view ()->message (msg); } } +#if defined(HAVE_QT) lay::PropertiesPage * Service::properties_page (db::Manager *manager, QWidget *parent) { return new img::PropertiesPage (this, manager, parent); } +#endif void Service::get_selection (std::vector &sel) const @@ -1463,15 +1472,16 @@ Service::menu_activated (const std::string &symbol) { if (symbol == "img::clear_all_images") { - manager ()->transaction (tl::to_string (QObject::tr ("Clear all images"))); + manager ()->transaction (tl::to_string (tr ("Clear all images"))); clear_images (); manager ()->commit (); } else if (symbol == "img::add_image") { +#if defined(HAVE_QT) if (! images_visible ()) { lay::TipDialog td (QApplication::activeWindow (), - tl::to_string (QObject::tr ("Images are not visible. If you add an image you will not see it.\n\n" + tl::to_string (tr ("Images are not visible. If you add an image you will not see it.\n\n" "Choose 'View/Show Images' to make images visible.")), "add-image-while-not-visible", lay::TipDialog::okcancel_buttons); @@ -1482,6 +1492,7 @@ Service::menu_activated (const std::string &symbol) return; } } +#endif add_image (); @@ -1573,6 +1584,7 @@ Service::top_z_position () const void Service::add_image () { +#if defined(HAVE_QT) img::Object *new_image = new img::Object (); AddNewImageDialog dialog (QApplication::activeWindow (), new_image); @@ -1580,7 +1592,7 @@ Service::add_image () clear_selection (); - manager ()->transaction (tl::to_string (QObject::tr ("Add image"))); + manager ()->transaction (tl::to_string (tr ("Add image"))); new_image->set_z_position (top_z_position ()); mp_view->annotation_shapes ().insert (db::DUserObject (new_image)); manager ()->commit (); @@ -1588,6 +1600,7 @@ Service::add_image () } else { delete new_image; } +#endif } void diff --git a/src/img/img/imgService.h b/src/img/img/imgService.h index 65e7bfa70..56f70fda6 100644 --- a/src/img/img/imgService.h +++ b/src/img/img/imgService.h @@ -369,10 +369,12 @@ public: */ virtual void transform (const db::DCplxTrans &trans); +#if defined(HAVE_QT) /** * @brief Create the properties page */ virtual lay::PropertiesPage *properties_page (db::Manager *manager, QWidget *parent); +#endif /** * @brief Get the selection for the properties page diff --git a/src/laybasic/laybasic/layColor.h b/src/laybasic/laybasic/layColor.h index 1be4ae0b1..48766d3e0 100644 --- a/src/laybasic/laybasic/layColor.h +++ b/src/laybasic/laybasic/layColor.h @@ -37,6 +37,14 @@ namespace lay */ typedef uint32_t color_t; +/** + * @brief Gets the color components from a color_t + */ +inline unsigned int alpha (color_t c) { return (c >> 24) & 0xff; } +inline unsigned int red (color_t c) { return (c >> 16) & 0xff; } +inline unsigned int green (color_t c) { return (c >> 8) & 0xff; } +inline unsigned int blue (color_t c) { return c & 0xff; } + /** * @brief A wrapper for a color value * diff --git a/src/laybasic/laybasic/layDragDropData.cc b/src/laybasic/laybasic/layDragDropData.cc new file mode 100644 index 000000000..76ceadf80 --- /dev/null +++ b/src/laybasic/laybasic/layDragDropData.cc @@ -0,0 +1,108 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2022 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "layDragDropData.h" + +#include +#include + +namespace lay +{ + +// --------------------------------------------------------------- +// Implementation of DragDropDataBase + +const char *drag_drop_mime_type () +{ + return "application/klayout-ddd"; +} + +QMimeData * +DragDropDataBase::to_mime_data () const +{ + QMimeData *mimeData = new QMimeData(); + mimeData->setData (QString::fromUtf8 (drag_drop_mime_type ()), serialized ()); + return mimeData; +} + +// --------------------------------------------------------------- +// Implementation of CellDragDropData + +QByteArray +CellDragDropData::serialized () const +{ + QByteArray data; + QDataStream stream (&data, QIODevice::WriteOnly); + + stream << QString::fromUtf8 ("CellDragDropData"); + stream << (quintptr) mp_layout; + stream << (quintptr) mp_library; + stream << m_cell_index; + stream << m_is_pcell; + stream << int (m_pcell_params.size ()); + for (std::vector::const_iterator i = m_pcell_params.begin (); i != m_pcell_params.end (); ++i) { + stream << tl::to_qstring (i->to_parsable_string ()); + } + + return data; +} + +bool +CellDragDropData::deserialize (const QByteArray &ba) +{ + QDataStream stream (const_cast (&ba), QIODevice::ReadOnly); + + QString tag; + stream >> tag; + + if (tag == QString::fromUtf8 ("CellDragDropData")) { + + quintptr p = 0; + stream >> p; + mp_layout = reinterpret_cast (p); + stream >> p; + mp_library = reinterpret_cast (p); + stream >> m_cell_index; + stream >> m_is_pcell; + + m_pcell_params.clear (); + int n = 0; + stream >> n; + while (n-- > 0) { + QString s; + stream >> s; + std::string stl_s = tl::to_string (s); + tl::Extractor ex (stl_s.c_str ()); + m_pcell_params.push_back (tl::Variant ()); + ex.read (m_pcell_params.back ()); + } + + return true; + + } else { + + return false; + + } +} + +} diff --git a/src/laybasic/laybasic/layDragDropData.h b/src/laybasic/laybasic/layDragDropData.h new file mode 100644 index 000000000..c830debe3 --- /dev/null +++ b/src/laybasic/laybasic/layDragDropData.h @@ -0,0 +1,171 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2022 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_layDragDropData +#define HDR_layDragDropData + +#include "laybasicCommon.h" + +#include "dbLayout.h" +#include "dbLibrary.h" + +#include +#include + +#include + +namespace lay +{ + +LAYBASIC_PUBLIC const char *drag_drop_mime_type (); + +/** + * @brief A helper class required to store the drag/drop data + * + * Drag/drop data is basically a collection of key/value pairs. + * A category string is provided to identify the kind of data. + */ + +class LAYBASIC_PUBLIC DragDropDataBase +{ +public: + /** + * @brief Default constructor + */ + DragDropDataBase () { } + + /** + * @brief Dtor + */ + virtual ~DragDropDataBase () { } + + /** + * @brief Serializes itself to an QByteArray + */ + virtual QByteArray serialized () const = 0; + + /** + * @brief Try deserialization from an QByteArray + * + * Returns false, if deserialization failed. + */ + virtual bool deserialize (const QByteArray &ba) = 0; + + /** + * @brief Create a QMimeData object from the object + */ + QMimeData *to_mime_data () const; +}; + +/** + * @brief Drag/drop data for a cell + */ + +class LAYBASIC_PUBLIC CellDragDropData + : public DragDropDataBase +{ +public: + /** + * @brief Default ctor + */ + CellDragDropData () + : mp_layout (0), mp_library (0), m_cell_index (0), m_is_pcell (false) + { + // .. nothing yet .. + } + + /** + * @brief Specifies drag & drop of a cell + * + * @param layout the layout where the cell lives in + * @param cell_index The index of the cell + */ + CellDragDropData (const db::Layout *layout, const db::Library *library, db::cell_index_type cell_or_pcell_index, bool is_pcell, const std::vector &pcell_params = std::vector ()) + : mp_layout (layout), mp_library (library), m_cell_index (cell_or_pcell_index), m_is_pcell (is_pcell), m_pcell_params (pcell_params) + { + // .. nothing yet .. + } + + /** + * @brief Gets the layout object where the cell lives in + */ + const db::Layout *layout () const + { + return mp_layout; + } + + /** + * @brief Gets the layout object where the cell lives in + */ + const db::Library *library () const + { + return mp_library; + } + + /** + * @brief PCell parameters + */ + const std::vector &pcell_params () const + { + return m_pcell_params; + } + + /** + * @brief Gets the index of the cell + */ + db::cell_index_type cell_index () const + { + return m_cell_index; + } + + /** + * @brief Gets a value indicating whether the cell is a pcell + */ + bool is_pcell () const + { + return m_is_pcell; + } + + /** + * @brief Serializes itself to an QByteArray + */ + virtual QByteArray serialized () const; + + /** + * @brief Try deserialization from an QByteArray + * + * Returns false, if deserialization failed. + */ + bool deserialize (const QByteArray &ba); + +private: + const db::Layout *mp_layout; + const db::Library *mp_library; + db::cell_index_type m_cell_index; + bool m_is_pcell; + std::vector m_pcell_params; +}; + +} + +#endif