summaryrefslogtreecommitdiffabout
path: root/libkdepim
Side-by-side diff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp12
-rw-r--r--libkdepim/kdatepicker.h2
2 files changed, 13 insertions, 1 deletions
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
index c13734f..77793c4 100644
--- a/libkdepim/kdatepicker.cpp
+++ b/libkdepim/kdatepicker.cpp
@@ -2,219 +2,229 @@
This file is part of the KDE libraries
Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
(C) 1998-2001 Mirko Boehm (mirko@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "kdatepicker.h"
#include <kglobal.h>
#include <kapplication.h>
#include <klocale.h>
#include <kiconloader.h>
#include <qframe.h>
#include <qpainter.h>
#include <qdialog.h>
#include <qtoolbutton.h>
#include <qfont.h>
#include <qapplication.h>
#include <qlineedit.h>
#include <qvalidator.h>
#include <kdebug.h>
#include <knotifyclient.h>
#include <kglobalsettings.h>
#include "kdatetbl.h"
#include "kdateedit.h"
//#include "kdatepicker.moc"
KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
: QFrame(parent,name),
yearForward(new QToolButton(this)),
yearBackward(new QToolButton(this)),
monthForward(new QToolButton(this)),
monthBackward(new QToolButton(this)),
selectMonth(new QToolButton(this)),
selectYear(new QToolButton(this)),
+ todayBut(new QToolButton(this)),
//line(new QLineEdit(this)),
val(new KDateValidator(this))
//table(new KDateTable(this)),
//fontsize(1)
{
QFont fo = KGlobalSettings::generalFont();
int add = 2;
if ( QApplication::desktop()->width() >= 480 && QApplication::desktop()->width() <= 640 )
add += 4;
fo.setPointSize(fo.pointSize()+add );
setFont( fo );
table = new KDateTable(this);
setFontSize(font().pointSize());
//line->setValidator(val);
lineDate = new KDateEdit( this, "dateediipicker", true );
yearForward->setPixmap(SmallIcon("2rightarrowB"));
yearBackward->setPixmap(SmallIcon("2leftarrowB"));
monthForward->setPixmap(SmallIcon("1rightarrowB"));
monthBackward->setPixmap(SmallIcon("1leftarrowB"));
+ todayBut->setPixmap(SmallIcon("today"));
setDate(dt); // set button texts
connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
+ connect(todayBut, SIGNAL(clicked()), SLOT(goToday()));
//connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
table->setFocus();
}
KDatePicker::~KDatePicker()
{
}
void
KDatePicker::resizeEvent(QResizeEvent*)
{
QWidget *buttons[] = {
yearBackward,
monthBackward,
selectMonth,
selectYear,
monthForward,
yearForward };
const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
QSize sizes[NoOfButtons];
int buttonHeight=0;
int count;
int w;
int x=0;
// ----- calculate button row height:
for(count=0; count<NoOfButtons; ++count) {
int xS = buttons[count]->sizeHint().width();
int yS = buttons[count]->sizeHint().height();
if ( QApplication::desktop()->width() < 320 )
sizes[count]=QSize ( xS+4, yS );
else
sizes[count]=QSize ( xS+10, yS );
buttonHeight=QMAX(buttonHeight, sizes[count].height());
}
buttonHeight += 10;
// ----- calculate size of the month button:
w=0;
for(count=0; count<NoOfButtons; ++count) {
if(buttons[count]!=selectMonth)
{
w+=sizes[count].width();
} else {
x=count;
}
}
sizes[x].setWidth(width()-w); // stretch the month button
// ----- place the buttons:
x=0;
for(count=0; count<NoOfButtons; ++count)
{
w=sizes[count].width();
buttons[count]->setGeometry(x, 0, w, buttonHeight);
x+=w;
}
// ----- place the line edit for direct input:
sizes[0]=lineDate->sizeHint();
//line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
- lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
+ int todaywid = todayBut->sizeHint().width();
+todayBut->setGeometry(0, height()-sizes[0].height(),todaywid, sizes[0].height());
+ lineDate->setGeometry(0+todaywid, height()-sizes[0].height(), width()-todaywid, sizes[0].height());
// ----- adjust the table:
table->setGeometry(0, buttonHeight, width(),
height()-buttonHeight-sizes[0].height());
}
void
KDatePicker::dateChangedSlot(QDate date)
{
lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
//line->setText(KGlobal::locale()->formatDate(date, true));
emit(dateChanged(date));
}
void
KDatePicker::tableClickedSlot()
{
emit(dateSelected(table->getDate()));
emit(tableClicked());
}
const QDate&
KDatePicker::getDate() const
{
return table->getDate();
}
const QDate &
KDatePicker::date() const
{
return table->getDate();
}
+void KDatePicker::goToday()
+{
+ slotSetDate( QDate::currentDate() );
+
+}
void KDatePicker::slotSetDate( QDate date )
{
if(date.isValid()) {
QString temp;
// -----
table->setDate(date);
selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
temp.setNum(date.year());
selectYear->setText(temp);
//line->setText(KGlobal::locale()->formatDate(date, true));
lineDate->setDate( date );
}
}
bool
KDatePicker::setDate(const QDate& date)
{
table->setFocus();
if(date.isValid()) {
QString temp;
// -----
table->setDate(date);
selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
temp.setNum(date.year());
selectYear->setText(temp);
//line->setText(KGlobal::locale()->formatDate(date, true));
lineDate->setDate( date );
return true;
} else {
return false;
}
}
void
KDatePicker::monthForwardClicked()
{
QDate temp=table->getDate();
int day=temp.day();
// -----
if(temp.month()==12) {
temp.setYMD(temp.year()+1, 1, 1);
} else {
temp.setYMD(temp.year(), temp.month()+1, 1);
}
diff --git a/libkdepim/kdatepicker.h b/libkdepim/kdatepicker.h
index 6625357..3db9a89 100644
--- a/libkdepim/kdatepicker.h
+++ b/libkdepim/kdatepicker.h
@@ -62,120 +62,122 @@ public:
* The destructor.
**/
virtual ~KDatePicker();
/** The size hint for date pickers. The size hint recommends the
* minimum size of the widget so that all elements may be placed
* without clipping. This sometimes looks ugly, so when using the
* size hint, try adding 28 to each of the reported numbers of
* pixels.
**/
QSize sizeHint() const;
/**
* Sets the date.
*
* @returns @p false and does not change anything
* if the date given is invalid.
**/
bool setDate(const QDate&);
/**
* Returns the selected date.
* @deprecated
**/
const QDate& getDate() const;
/**
* @returns the selected date.
*/
const QDate &date() const;
/**
* Enables or disables the widget.
**/
void setEnabled(bool);
/**
* Sets the font size of the widgets elements.
**/
void setFontSize(int);
/**
* Returns the font size of the widget elements.
*/
int fontSize() const
{ return fontsize; }
protected:
/// the resize event
void resizeEvent(QResizeEvent*);
+ QToolButton *todayBut;
/// the year forward button
QToolButton *yearForward;
/// the year backward button
QToolButton *yearBackward;
/// the month forward button
QToolButton *monthForward;
/// the month backward button
QToolButton *monthBackward;
/// the button for selecting the month directly
QToolButton *selectMonth;
/// the button for selecting the year directly
QToolButton *selectYear;
/// the line edit to enter the date directly
//QLineEdit *line;
KDateEdit *lineDate;
/// the validator for the line edit:
KDateValidator *val;
/// the date table
KDateTable *table;
/// the size calculated during resize events
// QSize sizehint;
/// the widest month string in pixels:
QSize maxMonthRect;
protected slots:
void dateChangedSlot(QDate);
void tableClickedSlot();
void monthForwardClicked();
void monthBackwardClicked();
void yearForwardClicked();
void yearBackwardClicked();
void selectMonthClicked();
void selectYearClicked();
void lineEnterPressed();
void slotSetDate(QDate);
+ void goToday();
signals:
/** This signal is emitted each time the selected date is changed.
* Usually, this does not mean that the date has been entered,
* since the date also changes, for example, when another month is
* selected.
* @see dateSelected
*/
void dateChanged(QDate);
/** This signal is emitted each time a day has been selected by
* clicking on the table (hitting a day in the current month). It
* has the same meaning as dateSelected() in older versions of
* KDatePicker.
*/
void dateSelected(QDate);
/** This signal is emitted when enter is pressed and a VALID date
* has been entered before into the line edit. Connect to both
* dateEntered() and dateSelected() to receive all events where the
* user really enters a date.
*/
void dateEntered(QDate);
/** This signal is emitted when the day has been selected by
* clicking on it in the table.
*/
void tableClicked();
private:
/// the font size for the widget
int fontsize;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KDatePickerPrivate;
KDatePickerPrivate *d;
void keyPressEvent ( QKeyEvent * ) ;
};
#endif // KDATEPICKER_H