summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-04-02 17:04:37 (UTC)
committer zautrix <zautrix>2005-04-02 17:04:37 (UTC)
commitf3c3a836ae97ef3e65cfbcd22156b0ba6eaae578 (patch) (unidiff)
tree726772f4d535882705cda8cab76ae5460a29beab
parent470327bf20835778a29cd2ce9414baa0cc176829 (diff)
downloadkdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.zip
kdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.tar.gz
kdepimpi-f3c3a836ae97ef3e65cfbcd22156b0ba6eaae578.tar.bz2
fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp130
1 files changed, 26 insertions, 104 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 95388ef..880d399 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -99,218 +99,139 @@ TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
99} 99}
100 100
101void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
102{ 102{
103 mCellHeight = height; 103 mCellHeight = height;
104} 104}
105 105
106/* 106/*
107 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
108 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
109*/ 109*/
110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
111{ 111{
112 112
113 cx = contentsX() + frameWidth()*2; 113 cx = contentsX() + frameWidth()*2;
114 cw = contentsWidth() ; 114 cw = contentsWidth() ;
115 // end of workaround 115 // end of workaround
116 116
117 int cell = ((int)(cy/mCellHeight)); 117 int cell = ((int)(cy/mCellHeight));
118 int y = cell * mCellHeight; 118 int y = cell * mCellHeight;
119 QFontMetrics fm = fontMetrics(); 119 QFontMetrics fm = fontMetrics();
120 QString hour; 120 QString hour;
121 QString suffix = "am"; 121 QString suffix = "am";
122 int timeHeight = fm.ascent(); 122 int timeHeight = fm.ascent();
123 QFont nFont = p->font(); 123 QFont nFont = font();
124 p->setFont( font());
124 125
125 if (!KGlobal::locale()->use12Clock()) { 126 if (!KGlobal::locale()->use12Clock()) {
126 if ( QApplication::desktop()->width() <= 320 )
127 suffix = "00"; 127 suffix = "00";
128 else 128 } else
129 suffix = "00"; 129 if (cell > 11) suffix = "pm";
130 }
131 130
132 if ( timeHeight > mCellHeight ) { 131 if ( timeHeight > mCellHeight ) {
133 timeHeight = mCellHeight-1; 132 timeHeight = mCellHeight-1;
134 int pointS = nFont.pointSize(); 133 int pointS = nFont.pointSize();
135 while ( pointS > 4 ) { 134 while ( pointS > 4 ) {
136 nFont.setPointSize( pointS ); 135 nFont.setPointSize( pointS );
137 fm = QFontMetrics( nFont ); 136 fm = QFontMetrics( nFont );
138 if ( fm.ascent() < mCellHeight ) 137 if ( fm.ascent() < mCellHeight )
139 break; 138 break;
140 -- pointS; 139 -- pointS;
141 } 140 }
142 fm = QFontMetrics( nFont ); 141 fm = QFontMetrics( nFont );
143 timeHeight = fm.ascent(); 142 timeHeight = fm.ascent();
144 } 143 }
145 //timeHeight -= (timeHeight/4-2); 144 //timeHeight -= (timeHeight/4-2);
146 QFont sFont = nFont; 145 QFont sFont = nFont;
147 sFont.setPointSize( sFont.pointSize()/2 ); 146 sFont.setPointSize( sFont.pointSize()/2 );
148 QFontMetrics fmS( sFont ); 147 QFontMetrics fmS( sFont );
149 int sHei = fmS.ascent() ; 148 int sHei = fmS.ascent() ;
150 //sHei -= (sHei/4-2); 149 //sHei -= (sHei/4-2);
151 int startW = this->width() - frameWidth()-2; 150 int startW = mMiniWidth - frameWidth()-2 ;
152 int tw2 = fmS.width(suffix); 151 int tw2 = fmS.width(suffix);
153 timeHeight = (timeHeight-1) /2 -1; 152 timeHeight = (timeHeight-1) /2 -1;
153 //testline
154 //p->drawLine(0,0,0,contentsHeight());
154 while (y < cy + ch+mCellHeight) { 155 while (y < cy + ch+mCellHeight) {
155 p->drawLine(startW-tw2+1 ,y,cw,y); 156 p->drawLine(startW-tw2 ,y,cw+2,y);
156 hour.setNum(cell); 157 hour.setNum(cell);
157 // handle 24h and am/pm time formats 158 // handle 24h and am/pm time formats
158 if (KGlobal::locale()->use12Clock()) { 159 if (KGlobal::locale()->use12Clock()) {
159 if (cell > 11) suffix = "pm"; 160 if (cell == 12) suffix = "pm";
160 else
161 suffix = "am";
162 if (cell == 0) hour.setNum(12); 161 if (cell == 0) hour.setNum(12);
163 if (cell > 12) hour.setNum(cell - 12); 162 if (cell > 12) hour.setNum(cell - 12);
164 } 163 }
165 164
166 // center and draw the time label 165 // center and draw the time label
167 int timeWidth = fm.width(hour); 166 int timeWidth = fm.width(hour);
168 int offset = startW - timeWidth - tw2 ; 167 int offset = startW - timeWidth - tw2 -1 ;
169 p->setFont( nFont ); 168 p->setFont( nFont );
170 p->drawText( offset, y+ timeHeight, hour); 169 p->drawText( offset, y+ timeHeight, hour);
171 p->setFont( sFont ); 170 p->setFont( sFont );
172 offset = startW - tw2+1; 171 offset = startW - tw2;
173 p->drawText( offset, y -1, suffix); 172 p->drawText( offset, y -1, suffix);
174 173
175 // increment indices 174 // increment indices
176 y += mCellHeight; 175 y += mCellHeight;
177 cell++; 176 cell++;
178 } 177 }
179 178
180 179
181 180
182 181
183#if 0
184 mRedrawNeeded = true;
185 if ( mRedrawNeeded ) {
186 cx = contentsX() + frameWidth()*2;
187 cw = contentsWidth() ;
188 // end of workaround
189
190 int cell = ((int)(cy/mCellHeight));
191 int y = cell * mCellHeight;
192 QFontMetrics fm = fontMetrics();
193 QString hour;
194 QString suffix;
195 int timeHeight = fm.ascent();
196 QFont nFont = p->font();
197
198 if (!KGlobal::locale()->use12Clock()) {
199 if ( QApplication::desktop()->width() <= 320 )
200 suffix = "";
201 else
202 suffix = "00";
203 }
204
205 if ( timeHeight > mCellHeight ) {
206 timeHeight = mCellHeight-1;
207 int pointS = nFont.pointSize();
208 while ( pointS > 4 ) {
209 nFont.setPointSize( pointS );
210 fm = QFontMetrics( nFont );
211 if ( fm.ascent() < mCellHeight )
212 break;
213 -- pointS;
214 }
215 fm = QFontMetrics( nFont );
216 timeHeight = fm.ascent();
217 }
218 //timeHeight -= (timeHeight/4-2);
219 QFont sFont = nFont;
220 sFont.setPointSize( sFont.pointSize()/2 );
221 QFontMetrics fmS( sFont );
222 int sHei = fmS.ascent() ;
223 //sHei -= (sHei/4-2);
224 int startW = this->width() - frameWidth()-2;
225 int tw2 = fmS.width(suffix);
226 while (y < cy + ch) {
227 p->drawLine(cx,y,cw,y);
228 hour.setNum(cell);
229 // handle 24h and am/pm time formats
230 if (KGlobal::locale()->use12Clock()) {
231 if (cell > 11) suffix = "pm";
232 else
233 suffix = "am";
234 if (cell == 0) hour.setNum(12);
235 if (cell > 12) hour.setNum(cell - 12);
236 tw2 = fmS.width(suffix);
237 }
238
239 // center and draw the time label
240 int timeWidth = fm.width(hour);
241 int offset = startW - timeWidth - tw2 ;
242 p->setFont( nFont );
243 p->drawText( offset, y+ timeHeight, hour);
244 p->setFont( sFont );
245 offset = startW - tw2+1;
246 p->drawText( offset, y+ sHei, suffix);
247
248 // increment indices
249 y += mCellHeight;
250 cell++;
251 }
252 } else {
253 //qDebug("NO redraw ");
254 }
255 // double buffer not yet implemented
256 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
257 //mRedrawNeeded = false;
258#endif
259} 182}
260 183
261/** 184/**
262 Calculates the minimum width. 185 Calculates the minimum width.
263*/ 186*/
264int TimeLabels::minimumWidth() const 187int TimeLabels::minimumWidth() const
265{ 188{
266 return mMiniWidth; 189 return mMiniWidth;
267} 190}
268 191
269/** updates widget's internal state */ 192/** updates widget's internal state */
270void TimeLabels::updateConfig() 193void TimeLabels::updateConfig()
271{ 194{
272 mRedrawNeeded = true; 195 mRedrawNeeded = true;
273 // set the font 196 // set the font
274 // config->setGroup("Fonts"); 197 // config->setGroup("Fonts");
275 // QFont font = config->readFontEntry("TimeBar Font"); 198 // QFont font = config->readFontEntry("TimeBar Font");
276 setFont(KOPrefs::instance()->mTimeBarFont); 199 setFont(KOPrefs::instance()->mTimeBarFont);
277 QString test = "20"; 200 QString test = "20";
278 if (KGlobal::locale()->use12Clock()) 201 if (KGlobal::locale()->use12Clock())
279 test = "12"; 202 test = "12";
280 mMiniWidth = fontMetrics().width(test); 203 mMiniWidth = fontMetrics().width(test);
281 if (KGlobal::locale()->use12Clock()) 204 if (KGlobal::locale()->use12Clock())
282 test = "pm"; 205 test = "pm";
283 else { 206 else {
284 if ( QApplication::desktop()->width() <= 320 ) 207 test = "00";
285 test = "00";
286 else
287 test = "00";
288 } 208 }
289 QFont sFont = font(); 209 QFont sFont = font();
290 sFont.setPointSize( sFont.pointSize()/2 ); 210 sFont.setPointSize( sFont.pointSize()/2 );
291 QFontMetrics fmS( sFont ); 211 QFontMetrics fmS( sFont );
292 mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; 212 mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ;
213 qDebug("testwid %d %d", mMiniWidth ,fmS.width( test ));
293 // update geometry restrictions based on new settings 214 // update geometry restrictions based on new settings
294 setFixedWidth( mMiniWidth ); 215 setFixedWidth( mMiniWidth );
295 216
296 // update HourSize 217 // update HourSize
297 mCellHeight = KOPrefs::instance()->mHourSize*4; 218 mCellHeight = KOPrefs::instance()->mHourSize*4;
298 resizeContents(50,mRows * mCellHeight); 219 resizeContents(50,mRows * mCellHeight);
299} 220}
300 221
301/** update time label positions */ 222/** update time label positions */
302void TimeLabels::positionChanged() 223void TimeLabels::positionChanged()
303{ 224{
304 int adjustment = mAgenda->contentsY(); 225 int adjustment = mAgenda->contentsY();
305 setContentsPos(0, adjustment); 226 setContentsPos(0, adjustment);
306} 227}
307 228
308/** */ 229/** */
309void TimeLabels::setAgenda(KOAgenda* agenda) 230void TimeLabels::setAgenda(KOAgenda* agenda)
310{ 231{
311 mAgenda = agenda; 232 mAgenda = agenda;
312} 233}
313 234
314void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 235void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
315{ 236{
316 mMouseDownY = e->pos().y(); 237 mMouseDownY = e->pos().y();
@@ -713,68 +634,72 @@ void KOAgendaView::slotDaylabelClicked( int num )
713 } 634 }
714 else 635 else
715 showDateView( 10, firstDate.addDays(1) ); 636 showDateView( 10, firstDate.addDays(1) );
716} 637}
717 638
718KOAgendaButton* KOAgendaView::getNewDaylabel() 639KOAgendaButton* KOAgendaView::getNewDaylabel()
719{ 640{
720 641
721 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); 642 KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels);
722 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); 643 connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) );
723 mDayLabelsList.append( dayLabel ); 644 mDayLabelsList.append( dayLabel );
724 mLayoutDayLabels->addWidget(dayLabel); 645 mLayoutDayLabels->addWidget(dayLabel);
725 return dayLabel ; 646 return dayLabel ;
726} 647}
727 648
728void KOAgendaView::createDayLabels() 649void KOAgendaView::createDayLabels()
729{ 650{
730 651
731 if ( mBlockUpdating || globalFlagBlockLabel == 1) { 652 if ( mBlockUpdating || globalFlagBlockLabel == 1) {
732 // qDebug(" KOAgendaView::createDayLabels() blocked "); 653 // qDebug(" KOAgendaView::createDayLabels() blocked ");
733 return; 654 return;
734 655
735 } 656 }
736 int newHight; 657 int newHight;
658 if ( !mSelectedDates.count())
659 return;
737 660
738 // ### Before deleting and recreating we could check if mSelectedDates changed... 661 // ### Before deleting and recreating we could check if mSelectedDates changed...
739 // It would remove some flickering and gain speed (since this is called by 662 // It would remove some flickering and gain speed (since this is called by
740 // each updateView() call) 663 // each updateView() call)
741 664
742 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; 665 int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2;
743 if ( QApplication::desktop()->width() <= 320 )
744 maxWid -= 10;
745 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); 666 mDayLabelsFrame->setMaximumWidth( mUpcomingWidth );
746 if ( maxWid < 0 ) 667 if ( maxWid < 20 )
747 maxWid = 20; 668 maxWid = 20;
748 669
749 QFont dlf = KOPrefs::instance()->mTimeLabelsFont; 670 QFont dlf = KOPrefs::instance()->mTimeLabelsFont;
750 QFontMetrics fm ( dlf ); 671 QFontMetrics fm ( dlf );
751 int selCount = mSelectedDates.count(); 672 int selCount = mSelectedDates.count();
673 int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1;
752 QString dayTest = "Mon 20"; 674 QString dayTest = "Mon 20";
753 //QString dayTest = "Mon 20"; 675 //QString dayTest = "Mon 20";
754 int wid = fm.width( dayTest ); 676 int wid = fm.width( dayTest );
755 //maxWid -= ( selCount * 3 ); //working for QLabels 677 //maxWid -= ( selCount * 3 ); //working for QLabels
756 maxWid -= ( selCount * 3 ); //working for QPushButton 678 if ( QApplication::desktop()->width() <= 320 )
679 maxWid -= ( selCount * 3 ); //working for QPushButton
680 else
681 maxWid -= ( selCount * 3 ); //working for QPushButton
757 if ( maxWid < 0 ) 682 if ( maxWid < 0 )
758 maxWid = 20; 683 maxWid = 20;
759 int needWid = wid * selCount; 684 int needWid = wid * selCount;
760 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); 685 //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid );
761 //if ( needWid > maxWid ) 686 //if ( needWid > maxWid )
762 // qDebug("DAYLABELS TOOOOOOO BIG "); 687 // qDebug("DAYLABELS TOOOOOOO BIG ");
763 while ( needWid > maxWid ) { 688 while ( needWid > maxWid ) {
764 dayTest = dayTest.left( dayTest.length() - 1 ); 689 dayTest = dayTest.left( dayTest.length() - 1 );
765 wid = fm.width( dayTest ); 690 wid = fm.width( dayTest );
766 needWid = wid * selCount; 691 needWid = wid * selCount;
767 } 692 }
768 int maxLen = dayTest.length(); 693 int maxLen = dayTest.length();
769 int fontPoint = dlf.pointSize(); 694 int fontPoint = dlf.pointSize();
770 if ( maxLen < 2 ) { 695 if ( maxLen < 2 ) {
771 int fontPoint = dlf.pointSize(); 696 int fontPoint = dlf.pointSize();
772 while ( fontPoint > 4 ) { 697 while ( fontPoint > 4 ) {
773 --fontPoint; 698 --fontPoint;
774 dlf.setPointSize( fontPoint ); 699 dlf.setPointSize( fontPoint );
775 QFontMetrics f( dlf ); 700 QFontMetrics f( dlf );
776 wid = f.width( "30" ); 701 wid = f.width( "30" );
777 needWid = wid * selCount; 702 needWid = wid * selCount;
778 if ( needWid < maxWid ) 703 if ( needWid < maxWid )
779 break; 704 break;
780 } 705 }
@@ -891,59 +816,56 @@ void KOAgendaView::createDayLabels()
891 QLabel *label = new QLabel(text,mDayLabels); 816 QLabel *label = new QLabel(text,mDayLabels);
892 label->setAlignment(AlignCenter); 817 label->setAlignment(AlignCenter);
893 dayLayout->addWidget(label); 818 dayLayout->addWidget(label);
894 } 819 }
895 } 820 }
896 821
897 for(it = cds.first(); it; it = cds.next()) { 822 for(it = cds.first(); it; it = cds.next()) {
898 QWidget *wid = it->smallWidget(mDayLabels,date); 823 QWidget *wid = it->smallWidget(mDayLabels,date);
899 if ( wid ) { 824 if ( wid ) {
900 // wid->setHeight(20); 825 // wid->setHeight(20);
901 dayLayout->addWidget(wid); 826 dayLayout->addWidget(wid);
902 } 827 }
903 } 828 }
904#endif 829#endif
905 } 830 }
906 if ( ! appendLabels ) { 831 if ( ! appendLabels ) {
907 dayLabel = mDayLabelsList.next(); 832 dayLabel = mDayLabelsList.next();
908 if ( !dayLabel ) 833 if ( !dayLabel )
909 appendLabels = true; 834 appendLabels = true;
910 } 835 }
911 if ( appendLabels ) { 836 if ( appendLabels ) {
912 dayLabel = getNewDaylabel(); 837 dayLabel = getNewDaylabel();
913 } 838 }
914 //dayLabel->hide();//test only 839 //dayLabel->hide();//test only
915 int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; 840
916 if ( offset < 0 ) offset = 0; 841 dayLabel->setText(">");
917 //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 );
918 dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) );
919 dayLabel->setFont( dlf ); 842 dayLabel->setFont( dlf );
920 dayLabel->setAutoRepeat( true ); 843 dayLabel->setAutoRepeat( true );
921 dayLabel->show(); 844 dayLabel->show();
922 dayLabel->setNum( -2 ); 845 dayLabel->setNum( -2 );
923 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); 846 dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo );
924 847
925 //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2);
926 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); 848 //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2);
927 if ( !appendLabels ) { 849 if ( !appendLabels ) {
928 dayLabel = mDayLabelsList.next(); 850 dayLabel = mDayLabelsList.next();
929 while ( dayLabel ) { 851 while ( dayLabel ) {
930 //qDebug("!dayLabel %d",dayLabel ); 852 //qDebug("!dayLabel %d",dayLabel );
931 dayLabel->hide(); 853 dayLabel->hide();
932 dayLabel = mDayLabelsList.next(); 854 dayLabel = mDayLabelsList.next();
933 } 855 }
934 } 856 }
935 857
936 mDayLabelsFrame->setFixedHeight( newHight + 4 ); 858 mDayLabelsFrame->setFixedHeight( newHight + 4 );
937} 859}
938 860
939int KOAgendaView::maxDatesHint() 861int KOAgendaView::maxDatesHint()
940{ 862{
941 // Not sure about the max number of events, so return 0 for now. 863 // Not sure about the max number of events, so return 0 for now.
942 return 0; 864 return 0;
943} 865}
944 866
945int KOAgendaView::currentDateCount() 867int KOAgendaView::currentDateCount()
946{ 868{
947 return mSelectedDates.count(); 869 return mSelectedDates.count();
948} 870}
949 871