summaryrefslogtreecommitdiffabout
path: root/libkdepim/kdatepicker.cpp
Side-by-side diff
Diffstat (limited to 'libkdepim/kdatepicker.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/kdatepicker.cpp12
1 files changed, 11 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
@@ -26,76 +26,79 @@
#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;
@@ -115,82 +118,89 @@ KDatePicker::resizeEvent(QResizeEvent*)
}
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));