summaryrefslogtreecommitdiffabout
path: root/korganizer/timespanview.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/timespanview.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'korganizer/timespanview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/timespanview.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/korganizer/timespanview.cpp b/korganizer/timespanview.cpp
new file mode 100644
index 0000000..f8314e7
--- a/dev/null
+++ b/korganizer/timespanview.cpp
@@ -0,0 +1,158 @@
1
2#ifndef DESKTOP_VERSION
3#include <qksplitter.h>
4#else
5#include <qsplitter.h>
6#endif
7#include <qlistview.h>
8#include <qlayout.h>
9#include <qheader.h>
10#include <qpushbutton.h>
11
12#include <klocale.h>
13#include <kdebug.h>
14
15#include "lineview.h"
16#include "timeline.h"
17
18#include "timespanview.h"
19#include "timespanview.moc"
20
21
22TimeSpanView::TimeSpanView( QWidget *parent, const char *name ) :
23 QWidget( parent, name )
24{
25 QBoxLayout *topLayout = new QVBoxLayout( this );
26#ifndef DESKTOP_VERSION
27 mSplitter = new QKSplitter( this );
28#else
29 mSplitter = new QSplitter( this );
30#endif
31 topLayout->addWidget( mSplitter );
32
33 mList = new QListView( mSplitter );
34 mList->addColumn( i18n("Summary") );
35
36 QWidget *rightPane = new QWidget( mSplitter );
37 QBoxLayout *rightPaneLayout = new QVBoxLayout( rightPane );
38
39 mTimeLine = new TimeLine( rightPane );
40 mTimeLine->setFixedHeight( mList->header()->height() );
41 rightPaneLayout->addWidget( mTimeLine );
42
43 mLineView = new LineView( rightPane );
44 rightPaneLayout->addWidget( mLineView );
45
46 QBoxLayout *buttonLayout = new QHBoxLayout( rightPaneLayout );
47
48 QPushButton *zoomInButton = new QPushButton( i18n("Zoom In"), rightPane );
49 connect( zoomInButton, SIGNAL( clicked() ), SLOT( zoomIn() ) );
50 buttonLayout->addWidget( zoomInButton );
51
52 QPushButton *zoomOutButton = new QPushButton( i18n("Zoom Out"), rightPane );
53 connect( zoomOutButton, SIGNAL( clicked() ), SLOT( zoomOut() ) );
54 buttonLayout->addWidget( zoomOutButton );
55
56 QPushButton *centerButton = new QPushButton( i18n("Center View"), rightPane );
57 connect( centerButton, SIGNAL( clicked() ), SLOT( centerView() ) );
58 buttonLayout->addWidget( centerButton );
59
60 connect(mLineView->horizontalScrollBar(),SIGNAL(valueChanged(int)),
61 mTimeLine,SLOT(setContentsPos(int)));
62}
63
64TimeSpanView::~TimeSpanView()
65{
66}
67
68QValueList<int> TimeSpanView::splitterSizes()
69{
70 return mSplitter->sizes();
71}
72
73void TimeSpanView::setSplitterSizes( QValueList<int> sizes )
74{
75 mSplitter->setSizes( sizes );
76}
77
78void TimeSpanView::addItem( KCal::Event *event )
79{
80 new QListViewItem( mList, event->summary() );
81
82 QDateTime startDt = event->dtStart();
83 QDateTime endDt = event->dtEnd();
84
85// kdDebug() << "TimeSpanView::addItem(): start: " << startDt.toString()
86// << " end: " << endDt.toString() << endl;
87
88 int startSecs = mStartDate.secsTo( startDt );
89 int durationSecs = startDt.secsTo( endDt );
90
91// kdDebug() << "--- startSecs: " << startSecs << " dur: " << durationSecs << endl;
92
93 int startX = mStartDate.secsTo( startDt ) / mSecsPerPixel;
94 int endX = startX + startDt.secsTo( endDt ) / mSecsPerPixel;
95
96// kdDebug() << "TimeSpanView::addItem(): s: " << startX << " e: " << endX << endl;
97
98 mLineView->addLine( startX, endX );
99}
100
101void TimeSpanView::clear()
102{
103 mList->clear();
104 mLineView->clear();
105}
106
107void TimeSpanView::updateView()
108{
109#if QT_VERSION >= 300
110 mLineView->updateContents();
111 mTimeLine->updateContents();
112#else
113#endif
114}
115
116void TimeSpanView::setDateRange( const QDateTime &start, const QDateTime &end )
117{
118 mStartDate = start;
119 mEndDate = end;
120
121 mTimeLine->setDateRange( start, end );
122
123 mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mLineView->pixelWidth();
124}
125
126QDateTime TimeSpanView::startDateTime()
127{
128 return mStartDate;
129}
130
131QDateTime TimeSpanView::endDateTime()
132{
133 return mEndDate;
134}
135
136void TimeSpanView::zoomIn()
137{
138 int span = mStartDate.daysTo( mEndDate );
139 setDateRange( mStartDate.addDays( span / 4 ), mEndDate.addDays( span / -4 ) );
140
141 emit dateRangeChanged();
142}
143
144void TimeSpanView::zoomOut()
145{
146 int span = mStartDate.daysTo( mEndDate );
147 setDateRange( mStartDate.addDays( span / -4 ), mEndDate.addDays( span / 4 ) );
148
149 emit dateRangeChanged();
150}
151
152void TimeSpanView::centerView()
153{
154 QScrollBar *scrollBar = mLineView->horizontalScrollBar();
155 int min = scrollBar->minValue();
156 int max = scrollBar->maxValue();
157 scrollBar->setValue( min + (max-min) / 2 );
158}