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 <tqsplitter.h>
00026 #include <tqlistview.h>
00027 #include <tqlayout.h>
00028 #include <tqheader.h>
00029 #include <tqpushbutton.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( TQWidget *parent, const char *name ) :
00043 TQWidget( parent, name )
00044 {
00045 TQBoxLayout *topLayout = new TQVBoxLayout( this );
00046
00047 mSplitter = new TQSplitter( this );
00048 topLayout->addWidget( mSplitter );
00049
00050 mList = new TQListView( mSplitter );
00051 mList->addColumn( i18n("Summary") );
00052
00053 TQWidget *rightPane = new TQWidget( mSplitter );
00054 TQBoxLayout *rightPaneLayout = new TQVBoxLayout( 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 TQBoxLayout *buttonLayout = new TQHBoxLayout( rightPaneLayout );
00064
00065 TQPushButton *zoomInButton = new TQPushButton( i18n("Zoom In"), rightPane );
00066 connect( zoomInButton, TQT_SIGNAL( clicked() ), TQT_SLOT( zoomIn() ) );
00067 buttonLayout->addWidget( zoomInButton );
00068
00069 TQPushButton *zoomOutButton = new TQPushButton( i18n("Zoom Out"), rightPane );
00070 connect( zoomOutButton, TQT_SIGNAL( clicked() ), TQT_SLOT( zoomOut() ) );
00071 buttonLayout->addWidget( zoomOutButton );
00072
00073 TQPushButton *centerButton = new TQPushButton( i18n("Center View"), rightPane );
00074 connect( centerButton, TQT_SIGNAL( clicked() ), TQT_SLOT( centerView() ) );
00075 buttonLayout->addWidget( centerButton );
00076
00077 connect(mLineView->horizontalScrollBar(),TQT_SIGNAL(valueChanged(int)),
00078 mTimeLine,TQT_SLOT(setContentsPos(int)));
00079 }
00080
00081 TimeSpanWidget::~TimeSpanWidget()
00082 {
00083 }
00084
00085 TQValueList<int> TimeSpanWidget::splitterSizes()
00086 {
00087 return mSplitter->sizes();
00088 }
00089
00090 void TimeSpanWidget::setSplitterSizes( TQValueList<int> sizes )
00091 {
00092 mSplitter->setSizes( sizes );
00093 }
00094
00095 void TimeSpanWidget::addItem( KCal::Event *event )
00096 {
00097 new TQListViewItem( mList, event->summary() );
00098
00099 TQDateTime startDt = event->dtStart();
00100 TQDateTime 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 mLineView->updateContents();
00127 mTimeLine->updateContents();
00128 }
00129
00130 void TimeSpanWidget::setDateRange( const TQDateTime &start, const TQDateTime &end )
00131 {
00132 mStartDate = start;
00133 mEndDate = end;
00134
00135 mTimeLine->setDateRange( start, end );
00136
00137 mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mLineView->pixelWidth();
00138 }
00139
00140 TQDateTime TimeSpanWidget::startDateTime()
00141 {
00142 return mStartDate;
00143 }
00144
00145 TQDateTime TimeSpanWidget::endDateTime()
00146 {
00147 return mEndDate;
00148 }
00149
00150 void TimeSpanWidget::zoomIn()
00151 {
00152 int span = mStartDate.daysTo( mEndDate );
00153 setDateRange( mStartDate.addDays( span / 4 ), mEndDate.addDays( span / -4 ) );
00154
00155 emit dateRangeChanged();
00156 }
00157
00158 void TimeSpanWidget::zoomOut()
00159 {
00160 int span = mStartDate.daysTo( mEndDate );
00161 setDateRange( mStartDate.addDays( span / -4 ), mEndDate.addDays( span / 4 ) );
00162
00163 emit dateRangeChanged();
00164 }
00165
00166 void TimeSpanWidget::centerView()
00167 {
00168 TQScrollBar *scrollBar = mLineView->horizontalScrollBar();
00169 int min = scrollBar->minValue();
00170 int max = scrollBar->maxValue();
00171 scrollBar->setValue( min + (max-min) / 2 );
00172 }
|