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