[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kpresenter/part
From: Matus Hanzes <matus.hanzes () ixonos ! com>
Date: 2010-11-16 9:48:57
Message-ID: 20101116094857.6443CAC8A2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1197608 by hanzes:
Added support for hyperlinks in kpresenter presentation mode
M +54 -1 KPrPresentationTool.cpp
M +14 -0 KPrPresentationTool.h
--- trunk/koffice/kpresenter/part/KPrPresentationTool.cpp #1197607:1197608
@@ -28,12 +28,17 @@
#include <QtGui/QVBoxLayout>
#include <QtGui/QPainter>
#include <QKeyEvent>
+#include <qabstracttextdocumentlayout.h>
+#include <qcursor.h>
+#include <qdesktopservices.h>
+#include <qurl.h>
#include <KoShape.h>
#include <KoShapeManager.h>
#include <KoPointerEvent.h>
#include <KoEventAction.h>
#include <KoPACanvas.h>
+#include <KoTextShapeData.h>
#include "KPrViewModePresentation.h"
#include "KPrPresentationStrategy.h"
@@ -97,6 +102,12 @@
finishEventActions();
KoShape * shapeClicked = canvas()->shapeManager()->shapeAt( event->point );
if (shapeClicked) {
+ QString link;
+ if (checkHyperlink(event, shapeClicked, link)) {
+ runHyperlink(link);
+ return;
+ }
+
m_eventActions = shapeClicked->eventActions();
if (!m_eventActions.isEmpty()) {
foreach ( KoEventAction * eventAction, m_eventActions ) {
@@ -122,9 +133,17 @@
void KPrPresentationTool::mouseMoveEvent( KoPointerEvent *event )
{
- Q_UNUSED(event);
+ KoShape * shape = canvas()->shapeManager()->shapeAt(event->point);
+
+ QString link;
+ if (checkHyperlink(event, shape, link)) {
+ canvas()->setCursor(Qt::PointingHandCursor);
+ return;
}
+ canvas()->setCursor(Qt::ArrowCursor);
+}
+
void KPrPresentationTool::mouseReleaseEvent( KoPointerEvent *event )
{
Q_UNUSED(event);
@@ -268,6 +287,40 @@
return false;
}
+bool KPrPresentationTool::checkHyperlink(KoPointerEvent *event, KoShape *shape, QString & hyperLink)
+{
+ if (!shape) {
+ return false;
+ }
+
+ KoTextShapeData *textShapeData = qobject_cast<KoTextShapeData*>(shape->userData());
+ if (textShapeData) {
+ QPointF p = shape->absoluteTransformation(0).inverted().map(event->point);
+ p = p + QPointF(0.0, textShapeData->documentOffset());
+
+ int caretPos = textShapeData->document()->documentLayout()->hitTest(p, Qt::ExactHit);
+
+ if (textShapeData->endPosition() != -1 && caretPos != -1) {
+ QTextCursor mouseOver(textShapeData->document());
+ mouseOver.setPosition(caretPos);
+
+ QTextCharFormat fmt = mouseOver.charFormat();
+ hyperLink = fmt.anchorHref();
+ if (!hyperLink.isEmpty()) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void KPrPresentationTool::runHyperlink(QString hyperLink)
+{
+ QUrl url = QUrl::fromUserInput(hyperLink);
+
+ QDesktopServices::openUrl(url);
+}
+
KPrPresentationStrategyBase *KPrPresentationTool::strategy()
{
return m_strategy;
--- trunk/koffice/kpresenter/part/KPrPresentationTool.h #1197607:1197608
@@ -71,6 +71,20 @@
void switchStrategy( KPrPresentationStrategyBase * strategy );
bool eventFilter( QObject * obj, QEvent * event );
+ /**
+ * Returns true if shape is a TextShape and event->point is over hyperlink
+ * @param event the mouse event
+ * @param shape the shape fhich is searched for hyperlink
+ * @param hyperLink the string which is filled with hyperlink url
+ */
+ bool checkHyperlink(KoPointerEvent *event, KoShape * shape, QString & hyperLink);
+
+ /**
+ * Runs url string defined inside hyperlink
+ * @param hyperLink the hyperlink string
+ */
+ void runHyperlink(QString hyperLink);
+
KPrViewModePresentation & m_viewMode;
QSet<KoEventAction *> m_eventActions;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic