summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp2
-rw-r--r--korganizer/navigatorbar.cpp5
-rw-r--r--libkdepim/kdatepicker.cpp7
-rw-r--r--microkde/kdatetbl.cpp36
-rw-r--r--microkde/kdatetbl.h4
-rw-r--r--microkde/kglobalsettings.cpp1
6 files changed, 32 insertions, 23 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 856f7db..468fd5b 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1937,130 +1937,130 @@ void MainWindow::importFile( QString fn, bool quick )
1937 result = QMessageBox::warning( this, "KO/Pi: Warning!", 1937 result = QMessageBox::warning( this, "KO/Pi: Warning!",
1938 mess, 1938 mess,
1939 "Import", "Cancel", 0, 1939 "Import", "Cancel", 0,
1940 0, 1 ); 1940 0, 1 );
1941 } 1941 }
1942 if ( result == 0 ) { 1942 if ( result == 0 ) {
1943 if ( mView->openCalendar( fn, true )) { 1943 if ( mView->openCalendar( fn, true )) {
1944 KOPrefs::instance()->mLastImportFile = fn; 1944 KOPrefs::instance()->mLastImportFile = fn;
1945 setCaption(i18n("Imported file successfully")); 1945 setCaption(i18n("Imported file successfully"));
1946 } else { 1946 } else {
1947 setCaption(i18n("Error importing file")); 1947 setCaption(i18n("Error importing file"));
1948 } 1948 }
1949 } 1949 }
1950} 1950}
1951 1951
1952void MainWindow::importIcal() 1952void MainWindow::importIcal()
1953{ 1953{
1954 1954
1955 QString fn =KOPrefs::instance()->mLastImportFile; 1955 QString fn =KOPrefs::instance()->mLastImportFile;
1956 1956
1957 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 1957 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
1958 if ( fn == "" ) 1958 if ( fn == "" )
1959 return; 1959 return;
1960 importFile( fn, true ); 1960 importFile( fn, true );
1961 1961
1962} 1962}
1963 1963
1964void MainWindow::exportVCalendar() 1964void MainWindow::exportVCalendar()
1965{ 1965{
1966 QString fn = KOPrefs::instance()->mLastVcalFile; 1966 QString fn = KOPrefs::instance()->mLastVcalFile;
1967 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 1967 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
1968 if ( fn == "" ) 1968 if ( fn == "" )
1969 return; 1969 return;
1970 QFileInfo info; 1970 QFileInfo info;
1971 info.setFile( fn ); 1971 info.setFile( fn );
1972 QString mes; 1972 QString mes;
1973 bool createbup = true; 1973 bool createbup = true;
1974 if ( info. exists() ) { 1974 if ( info. exists() ) {
1975 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 1975 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
1976 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 1976 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
1977 i18n("Overwrite!"), i18n("Cancel"), 0, 1977 i18n("Overwrite!"), i18n("Cancel"), 0,
1978 0, 1 ); 1978 0, 1 );
1979 if ( result != 0 ) { 1979 if ( result != 0 ) {
1980 createbup = false; 1980 createbup = false;
1981 } 1981 }
1982 } 1982 }
1983 if ( createbup ) { 1983 if ( createbup ) {
1984 if ( mView->exportVCalendar( fn ) ) { 1984 if ( mView->exportVCalendar( fn ) ) {
1985 KOPrefs::instance()->mLastVcalFile = fn; 1985 KOPrefs::instance()->mLastVcalFile = fn;
1986 if ( fn.length() > 20 ) 1986 if ( fn.length() > 20 )
1987 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 1987 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
1988 else 1988 else
1989 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 1989 mes = i18n("KO/Pi:Exported to %1").arg(fn );
1990 setCaption(mes); 1990 setCaption(mes);
1991 } 1991 }
1992 } 1992 }
1993 1993
1994} 1994}
1995 1995
1996void MainWindow::syncFileRequest() 1996void MainWindow::syncFileRequest()
1997{ 1997{
1998 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 1998 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
1999 mSyncManager->slotSyncMenu( 999 ); 1999 mSyncManager->slotSyncMenu( 999 );
2000 } 2000 }
2001 save(); 2001 save();
2002} 2002}
2003void MainWindow::getFile( bool success ) 2003void MainWindow::getFile( bool success )
2004{ 2004{
2005 if ( ! success ) { 2005 if ( ! success ) {
2006 setCaption( i18n("Error receiving file. Nothing changed!") ); 2006 setCaption( i18n("Error receiving file. Nothing changed!") );
2007 return; 2007 return;
2008 } 2008 }
2009 mView->openCalendar( defaultFileName() ); 2009 mView->openCalendar( defaultFileName() );
2010 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2010 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2011 mSyncManager->slotSyncMenu( 999 ); 2011 mSyncManager->slotSyncMenu( 999 );
2012 } 2012 }
2013 setCaption( i18n("Pi-Sync successful!") ); 2013 setCaption( i18n("Pi-Sync successful!") );
2014} 2014}
2015 2015
2016void MainWindow::printSel( ) 2016void MainWindow::printSel( )
2017{ 2017{
2018 mView->viewManager()->agendaView()->agenda()->printSelection(); 2018 mView->viewManager()->agendaView()->agenda()->printSelection();
2019} 2019}
2020 2020
2021void MainWindow::printCal() 2021void MainWindow::printCal()
2022{ 2022{
2023 mView->print();//mCp->showDialog(); 2023 mView->print();//mCp->showDialog();
2024} 2024}
2025 2025
2026 2026
2027#include "libkdepim/kdatepicker.h" 2027#include "libkdepim/kdatepicker.h"
2028#include <kdatetbl.h> 2028#include <kdatetbl.h>
2029void MainWindow::weekAction() 2029void MainWindow::weekAction()
2030{ 2030{
2031 int month; 2031 int month;
2032 KPopupFrame* popup = new KPopupFrame(this); 2032 KPopupFrame* popup = new KPopupFrame(this);
2033 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(10, popup); 2033 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(popup);
2034 // ----- 2034 // -----
2035 picker->resize(picker->sizeHint()); 2035 picker->resize(picker->sizeHint());
2036 popup->setMainWidget(picker); 2036 popup->setMainWidget(picker);
2037 picker->setFocus(); 2037 picker->setFocus();
2038 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 2038 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
2039 int x = 0; 2039 int x = 0;
2040 int y = iconToolBar->height(); 2040 int y = iconToolBar->height();
2041 int dX = 0; 2041 int dX = 0;
2042 int dY = 0; 2042 int dY = 0;
2043 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 2043 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
2044 if ( iconToolBar->y() > height()/2 ) { 2044 if ( iconToolBar->y() > height()/2 ) {
2045 dY = picker->sizeHint().height()+8; 2045 dY = picker->sizeHint().height()+8;
2046 y = 0; 2046 y = 0;
2047 } 2047 }
2048 } else { 2048 } else {
2049 if ( iconToolBar->x() > width()/2 ) { // right side 2049 if ( iconToolBar->x() > width()/2 ) { // right side
2050 x=0; 2050 x=0;
2051 dX= picker->sizeHint().width()+8; 2051 dX= picker->sizeHint().width()+8;
2052 y = 0; 2052 y = 0;
2053 } else { 2053 } else {
2054 x= iconToolBar->width(); 2054 x= iconToolBar->width();
2055 y = 0; 2055 y = 0;
2056 } 2056 }
2057 } 2057 }
2058 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() ); 2058 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() );
2059 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY)))) 2059 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY))))
2060 { 2060 {
2061 month = picker->getResult(); 2061 month = picker->getResult();
2062 emit selectWeek ( month ); 2062 emit selectWeek ( month );
2063 //qDebug("weekSelected %d ", month); 2063 //qDebug("weekSelected %d ", month);
2064 } 2064 }
2065 delete popup; 2065 delete popup;
2066} 2066}
diff --git a/korganizer/navigatorbar.cpp b/korganizer/navigatorbar.cpp
index 4a31c77..2b8fd4f 100644
--- a/korganizer/navigatorbar.cpp
+++ b/korganizer/navigatorbar.cpp
@@ -75,129 +75,126 @@ NavigatorBar::NavigatorBar( const QDate & date, QWidget *parent, const char *nam
75#endif 75#endif
76 if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 ) 76 if ( QString ( name ) == QString("useBigPixmaps") && QApplication::desktop()->width() > 320 )
77 isDesktop = true; 77 isDesktop = true;
78 // Create backward navigation buttons 78 // Create backward navigation buttons
79 mPrevYear = new QPushButton( mCtrlFrame ); 79 mPrevYear = new QPushButton( mCtrlFrame );
80 mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) ); 80 mPrevYear->setPixmap( SmallIcon( isDesktop ? "2leftarrowB" : "2leftarrow" ) );
81 QToolTip::add( mPrevYear, i18n("Previous Year") ); 81 QToolTip::add( mPrevYear, i18n("Previous Year") );
82 82
83 mPrevMonth = new QPushButton( mCtrlFrame ); 83 mPrevMonth = new QPushButton( mCtrlFrame );
84 mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") ); 84 mPrevMonth->setPixmap( SmallIcon( isDesktop ? "1leftarrowB" : "1leftarrow") );
85 QToolTip::add( mPrevMonth, i18n("Previous Month") ); 85 QToolTip::add( mPrevMonth, i18n("Previous Month") );
86 86
87 // Create forward navigation buttons 87 // Create forward navigation buttons
88 mNextMonth = new QPushButton( mCtrlFrame ); 88 mNextMonth = new QPushButton( mCtrlFrame );
89 mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") ); 89 mNextMonth->setPixmap( SmallIcon( isDesktop ? "1rightarrowB" : "1rightarrow") );
90 QToolTip::add( mNextMonth, i18n("Next Month") ); 90 QToolTip::add( mNextMonth, i18n("Next Month") );
91 91
92 mNextYear = new QPushButton( mCtrlFrame ); 92 mNextYear = new QPushButton( mCtrlFrame );
93 mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") ); 93 mNextYear->setPixmap( SmallIcon( isDesktop ? "2rightarrowB": "2rightarrow") );
94 QToolTip::add( mNextYear, i18n("Next Year") ); 94 QToolTip::add( mNextYear, i18n("Next Year") );
95 mSelectMonth = new QPushButton( mCtrlFrame ); 95 mSelectMonth = new QPushButton( mCtrlFrame );
96 // Create month name label 96 // Create month name label
97 //selectMonth->setFont( tfont ); 97 //selectMonth->setFont( tfont );
98 // selectMonth->setAlignment( AlignCenter ); 98 // selectMonth->setAlignment( AlignCenter );
99 //mDateLabel = new QLabel( selectMonth ); 99 //mDateLabel = new QLabel( selectMonth );
100 //mDateLabel->setFont( tfont ); 100 //mDateLabel->setFont( tfont );
101 //mDateLabel->setAlignment( AlignCenter ); 101 //mDateLabel->setAlignment( AlignCenter );
102 if ( QString ( name ) == QString("useBigPixmaps") ) { 102 if ( QString ( name ) == QString("useBigPixmaps") ) {
103 mNextMonth->setFlat( true); 103 mNextMonth->setFlat( true);
104 mNextYear->setFlat( true); 104 mNextYear->setFlat( true);
105 mSelectMonth->setFlat( true); 105 mSelectMonth->setFlat( true);
106 mPrevYear->setFlat( true); 106 mPrevYear->setFlat( true);
107 mPrevMonth->setFlat( true); 107 mPrevMonth->setFlat( true);
108 } 108 }
109 mSelectMonth->setFont( tfont ); 109 mSelectMonth->setFont( tfont );
110 // Set minimum width to width of widest month name label 110 // Set minimum width to width of widest month name label
111 int i; 111 int i;
112 int maxwidth = 0; 112 int maxwidth = 0;
113 QFontMetrics fm ( mSelectMonth->font() ); 113 QFontMetrics fm ( mSelectMonth->font() );
114 int width = fm.width("September '00" ); 114 int width = fm.width("September '00" );
115// for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date); 115// for( i = 1; i <= KOGlobals::self()->calendarSystem()->monthsInYear(date);
116// ++i ) { 116// ++i ) {
117// //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i, 117// //int width = fm.width( KOGlobals::self()->calendarSystem()->monthName(i,
118// // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" ); 118// // KOGlobals::self()->calendarSystem()->year(date) ) + " 2000" );
119// int width = fm.width("September 2000" ); 119// int width = fm.width("September 2000" );
120// if ( width > maxwidth ) maxwidth = width; 120// if ( width > maxwidth ) maxwidth = width;
121// } 121// }
122 maxwidth = width+2; 122 maxwidth = width+2;
123 int size = fm.height()+2; 123 int size = fm.height()+2;
124 if ( QApplication::desktop()->width() >= 480 ) { 124 if ( QApplication::desktop()->width() >= 480 ) {
125 size += 6; 125 size += 6;
126 maxwidth+= 6; 126 maxwidth+= 6;
127 } 127 }
128 128
129 mSelectMonth->setFixedWidth( maxwidth ); 129 mSelectMonth->setFixedWidth( maxwidth );
130 mSelectMonth->setFixedHeight( size ); 130 mSelectMonth->setFixedHeight( size );
131 mPrevYear->setFixedHeight( size ); 131 mPrevYear->setFixedHeight( size );
132 mPrevMonth->setFixedHeight( size ); 132 mPrevMonth->setFixedHeight( size );
133 mNextMonth->setFixedHeight( size ); 133 mNextMonth->setFixedHeight( size );
134 mNextYear->setFixedHeight ( size ); 134 mNextYear->setFixedHeight ( size );
135 // set up control frame layout 135 // set up control frame layout
136 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 ); 136 QBoxLayout *ctrlLayout = new QHBoxLayout( mCtrlFrame, 1 );
137 ctrlLayout->addWidget( mPrevYear, 3 ); 137 ctrlLayout->addWidget( mPrevYear, 3 );
138 ctrlLayout->addWidget( mPrevMonth, 3 ); 138 ctrlLayout->addWidget( mPrevMonth, 3 );
139 //ctrlLayout->addStretch( 1 ); 139 //ctrlLayout->addStretch( 1 );
140 // ctrlLayout->addSpacing( 1 ); 140 // ctrlLayout->addSpacing( 1 );
141 // ctrlLayout->addWidget( mDateLabel ); 141 // ctrlLayout->addWidget( mDateLabel );
142 ctrlLayout->addWidget( mSelectMonth ); 142 ctrlLayout->addWidget( mSelectMonth );
143 // ctrlLayout->addSpacing( 1 ); 143 // ctrlLayout->addSpacing( 1 );
144 // ctrlLayout->addStretch( 1 ); 144 // ctrlLayout->addStretch( 1 );
145 ctrlLayout->addWidget( mNextMonth, 3 ); 145 ctrlLayout->addWidget( mNextMonth, 3 );
146 ctrlLayout->addWidget( mNextYear, 3 ); 146 ctrlLayout->addWidget( mNextYear, 3 );
147 147
148 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) ); 148 connect( mPrevYear, SIGNAL( clicked() ), SIGNAL( goPrevYear() ) );
149 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) ); 149 connect( mPrevMonth, SIGNAL( clicked() ), SIGNAL( goPrevMonth() ) );
150 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) ); 150 connect( mNextMonth, SIGNAL( clicked() ), SIGNAL( goNextMonth() ) );
151 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) ); 151 connect( mNextYear, SIGNAL( clicked() ), SIGNAL( goNextYear() ) );
152 connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) ); 152 connect( mSelectMonth, SIGNAL( clicked() ),SLOT( selectMonth() ) );
153 mPrevYear->setFocusPolicy(NoFocus); 153 mPrevYear->setFocusPolicy(NoFocus);
154 mPrevMonth->setFocusPolicy(NoFocus); 154 mPrevMonth->setFocusPolicy(NoFocus);
155 mNextMonth->setFocusPolicy(NoFocus); 155 mNextMonth->setFocusPolicy(NoFocus);
156 mNextYear->setFocusPolicy(NoFocus); 156 mNextYear->setFocusPolicy(NoFocus);
157 mSelectMonth->setFocusPolicy(NoFocus); 157 mSelectMonth->setFocusPolicy(NoFocus);
158 setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) ); 158 setSizePolicy( QSizePolicy ( QSizePolicy::Expanding ,QSizePolicy::Fixed ) );
159 159
160} 160}
161 161
162NavigatorBar::~NavigatorBar() 162NavigatorBar::~NavigatorBar()
163{ 163{
164} 164}
165 165
166void NavigatorBar::selectMonth() 166void NavigatorBar::selectMonth()
167{ 167{
168 168
169 int month; 169 int month;
170 KPopupFrame* popup = new KPopupFrame(this); 170 KPopupFrame* popup = new KPopupFrame(this);
171 int size = 12; 171 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
172 if ( QApplication::desktop()->width() >= 480 )
173 size = 18;
174 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(size, popup);
175 // ----- 172 // -----
176 picker->resize(picker->sizeHint()); 173 picker->resize(picker->sizeHint());
177 popup->setMainWidget(picker); 174 popup->setMainWidget(picker);
178 picker->setFocus(); 175 picker->setFocus();
179 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 176 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
180 if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height())))) 177 if(popup->exec(mSelectMonth->mapToGlobal(QPoint(0, mSelectMonth->height()))))
181 { 178 {
182 month = picker->getResult(); 179 month = picker->getResult();
183 emit monthSelected ( month ); 180 emit monthSelected ( month );
184 } else { 181 } else {
185 KNotifyClient::beep(); 182 KNotifyClient::beep();
186 } 183 }
187 delete popup; 184 delete popup;
188} 185}
189void NavigatorBar::selectDates( const KCal::DateList &dateList ) 186void NavigatorBar::selectDates( const KCal::DateList &dateList )
190{ 187{
191 if (dateList.count() > 0) { 188 if (dateList.count() > 0) {
192 QDate date = dateList.first(); 189 QDate date = dateList.first();
193 190
194 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem(); 191 const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
195 192
196 // compute the label at the top of the navigator 193 // compute the label at the top of the navigator
197 QString dtstr = i18n(calSys->monthName( date )) + " '" + 194 QString dtstr = i18n(calSys->monthName( date )) + " '" +
198 QString::number( calSys->year( date ) ).right(2); 195 QString::number( calSys->year( date ) ).right(2);
199 196
200 mSelectMonth->setText( dtstr ); 197 mSelectMonth->setText( dtstr );
201 } 198 }
202} 199}
203 200
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index 2be9c9e..d6e9b51 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -1,153 +1,156 @@
1/* -*- C++ -*- 1/* -*- C++ -*-
2 This file is part of the KDE libraries 2 This file is part of the KDE libraries
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
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include "kdatepicker.h" 21#include "kdatepicker.h"
22#include <kglobal.h> 22#include <kglobal.h>
23#include <kapplication.h> 23#include <kapplication.h>
24#include <klocale.h> 24#include <klocale.h>
25#include <kiconloader.h> 25#include <kiconloader.h>
26#include <qframe.h> 26#include <qframe.h>
27#include <qpainter.h> 27#include <qpainter.h>
28#include <qdialog.h> 28#include <qdialog.h>
29#include <qtoolbutton.h> 29#include <qtoolbutton.h>
30#include <qfont.h> 30#include <qfont.h>
31#include <qapplication.h> 31#include <qapplication.h>
32#include <qlineedit.h> 32#include <qlineedit.h>
33#include <qvalidator.h> 33#include <qvalidator.h>
34#include <kdebug.h> 34#include <kdebug.h>
35#include <knotifyclient.h> 35#include <knotifyclient.h>
36#include <kglobalsettings.h> 36#include <kglobalsettings.h>
37#include "kdatetbl.h" 37#include "kdatetbl.h"
38#include "kdateedit.h" 38#include "kdateedit.h"
39//#include "kdatepicker.moc" 39//#include "kdatepicker.moc"
40 40
41 41
42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
43 : QFrame(parent,name), 43 : QFrame(parent,name),
44 yearForward(new QToolButton(this)), 44 yearForward(new QToolButton(this)),
45 yearBackward(new QToolButton(this)), 45 yearBackward(new QToolButton(this)),
46 monthForward(new QToolButton(this)), 46 monthForward(new QToolButton(this)),
47 monthBackward(new QToolButton(this)), 47 monthBackward(new QToolButton(this)),
48 selectMonth(new QToolButton(this)), 48 selectMonth(new QToolButton(this)),
49 selectYear(new QToolButton(this)), 49 selectYear(new QToolButton(this)),
50 //line(new QLineEdit(this)), 50 //line(new QLineEdit(this)),
51 val(new KDateValidator(this)) 51 val(new KDateValidator(this))
52 //table(new KDateTable(this)), 52 //table(new KDateTable(this)),
53 //fontsize(1) 53 //fontsize(1)
54{ 54{
55 setFont ( KGlobalSettings::generalFont() ); 55 setFont ( KGlobalSettings::generalFont() );
56 table = new KDateTable(this); 56 table = new KDateTable(this);
57 setFontSize(font().pointSize()+2); 57 int add = 2;
58 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
59 add += 4;
60 setFontSize(font().pointSize()+add);
58 //line->setValidator(val); 61 //line->setValidator(val);
59 lineDate = new KDateEdit( this, "dateediipicker", true ); 62 lineDate = new KDateEdit( this, "dateediipicker", true );
60 yearForward->setPixmap(SmallIcon("2rightarrowB")); 63 yearForward->setPixmap(SmallIcon("2rightarrowB"));
61 yearBackward->setPixmap(SmallIcon("2leftarrowB")); 64 yearBackward->setPixmap(SmallIcon("2leftarrowB"));
62 monthForward->setPixmap(SmallIcon("1rightarrowB")); 65 monthForward->setPixmap(SmallIcon("1rightarrowB"));
63 monthBackward->setPixmap(SmallIcon("1leftarrowB")); 66 monthBackward->setPixmap(SmallIcon("1leftarrowB"));
64 setDate(dt); // set button texts 67 setDate(dt); // set button texts
65 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 68 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
66 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 69 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
67 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 70 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
68 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 71 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
69 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 72 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
70 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 73 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
71 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 74 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
72 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 75 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
73 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 76 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
74 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); 77 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
75 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 78 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
76 table->setFocus(); 79 table->setFocus();
77 80
78} 81}
79 82
80KDatePicker::~KDatePicker() 83KDatePicker::~KDatePicker()
81{ 84{
82} 85}
83 86
84void 87void
85KDatePicker::resizeEvent(QResizeEvent*) 88KDatePicker::resizeEvent(QResizeEvent*)
86{ 89{
87 QWidget *buttons[] = { 90 QWidget *buttons[] = {
88 yearBackward, 91 yearBackward,
89 monthBackward, 92 monthBackward,
90 selectMonth, 93 selectMonth,
91 selectYear, 94 selectYear,
92 monthForward, 95 monthForward,
93 yearForward }; 96 yearForward };
94 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 97 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
95 QSize sizes[NoOfButtons]; 98 QSize sizes[NoOfButtons];
96 int buttonHeight=0; 99 int buttonHeight=0;
97 int count; 100 int count;
98 int w; 101 int w;
99 int x=0; 102 int x=0;
100 // ----- calculate button row height: 103 // ----- calculate button row height:
101 for(count=0; count<NoOfButtons; ++count) { 104 for(count=0; count<NoOfButtons; ++count) {
102 int xS = buttons[count]->sizeHint().width(); 105 int xS = buttons[count]->sizeHint().width();
103 int yS = buttons[count]->sizeHint().height(); 106 int yS = buttons[count]->sizeHint().height();
104 if ( QApplication::desktop()->width() < 320 ) 107 if ( QApplication::desktop()->width() < 320 )
105 sizes[count]=QSize ( xS+4, yS ); 108 sizes[count]=QSize ( xS+4, yS );
106 else 109 else
107 sizes[count]=QSize ( xS+10, yS ); 110 sizes[count]=QSize ( xS+10, yS );
108 111
109 buttonHeight=QMAX(buttonHeight, sizes[count].height()); 112 buttonHeight=QMAX(buttonHeight, sizes[count].height());
110 } 113 }
111 buttonHeight += 10; 114 buttonHeight += 10;
112 // ----- calculate size of the month button: 115 // ----- calculate size of the month button:
113 w=0; 116 w=0;
114 for(count=0; count<NoOfButtons; ++count) { 117 for(count=0; count<NoOfButtons; ++count) {
115 if(buttons[count]!=selectMonth) 118 if(buttons[count]!=selectMonth)
116 { 119 {
117 w+=sizes[count].width(); 120 w+=sizes[count].width();
118 } else { 121 } else {
119 x=count; 122 x=count;
120 } 123 }
121 } 124 }
122 sizes[x].setWidth(width()-w); // stretch the month button 125 sizes[x].setWidth(width()-w); // stretch the month button
123 // ----- place the buttons: 126 // ----- place the buttons:
124 x=0; 127 x=0;
125 for(count=0; count<NoOfButtons; ++count) 128 for(count=0; count<NoOfButtons; ++count)
126 { 129 {
127 w=sizes[count].width(); 130 w=sizes[count].width();
128 buttons[count]->setGeometry(x, 0, w, buttonHeight); 131 buttons[count]->setGeometry(x, 0, w, buttonHeight);
129 x+=w; 132 x+=w;
130 } 133 }
131 // ----- place the line edit for direct input: 134 // ----- place the line edit for direct input:
132 sizes[0]=lineDate->sizeHint(); 135 sizes[0]=lineDate->sizeHint();
133 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); 136 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
134 lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); 137 lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
135 // ----- adjust the table: 138 // ----- adjust the table:
136 table->setGeometry(0, buttonHeight, width(), 139 table->setGeometry(0, buttonHeight, width(),
137 height()-buttonHeight-sizes[0].height()); 140 height()-buttonHeight-sizes[0].height());
138} 141}
139 142
140void 143void
141KDatePicker::dateChangedSlot(QDate date) 144KDatePicker::dateChangedSlot(QDate date)
142{ 145{
143 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); 146 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
144 //line->setText(KGlobal::locale()->formatDate(date, true)); 147 //line->setText(KGlobal::locale()->formatDate(date, true));
145 emit(dateChanged(date)); 148 emit(dateChanged(date));
146} 149}
147 150
148void 151void
149KDatePicker::tableClickedSlot() 152KDatePicker::tableClickedSlot()
150{ 153{
151 154
152 emit(dateSelected(table->getDate())); 155 emit(dateSelected(table->getDate()));
153 emit(tableClicked()); 156 emit(tableClicked());
@@ -190,193 +193,193 @@ KDatePicker::setDate(const QDate& date)
190 table->setDate(date); 193 table->setDate(date);
191 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); 194 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
192 temp.setNum(date.year()); 195 temp.setNum(date.year());
193 selectYear->setText(temp); 196 selectYear->setText(temp);
194 //line->setText(KGlobal::locale()->formatDate(date, true)); 197 //line->setText(KGlobal::locale()->formatDate(date, true));
195 lineDate->setDate( date ); 198 lineDate->setDate( date );
196 return true; 199 return true;
197 } else { 200 } else {
198 201
199 return false; 202 return false;
200 } 203 }
201 204
202 205
203} 206}
204 207
205void 208void
206KDatePicker::monthForwardClicked() 209KDatePicker::monthForwardClicked()
207{ 210{
208 QDate temp=table->getDate(); 211 QDate temp=table->getDate();
209 int day=temp.day(); 212 int day=temp.day();
210 // ----- 213 // -----
211 if(temp.month()==12) { 214 if(temp.month()==12) {
212 temp.setYMD(temp.year()+1, 1, 1); 215 temp.setYMD(temp.year()+1, 1, 1);
213 } else { 216 } else {
214 temp.setYMD(temp.year(), temp.month()+1, 1); 217 temp.setYMD(temp.year(), temp.month()+1, 1);
215 } 218 }
216 if(temp.daysInMonth()<day) { 219 if(temp.daysInMonth()<day) {
217 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 220 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
218 } else { 221 } else {
219 temp.setYMD(temp.year(), temp.month(), day); 222 temp.setYMD(temp.year(), temp.month(), day);
220 } 223 }
221 // assert(temp.isValid()); 224 // assert(temp.isValid());
222 setDate(temp); 225 setDate(temp);
223} 226}
224 227
225void 228void
226KDatePicker::monthBackwardClicked() 229KDatePicker::monthBackwardClicked()
227{ 230{
228 QDate temp=table->getDate(); 231 QDate temp=table->getDate();
229 int day=temp.day(); 232 int day=temp.day();
230 // ----- 233 // -----
231 if(temp.month()==1) 234 if(temp.month()==1)
232 { 235 {
233 temp.setYMD(temp.year()-1, 12, 1); 236 temp.setYMD(temp.year()-1, 12, 1);
234 } else { 237 } else {
235 temp.setYMD(temp.year(), temp.month()-1, 1); 238 temp.setYMD(temp.year(), temp.month()-1, 1);
236 } 239 }
237 if(temp.daysInMonth()<day) 240 if(temp.daysInMonth()<day)
238 { 241 {
239 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 242 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
240 } else { 243 } else {
241 temp.setYMD(temp.year(), temp.month(), day); 244 temp.setYMD(temp.year(), temp.month(), day);
242 } 245 }
243 // assert(temp.isValid()); 246 // assert(temp.isValid());
244 setDate(temp); 247 setDate(temp);
245} 248}
246 249
247void 250void
248KDatePicker::yearForwardClicked() 251KDatePicker::yearForwardClicked()
249{ 252{
250 QDate temp=table->getDate(); 253 QDate temp=table->getDate();
251 int day=temp.day(); 254 int day=temp.day();
252 // ----- 255 // -----
253 temp.setYMD(temp.year()+1, temp.month(), 1); 256 temp.setYMD(temp.year()+1, temp.month(), 1);
254 if(temp.daysInMonth()<day) 257 if(temp.daysInMonth()<day)
255 { 258 {
256 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 259 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
257 } else { 260 } else {
258 temp.setYMD(temp.year(), temp.month(), day); 261 temp.setYMD(temp.year(), temp.month(), day);
259 } 262 }
260 // assert(temp.isValid()); 263 // assert(temp.isValid());
261 setDate(temp); 264 setDate(temp);
262} 265}
263 266
264void 267void
265KDatePicker::yearBackwardClicked() 268KDatePicker::yearBackwardClicked()
266{ 269{
267 QDate temp=table->getDate(); 270 QDate temp=table->getDate();
268 int day=temp.day(); 271 int day=temp.day();
269 // ----- 272 // -----
270 temp.setYMD(temp.year()-1, temp.month(), 1); 273 temp.setYMD(temp.year()-1, temp.month(), 1);
271 if(temp.daysInMonth()<day) 274 if(temp.daysInMonth()<day)
272 { 275 {
273 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth()); 276 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
274 } else { 277 } else {
275 temp.setYMD(temp.year(), temp.month(), day); 278 temp.setYMD(temp.year(), temp.month(), day);
276 } 279 }
277 // assert(temp.isValid()); 280 // assert(temp.isValid());
278 setDate(temp); 281 setDate(temp);
279} 282}
280 283
281void 284void
282KDatePicker::selectMonthClicked() 285KDatePicker::selectMonthClicked()
283{ 286{
284 int month; 287 int month;
285 KPopupFrame* popup = new KPopupFrame(this); 288 KPopupFrame* popup = new KPopupFrame(this);
286 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup); 289 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(popup);
287 // ----- 290 // -----
288 picker->resize(picker->sizeHint()); 291 picker->resize(picker->sizeHint());
289 popup->setMainWidget(picker); 292 popup->setMainWidget(picker);
290 picker->setFocus(); 293 picker->setFocus();
291 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 294 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
292 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height())))) 295 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
293 { 296 {
294 QDate date; 297 QDate date;
295 int day; 298 int day;
296 // ----- 299 // -----
297 month=picker->getResult(); 300 month=picker->getResult();
298 date=table->getDate(); 301 date=table->getDate();
299 day=date.day(); 302 day=date.day();
300 // ----- construct a valid date in this month: 303 // ----- construct a valid date in this month:
301 date.setYMD(date.year(), month, 1); 304 date.setYMD(date.year(), month, 1);
302 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth())); 305 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
303 // ----- set this month 306 // ----- set this month
304 setDate(date); 307 setDate(date);
305 } else { 308 } else {
306 KNotifyClient::beep(); 309 KNotifyClient::beep();
307 } 310 }
308 delete popup; 311 delete popup;
309} 312}
310 313
311void 314void
312KDatePicker::selectYearClicked() 315KDatePicker::selectYearClicked()
313{ 316{
314 int year; 317 int year;
315 KPopupFrame* popup = new KPopupFrame(this); 318 KPopupFrame* popup = new KPopupFrame(this);
316 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup); 319 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup);
317 // ----- 320 // -----
318 picker->resize(picker->sizeHint()); 321 picker->resize(picker->sizeHint());
319 popup->setMainWidget(picker); 322 popup->setMainWidget(picker);
320 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 323 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
321 picker->setFocus(); 324 picker->setFocus();
322 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height())))) 325 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
323 { 326 {
324 QDate date; 327 QDate date;
325 int day; 328 int day;
326 // ----- 329 // -----
327 year=picker->getYear(); 330 year=picker->getYear();
328 date=table->getDate(); 331 date=table->getDate();
329 day=date.day(); 332 day=date.day();
330 // ----- construct a valid date in this month: 333 // ----- construct a valid date in this month:
331 date.setYMD(year, date.month(), 1); 334 date.setYMD(year, date.month(), 1);
332 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth())); 335 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
333 // ----- set this month 336 // ----- set this month
334 setDate(date); 337 setDate(date);
335 } else { 338 } else {
336 KNotifyClient::beep(); 339 KNotifyClient::beep();
337 } 340 }
338 delete popup; 341 delete popup;
339} 342}
340 343
341void 344void
342KDatePicker::setEnabled(bool enable) 345KDatePicker::setEnabled(bool enable)
343{ 346{
344 QWidget *widgets[]= { 347 QWidget *widgets[]= {
345 yearForward, yearBackward, monthForward, monthBackward, 348 yearForward, yearBackward, monthForward, monthBackward,
346 selectMonth, selectYear, 349 selectMonth, selectYear,
347 lineDate, table }; 350 lineDate, table };
348 const int Size=sizeof(widgets)/sizeof(widgets[0]); 351 const int Size=sizeof(widgets)/sizeof(widgets[0]);
349 int count; 352 int count;
350 // ----- 353 // -----
351 for(count=0; count<Size; ++count) 354 for(count=0; count<Size; ++count)
352 { 355 {
353 widgets[count]->setEnabled(enable); 356 widgets[count]->setEnabled(enable);
354 } 357 }
355} 358}
356 359
357void 360void
358KDatePicker::lineEnterPressed() 361KDatePicker::lineEnterPressed()
359{ 362{
360 QDate temp; 363 QDate temp;
361 // ----- 364 // -----
362 temp = lineDate->date(); 365 temp = lineDate->date();
363 //if(val->date(line->text(), temp)==QValidator::Acceptable) 366 //if(val->date(line->text(), temp)==QValidator::Acceptable)
364 //{ 367 //{
365 emit(dateEntered(temp)); 368 emit(dateEntered(temp));
366 setDate(temp); 369 setDate(temp);
367 // } else { 370 // } else {
368// KNotifyClient::beep(); 371// KNotifyClient::beep();
369// } 372// }
370} 373}
371 374
372QSize 375QSize
373KDatePicker::sizeHint() const 376KDatePicker::sizeHint() const
374{ 377{
375 QSize tableSize=table->sizeHint(); 378 QSize tableSize=table->sizeHint();
376 QWidget *buttons[]={ 379 QWidget *buttons[]={
377 yearBackward, 380 yearBackward,
378 monthBackward, 381 monthBackward,
379 selectMonth, 382 selectMonth,
380 selectYear, 383 selectYear,
381 monthForward, 384 monthForward,
382 yearForward }; 385 yearForward };
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index e827412..990cfb9 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -1,552 +1,556 @@
1/* -*- C++ -*- 1/* -*- C++ -*-
2 This file is part of the KDE libraries 2 This file is part of the KDE libraries
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
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/////////////////// KDateTable widget class ////////////////////// 21/////////////////// KDateTable widget class //////////////////////
22// 22//
23// Copyright (C) 1997 Tim D. Gilman 23// Copyright (C) 1997 Tim D. Gilman
24// (C) 1998-2001 Mirko Boehm 24// (C) 1998-2001 Mirko Boehm
25// Written using Qt (http://www.troll.no) for the 25// Written using Qt (http://www.troll.no) for the
26// KDE project (http://www.kde.org) 26// KDE project (http://www.kde.org)
27// 27//
28// This is a support class for the KDatePicker class. It just 28// This is a support class for the KDatePicker class. It just
29// draws the calender table without titles, but could theoretically 29// draws the calender table without titles, but could theoretically
30// be used as a standalone. 30// be used as a standalone.
31// 31//
32// When a date is selected by the user, it emits a signal: 32// When a date is selected by the user, it emits a signal:
33// dateSelected(QDate) 33// dateSelected(QDate)
34 34
35#include <kglobal.h> 35#include <kglobal.h>
36#include <kglobalsettings.h> 36#include <kglobalsettings.h>
37#include <kapplication.h> 37#include <kapplication.h>
38#include <klocale.h> 38#include <klocale.h>
39#include <kdebug.h> 39#include <kdebug.h>
40#include <knotifyclient.h> 40#include <knotifyclient.h>
41#include "kdatetbl.h" 41#include "kdatetbl.h"
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qstring.h> 43#include <qstring.h>
44#include <qpen.h> 44#include <qpen.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#include <qdialog.h> 46#include <qdialog.h>
47#include <assert.h> 47#include <assert.h>
48#include <qapplication.h> 48#include <qapplication.h>
49 49
50KDateValidator::KDateValidator(QWidget* parent, const char* name) 50KDateValidator::KDateValidator(QWidget* parent, const char* name)
51 : QValidator(parent, name) 51 : QValidator(parent, name)
52{ 52{
53} 53}
54 54
55QValidator::State 55QValidator::State
56KDateValidator::validate(QString& text, int&) const 56KDateValidator::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}
62 62
63QValidator::State 63QValidator::State
64KDateValidator::date(const QString& text, QDate& d) const 64KDateValidator::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}
74 74
75void 75void
76KDateValidator::fixup( QString& ) const 76KDateValidator::fixup( QString& ) const
77{ 77{
78 78
79} 79}
80 80
81KDateTable::KDateTable(QWidget *parent, QDate date_, const char* name, WFlags f) 81KDateTable::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 setFont( KGlobalSettings::generalFont() );
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}
101 101
102void 102void
103KDateTable::paintCell(QPainter *painter, int row, int col) 103KDateTable::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=font();
114 // ----- 114 // -----
115 font.setPointSize(fontsize);
116 if(row==0) 115 if(row==0)
117 { // we are drawing the headline 116 { // we are drawing the headline
118 font.setBold(true); 117 _font.setBold(true);
119 painter->setFont(font); 118 painter->setFont(_font);
120 bool normalday = true; 119 bool normalday = true;
121 QString daystr; 120 QString daystr;
122 if (KGlobal::locale()->weekStartsMonday()) 121 if (KGlobal::locale()->weekStartsMonday())
123 { 122 {
124 daystr = KGlobal::locale()->weekDayName(col+1, true); 123 daystr = KGlobal::locale()->weekDayName(col+1, true);
125 if (col == 5 || col == 6) 124 if (col == 5 || col == 6)
126 normalday = false; 125 normalday = false;
127 } else { 126 } else {
128 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true); 127 daystr = KGlobal::locale()->weekDayName(col==0? 7 : col, true);
129 if (col == 0 || col == 6) 128 if (col == 0 || col == 6)
130 normalday = false; 129 normalday = false;
131 } 130 }
132 if (!normalday) 131 if (!normalday)
133 { 132 {
134 painter->setPen(QColor(220,245,255)); 133 painter->setPen(QColor(220,245,255));
135 painter->setBrush(brushLightblue); 134 painter->setBrush(brushLightblue);
136 painter->drawRect(0, 0, w, h); 135 painter->drawRect(0, 0, w, h);
137 painter->setPen(blue); 136 painter->setPen(blue);
138 } else { 137 } else {
139 painter->setPen(blue); 138 painter->setPen(blue);
140 painter->setBrush(brushBlue); 139 painter->setBrush(brushBlue);
141 painter->drawRect(0, 0, w, h); 140 painter->drawRect(0, 0, w, h);
142 painter->setPen(white); 141 painter->setPen(white);
143 } 142 }
144 painter->drawText(0, 0, w, h-1, AlignCenter, 143 painter->drawText(0, 0, w, h-1, AlignCenter,
145 daystr, -1, &rect); 144 daystr, -1, &rect);
146 painter->setPen(black); 145 painter->setPen(black);
147 painter->moveTo(0, h-1); 146 painter->moveTo(0, h-1);
148 painter->lineTo(w-1, h-1); 147 painter->lineTo(w-1, h-1);
149 // ----- draw the weekday: 148 // ----- draw the weekday:
150 } else { 149 } else {
151 painter->setFont(font); 150 painter->setFont(_font);
152 pos=7*(row-1)+col; 151 pos=7*(row-1)+col;
153 if (KGlobal::locale()->weekStartsMonday()) 152 if (KGlobal::locale()->weekStartsMonday())
154 pos++; 153 pos++;
155 if(pos<firstday || (firstday+numdays<=pos)) 154 if(pos<firstday || (firstday+numdays<=pos))
156 { // we are either 155 { // we are either
157 // ° painting a day of the previous month or 156 // ° painting a day of the previous month or
158 // ° painting a day of the following month 157 // ° painting a day of the following month
159 if(pos<firstday) 158 if(pos<firstday)
160 { // previous month 159 { // previous month
161 text.setNum(numDaysPrevMonth+pos-firstday+1); 160 text.setNum(numDaysPrevMonth+pos-firstday+1);
162 } else { // following month 161 } else { // following month
163 text.setNum(pos-firstday-numdays+1); 162 text.setNum(pos-firstday-numdays+1);
164 } 163 }
165 painter->setPen(gray); 164 painter->setPen(gray);
166 } else { // paint a day of the current month 165 } else { // paint a day of the current month
167 text.setNum(pos-firstday+1); 166 text.setNum(pos-firstday+1);
168 painter->setPen(black); 167 painter->setPen(black);
169 } 168 }
170 169
171 pen=painter->pen(); 170 pen=painter->pen();
172 if(firstday+date.day()-1==pos) 171 if(firstday+date.day()-1==pos)
173 { 172 {
174 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 173 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
175 painter->setPen(green); 174 painter->setPen(green);
176 else 175 else
177 painter->setPen(red); 176 painter->setPen(red);
178 if(hasFocus()) 177 if(hasFocus())
179 { 178 {
180 painter->setBrush(darkRed); 179 painter->setBrush(darkRed);
181 pen=white; 180 pen=white;
182 } else { 181 } else {
183 painter->setBrush(darkGray); 182 painter->setBrush(darkGray);
184 pen=white; 183 pen=white;
185 } 184 }
186 } else { 185 } else {
187 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos) 186 if(mMarkCurrent && firstday+QDate::currentDate().day()-1==pos)
188 { 187 {
189 painter->setPen(green); 188 painter->setPen(green);
190 painter->setBrush(darkGreen); 189 painter->setBrush(darkGreen);
191 pen=white; 190 pen=white;
192 } else { 191 } else {
193 painter->setBrush(QColor(220,245,255)); 192 painter->setBrush(QColor(220,245,255));
194 painter->setPen(QColor(220,245,255)); 193 painter->setPen(QColor(220,245,255));
195 } 194 }
196 } 195 }
197 painter->drawRect(0, 0, w, h); 196 painter->drawRect(0, 0, w, h);
198 painter->setPen(pen); 197 painter->setPen(pen);
199 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect); 198 painter->drawText(0, 0, w, h, AlignCenter, text, -1, &rect);
200 } 199 }
201 /* 200 /*
202 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width()); 201 if(rect.width()>maxCell.width()) maxCell.setWidth(rect.width());
203 if(rect.height()>maxCell.height()) { 202 if(rect.height()>maxCell.height()) {
204 maxCell.setHeight(rect.height()); 203 maxCell.setHeight(rect.height());
205 } 204 }
206 */ 205 */
207} 206}
208 207
209void 208void
210KDateTable::keyPressEvent( QKeyEvent *e ) 209KDateTable::keyPressEvent( QKeyEvent *e )
211{ 210{
212 /* 211 /*
213 // not working properly 212 // not working properly
214 if ( e->key() == Qt::Key_Prior ) { 213 if ( e->key() == Qt::Key_Prior ) {
215 if ( date.month() == 1 ) { 214 if ( date.month() == 1 ) {
216 KNotifyClient::beep(); 215 KNotifyClient::beep();
217 return; 216 return;
218 } 217 }
219 int day = date.day(); 218 int day = date.day();
220 if ( day > 27 ) 219 if ( day > 27 )
221 while ( !QDate::isValid( date.year(), date.month()-1, day ) ) 220 while ( !QDate::isValid( date.year(), date.month()-1, day ) )
222 day--; 221 day--;
223 setDate(QDate(date.year(), date.month()-1, day)); 222 setDate(QDate(date.year(), date.month()-1, day));
224 return; 223 return;
225 } 224 }
226 if ( e->key() == Qt::Key_Next ) { 225 if ( e->key() == Qt::Key_Next ) {
227 if ( date.month() == 12 ) { 226 if ( date.month() == 12 ) {
228 KNotifyClient::beep(); 227 KNotifyClient::beep();
229 return; 228 return;
230 } 229 }
231 int day = date.day(); 230 int day = date.day();
232 if ( day > 27 ) 231 if ( day > 27 )
233 while ( !QDate::isValid( date.year(), date.month()+1, day ) ) 232 while ( !QDate::isValid( date.year(), date.month()+1, day ) )
234 day--; 233 day--;
235 setDate(QDate(date.year(), date.month()+1, day)); 234 setDate(QDate(date.year(), date.month()+1, day));
236 return; 235 return;
237 } 236 }
238 */ 237 */
239 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 238 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
240 239
241 int temp=firstday+date.day()-dayoff; 240 int temp=firstday+date.day()-dayoff;
242 int pos = temp; 241 int pos = temp;
243 bool irgnore = true; 242 bool irgnore = true;
244 if ( e->state() != Qt::ControlButton ) { 243 if ( e->state() != Qt::ControlButton ) {
245 if ( e->key() == Qt::Key_Up ) { 244 if ( e->key() == Qt::Key_Up ) {
246 pos -= 7; 245 pos -= 7;
247 irgnore = false; 246 irgnore = false;
248 } 247 }
249 if ( e->key() == Qt::Key_Down ) { 248 if ( e->key() == Qt::Key_Down ) {
250 pos += 7; 249 pos += 7;
251 irgnore = false; 250 irgnore = false;
252 } 251 }
253 if ( e->key() == Qt::Key_Left ) { 252 if ( e->key() == Qt::Key_Left ) {
254 pos--; 253 pos--;
255 irgnore = false; 254 irgnore = false;
256 } 255 }
257 if ( e->key() == Qt::Key_Right ) { 256 if ( e->key() == Qt::Key_Right ) {
258 pos++; 257 pos++;
259 irgnore = false; 258 irgnore = false;
260 } 259 }
261 } 260 }
262 if ( irgnore ) 261 if ( irgnore )
263 e->ignore(); 262 e->ignore();
264 263
265 if(pos+dayoff<=firstday) 264 if(pos+dayoff<=firstday)
266 { // this day is in the previous month 265 { // this day is in the previous month
267 KNotifyClient::beep(); 266 KNotifyClient::beep();
268 return; 267 return;
269 } 268 }
270 if(firstday+numdays<pos+dayoff) 269 if(firstday+numdays<pos+dayoff)
271 { // this date is in the next month 270 { // this date is in the next month
272 KNotifyClient::beep(i18n( "Month not long enough" )); 271 KNotifyClient::beep(i18n( "Month not long enough" ));
273 return; 272 return;
274 } 273 }
275 274
276 if ( pos == temp ) 275 if ( pos == temp )
277 return; 276 return;
278 277
279 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff)); 278 setDate(QDate(date.year(), date.month(), pos-firstday+dayoff));
280 updateCell(temp/7+1, temp%7); // Update the previously selected cell 279 updateCell(temp/7+1, temp%7); // Update the previously selected cell
281 updateCell(pos/7+1, pos%7); // Update the selected cell 280 updateCell(pos/7+1, pos%7); // Update the selected cell
282 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 281 assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
283 282
284 283
285} 284}
286 285
287void 286void
288KDateTable::viewportResizeEvent(QResizeEvent * e) 287KDateTable::viewportResizeEvent(QResizeEvent * e)
289{ 288{
290 QGridView::viewportResizeEvent(e); 289 QGridView::viewportResizeEvent(e);
291 290
292 setCellWidth(viewport()->width()/7); 291 setCellWidth(viewport()->width()/7);
293 setCellHeight(viewport()->height()/7); 292 setCellHeight(viewport()->height()/7);
294} 293}
295 294
296void 295void
297KDateTable::setFontSize(int size) 296KDateTable::setFontSize(int size)
298{ 297{
299 int count; 298 int count;
300 QRect rect; 299 QRect rect;
301 // ----- store rectangles: 300 // ----- store rectangles:
302 fontsize=size; 301 fontsize=size;
303 QFont font = KGlobalSettings::generalFont(); 302 QFont _font = font();
304 font.setPointSize(fontsize); 303 _font.setPointSize(fontsize);
305 font.setBold( true ); 304 setFont( _font );
306 QFontMetrics metrics(font); 305 _font.setBold( true );
306 QFontMetrics metrics(_font);
307 307
308 // ----- find largest day name: 308 // ----- find largest day name:
309 maxCell.setWidth(0); 309 maxCell.setWidth(0);
310 maxCell.setHeight(0); 310 maxCell.setHeight(0);
311 for(count=0; count<7; ++count) 311 for(count=0; count<7; ++count)
312 { 312 {
313 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true)); 313 rect=metrics.boundingRect(KGlobal::locale()->weekDayName(count+1, true));
314 maxCell.setWidth(QMAX(maxCell.width(), rect.width())); 314 maxCell.setWidth(QMAX(maxCell.width(), rect.width()));
315 maxCell.setHeight(QMAX(maxCell.height(), rect.height())); 315 maxCell.setHeight(QMAX(maxCell.height(), rect.height()));
316 } 316 }
317 // ----- compare with a real wide number and add some space: 317 // ----- compare with a real wide number and add some space:
318 rect=metrics.boundingRect(QString::fromLatin1("88")); 318 rect=metrics.boundingRect(QString::fromLatin1("88"));
319 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width())); 319 maxCell.setWidth(QMAX(maxCell.width()+2, rect.width()));
320#ifdef DESKTOP_VERSION 320#ifdef DESKTOP_VERSION
321 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height())); 321 maxCell.setHeight(QMAX(maxCell.height()+8, rect.height()));
322#else 322#else
323 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height())); 323 maxCell.setHeight(QMAX(maxCell.height()+4, rect.height()));
324#endif 324#endif
325 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) { 325 if ( maxCell.width() * 1000 / maxCell.height() > 1900 ) {
326 maxCell.setHeight(maxCell.width() * 1000 / 1900 ); 326 maxCell.setHeight(maxCell.width() * 1000 / 1900 );
327 qDebug("setmax "); 327 qDebug("setmax ");
328 } 328 }
329} 329}
330 330
331void 331void
332KDateTable::contentsMousePressEvent(QMouseEvent *e) 332KDateTable::contentsMousePressEvent(QMouseEvent *e)
333{ 333{
334 if(e->type()!=QEvent::MouseButtonPress) 334 if(e->type()!=QEvent::MouseButtonPress)
335 { // the KDatePicker only reacts on mouse press events: 335 { // the KDatePicker only reacts on mouse press events:
336 return; 336 return;
337 } 337 }
338 if(!isEnabled()) 338 if(!isEnabled())
339 { 339 {
340 KNotifyClient::beep(); 340 KNotifyClient::beep();
341 return; 341 return;
342 } 342 }
343 343
344 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0; 344 int dayoff = KGlobal::locale()->weekStartsMonday() ? 1 : 0;
345 // ----- 345 // -----
346 int row, col, pos, temp; 346 int row, col, pos, temp;
347 QPoint mouseCoord; 347 QPoint mouseCoord;
348 // ----- 348 // -----
349 mouseCoord = e->pos(); 349 mouseCoord = e->pos();
350 row=rowAt(mouseCoord.y()); 350 row=rowAt(mouseCoord.y());
351 col=columnAt(mouseCoord.x()); 351 col=columnAt(mouseCoord.x());
352 if(row<0 || col<0) 352 if(row<0 || col<0)
353 { // the user clicked on the frame of the table 353 { // the user clicked on the frame of the table
354 return; 354 return;
355 } 355 }
356 pos=7*(row-1)+col+1; 356 pos=7*(row-1)+col+1;
357#if 0 357#if 0
358 if(pos+dayoff<=firstday) 358 if(pos+dayoff<=firstday)
359 { // this day is in the previous month 359 { // this day is in the previous month
360 KNotifyClient::beep(); 360 KNotifyClient::beep();
361 return; 361 return;
362 } 362 }
363 if(firstday+numdays<pos+dayoff) 363 if(firstday+numdays<pos+dayoff)
364 { // this date is in the next month 364 { // this date is in the next month
365 KNotifyClient::beep(); 365 KNotifyClient::beep();
366 return; 366 return;
367 } 367 }
368#endif 368#endif
369 temp=firstday+date.day()-dayoff-1; 369 temp=firstday+date.day()-dayoff-1;
370 QDate da = QDate(date.year(), date.month(),1); 370 QDate da = QDate(date.year(), date.month(),1);
371 setDate(da.addDays( pos-firstday+dayoff-1)); 371 setDate(da.addDays( pos-firstday+dayoff-1));
372 updateCell(temp/7+1, temp%7); // Update the previously selected cell 372 updateCell(temp/7+1, temp%7); // Update the previously selected cell
373 updateCell(row, col); // Update the selected cell 373 updateCell(row, col); // Update the selected cell
374 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid()); 374 // assert(QDate(date.year(), date.month(), pos-firstday+dayoff).isValid());
375 emit(tableClicked()); 375 emit(tableClicked());
376} 376}
377 377
378bool 378bool
379KDateTable::setDate(const QDate& date_) 379KDateTable::setDate(const QDate& date_)
380{ 380{
381 bool changed=false; 381 bool changed=false;
382 QDate temp; 382 QDate temp;
383 mMarkCurrent = false; 383 mMarkCurrent = false;
384 // ----- 384 // -----
385 if(!date_.isValid()) 385 if(!date_.isValid())
386 { 386 {
387 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl; 387 kdDebug() << "KDateTable::setDate: refusing to set invalid date." << endl;
388 return false; 388 return false;
389 } 389 }
390 if(date!=date_) 390 if(date!=date_)
391 { 391 {
392 date=date_; 392 date=date_;
393 changed=true; 393 changed=true;
394 } 394 }
395 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() ); 395 mMarkCurrent = ( date.month() == QDate::currentDate().month() && date.year() == QDate::currentDate().year() );
396 temp.setYMD(date.year(), date.month(), 1); 396 temp.setYMD(date.year(), date.month(), 1);
397 firstday=temp.dayOfWeek(); 397 firstday=temp.dayOfWeek();
398 if(firstday==1) firstday=8; 398 if(firstday==1) firstday=8;
399 numdays=date.daysInMonth(); 399 numdays=date.daysInMonth();
400 if(date.month()==1) 400 if(date.month()==1)
401 { // set to december of previous year 401 { // set to december of previous year
402 temp.setYMD(date.year()-1, 12, 1); 402 temp.setYMD(date.year()-1, 12, 1);
403 } else { // set to previous month 403 } else { // set to previous month
404 temp.setYMD(date.year(), date.month()-1, 1); 404 temp.setYMD(date.year(), date.month()-1, 1);
405 } 405 }
406 numDaysPrevMonth=temp.daysInMonth(); 406 numDaysPrevMonth=temp.daysInMonth();
407 if(changed) 407 if(changed)
408 { 408 {
409 repaintContents(false); 409 repaintContents(false);
410 } 410 }
411 emit(dateChanged(date)); 411 emit(dateChanged(date));
412 return true; 412 return true;
413} 413}
414 414
415const QDate& 415const QDate&
416KDateTable::getDate() const 416KDateTable::getDate() const
417{ 417{
418 return date; 418 return date;
419} 419}
420 420
421void KDateTable::focusInEvent( QFocusEvent *e ) 421void KDateTable::focusInEvent( QFocusEvent *e )
422{ 422{
423 repaintContents(false); 423 repaintContents(false);
424 QGridView::focusInEvent( e ); 424 QGridView::focusInEvent( e );
425} 425}
426 426
427void KDateTable::focusOutEvent( QFocusEvent *e ) 427void KDateTable::focusOutEvent( QFocusEvent *e )
428{ 428{
429 repaintContents(false); 429 repaintContents(false);
430 QGridView::focusOutEvent( e ); 430 QGridView::focusOutEvent( e );
431} 431}
432 432
433QSize 433QSize
434KDateTable::sizeHint() const 434KDateTable::sizeHint() const
435{ 435{
436 if(maxCell.height()>0 && maxCell.width()>0) 436 if(maxCell.height()>0 && maxCell.width()>0)
437 { 437 {
438 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(), 438 return QSize((maxCell.width()+2)*numCols()+2*frameWidth(),
439 (maxCell.height()+4)*numRows()+2*frameWidth()); 439 (maxCell.height()+4)*numRows()+2*frameWidth());
440 } else { 440 } else {
441 return QSize(-1, -1); 441 return QSize(-1, -1);
442 } 442 }
443} 443}
444 444
445KDateInternalMonthPicker::KDateInternalMonthPicker 445KDateInternalMonthPicker::KDateInternalMonthPicker
446(int fontsize, QWidget* parent, const char* name) 446(QWidget* parent, const char* name)
447 : QGridView(parent, name), 447 : QGridView(parent, name),
448 result(0) // invalid 448 result(0) // invalid
449{ 449{
450 QRect rect; 450 QRect rect;
451 QFont font; 451 QFont font;
452 // ----- 452 // -----
453 activeCol = -1; 453 activeCol = -1;
454 activeRow = -1; 454 activeRow = -1;
455 font=KGlobalSettings::generalFont(); 455 font=KGlobalSettings::generalFont();
456 //font.setPointSize(fontsize); 456 int fontsize = 10;
457 int add = 2;
458 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
459 add += 6;
460 font.setPointSize(fontsize+add);
457 setFont(font); 461 setFont(font);
458 setHScrollBarMode(AlwaysOff); 462 setHScrollBarMode(AlwaysOff);
459 setVScrollBarMode(AlwaysOff); 463 setVScrollBarMode(AlwaysOff);
460 setFrameStyle(QFrame::NoFrame); 464 setFrameStyle(QFrame::NoFrame);
461 setNumRows(4); 465 setNumRows(4);
462 setNumCols(3); 466 setNumCols(3);
463 // enable to find drawing failures: 467 // enable to find drawing failures:
464 // setTableFlags(Tbl_clipCellPainting); 468 // setTableFlags(Tbl_clipCellPainting);
465#if 0 469#if 0
466 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 470 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
467#endif 471#endif
468 // ----- find the preferred size 472 // ----- find the preferred size
469 // (this is slow, possibly, but unfortunatly it is needed here): 473 // (this is slow, possibly, but unfortunatly it is needed here):
470 QFontMetrics metrics(font); 474 QFontMetrics metrics(font);
471 for(int i=1; i <= 12; ++i) 475 for(int i=1; i <= 12; ++i)
472 { 476 {
473 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false)); 477 rect=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
474 if(max.width()<rect.width()) max.setWidth(rect.width()); 478 if(max.width()<rect.width()) max.setWidth(rect.width());
475 if(max.height()<rect.height()) max.setHeight(rect.height()); 479 if(max.height()<rect.height()) max.setHeight(rect.height());
476 } 480 }
477 481
478} 482}
479 483
480QSize 484QSize
481KDateInternalMonthPicker::sizeHint() const 485KDateInternalMonthPicker::sizeHint() const
482{ 486{
483 return QSize((max.width()+6)*numCols()+2*frameWidth(), 487 return QSize((max.width()+6)*numCols()+2*frameWidth(),
484 (max.height()+6)*numRows()+2*frameWidth()); 488 (max.height()+6)*numRows()+2*frameWidth());
485} 489}
486 490
487int 491int
488KDateInternalMonthPicker::getResult() const 492KDateInternalMonthPicker::getResult() const
489{ 493{
490 return result; 494 return result;
491} 495}
492 496
493void 497void
494KDateInternalMonthPicker::setupPainter(QPainter *p) 498KDateInternalMonthPicker::setupPainter(QPainter *p)
495{ 499{
496 p->setPen(black); 500 p->setPen(black);
497} 501}
498 502
499void 503void
500KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*) 504KDateInternalMonthPicker::viewportResizeEvent(QResizeEvent*)
501{ 505{
502 setCellWidth(width()/3); 506 setCellWidth(width()/3);
503 setCellHeight(height()/4); 507 setCellHeight(height()/4);
504} 508}
505 509
506void 510void
507KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col) 511KDateInternalMonthPicker::paintCell(QPainter* painter, int row, int col)
508{ 512{
509 int index; 513 int index;
510 QString text; 514 QString text;
511 // ----- find the number of the cell: 515 // ----- find the number of the cell:
512 index=3*row+col+1; 516 index=3*row+col+1;
513 text=KGlobal::locale()->monthName(index, false); 517 text=KGlobal::locale()->monthName(index, false);
514 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 518 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
515 if ( activeCol == col && activeRow == row ) 519 if ( activeCol == col && activeRow == row )
516 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 520 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
517} 521}
518 522
519void 523void
520KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e) 524KDateInternalMonthPicker::contentsMousePressEvent(QMouseEvent *e)
521{ 525{
522 if(!isEnabled() || e->button() != LeftButton) 526 if(!isEnabled() || e->button() != LeftButton)
523 { 527 {
524 KNotifyClient::beep(); 528 KNotifyClient::beep();
525 return; 529 return;
526 } 530 }
527 // ----- 531 // -----
528 int row, col; 532 int row, col;
529 QPoint mouseCoord; 533 QPoint mouseCoord;
530 // ----- 534 // -----
531 mouseCoord = e->pos(); 535 mouseCoord = e->pos();
532 row=rowAt(mouseCoord.y()); 536 row=rowAt(mouseCoord.y());
533 col=columnAt(mouseCoord.x()); 537 col=columnAt(mouseCoord.x());
534 538
535 if(row<0 || col<0) 539 if(row<0 || col<0)
536 { // the user clicked on the frame of the table 540 { // the user clicked on the frame of the table
537 activeCol = -1; 541 activeCol = -1;
538 activeRow = -1; 542 activeRow = -1;
539 } else { 543 } else {
540 activeCol = col; 544 activeCol = col;
541 activeRow = row; 545 activeRow = row;
542 updateCell( row, col /*, false */ ); 546 updateCell( row, col /*, false */ );
543 } 547 }
544} 548}
545 549
546void 550void
547KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e) 551KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
548{ 552{
549 if (e->state() & LeftButton) 553 if (e->state() & LeftButton)
550 { 554 {
551 int row, col; 555 int row, col;
552 QPoint mouseCoord; 556 QPoint mouseCoord;
@@ -668,203 +672,207 @@ KDateInternalYearSelector::setYear(int year)
668 672
669KPopupFrame::KPopupFrame(QWidget* parent, const char* name) 673KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
670 : QFrame(parent, name, WType_Popup), 674 : QFrame(parent, name, WType_Popup),
671 result(0), // rejected 675 result(0), // rejected
672 main(0) 676 main(0)
673{ 677{
674 setFrameStyle(QFrame::Box|QFrame::Raised); 678 setFrameStyle(QFrame::Box|QFrame::Raised);
675 setMidLineWidth(2); 679 setMidLineWidth(2);
676} 680}
677 681
678void 682void
679KPopupFrame::keyPressEvent(QKeyEvent* e) 683KPopupFrame::keyPressEvent(QKeyEvent* e)
680{ 684{
681 if(e->key()==Key_Escape) 685 if(e->key()==Key_Escape)
682 { 686 {
683 result=0; // rejected 687 result=0; // rejected
684 qApp->exit_loop(); 688 qApp->exit_loop();
685 } 689 }
686} 690}
687 691
688void 692void
689KPopupFrame::close(int r) 693KPopupFrame::close(int r)
690{ 694{
691 result=r; 695 result=r;
692 qApp->exit_loop(); 696 qApp->exit_loop();
693} 697}
694 698
695void 699void
696KPopupFrame::setMainWidget(QWidget* m) 700KPopupFrame::setMainWidget(QWidget* m)
697{ 701{
698 main=m; 702 main=m;
699 if(main!=0) 703 if(main!=0)
700 { 704 {
701 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth()); 705 resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
702 } 706 }
703} 707}
704 708
705void 709void
706KPopupFrame::resizeEvent(QResizeEvent*) 710KPopupFrame::resizeEvent(QResizeEvent*)
707{ 711{
708 if(main!=0) 712 if(main!=0)
709 { 713 {
710 main->setGeometry(frameWidth(), frameWidth(), 714 main->setGeometry(frameWidth(), frameWidth(),
711 width()-2*frameWidth(), height()-2*frameWidth()); 715 width()-2*frameWidth(), height()-2*frameWidth());
712 } 716 }
713} 717}
714 718
715void 719void
716KPopupFrame::popup(const QPoint &pos) 720KPopupFrame::popup(const QPoint &pos)
717{ 721{
718 // Make sure the whole popup is visible. 722 // Make sure the whole popup is visible.
719 QRect d = QApplication::desktop()->frameGeometry(); 723 QRect d = QApplication::desktop()->frameGeometry();
720 int x = pos.x(); 724 int x = pos.x();
721 int y = pos.y(); 725 int y = pos.y();
722 int w = width(); 726 int w = width();
723 int h = height(); 727 int h = height();
724 if (x+w > d.x()+d.width()) 728 if (x+w > d.x()+d.width())
725 x = d.width() - w; 729 x = d.width() - w;
726 if (y+h > d.y()+d.height()) 730 if (y+h > d.y()+d.height())
727 y = d.height() - h; 731 y = d.height() - h;
728 if (x < d.x()) 732 if (x < d.x())
729 x = 0; 733 x = 0;
730 if (y < d.y()) 734 if (y < d.y())
731 y = 0; 735 y = 0;
732 736
733 // Pop the thingy up. 737 // Pop the thingy up.
734 move(x, y); 738 move(x, y);
735 show(); 739 show();
736} 740}
737 741
738int 742int
739KPopupFrame::exec(QPoint pos) 743KPopupFrame::exec(QPoint pos)
740{ 744{
741 popup(pos); 745 popup(pos);
742 repaint(); 746 repaint();
743 qApp->enter_loop(); 747 qApp->enter_loop();
744 hide(); 748 hide();
745 return result; 749 return result;
746} 750}
747 751
748int 752int
749KPopupFrame::exec(int x, int y) 753KPopupFrame::exec(int x, int y)
750{ 754{
751 return exec(QPoint(x, y)); 755 return exec(QPoint(x, y));
752} 756}
753 757
754void KPopupFrame::virtual_hook( int, void* ) 758void KPopupFrame::virtual_hook( int, void* )
755{ /*BASE::virtual_hook( id, data );*/ } 759{ /*BASE::virtual_hook( id, data );*/ }
756 760
757void KDateTable::virtual_hook( int, void* ) 761void KDateTable::virtual_hook( int, void* )
758{ /*BASE::virtual_hook( id, data );*/ } 762{ /*BASE::virtual_hook( id, data );*/ }
759 763
760//#include "kdatetbl.moc" 764//#include "kdatetbl.moc"
761 765
762 766
763KDateInternalWeekPicker::KDateInternalWeekPicker 767KDateInternalWeekPicker::KDateInternalWeekPicker
764(int fontsize, QWidget* parent, const char* name) 768(QWidget* parent, const char* name)
765 : QGridView(parent, name), 769 : QGridView(parent, name),
766 result(0) // invalid 770 result(0) // invalid
767{ 771{
768 QRect rect; 772 QRect rect;
769 QFont font; 773 QFont font;
770 // ----- 774 // -----
771 activeCol = -1; 775 activeCol = -1;
772 activeRow = -1; 776 activeRow = -1;
773 font=KGlobalSettings::generalFont(); 777 font=KGlobalSettings::generalFont();
774 //font.setPointSize(fontsize); 778 int fontsize = 10;
779 int add = 2;
780 if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
781 add += 4;
782 font.setPointSize(fontsize+add);
775 setFont(font); 783 setFont(font);
776 setHScrollBarMode(AlwaysOff); 784 setHScrollBarMode(AlwaysOff);
777 setVScrollBarMode(AlwaysOff); 785 setVScrollBarMode(AlwaysOff);
778 setFrameStyle(QFrame::NoFrame); 786 setFrameStyle(QFrame::NoFrame);
779 setNumRows(13); 787 setNumRows(13);
780 setNumCols(4); 788 setNumCols(4);
781 // enable to find drawing failures: 789 // enable to find drawing failures:
782 // setTableFlags(Tbl_clipCellPainting); 790 // setTableFlags(Tbl_clipCellPainting);
783#if 0 791#if 0
784 viewport()->setEraseColor(lightGray); // for consistency with the datepicker 792 viewport()->setEraseColor(lightGray); // for consistency with the datepicker
785#endif 793#endif
786 // ----- find the preferred size 794 // ----- find the preferred size
787 // (this is slow, possibly, but unfortunatly it is needed here): 795 // (this is slow, possibly, but unfortunatly it is needed here):
788 QFontMetrics metrics(font); 796 QFontMetrics metrics(font);
789 for(int i=1; i <= 52; ++i) 797 for(int i=1; i <= 52; ++i)
790 { 798 {
791 rect=metrics.boundingRect(QString::number( i )); 799 rect=metrics.boundingRect(QString::number( i ));
792 if(max.width()<rect.width()) max.setWidth(rect.width()); 800 if(max.width()<rect.width()) max.setWidth(rect.width());
793 if(max.height()<rect.height()) max.setHeight(rect.height()); 801 if(max.height()<rect.height()) max.setHeight(rect.height());
794 } 802 }
795 if ( QApplication::desktop()->width() > 640 ) { 803 if ( QApplication::desktop()->width() > 640 ) {
796 804
797 max.setWidth(max.width()+6); 805 max.setWidth(max.width()+6);
798 max.setHeight(max.height()+8); 806 max.setHeight(max.height()+8);
799 } 807 }
800} 808}
801 809
802QSize 810QSize
803KDateInternalWeekPicker::sizeHint() const 811KDateInternalWeekPicker::sizeHint() const
804{ 812{
805 return QSize((max.width()+6)*numCols()+2*frameWidth(), 813 return QSize((max.width()+6)*numCols()+2*frameWidth(),
806 (max.height()+6)*numRows()+2*frameWidth()); 814 (max.height()+6)*numRows()+2*frameWidth());
807} 815}
808 816
809int 817int
810KDateInternalWeekPicker::getResult() const 818KDateInternalWeekPicker::getResult() const
811{ 819{
812 return result; 820 return result;
813} 821}
814 822
815void 823void
816KDateInternalWeekPicker::setupPainter(QPainter *p) 824KDateInternalWeekPicker::setupPainter(QPainter *p)
817{ 825{
818 p->setPen(black); 826 p->setPen(black);
819} 827}
820 828
821void 829void
822KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*) 830KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
823{ 831{
824 setCellWidth(width()/4); 832 setCellWidth(width()/4);
825 setCellHeight(height()/13); 833 setCellHeight(height()/13);
826} 834}
827 835
828void 836void
829KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col) 837KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
830{ 838{
831 int index; 839 int index;
832 QString text; 840 QString text;
833 // ----- find the number of the cell: 841 // ----- find the number of the cell:
834 index=4*row+col+1; 842 index=4*row+col+1;
835 text=QString::number( index ); 843 text=QString::number( index );
836 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text); 844 painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
837 if ( activeCol == col && activeRow == row ) 845 if ( activeCol == col && activeRow == row )
838 painter->drawRect( 0, 0, cellWidth(), cellHeight() ); 846 painter->drawRect( 0, 0, cellWidth(), cellHeight() );
839} 847}
840 848
841void 849void
842KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e) 850KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
843{ 851{
844 if(!isEnabled() || e->button() != LeftButton) 852 if(!isEnabled() || e->button() != LeftButton)
845 { 853 {
846 KNotifyClient::beep(); 854 KNotifyClient::beep();
847 return; 855 return;
848 } 856 }
849 // ----- 857 // -----
850 int row, col; 858 int row, col;
851 QPoint mouseCoord; 859 QPoint mouseCoord;
852 // ----- 860 // -----
853 mouseCoord = e->pos(); 861 mouseCoord = e->pos();
854 row=rowAt(mouseCoord.y()); 862 row=rowAt(mouseCoord.y());
855 col=columnAt(mouseCoord.x()); 863 col=columnAt(mouseCoord.x());
856 864
857 if(row<0 || col<0) 865 if(row<0 || col<0)
858 { // the user clicked on the frame of the table 866 { // the user clicked on the frame of the table
859 activeCol = -1; 867 activeCol = -1;
860 activeRow = -1; 868 activeRow = -1;
861 } else { 869 } else {
862 activeCol = col; 870 activeCol = col;
863 activeRow = row; 871 activeRow = row;
864 updateCell( row, col /*, false */ ); 872 updateCell( row, col /*, false */ );
865 } 873 }
866} 874}
867 875
868void 876void
869KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e) 877KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
870{ 878{
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index 2efa532..87808df 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -1,156 +1,156 @@
1/* -*- C++ -*- 1/* -*- C++ -*-
2 This file is part of the KDE libraries 2 This file is part of the KDE libraries
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
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef KDATETBL_H 20#ifndef KDATETBL_H
21#define KDATETBL_H 21#define KDATETBL_H
22 22
23#include <qvalidator.h> 23#include <qvalidator.h>
24#include <qgridview.h> 24#include <qgridview.h>
25#include <qlineedit.h> 25#include <qlineedit.h>
26#include <qdatetime.h> 26#include <qdatetime.h>
27 27
28/** 28/**
29* A table containing month names. It is used to pick a month directly. 29* A table containing month names. It is used to pick a month directly.
30* @internal 30* @internal
31* @version $Id$ 31* @version $Id$
32* @author Tim Gilman, Mirko Boehm 32* @author Tim Gilman, Mirko Boehm
33*/ 33*/
34class KDateInternalMonthPicker : public QGridView 34class KDateInternalMonthPicker : public QGridView
35{ 35{
36 Q_OBJECT 36 Q_OBJECT
37protected: 37protected:
38 /** 38 /**
39 * Store the month that has been clicked [1..12]. 39 * Store the month that has been clicked [1..12].
40 */ 40 */
41 int result; 41 int result;
42 /** 42 /**
43 * the cell under mouse cursor when LBM is pressed 43 * the cell under mouse cursor when LBM is pressed
44 */ 44 */
45 short int activeCol; 45 short int activeCol;
46 short int activeRow; 46 short int activeRow;
47 /** 47 /**
48 * Contains the largest rectangle needed by the month names. 48 * Contains the largest rectangle needed by the month names.
49 */ 49 */
50 QRect max; 50 QRect max;
51signals: 51signals:
52 /** 52 /**
53 * This is send from the mouse click event handler. 53 * This is send from the mouse click event handler.
54 */ 54 */
55 void closeMe(int); 55 void closeMe(int);
56public: 56public:
57 /** 57 /**
58 * The constructor. 58 * The constructor.
59 */ 59 */
60 KDateInternalMonthPicker(int fontsize, QWidget* parent, const char* name=0); 60 KDateInternalMonthPicker(QWidget* parent, const char* name=0);
61 /** 61 /**
62 * The size hint. 62 * The size hint.
63 */ 63 */
64 QSize sizeHint() const; 64 QSize sizeHint() const;
65 /** 65 /**
66 * Return the result. 0 means no selection (reject()), 1..12 are the 66 * Return the result. 0 means no selection (reject()), 1..12 are the
67 * months. 67 * months.
68 */ 68 */
69 int getResult() const; 69 int getResult() const;
70protected: 70protected:
71 /** 71 /**
72 * Set up the painter. 72 * Set up the painter.
73 */ 73 */
74 void setupPainter(QPainter *p); 74 void setupPainter(QPainter *p);
75 /** 75 /**
76 * The resize event. 76 * The resize event.
77 */ 77 */
78 void viewportResizeEvent(QResizeEvent*); 78 void viewportResizeEvent(QResizeEvent*);
79 /** 79 /**
80 * Paint a cell. This simply draws the month names in it. 80 * Paint a cell. This simply draws the month names in it.
81 */ 81 */
82 virtual void paintCell(QPainter* painter, int row, int col); 82 virtual void paintCell(QPainter* painter, int row, int col);
83 /** 83 /**
84 * Catch mouse click and move events to paint a rectangle around the item. 84 * Catch mouse click and move events to paint a rectangle around the item.
85 */ 85 */
86 void contentsMousePressEvent(QMouseEvent *e); 86 void contentsMousePressEvent(QMouseEvent *e);
87 void contentsMouseMoveEvent(QMouseEvent *e); 87 void contentsMouseMoveEvent(QMouseEvent *e);
88 /** 88 /**
89 * Emit monthSelected(int) when a cell has been released. 89 * Emit monthSelected(int) when a cell has been released.
90 */ 90 */
91 void contentsMouseReleaseEvent(QMouseEvent *e); 91 void contentsMouseReleaseEvent(QMouseEvent *e);
92 92
93private: 93private:
94 class KDateInternalMonthPrivate; 94 class KDateInternalMonthPrivate;
95 KDateInternalMonthPrivate *d; 95 KDateInternalMonthPrivate *d;
96}; 96};
97 97
98/** Year selection widget. 98/** Year selection widget.
99* @internal 99* @internal
100* @version $Id$ 100* @version $Id$
101* @author Tim Gilman, Mirko Boehm 101* @author Tim Gilman, Mirko Boehm
102*/ 102*/
103class KDateInternalYearSelector : public QLineEdit 103class KDateInternalYearSelector : public QLineEdit
104{ 104{
105 Q_OBJECT 105 Q_OBJECT
106protected: 106protected:
107 QIntValidator *val; 107 QIntValidator *val;
108 int result; 108 int result;
109public slots: 109public slots:
110 void yearEnteredSlot(); 110 void yearEnteredSlot();
111signals: 111signals:
112 void closeMe(int); 112 void closeMe(int);
113public: 113public:
114 KDateInternalYearSelector(int fontsize, 114 KDateInternalYearSelector(int fontsize,
115 QWidget* parent=0, 115 QWidget* parent=0,
116 const char* name=0); 116 const char* name=0);
117 int getYear(); 117 int getYear();
118 void setYear(int year); 118 void setYear(int year);
119 119
120private: 120private:
121 class KDateInternalYearPrivate; 121 class KDateInternalYearPrivate;
122 KDateInternalYearPrivate *d; 122 KDateInternalYearPrivate *d;
123}; 123};
124 124
125/** 125/**
126 * Frame with popup menu behaviour. 126 * Frame with popup menu behaviour.
127 * @author Tim Gilman, Mirko Boehm 127 * @author Tim Gilman, Mirko Boehm
128 * @version $Id$ 128 * @version $Id$
129 */ 129 */
130class KPopupFrame : public QFrame 130class KPopupFrame : public QFrame
131{ 131{
132 Q_OBJECT 132 Q_OBJECT
133protected: 133protected:
134 /** 134 /**
135 * The result. It is returned from exec() when the popup window closes. 135 * The result. It is returned from exec() when the popup window closes.
136 */ 136 */
137 int result; 137 int result;
138 /** 138 /**
139 * Catch key press events. 139 * Catch key press events.
140 */ 140 */
141 void keyPressEvent(QKeyEvent* e); 141 void keyPressEvent(QKeyEvent* e);
142 /** 142 /**
143 * The only subwidget that uses the whole dialog window. 143 * The only subwidget that uses the whole dialog window.
144 */ 144 */
145 QWidget *main; 145 QWidget *main;
146public slots: 146public slots:
147 /** 147 /**
148 * Close the popup window. This is called from the main widget, usually. 148 * Close the popup window. This is called from the main widget, usually.
149 * @p r is the result returned from exec(). 149 * @p r is the result returned from exec().
150 */ 150 */
151 void close(int r); 151 void close(int r);
152public: 152public:
153 /** 153 /**
154 * The contructor. Creates a dialog without buttons. 154 * The contructor. Creates a dialog without buttons.
155 */ 155 */
156 KPopupFrame(QWidget* parent=0, const char* name=0); 156 KPopupFrame(QWidget* parent=0, const char* name=0);
@@ -240,133 +240,133 @@ public:
240 /** 240 /**
241 * Select and display this date. 241 * Select and display this date.
242 */ 242 */
243 bool setDate(const QDate&); 243 bool setDate(const QDate&);
244 const QDate& getDate() const; 244 const QDate& getDate() const;
245 245
246 246
247protected: 247protected:
248 bool mMarkCurrent; 248 bool mMarkCurrent;
249 /** 249 /**
250 * Paint a cell. 250 * Paint a cell.
251 */ 251 */
252 virtual void paintCell(QPainter*, int, int); 252 virtual void paintCell(QPainter*, int, int);
253 /** 253 /**
254 * Handle the resize events. 254 * Handle the resize events.
255 */ 255 */
256 virtual void viewportResizeEvent(QResizeEvent *); 256 virtual void viewportResizeEvent(QResizeEvent *);
257 /** 257 /**
258 * React on mouse clicks that select a date. 258 * React on mouse clicks that select a date.
259 */ 259 */
260 virtual void contentsMousePressEvent(QMouseEvent *); 260 virtual void contentsMousePressEvent(QMouseEvent *);
261 virtual void keyPressEvent( QKeyEvent *e ); 261 virtual void keyPressEvent( QKeyEvent *e );
262 virtual void focusInEvent( QFocusEvent *e ); 262 virtual void focusInEvent( QFocusEvent *e );
263 virtual void focusOutEvent( QFocusEvent *e ); 263 virtual void focusOutEvent( QFocusEvent *e );
264 /** 264 /**
265 * The font size of the displayed text. 265 * The font size of the displayed text.
266 */ 266 */
267 int fontsize; 267 int fontsize;
268 /** 268 /**
269 * The currently selected date. 269 * The currently selected date.
270 */ 270 */
271 QDate date; 271 QDate date;
272 /** 272 /**
273 * The day of the first day in the month [1..7]. 273 * The day of the first day in the month [1..7].
274 */ 274 */
275 int firstday; 275 int firstday;
276 /** 276 /**
277 * The number of days in the current month. 277 * The number of days in the current month.
278 */ 278 */
279 int numdays; 279 int numdays;
280 /** 280 /**
281 * The number of days in the previous month. 281 * The number of days in the previous month.
282 */ 282 */
283 int numDaysPrevMonth; 283 int numDaysPrevMonth;
284 /** 284 /**
285 * unused 285 * unused
286 */ 286 */
287 bool unused_hasSelection; 287 bool unused_hasSelection;
288 /** 288 /**
289 * Save the size of the largest used cell content. 289 * Save the size of the largest used cell content.
290 */ 290 */
291 QRect maxCell; 291 QRect maxCell;
292signals: 292signals:
293 /** 293 /**
294 * The selected date changed. 294 * The selected date changed.
295 */ 295 */
296 void dateChanged(QDate); 296 void dateChanged(QDate);
297 /** 297 /**
298 * A date has been selected by clicking on the table. 298 * A date has been selected by clicking on the table.
299 */ 299 */
300 void tableClicked(); 300 void tableClicked();
301 301
302protected: 302protected:
303 virtual void virtual_hook( int id, void* data ); 303 virtual void virtual_hook( int id, void* data );
304private: 304private:
305 class KDateTablePrivate; 305 class KDateTablePrivate;
306 KDateTablePrivate *d; 306 KDateTablePrivate *d;
307}; 307};
308 308
309#endif // KDATETBL_H 309#endif // KDATETBL_H
310class KDateInternalWeekPicker : public QGridView 310class KDateInternalWeekPicker : public QGridView
311{ 311{
312 Q_OBJECT 312 Q_OBJECT
313protected: 313protected:
314 /** 314 /**
315 * Store the month that has been clicked [1..12]. 315 * Store the month that has been clicked [1..12].
316 */ 316 */
317 int result; 317 int result;
318 /** 318 /**
319 * the cell under mouse cursor when LBM is pressed 319 * the cell under mouse cursor when LBM is pressed
320 */ 320 */
321 short int activeCol; 321 short int activeCol;
322 short int activeRow; 322 short int activeRow;
323 /** 323 /**
324 * Contains the largest rectangle needed by the month names. 324 * Contains the largest rectangle needed by the month names.
325 */ 325 */
326 QRect max; 326 QRect max;
327signals: 327signals:
328 /** 328 /**
329 * This is send from the mouse click event handler. 329 * This is send from the mouse click event handler.
330 */ 330 */
331 void closeMe(int); 331 void closeMe(int);
332public: 332public:
333 /** 333 /**
334 * The constructor. 334 * The constructor.
335 */ 335 */
336 KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0); 336 KDateInternalWeekPicker(QWidget* parent, const char* name=0);
337 /** 337 /**
338 * The size hint. 338 * The size hint.
339 */ 339 */
340 QSize sizeHint() const; 340 QSize sizeHint() const;
341 /** 341 /**
342 * Return the result. 0 means no selection (reject()), 1..12 are the 342 * Return the result. 0 means no selection (reject()), 1..12 are the
343 * months. 343 * months.
344 */ 344 */
345 int getResult() const; 345 int getResult() const;
346protected: 346protected:
347 /** 347 /**
348 * Set up the painter. 348 * Set up the painter.
349 */ 349 */
350 void setupPainter(QPainter *p); 350 void setupPainter(QPainter *p);
351 /** 351 /**
352 * The resize event. 352 * The resize event.
353 */ 353 */
354 void viewportResizeEvent(QResizeEvent*); 354 void viewportResizeEvent(QResizeEvent*);
355 /** 355 /**
356 * Paint a cell. This simply draws the month names in it. 356 * Paint a cell. This simply draws the month names in it.
357 */ 357 */
358 virtual void paintCell(QPainter* painter, int row, int col); 358 virtual void paintCell(QPainter* painter, int row, int col);
359 /** 359 /**
360 * Catch mouse click and move events to paint a rectangle around the item. 360 * Catch mouse click and move events to paint a rectangle around the item.
361 */ 361 */
362 void contentsMousePressEvent(QMouseEvent *e); 362 void contentsMousePressEvent(QMouseEvent *e);
363 void contentsMouseMoveEvent(QMouseEvent *e); 363 void contentsMouseMoveEvent(QMouseEvent *e);
364 /** 364 /**
365 * Emit monthSelected(int) when a cell has been released. 365 * Emit monthSelected(int) when a cell has been released.
366 */ 366 */
367 void contentsMouseReleaseEvent(QMouseEvent *e); 367 void contentsMouseReleaseEvent(QMouseEvent *e);
368 368
369private: 369private:
370 class KDateInternalMonthPrivate; 370 class KDateInternalMonthPrivate;
371 KDateInternalMonthPrivate *d; 371 KDateInternalMonthPrivate *d;
372}; 372};
diff --git a/microkde/kglobalsettings.cpp b/microkde/kglobalsettings.cpp
index 30e793f..fbbf814 100644
--- a/microkde/kglobalsettings.cpp
+++ b/microkde/kglobalsettings.cpp
@@ -1,43 +1,44 @@
1#include "kglobalsettings.h" 1#include "kglobalsettings.h"
2#include "kconfig.h" 2#include "kconfig.h"
3#include "kglobal.h" 3#include "kglobal.h"
4#include "kconfigbase.h" 4#include "kconfigbase.h"
5 5
6#include <qapplication.h> 6#include <qapplication.h>
7 7
8QFont KGlobalSettings::generalFont() 8QFont KGlobalSettings::generalFont()
9{ 9{
10 int size = 12; 10 int size = 12;
11 if (QApplication::desktop()->width() < 480 ) 11 if (QApplication::desktop()->width() < 480 )
12 size = 10; 12 size = 10;
13 QFont f = QApplication::font(); 13 QFont f = QApplication::font();
14 //qDebug("pointsize %d ", f.pointSize());
14 f.setPointSize( size ); 15 f.setPointSize( size );
15 return f; 16 return f;
16} 17}
17QFont KGlobalSettings::toolBarFont() 18QFont KGlobalSettings::toolBarFont()
18{ 19{
19 return QApplication::font(); 20 return QApplication::font();
20} 21}
21 22
22QColor KGlobalSettings::toolBarHighlightColor() 23QColor KGlobalSettings::toolBarHighlightColor()
23{ 24{
24 return QColor( "black" ); 25 return QColor( "black" );
25} 26}
26 27
27QRect KGlobalSettings::desktopGeometry( QWidget * ) 28QRect KGlobalSettings::desktopGeometry( QWidget * )
28{ 29{
29 return QApplication::desktop()->rect(); 30 return QApplication::desktop()->rect();
30} 31}
31 32
32 /** 33 /**
33 * Returns whether KDE runs in single (default) or double click 34 * Returns whether KDE runs in single (default) or double click
34 * mode. 35 * mode.
35 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html 36 * see http://developer.kde.org/documentation/standards/kde/style/mouse/index.html
36 * @return true if single click mode, or false if double click mode. 37 * @return true if single click mode, or false if double click mode.
37 **/ 38 **/
38bool KGlobalSettings::singleClick() 39bool KGlobalSettings::singleClick()
39{ 40{
40 KConfig *c = KGlobal::config(); 41 KConfig *c = KGlobal::config();
41 KConfigGroupSaver cgs( c, "KDE" ); 42 KConfigGroupSaver cgs( c, "KDE" );
42 return c->readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK); 43 return c->readBoolEntry("SingleClick", KDE_DEFAULT_SINGLECLICK);
43} 44}