author | zautrix <zautrix> | 2005-02-07 06:10:09 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-07 06:10:09 (UTC) |
commit | 301a4a207171549bd87815705d8dcf32ad15559d (patch) (side-by-side diff) | |
tree | 715fde2cd0af0c057f767c25d8e67298425b2c82 /microkde/kdatetbl.cpp | |
parent | 961fc44f4092c1f981eb3be4284715e6829f885c (diff) | |
download | kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.zip kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.gz kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.bz2 |
new cool feature
-rw-r--r-- | microkde/kdatetbl.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp index 508ce31..fce0e5a 100644 --- a/microkde/kdatetbl.cpp +++ b/microkde/kdatetbl.cpp @@ -748,3 +748,168 @@ void KDateTable::virtual_hook( int, void* ) { /*BASE::virtual_hook( id, data );*/ } //#include "kdatetbl.moc" + + +KDateInternalWeekPicker::KDateInternalWeekPicker +(int fontsize, QWidget* parent, const char* name) + : QGridView(parent, name), + result(0) // invalid +{ + QRect rect; + QFont font; + // ----- + activeCol = -1; + activeRow = -1; + font=KGlobalSettings::generalFont(); + font.setPointSize(fontsize); + setFont(font); + setHScrollBarMode(AlwaysOff); + setVScrollBarMode(AlwaysOff); + setFrameStyle(QFrame::NoFrame); + setNumRows(13); + setNumCols(4); + // enable to find drawing failures: + // setTableFlags(Tbl_clipCellPainting); +#if 0 + viewport()->setEraseColor(lightGray); // for consistency with the datepicker +#endif + // ----- find the preferred size + // (this is slow, possibly, but unfortunatly it is needed here): + QFontMetrics metrics(font); + for(int i=1; i <= 52; ++i) + { + rect=metrics.boundingRect(QString::number( i )); + if(max.width()<rect.width()) max.setWidth(rect.width()); + if(max.height()<rect.height()) max.setHeight(rect.height()); + } + +} + +QSize +KDateInternalWeekPicker::sizeHint() const +{ + return QSize((max.width()+6)*numCols()+2*frameWidth(), + (max.height()+6)*numRows()+2*frameWidth()); +} + +int +KDateInternalWeekPicker::getResult() const +{ + return result; +} + +void +KDateInternalWeekPicker::setupPainter(QPainter *p) +{ + p->setPen(black); +} + +void +KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) +{ + setCellWidth(width()/4); + setCellHeight(height()/13); +} + +void +KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) +{ + int index; + QString text; + // ----- find the number of the cell: + index=4*row+col+1; + text=QString::number( index ); + painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); + if ( activeCol == col && activeRow == row ) + painter->drawRect( 0, 0, cellWidth(), cellHeight() ); +} + +void +KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) +{ + if(!isEnabled() || e->button() != LeftButton) + { + KNotifyClient::beep(); + return; + } + // ----- + int row, col; + QPoint mouseCoord; + // ----- + mouseCoord = e->pos(); + row=rowAt(mouseCoord.y()); + col=columnAt(mouseCoord.x()); + + if(row<0 || col<0) + { // the user clicked on the frame of the table + activeCol = -1; + activeRow = -1; + } else { + activeCol = col; + activeRow = row; + updateCell( row, col /*, false */ ); + } +} + +void +KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) +{ + if (e->state() & LeftButton) + { + int row, col; + QPoint mouseCoord; + // ----- + mouseCoord = e->pos(); + row=rowAt(mouseCoord.y()); + col=columnAt(mouseCoord.x()); + int tmpRow = -1, tmpCol = -1; + if(row<0 || col<0) + { // the user clicked on the frame of the table + if ( activeCol > -1 ) + { + tmpRow = activeRow; + tmpCol = activeCol; + } + activeCol = -1; + activeRow = -1; + } else { + bool differentCell = (activeRow != row || activeCol != col); + if ( activeCol > -1 && differentCell) + { + tmpRow = activeRow; + tmpCol = activeCol; + } + if ( differentCell) + { + activeRow = row; + activeCol = col; + updateCell( row, col /*, false */ ); // mark the new active cell + } + } + if ( tmpRow > -1 ) // repaint the former active cell + updateCell( tmpRow, tmpCol /*, true */ ); + } +} + +void +KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) +{ + if(!isEnabled()) + { + return; + } + // ----- + int row, col, pos; + QPoint mouseCoord; + // ----- + mouseCoord = e->pos(); + row=rowAt(mouseCoord.y()); + col=columnAt(mouseCoord.x()); + if(row<0 || col<0) + { // the user clicked on the frame of the table + emit(closeMe(0)); + } + pos=4*row+col+1; + result=pos; + emit(closeMe(1)); +} |