korganizer Library API Documentation

timespanview.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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 "timespanview.h" 00040 #include "timespanview.moc" 00041 00042 TimeSpanView::TimeSpanView( 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 TimeSpanView::~TimeSpanView() 00082 { 00083 } 00084 00085 QValueList<int> TimeSpanView::splitterSizes() 00086 { 00087 return mSplitter->sizes(); 00088 } 00089 00090 void TimeSpanView::setSplitterSizes( QValueList<int> sizes ) 00091 { 00092 mSplitter->setSizes( sizes ); 00093 } 00094 00095 void TimeSpanView::addItem( KCal::Event *event ) 00096 { 00097 new QListViewItem( mList, event->summary() ); 00098 00099 QDateTime startDt = event->dtStart(); 00100 QDateTime endDt = event->dtEnd(); 00101 00102 // kdDebug(5850) << "TimeSpanView::addItem(): start: " << startDt.toString() 00103 // << " end: " << endDt.toString() << endl; 00104 00105 // int startSecs = mStartDate.secsTo( startDt ); 00106 // int durationSecs = startDt.secsTo( endDt ); 00107 00108 // kdDebug(5850) << "--- startSecs: " << startSecs << " dur: " << durationSecs << endl; 00109 00110 int startX = mStartDate.secsTo( startDt ) / mSecsPerPixel; 00111 int endX = startX + startDt.secsTo( endDt ) / mSecsPerPixel; 00112 00113 // kdDebug(5850) << "TimeSpanView::addItem(): s: " << startX << " e: " << endX << endl; 00114 00115 mLineView->addLine( startX, endX ); 00116 } 00117 00118 void TimeSpanView::clear() 00119 { 00120 mList->clear(); 00121 mLineView->clear(); 00122 } 00123 00124 void TimeSpanView::updateView() 00125 { 00126 #if QT_VERSION >= 300 00127 mLineView->updateContents(); 00128 mTimeLine->updateContents(); 00129 #else 00130 #endif 00131 } 00132 00133 void TimeSpanView::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 TimeSpanView::startDateTime() 00144 { 00145 return mStartDate; 00146 } 00147 00148 QDateTime TimeSpanView::endDateTime() 00149 { 00150 return mEndDate; 00151 } 00152 00153 void TimeSpanView::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 TimeSpanView::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 TimeSpanView::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 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:32 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003