-rw-r--r-- | korganizer/koagendaview.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 2996acb..218396d 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp | |||
@@ -36,211 +36,221 @@ | |||
36 | #include <qpainter.h> | 36 | #include <qpainter.h> |
37 | #include <qpushbutton.h> | 37 | #include <qpushbutton.h> |
38 | #include <qapplication.h> | 38 | #include <qapplication.h> |
39 | 39 | ||
40 | #include <kapplication.h> | 40 | #include <kapplication.h> |
41 | #include <KDGanttMinimizeSplitter.h> | 41 | #include <KDGanttMinimizeSplitter.h> |
42 | #include <kdebug.h> | 42 | #include <kdebug.h> |
43 | #include <kstandarddirs.h> | 43 | #include <kstandarddirs.h> |
44 | #include <kiconloader.h> | 44 | #include <kiconloader.h> |
45 | #include <klocale.h> | 45 | #include <klocale.h> |
46 | #include <kconfig.h> | 46 | #include <kconfig.h> |
47 | #include <kglobal.h> | 47 | #include <kglobal.h> |
48 | #include "calendarview.h" | 48 | #include "calendarview.h" |
49 | #include "koviewmanager.h" | 49 | #include "koviewmanager.h" |
50 | 50 | ||
51 | #include <libkcal/calendar.h> | 51 | #include <libkcal/calendar.h> |
52 | #include <libkcal/icaldrag.h> | 52 | #include <libkcal/icaldrag.h> |
53 | #include <libkcal/dndfactory.h> | 53 | #include <libkcal/dndfactory.h> |
54 | 54 | ||
55 | #include <kcalendarsystem.h> | 55 | #include <kcalendarsystem.h> |
56 | 56 | ||
57 | #include "koglobals.h" | 57 | #include "koglobals.h" |
58 | #ifndef KORG_NOPLUGINS | 58 | #ifndef KORG_NOPLUGINS |
59 | #include "kocore.h" | 59 | #include "kocore.h" |
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; |
72 | extern int globalFlagBlockAgenda; | 72 | extern int globalFlagBlockAgenda; |
73 | extern int globalFlagBlockStartup; | 73 | extern int globalFlagBlockStartup; |
74 | extern int globalFlagBlockAgendaItemPaint; | 74 | extern int globalFlagBlockAgendaItemPaint; |
75 | extern int globalFlagBlockAgendaItemUpdate; | 75 | extern int globalFlagBlockAgendaItemUpdate; |
76 | extern int globalFlagBlockLabel; | 76 | extern int globalFlagBlockLabel; |
77 | using namespace KOrg; | 77 | using namespace KOrg; |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : | 81 | TimeLabels::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 | ||
99 | void TimeLabels::setCellHeight(int height) | 101 | void 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 | */ |
108 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) | 110 | void 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 |
121 | if ( mRedrawNeeded ) { | ||
119 | cx = contentsX() + 2; | 122 | cx = contentsX() + 2; |
120 | cw = contentsWidth() - 2; | 123 | cw = contentsWidth() - 2; |
121 | // end of workaround | 124 | // end of workaround |
122 | 125 | ||
123 | int cell = ((int)(cy/mCellHeight)); | 126 | int cell = ((int)(cy/mCellHeight)); |
124 | int y = cell * mCellHeight; | 127 | int y = cell * mCellHeight; |
125 | QFontMetrics fm = fontMetrics(); | 128 | QFontMetrics fm = fontMetrics(); |
126 | QString hour; | 129 | QString hour; |
127 | QString suffix; | 130 | QString suffix; |
128 | int tW = fm.width("24:00i"); | 131 | int tW = fm.width("24:00i"); |
129 | int timeHeight = fm.height(); | 132 | int timeHeight = fm.height(); |
130 | //timeHeight -= (timeHeight/4-2); | 133 | //timeHeight -= (timeHeight/4-2); |
131 | int borderWidth = 0; | 134 | int borderWidth = 0; |
132 | QFont nFont = p->font(); | 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 ); |
143 | fm = QFontMetrics( nFont ); | 146 | fm = QFontMetrics( nFont ); |
144 | if ( fm.height() < mCellHeight ) | 147 | if ( fm.height() < mCellHeight ) |
145 | break; | 148 | break; |
146 | -- pointS; | 149 | -- pointS; |
147 | } | 150 | } |
148 | fm = QFontMetrics( nFont ); | 151 | fm = QFontMetrics( nFont ); |
149 | borderWidth = 4; | 152 | borderWidth = 4; |
150 | timeHeight = fm.height(); | 153 | timeHeight = fm.height(); |
151 | } | 154 | } |
152 | timeHeight -= (timeHeight/4-2); | 155 | timeHeight -= (timeHeight/4-2); |
153 | QFont sFont = nFont; | 156 | QFont sFont = nFont; |
154 | sFont.setPointSize( sFont.pointSize()/2+2 ); | 157 | sFont.setPointSize( sFont.pointSize()/2+2 ); |
155 | QFontMetrics fmS( sFont ); | 158 | QFontMetrics fmS( sFont ); |
156 | int sHei = fmS.height(); | 159 | int sHei = fmS.height(); |
157 | sHei -= (sHei/4-2); | 160 | sHei -= (sHei/4-2); |
158 | int startW = this->width() - frameWidth(); | 161 | int startW = this->width() - frameWidth(); |
159 | while (y < cy + ch) { | 162 | while (y < cy + ch) { |
160 | p->drawLine(cx,y,cx+tW,y); | 163 | p->drawLine(cx,y,cx+tW,y); |
161 | hour.setNum(cell); | 164 | hour.setNum(cell); |
162 | 165 | ||
163 | // handle 24h and am/pm time formats | 166 | // handle 24h and am/pm time formats |
164 | if (KGlobal::locale()->use12Clock()) { | 167 | if (KGlobal::locale()->use12Clock()) { |
165 | if (cell > 11) suffix = "pm"; | 168 | if (cell > 11) suffix = "pm"; |
166 | else | 169 | else |
167 | suffix = "am"; | 170 | suffix = "am"; |
168 | if (cell == 0) hour.setNum(12); | 171 | if (cell == 0) hour.setNum(12); |
169 | if (cell > 12) hour.setNum(cell - 12); | 172 | if (cell > 12) hour.setNum(cell - 12); |
170 | } | 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++; |
185 | } | 188 | } |
189 | } else { | ||
190 | //qDebug("NO redraw "); | ||
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 | */ |
191 | int TimeLabels::minimumWidth() const | 200 | int 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 */ |
197 | void TimeLabels::updateConfig() | 206 | void 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 */ |
216 | void TimeLabels::positionChanged() | 226 | void 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 | /** */ |
223 | void TimeLabels::setAgenda(KOAgenda* agenda) | 233 | void TimeLabels::setAgenda(KOAgenda* agenda) |
224 | { | 234 | { |
225 | mAgenda = agenda; | 235 | mAgenda = agenda; |
226 | } | 236 | } |
227 | 237 | ||
228 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) | 238 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) |
229 | { | 239 | { |
230 | mMouseDownY = e->pos().y(); | 240 | mMouseDownY = e->pos().y(); |
231 | mOrgCap = topLevelWidget()->caption(); | 241 | mOrgCap = topLevelWidget()->caption(); |
232 | } | 242 | } |
233 | 243 | ||
234 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) | 244 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) |
235 | { | 245 | { |
236 | int diff = mMouseDownY - e->pos().y(); | 246 | int diff = mMouseDownY - e->pos().y(); |
237 | if ( diff < 10 && diff > -10 ) | 247 | if ( diff < 10 && diff > -10 ) |
238 | return; | 248 | return; |
239 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; | 249 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; |
240 | if ( tSize < 4 ) | 250 | if ( tSize < 4 ) |
241 | tSize = 4; | 251 | tSize = 4; |
242 | if ( tSize > 22 ) | 252 | if ( tSize > 22 ) |
243 | tSize = 22; | 253 | tSize = 22; |
244 | tSize = (tSize-2)/2; | 254 | tSize = (tSize-2)/2; |
245 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); | 255 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); |
246 | 256 | ||