Skip to content

Commit

Permalink
Add Copy position URL + some keystrokes
Browse files Browse the repository at this point in the history
  • Loading branch information
kovzol committed Jan 13, 2024
1 parent 0de6509 commit a8ec166
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/ui_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/ui-hlp/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
31 changes: 31 additions & 0 deletions src/ui-hlp/ui_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <malloc.h>
#endif
#endif
#include <qclipboard.h>
#include <QApplication>
#include <stdio.h>

#include "config.h"
#include "filter.h"
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a8ec166

Please sign in to comment.