KDTimeLineWidget Class Reference
[KDTimeLineWidget]

KDTimeLineWidget is a widget showing a timeline with a current time and optionally a number of events. It does not provide scrollbars or other means of navigation. More...

List of all members.

Public Slots

void setStartDateTime (const QDateTime &)
void setEndDateTime (const QDateTime &)
void setSnapToTickmarks (bool)
void setCurrentDateTime (const QDateTime &)
void nextCurrentDateTime ()
void previousCurrentDateTime ()
void setElapsedDateTime (const QDateTime &)
void setCurrentItem (KDTimeLineWidgetItem *)
void nextCurrentItem ()
void previousCurrentItem ()

Signals

void itemSelected (KDTimeLineWidgetItem *)
void itemMoved (KDTimeLineWidgetItem *)
void currentDateTimeChanged (const QDateTime &)

Public Member Functions

 KDTimeLineWidget (QWidget *parent=0)
virtual ~KDTimeLineWidget ()
void setDateTimeFormat (const QString &format)
void setDateTimeFormat (Qt::DateFormat format)
void addItem (KDTimeLineWidgetItem *item)
void removeItem (KDTimeLineWidgetItem *item)
int itemCount () const
KDTimeLineWidgetItemcurrentItem () const
QDateTime dateTimeAt (int x) const
int position (const QDateTime &dt) const

Properties

QDateTime startDateTime
QDateTime endDateTime
QDateTime currentDateTime
bool snapToTickmarks


Detailed Description

KDTimeLineWidget is a widget showing a timeline with a current time and optionally a number of events. It does not provide scrollbars or other means of navigation.

kdtimelinewidget.png

Definition at line 71 of file kdtimelinewidget.h.


Constructor & Destructor Documentation

KDTimeLineWidget::KDTimeLineWidget ( QWidget *  parent = 0  )  [explicit]

Contructor. Creates a KDTimeLineWidget with parent parent showing time from now and one day forward.

Definition at line 333 of file kdtimelinewidget.cpp.

00334   : QWidget(parent),
00335     d( new Private( this ) )
00336 {
00337   setFocusPolicy( Qt::StrongFocus );
00338   setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
00339 }

KDTimeLineWidget::~KDTimeLineWidget (  )  [virtual]

Destructor. When a KDTimeLineWidget is deleted, any KDTimeLineWidgetItems contained in it are deleted too.

Definition at line 343 of file kdtimelinewidget.cpp.

00344 {
00345     qDeleteAll( d->items );
00346     //while( !items.isEmpty() ) delete items.front();
00347 }


Member Function Documentation

void KDTimeLineWidget::setDateTimeFormat ( const QString &  format  ) 

Set the datetime format string used to display textual datetimes on the timeline. Default is QString::null which means that the Qt::DateFormat set with setDateTimeFormat( Qt::DateFormat ) is used instead.

Definition at line 416 of file kdtimelinewidget.cpp.

00417 {
00418   d->date_format_str = format;
00419   update();
00420 }

void KDTimeLineWidget::setDateTimeFormat ( Qt::DateFormat  format  ) 

Set the datetime format string used to display textual datetimes on the timeline. Default is Qt::TextFormat. Calling this method sets the datime format string to QString::null.

Definition at line 426 of file kdtimelinewidget.cpp.

00427 {
00428   d->date_format = format;
00429   d->date_format_str.clear();
00430   update();
00431 }

void KDTimeLineWidget::addItem ( KDTimeLineWidgetItem item  ) 

Add a KDTimeLineWidgetItem to this KDTimeLineWidget. The KDTimeLineWidget object becomes the owner of item

Definition at line 441 of file kdtimelinewidget.cpp.

00442 {
00443   Q_ASSERT(item);
00444   QList<KDTimeLineWidgetItem*>::iterator it = kd_lower_bound( d->items.begin(),
00445                                                         d->items.end(),
00446                                                         item,
00447                                                         KDTimeLineWidgetItemLessThan() );
00448   d->items.insert(it,item);
00449   item->d->setTimeLineWidget(this);
00450   update();
00451 }

void KDTimeLineWidget::removeItem ( KDTimeLineWidgetItem item  ) 

Remove a KDTimeLineWidgetItem from this KDTimeLineWidget. Ownership is transferred to the caller and the item is not deleted.

Definition at line 456 of file kdtimelinewidget.cpp.

00457 {
00458   Q_ASSERT(item);
00459   d->items.removeAll(item);
00460   item->d->setTimeLineWidget(0);
00461   if( d->currentitem == item ) d->currentitem = 0;
00462   update();
00463 }

int KDTimeLineWidget::itemCount (  )  const

Returns the number of KDTimeLineWidgetItems.

Definition at line 554 of file kdtimelinewidget.cpp.

00554 { return d->items.size(); }

KDTimeLineWidgetItem * KDTimeLineWidget::currentItem (  )  const

Returns:
the current item.

Definition at line 466 of file kdtimelinewidget.cpp.

00467 {
00468   return d->currentitem;
00469 }

QDateTime KDTimeLineWidget::dateTimeAt ( int  x  )  const

Returns the datetime associated with the given x coordinate in the widget

Definition at line 564 of file kdtimelinewidget.cpp.

00565 {
00566   return usecs_to_datetime( d->viewToTime( x ) );
00567 }

int KDTimeLineWidget::position ( const QDateTime &  dt  )  const

Returns:
the position x coordinate in widget coordinates corresponding to the time dt

Definition at line 571 of file kdtimelinewidget.cpp.

00572 {
00573   return d->timeToView( datetime_to_usecs(dt) );
00574 }

void KDTimeLineWidget::itemSelected ( KDTimeLineWidgetItem  )  [signal]

This signal is emitted when the user clicks an event item

void KDTimeLineWidget::itemMoved ( KDTimeLineWidgetItem  )  [signal]

This signal is emitted when the user has moved an event item

void KDTimeLineWidget::currentDateTimeChanged ( const QDateTime &   )  [signal]

This signal is emitted when the user has changed the current datetime

void KDTimeLineWidget::setStartDateTime ( const QDateTime &  dt  )  [slot]

Set the starting time of the time line to dt

Definition at line 350 of file kdtimelinewidget.cpp.

00351 {
00352   d->starttime = dt;
00353   if( d->starttime > d->endtime ) d->endtime = d->starttime;
00354   update();
00355 }

void KDTimeLineWidget::setEndDateTime ( const QDateTime &  dt  )  [slot]

Set the ending time of the time line to dt

Definition at line 366 of file kdtimelinewidget.cpp.

00367 {
00368   d->endtime = dt;
00369   if( d->starttime > d->endtime ) d->starttime = d->endtime;
00370   update();
00371 }

void KDTimeLineWidget::setSnapToTickmarks ( bool  b  )  [slot]

If set to true, the current time indicator can only be positioned so it is aligned to minor tickmarks. If set to false, it can be positioned freely in time.

Definition at line 962 of file kdtimelinewidget.cpp.

00963 {
00964   d->snaptoticks = b;
00965   setCurrentDateTime( d->snapTo( position(currentDateTime()) ) );
00966 }

void KDTimeLineWidget::setCurrentDateTime ( const QDateTime &  dt  )  [slot]

Set the current time of the timeline to dt. Current time display can be disabled by passing an invalid QDateTime to this method.

Definition at line 382 of file kdtimelinewidget.cpp.

00383 {
00384   QDateTime old = d->currenttime;
00385   d->currenttime = dt;
00386   if( old != dt ) emit currentDateTimeChanged(dt);
00387   update();
00388 }

void KDTimeLineWidget::nextCurrentDateTime (  )  [slot]

Advances the current time indicator to the next minor tickmark.

Definition at line 482 of file kdtimelinewidget.cpp.

00483 {
00484     const QFontMetrics fm = fontMetrics();
00485     const int minw = fm.width( d->dateTimeToString( d->starttime) ) + fm.width( QLatin1String( "XXX" ) );
00486 
00487     QList< qint64 > major;
00488     QList< qint64 > minor;
00489     d->getTickmarkValues( major, minor, minw );
00490 
00491     if( minor.isEmpty() )
00492         return;
00493 
00494     const qint64 timex = datetime_to_usecs( currentDateTime() );
00495     const QList< qint64 >::const_iterator bound = kd_upper_bound( minor.begin(), minor.end(), timex, std::less< qint64 >() );
00496     if( bound != minor.end() )
00497         setCurrentDateTime( usecs_to_datetime( *bound ) );
00498     else
00499         return setCurrentDateTime( usecs_to_datetime( minor.last() ) );
00500 }

void KDTimeLineWidget::previousCurrentDateTime (  )  [slot]

Advances the current time indicator to the previous minor tickmark.

Definition at line 503 of file kdtimelinewidget.cpp.

00504 {
00505     const QFontMetrics fm = fontMetrics();
00506     const int minw = fm.width( d->dateTimeToString( d->starttime) ) + fm.width( QLatin1String( "XXX" ) );
00507 
00508     QList< qint64 > major;
00509     QList< qint64 > minor;
00510     d->getTickmarkValues( major, minor, minw );
00511 
00512     if( minor.isEmpty() )
00513         return;
00514 
00515     const qint64 timex = datetime_to_usecs( currentDateTime() );
00516     const QList< qint64 >::const_iterator bound = kd_lower_bound( minor.begin(), minor.end(), timex, std::less< qint64 >() );
00517     if( bound != minor.begin() )
00518         setCurrentDateTime( usecs_to_datetime( *( bound - 1 ) ) );
00519     else
00520         return setCurrentDateTime( usecs_to_datetime( minor.first() ) );
00521 }

void KDTimeLineWidget::setElapsedDateTime ( const QDateTime &  dt  )  [slot]

Set the elapsed time of the timeline to dt. Current time display can be disabled by passing an invalid QDateTime to this method.

Definition at line 398 of file kdtimelinewidget.cpp.

00399 {
00400   QDateTime old = d->elapsedtime;
00401   d->elapsedtime = dt;
00402   if( old != dt ) emit elapsedDateTimeChanged(dt);
00403   update();
00404 }

void KDTimeLineWidget::setCurrentItem ( KDTimeLineWidgetItem item  )  [slot]

Sets the current items to item. item must be an item on this timeline.

Definition at line 474 of file kdtimelinewidget.cpp.

00475 {
00476   //KDTimeLineWidgetItem* old = d->currentitem;
00477   d->currentitem = item;
00478   update();
00479 }

void KDTimeLineWidget::nextCurrentItem (  )  [slot]

Sets the next item on the timeline to be current. Does nothing if there is no next item

Definition at line 525 of file kdtimelinewidget.cpp.

00526 {
00527   if( d->items.isEmpty() ) return;
00528   if( !currentItem() ) {
00529     setCurrentItem( d->items.front() );
00530   } else {
00531     /* TODO: This can be optimized */
00532     int idx = d->items.indexOf(currentItem());
00533     if( idx >= 0 && idx < d->items.size()-1 ) setCurrentItem( d->items.at(++idx) );
00534   }
00535 }

void KDTimeLineWidget::previousCurrentItem (  )  [slot]

Sets the previous item on the timeline to be current. Does nothing if there is no previous item

Definition at line 539 of file kdtimelinewidget.cpp.

00540 {
00541   if( d->items.isEmpty() ) return;
00542   if( !currentItem() ) {
00543     setCurrentItem( d->items.front() );
00544   } else {
00545     /* TODO: This can be optimized */
00546     int idx = d->items.indexOf(currentItem());
00547     if( idx > 0 ) setCurrentItem( d->items.at(--idx) );
00548   }
00549 }


Property Documentation

QDateTime KDTimeLineWidget::startDateTime [read, write]

Returns:
the oldest point in time displayed by this KDTimeLineWidget.
See also:
KDTimeLineWidget::setStartDateTime( const QDateTime& )

Definition at line 73 of file kdtimelinewidget.h.

QDateTime KDTimeLineWidget::endDateTime [read, write]

Returns:
the youngest point in time displayed by this KDTimeLineWidget.
See also:
KDTimeLineWidget::setEndDateTime( const QDateTime& )

Definition at line 74 of file kdtimelinewidget.h.

QDateTime KDTimeLineWidget::currentDateTime [read, write]

Returns:
the datetime of the current time indicator.

Definition at line 75 of file kdtimelinewidget.h.

bool KDTimeLineWidget::snapToTickmarks [read, write]

Returns:
true if the current time indicator will snap to the minor tickmarks in this timeline and false otherwise.
See also:
KDTimeLineWidget::setSnapToTickmarks(bool)

Definition at line 77 of file kdtimelinewidget.h.


The documentation for this class was generated from the following files:
Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.net/

http://www.kdab.net/kdtools/