Commit 2dbbacdd authored by Sebastian Sauer's avatar Sebastian Sauer

Finally apply the patch from Matus Hanzes to have picture's as hyperlink in calligra words.

from http://reviewboard.kde.org/r/5071/
closes https://bugs.kde.org/show_bug.cgi?id=239700
Great work Hanzes! :)
parent e4a68740
......@@ -1737,6 +1737,18 @@ void KoShape::setToolDelegates(const QSet<KoShape*> &delegates)
d->toolDelegates = delegates;
}
QString KoShape::hyperLink () const
{
Q_D(const KoShape);
return d->hyperLink;
}
void KoShape::setHyperLink (QString & hyperLink)
{
Q_D(KoShape);
d->hyperLink = hyperLink;
}
KoShapePrivate *KoShape::priv()
{
Q_D(KoShape);
......
......@@ -929,6 +929,17 @@ public:
*/
void setToolDelegates(const QSet<KoShape*> &delegates);
/**
* Return the hyperlink for this shape.
*/
QString hyperLink () const;
/**
* Set hyperlink for this shape.
* @param hyperLink name.
*/
void setHyperLink (QString & hyperLink);
/**
* \internal
* Returns the private object for use within the flake lib
......
......@@ -106,6 +106,7 @@ public:
QSet<KoEventAction *> eventActions; ///< list of event actions the shape has
KoFilterEffectStack *filterEffectStack; ///< stack of filter effects applied to the shape
qreal transparency; ///< the shapes transparency
QString hyperLink; //hyperlink for this shape
static const int MaxZIndex = 32767;
int zIndex : 16; // keep maxZIndex in sync!
......
......@@ -1090,6 +1090,8 @@ void KoTextLoader::loadSpan(const KoXmlElement &element, QTextCursor &cursor, bo
If a heading has a numbering applied, the text of the formatted number can be included in a
<text:number> element. This text can be used by applications that do not support numbering of
headings, but it will be ignored by applications that support numbering. */
} else if ((isDrawNS) && localName == "a") { // draw:a
loadShapeWithHyperLink(ts, cursor);
} else if (isDrawNS) {
loadShape(ts, cursor);
} else {
......@@ -1344,12 +1346,29 @@ void KoTextLoader::loadTable(const KoXmlElement &tableElem, QTextCursor &cursor)
d->inTable = false;
}
void KoTextLoader::loadShape(const KoXmlElement &element, QTextCursor &cursor)
void KoTextLoader::loadShapeWithHyperLink(const KoXmlElement &element, QTextCursor& cursor)
{
// get the hyperlink
QString hyperLink = element.attributeNS(KoXmlNS::xlink, "href");
KoShape *shape = 0;
//load the shape for hyperlink
KoXmlNode node = element.firstChild();
if (!node.isNull()) {
KoXmlElement ts = node.toElement();
shape = loadShape(ts, cursor);
if (shape) {
shape->setHyperLink(hyperLink);
}
}
}
KoShape *KoTextLoader::loadShape(const KoXmlElement &element, QTextCursor &cursor)
{
KoShape *shape = KoShapeRegistry::instance()->createShapeFromOdf(element, d->context);
if (!shape) {
kDebug(32500) << "shape '" << element.localName() << "' unhandled";
return;
return 0;
}
QString anchorType;
......@@ -1379,6 +1398,7 @@ void KoTextLoader::loadShape(const KoXmlElement &element, QTextCursor &cursor)
} else {
d->textSharedData->shapeInserted(shape, element, d->context);
}
return shape;
}
void KoTextLoader::loadTableOfContents(const KoXmlElement &element, QTextCursor &cursor)
......
......@@ -149,10 +149,15 @@ private:
*/
void loadNote(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the shape element and assign hyperlink to it \p element into the \p cursor .
*/
void loadShapeWithHyperLink(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the shape element \p element into the \p cursor .
*/
void loadShape(const KoXmlElement &element, QTextCursor& cursor);
KoShape *loadShape(const KoXmlElement &element, QTextCursor& cursor);
/**
* Load the table of content element \p element into the \p cursor .
......
......@@ -941,7 +941,6 @@ void TextTool::mouseMoveEvent(KoPointerEvent *event)
{
m_changeTipPos = event->globalPos();
useCursor(Qt::IBeamCursor);
if (event->buttons()) {
updateSelectedShape(event->point);
}
......@@ -954,6 +953,11 @@ void TextTool::mouseMoveEvent(KoPointerEvent *event)
int position = pointToPosition(event->point);
if (event->buttons() == Qt::NoButton) {
if (m_textShapeData->endPosition() == position) {
useCursor(Qt::IBeamCursor);
return;
}
QTextCursor cursor(*(m_textEditor.data()->cursor()));
cursor.setPosition(position);
......@@ -967,14 +971,23 @@ void TextTool::mouseMoveEvent(KoPointerEvent *event)
m_changeTipCursorPos = position;
}
if (cursor.charFormat().isAnchor())
if (cursor.charFormat().isAnchor()) {
useCursor(Qt::PointingHandCursor);
else
useCursor(Qt::IBeamCursor);
return;
}
// check if mouse pointer is not over shape with hyperlink
KoShape *selectedShape = canvas()->shapeManager()->shapeAt(event->point);
if (selectedShape != 0 && selectedShape != m_textShape && selectedShape->hyperLink().size() != 0) {
useCursor(Qt::PointingHandCursor);
return;
}
useCursor(Qt::IBeamCursor);
return;
}
useCursor(Qt::IBeamCursor);
if (position == m_textEditor.data()->position()) return;
if (position >= 0) {
if (m_textEditor.data()->hasSelection())
......@@ -993,6 +1006,14 @@ void TextTool::mouseReleaseEvent(KoPointerEvent *event)
event->ignore();
editingPluginEvents();
// check if mouse pointer is not over some shape with hyperlink
KoShape *selectedShape = canvas()->shapeManager()->shapeAt(event->point);
if (selectedShape != 0 && selectedShape != m_textShape && selectedShape->hyperLink().size() != 0) {
QString url = selectedShape->hyperLink();
runUrl(event, url);
return;
}
// Is there an anchor here ?
if (m_textEditor.data()->charFormat().isAnchor() && !m_textEditor.data()->hasSelection()) {
QString anchor = m_textEditor.data()->charFormat().anchorHref();
......@@ -1015,24 +1036,7 @@ void TextTool::mouseReleaseEvent(KoPointerEvent *event)
}
}
bool isLocalLink = (anchor.indexOf("file:") == 0);
QString type = KMimeType::findByUrl(anchor, 0, isLocalLink)->name();
if (KRun::isExecutableFile(anchor, type)) {
QString question = i18n("This link points to the program or script '%1'.\n"
"Malicious programs can harm your computer. "
"Are you sure that you want to run this program?", anchor);
// this will also start local programs, so adding a "don't warn again"
// checkbox will probably be too dangerous
int choice = KMessageBox::warningYesNo(0, question, i18n("Open Link?"));
if (choice != KMessageBox::Yes)
return;
}
event->accept();
new KRun(m_textEditor.data()->charFormat().anchorHref(), 0);
m_textEditor.data()->setPosition(0);
ensureCursorVisible();
runUrl(event, anchor);
return;
} else {
QStringList anchorList = m_textEditor.data()->charFormat().anchorNames();
......@@ -2250,6 +2254,28 @@ void TextTool::writeConfig()
}
}
void TextTool::runUrl(KoPointerEvent *event, QString &url)
{
bool isLocalLink = (url.indexOf("file:") == 0);
QString type = KMimeType::findByUrl(url, 0, isLocalLink)->name();
if (KRun::isExecutableFile(url, type)) {
QString question = i18n("This link points to the program or script '%1'.\n"
"Malicious programs can harm your computer. "
"Are you sure that you want to run this program?", url);
// this will also start local programs, so adding a "don't warn again"
// checkbox will probably be too dangerous
int choice = KMessageBox::warningYesNo(0, question, i18n("Open Link?"));
if (choice != KMessageBox::Yes)
return;
}
event->accept();
new KRun(url, 0);
m_textEditor.data()->setPosition(0);
ensureCursorVisible();
}
void TextTool::debugTextDocument()
{
#ifndef NDEBUG
......
......@@ -293,6 +293,7 @@ private:
void finishedParagraph();
void readConfig();
void writeConfig();
void runUrl(KoPointerEvent *event, QString &url);
private:
friend class UndoTextCommand;
......
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