summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Unidiff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp10
1 files changed, 3 insertions, 7 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index d8bc9f5..2be9c9e 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -1,189 +1,185 @@
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 "kdatetbl.h" 37#include "kdatetbl.h"
37#include "kdateedit.h" 38#include "kdateedit.h"
38//#include "kdatepicker.moc" 39//#include "kdatepicker.moc"
39 40
40 41
41KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name) 42KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
42 : QFrame(parent,name), 43 : QFrame(parent,name),
43 yearForward(new QToolButton(this)), 44 yearForward(new QToolButton(this)),
44 yearBackward(new QToolButton(this)), 45 yearBackward(new QToolButton(this)),
45 monthForward(new QToolButton(this)), 46 monthForward(new QToolButton(this)),
46 monthBackward(new QToolButton(this)), 47 monthBackward(new QToolButton(this)),
47 selectMonth(new QToolButton(this)), 48 selectMonth(new QToolButton(this)),
48 selectYear(new QToolButton(this)), 49 selectYear(new QToolButton(this)),
49 //line(new QLineEdit(this)), 50 //line(new QLineEdit(this)),
50 val(new KDateValidator(this)) 51 val(new KDateValidator(this))
51 //table(new KDateTable(this)), 52 //table(new KDateTable(this)),
52 //fontsize(1) 53 //fontsize(1)
53{ 54{
54 // ----- 55 setFont ( KGlobalSettings::generalFont() );
55 int size = 12;
56 if ( QApplication::desktop()->width() >= 480 )
57 size = 18;
58 fontsize = size;
59 setFont ( QFont("helvetica",size) );
60 table = new KDateTable(this); 56 table = new KDateTable(this);
61 setFontSize(size); 57 setFontSize(font().pointSize()+2);
62 //line->setValidator(val); 58 //line->setValidator(val);
63 lineDate = new KDateEdit( this, "dateediipicker", true ); 59 lineDate = new KDateEdit( this, "dateediipicker", true );
64 yearForward->setPixmap(SmallIcon("2rightarrowB")); 60 yearForward->setPixmap(SmallIcon("2rightarrowB"));
65 yearBackward->setPixmap(SmallIcon("2leftarrowB")); 61 yearBackward->setPixmap(SmallIcon("2leftarrowB"));
66 monthForward->setPixmap(SmallIcon("1rightarrowB")); 62 monthForward->setPixmap(SmallIcon("1rightarrowB"));
67 monthBackward->setPixmap(SmallIcon("1leftarrowB")); 63 monthBackward->setPixmap(SmallIcon("1leftarrowB"));
68 setDate(dt); // set button texts 64 setDate(dt); // set button texts
69 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate))); 65 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
70 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot())); 66 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
71 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked())); 67 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
72 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked())); 68 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
73 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked())); 69 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
74 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked())); 70 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
75 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked())); 71 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
76 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked())); 72 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
77 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 73 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
78 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate))); 74 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
79 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed())); 75 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
80 table->setFocus(); 76 table->setFocus();
81 77
82} 78}
83 79
84KDatePicker::~KDatePicker() 80KDatePicker::~KDatePicker()
85{ 81{
86} 82}
87 83
88void 84void
89KDatePicker::resizeEvent(QResizeEvent*) 85KDatePicker::resizeEvent(QResizeEvent*)
90{ 86{
91 QWidget *buttons[] = { 87 QWidget *buttons[] = {
92 yearBackward, 88 yearBackward,
93 monthBackward, 89 monthBackward,
94 selectMonth, 90 selectMonth,
95 selectYear, 91 selectYear,
96 monthForward, 92 monthForward,
97 yearForward }; 93 yearForward };
98 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]); 94 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
99 QSize sizes[NoOfButtons]; 95 QSize sizes[NoOfButtons];
100 int buttonHeight=0; 96 int buttonHeight=0;
101 int count; 97 int count;
102 int w; 98 int w;
103 int x=0; 99 int x=0;
104 // ----- calculate button row height: 100 // ----- calculate button row height:
105 for(count=0; count<NoOfButtons; ++count) { 101 for(count=0; count<NoOfButtons; ++count) {
106 int xS = buttons[count]->sizeHint().width(); 102 int xS = buttons[count]->sizeHint().width();
107 int yS = buttons[count]->sizeHint().height(); 103 int yS = buttons[count]->sizeHint().height();
108 if ( QApplication::desktop()->width() < 320 ) 104 if ( QApplication::desktop()->width() < 320 )
109 sizes[count]=QSize ( xS+4, yS ); 105 sizes[count]=QSize ( xS+4, yS );
110 else 106 else
111 sizes[count]=QSize ( xS+10, yS ); 107 sizes[count]=QSize ( xS+10, yS );
112 108
113 buttonHeight=QMAX(buttonHeight, sizes[count].height()); 109 buttonHeight=QMAX(buttonHeight, sizes[count].height());
114 } 110 }
115 buttonHeight += 10; 111 buttonHeight += 10;
116 // ----- calculate size of the month button: 112 // ----- calculate size of the month button:
117 w=0; 113 w=0;
118 for(count=0; count<NoOfButtons; ++count) { 114 for(count=0; count<NoOfButtons; ++count) {
119 if(buttons[count]!=selectMonth) 115 if(buttons[count]!=selectMonth)
120 { 116 {
121 w+=sizes[count].width(); 117 w+=sizes[count].width();
122 } else { 118 } else {
123 x=count; 119 x=count;
124 } 120 }
125 } 121 }
126 sizes[x].setWidth(width()-w); // stretch the month button 122 sizes[x].setWidth(width()-w); // stretch the month button
127 // ----- place the buttons: 123 // ----- place the buttons:
128 x=0; 124 x=0;
129 for(count=0; count<NoOfButtons; ++count) 125 for(count=0; count<NoOfButtons; ++count)
130 { 126 {
131 w=sizes[count].width(); 127 w=sizes[count].width();
132 buttons[count]->setGeometry(x, 0, w, buttonHeight); 128 buttons[count]->setGeometry(x, 0, w, buttonHeight);
133 x+=w; 129 x+=w;
134 } 130 }
135 // ----- place the line edit for direct input: 131 // ----- place the line edit for direct input:
136 sizes[0]=lineDate->sizeHint(); 132 sizes[0]=lineDate->sizeHint();
137 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); 133 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
138 lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height()); 134 lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
139 // ----- adjust the table: 135 // ----- adjust the table:
140 table->setGeometry(0, buttonHeight, width(), 136 table->setGeometry(0, buttonHeight, width(),
141 height()-buttonHeight-sizes[0].height()); 137 height()-buttonHeight-sizes[0].height());
142} 138}
143 139
144void 140void
145KDatePicker::dateChangedSlot(QDate date) 141KDatePicker::dateChangedSlot(QDate date)
146{ 142{
147 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true)); 143 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
148 //line->setText(KGlobal::locale()->formatDate(date, true)); 144 //line->setText(KGlobal::locale()->formatDate(date, true));
149 emit(dateChanged(date)); 145 emit(dateChanged(date));
150} 146}
151 147
152void 148void
153KDatePicker::tableClickedSlot() 149KDatePicker::tableClickedSlot()
154{ 150{
155 151
156 emit(dateSelected(table->getDate())); 152 emit(dateSelected(table->getDate()));
157 emit(tableClicked()); 153 emit(tableClicked());
158} 154}
159 155
160const QDate& 156const QDate&
161KDatePicker::getDate() const 157KDatePicker::getDate() const
162{ 158{
163 return table->getDate(); 159 return table->getDate();
164} 160}
165 161
166const QDate & 162const QDate &
167KDatePicker::date() const 163KDatePicker::date() const
168{ 164{
169 return table->getDate(); 165 return table->getDate();
170} 166}
171 167
172void KDatePicker::slotSetDate( QDate date ) 168void KDatePicker::slotSetDate( QDate date )
173{ 169{
174 170
175 if(date.isValid()) { 171 if(date.isValid()) {
176 QString temp; 172 QString temp;
177 // ----- 173 // -----
178 table->setDate(date); 174 table->setDate(date);
179 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false)); 175 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
180 temp.setNum(date.year()); 176 temp.setNum(date.year());
181 selectYear->setText(temp); 177 selectYear->setText(temp);
182 //line->setText(KGlobal::locale()->formatDate(date, true)); 178 //line->setText(KGlobal::locale()->formatDate(date, true));
183 lineDate->setDate( date ); 179 lineDate->setDate( date );
184 } 180 }
185 181
186} 182}
187bool 183bool
188KDatePicker::setDate(const QDate& date) 184KDatePicker::setDate(const QDate& date)
189{ 185{