summaryrefslogtreecommitdiffabout
path: root/korganizer/koagendaview.cpp
Unidiff
Diffstat (limited to 'korganizer/koagendaview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp134
1 files changed, 72 insertions, 62 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 2996acb..218396d 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -60,163 +60,173 @@
60#endif 60#endif
61#include "koprefs.h" 61#include "koprefs.h"
62#include "koagenda.h" 62#include "koagenda.h"
63#include "koagendaitem.h" 63#include "koagendaitem.h"
64#ifndef KORG_NOPRINTER 64#ifndef KORG_NOPRINTER
65#include "calprinter.h" 65#include "calprinter.h"
66#endif 66#endif
67 67
68#include "koagendaview.h" 68#include "koagendaview.h"
69//#include "koagendaview.moc" 69//#include "koagendaview.moc"
70 70
71//extern bool globalFlagBlockPainting; 71//extern bool globalFlagBlockPainting;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) :
82 QScrollView(parent,name,f) 82 QScrollView(parent,name,f)
83{ 83{
84 myPix.resize( 1, 1 );
84 mRows = rows; 85 mRows = rows;
85 86
87 mRedrawNeeded = true;
86 setMinimumHeight( 20 ); 88 setMinimumHeight( 20 );
87 mCellHeight = KOPrefs::instance()->mHourSize*4; 89 mCellHeight = KOPrefs::instance()->mHourSize*4;
88 90
89 enableClipper(true); 91 enableClipper(true);
90 92
91 setHScrollBarMode(AlwaysOff); 93 setHScrollBarMode(AlwaysOff);
92 setVScrollBarMode(AlwaysOff); 94 setVScrollBarMode(AlwaysOff);
93 95
94 resizeContents(50,mRows * mCellHeight); 96 resizeContents(50,mRows * mCellHeight);
95 97
96 viewport()->setBackgroundMode( PaletteBackground ); 98 viewport()->setBackgroundMode( PaletteBackground );
97} 99}
98 100
99void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
100{ 102{
101 mCellHeight = height; 103 mCellHeight = height;
102} 104}
103 105
104/* 106/*
105 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
106 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
107*/ 109*/
108void 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)
109{ 111{
110 112
111 // if ( globalFlagBlockAgenda ) 113 // if ( globalFlagBlockAgenda )
112 // return; 114 // return;
113 // bug: the parameters cx, cy, cw, ch are the areas that need to be 115 // bug: the parameters cx, cy, cw, ch are the areas that need to be
114 // redrawn, not the area of the widget. unfortunately, this 116 // redrawn, not the area of the widget. unfortunately, this
115 // code assumes the latter... 117 // code assumes the latter...
116 118
117 // now, for a workaround... 119 // now, for a workaround...
118 // these two assignments fix the weird redraw bug 120 // these two assignments fix the weird redraw bug
119 cx = contentsX() + 2; 121 if ( mRedrawNeeded ) {
120 cw = contentsWidth() - 2; 122 cx = contentsX() + 2;
121 // end of workaround 123 cw = contentsWidth() - 2;
122 124 // end of workaround
123 int cell = ((int)(cy/mCellHeight)); 125
124 int y = cell * mCellHeight; 126 int cell = ((int)(cy/mCellHeight));
125 QFontMetrics fm = fontMetrics(); 127 int y = cell * mCellHeight;
126 QString hour; 128 QFontMetrics fm = fontMetrics();
127 QString suffix; 129 QString hour;
128 int tW = fm.width("24:00i"); 130 QString suffix;
129 int timeHeight = fm.height(); 131 int tW = fm.width("24:00i");
130 //timeHeight -= (timeHeight/4-2); 132 int timeHeight = fm.height();
131 int borderWidth = 0; 133 //timeHeight -= (timeHeight/4-2);
132 QFont nFont = p->font(); 134 int borderWidth = 0;
135 QFont nFont = p->font();
133 136
134 if (!KGlobal::locale()->use12Clock()) 137 if (!KGlobal::locale()->use12Clock())
135 suffix = "00"; 138 suffix = "00";
136 else 139 else
137 borderWidth = 0; 140 borderWidth = 0;
138 if ( timeHeight > mCellHeight ) { 141 if ( timeHeight > mCellHeight ) {
139 timeHeight = mCellHeight-1; 142 timeHeight = mCellHeight-1;
140 int pointS = nFont.pointSize(); 143 int pointS = nFont.pointSize();
141 while ( pointS > 4 ) { 144 while ( pointS > 4 ) {
142 nFont.setPointSize( pointS ); 145 nFont.setPointSize( pointS );
146 fm = QFontMetrics( nFont );
147 if ( fm.height() < mCellHeight )
148 break;
149 -- pointS;
150 }
143 fm = QFontMetrics( nFont ); 151 fm = QFontMetrics( nFont );
144 if ( fm.height() < mCellHeight ) 152 borderWidth = 4;
145 break; 153 timeHeight = fm.height();
146 -- pointS;
147 }
148 fm = QFontMetrics( nFont );
149 borderWidth = 4;
150 timeHeight = fm.height();
151 }
152 timeHeight -= (timeHeight/4-2);
153 QFont sFont = nFont;
154 sFont.setPointSize( sFont.pointSize()/2+2 );
155 QFontMetrics fmS( sFont );
156 int sHei = fmS.height();
157 sHei -= (sHei/4-2);
158 int startW = this->width() - frameWidth();
159 while (y < cy + ch) {
160 p->drawLine(cx,y,cx+tW,y);
161 hour.setNum(cell);
162
163 // handle 24h and am/pm time formats
164 if (KGlobal::locale()->use12Clock()) {
165 if (cell > 11) suffix = "pm";
166 else
167 suffix = "am";
168 if (cell == 0) hour.setNum(12);
169 if (cell > 12) hour.setNum(cell - 12);
170 } 154 }
155 timeHeight -= (timeHeight/4-2);
156 QFont sFont = nFont;
157 sFont.setPointSize( sFont.pointSize()/2+2 );
158 QFontMetrics fmS( sFont );
159 int sHei = fmS.height();
160 sHei -= (sHei/4-2);
161 int startW = this->width() - frameWidth();
162 while (y < cy + ch) {
163 p->drawLine(cx,y,cx+tW,y);
164 hour.setNum(cell);
165
166 // handle 24h and am/pm time formats
167 if (KGlobal::locale()->use12Clock()) {
168 if (cell > 11) suffix = "pm";
169 else
170 suffix = "am";
171 if (cell == 0) hour.setNum(12);
172 if (cell > 12) hour.setNum(cell - 12);
173 }
171 174
172 // center and draw the time label 175 // center and draw the time label
173 int timeWidth = fm.width(hour+"i"); 176 int timeWidth = fm.width(hour+"i");
174 int tw2 = fm.width(suffix); 177 int tw2 = fm.width(suffix);
175 int offset = startW - timeWidth - tw2 ; 178 int offset = startW - timeWidth - tw2 ;
176 p->setFont( nFont ); 179 p->setFont( nFont );
177 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour); 180 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour);
178 p->setFont( sFont ); 181 p->setFont( sFont );
179 offset = startW - tw2-1; 182 offset = startW - tw2-1;
180 p->drawText(cx - borderWidth + offset, y+ sHei, suffix); 183 p->drawText(cx - borderWidth + offset, y+ sHei, suffix);
181 184
182 // increment indices 185 // increment indices
183 y += mCellHeight; 186 y += mCellHeight;
184 cell++; 187 cell++;
188 }
189 } else {
190 //qDebug("NO redraw ");
185 } 191 }
192 // double buffer not yet implemented
193 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
194 //mRedrawNeeded = false;
186} 195}
187 196
188/** 197/**
189 Calculates the minimum width. 198 Calculates the minimum width.
190*/ 199*/
191int TimeLabels::minimumWidth() const 200int TimeLabels::minimumWidth() const
192{ 201{
193 return mMiniWidth; 202 return mMiniWidth;
194} 203}
195 204
196/** updates widget's internal state */ 205/** updates widget's internal state */
197void TimeLabels::updateConfig() 206void TimeLabels::updateConfig()
198{ 207{
208 mRedrawNeeded = true;
199 // set the font 209 // set the font
200 // config->setGroup("Fonts"); 210 // config->setGroup("Fonts");
201 // QFont font = config->readFontEntry("TimeBar Font"); 211 // QFont font = config->readFontEntry("TimeBar Font");
202 setFont(KOPrefs::instance()->mTimeBarFont); 212 setFont(KOPrefs::instance()->mTimeBarFont);
203 QString test = "88:88"; 213 QString test = "88:88";
204 if (KGlobal::locale()->use12Clock()) 214 if (KGlobal::locale()->use12Clock())
205 test += "i"; 215 test += "i";
206 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; 216 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ;
207 // update geometry restrictions based on new settings 217 // update geometry restrictions based on new settings
208 setFixedWidth(minimumWidth()); 218 setFixedWidth(minimumWidth());
209 219
210 // update HourSize 220 // update HourSize
211 mCellHeight = KOPrefs::instance()->mHourSize*4; 221 mCellHeight = KOPrefs::instance()->mHourSize*4;
212 resizeContents(50,mRows * mCellHeight); 222 resizeContents(50,mRows * mCellHeight);
213} 223}
214 224
215/** update time label positions */ 225/** update time label positions */
216void TimeLabels::positionChanged() 226void TimeLabels::positionChanged()
217{ 227{
218 int adjustment = mAgenda->contentsY(); 228 int adjustment = mAgenda->contentsY();
219 setContentsPos(0, adjustment); 229 setContentsPos(0, adjustment);
220} 230}
221 231
222/** */ 232/** */