summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp106
-rw-r--r--korganizer/mainwindow.h15
-rw-r--r--microkde/kdatetbl.cpp1091
-rw-r--r--microkde/kdatetbl.h63
4 files changed, 775 insertions, 500 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 348dd5e..119e28a 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -74,2 +74,3 @@ using namespace KCal;
+
class KOex2phonePrefs : public QDialog
@@ -146,6 +147,7 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
mFlagKeyPressed = false;
+ setCaption("KOrganizer/Pi");
KOPrefs *p = KOPrefs::instance();
KPimGlobalPrefs::instance()->setGlobalConfig();
- if ( p->mHourSize > 18 )
- p->mHourSize = 18;
+ if ( p->mHourSize > 22 )
+ p->mHourSize = 22;
QMainWindow::ToolBarDock tbd;
@@ -169,4 +171,2 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
mCalendarModifiedFlag = false;
-
- setCaption("KOrganizer/Pi");
QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this );
@@ -559,30 +559,41 @@ void MainWindow::initActions()
connect ( selectFilterMenu, SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenu() ) );
-
- menuBarWeek = new QPEMenuBar( iconToolBar );
- QPopupMenu * wpo = new QPopupMenu (this);
- QPopupMenu * all = new QPopupMenu (this);
- //wpo->insertItem( i18n("W#"), 0 );
- int first = 1;
- int i;
- for ( i = 1; i < 50; ++i ) {
- if ( !(i%10) ) {
- all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo );
- connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) );
- first = i;
- wpo = new QPopupMenu (this);
+ QIconSet icon;
+ int pixWid = 22, pixHei = 22;
+ QString pathString = "";
+ if ( !p->mToolBarMiniIcons ) {
+ if ( QApplication::desktop()->width() < 480 ) {
+ pathString += "icons16/";
+ pixWid = 18; pixHei = 16;
}
- wpo->insertItem( QString::number(i), i );
- }
- for ( i = 50; i < 53; ++i ) {
- wpo->insertItem( QString::number(i), i);
+ } else {
+ pathString += "iconsmini/";
+ pixWid = 18; pixHei = 16;
+ }
+ mWeekBgColor = iconToolBar->backgroundColor();
+ mWeekPixmap.resize( pixWid , pixHei );
+ mWeekPixmap.fill( mWeekBgColor );
+ icon = mWeekPixmap;
+ mWeekAction = new QAction( i18n("Select week number"),icon, i18n("Select week number"), 0, this );
+ mWeekAction->addTo( iconToolBar );
+ mWeekFont = font();
+
+ int fontPoint = mWeekFont.pointSize();
+ QFontMetrics f( mWeekFont );
+ int fontWid = f.width( "30" );
+ while ( fontWid > pixWid ) {
+ --fontPoint;
+ mWeekFont.setPointSize( fontPoint );
+ QFontMetrics f( mWeekFont );
+ fontWid = f.width( "30" );
+ qDebug("dec-- ");
}
- all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo );
- connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) );
- menuBarWeek->insertItem( "00",all,1);
- menuBarWeek->setMaximumSize( menuBarWeek->sizeHint( ));
+
+ connect( mWeekAction, SIGNAL( activated() ),
+ this, SLOT( weekAction() ) );
connect( this, SIGNAL( selectWeek ( int ) ), mView->dateNavigator(), SLOT( selectWeek ( int ) ) );
+
+ //#endif
// ******************
QAction *action;
- QIconSet icon;
// QPopupMenu *configureMenu= new QPopupMenu( menuBar );
@@ -590,8 +601,3 @@ void MainWindow::initActions()
- QString pathString = "";
- if ( !p->mToolBarMiniIcons ) {
- if ( QApplication::desktop()->width() < 480 )
- pathString += "icons16/";
- } else
- pathString += "iconsmini/";
+
configureAgendaMenu->setCheckable( true );
@@ -1372,4 +1378,10 @@ void MainWindow::updateWeek(QDate seda)
}
- //qDebug("weeknum %s ", QString::number( weekNum).latin1());
- menuBarWeek-> changeItem(1, QString::number( weekNum) );
+
+ mWeekPixmap.fill( mWeekBgColor );
+ QPainter p ( &mWeekPixmap );
+ p.setFont( mWeekFont );
+ p.drawText( 0,0,mWeekPixmap.width(), mWeekPixmap.height(),AlignCenter, QString::number( weekNum) );
+ p.end();
+ QIconSet icon3 ( mWeekPixmap );
+ mWeekAction->setIconSet ( icon3 );
@@ -1721,3 +1733,3 @@ void MainWindow::keyPressEvent ( QKeyEvent * e )
size = p->mHourSize +2;
- if ( size <= 18 )
+ if ( size <= 22 )
configureAgenda( size );
@@ -2013 +2025,25 @@ void MainWindow::printCal()
+
+#include "libkdepim/kdatepicker.h"
+#include <kdatetbl.h>
+void MainWindow::weekAction()
+{
+ int month;
+ KPopupFrame* popup = new KPopupFrame(this);
+ int size = 12;
+ if ( QApplication::desktop()->width() >= 480 )
+ size = 18;
+ KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(size, popup);
+ // -----
+ picker->resize(picker->sizeHint());
+ popup->setMainWidget(picker);
+ picker->setFocus();
+ connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
+ if(popup->exec(iconToolBar->mapToGlobal(QPoint(0, iconToolBar->height()))))
+ {
+ month = picker->getResult();
+ emit selectWeek ( month );
+ //qDebug("weekSelected %d ", month);
+ }
+ delete popup;
+}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 076ab94..5b9f903 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -7,2 +7,3 @@
#include <qfile.h>
+#include <qmenubar.h>
#include <qtextstream.h>
@@ -25,3 +26,2 @@ class KSyncProfile;
class QPEToolBar;
-class QPEMenuBar;
@@ -32,2 +32,9 @@ class CalendarLocal;
+class KOMenuBar : public QMenuBar
+{
+ public:
+ KOMenuBar( QWidget *parent=0 ): QMenuBar (parent ) {;}
+ QSize sizeHint () const{ qDebug("sizejint ");return QSize ( 40,25 );}
+};
+
using namespace KCal;
@@ -52,2 +59,3 @@ class MainWindow : public QMainWindow
void setCaptionToDates();
+ void weekAction();
void about();
@@ -122,3 +130,6 @@ class MainWindow : public QMainWindow
QAction *mNewSubTodoAction;
- QPEMenuBar *menuBarWeek;
+ QAction *mWeekAction;
+ QFont mWeekFont;
+ QPixmap mWeekPixmap;
+ QColor mWeekBgColor;
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 508ce31..fce0e5a 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -3,3 +3,3 @@
Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
- (C) 1998-2001 Mirko Boehm (mirko@kde.org)
+ (C) 1998-2001 Mirko Boehm (mirko@kde.org)
This library is free software; you can redistribute it and/or
@@ -57,5 +57,5 @@ KDateValidator::validate(QString& text, int&) const
{
- QDate temp;
- // ----- everything is tested in date():
- return date(text, temp);
+ QDate temp;
+ // ----- everything is tested in date():
+ return date(text, temp);
}
@@ -65,9 +65,9 @@ KDateValidator::date(const QString& text, QDate& d) const
{
- QDate tmp = KGlobal::locale()->readDate(text);
- if (!tmp.isNull())
- {
- d = tmp;
- return Acceptable;
- } else
- return Valid;
+ QDate tmp = KGlobal::locale()->readDate(text);
+ if (!tmp.isNull())
+ {
+ d = tmp;
+ return Acceptable;
+ } else
+ return Valid;
}
@@ -81,20 +81,20 @@ KDateValidator::fixup( QString& ) const
KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f)
- : QGridView(parent, name, f)
+ : QGridView(parent, name, f)
{
- setFontSize(10);
- if(!date_.isValid())
- {
- date_=QDate::currentDate();
- }
- setFocusPolicy( QWidget::StrongFocus );
- setNumRows(7); // 6 weeks max + headline
- setNumCols(7); // 7 days a week
- setHScrollBarMode(AlwaysOff);
- setVScrollBarMode(AlwaysOff);
- viewport()->setBackgroundColor(QColor(220,245,255));
+ setFontSize(10);
+ if(!date_.isValid())
+ {
+ date_=QDate::currentDate();
+ }
+ setFocusPolicy( QWidget::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(lightGray);
#endif
- mMarkCurrent = false;
- setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
+ mMarkCurrent = false;
+ setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth
}
@@ -104,100 +104,100 @@ 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 brushLightblue(QColor(220,245,255));
- QFont font=KGlobalSettings::generalFont();
- // -----
- font.setPointSize(fontsize);
- 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);
- } else {
- painter->setPen(blue);
- painter->setBrush(brushBlue);
- painter->drawRect(0, 0, w, h);
- painter->setPen(white);
- }
- painter->drawText(0, 0, w, h-1, AlignCenter,
- daystr, -1, &rect);
- painter->setPen(black);
- painter->moveTo(0, h-1);
- painter->lineTo(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);
+ QRect rect;
+ QString text;
+ QPen pen;
+ int w=cellWidth();
+ int h=cellHeight();
+ int pos;
+ QBrush brushBlue(blue);
+ QBrush brushLightblue(QColor(220,245,255));
+ QFont font=KGlobalSettings::generalFont();
+ // -----
+ font.setPointSize(fontsize);
+ 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;
}
- painter->setPen(gray);
- } else { // paint a day of the current month
- text.setNum(pos-firstday+1);
- painter->setPen(black);
+ if (!normalday)
+ {
+ painter->setPen(QColor(220,245,255));
+ painter->setBrush(brushLightblue);
+ painter->drawRect(0, 0, w, h);
+ painter->setPen(blue);
+ } else {
+ painter->setPen(blue);
+ painter->setBrush(brushBlue);
+ painter->drawRect(0, 0, w, h);
+ painter->setPen(white);
+ }
+ painter->drawText(0, 0, w, h-1, AlignCenter,
+ daystr, -1, &rect);
+ painter->setPen(black);
+ painter->moveTo(0, h-1);
+ painter->lineTo(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);
+ } else { // paint a day of the current month
+ text.setNum(pos-firstday+1);
+ painter->setPen(black);
}
- pen=painter->pen();
- if(firstday+date.day()-1==pos)
- {
- if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
- painter->setPen(green);
- else
- painter->setPen(red);
- if(hasFocus())
- {
- painter->setBrush(darkRed);
- pen=white;
+ pen=painter->pen();
+ if(firstday+date.day()-1==pos)
+ {
+ if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
+ painter->setPen(green);
+ else
+ painter->setPen(red);
+ if(hasFocus())
+ {
+ painter->setBrush(darkRed);
+ pen=white;
+ } else {
+ painter->setBrush(darkGray);
+ pen=white;
+ }
} else {
- painter->setBrush(darkGray);
- pen=white;
+ if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
+ {
+ painter->setPen(green);
+ painter->setBrush(darkGreen);
+ pen=white;
+ } else {
+ painter->setBrush(QColor(220,245,255));
+ painter->setPen(QColor(220,245,255));
}
- } else {
- if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
- {
- painter->setPen(green);
- painter->setBrush(darkGreen);
- pen=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->drawRect(0, 0, w, h);
+ painter->setPen(pen);
+ painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
}
- if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
- if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
+ if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
+ if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height());
}
@@ -210,24 +210,24 @@ KDateTable::keyPressEvent( QKeyEvent *e )
if ( e->key() == Qt::Key_Prior ) {
- if ( date.month() == 1 ) {
- KNotifyClient::beep();
- return;
- }
- int day = date.day();
- if ( day > 27 )
- while ( !QDate::isValid( date.year(), date.month()-1, day ) )
- day--;
- setDate(QDate(date.year(), date.month()-1, day));
- return;
+ if ( date.month() == 1 ) {
+ KNotifyClient::beep();
+ return;
+ }
+ int day = date.day();
+ if ( day > 27 )
+ while ( !QDate::isValid( date.year(), date.month()-1, day ) )
+ day--;
+ setDate(QDate(date.year(), date.month()-1, day));
+ return;
}
if ( e->key() == Qt::Key_Next ) {
- if ( date.month() == 12 ) {
- KNotifyClient::beep();
- return;
- }
- int day = date.day();
- if ( day > 27 )
- while ( !QDate::isValid( date.year(), date.month()+1, day ) )
- day--;
- setDate(QDate(date.year(), date.month()+1, day));
- return;
+ if ( date.month() == 12 ) {
+ KNotifyClient::beep();
+ return;
+ }
+ int day = date.day();
+ if ( day > 27 )
+ while ( !QDate::isValid( date.year(), date.month()+1, day ) )
+ day--;
+ setDate(QDate(date.year(), date.month()+1, day));
+ return;
}
@@ -240,18 +240,18 @@ KDateTable::keyPressEvent( QKeyEvent *e )
if ( e->state() != Qt::ControlButton ) {
- if ( e->key() == Qt::Key_Up ) {
- pos -= 7;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Down ) {
- pos += 7;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Left ) {
- pos--;
- irgnore = false;
- }
- if ( e->key() == Qt::Key_Right ) {
- pos++;
- irgnore = false;
- }
+ if ( e->key() == Qt::Key_Up ) {
+ pos -= 7;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Down ) {
+ pos += 7;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Left ) {
+ pos--;
+ irgnore = false;
+ }
+ if ( e->key() == Qt::Key_Right ) {
+ pos++;
+ irgnore = false;
+ }
}
@@ -261,11 +261,11 @@ KDateTable::keyPressEvent( QKeyEvent *e )
if(pos+dayoff<=firstday)
- { // this day is in the previous month
- KNotifyClient::beep();
- return;
- }
+ { // this day is in the previous month
+ KNotifyClient::beep();
+ return;
+ }
if(firstday+numdays<pos+dayoff)
- { // this date is in the next month
- KNotifyClient::beep(i18n( "Month not long enough" ));
- return;
- }
+ { // this date is in the next month
+ KNotifyClient::beep(i18n( "Month not long enough" ));
+ return;
+ }
@@ -285,6 +285,6 @@ KDateTable::viewportResizeEvent(QResizeEvent * e)
{
- QGridView::viewportResizeEvent(e);
+ QGridView::viewportResizeEvent(e);
- setCellWidth(viewport()->width()/7);
- setCellHeight(viewport()->height()/7);
+ setCellWidth(viewport()->width()/7);
+ setCellHeight(viewport()->height()/7);
}
@@ -294,26 +294,26 @@ KDateTable::setFontSize(int size)
{
- int count;
- QRect rect;
- // ----- store rectangles:
- fontsize=size;
- QFont font = KGlobalSettings::generalFont();
- font.setPointSize(fontsize);
- font.setBold( true );
- QFontMetrics metrics(font);
-
- // ----- find largest day name:
- maxCell.setWidth(0);
- maxCell.setHeight(0);
- for(count=0; count<7; ++count)
- {
- rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
- maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
- maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
- }
- // ----- compare with a real wide number and add some space:
- rect=metrics.boundingRect(QString::fromLatin1("88"));
- maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
- maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
- if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
- maxCell.setHeight(maxCell.width() * 1000 / 1900 );
+ int count;
+ QRect rect;
+ // ----- store rectangles:
+ fontsize=size;
+ QFont font = KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ font.setBold( true );
+ QFontMetrics metrics(font);
+
+ // ----- find largest day name:
+ maxCell.setWidth(0);
+ maxCell.setHeight(0);
+ for(count=0; count<7; ++count)
+ {
+ rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
+ maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
+ maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
+ }
+ // ----- compare with a real wide number and add some space:
+ rect=metrics.boundingRect(QString::fromLatin1("88"));
+ maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
+ maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
+ if ( maxCell.width() * 1000 / maxCell.height() > 1900 )
+ maxCell.setHeight(maxCell.width() * 1000 / 1900 );
}
@@ -323,44 +323,44 @@ KDateTable::contentsMousePressEvent(QMouseEvent *e)
{
- if(e->type()!=QEvent::MouseButtonPress)
- { // the KDatePicker only reacts on mouse press events:
- return;
- }
- if(!isEnabled())
- {
- KNotifyClient::beep();
- return;
- }
+ if(e->type()!=QEvent::MouseButtonPress)
+ { // the KDatePicker only reacts on mouse press events:
+ return;
+ }
+ if(!isEnabled())
+ {
+ KNotifyClient::beep();
+ return;
+ }
- int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
- // -----
- int row, col, pos, temp;
- 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
- return;
- }
- pos=7*(row-1)+col+1;
+ int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
+ // -----
+ int row, col, pos, temp;
+ 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
+ return;
+ }
+ pos=7*(row-1)+col+1;
#if 0
- if(pos+dayoff<=firstday)
- { // this day is in the previous month
- KNotifyClient::beep();
- return;
- }
- if(firstday+numdays<pos+dayoff)
- { // this date is in the next month
- KNotifyClient::beep();
- return;
- }
+ if(pos+dayoff<=firstday)
+ { // this day is in the previous month
+ KNotifyClient::beep();
+ return;
+ }
+ if(firstday+numdays<pos+dayoff)
+ { // this date is in the next month
+ KNotifyClient::beep();
+ return;
+ }
#endif
- temp=firstday+date.day()-dayoff-1;
- QDate da = QDate(date.year(), date.month(),1);
- setDate(da.addDays( pos-firstday+dayoff-1));
- updateCell(temp/7+1, temp%7); // Update the previously selected cell
- updateCell(row, col); // Update the selected cell
- // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
- emit(tableClicked());
+ temp=firstday+date.day()-dayoff-1;
+ QDate da = QDate(date.year(), date.month(),1);
+ setDate(da.addDays( pos-firstday+dayoff-1));
+ updateCell(temp/7+1, temp%7); // Update the previously selected cell
+ updateCell(row, col); // Update the selected cell
+ // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
+ emit(tableClicked());
}
@@ -370,34 +370,34 @@ KDateTable::setDate(const QDate& date_)
{
- bool changed=false;
- QDate temp;
- mMarkCurrent = false;
- // -----
- if(!date_.isValid())
- {
- kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
- return false;
- }
- if(date!=date_)
- {
- date=date_;
- changed=true;
- }
- mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
- temp.setYMD(date.year(), date.month(), 1);
- firstday=temp.dayOfWeek();
- if(firstday==1) firstday=8;
- numdays=date.daysInMonth();
- if(date.month()==1)
- { // set to december of previous year
- temp.setYMD(date.year()-1, 12, 1);
- } else { // set to previous month
- temp.setYMD(date.year(), date.month()-1, 1);
- }
- numDaysPrevMonth=temp.daysInMonth();
- if(changed)
- {
- repaintContents(false);
+ bool changed=false;
+ QDate temp;
+ mMarkCurrent = false;
+ // -----
+ if(!date_.isValid())
+ {
+ kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
+ return false;
+ }
+ if(date!=date_)
+ {
+ date=date_;
+ changed=true;
+ }
+ mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
+ temp.setYMD(date.year(), date.month(), 1);
+ firstday=temp.dayOfWeek();
+ if(firstday==1) firstday=8;
+ numdays=date.daysInMonth();
+ if(date.month()==1)
+ { // set to december of previous year
+ temp.setYMD(date.year()-1, 12, 1);
+ } else { // set to previous month
+ temp.setYMD(date.year(), date.month()-1, 1);
}
- emit(dateChanged(date));
- return true;
+ numDaysPrevMonth=temp.daysInMonth();
+ if(changed)
+ {
+ repaintContents(false);
+ }
+ emit(dateChanged(date));
+ return true;
}
@@ -407,3 +407,3 @@ KDateTable::getDate() const
{
- return date;
+ return date;
}
@@ -425,8 +425,8 @@ 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);
+ 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);
}
@@ -436,32 +436,32 @@ KDateInternalMonthPicker::KDateInternalMonthPicker
(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(4);
- setNumCols(3);
- // enable to find drawing failures:
- // setTableFlags(Tbl_clipCellPainting);
+ : 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(4);
+ setNumCols(3);
+ // enable to find drawing failures:
+ // setTableFlags(Tbl_clipCellPainting);
#if 0
- viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+ 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 <= 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());
- }
+ // ----- 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());
+ }
@@ -472,4 +472,4 @@ KDateInternalMonthPicker::sizeHint() const
{
- return QSize((max.width()+6)*numCols()+2*frameWidth(),
- (max.height()+6)*numRows()+2*frameWidth());
+ return QSize((max.width()+6)*numCols()+2*frameWidth(),
+ (max.height()+6)*numRows()+2*frameWidth());
}
@@ -479,3 +479,3 @@ KDateInternalMonthPicker::getResult() const
{
- return result;
+ return result;
}
@@ -485,3 +485,3 @@ KDateInternalMonthPicker::setupPainter(QPainter *p)
{
- p->setPen(black);
+ p->setPen(black);
}
@@ -491,4 +491,4 @@ KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
{
- setCellWidth(width()/3);
- setCellHeight(height()/4);
+ setCellWidth(width()/3);
+ setCellHeight(height()/4);
}
@@ -498,10 +498,10 @@ 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);
- if ( activeCol == col && activeRow == row )
- painter->drawRect( 0, 0, cellWidth(), cellHeight() );
+ 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);
+ if ( activeCol == col && activeRow == row )
+ painter->drawRect( 0, 0, cellWidth(), cellHeight() );
}
@@ -511,24 +511,24 @@ KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
{
- if(!isEnabled() || e->button() != LeftButton)
- {
- KNotifyClient::beep();
- return;
+ 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 */ );
}
- // -----
- 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 */ );
- }
}
@@ -538,37 +538,37 @@ KDateInternalMonthPicker::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 (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 */ );
}
- if ( tmpRow > -1 ) // repaint the former active cell
- updateCell( tmpRow, tmpCol /*, true */ );
- }
}
@@ -578,20 +578,20 @@ KDateInternalMonthPicker::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=3*row+col+1;
- result=pos;
- emit(closeMe(1));
+ 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=3*row+col+1;
+ result=pos;
+ emit(closeMe(1));
}
@@ -602,18 +602,18 @@ 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);
+ : 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(QFrame::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()));
+ // we have to respect the limits of QDate here, I fear:
+ val->setRange(0, 8000);
+ setValidator(val);
+ connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
}
@@ -623,20 +623,20 @@ KDateInternalYearSelector::yearEnteredSlot()
{
- bool ok;
- int year;
- QDate date;
- // ----- check if this is a valid year:
- year=text().toInt(&ok);
- if(!ok)
- {
- KNotifyClient::beep();
- return;
- }
- date.setYMD(year, 1, 1);
- if(!date.isValid())
- {
- KNotifyClient::beep();
- return;
- }
- result=year;
- emit(closeMe(1));
+ bool ok;
+ int year;
+ QDate date;
+ // ----- check if this is a valid year:
+ year=text().toInt(&ok);
+ if(!ok)
+ {
+ KNotifyClient::beep();
+ return;
+ }
+ date.setYMD(year, 1, 1);
+ if(!date.isValid())
+ {
+ KNotifyClient::beep();
+ return;
+ }
+ result=year;
+ emit(closeMe(1));
}
@@ -646,3 +646,3 @@ KDateInternalYearSelector::getYear()
{
- return result;
+ return result;
}
@@ -652,6 +652,6 @@ KDateInternalYearSelector::setYear(int year)
{
- QString temp;
- // -----
- temp.setNum(year);
- setText(temp);
+ QString temp;
+ // -----
+ temp.setNum(year);
+ setText(temp);
}
@@ -659,8 +659,8 @@ KDateInternalYearSelector::setYear(int year)
KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
- : QFrame(parent, name, WType_Popup),
- result(0), // rejected
- main(0)
+ : QFrame(parent, name, WType_Popup),
+ result(0), // rejected
+ main(0)
{
- setFrameStyle(QFrame::Box|QFrame::Raised);
- setMidLineWidth(2);
+ setFrameStyle(QFrame::Box|QFrame::Raised);
+ setMidLineWidth(2);
}
@@ -670,7 +670,7 @@ KPopupFrame::keyPressEvent(QKeyEvent* e)
{
- if(e->key()==Key_Escape)
- {
- result=0; // rejected
- qApp->exit_loop();
- }
+ if(e->key()==Key_Escape)
+ {
+ result=0; // rejected
+ qApp->exit_loop();
+ }
}
@@ -680,4 +680,4 @@ KPopupFrame::close(int r)
{
- result=r;
- qApp->exit_loop();
+ result=r;
+ qApp->exit_loop();
}
@@ -687,7 +687,7 @@ KPopupFrame::setMainWidget(QWidget* m)
{
- main=m;
- if(main!=0)
- {
- resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
- }
+ main=m;
+ if(main!=0)
+ {
+ resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
+ }
}
@@ -697,7 +697,7 @@ KPopupFrame::resizeEvent(QResizeEvent*)
{
- if(main!=0)
- {
- main->setGeometry(frameWidth(), frameWidth(),
- width()-2*frameWidth(), height()-2*frameWidth());
- }
+ if(main!=0)
+ {
+ main->setGeometry(frameWidth(), frameWidth(),
+ width()-2*frameWidth(), height()-2*frameWidth());
+ }
}
@@ -707,20 +707,20 @@ KPopupFrame::popup(const QPoint &pos)
{
- // Make sure the whole popup is visible.
- QRect d = QApplication::desktop()->frameGeometry();
- int x = pos.x();
- int y = pos.y();
- int w = width();
- int h = height();
- if (x+w > d.x()+d.width())
- x = d.width() - w;
- if (y+h > d.y()+d.height())
- y = d.height() - h;
- if (x < d.x())
- x = 0;
- if (y < d.y())
- y = 0;
-
- // Pop the thingy up.
- move(x, y);
- show();
+ // Make sure the whole popup is visible.
+ QRect d = QApplication::desktop()->frameGeometry();
+ int x = pos.x();
+ int y = pos.y();
+ int w = width();
+ int h = height();
+ if (x+w > d.x()+d.width())
+ x = d.width() - w;
+ if (y+h > d.y()+d.height())
+ y = d.height() - h;
+ if (x < d.x())
+ x = 0;
+ if (y < d.y())
+ y = 0;
+
+ // Pop the thingy up.
+ move(x, y);
+ show();
}
@@ -730,7 +730,7 @@ KPopupFrame::exec(QPoint pos)
{
- popup(pos);
- repaint();
- qApp->enter_loop();
- hide();
- return result;
+ popup(pos);
+ repaint();
+ qApp->enter_loop();
+ hide();
+ return result;
}
@@ -740,3 +740,3 @@ KPopupFrame::exec(int x, int y)
{
- return exec(QPoint(x, y));
+ return exec(QPoint(x, y));
}
@@ -750 +750,166 @@ void KDateTable::virtual_hook( int, void* )
//#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));
+}
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index b4d3e16..2efa532 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -309 +309,64 @@ private:
#endif // KDATETBL_H
+class KDateInternalWeekPicker : public QGridView
+{
+ Q_OBJECT
+protected:
+ /**
+ * Store the month that has been clicked [1..12].
+ */
+ int result;
+ /**
+ * the cell under mouse cursor when LBM is pressed
+ */
+ short int activeCol;
+ short int activeRow;
+ /**
+ * Contains the largest rectangle needed by the month names.
+ */
+ QRect max;
+signals:
+ /**
+ * This is send from the mouse click event handler.
+ */
+ void closeMe(int);
+public:
+ /**
+ * The constructor.
+ */
+ KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0);
+ /**
+ * The size hint.
+ */
+ QSize sizeHint() const;
+ /**
+ * Return the result. 0 means no selection (reject()), 1..12 are the
+ * months.
+ */
+ int getResult() const;
+protected:
+ /**
+ * Set up the painter.
+ */
+ void setupPainter(QPainter *p);
+ /**
+ * The resize event.
+ */
+ void viewportResizeEvent(QResizeEvent*);
+ /**
+ * Paint a cell. This simply draws the month names in it.
+ */
+ virtual void paintCell(QPainter* painter, int row, int col);
+ /**
+ * Catch mouse click and move events to paint a rectangle around the item.
+ */
+ void contentsMousePressEvent(QMouseEvent *e);
+ void contentsMouseMoveEvent(QMouseEvent *e);
+ /**
+ * Emit monthSelected(int) when a cell has been released.
+ */
+ void contentsMouseReleaseEvent(QMouseEvent *e);
+
+private:
+ class KDateInternalMonthPrivate;
+ KDateInternalMonthPrivate *d;
+};