Branch 'kolab/integration/4.13.0' - calendarviews/month
Christian Mollekopf
mollekopf at kolabsys.com
Wed Sep 24 14:13:53 CEST 2014
calendarviews/month/monthgraphicsitems.cpp | 12 ++++++------
calendarviews/month/monthgraphicsitems.h | 4 ++--
calendarviews/month/monthscene.cpp | 18 ++++++++++++++++++
calendarviews/month/monthscene.h | 1 +
4 files changed, 27 insertions(+), 8 deletions(-)
New commits:
commit 195e7f4228132649b61f9e4f81869af3d5c99165
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date: Wed Sep 24 14:13:40 2014 +0200
MonthView: Generate the tooltip-text on demand.
This used to be a major bottleneck because generating the tooltip was relatively
expensive, and generated for every event (which is pointless).
diff --git a/calendarviews/month/monthgraphicsitems.cpp b/calendarviews/month/monthgraphicsitems.cpp
index 7168832..7ecfe6c 100644
--- a/calendarviews/month/monthgraphicsitems.cpp
+++ b/calendarviews/month/monthgraphicsitems.cpp
@@ -133,7 +133,7 @@ static const int ft = 2; // frame thickness
MonthGraphicsItem::MonthGraphicsItem( MonthItem *manager )
: QGraphicsItem( 0, manager->monthScene() ),
- mMonthItem( manager ), mToolTipNeedsUpdate( false )
+ mMonthItem( manager )
{
QTransform transform;
transform = transform.translate( 0.5, 0.5 );
@@ -332,7 +332,6 @@ void MonthGraphicsItem::paint( QPainter *p, const QStyleOptionGraphicsItem *, QW
void MonthGraphicsItem::setStartDate( const QDate &date )
{
mStartDate = date;
- mToolTipNeedsUpdate = true;
}
QDate MonthGraphicsItem::endDate() const
@@ -385,12 +384,13 @@ void MonthGraphicsItem::updateGeometry()
mMonthItem->monthScene()->maxRowCount() ) {
hide();
} else {
- if ( mToolTipNeedsUpdate ) {
- setToolTip( mMonthItem->toolTipText( mStartDate ) );
- mToolTipNeedsUpdate = false;
- }
show();
update();
}
}
+QString MonthGraphicsItem::getToolTip() const
+{
+ return mMonthItem->toolTipText( mStartDate );
+}
+
diff --git a/calendarviews/month/monthgraphicsitems.h b/calendarviews/month/monthgraphicsitems.h
index a260270..1bbff5e 100644
--- a/calendarviews/month/monthgraphicsitems.h
+++ b/calendarviews/month/monthgraphicsitems.h
@@ -184,6 +184,8 @@ class EVENTVIEWS_EXPORT MonthGraphicsItem : public QObject, public QGraphicsItem
virtual void paint( QPainter *, const QStyleOptionGraphicsItem *, QWidget * );
virtual QPainterPath shape() const;
+ QString getToolTip() const;
+
private:
// Shape of the item, see shape()
QPainterPath widgetPath( bool border ) const;
@@ -196,8 +198,6 @@ class EVENTVIEWS_EXPORT MonthGraphicsItem : public QObject, public QGraphicsItem
// The current item is part of a MonthItem
MonthItem *mMonthItem;
-
- bool mToolTipNeedsUpdate;
};
}
diff --git a/calendarviews/month/monthscene.cpp b/calendarviews/month/monthscene.cpp
index f992cbb..05c0677 100644
--- a/calendarviews/month/monthscene.cpp
+++ b/calendarviews/month/monthscene.cpp
@@ -33,6 +33,7 @@
#include <QGraphicsSceneMouseEvent>
#include <QResizeEvent>
+#include <QToolTip>
static const int AUTO_REPEAT_DELAY = 600;
@@ -647,6 +648,23 @@ void MonthScene::timerEvent( QTimerEvent *e )
}
}
+void MonthScene::helpEvent( QGraphicsSceneHelpEvent *helpEvent )
+{
+ // Find the first item that does tooltips
+ const QPointF pos = helpEvent->scenePos();
+ MonthGraphicsItem *toolTipItem = dynamic_cast<MonthGraphicsItem*>( itemAt( pos ) );
+
+ // Show or hide the tooltip
+ QString text;
+ QPoint point;
+ if (toolTipItem) {
+ text = toolTipItem->getToolTip();
+ point = helpEvent->screenPos();
+ }
+ QToolTip::showText(point, text, helpEvent->widget());
+ helpEvent->setAccepted(!text.isEmpty());
+}
+
void MonthScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent *mouseEvent )
{
QPointF pos = mouseEvent->scenePos();
diff --git a/calendarviews/month/monthscene.h b/calendarviews/month/monthscene.h
index 2a7392b..04ba0f2 100644
--- a/calendarviews/month/monthscene.h
+++ b/calendarviews/month/monthscene.h
@@ -176,6 +176,7 @@ class EVENTVIEWS_EXPORT MonthScene : public QGraphicsScene
virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent *mouseEvent );
virtual void wheelEvent( QGraphicsSceneWheelEvent *wheelEvent );
virtual void timerEvent( QTimerEvent *e );
+ virtual void helpEvent( QGraphicsSceneHelpEvent *helpEvent );
/**
Scrolls all incidences in cells up
*/
More information about the commits
mailing list