-rw-r--r-- | korganizer/koagendaview.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 18f242c..f6f390b 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp | |||
@@ -80,175 +80,175 @@ using namespace KOrg; | |||
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 | 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 | ||
99 | void TimeLabels::setCellHeight(int height) | 99 | void 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 | */ |
108 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) | 108 | void 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; | ||
129 | int tW = fm.width("24:00i"); | 128 | int tW = fm.width("24:00i"); |
130 | int timeHeight = fm.height(); | 129 | int timeHeight = fm.height(); |
131 | //timeHeight -= (timeHeight/4-2); | 130 | //timeHeight -= (timeHeight/4-2); |
132 | int borderWidth = 0; | 131 | int borderWidth = 0; |
133 | QFont nFont = p->font(); | 132 | QFont nFont = p->font(); |
134 | 133 | ||
135 | if (!KGlobal::locale()->use12Clock()) | 134 | if (!KGlobal::locale()->use12Clock()) |
136 | suffix = "00"; | 135 | suffix = "00"; |
137 | else | 136 | else |
138 | borderWidth = 0; | 137 | borderWidth = 0; |
139 | if ( timeHeight > mCellHeight ) { | 138 | if ( timeHeight > mCellHeight ) { |
140 | timeHeight = mCellHeight-1; | 139 | timeHeight = mCellHeight-1; |
141 | int pointS = nFont.pointSize(); | 140 | int pointS = nFont.pointSize(); |
142 | while ( pointS > 4 ) { | 141 | while ( pointS > 4 ) { |
143 | nFont.setPointSize( pointS ); | 142 | nFont.setPointSize( pointS ); |
144 | fm = QFontMetrics( nFont ); | 143 | fm = QFontMetrics( nFont ); |
145 | if ( fm.height() < mCellHeight ) | 144 | if ( fm.height() < mCellHeight ) |
146 | break; | 145 | break; |
147 | -- pointS; | 146 | -- pointS; |
148 | } | 147 | } |
149 | fm = QFontMetrics( nFont ); | 148 | fm = QFontMetrics( nFont ); |
150 | borderWidth = 4; | 149 | borderWidth = 4; |
151 | timeHeight = fm.height(); | 150 | timeHeight = fm.height(); |
152 | } | 151 | } |
153 | timeHeight -= (timeHeight/4-2); | 152 | timeHeight -= (timeHeight/4-2); |
154 | QFont sFont = nFont; | 153 | QFont sFont = nFont; |
155 | sFont.setPointSize( sFont.pointSize()/2+2 ); | 154 | sFont.setPointSize( sFont.pointSize()/2+2 ); |
156 | QFontMetrics fmS( sFont ); | 155 | QFontMetrics fmS( sFont ); |
157 | int sHei = fmS.height(); | 156 | int sHei = fmS.height(); |
158 | 157 | sHei -= (sHei/4-2); | |
158 | int startW = this->width() - frameWidth(); | ||
159 | while (y < cy + ch) { | 159 | while (y < cy + ch) { |
160 | p->drawLine(cx,y,cx+tW,y); | 160 | p->drawLine(cx,y,cx+tW,y); |
161 | hour.setNum(cell); | 161 | hour.setNum(cell); |
162 | 162 | ||
163 | // handle 24h and am/pm time formats | 163 | // handle 24h and am/pm time formats |
164 | if (KGlobal::locale()->use12Clock()) { | 164 | if (KGlobal::locale()->use12Clock()) { |
165 | if (cell > 11) suffix = "pm"; | 165 | if (cell > 11) suffix = "pm"; |
166 | else | 166 | else |
167 | suffix = "am"; | 167 | suffix = "am"; |
168 | if (cell == 0) hour.setNum(12); | 168 | if (cell == 0) hour.setNum(12); |
169 | if (cell > 12) hour.setNum(cell - 12); | 169 | if (cell > 12) hour.setNum(cell - 12); |
170 | } | 170 | } |
171 | 171 | ||
172 | // create string in format of "XX:XX" or "XXpm/am" | ||
173 | fullTime = hour;// + suffix; | ||
174 | |||
175 | // center and draw the time label | 172 | // center and draw the time label |
176 | int timeWidth = fm.width(fullTime+"i"); | 173 | int timeWidth = fm.width(hour+"i"); |
177 | int tw2 = fm.width(suffix); | 174 | int tw2 = fm.width(suffix); |
178 | int offset = this->width() - timeWidth - tw2; | 175 | int offset = startW - timeWidth - tw2 ; |
179 | p->setFont( nFont ); | 176 | p->setFont( nFont ); |
180 | p->drawText(cx - borderWidth + offset, y+ timeHeight, fullTime); | 177 | p->drawText(cx - borderWidth + offset, y+ timeHeight, hour); |
181 | p->setFont( sFont ); | 178 | p->setFont( sFont ); |
182 | offset += timeWidth; | 179 | offset = startW - tw2-1; |
183 | p->drawText(cx - borderWidth + offset, y+ sHei, suffix); | 180 | p->drawText(cx - borderWidth + offset, y+ sHei, suffix); |
184 | 181 | ||
185 | // increment indices | 182 | // increment indices |
186 | y += mCellHeight; | 183 | y += mCellHeight; |
187 | cell++; | 184 | cell++; |
188 | } | 185 | } |
189 | } | 186 | } |
190 | 187 | ||
191 | /** | 188 | /** |
192 | Calculates the minimum width. | 189 | Calculates the minimum width. |
193 | */ | 190 | */ |
194 | int TimeLabels::minimumWidth() const | 191 | int TimeLabels::minimumWidth() const |
195 | { | 192 | { |
196 | return mMiniWidth; | 193 | return mMiniWidth; |
197 | } | 194 | } |
198 | 195 | ||
199 | /** updates widget's internal state */ | 196 | /** updates widget's internal state */ |
200 | void TimeLabels::updateConfig() | 197 | void TimeLabels::updateConfig() |
201 | { | 198 | { |
202 | // set the font | 199 | // set the font |
203 | // config->setGroup("Fonts"); | 200 | // config->setGroup("Fonts"); |
204 | // QFont font = config->readFontEntry("TimeBar Font"); | 201 | // QFont font = config->readFontEntry("TimeBar Font"); |
205 | setFont(KOPrefs::instance()->mTimeBarFont); | 202 | setFont(KOPrefs::instance()->mTimeBarFont); |
206 | mMiniWidth = fontMetrics().width("88:88") + 2 ; | 203 | QString test = "88:88"; |
204 | if (KGlobal::locale()->use12Clock()) | ||
205 | test += "i"; | ||
206 | mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; | ||
207 | // update geometry restrictions based on new settings | 207 | // update geometry restrictions based on new settings |
208 | setFixedWidth(minimumWidth()); | 208 | setFixedWidth(minimumWidth()); |
209 | 209 | ||
210 | // update HourSize | 210 | // update HourSize |
211 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 211 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
212 | resizeContents(50,mRows * mCellHeight); | 212 | resizeContents(50,mRows * mCellHeight); |
213 | } | 213 | } |
214 | 214 | ||
215 | /** update time label positions */ | 215 | /** update time label positions */ |
216 | void TimeLabels::positionChanged() | 216 | void TimeLabels::positionChanged() |
217 | { | 217 | { |
218 | int adjustment = mAgenda->contentsY(); | 218 | int adjustment = mAgenda->contentsY(); |
219 | setContentsPos(0, adjustment); | 219 | setContentsPos(0, adjustment); |
220 | } | 220 | } |
221 | 221 | ||
222 | /** */ | 222 | /** */ |
223 | void TimeLabels::setAgenda(KOAgenda* agenda) | 223 | void TimeLabels::setAgenda(KOAgenda* agenda) |
224 | { | 224 | { |
225 | mAgenda = agenda; | 225 | mAgenda = agenda; |
226 | } | 226 | } |
227 | 227 | ||
228 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) | 228 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) |
229 | { | 229 | { |
230 | mMouseDownY = e->pos().y(); | 230 | mMouseDownY = e->pos().y(); |
231 | mOrgCap = topLevelWidget()->caption(); | 231 | mOrgCap = topLevelWidget()->caption(); |
232 | } | 232 | } |
233 | 233 | ||
234 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) | 234 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) |
235 | { | 235 | { |
236 | int diff = mMouseDownY - e->pos().y(); | 236 | int diff = mMouseDownY - e->pos().y(); |
237 | if ( diff < 10 && diff > -10 ) | 237 | if ( diff < 10 && diff > -10 ) |
238 | return; | 238 | return; |
239 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; | 239 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; |
240 | if ( tSize < 4 ) | 240 | if ( tSize < 4 ) |
241 | tSize = 4; | 241 | tSize = 4; |
242 | if ( tSize > 22 ) | 242 | if ( tSize > 22 ) |
243 | tSize = 22; | 243 | tSize = 22; |
244 | tSize = (tSize-2)/2; | 244 | tSize = (tSize-2)/2; |
245 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); | 245 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); |
246 | 246 | ||
247 | } | 247 | } |
248 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) | 248 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) |
249 | { | 249 | { |
250 | topLevelWidget()->setCaption( mOrgCap ); | 250 | topLevelWidget()->setCaption( mOrgCap ); |
251 | int diff = mMouseDownY - e->pos().y(); | 251 | int diff = mMouseDownY - e->pos().y(); |
252 | if ( diff < 10 && diff > -10 ) | 252 | if ( diff < 10 && diff > -10 ) |
253 | return; | 253 | return; |
254 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); | 254 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); |
@@ -791,101 +791,98 @@ void KOAgendaView::createDayLabels() | |||
791 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); | 791 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); |
792 | CalendarDecoration *it; | 792 | CalendarDecoration *it; |
793 | for(it = cds.first(); it; it = cds.next()) { | 793 | for(it = cds.first(); it; it = cds.next()) { |
794 | QString text = it->shortText( date ); | 794 | QString text = it->shortText( date ); |
795 | if ( !text.isEmpty() ) { | 795 | if ( !text.isEmpty() ) { |
796 | QLabel *label = new QLabel(text,mDayLabels); | 796 | QLabel *label = new QLabel(text,mDayLabels); |
797 | label->setAlignment(AlignCenter); | 797 | label->setAlignment(AlignCenter); |
798 | dayLayout->addWidget(label); | 798 | dayLayout->addWidget(label); |
799 | } | 799 | } |
800 | } | 800 | } |
801 | 801 | ||
802 | for(it = cds.first(); it; it = cds.next()) { | 802 | for(it = cds.first(); it; it = cds.next()) { |
803 | QWidget *wid = it->smallWidget(mDayLabels,date); | 803 | QWidget *wid = it->smallWidget(mDayLabels,date); |
804 | if ( wid ) { | 804 | if ( wid ) { |
805 | // wid->setHeight(20); | 805 | // wid->setHeight(20); |
806 | dayLayout->addWidget(wid); | 806 | dayLayout->addWidget(wid); |
807 | } | 807 | } |
808 | } | 808 | } |
809 | #endif | 809 | #endif |
810 | } | 810 | } |
811 | if ( ! appendLabels ) { | 811 | if ( ! appendLabels ) { |
812 | dayLabel = mDayLabelsList.next(); | 812 | dayLabel = mDayLabelsList.next(); |
813 | if ( !dayLabel ) | 813 | if ( !dayLabel ) |
814 | appendLabels = true; | 814 | appendLabels = true; |
815 | } | 815 | } |
816 | if ( appendLabels ) { | 816 | if ( appendLabels ) { |
817 | dayLabel = getNewDaylabel(); | 817 | dayLabel = getNewDaylabel(); |
818 | } | 818 | } |
819 | //dayLabel->hide();//test only | 819 | //dayLabel->hide();//test only |
820 | 820 | ||
821 | int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; | 821 | int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()-3 ) % mSelectedDates.count() ; |
822 | if ( offset < 0 ) offset = 0; | 822 | if ( offset < 0 ) offset = 0; |
823 | //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); | 823 | //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); |
824 | dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); | 824 | dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); |
825 | dayLabel->setFont( dlf ); | 825 | dayLabel->setFont( dlf ); |
826 | dayLabel->show(); | 826 | dayLabel->show(); |
827 | dayLabel->setNum( -2 ); | 827 | dayLabel->setNum( -2 ); |
828 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); | 828 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); |
829 | //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); | 829 | //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); |
830 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); | 830 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); |
831 | if ( !appendLabels ) { | 831 | if ( !appendLabels ) { |
832 | dayLabel = mDayLabelsList.next(); | 832 | dayLabel = mDayLabelsList.next(); |
833 | while ( dayLabel ) { | 833 | while ( dayLabel ) { |
834 | //qDebug("!dayLabel %d",dayLabel ); | 834 | //qDebug("!dayLabel %d",dayLabel ); |
835 | dayLabel->hide(); | 835 | dayLabel->hide(); |
836 | dayLabel = mDayLabelsList.next(); | 836 | dayLabel = mDayLabelsList.next(); |
837 | } | 837 | } |
838 | } | 838 | } |
839 | //mDayLabelsFrame->show(); | 839 | |
840 | //mDayLabels->show(); | 840 | mDayLabelsFrame->setFixedHeight( newHight + 4 ); |
841 | //qDebug("heigt %d %d %d ",mDayLabelsFrame->height(), mDayLabelsFrame->sizeHint().height(), newHight); | ||
842 | //mDayLabelsFrame->resize( mAgenda->visibleWidth(), newHight ); | ||
843 | mDayLabelsFrame->setFixedHeight( newHight ); | ||
844 | } | 841 | } |
845 | 842 | ||
846 | int KOAgendaView::maxDatesHint() | 843 | int KOAgendaView::maxDatesHint() |
847 | { | 844 | { |
848 | // Not sure about the max number of events, so return 0 for now. | 845 | // Not sure about the max number of events, so return 0 for now. |
849 | return 0; | 846 | return 0; |
850 | } | 847 | } |
851 | 848 | ||
852 | int KOAgendaView::currentDateCount() | 849 | int KOAgendaView::currentDateCount() |
853 | { | 850 | { |
854 | return mSelectedDates.count(); | 851 | return mSelectedDates.count(); |
855 | } | 852 | } |
856 | 853 | ||
857 | QPtrList<Incidence> KOAgendaView::selectedIncidences() | 854 | QPtrList<Incidence> KOAgendaView::selectedIncidences() |
858 | { | 855 | { |
859 | QPtrList<Incidence> selected; | 856 | QPtrList<Incidence> selected; |
860 | Incidence *incidence; | 857 | Incidence *incidence; |
861 | 858 | ||
862 | incidence = mAgenda->selectedIncidence(); | 859 | incidence = mAgenda->selectedIncidence(); |
863 | if (incidence) selected.append(incidence); | 860 | if (incidence) selected.append(incidence); |
864 | 861 | ||
865 | incidence = mAllDayAgenda->selectedIncidence(); | 862 | incidence = mAllDayAgenda->selectedIncidence(); |
866 | if (incidence) selected.append(incidence); | 863 | if (incidence) selected.append(incidence); |
867 | 864 | ||
868 | return selected; | 865 | return selected; |
869 | } | 866 | } |
870 | 867 | ||
871 | DateList KOAgendaView::selectedDates() | 868 | DateList KOAgendaView::selectedDates() |
872 | { | 869 | { |
873 | DateList selected; | 870 | DateList selected; |
874 | QDate qd; | 871 | QDate qd; |
875 | 872 | ||
876 | qd = mAgenda->selectedIncidenceDate(); | 873 | qd = mAgenda->selectedIncidenceDate(); |
877 | if (qd.isValid()) selected.append(qd); | 874 | if (qd.isValid()) selected.append(qd); |
878 | 875 | ||
879 | qd = mAllDayAgenda->selectedIncidenceDate(); | 876 | qd = mAllDayAgenda->selectedIncidenceDate(); |
880 | if (qd.isValid()) selected.append(qd); | 877 | if (qd.isValid()) selected.append(qd); |
881 | 878 | ||
882 | return selected; | 879 | return selected; |
883 | } | 880 | } |
884 | 881 | ||
885 | 882 | ||
886 | void KOAgendaView::updateView() | 883 | void KOAgendaView::updateView() |
887 | { | 884 | { |
888 | if ( mBlockUpdating ) | 885 | if ( mBlockUpdating ) |
889 | return; | 886 | return; |
890 | // kdDebug() << "KOAgendaView::updateView()" << endl; | 887 | // kdDebug() << "KOAgendaView::updateView()" << endl; |
891 | fillAgenda(); | 888 | fillAgenda(); |