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