diff --git a/src/include/ui_helper.h b/src/include/ui_helper.h index c6b6e5d2..db10ba16 100644 --- a/src/include/ui_helper.h +++ b/src/include/ui_helper.h @@ -462,6 +462,7 @@ void uih_loadexample(struct uih_context *c); void uih_loadpngfile(struct uih_context *c, xio_constpath d); void uih_savepngfile(struct uih_context *c, xio_constpath d); void uih_saveposfile(struct uih_context *c, xio_constpath d); +void uih_copyposurl(struct uih_context *c); char *uih_savepostostr(struct uih_context *c); void uih_savecfg(struct uih_context *c); void uih_saveanimfile(struct uih_context *c, xio_constpath d); diff --git a/src/ui-hlp/menu.cpp b/src/ui-hlp/menu.cpp index ebfb73e8..c6a25319 100644 --- a/src/ui-hlp/menu.cpp +++ b/src/ui-hlp/menu.cpp @@ -1260,6 +1260,8 @@ void uih_registermenus_i18n(void) MENUNOP_I("edit", NULL, TR("Menu", "Redo"), "redo", MENUFLAG_INTERRUPT | MENUFLAG_NOPLAY | MENUFLAG_NOOPTION, uih_redo); + MENUNOP_I("edit", NULL, TR("Menu", "Copy position URL"), "copyurl", + MENUFLAG_INTERRUPT | MENUFLAG_NOPLAY | MENUFLAG_NOOPTION, uih_copyposurl); SUBMENU_I("fractal", NULL, TR("Menu", "Formulae"), "mformula"); SUBMENU_I("fractal", NULL, TR("Menu", "More formulae"), "oformula"); diff --git a/src/ui-hlp/ui_helper.cpp b/src/ui-hlp/ui_helper.cpp index a18a6395..24d189e5 100644 --- a/src/ui-hlp/ui_helper.cpp +++ b/src/ui-hlp/ui_helper.cpp @@ -10,6 +10,9 @@ #include #endif #endif +#include +#include +#include #include "config.h" #include "filter.h" @@ -698,6 +701,34 @@ void uih_saveposfile(struct uih_context *c, xio_constpath d) } } +/* Copy the position URL in the clipboard. */ +/* For some reason, the messages are shown twice in the web version. FIXME. */ +void uih_copyposurl(struct uih_context *c) +{ + c->errstring = NULL; + char *pos = uih_savepostostr(c); + QString qPos = QString(pos); + QStringList qPosCommands = qPos.split("\n"); + QString url = "https://xaos.app?"; + for (QString c: qPosCommands) { + if (!c.startsWith(";") && c != "(initstate)" && c != "(formula 'mandel)" + && c != "(defaultpalette 0)" && c != "(maxiter 1000)") { + // Comments and defaults are removed. + url += c; + } + } + QClipboard* clipboard = QApplication::clipboard(); + clipboard->setText(QString(url)); + if (c->errstring == NULL) { + char s[256]; + if (url.length() > 200) { + url = url.left(200) + "..."; + } + sprintf(s, TR("Message", "Clipboard set to %s."), url.toStdString().c_str()); + uih_message(c, s); + } +} + char *uih_savepostostr(struct uih_context *c) { xio_file f; diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 634d32e4..73882ed6 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -779,6 +779,14 @@ QKeySequence::StandardKey MainWindow::keyForItem(const QString &name) return QKeySequence::Refresh; if (name == "help") return QKeySequence::HelpContents; + if (name == "copyurl") + return QKeySequence::Copy; + if (name == "saveimg") + return QKeySequence::SaveAs; + if (name == "fractalinfo") + return QKeySequence::WhatsThis; + if (name == "autopilot") + return QKeySequence::ZoomIn; return QKeySequence::UnknownKey; }