korganizer Library API Documentation

timespanview.cpp

00001 #include <qsplitter.h>
00002 #include <qlistview.h>
00003 #include <qlayout.h>
00004 #include <qheader.h>
00005 #include <qpushbutton.h>
00006 
00007 #include <klocale.h>
00008 #include <kdebug.h>
00009 
00010 #include "lineview.h"
00011 #include "timeline.h"
00012 
00013 #include "timespanview.h"
00014 #include "timespanview.moc"
00015 
00016 TimeSpanView::TimeSpanView( QWidget *parent, const char *name ) :
00017   QWidget( parent, name )
00018 {
00019   QBoxLayout *topLayout = new QVBoxLayout( this );
00020 
00021   mSplitter = new QSplitter( this );
00022   topLayout->addWidget( mSplitter );
00023 
00024   mList = new QListView( mSplitter );
00025   mList->addColumn( i18n("Summary") );
00026   
00027   QWidget *rightPane = new QWidget( mSplitter );
00028   QBoxLayout *rightPaneLayout = new QVBoxLayout( rightPane );
00029 
00030   mTimeLine = new TimeLine( rightPane );
00031   mTimeLine->setFixedHeight( mList->header()->height() );
00032   rightPaneLayout->addWidget( mTimeLine );
00033   
00034   mLineView = new LineView( rightPane );
00035   rightPaneLayout->addWidget( mLineView );
00036 
00037   QBoxLayout *buttonLayout = new QHBoxLayout( rightPaneLayout );
00038   
00039   QPushButton *zoomInButton = new QPushButton( i18n("Zoom In"), rightPane );
00040   connect( zoomInButton, SIGNAL( clicked() ), SLOT( zoomIn() ) );
00041   buttonLayout->addWidget( zoomInButton );
00042   
00043   QPushButton *zoomOutButton = new QPushButton( i18n("Zoom Out"), rightPane );
00044   connect( zoomOutButton, SIGNAL( clicked() ), SLOT( zoomOut() ) );
00045   buttonLayout->addWidget( zoomOutButton );
00046   
00047   QPushButton *centerButton = new QPushButton( i18n("Center View"), rightPane );
00048   connect( centerButton, SIGNAL( clicked() ), SLOT( centerView() ) );
00049   buttonLayout->addWidget( centerButton );
00050 
00051   connect(mLineView->horizontalScrollBar(),SIGNAL(valueChanged(int)),
00052           mTimeLine,SLOT(setContentsPos(int)));
00053 }
00054 
00055 TimeSpanView::~TimeSpanView()
00056 {
00057 }
00058 
00059 QValueList<int> TimeSpanView::splitterSizes()
00060 {
00061   return mSplitter->sizes();
00062 }
00063 
00064 void TimeSpanView::setSplitterSizes( QValueList<int> sizes )
00065 {
00066   mSplitter->setSizes( sizes );
00067 }
00068 
00069 void TimeSpanView::addItem( KCal::Event *event )
00070 {
00071   new QListViewItem( mList, event->summary() );
00072   
00073   QDateTime startDt = event->dtStart();
00074   QDateTime endDt = event->dtEnd();
00075 
00076 //  kdDebug() << "TimeSpanView::addItem(): start: " << startDt.toString()
00077 //            << "  end: " << endDt.toString() << endl;
00078 
00079   int startSecs = mStartDate.secsTo( startDt );
00080   int durationSecs = startDt.secsTo( endDt );
00081   
00082 //  kdDebug() << "--- startSecs: " << startSecs << "  dur: " << durationSecs << endl;
00083 
00084   int startX = mStartDate.secsTo( startDt ) / mSecsPerPixel;
00085   int endX = startX + startDt.secsTo( endDt ) / mSecsPerPixel;
00086   
00087 //  kdDebug() << "TimeSpanView::addItem(): s: " << startX << "  e: " << endX << endl;
00088   
00089   mLineView->addLine( startX, endX );
00090 }
00091 
00092 void TimeSpanView::clear()
00093 {
00094   mList->clear();
00095   mLineView->clear();
00096 }
00097 
00098 void TimeSpanView::updateView()
00099 {
00100 #if QT_VERSION >= 300
00101   mLineView->updateContents();
00102   mTimeLine->updateContents();
00103 #else
00104 #endif
00105 }
00106 
00107 void TimeSpanView::setDateRange( const QDateTime &start, const QDateTime &end )
00108 {
00109   mStartDate = start;
00110   mEndDate = end;
00111   
00112   mTimeLine->setDateRange( start, end );
00113 
00114   mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mLineView->pixelWidth();
00115 }
00116 
00117 QDateTime TimeSpanView::startDateTime()
00118 {
00119   return mStartDate;
00120 }
00121 
00122 QDateTime TimeSpanView::endDateTime()
00123 {
00124   return mEndDate;
00125 }
00126 
00127 void TimeSpanView::zoomIn()
00128 {
00129   int span = mStartDate.daysTo( mEndDate );
00130   setDateRange( mStartDate.addDays( span / 4 ), mEndDate.addDays( span / -4 ) );
00131 
00132   emit dateRangeChanged();
00133 }
00134 
00135 void TimeSpanView::zoomOut()
00136 {
00137   int span = mStartDate.daysTo( mEndDate );
00138   setDateRange( mStartDate.addDays( span / -4 ), mEndDate.addDays( span / 4 ) );
00139 
00140   emit dateRangeChanged();
00141 }
00142 
00143 void TimeSpanView::centerView()
00144 {
00145   QScrollBar *scrollBar = mLineView->horizontalScrollBar();
00146   int min = scrollBar->minValue();
00147   int max = scrollBar->maxValue();
00148   scrollBar->setValue( min + (max-min) / 2 );
00149 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 15 11:41:10 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001