summaryrefslogtreecommitdiffabout
path: root/korganizer/datenavigatorcontainer.cpp
Unidiff
Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp218
1 files changed, 218 insertions, 0 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
new file mode 100644
index 0000000..cbfc5b2
--- a/dev/null
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -0,0 +1,218 @@
1/*
2 This file is part of KOrganizer.
3
4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
24*/
25
26#include <kdebug.h>
27#include <klocale.h>
28
29//#include "koglobals.h"
30#include "navigatorbar.h"
31#include "kdatenavigator.h"
32
33#include <kcalendarsystem.h>
34
35#include "datenavigatorcontainer.h"
36
37DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
38 const char *name )
39 : QWidget( parent, name ), mCalendar( 0 ),
40 mHorizontalCount( 1 ), mVerticalCount( 1 )
41{
42 mExtraViews.setAutoDelete( true );
43
44 mNavigatorView = new KDateNavigator( this, name );
45
46 connectNavigatorView( mNavigatorView );
47}
48
49DateNavigatorContainer::~DateNavigatorContainer()
50{
51}
52
53void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
54{
55 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
56 SIGNAL( datesSelected( const KCal::DateList & ) ) );
57#if 0
58 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
59 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
60 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
61 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
62#endif
63 connect( v, SIGNAL( weekClicked( const QDate & ) ),
64 SIGNAL( weekClicked( const QDate & ) ) );
65
66 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
67 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
68
69 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
70 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
71 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
72 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
73
74 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) );
75}
76
77void DateNavigatorContainer::setCalendar( Calendar *cal )
78{
79 mCalendar = cal;
80 mNavigatorView->setCalendar( cal );
81 KDateNavigator *n;
82 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
83 n->setCalendar( cal );
84 }
85}
86
87void DateNavigatorContainer::updateDayMatrix()
88{
89 mNavigatorView->updateDayMatrix();
90 KDateNavigator *n;
91 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
92 n->updateDayMatrix();
93 }
94}
95
96void DateNavigatorContainer::updateToday()
97{
98 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
99#if 0
100 mNavigatorView->updateToday();
101 KDateNavigator *n;
102 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
103 n->updateToday();
104 }
105#endif
106}
107
108void DateNavigatorContainer::updateView()
109{
110 mNavigatorView->updateView();
111 KDateNavigator *n;
112 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
113 n->updateView();
114 }
115}
116
117void DateNavigatorContainer::updateConfig()
118{
119 mNavigatorView->updateConfig();
120 KDateNavigator *n;
121 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
122 n->updateConfig();
123 }
124}
125
126void DateNavigatorContainer::selectDates( const DateList &dateList )
127{
128 mNavigatorView->selectDates( dateList );
129 setBaseDates();
130}
131
132void DateNavigatorContainer::setBaseDates()
133{
134 KCal::DateList dateList = mNavigatorView->selectedDates();
135 if ( dateList.isEmpty() ) {
136 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl;
137 }
138 QDate baseDate = dateList.first();
139 KDateNavigator *n;
140 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
141 baseDate = baseDate.addDays( baseDate.daysInMonth () );
142 n->setBaseDate( baseDate );
143 }
144}
145
146void DateNavigatorContainer::resizeEvent( QResizeEvent * )
147{
148#if 0
149 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
150 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
151 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
152 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
153 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
154#endif
155
156 QSize minSize = mNavigatorView->minimumSizeHint();
157
158// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
159
160 int verticalCount = size().height() / minSize.height();
161 int horizontalCount = size().width() / minSize.width();
162 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
163 if ( horizontalCount != mHorizontalCount ||
164 verticalCount != mVerticalCount ) {
165 uint count = horizontalCount * verticalCount;
166 if ( count == 0 ) return;
167
168 while ( count > ( mExtraViews.count() + 1 ) ) {
169 KDateNavigator *n = new KDateNavigator( this );
170 mExtraViews.append( n );
171 n->setCalendar( mCalendar );
172 setBaseDates();
173 connectNavigatorView( n );
174 n->show();
175 }
176
177 while ( count < ( mExtraViews.count() + 1 ) ) {
178 mExtraViews.removeLast();
179 }
180
181 mHorizontalCount = horizontalCount;
182 mVerticalCount = verticalCount;
183 }
184
185 int height = size().height() / verticalCount;
186 int width = size().width() / horizontalCount;
187
188 NavigatorBar *bar = mNavigatorView->navigatorBar();
189 if ( horizontalCount > 1 ) bar->showButtons( true, false );
190 else bar->showButtons( true, true );
191
192 mNavigatorView->setGeometry(0,
193 0, width, height );
194 for( uint i = 0; i < mExtraViews.count(); ++i ) {
195 int x = ( i + 1 ) % horizontalCount;
196 int y = ( i + 1 ) / horizontalCount;
197
198 KDateNavigator *view = mExtraViews.at( i );
199 bar = view->navigatorBar();
200 if ( y > 0 ) bar->showButtons( false, false );
201 else {
202 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
203 else bar->showButtons( false, false );
204 }
205 view->setGeometry( x * width,
206 y * height, width, height );
207 }
208}
209
210QSize DateNavigatorContainer::minimumSizeHint() const
211{
212 return mNavigatorView->minimumSizeHint();
213}
214
215QSize DateNavigatorContainer::sizeHint() const
216{
217 return mNavigatorView->sizeHint();
218}