summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/template-widget.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/ui/dialog/template-widget.cpp
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ui/dialog/template-widget.cpp')
-rw-r--r--src/ui/dialog/template-widget.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/ui/dialog/template-widget.cpp b/src/ui/dialog/template-widget.cpp
new file mode 100644
index 0000000..595e74a
--- /dev/null
+++ b/src/ui/dialog/template-widget.cpp
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * @brief New From Template - templates widget - implementation
+ */
+/* Authors:
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof KosiƄski
+ *
+ * Copyright (C) 2013 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include "template-widget.h"
+
+#include <glibmm/miscutils.h>
+#include <gtkmm/messagedialog.h>
+
+#include "desktop.h"
+#include "document.h"
+#include "document-undo.h"
+#include "file.h"
+#include "inkscape.h"
+
+#include "extension/implementation/implementation.h"
+
+#include "object/sp-namedview.h"
+
+namespace Inkscape {
+namespace UI {
+
+
+TemplateWidget::TemplateWidget()
+ : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
+ , _more_info_button(_("More info"))
+ , _short_description_label(" ")
+ , _template_name_label(_("no template selected"))
+ , _effect_prefs(nullptr)
+ , _preview_box(Gtk::ORIENTATION_HORIZONTAL)
+{
+ pack_start(_template_name_label, Gtk::PACK_SHRINK, 10);
+ pack_start(_preview_box, Gtk::PACK_SHRINK, 0);
+
+ _preview_box.pack_start(_preview_image, Gtk::PACK_EXPAND_PADDING, 15);
+ _preview_box.pack_start(_preview_render, Gtk::PACK_EXPAND_PADDING, 10);
+
+ _short_description_label.set_line_wrap(true);
+
+ _more_info_button.set_halign(Gtk::ALIGN_END);
+ _more_info_button.set_valign(Gtk::ALIGN_CENTER);
+ pack_end(_more_info_button, Gtk::PACK_SHRINK);
+
+ pack_end(_short_description_label, Gtk::PACK_SHRINK, 5);
+
+ _more_info_button.signal_clicked().connect(
+ sigc::mem_fun(*this, &TemplateWidget::_displayTemplateDetails));
+ _more_info_button.set_sensitive(false);
+}
+
+
+void TemplateWidget::create()
+{
+ if (_current_template.display_name == "")
+ return;
+
+ if (_current_template.is_procedural){
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ SPDesktop *desc = sp_file_new_default();
+ _current_template.tpl_effect->effect(desc);
+ DocumentUndo::clearUndo(desc->getDocument());
+ desc->getDocument()->setModifiedSinceSave(false);
+
+ // Apply cx,cy etc. from document
+ sp_namedview_window_from_document( desc );
+
+ if (desktop)
+ desktop->clearWaitingCursor();
+ }
+ else {
+ sp_file_new(_current_template.path);
+ }
+}
+
+
+void TemplateWidget::display(TemplateLoadTab::TemplateData data)
+{
+ clear();
+ _current_template = data;
+
+ _template_name_label.set_text(_current_template.display_name);
+ _short_description_label.set_text(_current_template.short_description);
+
+ if (data.preview_name != ""){
+ std::string imagePath = Glib::build_filename(Glib::path_get_dirname(_current_template.path),
+ Glib::filename_from_utf8(_current_template.preview_name));
+ _preview_image.set(imagePath);
+ _preview_image.show();
+ }
+ else if (!data.is_procedural){
+ Glib::ustring gPath = data.path.c_str();
+ _preview_render.showImage(gPath);
+ _preview_render.show();
+ }
+
+ if (data.is_procedural){
+ _effect_prefs = data.tpl_effect->get_imp()->prefs_effect(data.tpl_effect, SP_ACTIVE_DESKTOP, nullptr, nullptr);
+ pack_start(*_effect_prefs);
+ }
+ _more_info_button.set_sensitive(true);
+}
+
+void TemplateWidget::clear()
+{
+ _template_name_label.set_text("");
+ _short_description_label.set_text("");
+ _preview_render.hide();
+ _preview_image.hide();
+ if (_effect_prefs != nullptr){
+ remove (*_effect_prefs);
+ _effect_prefs = nullptr;
+ }
+ _more_info_button.set_sensitive(false);
+}
+
+void TemplateWidget::_displayTemplateDetails()
+{
+ Glib::ustring message = _current_template.display_name + "\n\n";
+
+ if (!_current_template.author.empty()) {
+ message += _("Author");
+ message += ": ";
+ message += _current_template.author + " " + _current_template.creation_date + "\n\n";
+ }
+
+ if (!_current_template.keywords.empty()){
+ message += _("Keywords");
+ message += ":";
+ for (const auto & keyword : _current_template.keywords) {
+ message += " ";
+ message += keyword;
+ }
+ message += "\n\n";
+ }
+
+ if (!_current_template.path.empty()) {
+ message += _("Path");
+ message += ": ";
+ message += _current_template.path;
+ message += "\n\n";
+ }
+
+ Gtk::MessageDialog dl(message, false, Gtk::MESSAGE_OTHER);
+ dl.run();
+}
+
+}
+}