author | zautrix <zautrix> | 2005-02-07 06:10:09 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-07 06:10:09 (UTC) |
commit | 301a4a207171549bd87815705d8dcf32ad15559d (patch) (unidiff) | |
tree | 715fde2cd0af0c057f767c25d8e67298425b2c82 | |
parent | 961fc44f4092c1f981eb3be4284715e6829f885c (diff) | |
download | kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.zip kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.gz kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.bz2 |
new cool feature
-rw-r--r-- | korganizer/mainwindow.cpp | 106 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 15 | ||||
-rw-r--r-- | microkde/kdatetbl.cpp | 1091 | ||||
-rw-r--r-- | microkde/kdatetbl.h | 63 |
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; | |||
74 | 74 | ||
75 | |||
75 | class KOex2phonePrefs : public QDialog | 76 | class KOex2phonePrefs : public QDialog |
@@ -146,6 +147,7 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : | |||
146 | mFlagKeyPressed = false; | 147 | mFlagKeyPressed = false; |
148 | setCaption("KOrganizer/Pi"); | ||
147 | KOPrefs *p = KOPrefs::instance(); | 149 | KOPrefs *p = KOPrefs::instance(); |
148 | KPimGlobalPrefs::instance()->setGlobalConfig(); | 150 | KPimGlobalPrefs::instance()->setGlobalConfig(); |
149 | if ( p->mHourSize > 18 ) | 151 | if ( p->mHourSize > 22 ) |
150 | p->mHourSize = 18; | 152 | p->mHourSize = 22; |
151 | QMainWindow::ToolBarDock tbd; | 153 | QMainWindow::ToolBarDock tbd; |
@@ -169,4 +171,2 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : | |||
169 | mCalendarModifiedFlag = false; | 171 | mCalendarModifiedFlag = false; |
170 | |||
171 | setCaption("KOrganizer/Pi"); | ||
172 | QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); | 172 | QLabel* splash = new QLabel(i18n("KO/Pi is starting ... "), this ); |
@@ -559,30 +559,41 @@ void MainWindow::initActions() | |||
559 | connect ( selectFilterMenu, SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenu() ) ); | 559 | connect ( selectFilterMenu, SIGNAL( aboutToShow() ), this, SLOT (fillFilterMenu() ) ); |
560 | 560 | QIconSet icon; | |
561 | menuBarWeek = new QPEMenuBar( iconToolBar ); | 561 | int pixWid = 22, pixHei = 22; |
562 | QPopupMenu * wpo = new QPopupMenu (this); | 562 | QString pathString = ""; |
563 | QPopupMenu * all = new QPopupMenu (this); | 563 | if ( !p->mToolBarMiniIcons ) { |
564 | //wpo->insertItem( i18n("W#"), 0 ); | 564 | if ( QApplication::desktop()->width() < 480 ) { |
565 | int first = 1; | 565 | pathString += "icons16/"; |
566 | int i; | 566 | pixWid = 18; pixHei = 16; |
567 | for ( i = 1; i < 50; ++i ) { | ||
568 | if ( !(i%10) ) { | ||
569 | all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo ); | ||
570 | connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) ); | ||
571 | first = i; | ||
572 | wpo = new QPopupMenu (this); | ||
573 | } | 567 | } |
574 | wpo->insertItem( QString::number(i), i ); | 568 | } else { |
575 | } | 569 | pathString += "iconsmini/"; |
576 | for ( i = 50; i < 53; ++i ) { | 570 | pixWid = 18; pixHei = 16; |
577 | wpo->insertItem( QString::number(i), i); | 571 | } |
572 | mWeekBgColor = iconToolBar->backgroundColor(); | ||
573 | mWeekPixmap.resize( pixWid , pixHei ); | ||
574 | mWeekPixmap.fill( mWeekBgColor ); | ||
575 | icon = mWeekPixmap; | ||
576 | mWeekAction = new QAction( i18n("Select week number"),icon, i18n("Select week number"), 0, this ); | ||
577 | mWeekAction->addTo( iconToolBar ); | ||
578 | mWeekFont = font(); | ||
579 | |||
580 | int fontPoint = mWeekFont.pointSize(); | ||
581 | QFontMetrics f( mWeekFont ); | ||
582 | int fontWid = f.width( "30" ); | ||
583 | while ( fontWid > pixWid ) { | ||
584 | --fontPoint; | ||
585 | mWeekFont.setPointSize( fontPoint ); | ||
586 | QFontMetrics f( mWeekFont ); | ||
587 | fontWid = f.width( "30" ); | ||
588 | qDebug("dec-- "); | ||
578 | } | 589 | } |
579 | all->insertItem( i18n("Select week %1-%2" ).arg(first).arg( i-1) ,wpo ); | 590 | |
580 | connect( wpo, SIGNAL( activated(int) ), SIGNAL( selectWeek ( int ) ) ); | 591 | connect( mWeekAction, SIGNAL( activated() ), |
581 | menuBarWeek->insertItem( "00",all,1); | 592 | this, SLOT( weekAction() ) ); |
582 | menuBarWeek->setMaximumSize( menuBarWeek->sizeHint( )); | ||
583 | 593 | ||
584 | connect( this, SIGNAL( selectWeek ( int ) ), mView->dateNavigator(), SLOT( selectWeek ( int ) ) ); | 594 | connect( this, SIGNAL( selectWeek ( int ) ), mView->dateNavigator(), SLOT( selectWeek ( int ) ) ); |
595 | |||
596 | //#endif | ||
585 | // ****************** | 597 | // ****************** |
586 | QAction *action; | 598 | QAction *action; |
587 | QIconSet icon; | ||
588 | // QPopupMenu *configureMenu= new QPopupMenu( menuBar ); | 599 | // QPopupMenu *configureMenu= new QPopupMenu( menuBar ); |
@@ -590,8 +601,3 @@ void MainWindow::initActions() | |||
590 | 601 | ||
591 | QString pathString = ""; | 602 | |
592 | if ( !p->mToolBarMiniIcons ) { | ||
593 | if ( QApplication::desktop()->width() < 480 ) | ||
594 | pathString += "icons16/"; | ||
595 | } else | ||
596 | pathString += "iconsmini/"; | ||
597 | configureAgendaMenu->setCheckable( true ); | 603 | configureAgendaMenu->setCheckable( true ); |
@@ -1372,4 +1378,10 @@ void MainWindow::updateWeek(QDate seda) | |||
1372 | } | 1378 | } |
1373 | //qDebug("weeknum %s ", QString::number( weekNum).latin1()); | 1379 | |
1374 | menuBarWeek-> changeItem(1, QString::number( weekNum) ); | 1380 | mWeekPixmap.fill( mWeekBgColor ); |
1381 | QPainter p ( &mWeekPixmap ); | ||
1382 | p.setFont( mWeekFont ); | ||
1383 | p.drawText( 0,0,mWeekPixmap.width(), mWeekPixmap.height(),AlignCenter, QString::number( weekNum) ); | ||
1384 | p.end(); | ||
1385 | QIconSet icon3 ( mWeekPixmap ); | ||
1386 | mWeekAction->setIconSet ( icon3 ); | ||
1375 | 1387 | ||
@@ -1721,3 +1733,3 @@ void MainWindow::keyPressEvent ( QKeyEvent * e ) | |||
1721 | size = p->mHourSize +2; | 1733 | size = p->mHourSize +2; |
1722 | if ( size <= 18 ) | 1734 | if ( size <= 22 ) |
1723 | configureAgenda( size ); | 1735 | configureAgenda( size ); |
@@ -2013 +2025,25 @@ void MainWindow::printCal() | |||
2013 | 2025 | ||
2026 | |||
2027 | #include "libkdepim/kdatepicker.h" | ||
2028 | #include <kdatetbl.h> | ||
2029 | void MainWindow::weekAction() | ||
2030 | { | ||
2031 | int month; | ||
2032 | KPopupFrame* popup = new KPopupFrame(this); | ||
2033 | int size = 12; | ||
2034 | if ( QApplication::desktop()->width() >= 480 ) | ||
2035 | size = 18; | ||
2036 | KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(size, popup); | ||
2037 | // ----- | ||
2038 | picker->resize(picker->sizeHint()); | ||
2039 | popup->setMainWidget(picker); | ||
2040 | picker->setFocus(); | ||
2041 | connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); | ||
2042 | if(popup->exec(iconToolBar->mapToGlobal(QPoint(0, iconToolBar->height())))) | ||
2043 | { | ||
2044 | month = picker->getResult(); | ||
2045 | emit selectWeek ( month ); | ||
2046 | //qDebug("weekSelected %d ", month); | ||
2047 | } | ||
2048 | delete popup; | ||
2049 | } | ||
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 @@ | |||
7 | #include <qfile.h> | 7 | #include <qfile.h> |
8 | #include <qmenubar.h> | ||
8 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
@@ -25,3 +26,2 @@ class KSyncProfile; | |||
25 | class QPEToolBar; | 26 | class QPEToolBar; |
26 | class QPEMenuBar; | ||
27 | 27 | ||
@@ -32,2 +32,9 @@ class CalendarLocal; | |||
32 | 32 | ||
33 | class KOMenuBar : public QMenuBar | ||
34 | { | ||
35 | public: | ||
36 | KOMenuBar( QWidget *parent=0 ): QMenuBar (parent ) {;} | ||
37 | QSize sizeHint () const{ qDebug("sizejint ");return QSize ( 40,25 );} | ||
38 | }; | ||
39 | |||
33 | using namespace KCal; | 40 | using namespace KCal; |
@@ -52,2 +59,3 @@ class MainWindow : public QMainWindow | |||
52 | void setCaptionToDates(); | 59 | void setCaptionToDates(); |
60 | void weekAction(); | ||
53 | void about(); | 61 | void about(); |
@@ -122,3 +130,6 @@ class MainWindow : public QMainWindow | |||
122 | QAction *mNewSubTodoAction; | 130 | QAction *mNewSubTodoAction; |
123 | QPEMenuBar *menuBarWeek; | 131 | QAction *mWeekAction; |
132 | QFont mWeekFont; | ||
133 | QPixmap mWeekPixmap; | ||
134 | QColor mWeekBgColor; | ||
124 | 135 | ||
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 @@ | |||
3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) | 3 | Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org) |
4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) | 4 | (C) 1998-2001 Mirko Boehm (mirko@kde.org) |
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
@@ -57,5 +57,5 @@ KDateValidator::validate(QString& text, int&) const | |||
57 | { | 57 | { |
58 | QDate temp; | 58 | QDate temp; |
59 | // ----- everything is tested in date(): | 59 | // ----- everything is tested in date(): |
60 | return date(text, temp); | 60 | return date(text, temp); |
61 | } | 61 | } |
@@ -65,9 +65,9 @@ KDateValidator::date(const QString& text, QDate& d) const | |||
65 | { | 65 | { |
66 | QDate tmp = KGlobal::locale()->readDate(text); | 66 | QDate tmp = KGlobal::locale()->readDate(text); |
67 | if (!tmp.isNull()) | 67 | if (!tmp.isNull()) |
68 | { | 68 | { |
69 | d = tmp; | 69 | d = tmp; |
70 | return Acceptable; | 70 | return Acceptable; |
71 | } else | 71 | } else |
72 | return Valid; | 72 | return Valid; |
73 | } | 73 | } |
@@ -81,20 +81,20 @@ KDateValidator::fixup( QString& ) const | |||
81 | KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) | 81 | KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) |
82 | : QGridView(parent, name, f) | 82 | : QGridView(parent, name, f) |
83 | { | 83 | { |
84 | setFontSize(10); | 84 | setFontSize(10); |
85 | if(!date_.isValid()) | 85 | if(!date_.isValid()) |
86 | { | 86 | { |
87 | date_=QDate::currentDate(); | 87 | date_=QDate::currentDate(); |
88 | } | 88 | } |
89 | setFocusPolicy( QWidget::StrongFocus ); | 89 | setFocusPolicy( QWidget::StrongFocus ); |
90 | setNumRows(7); // 6 weeks max + headline | 90 | setNumRows(7); // 6 weeks max + headline |
91 | setNumCols(7); // 7 days a week | 91 | setNumCols(7); // 7 days a week |
92 | setHScrollBarMode(AlwaysOff); | 92 | setHScrollBarMode(AlwaysOff); |
93 | setVScrollBarMode(AlwaysOff); | 93 | setVScrollBarMode(AlwaysOff); |
94 | viewport()->setBackgroundColor(QColor(220,245,255)); | 94 | viewport()->setBackgroundColor(QColor(220,245,255)); |
95 | #if 0 | 95 | #if 0 |
96 | viewport()->setEraseColor(lightGray); | 96 | viewport()->setEraseColor(lightGray); |
97 | #endif | 97 | #endif |
98 | mMarkCurrent = false; | 98 | mMarkCurrent = false; |
99 | setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth | 99 | setDate(date_); // this initializes firstday, numdays, numDaysPrevMonth |
100 | } | 100 | } |
@@ -104,100 +104,100 @@ KDateTable::paintCell(QPainter *painter, int row, int col) | |||
104 | { | 104 | { |
105 | QRect rect; | 105 | QRect rect; |
106 | QString text; | 106 | QString text; |
107 | QPen pen; | 107 | QPen pen; |
108 | int w=cellWidth(); | 108 | int w=cellWidth(); |
109 | int h=cellHeight(); | 109 | int h=cellHeight(); |
110 | int pos; | 110 | int pos; |
111 | QBrush brushBlue(blue); | 111 | QBrush brushBlue(blue); |
112 | QBrush brushLightblue(QColor(220,245,255)); | 112 | QBrush brushLightblue(QColor(220,245,255)); |
113 | QFont font=KGlobalSettings::generalFont(); | 113 | QFont font=KGlobalSettings::generalFont(); |
114 | // ----- | 114 | // ----- |
115 | font.setPointSize(fontsize); | 115 | font.setPointSize(fontsize); |
116 | if(row==0) | 116 | if(row==0) |
117 | { // we are drawing the headline | 117 | { // we are drawing the headline |
118 | font.setBold(true); | 118 | font.setBold(true); |
119 | painter->setFont(font); | 119 | painter->setFont(font); |
120 | bool normalday = true; | 120 | bool normalday = true; |
121 | QString daystr; | 121 | QString daystr; |
122 | if (KGlobal::locale()->weekStartsMonday()) | 122 | if (KGlobal::locale()->weekStartsMonday()) |
123 | { | 123 | { |
124 | daystr = KGlobal::locale()->weekDayName(col+1, true); | 124 | daystr = KGlobal::locale()->weekDayName(col+1, true); |
125 | if (col == 5 || col == 6) | 125 | if (col == 5 || col == 6) |
126 | normalday = false; | 126 | normalday = false; |
127 | } else { | 127 | } else { |
128 | daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); | 128 | daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); |
129 | if (col == 0 || col == 6) | 129 | if (col == 0 || col == 6) |
130 | normalday = false; | 130 | normalday = false; |
131 | } | ||
132 | if (!normalday) | ||
133 | { | ||
134 | painter->setPen(QColor(220,245,255)); | ||
135 | painter->setBrush(brushLightblue); | ||
136 | painter->drawRect(0, 0, w, h); | ||
137 | painter->setPen(blue); | ||
138 | } else { | ||
139 | painter->setPen(blue); | ||
140 | painter->setBrush(brushBlue); | ||
141 | painter->drawRect(0, 0, w, h); | ||
142 | painter->setPen(white); | ||
143 | } | ||
144 | painter->drawText(0, 0, w, h-1, AlignCenter, | ||
145 | daystr, -1, &rect); | ||
146 | painter->setPen(black); | ||
147 | painter->moveTo(0, h-1); | ||
148 | painter->lineTo(w-1, h-1); | ||
149 | // ----- draw the weekday: | ||
150 | } else { | ||
151 | painter->setFont(font); | ||
152 | pos=7*(row-1)+col; | ||
153 | if (KGlobal::locale()->weekStartsMonday()) | ||
154 | pos++; | ||
155 | if(pos<firstday || (firstday+numdays<=pos)) | ||
156 | { // we are either | ||
157 | // ° painting a day of the previous month or | ||
158 | // ° painting a day of the following month | ||
159 | if(pos<firstday) | ||
160 | { // previous month | ||
161 | text.setNum(numDaysPrevMonth+pos-firstday+1); | ||
162 | } else { // following month | ||
163 | text.setNum(pos-firstday-numdays+1); | ||
164 | } | 131 | } |
165 | painter->setPen(gray); | 132 | if (!normalday) |
166 | } else { // paint a day of the current month | 133 | { |
167 | text.setNum(pos-firstday+1); | 134 | painter->setPen(QColor(220,245,255)); |
168 | painter->setPen(black); | 135 | painter->setBrush(brushLightblue); |
136 | painter->drawRect(0, 0, w, h); | ||
137 | painter->setPen(blue); | ||
138 | } else { | ||
139 | painter->setPen(blue); | ||
140 | painter->setBrush(brushBlue); | ||
141 | painter->drawRect(0, 0, w, h); | ||
142 | painter->setPen(white); | ||
143 | } | ||
144 | painter->drawText(0, 0, w, h-1, AlignCenter, | ||
145 | daystr, -1, &rect); | ||
146 | painter->setPen(black); | ||
147 | painter->moveTo(0, h-1); | ||
148 | painter->lineTo(w-1, h-1); | ||
149 | // ----- draw the weekday: | ||
150 | } else { | ||
151 | painter->setFont(font); | ||
152 | pos=7*(row-1)+col; | ||
153 | if (KGlobal::locale()->weekStartsMonday()) | ||
154 | pos++; | ||
155 | if(pos<firstday || (firstday+numdays<=pos)) | ||
156 | { // we are either | ||
157 | // ° painting a day of the previous month or | ||
158 | // ° painting a day of the following month | ||
159 | if(pos<firstday) | ||
160 | { // previous month | ||
161 | text.setNum(numDaysPrevMonth+pos-firstday+1); | ||
162 | } else { // following month | ||
163 | text.setNum(pos-firstday-numdays+1); | ||
164 | } | ||
165 | painter->setPen(gray); | ||
166 | } else { // paint a day of the current month | ||
167 | text.setNum(pos-firstday+1); | ||
168 | painter->setPen(black); | ||
169 | } | 169 | } |
170 | 170 | ||
171 | pen=painter->pen(); | 171 | pen=painter->pen(); |
172 | if(firstday+date.day()-1==pos) | 172 | if(firstday+date.day()-1==pos) |
173 | { | 173 | { |
174 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) | 174 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) |
175 | painter->setPen(green); | 175 | painter->setPen(green); |
176 | else | 176 | else |
177 | painter->setPen(red); | 177 | painter->setPen(red); |
178 | if(hasFocus()) | 178 | if(hasFocus()) |
179 | { | 179 | { |
180 | painter->setBrush(darkRed); | 180 | painter->setBrush(darkRed); |
181 | pen=white; | 181 | pen=white; |
182 | } else { | ||
183 | painter->setBrush(darkGray); | ||
184 | pen=white; | ||
185 | } | ||
182 | } else { | 186 | } else { |
183 | painter->setBrush(darkGray); | 187 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) |
184 | pen=white; | 188 | { |
189 | painter->setPen(green); | ||
190 | painter->setBrush(darkGreen); | ||
191 | pen=white; | ||
192 | } else { | ||
193 | painter->setBrush(QColor(220,245,255)); | ||
194 | painter->setPen(QColor(220,245,255)); | ||
185 | } | 195 | } |
186 | } else { | 196 | } |
187 | if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) | 197 | painter->drawRect(0, 0, w, h); |
188 | { | 198 | painter->setPen(pen); |
189 | painter->setPen(green); | 199 | painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); |
190 | painter->setBrush(darkGreen); | ||
191 | pen=white; | ||
192 | } else { | ||
193 | painter->setBrush(QColor(220,245,255)); | ||
194 | painter->setPen(QColor(220,245,255)); | ||
195 | } | ||
196 | } | ||
197 | painter->drawRect(0, 0, w, h); | ||
198 | painter->setPen(pen); | ||
199 | painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); | ||
200 | } | 200 | } |
201 | if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); | 201 | if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); |
202 | if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); | 202 | if(rect.height()>maxCell.height()) maxCell.setHeight(rect.height()); |
203 | } | 203 | } |
@@ -210,24 +210,24 @@ KDateTable::keyPressEvent( QKeyEvent *e ) | |||
210 | if ( e->key() == Qt::Key_Prior ) { | 210 | if ( e->key() == Qt::Key_Prior ) { |
211 | if ( date.month() == 1 ) { | 211 | if ( date.month() == 1 ) { |
212 | KNotifyClient::beep(); | 212 | KNotifyClient::beep(); |
213 | return; | 213 | return; |
214 | } | 214 | } |
215 | int day = date.day(); | 215 | int day = date.day(); |
216 | if ( day > 27 ) | 216 | if ( day > 27 ) |
217 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) | 217 | while ( !QDate::isValid( date.year(), date.month()-1, day ) ) |
218 | day--; | 218 | day--; |
219 | setDate(QDate(date.year(), date.month()-1, day)); | 219 | setDate(QDate(date.year(), date.month()-1, day)); |
220 | return; | 220 | return; |
221 | } | 221 | } |
222 | if ( e->key() == Qt::Key_Next ) { | 222 | if ( e->key() == Qt::Key_Next ) { |
223 | if ( date.month() == 12 ) { | 223 | if ( date.month() == 12 ) { |
224 | KNotifyClient::beep(); | 224 | KNotifyClient::beep(); |
225 | return; | 225 | return; |
226 | } | 226 | } |
227 | int day = date.day(); | 227 | int day = date.day(); |
228 | if ( day > 27 ) | 228 | if ( day > 27 ) |
229 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) | 229 | while ( !QDate::isValid( date.year(), date.month()+1, day ) ) |
230 | day--; | 230 | day--; |
231 | setDate(QDate(date.year(), date.month()+1, day)); | 231 | setDate(QDate(date.year(), date.month()+1, day)); |
232 | return; | 232 | return; |
233 | } | 233 | } |
@@ -240,18 +240,18 @@ KDateTable::keyPressEvent( QKeyEvent *e ) | |||
240 | if ( e->state() != Qt::ControlButton ) { | 240 | if ( e->state() != Qt::ControlButton ) { |
241 | if ( e->key() == Qt::Key_Up ) { | 241 | if ( e->key() == Qt::Key_Up ) { |
242 | pos -= 7; | 242 | pos -= 7; |
243 | irgnore = false; | 243 | irgnore = false; |
244 | } | 244 | } |
245 | if ( e->key() == Qt::Key_Down ) { | 245 | if ( e->key() == Qt::Key_Down ) { |
246 | pos += 7; | 246 | pos += 7; |
247 | irgnore = false; | 247 | irgnore = false; |
248 | } | 248 | } |
249 | if ( e->key() == Qt::Key_Left ) { | 249 | if ( e->key() == Qt::Key_Left ) { |
250 | pos--; | 250 | pos--; |
251 | irgnore = false; | 251 | irgnore = false; |
252 | } | 252 | } |
253 | if ( e->key() == Qt::Key_Right ) { | 253 | if ( e->key() == Qt::Key_Right ) { |
254 | pos++; | 254 | pos++; |
255 | irgnore = false; | 255 | irgnore = false; |
256 | } | 256 | } |
257 | } | 257 | } |
@@ -261,11 +261,11 @@ KDateTable::keyPressEvent( QKeyEvent *e ) | |||
261 | if(pos+dayoff<=firstday) | 261 | if(pos+dayoff<=firstday) |
262 | { // this day is in the previous month | 262 | { // this day is in the previous month |
263 | KNotifyClient::beep(); | 263 | KNotifyClient::beep(); |
264 | return; | 264 | return; |
265 | } | 265 | } |
266 | if(firstday+numdays<pos+dayoff) | 266 | if(firstday+numdays<pos+dayoff) |
267 | { // this date is in the next month | 267 | { // this date is in the next month |
268 | KNotifyClient::beep(i18n( "Month not long enough" )); | 268 | KNotifyClient::beep(i18n( "Month not long enough" )); |
269 | return; | 269 | return; |
270 | } | 270 | } |
271 | 271 | ||
@@ -285,6 +285,6 @@ KDateTable::viewportResizeEvent(QResizeEvent * e) | |||
285 | { | 285 | { |
286 | QGridView::viewportResizeEvent(e); | 286 | QGridView::viewportResizeEvent(e); |
287 | 287 | ||
288 | setCellWidth(viewport()->width()/7); | 288 | setCellWidth(viewport()->width()/7); |
289 | setCellHeight(viewport()->height()/7); | 289 | setCellHeight(viewport()->height()/7); |
290 | } | 290 | } |
@@ -294,26 +294,26 @@ KDateTable::setFontSize(int size) | |||
294 | { | 294 | { |
295 | int count; | 295 | int count; |
296 | QRect rect; | 296 | QRect rect; |
297 | // ----- store rectangles: | 297 | // ----- store rectangles: |
298 | fontsize=size; | 298 | fontsize=size; |
299 | QFont font = KGlobalSettings::generalFont(); | 299 | QFont font = KGlobalSettings::generalFont(); |
300 | font.setPointSize(fontsize); | 300 | font.setPointSize(fontsize); |
301 | font.setBold( true ); | 301 | font.setBold( true ); |
302 | QFontMetrics metrics(font); | 302 | QFontMetrics metrics(font); |
303 | 303 | ||
304 | // ----- find largest day name: | 304 | // ----- find largest day name: |
305 | maxCell.setWidth(0); | 305 | maxCell.setWidth(0); |
306 | maxCell.setHeight(0); | 306 | maxCell.setHeight(0); |
307 | for(count=0; count<7; ++count) | 307 | for(count=0; count<7; ++count) |
308 | { | 308 | { |
309 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); | 309 | rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); |
310 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); | 310 | maxCell.setWidth(QMAX(maxCell.width(), rect.width())); |
311 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); | 311 | maxCell.setHeight(QMAX(maxCell.height(), rect.height())); |
312 | } | 312 | } |
313 | // ----- compare with a real wide number and add some space: | 313 | // ----- compare with a real wide number and add some space: |
314 | rect=metrics.boundingRect(QString::fromLatin1("88")); | 314 | rect=metrics.boundingRect(QString::fromLatin1("88")); |
315 | maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); | 315 | maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); |
316 | maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); | 316 | maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); |
317 | if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) | 317 | if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) |
318 | maxCell.setHeight(maxCell.width() * 1000 / 1900 ); | 318 | maxCell.setHeight(maxCell.width() * 1000 / 1900 ); |
319 | } | 319 | } |
@@ -323,44 +323,44 @@ KDateTable::contentsMousePressEvent(QMouseEvent *e) | |||
323 | { | 323 | { |
324 | if(e->type()!=QEvent::MouseButtonPress) | 324 | if(e->type()!=QEvent::MouseButtonPress) |
325 | { // the KDatePicker only reacts on mouse press events: | 325 | { // the KDatePicker only reacts on mouse press events: |
326 | return; | 326 | return; |
327 | } | 327 | } |
328 | if(!isEnabled()) | 328 | if(!isEnabled()) |
329 | { | 329 | { |
330 | KNotifyClient::beep(); | 330 | KNotifyClient::beep(); |
331 | return; | 331 | return; |
332 | } | 332 | } |
333 | 333 | ||
334 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; | 334 | int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; |
335 | // ----- | 335 | // ----- |
336 | int row, col, pos, temp; | 336 | int row, col, pos, temp; |
337 | QPoint mouseCoord; | 337 | QPoint mouseCoord; |
338 | // ----- | 338 | // ----- |
339 | mouseCoord = e->pos(); | 339 | mouseCoord = e->pos(); |
340 | row=rowAt(mouseCoord.y()); | 340 | row=rowAt(mouseCoord.y()); |
341 | col=columnAt(mouseCoord.x()); | 341 | col=columnAt(mouseCoord.x()); |
342 | if(row<0 || col<0) | 342 | if(row<0 || col<0) |
343 | { // the user clicked on the frame of the table | 343 | { // the user clicked on the frame of the table |
344 | return; | 344 | return; |
345 | } | 345 | } |
346 | pos=7*(row-1)+col+1; | 346 | pos=7*(row-1)+col+1; |
347 | #if 0 | 347 | #if 0 |
348 | if(pos+dayoff<=firstday) | 348 | if(pos+dayoff<=firstday) |
349 | { // this day is in the previous month | 349 | { // this day is in the previous month |
350 | KNotifyClient::beep(); | 350 | KNotifyClient::beep(); |
351 | return; | 351 | return; |
352 | } | 352 | } |
353 | if(firstday+numdays<pos+dayoff) | 353 | if(firstday+numdays<pos+dayoff) |
354 | { // this date is in the next month | 354 | { // this date is in the next month |
355 | KNotifyClient::beep(); | 355 | KNotifyClient::beep(); |
356 | return; | 356 | return; |
357 | } | 357 | } |
358 | #endif | 358 | #endif |
359 | temp=firstday+date.day()-dayoff-1; | 359 | temp=firstday+date.day()-dayoff-1; |
360 | QDate da = QDate(date.year(), date.month(),1); | 360 | QDate da = QDate(date.year(), date.month(),1); |
361 | setDate(da.addDays( pos-firstday+dayoff-1)); | 361 | setDate(da.addDays( pos-firstday+dayoff-1)); |
362 | updateCell(temp/7+1, temp%7); // Update the previously selected cell | 362 | updateCell(temp/7+1, temp%7); // Update the previously selected cell |
363 | updateCell(row, col); // Update the selected cell | 363 | updateCell(row, col); // Update the selected cell |
364 | // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); | 364 | // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); |
365 | emit(tableClicked()); | 365 | emit(tableClicked()); |
366 | } | 366 | } |
@@ -370,34 +370,34 @@ KDateTable::setDate(const QDate& date_) | |||
370 | { | 370 | { |
371 | bool changed=false; | 371 | bool changed=false; |
372 | QDate temp; | 372 | QDate temp; |
373 | mMarkCurrent = false; | 373 | mMarkCurrent = false; |
374 | // ----- | 374 | // ----- |
375 | if(!date_.isValid()) | 375 | if(!date_.isValid()) |
376 | { | 376 | { |
377 | kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; | 377 | kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; |
378 | return false; | 378 | return false; |
379 | } | 379 | } |
380 | if(date!=date_) | 380 | if(date!=date_) |
381 | { | 381 | { |
382 | date=date_; | 382 | date=date_; |
383 | changed=true; | 383 | changed=true; |
384 | } | 384 | } |
385 | mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); | 385 | mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); |
386 | temp.setYMD(date.year(), date.month(), 1); | 386 | temp.setYMD(date.year(), date.month(), 1); |
387 | firstday=temp.dayOfWeek(); | 387 | firstday=temp.dayOfWeek(); |
388 | if(firstday==1) firstday=8; | 388 | if(firstday==1) firstday=8; |
389 | numdays=date.daysInMonth(); | 389 | numdays=date.daysInMonth(); |
390 | if(date.month()==1) | 390 | if(date.month()==1) |
391 | { // set to december of previous year | 391 | { // set to december of previous year |
392 | temp.setYMD(date.year()-1, 12, 1); | 392 | temp.setYMD(date.year()-1, 12, 1); |
393 | } else { // set to previous month | 393 | } else { // set to previous month |
394 | temp.setYMD(date.year(), date.month()-1, 1); | 394 | temp.setYMD(date.year(), date.month()-1, 1); |
395 | } | ||
396 | numDaysPrevMonth=temp.daysInMonth(); | ||
397 | if(changed) | ||
398 | { | ||
399 | repaintContents(false); | ||
400 | } | 395 | } |
401 | emit(dateChanged(date)); | 396 | numDaysPrevMonth=temp.daysInMonth(); |
402 | return true; | 397 | if(changed) |
398 | { | ||
399 | repaintContents(false); | ||
400 | } | ||
401 | emit(dateChanged(date)); | ||
402 | return true; | ||
403 | } | 403 | } |
@@ -407,3 +407,3 @@ KDateTable::getDate() const | |||
407 | { | 407 | { |
408 | return date; | 408 | return date; |
409 | } | 409 | } |
@@ -425,8 +425,8 @@ KDateTable::sizeHint() const | |||
425 | { | 425 | { |
426 | if(maxCell.height()>0 && maxCell.width()>0) | 426 | if(maxCell.height()>0 && maxCell.width()>0) |
427 | { | 427 | { |
428 | return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), | 428 | return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), |
429 | (maxCell.height()+4)*numRows()+2*frameWidth()); | 429 | (maxCell.height()+4)*numRows()+2*frameWidth()); |
430 | } else { | 430 | } else { |
431 | return QSize(-1, -1); | 431 | return QSize(-1, -1); |
432 | } | 432 | } |
@@ -436,32 +436,32 @@ KDateInternalMonthPicker::KDateInternalMonthPicker | |||
436 | (int fontsize, QWidget* parent, const char* name) | 436 | (int fontsize, QWidget* parent, const char* name) |
437 | : QGridView(parent, name), | 437 | : QGridView(parent, name), |
438 | result(0) // invalid | 438 | result(0) // invalid |
439 | { | 439 | { |
440 | QRect rect; | 440 | QRect rect; |
441 | QFont font; | 441 | QFont font; |
442 | // ----- | 442 | // ----- |
443 | activeCol = -1; | 443 | activeCol = -1; |
444 | activeRow = -1; | 444 | activeRow = -1; |
445 | font=KGlobalSettings::generalFont(); | 445 | font=KGlobalSettings::generalFont(); |
446 | font.setPointSize(fontsize); | 446 | font.setPointSize(fontsize); |
447 | setFont(font); | 447 | setFont(font); |
448 | setHScrollBarMode(AlwaysOff); | 448 | setHScrollBarMode(AlwaysOff); |
449 | setVScrollBarMode(AlwaysOff); | 449 | setVScrollBarMode(AlwaysOff); |
450 | setFrameStyle(QFrame::NoFrame); | 450 | setFrameStyle(QFrame::NoFrame); |
451 | setNumRows(4); | 451 | setNumRows(4); |
452 | setNumCols(3); | 452 | setNumCols(3); |
453 | // enable to find drawing failures: | 453 | // enable to find drawing failures: |
454 | // setTableFlags(Tbl_clipCellPainting); | 454 | // setTableFlags(Tbl_clipCellPainting); |
455 | #if 0 | 455 | #if 0 |
456 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | 456 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker |
457 | #endif | 457 | #endif |
458 | // ----- find the preferred size | 458 | // ----- find the preferred size |
459 | // (this is slow, possibly, but unfortunatly it is needed here): | 459 | // (this is slow, possibly, but unfortunatly it is needed here): |
460 | QFontMetrics metrics(font); | 460 | QFontMetrics metrics(font); |
461 | for(int i=1; i <= 12; ++i) | 461 | for(int i=1; i <= 12; ++i) |
462 | { | 462 | { |
463 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); | 463 | rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); |
464 | if(max.width()<rect.width()) max.setWidth(rect.width()); | 464 | if(max.width()<rect.width()) max.setWidth(rect.width()); |
465 | if(max.height()<rect.height()) max.setHeight(rect.height()); | 465 | if(max.height()<rect.height()) max.setHeight(rect.height()); |
466 | } | 466 | } |
467 | 467 | ||
@@ -472,4 +472,4 @@ KDateInternalMonthPicker::sizeHint() const | |||
472 | { | 472 | { |
473 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | 473 | return QSize((max.width()+6)*numCols()+2*frameWidth(), |
474 | (max.height()+6)*numRows()+2*frameWidth()); | 474 | (max.height()+6)*numRows()+2*frameWidth()); |
475 | } | 475 | } |
@@ -479,3 +479,3 @@ KDateInternalMonthPicker::getResult() const | |||
479 | { | 479 | { |
480 | return result; | 480 | return result; |
481 | } | 481 | } |
@@ -485,3 +485,3 @@ KDateInternalMonthPicker::setupPainter(QPainter *p) | |||
485 | { | 485 | { |
486 | p->setPen(black); | 486 | p->setPen(black); |
487 | } | 487 | } |
@@ -491,4 +491,4 @@ KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) | |||
491 | { | 491 | { |
492 | setCellWidth(width()/3); | 492 | setCellWidth(width()/3); |
493 | setCellHeight(height()/4); | 493 | setCellHeight(height()/4); |
494 | } | 494 | } |
@@ -498,10 +498,10 @@ KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) | |||
498 | { | 498 | { |
499 | int index; | 499 | int index; |
500 | QString text; | 500 | QString text; |
501 | // ----- find the number of the cell: | 501 | // ----- find the number of the cell: |
502 | index=3*row+col+1; | 502 | index=3*row+col+1; |
503 | text=KGlobal::locale()->monthName(index, false); | 503 | text=KGlobal::locale()->monthName(index, false); |
504 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | 504 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); |
505 | if ( activeCol == col && activeRow == row ) | 505 | if ( activeCol == col && activeRow == row ) |
506 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | 506 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); |
507 | } | 507 | } |
@@ -511,24 +511,24 @@ KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) | |||
511 | { | 511 | { |
512 | if(!isEnabled() || e->button() != LeftButton) | 512 | if(!isEnabled() || e->button() != LeftButton) |
513 | { | 513 | { |
514 | KNotifyClient::beep(); | 514 | KNotifyClient::beep(); |
515 | return; | 515 | return; |
516 | } | ||
517 | // ----- | ||
518 | int row, col; | ||
519 | QPoint mouseCoord; | ||
520 | // ----- | ||
521 | mouseCoord = e->pos(); | ||
522 | row=rowAt(mouseCoord.y()); | ||
523 | col=columnAt(mouseCoord.x()); | ||
524 | |||
525 | if(row<0 || col<0) | ||
526 | { // the user clicked on the frame of the table | ||
527 | activeCol = -1; | ||
528 | activeRow = -1; | ||
529 | } else { | ||
530 | activeCol = col; | ||
531 | activeRow = row; | ||
532 | updateCell( row, col /*, false */ ); | ||
516 | } | 533 | } |
517 | // ----- | ||
518 | int row, col; | ||
519 | QPoint mouseCoord; | ||
520 | // ----- | ||
521 | mouseCoord = e->pos(); | ||
522 | row=rowAt(mouseCoord.y()); | ||
523 | col=columnAt(mouseCoord.x()); | ||
524 | |||
525 | if(row<0 || col<0) | ||
526 | { // the user clicked on the frame of the table | ||
527 | activeCol = -1; | ||
528 | activeRow = -1; | ||
529 | } else { | ||
530 | activeCol = col; | ||
531 | activeRow = row; | ||
532 | updateCell( row, col /*, false */ ); | ||
533 | } | ||
534 | } | 534 | } |
@@ -538,37 +538,37 @@ KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) | |||
538 | { | 538 | { |
539 | if (e->state() & LeftButton) | 539 | if (e->state() & LeftButton) |
540 | { | 540 | { |
541 | int row, col; | 541 | int row, col; |
542 | QPoint mouseCoord; | 542 | QPoint mouseCoord; |
543 | // ----- | 543 | // ----- |
544 | mouseCoord = e->pos(); | 544 | mouseCoord = e->pos(); |
545 | row=rowAt(mouseCoord.y()); | 545 | row=rowAt(mouseCoord.y()); |
546 | col=columnAt(mouseCoord.x()); | 546 | col=columnAt(mouseCoord.x()); |
547 | int tmpRow = -1, tmpCol = -1; | 547 | int tmpRow = -1, tmpCol = -1; |
548 | if(row<0 || col<0) | 548 | if(row<0 || col<0) |
549 | { // the user clicked on the frame of the table | 549 | { // the user clicked on the frame of the table |
550 | if ( activeCol > -1 ) | 550 | if ( activeCol > -1 ) |
551 | { | 551 | { |
552 | tmpRow = activeRow; | 552 | tmpRow = activeRow; |
553 | tmpCol = activeCol; | 553 | tmpCol = activeCol; |
554 | } | 554 | } |
555 | activeCol = -1; | 555 | activeCol = -1; |
556 | activeRow = -1; | 556 | activeRow = -1; |
557 | } else { | 557 | } else { |
558 | bool differentCell = (activeRow != row || activeCol != col); | 558 | bool differentCell = (activeRow != row || activeCol != col); |
559 | if ( activeCol > -1 && differentCell) | 559 | if ( activeCol > -1 && differentCell) |
560 | { | 560 | { |
561 | tmpRow = activeRow; | 561 | tmpRow = activeRow; |
562 | tmpCol = activeCol; | 562 | tmpCol = activeCol; |
563 | } | 563 | } |
564 | if ( differentCell) | 564 | if ( differentCell) |
565 | { | 565 | { |
566 | activeRow = row; | 566 | activeRow = row; |
567 | activeCol = col; | 567 | activeCol = col; |
568 | updateCell( row, col /*, false */ ); // mark the new active cell | 568 | updateCell( row, col /*, false */ ); // mark the new active cell |
569 | } | ||
569 | } | 570 | } |
571 | if ( tmpRow > -1 ) // repaint the former active cell | ||
572 | updateCell( tmpRow, tmpCol /*, true */ ); | ||
570 | } | 573 | } |
571 | if ( tmpRow > -1 ) // repaint the former active cell | ||
572 | updateCell( tmpRow, tmpCol /*, true */ ); | ||
573 | } | ||
574 | } | 574 | } |
@@ -578,20 +578,20 @@ KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e) | |||
578 | { | 578 | { |
579 | if(!isEnabled()) | 579 | if(!isEnabled()) |
580 | { | 580 | { |
581 | return; | 581 | return; |
582 | } | 582 | } |
583 | // ----- | 583 | // ----- |
584 | int row, col, pos; | 584 | int row, col, pos; |
585 | QPoint mouseCoord; | 585 | QPoint mouseCoord; |
586 | // ----- | 586 | // ----- |
587 | mouseCoord = e->pos(); | 587 | mouseCoord = e->pos(); |
588 | row=rowAt(mouseCoord.y()); | 588 | row=rowAt(mouseCoord.y()); |
589 | col=columnAt(mouseCoord.x()); | 589 | col=columnAt(mouseCoord.x()); |
590 | if(row<0 || col<0) | 590 | if(row<0 || col<0) |
591 | { // the user clicked on the frame of the table | 591 | { // the user clicked on the frame of the table |
592 | emit(closeMe(0)); | 592 | emit(closeMe(0)); |
593 | } | 593 | } |
594 | pos=3*row+col+1; | 594 | pos=3*row+col+1; |
595 | result=pos; | 595 | result=pos; |
596 | emit(closeMe(1)); | 596 | emit(closeMe(1)); |
597 | } | 597 | } |
@@ -602,18 +602,18 @@ KDateInternalYearSelector::KDateInternalYearSelector | |||
602 | (int fontsize, QWidget* parent, const char* name) | 602 | (int fontsize, QWidget* parent, const char* name) |
603 | : QLineEdit(parent, name), | 603 | : QLineEdit(parent, name), |
604 | val(new QIntValidator(this)), | 604 | val(new QIntValidator(this)), |
605 | result(0) | 605 | result(0) |
606 | { | 606 | { |
607 | QFont font; | 607 | QFont font; |
608 | // ----- | 608 | // ----- |
609 | font=KGlobalSettings::generalFont(); | 609 | font=KGlobalSettings::generalFont(); |
610 | font.setPointSize(fontsize); | 610 | font.setPointSize(fontsize); |
611 | setFont(font); | 611 | setFont(font); |
612 | #if 0 | 612 | #if 0 |
613 | setFrameStyle(QFrame::NoFrame); | 613 | setFrameStyle(QFrame::NoFrame); |
614 | #endif | 614 | #endif |
615 | // we have to respect the limits of QDate here, I fear: | 615 | // we have to respect the limits of QDate here, I fear: |
616 | val->setRange(0, 8000); | 616 | val->setRange(0, 8000); |
617 | setValidator(val); | 617 | setValidator(val); |
618 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); | 618 | connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot())); |
619 | } | 619 | } |
@@ -623,20 +623,20 @@ KDateInternalYearSelector::yearEnteredSlot() | |||
623 | { | 623 | { |
624 | bool ok; | 624 | bool ok; |
625 | int year; | 625 | int year; |
626 | QDate date; | 626 | QDate date; |
627 | // ----- check if this is a valid year: | 627 | // ----- check if this is a valid year: |
628 | year=text().toInt(&ok); | 628 | year=text().toInt(&ok); |
629 | if(!ok) | 629 | if(!ok) |
630 | { | 630 | { |
631 | KNotifyClient::beep(); | 631 | KNotifyClient::beep(); |
632 | return; | 632 | return; |
633 | } | 633 | } |
634 | date.setYMD(year, 1, 1); | 634 | date.setYMD(year, 1, 1); |
635 | if(!date.isValid()) | 635 | if(!date.isValid()) |
636 | { | 636 | { |
637 | KNotifyClient::beep(); | 637 | KNotifyClient::beep(); |
638 | return; | 638 | return; |
639 | } | 639 | } |
640 | result=year; | 640 | result=year; |
641 | emit(closeMe(1)); | 641 | emit(closeMe(1)); |
642 | } | 642 | } |
@@ -646,3 +646,3 @@ KDateInternalYearSelector::getYear() | |||
646 | { | 646 | { |
647 | return result; | 647 | return result; |
648 | } | 648 | } |
@@ -652,6 +652,6 @@ KDateInternalYearSelector::setYear(int year) | |||
652 | { | 652 | { |
653 | QString temp; | 653 | QString temp; |
654 | // ----- | 654 | // ----- |
655 | temp.setNum(year); | 655 | temp.setNum(year); |
656 | setText(temp); | 656 | setText(temp); |
657 | } | 657 | } |
@@ -659,8 +659,8 @@ KDateInternalYearSelector::setYear(int year) | |||
659 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) | 659 | KPopupFrame::KPopupFrame(QWidget* parent, const char* name) |
660 | : QFrame(parent, name, WType_Popup), | 660 | : QFrame(parent, name, WType_Popup), |
661 | result(0), // rejected | 661 | result(0), // rejected |
662 | main(0) | 662 | main(0) |
663 | { | 663 | { |
664 | setFrameStyle(QFrame::Box|QFrame::Raised); | 664 | setFrameStyle(QFrame::Box|QFrame::Raised); |
665 | setMidLineWidth(2); | 665 | setMidLineWidth(2); |
666 | } | 666 | } |
@@ -670,7 +670,7 @@ KPopupFrame::keyPressEvent(QKeyEvent* e) | |||
670 | { | 670 | { |
671 | if(e->key()==Key_Escape) | 671 | if(e->key()==Key_Escape) |
672 | { | 672 | { |
673 | result=0; // rejected | 673 | result=0; // rejected |
674 | qApp->exit_loop(); | 674 | qApp->exit_loop(); |
675 | } | 675 | } |
676 | } | 676 | } |
@@ -680,4 +680,4 @@ KPopupFrame::close(int r) | |||
680 | { | 680 | { |
681 | result=r; | 681 | result=r; |
682 | qApp->exit_loop(); | 682 | qApp->exit_loop(); |
683 | } | 683 | } |
@@ -687,7 +687,7 @@ KPopupFrame::setMainWidget(QWidget* m) | |||
687 | { | 687 | { |
688 | main=m; | 688 | main=m; |
689 | if(main!=0) | 689 | if(main!=0) |
690 | { | 690 | { |
691 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); | 691 | resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); |
692 | } | 692 | } |
693 | } | 693 | } |
@@ -697,7 +697,7 @@ KPopupFrame::resizeEvent(QResizeEvent*) | |||
697 | { | 697 | { |
698 | if(main!=0) | 698 | if(main!=0) |
699 | { | 699 | { |
700 | main->setGeometry(frameWidth(), frameWidth(), | 700 | main->setGeometry(frameWidth(), frameWidth(), |
701 | width()-2*frameWidth(), height()-2*frameWidth()); | 701 | width()-2*frameWidth(), height()-2*frameWidth()); |
702 | } | 702 | } |
703 | } | 703 | } |
@@ -707,20 +707,20 @@ KPopupFrame::popup(const QPoint &pos) | |||
707 | { | 707 | { |
708 | // Make sure the whole popup is visible. | 708 | // Make sure the whole popup is visible. |
709 | QRect d = QApplication::desktop()->frameGeometry(); | 709 | QRect d = QApplication::desktop()->frameGeometry(); |
710 | int x = pos.x(); | 710 | int x = pos.x(); |
711 | int y = pos.y(); | 711 | int y = pos.y(); |
712 | int w = width(); | 712 | int w = width(); |
713 | int h = height(); | 713 | int h = height(); |
714 | if (x+w > d.x()+d.width()) | 714 | if (x+w > d.x()+d.width()) |
715 | x = d.width() - w; | 715 | x = d.width() - w; |
716 | if (y+h > d.y()+d.height()) | 716 | if (y+h > d.y()+d.height()) |
717 | y = d.height() - h; | 717 | y = d.height() - h; |
718 | if (x < d.x()) | 718 | if (x < d.x()) |
719 | x = 0; | 719 | x = 0; |
720 | if (y < d.y()) | 720 | if (y < d.y()) |
721 | y = 0; | 721 | y = 0; |
722 | 722 | ||
723 | // Pop the thingy up. | 723 | // Pop the thingy up. |
724 | move(x, y); | 724 | move(x, y); |
725 | show(); | 725 | show(); |
726 | } | 726 | } |
@@ -730,7 +730,7 @@ KPopupFrame::exec(QPoint pos) | |||
730 | { | 730 | { |
731 | popup(pos); | 731 | popup(pos); |
732 | repaint(); | 732 | repaint(); |
733 | qApp->enter_loop(); | 733 | qApp->enter_loop(); |
734 | hide(); | 734 | hide(); |
735 | return result; | 735 | return result; |
736 | } | 736 | } |
@@ -740,3 +740,3 @@ KPopupFrame::exec(int x, int y) | |||
740 | { | 740 | { |
741 | return exec(QPoint(x, y)); | 741 | return exec(QPoint(x, y)); |
742 | } | 742 | } |
@@ -750 +750,166 @@ void KDateTable::virtual_hook( int, void* ) | |||
750 | //#include "kdatetbl.moc" | 750 | //#include "kdatetbl.moc" |
751 | |||
752 | |||
753 | KDateInternalWeekPicker::KDateInternalWeekPicker | ||
754 | (int fontsize, QWidget* parent, const char* name) | ||
755 | : QGridView(parent, name), | ||
756 | result(0) // invalid | ||
757 | { | ||
758 | QRect rect; | ||
759 | QFont font; | ||
760 | // ----- | ||
761 | activeCol = -1; | ||
762 | activeRow = -1; | ||
763 | font=KGlobalSettings::generalFont(); | ||
764 | font.setPointSize(fontsize); | ||
765 | setFont(font); | ||
766 | setHScrollBarMode(AlwaysOff); | ||
767 | setVScrollBarMode(AlwaysOff); | ||
768 | setFrameStyle(QFrame::NoFrame); | ||
769 | setNumRows(13); | ||
770 | setNumCols(4); | ||
771 | // enable to find drawing failures: | ||
772 | // setTableFlags(Tbl_clipCellPainting); | ||
773 | #if 0 | ||
774 | viewport()->setEraseColor(lightGray); // for consistency with the datepicker | ||
775 | #endif | ||
776 | // ----- find the preferred size | ||
777 | // (this is slow, possibly, but unfortunatly it is needed here): | ||
778 | QFontMetrics metrics(font); | ||
779 | for(int i=1; i <= 52; ++i) | ||
780 | { | ||
781 | rect=metrics.boundingRect(QString::number( i )); | ||
782 | if(max.width()<rect.width()) max.setWidth(rect.width()); | ||
783 | if(max.height()<rect.height()) max.setHeight(rect.height()); | ||
784 | } | ||
785 | |||
786 | } | ||
787 | |||
788 | QSize | ||
789 | KDateInternalWeekPicker::sizeHint() const | ||
790 | { | ||
791 | return QSize((max.width()+6)*numCols()+2*frameWidth(), | ||
792 | (max.height()+6)*numRows()+2*frameWidth()); | ||
793 | } | ||
794 | |||
795 | int | ||
796 | KDateInternalWeekPicker::getResult() const | ||
797 | { | ||
798 | return result; | ||
799 | } | ||
800 | |||
801 | void | ||
802 | KDateInternalWeekPicker::setupPainter(QPainter *p) | ||
803 | { | ||
804 | p->setPen(black); | ||
805 | } | ||
806 | |||
807 | void | ||
808 | KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) | ||
809 | { | ||
810 | setCellWidth(width()/4); | ||
811 | setCellHeight(height()/13); | ||
812 | } | ||
813 | |||
814 | void | ||
815 | KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) | ||
816 | { | ||
817 | int index; | ||
818 | QString text; | ||
819 | // ----- find the number of the cell: | ||
820 | index=4*row+col+1; | ||
821 | text=QString::number( index ); | ||
822 | painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); | ||
823 | if ( activeCol == col && activeRow == row ) | ||
824 | painter->drawRect( 0, 0, cellWidth(), cellHeight() ); | ||
825 | } | ||
826 | |||
827 | void | ||
828 | KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) | ||
829 | { | ||
830 | if(!isEnabled() || e->button() != LeftButton) | ||
831 | { | ||
832 | KNotifyClient::beep(); | ||
833 | return; | ||
834 | } | ||
835 | // ----- | ||
836 | int row, col; | ||
837 | QPoint mouseCoord; | ||
838 | // ----- | ||
839 | mouseCoord = e->pos(); | ||
840 | row=rowAt(mouseCoord.y()); | ||
841 | col=columnAt(mouseCoord.x()); | ||
842 | |||
843 | if(row<0 || col<0) | ||
844 | { // the user clicked on the frame of the table | ||
845 | activeCol = -1; | ||
846 | activeRow = -1; | ||
847 | } else { | ||
848 | activeCol = col; | ||
849 | activeRow = row; | ||
850 | updateCell( row, col /*, false */ ); | ||
851 | } | ||
852 | } | ||
853 | |||
854 | void | ||
855 | KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) | ||
856 | { | ||
857 | if (e->state() & LeftButton) | ||
858 | { | ||
859 | int row, col; | ||
860 | QPoint mouseCoord; | ||
861 | // ----- | ||
862 | mouseCoord = e->pos(); | ||
863 | row=rowAt(mouseCoord.y()); | ||
864 | col=columnAt(mouseCoord.x()); | ||
865 | int tmpRow = -1, tmpCol = -1; | ||
866 | if(row<0 || col<0) | ||
867 | { // the user clicked on the frame of the table | ||
868 | if ( activeCol > -1 ) | ||
869 | { | ||
870 | tmpRow = activeRow; | ||
871 | tmpCol = activeCol; | ||
872 | } | ||
873 | activeCol = -1; | ||
874 | activeRow = -1; | ||
875 | } else { | ||
876 | bool differentCell = (activeRow != row || activeCol != col); | ||
877 | if ( activeCol > -1 && differentCell) | ||
878 | { | ||
879 | tmpRow = activeRow; | ||
880 | tmpCol = activeCol; | ||
881 | } | ||
882 | if ( differentCell) | ||
883 | { | ||
884 | activeRow = row; | ||
885 | activeCol = col; | ||
886 | updateCell( row, col /*, false */ ); // mark the new active cell | ||
887 | } | ||
888 | } | ||
889 | if ( tmpRow > -1 ) // repaint the former active cell | ||
890 | updateCell( tmpRow, tmpCol /*, true */ ); | ||
891 | } | ||
892 | } | ||
893 | |||
894 | void | ||
895 | KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e) | ||
896 | { | ||
897 | if(!isEnabled()) | ||
898 | { | ||
899 | return; | ||
900 | } | ||
901 | // ----- | ||
902 | int row, col, pos; | ||
903 | QPoint mouseCoord; | ||
904 | // ----- | ||
905 | mouseCoord = e->pos(); | ||
906 | row=rowAt(mouseCoord.y()); | ||
907 | col=columnAt(mouseCoord.x()); | ||
908 | if(row<0 || col<0) | ||
909 | { // the user clicked on the frame of the table | ||
910 | emit(closeMe(0)); | ||
911 | } | ||
912 | pos=4*row+col+1; | ||
913 | result=pos; | ||
914 | emit(closeMe(1)); | ||
915 | } | ||
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: | |||
309 | #endif // KDATETBL_H | 309 | #endif // KDATETBL_H |
310 | class KDateInternalWeekPicker : public QGridView | ||
311 | { | ||
312 | Q_OBJECT | ||
313 | protected: | ||
314 | /** | ||
315 | * Store the month that has been clicked [1..12]. | ||
316 | */ | ||
317 | int result; | ||
318 | /** | ||
319 | * the cell under mouse cursor when LBM is pressed | ||
320 | */ | ||
321 | short int activeCol; | ||
322 | short int activeRow; | ||
323 | /** | ||
324 | * Contains the largest rectangle needed by the month names. | ||
325 | */ | ||
326 | QRect max; | ||
327 | signals: | ||
328 | /** | ||
329 | * This is send from the mouse click event handler. | ||
330 | */ | ||
331 | void closeMe(int); | ||
332 | public: | ||
333 | /** | ||
334 | * The constructor. | ||
335 | */ | ||
336 | KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0); | ||
337 | /** | ||
338 | * The size hint. | ||
339 | */ | ||
340 | QSize sizeHint() const; | ||
341 | /** | ||
342 | * Return the result. 0 means no selection (reject()), 1..12 are the | ||
343 | * months. | ||
344 | */ | ||
345 | int getResult() const; | ||
346 | protected: | ||
347 | /** | ||
348 | * Set up the painter. | ||
349 | */ | ||
350 | void setupPainter(QPainter *p); | ||
351 | /** | ||
352 | * The resize event. | ||
353 | */ | ||
354 | void viewportResizeEvent(QResizeEvent*); | ||
355 | /** | ||
356 | * Paint a cell. This simply draws the month names in it. | ||
357 | */ | ||
358 | virtual void paintCell(QPainter* painter, int row, int col); | ||
359 | /** | ||
360 | * Catch mouse click and move events to paint a rectangle around the item. | ||
361 | */ | ||
362 | void contentsMousePressEvent(QMouseEvent *e); | ||
363 | void contentsMouseMoveEvent(QMouseEvent *e); | ||
364 | /** | ||
365 | * Emit monthSelected(int) when a cell has been released. | ||
366 | */ | ||
367 | void contentsMouseReleaseEvent(QMouseEvent *e); | ||
368 | |||
369 | private: | ||
370 | class KDateInternalMonthPrivate; | ||
371 | KDateInternalMonthPrivate *d; | ||
372 | }; | ||