00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "timelabels.h"
00026
00027 #include <tqhbox.h>
00028 #include <tqvbox.h>
00029 #include <tqlabel.h>
00030 #include <tqframe.h>
00031 #include <tqlayout.h>
00032 #include <tqfont.h>
00033 #include <tqfontmetrics.h>
00034 #include <tqpainter.h>
00035 #include <tqstringlist.h>
00036 #include <tqdatetime.h>
00037
00038 #include <kglobal.h>
00039
00040 #include "koglobals.h"
00041 #include "kocore.h"
00042 #include "koprefs.h"
00043 #include "koagenda.h"
00044
00045 TimeLabels::TimeLabels(int rows,TQWidget *parent,const char *name,WFlags f) :
00046 TQScrollView(parent,name,f)
00047 {
00048 mRows = rows;
00049 mMiniWidth = 0;
00050 mAgenda = 0;
00051
00052 mCellHeight = KOPrefs::instance()->mHourSize*4;
00053
00054 enableClipper(true);
00055
00056 setHScrollBarMode(AlwaysOff);
00057 setVScrollBarMode(AlwaysOff);
00058
00059 resizeContents(50, int(mRows * mCellHeight) );
00060
00061 viewport()->setBackgroundMode( PaletteBackground );
00062
00063 mMousePos = new TQFrame(this);
00064 mMousePos->setLineWidth(0);
00065 mMousePos->setMargin(0);
00066 mMousePos->setBackgroundColor(TQt::red);
00067 mMousePos->setFixedSize(width(), 1);
00068 addChild(mMousePos, 0, 0);
00069 }
00070
00071 void TimeLabels::mousePosChanged(const TQPoint &pos)
00072 {
00073 moveChild(mMousePos, 0, pos.y());
00074 }
00075
00076 void TimeLabels::showMousePos()
00077 {
00078 mMousePos->show();
00079 }
00080
00081 void TimeLabels::hideMousePos()
00082 {
00083 mMousePos->hide();
00084 }
00085
00086 void TimeLabels::setCellHeight(double height)
00087 {
00088 mCellHeight = height;
00089 }
00090
00091
00092
00093
00094
00095 void TimeLabels::drawContents(TQPainter *p,int cx, int cy, int cw, int ch)
00096 {
00097
00098
00099
00100
00101
00102 cx = contentsX() + frameWidth()*2;
00103 cw = contentsWidth() ;
00104
00105
00106 int cell = ((int)(cy/mCellHeight));
00107 double y = cell * mCellHeight;
00108 TQFontMetrics fm = fontMetrics();
00109 TQString hour;
00110 TQString suffix = "am";
00111 int timeHeight = fm.ascent();
00112 TQFont nFont = font();
00113 p->setFont( font() );
00114
00115 if (!KGlobal::locale()->use12Clock()) {
00116 suffix = "00";
00117 } else
00118 if (cell > 11) suffix = "pm";
00119
00120 if ( timeHeight > mCellHeight ) {
00121 timeHeight = int(mCellHeight-1);
00122 int pointS = nFont.pointSize();
00123 while ( pointS > 4 ) {
00124 nFont.setPointSize( pointS );
00125 fm = TQFontMetrics( nFont );
00126 if ( fm.ascent() < mCellHeight )
00127 break;
00128 -- pointS;
00129 }
00130 fm = TQFontMetrics( nFont );
00131 timeHeight = fm.ascent();
00132 }
00133
00134 TQFont sFont = nFont;
00135 sFont.setPointSize( sFont.pointSize()/2 );
00136 TQFontMetrics fmS( sFont );
00137 int startW = mMiniWidth - frameWidth()-2 ;
00138 int tw2 = fmS.width(suffix);
00139 int divTimeHeight = (timeHeight-1) /2 - 1;
00140
00141
00142 while (y < cy + ch+mCellHeight) {
00143
00144 p->drawLine( cx, int(y), cw+2, int(y) );
00145 hour.setNum(cell);
00146
00147 if (KGlobal::locale()->use12Clock()) {
00148 if (cell == 12) suffix = "pm";
00149 if (cell == 0) hour.setNum(12);
00150 if (cell > 12) hour.setNum(cell - 12);
00151 }
00152
00153
00154 int timeWidth = fm.width(hour);
00155 int offset = startW - timeWidth - tw2 -1 ;
00156 p->setFont( nFont );
00157 p->drawText( offset, int(y+timeHeight), hour);
00158 p->setFont( sFont );
00159 offset = startW - tw2;
00160 p->drawText( offset, int(y+timeHeight-divTimeHeight), suffix);
00161
00162
00163 y += mCellHeight;
00164 cell++;
00165 }
00166
00167 }
00168
00172 int TimeLabels::minimumWidth() const
00173 {
00174 return mMiniWidth;
00175 }
00176
00178 void TimeLabels::updateConfig()
00179 {
00180
00181 if ( !mAgenda ) {
00182 return;
00183 }
00184
00185 setFont(KOPrefs::instance()->mTimeBarFont);
00186
00187 TQString test = "20";
00188 if ( KGlobal::locale()->use12Clock() )
00189 test = "12";
00190 mMiniWidth = fontMetrics().width( test );
00191 if ( KGlobal::locale()->use12Clock() )
00192 test = "pm";
00193 else {
00194 test = "00";
00195 }
00196 TQFont sFont = font();
00197 sFont.setPointSize( sFont.pointSize()/2 );
00198 TQFontMetrics fmS( sFont );
00199 mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ;
00200
00201 setFixedWidth( mMiniWidth );
00202
00203
00204 mCellHeight = KOPrefs::instance()->mHourSize*4;
00205
00206
00207
00208 if ( mAgenda && mCellHeight < 4*mAgenda->gridSpacingY() ) {
00209 mCellHeight = 4*mAgenda->gridSpacingY();
00210 }
00211 resizeContents( mMiniWidth, int(mRows * mCellHeight+1) );
00212 }
00213
00215 void TimeLabels::positionChanged()
00216 {
00217 if ( mAgenda ) {
00218 int adjustment = mAgenda->contentsY();
00219 setContentsPos( 0, adjustment );
00220 }
00221 }
00222
00223 void TimeLabels::positionChanged( int pos )
00224 {
00225 setContentsPos( 0, pos );
00226 }
00227
00229 void TimeLabels::setAgenda( KOAgenda* agenda )
00230 {
00231 mAgenda = agenda;
00232
00233 connect(mAgenda, TQT_SIGNAL(mousePosSignal(const TQPoint &)), this, TQT_SLOT(mousePosChanged(const TQPoint &)));
00234 connect(mAgenda, TQT_SIGNAL(enterAgenda()), this, TQT_SLOT(showMousePos()));
00235 connect(mAgenda, TQT_SIGNAL(leaveAgenda()), this, TQT_SLOT(hideMousePos()));
00236 connect(mAgenda, TQT_SIGNAL(gridSpacingYChanged( double ) ), this, TQT_SLOT( setCellHeight( double ) ) );
00237 }
00238
00239
00241 void TimeLabels::paintEvent(TQPaintEvent*)
00242 {
00243
00244
00245
00246
00247 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
00248 }
00249
00250 #include "timelabels.moc"