summaryrefslogtreecommitdiffabout
path: root/microkde/kdatepickernew.cpp
Side-by-side diff
Diffstat (limited to 'microkde/kdatepickernew.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdatepickernew.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdatepickernew.cpp b/microkde/kdatepickernew.cpp
index f60a422..8f8001e 100644
--- a/microkde/kdatepickernew.cpp
+++ b/microkde/kdatepickernew.cpp
@@ -188,257 +188,257 @@ KDatePicker::resizeEvent(QResizeEvent* e)
QWidget::resizeEvent(e);
}
void
KDatePicker::dateChangedSlot(QDate date)
{
kdDebug(298) << "KDatePicker::dateChangedSlot: date changed (" << date.year() << "/" << date.month() << "/" << date.day() << ")." << endl;
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
line->setText(KGlobal::locale()->formatDate(date, true));
selectMonth->setText(calendar->monthName(date, false));
fillWeeksCombo(date);
d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
selectYear->setText(calendar->yearString(date, false));
emit(dateChanged(date));
}
void
KDatePicker::tableClickedSlot()
{
kdDebug(298) << "KDatePicker::tableClickedSlot: table clicked." << endl;
emit(dateSelected(table->getDate()));
emit(tableClicked());
}
const QDate&
KDatePicker::getDate() const
{
return table->getDate();
}
const QDate &
KDatePicker::date() const
{
return table->getDate();
}
bool
KDatePicker::setDate(const QDate& date)
{
if(date.isValid())
{
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
table->setDate(date);
fillWeeksCombo(date);
d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
selectMonth->setText(calendar->monthName(date, false));
selectYear->setText(calendar->yearString(date, true));
line->setText(KGlobal::locale()->formatDate(date, true));
return true;
}
else
{
kdDebug(298) << "KDatePicker::setDate: refusing to set invalid date." << endl;
return false;
}
}
void
KDatePicker::monthForwardClicked()
{
QDate temp;
temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), 1 );
setDate( temp );
}
void
KDatePicker::monthBackwardClicked()
{
QDate temp;
temp = KGlobal::locale()->calendar()->addMonths( table->getDate(), -1 );
setDate( temp );
}
void
KDatePicker::yearForwardClicked()
{
QDate temp;
temp = KGlobal::locale()->calendar()->addYears( table->getDate(), 1 );
setDate( temp );
}
void
KDatePicker::yearBackwardClicked()
{
QDate temp;
temp = KGlobal::locale()->calendar()->addYears( table->getDate(), -1 );
setDate( temp );
}
void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary compatibility
void
KDatePicker::weekSelected(int week)
{
week++; // week number starts with 1
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
QDate date = table->getDate();
int year = calendar->year(date);
calendar->setYMD(date, year, 1, 1);
date = calendar->addDays(date, -7);
while (calendar->weekNumber(date) != 1)
date = calendar->addDays(date, 1);
// date is now first day in week 1 some day in week 1
date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7);
setDate(date);
}
void
KDatePicker::selectMonthClicked()
{
// every year can have different month names (in some calendar systems)
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
QDate date = table->getDate();
int i, month, months = calendar->monthsInYear(date);
- QPopupMenu popup(selectMonth);
+ Q3PopupMenu popup(selectMonth);
for (i = 1; i <= months; i++)
popup.insertItem(calendar->monthName(i, calendar->year(date)), i);
popup.setActiveItem(calendar->month(date) - 1);
if ( (month = popup.exec(selectMonth->mapToGlobal(QPoint(0, 0)), calendar->month(date) - 1)) == -1 ) return; // canceled
int day = calendar->day(date);
// ----- construct a valid date in this month:
//date.setYMD(date.year(), month, 1);
//date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
calendar->setYMD(date, calendar->year(date), month,
QMIN(day, calendar->daysInMonth(date)));
// ----- set this month
setDate(date);
}
void
KDatePicker::selectYearClicked()
{
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
int year;
KPopupFrame* popup = new KPopupFrame(this);
KDateInternalYearSelector* picker = new KDateInternalYearSelector(popup);
// -----
picker->resize(picker->sizeHint());
popup->setMainWidget(picker);
connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
picker->setFocus();
if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
{
QDate date;
int day;
// -----
year=picker->getYear();
date=table->getDate();
day=calendar->day(date);
// ----- construct a valid date in this month:
//date.setYMD(year, date.month(), 1);
//date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
calendar->setYMD(date, year, calendar->month(date),
QMIN(day, calendar->daysInMonth(date)));
// ----- set this month
setDate(date);
} else {
KNotifyClient::beep();
}
delete popup;
}
void
KDatePicker::setEnabled(bool enable)
{
QWidget *widgets[]= {
yearForward, yearBackward, monthForward, monthBackward,
selectMonth, selectYear,
line, table, d->selectWeek, d->todayButton };
const int Size=sizeof(widgets)/sizeof(widgets[0]);
int count;
// -----
for(count=0; count<Size; ++count)
{
widgets[count]->setEnabled(enable);
}
}
void
KDatePicker::lineEnterPressed()
{
QDate temp;
// -----
if(val->date(line->text(), temp)==QValidator::Acceptable)
{
kdDebug(298) << "KDatePicker::lineEnterPressed: valid date entered." << endl;
emit(dateEntered(temp));
setDate(temp);
} else {
KNotifyClient::beep();
kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << endl;
}
}
void
KDatePicker::todayButtonClicked()
{
setDate(QDate::currentDate());
}
QSize
KDatePicker::sizeHint() const
{
return QWidget::sizeHint();
}
void
KDatePicker::setFontSize(int s)
{
QWidget *buttons[]= {
// yearBackward,
// monthBackward,
selectMonth,
selectYear,
// monthForward,
// yearForward
};
const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
int count;
QFont font;
QRect r;
// -----
fontsize=s;
for(count=0; count<NoOfButtons; ++count)
{
font=buttons[count]->font();
font.setPointSize(s);
buttons[count]->setFont(font);
}
QFontMetrics metrics(selectMonth->fontMetrics());
for (int i = 1; ; ++i)
{
QString str = KGlobal::locale()->calendar()->monthName(i,
KGlobal::locale()->calendar()->year(table->getDate()), false);
if (str.isNull()) break;
r=metrics.boundingRect(str);
maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));