Commit 195b7faf authored by Tomas Mecir's avatar Tomas Mecir

make clickable links work

parent 24e0cd60
......@@ -24,7 +24,7 @@
#include <QAbstractTextDocumentLayout>
#include <QApplication>
#include <QAction>
#include <QFontDatabase>
#include <QDesktopServices>
#include <QGraphicsItemGroup>
#include <QGraphicsTextItem>
#include <QScrollBar>
......@@ -164,6 +164,10 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
d->scene.addItem (d->mainText);
d->scene.addItem (d->scrollTextGroup);
d->scene.addItem (d->scrollText);
connect (d->mainText, &QGraphicsTextItem::linkActivated, this, &cConsole::linkActivated);
connect (d->scrollText, &QGraphicsTextItem::linkActivated, this, &cConsole::linkActivated);
connect (d->mainText, &QGraphicsTextItem::linkHovered, this, &cConsole::linkHovered);
connect (d->scrollText, &QGraphicsTextItem::linkHovered, this, &cConsole::linkHovered);
d->mainText->setDocument (d->text);
// d->mainText->setFiltersChildEvents (true);
......@@ -482,6 +486,38 @@ void cConsole::fixupOutput ()
forceEmitSize ();
}
void cConsole::linkHovered (const QString &link)
{
viewport()->setCursor (link.isEmpty() ? Qt::IBeamCursor : Qt::PointingHandCursor);
}
void cConsole::linkActivated (const QString &link)
{
// TODO - menus and such, need to encode them in the level text. For now we just use plain text.
// see old code below for menu handling - except that we don't have the chunk pointer
// get the first two words, they are iscommand/toprompt
int pos = link.indexOf(' ');
if (pos < 0) return;
QString w1 = link.left(pos);
QString ll = link.mid(pos + 1);
pos = ll.indexOf(' ');
QString w2 = ll.left(pos);
QString cmd = ll.mid(pos + 1);
if (w1 == "link") {
// URL link
QDesktopServices::openUrl (QUrl (cmd));
return;
}
if (w2 == "prompt")
emit promptCommand (cmd);
else
emit sendCommand (cmd);
}
/*
void cConsole::activateLink (chunkLink *link, const QPoint &point)
{
......@@ -554,4 +590,3 @@ void sendCommand (const QString &command); -- in activateLink
void promptCommand (const QString &command); -- in activateLink
*/
......@@ -96,6 +96,8 @@ public slots:
/** adds selection to clipboard (adding to mouse selection buffer is done
automatically) */
void addSelectionToClipboard (QClipboard::Mode clipboardMode);
void linkHovered (const QString &link);
void linkActivated (const QString &link);
/** shifting it around (SHIFT+keys) */
void lineUp ();
......
......@@ -1284,13 +1284,8 @@ QString chunkBg::toHTML (QString &suffix)
QColor chunkLink::linkColor = Qt::blue;
QString chunkLink::toHTML (QString &)
{
if (_iscommand)
{
return "<a rel=\"command\" href=\"" + _target + "\">" + _text + "</a>";
}
else
{
return "<a rel=\"link\" href=\"" + _target + "\">" + _text + "</a>";
}
QString rel = _iscommand ? "command" : "link";
QString href = rel + " " + (_toprompt ? "prompt" : "send") + " " + _target;
return "<a rel=\"" + rel + "\" href=\"" + href + "\">" + _text + "</a>";
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment