[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/kdgantt
From:       Dag Andersen <danders () get2net ! dk>
Date:       2008-10-21 12:42:11
Message-ID: 1224592931.446733.555.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 874378 by danders:

1) Add mapping between screen x position and grid unit (eg x <-> QDateTime).
2) Add ToolTip for the graphicsview header.


 M  +21 -0     kdganttabstractgrid.cpp  
 M  +3 -0      kdganttabstractgrid.h  
 M  +23 -0     kdganttdatetimegrid.cpp  
 M  +3 -0      kdganttdatetimegrid.h  
 M  +15 -0     kdganttgraphicsview.cpp  
 M  +1 -0      kdganttgraphicsview_p.h  


--- trunk/KDE/kdepim/kdgantt/kdganttabstractgrid.cpp #874377:874378
@@ -92,6 +92,27 @@
     return ( ss.end() <= es.start() );
 }
 
+/*!
+ * Implement this to map from \a value to the corresponding location in the view.
+ * Return a negative value if \a value cannot be mapped.
+ * The default implementation returns -1.0.
+ */
+qreal AbstractGrid::mapToChart( const QVariant& value ) const
+{
+    Q_UNUSED( value );
+    return -1.0;
+}
+
+/*!
+ * Implement this to map from \a x to the corresponding location in the view.
+ * Return an invalid value if \a x cannot be mapped.
+ */
+QVariant AbstractGrid::mapFromChart( qreal x ) const
+{
+    Q_UNUSED( x );
+    return QVariant();
+}
+
 /*!\fn virtual Span AbstractGrid::mapToChart( const QModelIndex& idx ) const
  * Implement this to map from the data in the model to the location of
  * the corresponding item in the view.
--- trunk/KDE/kdepim/kdgantt/kdganttabstractgrid.h #874377:874378
@@ -49,6 +49,9 @@
         virtual Span mapToChart( const QModelIndex& idx ) const = 0;
         virtual bool mapFromChart( const Span& span, const QModelIndex& idx,
                                    const QList<Constraint>& constraints=QList<Constraint>() ) const = 0;
+        virtual qreal mapToChart( const QVariant &value ) const;
+        virtual QVariant mapFromChart( qreal x ) const;
+        
         bool isSatisfiedConstraint( const Constraint& c ) const;
 
         virtual void paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect,
--- trunk/KDE/kdepim/kdgantt/kdganttdatetimegrid.cpp #874377:874378
@@ -206,6 +206,29 @@
     return d->freeDays;
 }
 
+/*!
+ * \param value The datetime to get the x value for.
+ * \returns The x value corresponding to \a value or -1.0 if \a value is not a datetime variant.
+ */
+qreal DateTimeGrid::mapToChart( const QVariant& value ) const
+{
+    if ( ! qVariantCanConvert<QDateTime>( value ) ||
+         ( value.type() == QVariant::String && qVariantValue<QString>(value).isEmpty() ) )
+    {
+        return -1.0;
+    }
+    return d->dateTimeToChartX( value.toDateTime() );
+}
+
+/*!
+ * \param x The x value get the datetime for.
+ * \returns The datetime corresponding to \a x or an invalid datetime if x cannot be mapped.
+ */
+QVariant DateTimeGrid::mapFromChart( qreal x ) const
+{
+    return d->chartXtoDateTime( x );
+}
+
 /*! \param idx The index to get the Span for.
  * \returns The start and end pixels, in a Span, of the specified index.
  */
--- trunk/KDE/kdepim/kdgantt/kdganttdatetimegrid.h #874377:874378
@@ -59,6 +59,9 @@
         /*reimp*/ Span mapToChart( const QModelIndex& idx ) const;
         /*reimp*/ bool mapFromChart( const Span& span, const QModelIndex& idx,
                                      const QList<Constraint>& constraints=QList<Constraint>() ) const;
+        /*reimp*/ qreal mapToChart( const QVariant& value ) const;
+        /*reimp*/ QVariant mapFromChart( qreal x ) const;
+
         /*reimp*/ void paintGrid( QPainter* painter, const QRectF& sceneRect, const QRectF& exposedRect,
                                   AbstractRowController* rowController = 0,
                                   QWidget* widget=0 );
--- trunk/KDE/kdepim/kdgantt/kdganttgraphicsview.cpp #874377:874378
@@ -31,6 +31,8 @@
 #include <QPainter>
 #include <QPaintEvent>
 #include <QResizeEvent>
+#include <QEvent>
+#include <QHelpEvent>
 #include <QScrollBar>
 #include <QAbstractProxyModel>
 #include <QToolButton>
@@ -76,6 +78,19 @@
     view()->grid()->render( painter, targetRect, rect(), sourceRect, this, aspectRatioMode );
 }
 
+bool HeaderWidget::event( QEvent* event )
+{
+    if ( event->type() == QEvent::ToolTip ) {
+        DateTimeGrid* const grid = qobject_cast< DateTimeGrid* >( view()->grid() );
+        if ( grid ) {
+            QHelpEvent *e = static_cast<QHelpEvent*>( event );
+            QDateTime dt = grid->mapFromChart( e->x() ).toDateTime();
+            setToolTip( dt.toString() );
+        }
+    }
+    return QWidget::event( event );
+}
+
 void HeaderWidget::contextMenuEvent( QContextMenuEvent* event )
 {
     QMenu contextMenu;
--- trunk/KDE/kdepim/kdgantt/kdganttgraphicsview_p.h #874377:874378
@@ -43,6 +43,7 @@
     public Q_SLOTS:
         void scrollTo( int );
     protected:
+        /*reimp*/ bool event( QEvent* ev );
         /*reimp*/ void paintEvent( QPaintEvent* ev );
         /*reimp*/ void contextMenuEvent( QContextMenuEvent* ev );
     private:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic