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