1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
|
/*
This file is part of KOrganizer.
Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
As a special exception, permission is given to link this program
with any edition of TQt, and distribute the resulting executable,
without including the source code for TQt in the source distribution.
*/
#include <tqhbox.h>
#include <tqvbox.h>
#include <tqlabel.h>
#include <tqframe.h>
#include <tqlayout.h>
#ifndef KORG_NOSPLITTER
#include <tqsplitter.h>
#endif
#include <tqfont.h>
#include <tqfontmetrics.h>
#include <tqpopupmenu.h>
#include <tqtooltip.h>
#include <tqpainter.h>
#include <tqpushbutton.h>
#include <tqcursor.h>
#include <tqbitarray.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kconfig.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kholidays.h>
#include <libkcal/calendar.h>
#include <libkcal/icaldrag.h>
#include <libkcal/dndfactory.h>
#include <libkcal/calfilter.h>
#include <kcalendarsystem.h>
#include "koglobals.h"
#ifndef KORG_NOPLUGINS
#include "kocore.h"
#endif
#include "koprefs.h"
#include "koagenda.h"
#include "koagendaitem.h"
#include "timelabels.h"
#include "koincidencetooltip.h"
#include "kogroupware.h"
#include "kodialogmanager.h"
#include "koeventpopupmenu.h"
#include "koagendaview.h"
#include "koagendaview.moc"
using namespace KOrg;
EventIndicator::EventIndicator(Location loc,TQWidget *parent,const char *name)
: TQFrame(parent,name)
{
mColumns = 1;
mEnabled.resize( mColumns );
mLocation = loc;
if (mLocation == Top) mPixmap = KOGlobals::self()->smallIcon("upindicator");
else mPixmap = KOGlobals::self()->smallIcon("downindicator");
setMinimumHeight(mPixmap.height());
}
EventIndicator::~EventIndicator()
{
}
void EventIndicator::drawContents(TQPainter *p)
{
// kdDebug(5850) << "======== top: " << contentsRect().top() << " bottom "
// << contentsRect().bottom() << " left " << contentsRect().left()
// << " right " << contentsRect().right() << endl;
int i;
for(i=0;i<mColumns;++i) {
if (mEnabled[i]) {
int cellWidth = contentsRect().right()/mColumns;
int xOffset = KOGlobals::self()->reverseLayout() ?
(mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
i*cellWidth + cellWidth/2 -mPixmap.width()/2;
p->drawPixmap(TQPoint(xOffset,0),mPixmap);
}
}
}
void EventIndicator::changeColumns(int columns)
{
mColumns = columns;
mEnabled.resize(mColumns);
update();
}
void EventIndicator::enableColumn(int column, bool enable)
{
mEnabled[column] = enable;
}
#include <libkcal/incidence.h>
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
KOAlternateLabel::KOAlternateLabel(const TQString &shortlabel, const TQString &longlabel,
const TQString &extensivelabel, TQWidget *parent, const char *name )
: TQLabel(parent, name), mTextTypeFixed(false), mShortText(shortlabel),
mLongText(longlabel), mExtensiveText(extensivelabel)
{
setSizePolicy(TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ));
if (mExtensiveText.isEmpty()) mExtensiveText = mLongText;
squeezeTextToLabel();
}
KOAlternateLabel::~KOAlternateLabel()
{
}
void KOAlternateLabel::useShortText()
{
mTextTypeFixed = true;
TQLabel::setText( mShortText );
TQToolTip::remove( this );
TQToolTip::add( this, mExtensiveText );
update(); // for kolab/issue4350
}
void KOAlternateLabel::useLongText()
{
mTextTypeFixed = true;
TQLabel::setText( mLongText );
TQToolTip::remove( this );
TQToolTip::add( this, mExtensiveText );
update(); // for kolab/issue4350
}
void KOAlternateLabel::useExtensiveText()
{
mTextTypeFixed = true;
TQLabel::setText( mExtensiveText );
TQToolTip::remove( this );
TQToolTip::add( this, "" );
update(); // for kolab/issue4350
}
void KOAlternateLabel::useDefaultText()
{
mTextTypeFixed = false;
squeezeTextToLabel();
}
KOAlternateLabel::TextType KOAlternateLabel::largestFittingTextType() const
{
TQFontMetrics fm( fontMetrics() );
const int labelWidth = size().width();
const int longTextWidth = fm.width( mLongText );
const int extensiveTextWidth = fm.width( mExtensiveText );
if ( extensiveTextWidth <= labelWidth )
return Extensive;
else if ( longTextWidth <= labelWidth )
return Long;
else
return Short;
}
void KOAlternateLabel::setFixedType( TextType type )
{
switch ( type )
{
case Extensive: useExtensiveText(); break;
case Long: useLongText(); break;
case Short: useShortText(); break;
}
}
void KOAlternateLabel::squeezeTextToLabel()
{
if ( mTextTypeFixed )
return;
const TextType type = largestFittingTextType();
switch ( type )
{
case Extensive:
TQLabel::setText( mExtensiveText );
TQToolTip::remove( this );
TQToolTip::add( this, "" );
break;
case Long:
TQLabel::setText( mLongText );
TQToolTip::remove( this );
TQToolTip::add( this, mExtensiveText );
break;
case Short:
TQLabel::setText( mShortText );
TQToolTip::remove( this );
TQToolTip::add( this, mExtensiveText );
break;
}
update(); // for kolab/issue4350
}
void KOAlternateLabel::resizeEvent( TQResizeEvent * )
{
squeezeTextToLabel();
}
TQSize KOAlternateLabel::minimumSizeHint() const
{
TQSize sh = TQLabel::minimumSizeHint();
sh.setWidth(-1);
return sh;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
KOAgendaView::KOAgendaView( Calendar *cal,
CalendarView *calendarView,
TQWidget *parent,
const char *name,
bool isSideBySide ) :
KOrg::AgendaView (cal, parent,name), mExpandButton( 0 ),
mAllowAgendaUpdate( true ),
mUpdateItem( 0 ),
mIsSideBySide( isSideBySide ),
mPendingChanges( true ),
mAreDatesInitialized( false )
{
mSelectedDates.append(TQDate::currentDate());
mLayoutDayLabels = 0;
mDayLabelsFrame = 0;
mDayLabels = 0;
bool isRTL = KOGlobals::self()->reverseLayout();
if ( KOPrefs::instance()->compactDialogs() ) {
if ( KOPrefs::instance()->mVerticalScreen ) {
mExpandedPixmap = KOGlobals::self()->smallIcon( "1downarrow" );
mNotExpandedPixmap = KOGlobals::self()->smallIcon( "1uparrow" );
} else {
mExpandedPixmap = KOGlobals::self()->smallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
mNotExpandedPixmap = KOGlobals::self()->smallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
}
}
TQBoxLayout *topLayout = new TQVBoxLayout(this);
// Create day name labels for agenda columns
mDayLabelsFrame = new TQHBox(this);
topLayout->addWidget(mDayLabelsFrame);
// Create agenda splitter
#ifndef KORG_NOSPLITTER
mSplitterAgenda = new TQSplitter(Qt::Vertical,this);
topLayout->addWidget(mSplitterAgenda);
#if KDE_IS_VERSION( 3, 1, 93 )
mSplitterAgenda->setOpaqueResize( KGlobalSettings::opaqueResize() );
#else
mSplitterAgenda->setOpaqueResize();
#endif
mAllDayFrame = new TQHBox(mSplitterAgenda);
TQWidget *agendaFrame = new TQWidget(mSplitterAgenda);
#else
TQVBox *mainBox = new TQVBox( this );
topLayout->addWidget( mainBox );
mAllDayFrame = new TQHBox(mainBox);
TQWidget *agendaFrame = new TQWidget(mainBox);
#endif
// Create all-day agenda widget
mDummyAllDayLeft = new TQVBox( mAllDayFrame );
if ( isSideBySide )
mDummyAllDayLeft->hide();
if ( KOPrefs::instance()->compactDialogs() ) {
mExpandButton = new TQPushButton(mDummyAllDayLeft);
mExpandButton->setPixmap( mNotExpandedPixmap );
mExpandButton->setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed,
TQSizePolicy::Fixed ) );
connect( mExpandButton, TQT_SIGNAL( clicked() ), TQT_SIGNAL( toggleExpand() ) );
} else {
TQLabel *label = new TQLabel( i18n("All Day"), mDummyAllDayLeft );
label->setAlignment( TQt::AlignRight | TQt::AlignVCenter | TQt::WordBreak );
}
mAllDayAgenda = new KOAgenda( 1, calendarView, mAllDayFrame );
mAllDayAgenda->setCalendar( calendar() );
TQWidget *dummyAllDayRight = new TQWidget(mAllDayFrame);
// Create agenda frame
TQGridLayout *agendaLayout = new TQGridLayout(agendaFrame,3,3);
// TQHBox *agendaFrame = new TQHBox(splitterAgenda);
// create event indicator bars
mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
agendaLayout->addWidget(mEventIndicatorTop,0,1);
mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
agendaFrame);
agendaLayout->addWidget(mEventIndicatorBottom,2,1);
TQWidget *dummyAgendaRight = new TQWidget(agendaFrame);
agendaLayout->addWidget(dummyAgendaRight,0,2);
// Create time labels
mTimeLabels = new TimeLabels(24,agendaFrame);
agendaLayout->addWidget(mTimeLabels,1,0);
// Create agenda
mAgenda = new KOAgenda( 1, 96, KOPrefs::instance()->mHourSize, calendarView, agendaFrame );
mAgenda->setCalendar( calendar() );
agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
agendaLayout->setColStretch(1,1);
// Create event context menu for agenda
mAgendaPopup = eventPopup();
// Create event context menu for all day agenda
mAllDayAgendaPopup = eventPopup();
// make connections between dependent widgets
mTimeLabels->setAgenda(mAgenda);
if ( isSideBySide )
mTimeLabels->hide();
// Update widgets to reflect user preferences
// updateConfig();
createDayLabels( true );
if ( !isSideBySide ) {
// these blank widgets make the All Day Event box line up with the agenda
dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
}
updateTimeBarWidth();
// Scrolling
connect(mAgenda->verticalScrollBar(),TQT_SIGNAL(valueChanged(int)),
mTimeLabels, TQT_SLOT(positionChanged()));
connect( mAgenda,
TQT_SIGNAL( zoomView( const int, const TQPoint & ,const Qt::Orientation ) ),
TQT_SLOT( zoomView( const int, const TQPoint &, const Qt::Orientation ) ) );
connect(mTimeLabels->verticalScrollBar(),TQT_SIGNAL(valueChanged(int)),
TQT_SLOT(setContentsPos(int)));
// Create Events, depends on type of agenda
connect( mAgenda, TQT_SIGNAL(newTimeSpanSignal(const TQPoint &, const TQPoint &)),
TQT_SLOT(newTimeSpanSelected(const TQPoint &, const TQPoint &)));
connect( mAllDayAgenda, TQT_SIGNAL(newTimeSpanSignal(const TQPoint &, const TQPoint &)),
TQT_SLOT(newTimeSpanSelectedAllDay(const TQPoint &, const TQPoint &)));
// event indicator update
connect( mAgenda, TQT_SIGNAL(lowerYChanged(int)),
TQT_SLOT(updateEventIndicatorTop(int)));
connect( mAgenda, TQT_SIGNAL(upperYChanged(int)),
TQT_SLOT(updateEventIndicatorBottom(int)));
if ( !readOnly() ) {
connectAgenda( mAgenda, mAgendaPopup, mAllDayAgenda );
connectAgenda( mAllDayAgenda, mAllDayAgendaPopup, mAgenda);
}
if ( cal ) {
cal->registerObserver( this );
}
}
KOAgendaView::~KOAgendaView()
{
if ( calendar() )
calendar()->unregisterObserver( this );
delete mAgendaPopup;
delete mAllDayAgendaPopup;
}
void KOAgendaView::connectAgenda( KOAgenda *agenda, TQPopupMenu *popup,
KOAgenda *otherAgenda )
{
connect( agenda, TQT_SIGNAL(showIncidencePopupSignal(Calendar *,Incidence *,const TQDate &)),
popup, TQT_SLOT(showIncidencePopup(Calendar *,Incidence *,const TQDate &)) );
connect( agenda, TQT_SIGNAL(showNewEventPopupSignal()),
TQT_SLOT(showNewEventPopup()) );
// Create/Show/Edit/Delete Event
connect( agenda, TQT_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &)),
TQT_SIGNAL(newEventSignal(ResourceCalendar *,const TQString &)) );
connect( agenda, TQT_SIGNAL(newStartSelectSignal()),
otherAgenda, TQT_SLOT(clearSelection()) );
connect( agenda, TQT_SIGNAL(newStartSelectSignal()),
TQT_SIGNAL(timeSpanSelectionChanged()) );
connect( agenda, TQT_SIGNAL(editIncidenceSignal(Incidence *,const TQDate &)),
TQT_SIGNAL(editIncidenceSignal(Incidence *,const TQDate &)) );
connect( agenda, TQT_SIGNAL(showIncidenceSignal(Incidence *,const TQDate &)),
TQT_SIGNAL(showIncidenceSignal(Incidence *,const TQDate &)) );
connect( agenda, TQT_SIGNAL(deleteIncidenceSignal(Incidence *)),
TQT_SIGNAL(deleteIncidenceSignal(Incidence *)) );
connect( agenda, TQT_SIGNAL(startMultiModify(const TQString &)),
TQT_SIGNAL(startMultiModify(const TQString &)) );
connect( agenda, TQT_SIGNAL(endMultiModify()),
TQT_SIGNAL(endMultiModify()) );
connect( agenda, TQT_SIGNAL(itemModified(KOAgendaItem *)),
TQT_SLOT(updateEventDates(KOAgendaItem *)) );
connect( agenda, TQT_SIGNAL(enableAgendaUpdate(bool)),
TQT_SLOT(enableAgendaUpdate(bool)) );
// drag signals
connect( agenda, TQT_SIGNAL(startDragSignal(Incidence *)),
TQT_SLOT(startDrag(Incidence *)) );
// synchronize selections
connect( agenda, TQT_SIGNAL(incidenceSelected(Incidence *,const TQDate &)),
otherAgenda, TQT_SLOT(deselectItem()) );
connect( agenda, TQT_SIGNAL(incidenceSelected(Incidence *,const TQDate &)),
TQT_SIGNAL(incidenceSelected(Incidence *,const TQDate &)) );
// rescheduling of todos by d'n'd
connect( agenda, TQT_SIGNAL(droppedToDo(Todo *,const TQPoint &,bool)),
TQT_SLOT(slotTodoDropped(Todo *,const TQPoint &,bool)) );
}
void KOAgendaView::zoomInVertically( )
{
if ( !mIsSideBySide )
KOPrefs::instance()->mHourSize++;
mAgenda->updateConfig();
mAgenda->checkScrollBoundaries();
mTimeLabels->updateConfig();
mTimeLabels->positionChanged();
mTimeLabels->tqrepaint();
updateView();
}
void KOAgendaView::zoomOutVertically( )
{
if ( KOPrefs::instance()->mHourSize > 4 || mIsSideBySide ) {
if ( !mIsSideBySide )
KOPrefs::instance()->mHourSize--;
mAgenda->updateConfig();
mAgenda->checkScrollBoundaries();
mTimeLabels->updateConfig();
mTimeLabels->positionChanged();
mTimeLabels->tqrepaint();
updateView();
}
}
void KOAgendaView::zoomInHorizontally( const TQDate &date)
{
TQDate begin;
TQDate newBegin;
TQDate dateToZoom = date;
int ndays,count;
begin = mSelectedDates.first();
ndays = begin.daysTo( mSelectedDates.last() );
// zoom with Action and are there a selected Incidence?, Yes, I zoom in to it.
if ( ! dateToZoom.isValid () )
dateToZoom=mAgenda->selectedIncidenceDate();
if( !dateToZoom.isValid() ) {
if ( ndays > 1 ) {
newBegin=begin.addDays(1);
count = ndays-1;
emit zoomViewHorizontally ( newBegin , count );
}
} else {
if ( ndays <= 2 ) {
newBegin = dateToZoom;
count = 1;
} else {
newBegin = dateToZoom.addDays( -ndays/2 +1 );
count = ndays -1 ;
}
emit zoomViewHorizontally ( newBegin , count );
}
}
void KOAgendaView::zoomOutHorizontally( const TQDate &date )
{
TQDate begin;
TQDate newBegin;
TQDate dateToZoom = date;
int ndays,count;
begin = mSelectedDates.first();
ndays = begin.daysTo( mSelectedDates.last() );
// zoom with Action and are there a selected Incidence?, Yes, I zoom out to it.
if ( ! dateToZoom.isValid () )
dateToZoom=mAgenda->selectedIncidenceDate();
if ( !dateToZoom.isValid() ) {
newBegin = begin.addDays(-1);
count = ndays+3 ;
} else {
newBegin = dateToZoom.addDays( -ndays/2-1 );
count = ndays+3;
}
if ( abs( count ) >= 31 )
kdDebug(5850) << "change to the mounth view?"<<endl;
else
//We want to center the date
emit zoomViewHorizontally( newBegin, count );
}
void KOAgendaView::zoomView( const int delta, const TQPoint &pos,
const Qt::Orientation orient )
{
static TQDate zoomDate;
static TQTimer *t = new TQTimer( this );
//Zoom to the selected incidence, on the other way
// zoom to the date on screen after the first mousewheel move.
if ( orient == Qt::Horizontal ) {
TQDate date=mAgenda->selectedIncidenceDate();
if ( date.isValid() )
zoomDate=date;
else{
if ( !t->isActive() ) {
zoomDate= mSelectedDates[pos.x()];
}
t->start ( 1000,true );
}
if ( delta > 0 )
zoomOutHorizontally( zoomDate );
else
zoomInHorizontally( zoomDate );
} else {
// Qt::Vertical zoom
TQPoint posConstentsOld = mAgenda->gridToContents(pos);
if ( delta > 0 ) {
zoomOutVertically();
} else {
zoomInVertically();
}
TQPoint posConstentsNew = mAgenda->gridToContents(pos);
mAgenda->scrollBy( 0, posConstentsNew.y() - posConstentsOld.y() );
}
}
void KOAgendaView::createDayLabels( bool force )
{
// kdDebug(5850) << "KOAgendaView::createDayLabels()" << endl;
// Check if mSelectedDates has changed, if not just return
// Removes some flickering and gains speed (since this is called by each updateView())
if ( !force && mSaveSelectedDates == mSelectedDates ) {
return;
}
mSaveSelectedDates = mSelectedDates;
delete mDayLabels;
mDateDayLabels.clear();
mDayLabels = new TQFrame (mDayLabelsFrame);
mLayoutDayLabels = new TQHBoxLayout(mDayLabels);
if ( !mIsSideBySide )
mLayoutDayLabels->addSpacing(mTimeLabels->width());
const KCalendarSystem*calsys=KOGlobals::self()->calendarSystem();
DateList::ConstIterator dit;
for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) {
TQDate date = *dit;
TQBoxLayout *dayLayout = new TQVBoxLayout(mLayoutDayLabels);
mLayoutDayLabels->setStretchFactor(dayLayout, 1);
// dayLayout->setMinimumWidth(1);
int dW = calsys->dayOfWeek(date);
TQString veryLongStr = KGlobal::locale()->formatDate( date );
TQString longstr = i18n( "short_weekday date (e.g. Mon 13)","%1 %2" )
.tqarg( calsys->weekDayName( dW, true ) )
.tqarg( calsys->day(date) );
TQString shortstr = TQString::number(calsys->day(date));
KOAlternateLabel *dayLabel = new KOAlternateLabel(shortstr,
longstr, veryLongStr, mDayLabels);
dayLabel->useShortText(); // will be recalculated in updateDayLabelSizes() anyway
dayLabel->setMinimumWidth(1);
dayLabel->setAlignment(TQLabel::AlignHCenter);
if (date == TQDate::currentDate()) {
TQFont font = dayLabel->font();
font.setBold(true);
dayLabel->setFont(font);
}
dayLayout->addWidget(dayLabel);
mDateDayLabels.append( dayLabel );
// if a holiday region is selected, show the holiday name
TQStringList texts = KOGlobals::self()->holiday( date );
TQStringList::ConstIterator textit = texts.begin();
for ( ; textit != texts.end(); ++textit ) {
// use a KOAlternateLabel so when the text doesn't fit any more a tooltip is used
KOAlternateLabel*label = new KOAlternateLabel( (*textit), (*textit), TQString(), mDayLabels );
label->setMinimumWidth(1);
label->setAlignment(AlignCenter);
dayLayout->addWidget(label);
}
#ifndef KORG_NOPLUGINS
CalendarDecoration::List cds = KOCore::self()->calendarDecorations();
CalendarDecoration *it;
for(it = cds.first(); it; it = cds.next()) {
TQString text = it->shortText( date );
if ( !text.isEmpty() ) {
// use a KOAlternateLabel so when the text doesn't fit any more a tooltip is used
KOAlternateLabel*label = new KOAlternateLabel( text, text, TQString(), mDayLabels );
label->setMinimumWidth(1);
label->setAlignment(AlignCenter);
dayLayout->addWidget(label);
}
}
for(it = cds.first(); it; it = cds.next()) {
TQWidget *wid = it->smallWidget(mDayLabels,date);
if ( wid ) {
// wid->setHeight(20);
dayLayout->addWidget(wid);
}
}
#endif
}
if ( !mIsSideBySide )
mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width());
mDayLabels->show();
TQTimer::singleShot( 0, this, TQT_SLOT( updateDayLabelSizes() ) );
}
void KOAgendaView::enableAgendaUpdate( bool enable )
{
mAllowAgendaUpdate = enable;
}
int KOAgendaView::maxDatesHint()
{
// Not sure about the max number of events, so return 0 for now.
return 0;
}
int KOAgendaView::currentDateCount()
{
return mSelectedDates.count();
}
Incidence::List KOAgendaView::selectedIncidences()
{
Incidence::List selected;
Incidence *incidence;
incidence = mAgenda->selectedIncidence();
if (incidence) selected.append(incidence);
incidence = mAllDayAgenda->selectedIncidence();
if (incidence) selected.append(incidence);
return selected;
}
DateList KOAgendaView::selectedIncidenceDates()
{
DateList selected;
TQDate qd;
qd = mAgenda->selectedIncidenceDate();
if (qd.isValid()) selected.append(qd);
qd = mAllDayAgenda->selectedIncidenceDate();
if (qd.isValid()) selected.append(qd);
return selected;
}
bool KOAgendaView::eventDurationHint( TQDateTime &startDt, TQDateTime &endDt,
bool &allDay )
{
if ( selectionStart().isValid() ) {
TQDateTime start = selectionStart();
TQDateTime end = selectionEnd();
if ( start.secsTo( end ) == 15*60 ) {
// One cell in the agenda view selected, e.g.
// because of a double-click, => Use the default duration
TQTime defaultDuration( KOPrefs::instance()->mDefaultDuration.time() );
int addSecs = ( defaultDuration.hour()*3600 ) +
( defaultDuration.minute()*60 );
end = start.addSecs( addSecs );
}
startDt = start;
endDt = end;
allDay = selectedIsAllDay();
return true;
}
return false;
}
/** returns if only a single cell is selected, or a range of cells */
bool KOAgendaView::selectedIsSingleCell()
{
if ( !selectionStart().isValid() || !selectionEnd().isValid() ) return false;
if (selectedIsAllDay()) {
int days = selectionStart().daysTo(selectionEnd());
return ( days < 1 );
} else {
int secs = selectionStart().secsTo(selectionEnd());
return ( secs <= 24*60*60/mAgenda->rows() );
}
}
void KOAgendaView::updateView()
{
// kdDebug(5850) << "KOAgendaView::updateView()" << endl;
fillAgenda();
}
/*
Update configuration settings for the agenda view. This method is not
complete.
*/
void KOAgendaView::updateConfig()
{
// kdDebug(5850) << "KOAgendaView::updateConfig()" << endl;
// update config for tqchildren
mTimeLabels->updateConfig();
mAgenda->updateConfig();
mAllDayAgenda->updateConfig();
// widget synchronization
// FIXME: find a better way, maybe signal/slot
mTimeLabels->positionChanged();
// for some reason, this needs to be called explicitly
mTimeLabels->tqrepaint();
updateTimeBarWidth();
// ToolTips displaying summary of events
KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
->mEnableToolTips);
setHolidayMasks();
createDayLabels( true );
updateView();
}
void KOAgendaView::updateTimeBarWidth()
{
int width;
width = mDummyAllDayLeft->fontMetrics().width( i18n("All Day") );
width = TQMAX( width, mTimeLabels->width() );
mDummyAllDayLeft->setFixedWidth( width );
mTimeLabels->setFixedWidth( width );
}
void KOAgendaView::updateDayLabelSizes()
{
// First, calculate the maximum text type that fits for all labels
KOAlternateLabel::TextType overallType = KOAlternateLabel::Extensive;
TQPtrList<KOAlternateLabel>::const_iterator it = mDateDayLabels.constBegin();
for( ; it != mDateDayLabels.constEnd(); it++ ) {
KOAlternateLabel::TextType type = (*it)->largestFittingTextType();
if ( type < overallType )
overallType = type;
}
// Then, set that maximum text type to all the labels
it = mDateDayLabels.constBegin();
for( ; it != mDateDayLabels.constEnd(); it++ ) {
(*it)->setFixedType( overallType );
}
}
void KOAgendaView::resizeEvent( TQResizeEvent *resizeEvent )
{
updateDayLabelSizes();
KOrg::AgendaView::resizeEvent( resizeEvent );
}
void KOAgendaView::updateEventDates( KOAgendaItem *item )
{
kdDebug(5850) << "KOAgendaView::updateEventDates(): " << item->text()
<< "; item->cellXLeft(): " << item->cellXLeft()
<< "; item->cellYTop(): " << item->cellYTop()
<< "; item->lastMultiItem(): " << item->lastMultiItem()
<< "; item->itemPos(): " << item->itemPos()
<< "; item->itemCount(): " << item->itemCount()
<< endl;
TQDateTime startDt, endDt;
// Start date of this incidence, calculate the offset from it (so recurring and
// non-recurring items can be treated exactly the same, we never need to check
// for doesRecur(), because we only move the start day by the number of days the
// agenda item was really moved. Smart, isn't it?)
TQDate thisDate;
if ( item->cellXLeft() < 0 ) {
thisDate = ( mSelectedDates.first() ).addDays( item->cellXLeft() );
} else {
thisDate = mSelectedDates[ item->cellXLeft() ];
}
TQDate oldThisDate( item->itemDate() );
const int daysOffset = oldThisDate.daysTo( thisDate );
int daysLength = 0;
// startDt.setDate( startDate );
Incidence *incidence = item->incidence();
if ( !incidence ) {
return;
}
if ( !mChanger ||
!mChanger->beginChange( incidence, resourceCalendar(), subResourceCalendar() ) ) {
return;
}
Incidence *oldIncidence = incidence->clone();
TQTime startTime( 0, 0, 0 ), endTime( 0, 0, 0 );
if ( incidence->doesFloat() ) {
daysLength = item->cellWidth() - 1;
} else {
startTime = mAgenda->gyToTime( item->cellYTop() );
if ( item->lastMultiItem() ) {
endTime = mAgenda->gyToTime( item->lastMultiItem()->cellYBottom() + 1 );
daysLength = item->lastMultiItem()->cellXLeft() - item->cellXLeft();
kdDebug(5850) << "item->lastMultiItem()->cellXLeft(): " << item->lastMultiItem()->cellXLeft()
<< endl;
} else if ( item->itemPos() == item->itemCount() && item->itemCount() > 1 ) {
/* multiitem handling in agenda assumes two things:
- The start (first KOAgendaItem) is always visible.
- The first KOAgendaItem of the incidence has a non-null item->lastMultiItem()
pointing to the last KOagendaItem.
But those aren't always met, for example when in day-view.
kolab/issue4417
*/
// Cornercase 1: - Resizing the end of the event but the start isn't visible
endTime = mAgenda->gyToTime( item->cellYBottom() + 1 );
daysLength = item->itemCount() - 1;
startTime = incidence->dtStart().time();
} else if ( item->itemPos() == 1 && item->itemCount() > 1 ) {
// Cornercase 2: - Resizing the start of the event but the end isn't visible
endTime = incidence->dtEnd().time();
daysLength = item->itemCount() - 1;
} else {
endTime = mAgenda->gyToTime( item->cellYBottom() + 1 );
}
}
kdDebug(5850) << "daysLength: " << daysLength << "; startTime: " << startTime
<< "; endTime: " << endTime << "; thisDate: " << thisDate
<< "; incidence->dtStart(): " << incidence->dtStart() << endl;
// FIXME: use a visitor here
if ( incidence->type() == "Event" ) {
startDt = incidence->dtStart();
startDt = startDt.addDays( daysOffset );
startDt.setTime( startTime );
endDt = startDt.addDays( daysLength );
endDt.setTime( endTime );
Event* ev = static_cast<Event*>( incidence );
if ( incidence->dtStart() == startDt && ev->dtEnd() == endDt ) {
// No change
delete oldIncidence;
return;
}
incidence->setDtStart( startDt );
ev->setDtEnd( endDt );
} else if ( incidence->type() == "Todo" ) {
Todo *td = static_cast<Todo*>( incidence );
startDt = td->hasStartDate() ? td->dtStart() : td->dtDue();
startDt = thisDate.addDays( td->dtDue().daysTo( startDt ) );
startDt.setTime( startTime );
endDt.setDate( thisDate );
endDt.setTime( endTime );
if( td->dtDue() == endDt ) {
// No change
delete oldIncidence;
return;
}
}
// FIXME: Adjusting the recurrence should really go to CalendarView so this
// functionality will also be available in other views!
// TODO_Recurrence: This does not belong here, and I'm not really sure
// how it's supposed to work anyway.
/*
Recurrence *recur = incidence->recurrence();
if ( recur->doesRecur() && daysOffset != 0 ) {
switch ( recur->recurrenceType() ) {
case Recurrence::rYearlyPos: {
int freq = recur->frequency();
int duration = recur->duration();
TQDate endDt( recur->endDate() );
bool negative = false;
TQPtrList<Recurrence::rMonthPos> monthPos( recur->yearMonthPositions() );
if ( monthPos.first() ) {
negative = monthPos.first()->negative;
}
TQBitArray days( 7 );
int pos = 0;
days.fill( false );
days.setBit( thisDate.dayOfWeek() - 1 );
if ( negative ) {
pos = - ( thisDate.daysInMonth() - thisDate.day() - 1 ) / 7 - 1;
} else {
pos = ( thisDate.day()-1 ) / 7 + 1;
}
// Terrible hack: to change the month days, I have to unset the recurrence, and set all days manually again
recur->unsetRecurs();
if ( duration != 0 ) {
recur->setYearly( Recurrence::rYearlyPos, freq, duration );
} else {
recur->setYearly( Recurrence::rYearlyPos, freq, endDt );
}
recur->addYearlyMonthPos( pos, days );
recur->addYearlyNum( thisDate.month() );
break; }
case Recurrence::rYearlyDay: {
int freq = recur->frequency();
int duration = recur->duration();
TQDate endDt( recur->endDate() );
// Terrible hack: to change the month days, I have to unset the recurrence, and set all days manually again
recur->unsetRecurs();
if ( duration == 0 ) { // end by date
recur->setYearly( Recurrence::rYearlyDay, freq, endDt );
} else {
recur->setYearly( Recurrence::rYearlyDay, freq, duration );
}
recur->addYearlyNum( thisDate.dayOfYear() );
break; }
case Recurrence::rYearlyMonth: {
int freq = recur->frequency();
int duration = recur->duration();
TQDate endDt( recur->endDate() );
// Terrible hack: to change the month days, I have to unset the recurrence, and set all days manually again
recur->unsetRecurs();
if ( duration != 0 ) {
recur->setYearlyByDate( thisDate.day(), recur->feb29YearlyType(), freq, duration );
} else {
recur->setYearlyByDate( thisDate.day(), recur->feb29YearlyType(), freq, endDt );
}
recur->addYearlyNum( thisDate.month() );
break; }
case Recurrence::rMonthlyPos: {
int freq = recur->frequency();
int duration = recur->duration();
TQDate endDt( recur->endDate() );
TQPtrList<Recurrence::rMonthPos> monthPos( recur->monthPositions() );
if ( !monthPos.isEmpty() ) {
// FIXME: How shall I adapt the day x of week Y if we move the date across month borders???
// for now, just use the date of the moved item and assume the recurrence only occurs on that day.
// That's fine for korganizer, but might mess up other organizers.
TQBitArray rDays( 7 );
rDays = monthPos.first()->rDays;
bool negative = monthPos.first()->negative;
int newPos;
rDays.fill( false );
rDays.setBit( thisDate.dayOfWeek() - 1 );
if ( negative ) {
newPos = - ( thisDate.daysInMonth() - thisDate.day() - 1 ) / 7 - 1;
} else {
newPos = ( thisDate.day()-1 ) / 7 + 1;
}
// Terrible hack: to change the month days, I have to unset the recurrence, and set all days manually again
recur->unsetRecurs();
if ( duration == 0 ) { // end by date
recur->setMonthly( Recurrence::rMonthlyPos, freq, endDt );
} else {
recur->setMonthly( Recurrence::rMonthlyPos, freq, duration );
}
recur->addMonthlyPos( newPos, rDays );
}
break;}
case Recurrence::rMonthlyDay: {
int freq = recur->frequency();
int duration = recur->duration();
TQDate endDt( recur->endDate() );
TQPtrList<int> monthDays( recur->monthDays() );
// Terrible hack: to change the month days, I have to unset the recurrence, and set all days manually again
recur->unsetRecurs();
if ( duration == 0 ) { // end by date
recur->setMonthly( Recurrence::rMonthlyDay, freq, endDt );
} else {
recur->setMonthly( Recurrence::rMonthlyDay, freq, duration );
}
// FIXME: How shall I adapt the n-th day if we move the date across month borders???
// for now, just use the date of the moved item and assume the recurrence only occurs on that day.
// That's fine for korganizer, but might mess up other organizers.
recur->addMonthlyDay( thisDate.day() );
break;}
case Recurrence::rWeekly: {
TQBitArray days(7), oldDays( recur->days() );
int offset = daysOffset % 7;
if ( offset<0 ) offset = (offset+7) % 7;
// rotate the days
for (int d=0; d<7; d++ ) {
days.setBit( (d+offset) % 7, oldDays.at(d) );
}
if ( recur->duration() == 0 ) { // end by date
recur->setWeekly( recur->frequency(), days, recur->endDate(), recur->weekStart() );
} else { // duration or no end
recur->setWeekly( recur->frequency(), days, recur->duration(), recur->weekStart() );
}
break;}
// nothing to be done for the following:
case Recurrence::rDaily:
case Recurrence::rHourly:
case Recurrence::rMinutely:
case Recurrence::rNone:
default:
break;
}
if ( recur->duration()==0 ) { // end by date
recur->setEndDate( recur->endDate().addDays( daysOffset ) );
}
KMessageBox::information( this, i18n("A recurring calendar item was moved "
"to a different day. The recurrence settings "
"have been updated with that move. Please check "
"them in the editor."),
i18n("Recurrence Moved"),
"RecurrenceMoveInAgendaWarning" );
}*/
// FIXME: use a visitor here
if ( incidence->type() == "Event" ) {
incidence->setDtStart( startDt );
static_cast<Event*>( incidence )->setDtEnd( endDt );
} else if ( incidence->type() == "Todo" ) {
Todo *td = static_cast<Todo*>( incidence );
if ( td->hasStartDate() ) {
td->setDtStart( startDt );
}
td->setDtDue( endDt );
}
item->setItemDate( startDt.date() );
KOIncidenceToolTip::remove( item );
KOIncidenceToolTip::add( item, calendar(), incidence, thisDate, KOAgendaItem::toolTipGroup() );
const bool result = mChanger->changeIncidence( oldIncidence, incidence,
KOGlobals::DATE_MODIFIED, this );
mChanger->endChange( incidence, resourceCalendar(), subResourceCalendar() );
delete oldIncidence;
if ( !result ) {
mPendingChanges = true;
TQTimer::singleShot( 0, this, TQT_SLOT(updateView()) );
return;
}
// don't update the agenda as the item already has the correct coordinates.
// an update would delete the current item and recreate it, but we are still
// using a pointer to that item! => CRASH
enableAgendaUpdate( false );
// We need to do this in a timer to make sure we are not deleting the item
// we are currently working on, which would lead to crashes
// Only the actually moved agenda item is already at the correct position and mustn't be
// recreated. All others have to!!!
if ( incidence->doesRecur() ) {
mUpdateItem = incidence;
TQTimer::singleShot( 0, this, TQT_SLOT( doUpdateItem() ) );
}
enableAgendaUpdate( true );
// kdDebug(5850) << "KOAgendaView::updateEventDates() done " << endl;
}
void KOAgendaView::doUpdateItem()
{
if ( mUpdateItem ) {
changeIncidenceDisplay( mUpdateItem, KOGlobals::INCIDENCEEDITED );
mUpdateItem = 0;
}
}
void KOAgendaView::showDates( const TQDate &start, const TQDate &end )
{
// kdDebug(5850) << "KOAgendaView::selectDates" << endl;
if ( !mSelectedDates.isEmpty() && mSelectedDates.first() == start
&& mSelectedDates.last() == end && !mPendingChanges )
return;
mSelectedDates.clear();
TQDate d = start;
while ( d <= end ) {
mSelectedDates.append( d );
d = d.addDays( 1 );
}
mAreDatesInitialized = true;
// and update the view
fillAgenda();
}
void KOAgendaView::showIncidences( const Incidence::List &, const TQDate & )
{
kdDebug(5850) << "KOAgendaView::showIncidences( const Incidence::List & ) is not yet implemented" << endl;
}
void KOAgendaView::insertIncidence( Incidence *incidence, const TQDate &curDate )
{
if ( !filterByResource( incidence ) ) {
return;
}
// FIXME: Use a visitor here, or some other method to get rid of the dynamic_cast's
Event *event = dynamic_cast<Event *>( incidence );
Todo *todo = dynamic_cast<Todo *>( incidence );
int curCol = mSelectedDates.first().daysTo( curDate );
// In case incidence->dtStart() isn't visible (crosses bounderies)
if ( curCol < 0 ) {
curCol = 0;
}
// The date for the event is not displayed, just ignore it
if ( curCol >= int( mSelectedDates.count() ) ) {
return;
}
// Default values, which can never be reached
mMinY[curCol] = mAgenda->timeToY( TQTime( 23, 59 ) ) + 1;
mMaxY[curCol] = mAgenda->timeToY( TQTime( 0, 0 ) ) - 1;
int beginX;
int endX;
TQDate columnDate;
if ( event ) {
TQDate firstVisibleDate = mSelectedDates.first();
// its crossing bounderies, lets calculate beginX and endX
if ( curDate < firstVisibleDate ) {
beginX = curCol + firstVisibleDate.daysTo( curDate );
endX = beginX + event->dtStart().daysTo( event->dtEnd() );
columnDate = firstVisibleDate;
} else {
beginX = curCol;
endX = beginX + event->dtStart().daysTo( event->dtEnd() );
columnDate = curDate;
}
} else if ( todo ) {
if ( !todo->hasDueDate() ) {
return; // todo shall not be displayed if it has no date
}
columnDate = curDate;
beginX = endX = curCol;
} else {
return;
}
if ( todo && todo->isOverdue() ) {
mAllDayAgenda->insertAllDayItem( incidence, columnDate, curCol, curCol );
} else if ( incidence->doesFloat() ||
( todo &&
!todo->dtDue().isValid() ) ) {
mAllDayAgenda->insertAllDayItem( incidence, columnDate, beginX, endX );
} else if ( event && event->isMultiDay() ) {
int startY = mAgenda->timeToY( event->dtStart().time() );
TQTime endtime = event->dtEnd().time();
if ( endtime == TQTime( 0, 0, 0 ) ) {
endtime = TQTime( 23, 59, 59 );
}
int endY = mAgenda->timeToY( endtime ) - 1;
if ( ( beginX <= 0 && curCol == 0 ) || beginX == curCol ) {
mAgenda->insertMultiItem( event, columnDate, beginX, endX, startY, endY );
}
if ( beginX == curCol ) {
mMaxY[curCol] = mAgenda->timeToY( TQTime( 23, 59 ) );
if ( startY < mMinY[curCol] ) {
mMinY[curCol] = startY;
}
} else if ( endX == curCol ) {
mMinY[curCol] = mAgenda->timeToY( TQTime( 0, 0 ) );
if ( endY > mMaxY[curCol] ) {
mMaxY[curCol] = endY;
}
} else {
mMinY[curCol] = mAgenda->timeToY( TQTime( 0, 0 ) );
mMaxY[curCol] = mAgenda->timeToY( TQTime( 23, 59 ) );
}
} else {
int startY = 0, endY = 0;
if ( event ) {
startY = mAgenda->timeToY( incidence->dtStart().time() );
TQTime endtime = event->dtEnd().time();
if ( endtime == TQTime( 0, 0, 0 ) ) {
endtime = TQTime( 23, 59, 59 );
}
endY = mAgenda->timeToY( endtime ) - 1;
}
if ( todo ) {
TQTime t = todo->dtDue().time();
if ( t == TQTime( 0, 0 ) ) {
t = TQTime( 23, 59 );
}
int halfHour = 1800;
if ( t.addSecs( -halfHour ) < t ) {
startY = mAgenda->timeToY( t.addSecs( -halfHour ) );
endY = mAgenda->timeToY( t ) - 1;
} else {
startY = 0;
endY = mAgenda->timeToY( t.addSecs( halfHour ) ) - 1;
}
}
if ( endY < startY ) {
endY = startY;
}
mAgenda->insertItem( incidence, columnDate, curCol, startY, endY, 1, 1 );
if ( startY < mMinY[curCol] ) {
mMinY[curCol] = startY;
}
if ( endY > mMaxY[curCol] ) {
mMaxY[curCol] = endY;
}
}
}
void KOAgendaView::changeIncidenceDisplayAdded( Incidence *incidence )
{
Todo *todo = dynamic_cast<Todo *>(incidence);
CalFilter *filter = calendar()->filter();
if ( ( filter && !filter->filterIncidence( incidence ) ) ||
( ( todo && !KOPrefs::instance()->showAllDayTodo() ) ) ) {
return;
}
displayIncidence( incidence );
}
void KOAgendaView::changeIncidenceDisplay( Incidence *incidence, int mode )
{
switch ( mode ) {
case KOGlobals::INCIDENCEADDED:
{
// Add an event. No need to recreate the whole view!
// recreating everything even causes troubles: dropping to the
// day matrix recreates the agenda items, but the evaluation is
// still in an agendaItems' code, which was deleted in the mean time.
// Thus KOrg crashes...
changeIncidenceDisplayAdded( incidence );
updateEventIndicators();
break;
}
case KOGlobals::INCIDENCEEDITED:
{
if ( mAllowAgendaUpdate ) {
removeIncidence( incidence );
changeIncidenceDisplayAdded( incidence );
}
updateEventIndicators();
break;
}
case KOGlobals::INCIDENCEDELETED:
{
removeIncidence( incidence );
updateEventIndicators();
break;
}
default:
return;
}
// HACK: Update the view if the all-day agenda has been modified.
// Do this because there are some tqlayout problems in the
// all-day agenda that are not easily solved, but clearing
// and redrawing works ok.
if ( incidence->doesFloat() ) {
updateView();
}
}
void KOAgendaView::fillAgenda( const TQDate & )
{
fillAgenda();
}
void KOAgendaView::fillAgenda()
{
if ( !mAreDatesInitialized ) {
return;
}
mPendingChanges = false;
/* Remember the uids of the selected items. In case one of the
* items was deleted and re-added, we want to reselect it. */
const TQString &selectedAgendaUid = mAgenda->lastSelectedUid();
const TQString &selectedAllDayAgendaUid = mAllDayAgenda->lastSelectedUid();
enableAgendaUpdate( true );
clearView();
mAllDayAgenda->changeColumns( mSelectedDates.count() );
mAgenda->changeColumns( mSelectedDates.count() );
mEventIndicatorTop->changeColumns( mSelectedDates.count() );
mEventIndicatorBottom->changeColumns( mSelectedDates.count() );
createDayLabels( false );
setHolidayMasks();
mMinY.resize( mSelectedDates.count() );
mMaxY.resize( mSelectedDates.count() );
mAgenda->setDateList( mSelectedDates );
bool somethingReselected = false;
Incidence::List incidences = calendar()->incidences();
for ( Incidence::List::ConstIterator it = incidences.begin(); it!=incidences.constEnd(); ++it ) {
Incidence *incidence = (*it);
displayIncidence( incidence );
if( incidence->uid() == selectedAgendaUid && !selectedAgendaUid.isNull() ) {
mAgenda->selectItemByUID( incidence->uid() );
somethingReselected = true;
}
if( incidence->uid() == selectedAllDayAgendaUid && !selectedAllDayAgendaUid.isNull() ) {
mAllDayAgenda->selectItemByUID( incidence->uid() );
somethingReselected = true;
}
}
mAgenda->checkScrollBoundaries();
updateEventIndicators();
// mAgenda->viewport()->update();
// mAllDayAgenda->viewport()->update();
// make invalid
deleteSelectedDateTime();
if( !somethingReselected ) {
emit incidenceSelected( 0, TQDate() );
}
}
void KOAgendaView::displayIncidence( Incidence *incidence )
{
TQDate today = TQDate::currentDate();
DateTimeList::iterator t;
// FIXME: use a visitor here
Todo *todo = dynamic_cast<Todo *>( incidence );
Event *event = dynamic_cast<Event *>( incidence );
TQDateTime firstVisibleDateTime = mSelectedDates.first();
TQDateTime lastVisibleDateTime = mSelectedDates.last();
lastVisibleDateTime.setTime( TQTime( 23, 59, 59, 59 ) );
firstVisibleDateTime.setTime( TQTime( 0, 0 ) );
DateTimeList dateTimeList;
TQDateTime incDtStart = incidence->dtStart();
TQDateTime incDtEnd = incidence->dtEnd();
if ( todo &&
( !KOPrefs::instance()->showAllDayTodo() || !todo->hasDueDate() ) ) {
return;
}
if ( incidence->doesRecur() ) {
int eventDuration = event ? incDtStart.daysTo( incDtEnd ) : 0;
// if there's a multiday event that starts before firstVisibleDateTime but ends after
// lets include it. timesInInterval() ignores incidences that aren't totaly inside
// the range
TQDateTime startDateTimeWithOffset = firstVisibleDateTime.addDays( -eventDuration );
dateTimeList =
incidence->recurrence()->timesInInterval( startDateTimeWithOffset,
lastVisibleDateTime );
} else {
TQDateTime dateToAdd; // date to add to our date list
TQDateTime incidenceStart;
TQDateTime incidenceEnd;
if ( todo && todo->hasDueDate() && !todo->isOverdue() ) {
// If it's not overdue it will be shown at the original date (not today)
dateToAdd = todo->dtDue();
// To-dos are drawn with the bottom of the rectangle at dtDue
// if dtDue is at 00:00, then it should be displayed in the previous day, at 23:59
if ( !todo->doesFloat() && dateToAdd.time() == TQTime( 0, 0 ) ) {
dateToAdd = dateToAdd.addSecs( -1 );
}
incidenceEnd = dateToAdd;
} else if ( event ) {
dateToAdd = incDtStart;
incidenceEnd = incDtEnd;
}
if ( incidence->doesFloat() ) {
// so comparisons with < > actually work
dateToAdd.setTime( TQTime( 0, 0 ) );
incidenceEnd.setTime( TQTime( 23, 59, 59, 59 ) );
}
if ( dateToAdd <= lastVisibleDateTime && incidenceEnd > firstVisibleDateTime ) {
dateTimeList += dateToAdd;
}
}
// ToDo items shall be displayed today if they are already overdude
TQDateTime dateTimeToday = today;
if ( todo &&
todo->isOverdue() &&
dateTimeToday >= firstVisibleDateTime &&
dateTimeToday <= lastVisibleDateTime ) {
bool doAdd = true;
if ( todo->doesRecur() ) {
/* If there's a recurring instance showing up today don't add "today" again
* we don't want the event to appear duplicated */
for ( t = dateTimeList.begin(); t != dateTimeList.end(); ++t ) {
if ( (*t).date() == today ) {
doAdd = false;
break;
}
}
}
if ( doAdd ) {
dateTimeList += dateTimeToday;
}
}
for ( t = dateTimeList.begin(); t != dateTimeList.end(); ++t ) {
insertIncidence( incidence, (*t).date() );
}
}
void KOAgendaView::clearView()
{
// kdDebug(5850) << "ClearView" << endl;
mAllDayAgenda->clear();
mAgenda->clear();
}
CalPrinterBase::PrintType KOAgendaView::printType()
{
if ( currentDateCount() == 1 ) return CalPrinterBase::Day;
else return CalPrinterBase::Week;
}
void KOAgendaView::updateEventIndicatorTop( int newY )
{
uint i;
for( i = 0; i < mMinY.size(); ++i ) {
mEventIndicatorTop->enableColumn( i, newY > mMinY[i] );
}
mEventIndicatorTop->update();
}
void KOAgendaView::updateEventIndicatorBottom( int newY )
{
uint i;
for( i = 0; i < mMaxY.size(); ++i ) {
mEventIndicatorBottom->enableColumn( i, newY <= mMaxY[i] );
}
mEventIndicatorBottom->update();
}
void KOAgendaView::slotTodoDropped( Todo *todo, const TQPoint &gpos, bool allDay )
{
if ( gpos.x()<0 || gpos.y()<0 ) return;
TQDate day = mSelectedDates[gpos.x()];
TQTime time = mAgenda->gyToTime( gpos.y() );
TQDateTime newTime( day, time );
if ( todo ) {
Todo *existingTodo = calendar()->todo( todo->uid() );
if ( existingTodo ) {
kdDebug(5850) << "Drop existing Todo" << endl;
Todo *oldTodo = existingTodo->clone();
if ( mChanger &&
mChanger->beginChange( existingTodo, resourceCalendar(), subResourceCalendar() ) ) {
existingTodo->setDtDue( newTime );
existingTodo->setFloats( allDay );
existingTodo->setHasDueDate( true );
mChanger->changeIncidence( oldTodo, existingTodo,
KOGlobals::DATE_MODIFIED, this );
mChanger->endChange( existingTodo, resourceCalendar(), subResourceCalendar() );
} else {
KMessageBox::sorry( this, i18n("Unable to modify this to-do, "
"because it cannot be locked.") );
}
delete oldTodo;
} else {
kdDebug(5850) << "Drop new Todo" << endl;
todo->setDtDue( newTime );
todo->setFloats( allDay );
todo->setHasDueDate( true );
if ( !mChanger->addIncidence( todo, 0, TQString(), this ) ) {
KODialogManager::errorSaveIncidence( this, todo );
}
}
}
}
void KOAgendaView::startDrag( Incidence *incidence )
{
#ifndef KORG_NODND
DndFactory factory( calendar() );
ICalDrag *vd = factory.createDrag( incidence, this );
if ( vd->drag() ) {
kdDebug(5850) << "KOAgendaView::startDrag(): Delete drag source" << endl;
}
#endif
}
void KOAgendaView::readSettings()
{
readSettings(KOGlobals::self()->config());
}
void KOAgendaView::readSettings(KConfig *config)
{
// kdDebug(5850) << "KOAgendaView::readSettings()" << endl;
config->setGroup("Views");
#ifndef KORG_NOSPLITTER
TQValueList<int> sizes = config->readIntListEntry("Separator AgendaView");
if (sizes.count() == 2) {
mSplitterAgenda->setSizes(sizes);
}
#endif
updateConfig();
}
void KOAgendaView::writeSettings(KConfig *config)
{
// kdDebug(5850) << "KOAgendaView::writeSettings()" << endl;
config->setGroup("Views");
#ifndef KORG_NOSPLITTER
TQValueList<int> list = mSplitterAgenda->sizes();
config->writeEntry("Separator AgendaView",list);
#endif
}
void KOAgendaView::setHolidayMasks()
{
if ( mSelectedDates.isEmpty() || !mSelectedDates[0].isValid() ) {
return;
}
mHolidayMask.resize( mSelectedDates.count() + 1 );
for( uint i = 0; i < mSelectedDates.count(); ++i ) {
mHolidayMask[i] = !KOGlobals::self()->isWorkDay( mSelectedDates[ i ] );
}
// Store the information about the day before the visible area (needed for
// overnight working hours) in the last bit of the mask:
bool showDay = !KOGlobals::self()->isWorkDay( mSelectedDates[ 0 ].addDays( -1 ) );
mHolidayMask[ mSelectedDates.count() ] = showDay;
mAgenda->setHolidayMask( &mHolidayMask );
mAllDayAgenda->setHolidayMask( &mHolidayMask );
}
void KOAgendaView::setContentsPos( int y )
{
mAgenda->setContentsPos( 0, y );
}
void KOAgendaView::setExpandedButton( bool expanded )
{
if ( !mExpandButton ) return;
if ( expanded ) {
mExpandButton->setPixmap( mExpandedPixmap );
} else {
mExpandButton->setPixmap( mNotExpandedPixmap );
}
}
void KOAgendaView::clearSelection()
{
mAgenda->deselectItem();
mAllDayAgenda->deselectItem();
}
void KOAgendaView::newTimeSpanSelectedAllDay( const TQPoint &start, const TQPoint &end )
{
newTimeSpanSelected( start, end );
mTimeSpanInAllDay = true;
}
void KOAgendaView::newTimeSpanSelected( const TQPoint &start, const TQPoint &end )
{
if (!mSelectedDates.count()) return;
mTimeSpanInAllDay = false;
TQDate dayStart = mSelectedDates[ kClamp( start.x(), 0, (int)mSelectedDates.size() - 1 ) ];
TQDate dayEnd = mSelectedDates[ kClamp( end.x(), 0, (int)mSelectedDates.size() - 1 ) ];
TQTime timeStart = mAgenda->gyToTime(start.y());
TQTime timeEnd = mAgenda->gyToTime( end.y() + 1 );
TQDateTime dtStart(dayStart,timeStart);
TQDateTime dtEnd(dayEnd,timeEnd);
mTimeSpanBegin = dtStart;
mTimeSpanEnd = dtEnd;
}
void KOAgendaView::deleteSelectedDateTime()
{
mTimeSpanBegin.setDate(TQDate());
mTimeSpanEnd.setDate(TQDate());
mTimeSpanInAllDay = false;
}
void KOAgendaView::setTypeAheadReceiver( TQObject *o )
{
mAgenda->setTypeAheadReceiver( o );
mAllDayAgenda->setTypeAheadReceiver( o );
}
void KOAgendaView::finishTypeAhead()
{
mAgenda->finishTypeAhead();
mAllDayAgenda->finishTypeAhead();
}
void KOAgendaView::removeIncidence( Incidence *incidence )
{
mAgenda->removeIncidence( incidence );
mAllDayAgenda->removeIncidence( incidence );
}
void KOAgendaView::updateEventIndicators()
{
mMinY = mAgenda->minContentsY();
mMaxY = mAgenda->maxContentsY();
mAgenda->checkScrollBoundaries();
updateEventIndicatorTop( mAgenda->visibleContentsYMin() );
updateEventIndicatorBottom( mAgenda->visibleContentsYMax() );
}
void KOAgendaView::setIncidenceChanger( IncidenceChangerBase *changer )
{
mChanger = changer;
mAgenda->setIncidenceChanger( changer );
mAllDayAgenda->setIncidenceChanger( changer );
}
void KOAgendaView::clearTimeSpanSelection()
{
mAgenda->clearSelection();
mAllDayAgenda->clearSelection();
deleteSelectedDateTime();
}
bool KOAgendaView::filterByResource( Incidence *incidence )
{
// Special handling for groupware to-dos that are in Task folders.
// Put them in the top-level "Calendar" folder for lack of a better
// place since we never show Task type folders even in the
// multiagenda view.
if ( resourceCalendar() && incidence->type() == "Todo" ) {
TQString subRes = resourceCalendar()->subresourceIdentifier( incidence );
if ( resourceCalendar()->subresourceType( subRes ) == "todo" ) {
TQString calmatch = "/.INBOX.directory/Calendar";
TQString i18nmatch = "/.INBOX.directory/" + i18n( "Calendar" );
if ( subResourceCalendar().contains( calmatch ) ||
subResourceCalendar().contains( i18nmatch ) ) {
return true;
}
}
}
// Normal handling
if ( !resourceCalendar() )
return true;
CalendarResources *calRes = dynamic_cast<CalendarResources*>( calendar() );
if ( !calRes )
return true;
if ( calRes->resource( incidence ) != resourceCalendar() )
return false;
if ( !subResourceCalendar().isEmpty() ) {
if ( resourceCalendar()->subresourceIdentifier( incidence ) != subResourceCalendar() )
return false;
}
return true;
}
void KOAgendaView::resourcesChanged()
{
mPendingChanges = true;
}
void KOAgendaView::calendarIncidenceAdded(Incidence * incidence)
{
Q_UNUSED( incidence );
mPendingChanges = true;
}
void KOAgendaView::calendarIncidenceChanged(Incidence * incidence)
{
Q_UNUSED( incidence );
mPendingChanges = true;
}
void KOAgendaView::calendarIncidenceDeleted(Incidence * incidence)
{
Q_UNUSED( incidence );
mPendingChanges = true;
}
|