25 #include "timelabels.h"
33 #include <tqfontmetrics.h>
34 #include <tqpainter.h>
35 #include <tqstringlist.h>
36 #include <tqdatetime.h>
38 #include <tdeglobal.h>
40 #include "koglobals.h"
45 TimeLabels::TimeLabels(
int rows,TQWidget *parent,
const char *name,WFlags f) :
46 TQScrollView(parent,name,f)
52 mCellHeight = KOPrefs::instance()->mHourSize*4;
56 setHScrollBarMode(AlwaysOff);
57 setVScrollBarMode(AlwaysOff);
59 resizeContents(50,
int(mRows * mCellHeight) );
61 viewport()->setBackgroundMode( PaletteBackground );
63 mMousePos =
new TQFrame(
this);
64 mMousePos->setLineWidth(0);
65 mMousePos->setMargin(0);
66 mMousePos->setBackgroundColor(TQt::red);
67 mMousePos->setFixedSize(width(), 1);
68 addChild(mMousePos, 0, 0);
71 void TimeLabels::mousePosChanged(
const TQPoint &pos)
73 moveChild(mMousePos, 0, pos.y());
76 void TimeLabels::showMousePos()
81 void TimeLabels::hideMousePos()
86 void TimeLabels::setCellHeight(
double height)
95 void TimeLabels::drawContents(TQPainter *p,
int cx,
int cy,
int cw,
int ch)
102 cx = contentsX() + frameWidth()*2;
103 cw = contentsWidth() ;
106 int cell = ((int)(cy/mCellHeight));
107 double y = cell * mCellHeight;
108 TQFontMetrics fm = fontMetrics();
110 TQString suffix =
"am";
111 int timeHeight = fm.ascent();
112 TQFont nFont = font();
113 p->setFont( font() );
115 if (!TDEGlobal::locale()->use12Clock()) {
118 if (cell > 11) suffix =
"pm";
120 if ( timeHeight > mCellHeight ) {
121 timeHeight = int(mCellHeight-1);
122 int pointS = nFont.pointSize();
123 while ( pointS > 4 ) {
124 nFont.setPointSize( pointS );
125 fm = TQFontMetrics( nFont );
126 if ( fm.ascent() < mCellHeight )
130 fm = TQFontMetrics( nFont );
131 timeHeight = fm.ascent();
134 TQFont sFont = nFont;
135 sFont.setPointSize( sFont.pointSize()/2 );
136 TQFontMetrics fmS( sFont );
137 int startW = mMiniWidth - frameWidth()-2 ;
138 int tw2 = fmS.width(suffix);
139 int divTimeHeight = (timeHeight-1) /2 - 1;
142 while (y < cy + ch+mCellHeight) {
144 p->drawLine( cx,
int(y), cw+2, int(y) );
147 if (TDEGlobal::locale()->use12Clock()) {
148 if (cell == 12) suffix =
"pm";
149 if (cell == 0) hour.setNum(12);
150 if (cell > 12) hour.setNum(cell - 12);
154 int timeWidth = fm.width(hour);
155 int offset = startW - timeWidth - tw2 -1 ;
157 p->drawText( offset,
int(y+timeHeight), hour);
159 offset = startW - tw2;
160 p->drawText( offset,
int(y+timeHeight-divTimeHeight), suffix);
172 int TimeLabels::minimumWidth()
const
178 void TimeLabels::updateConfig()
185 setFont(KOPrefs::instance()->mTimeBarFont);
187 TQString test =
"20";
188 if ( TDEGlobal::locale()->use12Clock() )
190 mMiniWidth = fontMetrics().width( test );
191 if ( TDEGlobal::locale()->use12Clock() )
196 TQFont sFont = font();
197 sFont.setPointSize( sFont.pointSize()/2 );
198 TQFontMetrics fmS( sFont );
199 mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ;
201 setFixedWidth( mMiniWidth );
204 mCellHeight = KOPrefs::instance()->mHourSize*4;
208 if ( mAgenda && mCellHeight < 4*mAgenda->gridSpacingY() ) {
209 mCellHeight = 4*mAgenda->gridSpacingY();
211 resizeContents( mMiniWidth,
int(mRows * mCellHeight+1) );
215 void TimeLabels::positionChanged()
218 int adjustment = mAgenda->contentsY();
219 setContentsPos( 0, adjustment );
223 void TimeLabels::positionChanged(
int pos )
225 setContentsPos( 0, pos );
229 void TimeLabels::setAgenda( KOAgenda* agenda )
233 connect(mAgenda, TQ_SIGNAL(mousePosSignal(
const TQPoint &)),
this, TQ_SLOT(mousePosChanged(
const TQPoint &)));
234 connect(mAgenda, TQ_SIGNAL(enterAgenda()),
this, TQ_SLOT(showMousePos()));
235 connect(mAgenda, TQ_SIGNAL(leaveAgenda()),
this, TQ_SLOT(hideMousePos()));
236 connect(mAgenda, TQ_SIGNAL(gridSpacingYChanged(
double ) ),
this, TQ_SLOT( setCellHeight(
double ) ) );
241 void TimeLabels::paintEvent(TQPaintEvent*)
247 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
250 #include "timelabels.moc"