summaryrefslogtreecommitdiffabout
path: root/microkde/kdatetbl.cpp
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (side-by-side diff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kdatetbl.cpp
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-p1.zip
kdepimpi-p1.tar.gz
kdepimpi-p1.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'microkde/kdatetbl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp99
1 files changed, 53 insertions, 46 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 353f78d..10dc449 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -35,24 +35,32 @@
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kapplication.h>
#include <klocale.h>
#include <kdebug.h>
#include <knotifyclient.h>
#include "kdatetbl.h"
#include <qdatetime.h>
#include <qstring.h>
#include <qpen.h>
#include <qpainter.h>
#include <qdialog.h>
+#include <QDesktopWidget>
+//Added by qt3to4:
+#include <QResizeEvent>
+#include <QFocusEvent>
+#include <Q3Frame>
+#include <QMouseEvent>
+#include <QKeyEvent>
+#include <QEvent>
#include <assert.h>
#include <qapplication.h>
KDateValidator::KDateValidator(QWidget* parent, const char* name)
: QValidator(parent, name)
{
}
QValidator::State
KDateValidator::validate(QString& text, int&) const
{
QDate temp;
@@ -60,151 +68,150 @@ KDateValidator::validate(QString& text, int&) const
return date(text, temp);
}
QValidator::State
KDateValidator::date(const QString& text, QDate& d) const
{
QDate tmp = KGlobal::locale()->readDate(text);
if (!tmp.isNull())
{
d = tmp;
return Acceptable;
} else
- return Valid;
+ return QValidator::Intermediate;
}
void
KDateValidator::fixup( QString& ) const
{
}
-KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
- : QGridView(parent, name, f)
+KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, Qt::WFlags f)
+ : Q3GridView(parent, name, f)
{
setFont( KGlobalSettings::generalFont() );
if(!date_.isValid())
{
date_=QDate::currentDate();
}
- setFocusPolicy( QWidget::StrongFocus );
+ setFocusPolicy( Qt::StrongFocus );
setNumRows(7); // 6 weeks max + headline
setNumCols(7); // 7 days a week
setHScrollBarMode(AlwaysOff);
setVScrollBarMode(AlwaysOff);
viewport()->setBackgroundColor(QColor(220,245,255));
#if 0
- viewport()->setEraseColor(lightGray);
+ viewport()->setEraseColor(Qt::lightGray);
#endif
mMarkCurrent = false;
setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
}
void
KDateTable::paintCell(QPainter *painter, int row, int col)
{
QRect rect;
QString text;
QPen pen;
int w=cellWidth();
int h=cellHeight();
int pos;
- QBrush brushBlue(blue);
+ QBrush brushBlue(Qt::blue);
QBrush brushLightblue(QColor(220,245,255));
QFont _font=font();
// -----
if(row==0)
{ // we are drawing the headline
_font.setBold(true);
painter->setFont(_font);
bool normalday = true;
QString daystr;
if (KGlobal::locale()->weekStartsMonday())
{
daystr = KGlobal::locale()->weekDayName(col+1, true);
if (col == 5 || col == 6)
normalday = false;
} else {
daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
if (col == 0 || col == 6)
normalday = false;
}
if (!normalday)
{
painter->setPen(QColor(220,245,255));
painter->setBrush(brushLightblue);
painter->drawRect(0, 0, w, h);
- painter->setPen(blue);
+ painter->setPen(Qt::blue);
} else {
- painter->setPen(blue);
+ painter->setPen(Qt::blue);
painter->setBrush(brushBlue);
painter->drawRect(0, 0, w, h);
- painter->setPen(white);
+ painter->setPen(Qt::white);
}
- painter->drawText(0, 0, w, h-1, AlignCenter,
+ painter->drawText(0, 0, w, h-1, Qt::AlignCenter,
daystr, -1, &rect);
- painter->setPen(black);
- painter->moveTo(0, h-1);
- painter->lineTo(w-1, h-1);
+ painter->setPen(Qt::black);
+ painter->drawLine(0, h-1, w-1, h-1);
// ----- draw the weekday:
} else {
painter->setFont(_font);
pos=7*(row-1)+col;
if (KGlobal::locale()->weekStartsMonday())
pos++;
if(pos<firstday || (firstday+numdays<=pos))
{ // we are either
// ° painting a day of the previous month or
// ° painting a day of the following month
if(pos<firstday)
{ // previous month
text.setNum(numDaysPrevMonth+pos-firstday+1);
} else { // following month
text.setNum(pos-firstday-numdays+1);
}
- painter->setPen(gray);
+ painter->setPen(Qt::gray);
} else { // paint a day of the current month
text.setNum(pos-firstday+1);
- painter->setPen(black);
+ painter->setPen(Qt::black);
}
pen=painter->pen();
if(firstday+date.day()-1==pos)
{
if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
- painter->setPen(green);
+ painter->setPen(Qt::green);
else
- painter->setPen(red);
+ painter->setPen(Qt::red);
if(hasFocus())
{
- painter->setBrush(darkRed);
- pen=white;
+ painter->setBrush(Qt::darkRed);
+ pen=QColor(Qt::white);
} else {
- painter->setBrush(darkGray);
- pen=white;
+ painter->setBrush(Qt::darkGray);
+ pen=QColor(Qt::white);
}
} else {
if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
{
- painter->setPen(green);
- painter->setBrush(darkGreen);
- pen=white;
+ painter->setPen(Qt::green);
+ painter->setBrush(Qt::darkGreen);
+ pen=QColor(Qt::white);
} else {
painter->setBrush(QColor(220,245,255));
painter->setPen(QColor(220,245,255));
}
}
painter->drawRect(0, 0, w, h);
painter->setPen(pen);
- painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
+ painter->drawText(0, 0, w, h, Qt::AlignCenter, text, -1, &rect);
}
/*
if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
if(rect.height()>maxCell.height()) {
maxCell.setHeight(rect.height());
}
*/
}
void
KDateTable::keyPressEvent( QKeyEvent *e )
{
@@ -265,25 +272,25 @@ KDateTable::keyPressEvent( QKeyEvent *e )
}
pos += add;
setDate(date.addDays( add ));
updateCell(temp/7+1, temp%7); // Update the previously selected cell
updateCell(pos/7+1, pos%7); // Update the selected cell
}
void
KDateTable::viewportResizeEvent(QResizeEvent * e)
{
- QGridView::viewportResizeEvent(e);
+ Q3GridView::viewportResizeEvent(e);
setCellWidth(viewport()->width()/7);
setCellHeight(viewport()->height()/7);
}
void
KDateTable::setFontSize(int size)
{
int count;
QRect rect;
// ----- store rectangles:
fontsize=size;
@@ -400,73 +407,73 @@ KDateTable::setDate(const QDate& date_)
return true;
}
const QDate&
KDateTable::getDate() const
{
return date;
}
void KDateTable::focusInEvent( QFocusEvent *e )
{
repaintContents(false);
- QGridView::focusInEvent( e );
+ Q3GridView::focusInEvent( e );
}
void KDateTable::focusOutEvent( QFocusEvent *e )
{
repaintContents(false);
- QGridView::focusOutEvent( e );
+ Q3GridView::focusOutEvent( e );
}
QSize
KDateTable::sizeHint() const
{
if(maxCell.height()>0 && maxCell.width()>0)
{
return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
(maxCell.height()+4)*numRows()+2*frameWidth());
} else {
return QSize(-1, -1);
}
}
KDateInternalMonthPicker::KDateInternalMonthPicker
(QWidget* parent, const char* name)
- : QGridView(parent, name),
+ : Q3GridView(parent, name),
result(0) // invalid
{
QRect rect;
QFont font;
// -----
activeCol = -1;
activeRow = -1;
font=KGlobalSettings::generalFont();
int fontsize = 10;
int add = 2;
if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
add += 8;
if ( QApplication::desktop()->width() > 640 )
add += 6;
font.setPointSize(fontsize+add);
setFont(font);
setHScrollBarMode(AlwaysOff);
setVScrollBarMode(AlwaysOff);
- setFrameStyle(QFrame::NoFrame);
+ setFrameStyle(Q3Frame::NoFrame);
setNumRows(4);
setNumCols(3);
// enable to find drawing failures:
// setTableFlags(Tbl_clipCellPainting);
#if 0
- viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+ viewport()->setEraseColor(Qt::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 <= 12; ++i)
{
rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
if(max.width()<rect.width()) max.setWidth(rect.width());
if(max.height()<rect.height()) max.setHeight(rect.height());
}
}
@@ -478,51 +485,51 @@ KDateInternalMonthPicker::sizeHint() const
(max.height()+6)*numRows()+2*frameWidth());
}
int
KDateInternalMonthPicker::getResult() const
{
return result;
}
void
KDateInternalMonthPicker::setupPainter(QPainter *p)
{
- p->setPen(black);
+ p->setPen(Qt::black);
}
void
KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
{
setCellWidth(width()/3);
setCellHeight(height()/4);
}
void
KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
{
int index;
QString text;
// ----- find the number of the cell:
index=3*row+col+1;
text=KGlobal::locale()->monthName(index, false);
- painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
+ painter->drawText(0, 0, cellWidth(), cellHeight(), Qt::AlignCenter, text);
if ( activeCol == col && activeRow == row )
painter->drawRect( 0, 0, cellWidth(), cellHeight() );
}
void
KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
{
- if(!isEnabled() || e->button() != LeftButton)
+ if(!isEnabled() || e->button() != Qt::LeftButton)
{
KNotifyClient::beep();
return;
}
// -----
int row, col;
QPoint mouseCoord;
// -----
mouseCoord = e->pos();
row=rowAt(mouseCoord.y());
col=columnAt(mouseCoord.x());
@@ -531,25 +538,25 @@ KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
activeCol = -1;
activeRow = -1;
} else {
activeCol = col;
activeRow = row;
updateCell( row, col /*, false */ );
}
}
void
KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
{
- if (e->state() & LeftButton)
+ if (e->state() & Qt::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 )
{
@@ -605,25 +612,25 @@ KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
KDateInternalYearSelector::KDateInternalYearSelector
(int fontsize, QWidget* parent, const char* name)
: QLineEdit(parent, name),
val(new QIntValidator(this)),
result(0)
{
QFont font;
// -----
font=KGlobalSettings::generalFont();
font.setPointSize(fontsize);
setFont(font);
#if 0
- setFrameStyle(QFrame::NoFrame);
+ setFrameStyle(Q3Frame::NoFrame);
#endif
// we have to respect the limits of QDate here, I fear:
val->setRange(0, 8000);
setValidator(val);
connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
}
void
KDateInternalYearSelector::yearEnteredSlot()
{
bool ok;
int year;
@@ -652,36 +659,36 @@ KDateInternalYearSelector::getYear()
}
void
KDateInternalYearSelector::setYear(int year)
{
QString temp;
// -----
temp.setNum(year);
setText(temp);
}
KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
- : QFrame(parent, name, WType_Popup),
+ : Q3Frame(parent, name, Qt::WType_Popup),
result(0), // rejected
main(0)
{
- setFrameStyle(QFrame::Box|QFrame::Raised);
+ setFrameStyle(Q3Frame::Box|Q3Frame::Raised);
setMidLineWidth(2);
}
void
KPopupFrame::keyPressEvent(QKeyEvent* e)
{
- if(e->key()==Key_Escape)
+ if(e->key()==Qt::Key_Escape)
{
result=0; // rejected
qApp->exit_loop();
}
}
void
KPopupFrame::close(int r)
{
result=r;
qApp->exit_loop();
}
@@ -747,53 +754,53 @@ KPopupFrame::exec(int x, int y)
void KPopupFrame::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KDateTable::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
//#include "kdatetbl.moc"
KDateInternalWeekPicker::KDateInternalWeekPicker
(QWidget* parent, const char* name)
- : QGridView(parent, name),
+ : Q3GridView(parent, name),
result(0) // invalid
{
QRect rect;
QFont font;
// -----
activeCol = -1;
activeRow = -1;
font=KGlobalSettings::generalFont();
int fontsize = 10;
int add = 2;
if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
add += 6;
font.setPointSize(fontsize+add);
setFont(font);
setHScrollBarMode(AlwaysOff);
setVScrollBarMode(AlwaysOff);
- setFrameStyle(QFrame::NoFrame);
+ setFrameStyle(Q3Frame::NoFrame);
if ( QApplication::desktop()->height() > 240 ) {
setNumRows(13);
setNumCols(4);
} else {
setNumRows(4);
setNumCols(13);
}
// enable to find drawing failures:
// setTableFlags(Tbl_clipCellPainting);
#if 0
- viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+ viewport()->setEraseColor(Qt::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());
}
if ( QApplication::desktop()->width() > 640 ) {
@@ -809,51 +816,51 @@ KDateInternalWeekPicker::sizeHint() const
(max.height()+6)*numRows()+2*frameWidth());
}
int
KDateInternalWeekPicker::getResult() const
{
return result;
}
void
KDateInternalWeekPicker::setupPainter(QPainter *p)
{
- p->setPen(black);
+ p->setPen(Qt::black);
}
void
KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
{
setCellWidth(width()/ numCols());
setCellHeight(height()/ numRows());
}
void
KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
{
int index;
QString text;
// ----- find the number of the cell:
index=numCols()*row+col+1;
text=QString::number( index );
- painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
+ painter->drawText(0, 0, cellWidth(), cellHeight(), Qt::AlignCenter, text);
if ( activeCol == col && activeRow == row )
painter->drawRect( 0, 0, cellWidth(), cellHeight() );
}
void
KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
{
- if(!isEnabled() || e->button() != LeftButton)
+ if(!isEnabled() || e->button() != Qt::LeftButton)
{
KNotifyClient::beep();
return;
}
// -----
int row, col;
QPoint mouseCoord;
// -----
mouseCoord = e->pos();
row=rowAt(mouseCoord.y());
col=columnAt(mouseCoord.x());
@@ -862,25 +869,25 @@ KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
activeCol = -1;
activeRow = -1;
} else {
activeCol = col;
activeRow = row;
updateCell( row, col /*, false */ );
}
}
void
KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
{
- if (e->state() & LeftButton)
+ if (e->state() & Qt::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 )
{