timespanwidget.cpp
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include <tqsplitter.h>
26#include <tqlistview.h>
27#include <tqlayout.h>
28#include <tqheader.h>
29#include <tqpushbutton.h>
30
31#include <tdelocale.h>
32#include <kdebug.h>
33
34#include <libkcal/event.h>
35
36#include "lineview.h"
37#include "timeline.h"
38
39#include "timespanwidget.h"
40#include "timespanwidget.moc"
41
42TimeSpanWidget::TimeSpanWidget( TQWidget *parent, const char *name ) :
43 TQWidget( parent, name )
44{
45 TQBoxLayout *topLayout = new TQVBoxLayout( this );
46
47 mSplitter = new TQSplitter( this );
48 topLayout->addWidget( mSplitter );
49
50 mList = new TQListView( mSplitter );
51 mList->addColumn( i18n("Summary") );
52
53 TQWidget *rightPane = new TQWidget( mSplitter );
54 TQBoxLayout *rightPaneLayout = new TQVBoxLayout( rightPane );
55
56 mTimeLine = new TimeLine( rightPane );
57 mTimeLine->setFixedHeight( mList->header()->height() );
58 rightPaneLayout->addWidget( mTimeLine );
59
60 mLineView = new LineView( rightPane );
61 rightPaneLayout->addWidget( mLineView );
62
63 TQBoxLayout *buttonLayout = new TQHBoxLayout( rightPaneLayout );
64
65 TQPushButton *zoomInButton = new TQPushButton( i18n("Zoom In"), rightPane );
66 connect( zoomInButton, TQ_SIGNAL( clicked() ), TQ_SLOT( zoomIn() ) );
67 buttonLayout->addWidget( zoomInButton );
68
69 TQPushButton *zoomOutButton = new TQPushButton( i18n("Zoom Out"), rightPane );
70 connect( zoomOutButton, TQ_SIGNAL( clicked() ), TQ_SLOT( zoomOut() ) );
71 buttonLayout->addWidget( zoomOutButton );
72
73 TQPushButton *centerButton = new TQPushButton( i18n("Center View"), rightPane );
74 connect( centerButton, TQ_SIGNAL( clicked() ), TQ_SLOT( centerView() ) );
75 buttonLayout->addWidget( centerButton );
76
77 connect(mLineView->horizontalScrollBar(),TQ_SIGNAL(valueChanged(int)),
78 mTimeLine,TQ_SLOT(setContentsPos(int)));
79}
80
81TimeSpanWidget::~TimeSpanWidget()
82{
83}
84
85TQValueList<int> TimeSpanWidget::splitterSizes()
86{
87 return mSplitter->sizes();
88}
89
90void TimeSpanWidget::setSplitterSizes( TQValueList<int> sizes )
91{
92 mSplitter->setSizes( sizes );
93}
94
95void TimeSpanWidget::addItem( KCal::Event *event )
96{
97 new TQListViewItem( mList, event->summary() );
98
99 TQDateTime startDt = event->dtStart();
100 TQDateTime endDt = event->dtEnd();
101
102// kdDebug(5850) << "TimeSpanWidget::addItem(): start: " << startDt.toString()
103// << " end: " << endDt.toString() << endl;
104
105// int startSecs = mStartDate.secsTo( startDt );
106// int durationSecs = startDt.secsTo( endDt );
107
108// kdDebug(5850) << "--- startSecs: " << startSecs << " dur: " << durationSecs << endl;
109
110 int startX = mStartDate.secsTo( startDt ) / mSecsPerPixel;
111 int endX = startX + startDt.secsTo( endDt ) / mSecsPerPixel;
112
113// kdDebug(5850) << "TimeSpanWidget::addItem(): s: " << startX << " e: " << endX << endl;
114
115 mLineView->addLine( startX, endX );
116}
117
118void TimeSpanWidget::clear()
119{
120 mList->clear();
121 mLineView->clear();
122}
123
124void TimeSpanWidget::updateView()
125{
126 mLineView->updateContents();
127 mTimeLine->updateContents();
128}
129
130void TimeSpanWidget::setDateRange( const TQDateTime &start, const TQDateTime &end )
131{
132 mStartDate = start;
133 mEndDate = end;
134
135 mTimeLine->setDateRange( start, end );
136
137 mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mLineView->pixelWidth();
138}
139
140TQDateTime TimeSpanWidget::startDateTime()
141{
142 return mStartDate;
143}
144
145TQDateTime TimeSpanWidget::endDateTime()
146{
147 return mEndDate;
148}
149
150void TimeSpanWidget::zoomIn()
151{
152 int span = mStartDate.daysTo( mEndDate );
153 setDateRange( mStartDate.addDays( span / 4 ), mEndDate.addDays( span / -4 ) );
154
155 emit dateRangeChanged();
156}
157
158void TimeSpanWidget::zoomOut()
159{
160 int span = mStartDate.daysTo( mEndDate );
161 setDateRange( mStartDate.addDays( span / -4 ), mEndDate.addDays( span / 4 ) );
162
163 emit dateRangeChanged();
164}
165
166void TimeSpanWidget::centerView()
167{
168 TQScrollBar *scrollBar = mLineView->horizontalScrollBar();
169 int min = scrollBar->minValue();
170 int max = scrollBar->maxValue();
171 scrollBar->setValue( min + (max-min) / 2 );
172}
TQString summary() const