summaryrefslogtreecommitdiffabout
path: root/korganizer/koagendaview.cpp
Unidiff
Diffstat (limited to 'korganizer/koagendaview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index fa6b951..18f242c 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -83,111 +83,123 @@ TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
83{ 83{
84 mRows = rows; 84 mRows = rows;
85 85
86 setMinimumHeight( 20 ); 86 setMinimumHeight( 20 );
87 mCellHeight = KOPrefs::instance()->mHourSize*4; 87 mCellHeight = KOPrefs::instance()->mHourSize*4;
88 88
89 enableClipper(true); 89 enableClipper(true);
90 90
91 setHScrollBarMode(AlwaysOff); 91 setHScrollBarMode(AlwaysOff);
92 setVScrollBarMode(AlwaysOff); 92 setVScrollBarMode(AlwaysOff);
93 93
94 resizeContents(50,mRows * mCellHeight); 94 resizeContents(50,mRows * mCellHeight);
95 95
96 viewport()->setBackgroundMode( PaletteBackground ); 96 viewport()->setBackgroundMode( PaletteBackground );
97} 97}
98 98
99void TimeLabels::setCellHeight(int height) 99void TimeLabels::setCellHeight(int height)
100{ 100{
101 mCellHeight = height; 101 mCellHeight = height;
102} 102}
103 103
104/* 104/*
105 Optimization so that only the "dirty" portion of the scroll view 105 Optimization so that only the "dirty" portion of the scroll view
106 is redrawn. Unfortunately, this is not called by default paintEvent() method. 106 is redrawn. Unfortunately, this is not called by default paintEvent() method.
107*/ 107*/
108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
109{ 109{
110 110
111 // if ( globalFlagBlockAgenda ) 111 // if ( globalFlagBlockAgenda )
112 // return; 112 // return;
113 // bug: the parameters cx, cy, cw, ch are the areas that need to be 113 // bug: the parameters cx, cy, cw, ch are the areas that need to be
114 // redrawn, not the area of the widget. unfortunately, this 114 // redrawn, not the area of the widget. unfortunately, this
115 // code assumes the latter... 115 // code assumes the latter...
116 116
117 // now, for a workaround... 117 // now, for a workaround...
118 // these two assignments fix the weird redraw bug 118 // these two assignments fix the weird redraw bug
119 cx = contentsX() + 2; 119 cx = contentsX() + 2;
120 cw = contentsWidth() - 2; 120 cw = contentsWidth() - 2;
121 // end of workaround 121 // end of workaround
122 122
123 int cell = ((int)(cy/mCellHeight)); 123 int cell = ((int)(cy/mCellHeight));
124 int y = cell * mCellHeight; 124 int y = cell * mCellHeight;
125 QFontMetrics fm = fontMetrics(); 125 QFontMetrics fm = fontMetrics();
126 QString hour; 126 QString hour;
127 QString suffix; 127 QString suffix;
128 QString fullTime; 128 QString fullTime;
129 int tW = fm.width("24:00i"); 129 int tW = fm.width("24:00i");
130 int timeHeight = fm.height(); 130 int timeHeight = fm.height();
131 timeHeight -= (timeHeight/4-2); 131 //timeHeight -= (timeHeight/4-2);
132 int borderWidth = 0; 132 int borderWidth = 0;
133 QFont nFont = p->font(); 133 QFont nFont = p->font();
134 QFont sFont = nFont; 134
135 sFont.setPointSize( sFont.pointSize()/2+2 );
136 if (!KGlobal::locale()->use12Clock()) 135 if (!KGlobal::locale()->use12Clock())
137 suffix = "00"; 136 suffix = "00";
138 else 137 else
139 borderWidth = 0; 138 borderWidth = 0;
140 QFontMetrics fmS( sFont );
141 int sHei = fmS.height();
142 if ( timeHeight > mCellHeight ) { 139 if ( timeHeight > mCellHeight ) {
143 timeHeight = mCellHeight-1; 140 timeHeight = mCellHeight-1;
144 sHei -= 2; 141 int pointS = nFont.pointSize();
142 while ( pointS > 4 ) {
143 nFont.setPointSize( pointS );
144 fm = QFontMetrics( nFont );
145 if ( fm.height() < mCellHeight )
146 break;
147 -- pointS;
148 }
149 fm = QFontMetrics( nFont );
150 borderWidth = 4;
151 timeHeight = fm.height();
145 } 152 }
153 timeHeight -= (timeHeight/4-2);
154 QFont sFont = nFont;
155 sFont.setPointSize( sFont.pointSize()/2+2 );
156 QFontMetrics fmS( sFont );
157 int sHei = fmS.height();
146 158
147 while (y < cy + ch) { 159 while (y < cy + ch) {
148 p->drawLine(cx,y,cx+tW,y); 160 p->drawLine(cx,y,cx+tW,y);
149 hour.setNum(cell); 161 hour.setNum(cell);
150 162
151 // handle 24h and am/pm time formats 163 // handle 24h and am/pm time formats
152 if (KGlobal::locale()->use12Clock()) { 164 if (KGlobal::locale()->use12Clock()) {
153 if (cell > 11) suffix = "pm"; 165 if (cell > 11) suffix = "pm";
154 else 166 else
155 suffix = "am"; 167 suffix = "am";
156 if (cell == 0) hour.setNum(12); 168 if (cell == 0) hour.setNum(12);
157 if (cell > 12) hour.setNum(cell - 12); 169 if (cell > 12) hour.setNum(cell - 12);
158 } 170 }
159 171
160 // create string in format of "XX:XX" or "XXpm/am" 172 // create string in format of "XX:XX" or "XXpm/am"
161 fullTime = hour;// + suffix; 173 fullTime = hour;// + suffix;
162 174
163 // center and draw the time label 175 // center and draw the time label
164 int timeWidth = fm.width(fullTime+"i"); 176 int timeWidth = fm.width(fullTime+"i");
165 int tw2 = fm.width(suffix); 177 int tw2 = fm.width(suffix);
166 int offset = this->width() - timeWidth - tw2; 178 int offset = this->width() - timeWidth - tw2;
167 p->setFont( nFont ); 179 p->setFont( nFont );
168 p->drawText(cx - borderWidth + offset, y+ timeHeight, fullTime); 180 p->drawText(cx - borderWidth + offset, y+ timeHeight, fullTime);
169 p->setFont( sFont ); 181 p->setFont( sFont );
170 offset += timeWidth; 182 offset += timeWidth;
171 p->drawText(cx - borderWidth + offset, y+ sHei, suffix); 183 p->drawText(cx - borderWidth + offset, y+ sHei, suffix);
172 184
173 // increment indices 185 // increment indices
174 y += mCellHeight; 186 y += mCellHeight;
175 cell++; 187 cell++;
176 } 188 }
177} 189}
178 190
179/** 191/**
180 Calculates the minimum width. 192 Calculates the minimum width.
181*/ 193*/
182int TimeLabels::minimumWidth() const 194int TimeLabels::minimumWidth() const
183{ 195{
184 return mMiniWidth; 196 return mMiniWidth;
185} 197}
186 198
187/** updates widget's internal state */ 199/** updates widget's internal state */
188void TimeLabels::updateConfig() 200void TimeLabels::updateConfig()
189{ 201{
190 // set the font 202 // set the font
191 // config->setGroup("Fonts"); 203 // config->setGroup("Fonts");
192 // QFont font = config->readFontEntry("TimeBar Font"); 204 // QFont font = config->readFontEntry("TimeBar Font");
193 setFont(KOPrefs::instance()->mTimeBarFont); 205 setFont(KOPrefs::instance()->mTimeBarFont);
@@ -844,96 +856,102 @@ int KOAgendaView::currentDateCount()
844 856
845QPtrList<Incidence> KOAgendaView::selectedIncidences() 857QPtrList<Incidence> KOAgendaView::selectedIncidences()
846{ 858{
847 QPtrList<Incidence> selected; 859 QPtrList<Incidence> selected;
848 Incidence *incidence; 860 Incidence *incidence;
849 861
850 incidence = mAgenda->selectedIncidence(); 862 incidence = mAgenda->selectedIncidence();
851 if (incidence) selected.append(incidence); 863 if (incidence) selected.append(incidence);
852 864
853 incidence = mAllDayAgenda->selectedIncidence(); 865 incidence = mAllDayAgenda->selectedIncidence();
854 if (incidence) selected.append(incidence); 866 if (incidence) selected.append(incidence);
855 867
856 return selected; 868 return selected;
857} 869}
858 870
859DateList KOAgendaView::selectedDates() 871DateList KOAgendaView::selectedDates()
860{ 872{
861 DateList selected; 873 DateList selected;
862 QDate qd; 874 QDate qd;
863 875
864 qd = mAgenda->selectedIncidenceDate(); 876 qd = mAgenda->selectedIncidenceDate();
865 if (qd.isValid()) selected.append(qd); 877 if (qd.isValid()) selected.append(qd);
866 878
867 qd = mAllDayAgenda->selectedIncidenceDate(); 879 qd = mAllDayAgenda->selectedIncidenceDate();
868 if (qd.isValid()) selected.append(qd); 880 if (qd.isValid()) selected.append(qd);
869 881
870 return selected; 882 return selected;
871} 883}
872 884
873 885
874void KOAgendaView::updateView() 886void KOAgendaView::updateView()
875{ 887{
876 if ( mBlockUpdating ) 888 if ( mBlockUpdating )
877 return; 889 return;
878 // kdDebug() << "KOAgendaView::updateView()" << endl; 890 // kdDebug() << "KOAgendaView::updateView()" << endl;
879 fillAgenda(); 891 fillAgenda();
880 892
881} 893}
882 894
883 895
884/* 896/*
885 Update configuration settings for the agenda view. This method is not 897 Update configuration settings for the agenda view. This method is not
886 complete. 898 complete.
887*/ 899*/
888void KOAgendaView::updateConfig() 900void KOAgendaView::updateConfig()
889{ 901{
890 if ( mBlockUpdating ) 902 if ( mBlockUpdating )
891 return; 903 return;
904 if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) {
905 int old = KOPrefs::instance()->mHourSize;
906 KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1;
907 qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize );
908 }
909
892 910
893 // update config for children 911 // update config for children
894 mTimeLabels->updateConfig(); 912 mTimeLabels->updateConfig();
895 mAgenda->storePosition(); 913 mAgenda->storePosition();
896 mAgenda->updateConfig(); 914 mAgenda->updateConfig();
897 mAllDayAgenda->updateConfig(); 915 mAllDayAgenda->updateConfig();
898 // widget synchronization 916 // widget synchronization
899 //TODO: find a better way, maybe signal/slot 917 //TODO: find a better way, maybe signal/slot
900 mTimeLabels->positionChanged(); 918 mTimeLabels->positionChanged();
901 919
902 // for some reason, this needs to be called explicitly 920 // for some reason, this needs to be called explicitly
903 mTimeLabels->repaint(); 921 mTimeLabels->repaint();
904 922
905 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); 923 mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
906 924
907 // ToolTips displaying summary of events 925 // ToolTips displaying summary of events
908 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() 926 KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance()
909 ->mEnableToolTips); 927 ->mEnableToolTips);
910 928
911 //setHolidayMasks(); 929 //setHolidayMasks();
912 930
913 //createDayLabels(); called by via updateView(); 931 //createDayLabels(); called by via updateView();
914 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); 932 mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth());
915 updateView(); 933 updateView();
916 mAgenda->restorePosition(); 934 mAgenda->restorePosition();
917} 935}
918 936
919 937
920void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) 938void KOAgendaView::updateEventDates(KOAgendaItem *item, int type)
921{ 939{
922 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; 940 // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl;
923 //qDebug("KOAgendaView::updateEventDates "); 941 //qDebug("KOAgendaView::updateEventDates ");
924 QDateTime startDt,endDt; 942 QDateTime startDt,endDt;
925 QDate startDate; 943 QDate startDate;
926 int lenInSecs; 944 int lenInSecs;
927 // if ( type == KOAgenda::RESIZETOP ) 945 // if ( type == KOAgenda::RESIZETOP )
928 // qDebug("RESIZETOP "); 946 // qDebug("RESIZETOP ");
929 // if ( type == KOAgenda::RESIZEBOTTOM ) 947 // if ( type == KOAgenda::RESIZEBOTTOM )
930 // qDebug("RESIZEBOTTOM "); 948 // qDebug("RESIZEBOTTOM ");
931 // if ( type == KOAgenda::MOVE ) 949 // if ( type == KOAgenda::MOVE )
932 // qDebug("MOVE "); 950 // qDebug("MOVE ");
933 if ( item->incidence()->type() == "Event" ) { 951 if ( item->incidence()->type() == "Event" ) {
934 startDt =item->incidence()->dtStart(); 952 startDt =item->incidence()->dtStart();
935 endDt = item->incidence()->dtEnd(); 953 endDt = item->incidence()->dtEnd();
936 lenInSecs = startDt.secsTo( endDt ); 954 lenInSecs = startDt.secsTo( endDt );
937 } 955 }
938 956
939 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); 957 // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED );