[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: [Patch] #48264: added a Today button in kdatepicker
From: Martin Koller <m.koller () surfeu ! at>
Date: 2003-08-15 15:14:48
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 14 August 2003 23:45, Aaron J. Seigo wrote:
> On Thursday 14 August 2003 02:35, Martin Koller wrote:
> > General question: What is the policy regarding modification of the API
> > from 3.1 to 3.2 ?
>
> http://developer.kde.org/documentation/library/kdeqt/kde3arch/devel-
> binarycompatibility.html
Thanks.
>
> > In this case I would change a protected slot (e.g. selectWeekClicked())
> > to selectWeekClicked(const QString &)
> > Or shall I (to be code compatible) leave the old slot, which then does
> > nothing ?
>
> hrm... well, personally i wouldn't use a KComboBox, i'd keep it a
> pushbutton and simply add a popup to it using setPopup(QPopup*)...
> comboboxes tend to take up more space; the button is a good UI element
> IMHO, it just needs a popup menu rather than a popup lineedit...
>
> regardless, the existing slot needs to remain. perhaps it would be best if
> it were called prior to showing the menu (e.g. aboutToShow()) in case
> someone has subclassed it and reimplemented the slot to do some
> pre-processing? of course, if anyone has subclassed it and reimplemented
> the slot without calling the parent's implementation (in order to do their
> own selection stuff), then that would be problematic, i suppose.
> perhaps one way to do it would be to connect QPushButton::aboutToShow() to
> selectWeekClicked() and set up the menu in there?
The slot is not virtual.
So I leave it as an empty function.
Here is the patch which includes:
1) Added the Today Button with the today icon (without autoraise)
2) Changed the week selection to a QComboBox (without autoraise)
3) Changed the month selection to a standard popup menu
I'll leave the year selection for now as it is.
Maybe I find time to change this also.
If OK, please commit.
Thanks
- --
Best regards/Schöne Grüße
Martin
Public key at:
http://blackhole.pca.dfn.de:11371/pks/lookup?op=get&search=0x8DFB0F86
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE/PPjoHmdPoI37D4YRAjSuAKCCaW8l5aGpJ3WRuRqZUHsZmfuVvQCfX1RD
29rkTvqc0x24mwnWB5QrBqY=
=3oEA
-----END PGP SIGNATURE-----
["patch.2" (application/octet-stream)]
Index: kdatepicker.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kdatepicker.cpp,v
retrieving revision 1.60
diff -u -3 -p -r1.60 kdatepicker.cpp
--- kdatepicker.cpp 17 Jul 2003 21:02:04 -0000 1.60
+++ kdatepicker.cpp 15 Aug 2003 15:07:09 -0000
@@ -24,9 +24,11 @@
#include <qdialog.h>
#include <qstyle.h>
#include <qtoolbutton.h>
+#include <qcombobox.h>
#include <qtooltip.h>
#include <qfont.h>
#include <qvalidator.h>
+#include <qpopupmenu.h>
#include "kdatepicker.h"
#include <kglobal.h>
@@ -45,14 +47,30 @@
class KDatePicker::KDatePickerPrivate
{
public:
- KDatePickerPrivate() : closeButton(0L), selectWeek(0L), navigationLayout(0) {}
+ KDatePickerPrivate() : closeButton(0L), selectWeek(0L), todayButton(0), \
navigationLayout(0) {} +
+ void fillWeeksCombo(const QDate &date);
KToolBar *tb;
QToolButton *closeButton;
- QToolButton *selectWeek;
+ QComboBox *selectWeek;
+ QToolButton *todayButton;
QBoxLayout *navigationLayout;
};
+void KDatePicker::KDatePickerPrivate::fillWeeksCombo(const QDate &date)
+{
+ // every year can have a different number of weeks
+ const KCalendarSystem * calendar = KGlobal::locale()->calendar();
+ int i, weeks = calendar->weeksInYear(calendar->year(date));
+
+ if ( selectWeek->count() == weeks ) return; // we already have the correct number
+
+ selectWeek->clear();
+
+ for (i = 1; i <= weeks; i++)
+ selectWeek->insertItem(i18n("Week %1").arg(i));
+}
KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
: QFrame(parent,name)
@@ -93,8 +111,9 @@ void KDatePicker::init( const QDate &dt
fontsize++; // Make a little bigger
- d->selectWeek = new QToolButton( this );
- d->selectWeek->setAutoRaise(true);
+ d->selectWeek = new QComboBox(false, this); // read only week selection
+ d->todayButton = new QToolButton(this);
+ d->todayButton->setPixmap(SmallIcon("today"));
QToolTip::add(yearForward, i18n("Next year"));
QToolTip::add(yearBackward, i18n("Previous year"));
@@ -103,6 +122,7 @@ void KDatePicker::init( const QDate &dt
QToolTip::add(d->selectWeek, i18n("Select a week"));
QToolTip::add(selectMonth, i18n("Select a month"));
QToolTip::add(selectYear, i18n("Select a year"));
+ QToolTip::add(d->todayButton, i18n("Select the current day"));
// -----
setFontSize(fontsize);
@@ -119,7 +139,8 @@ void KDatePicker::init( const QDate &dt
connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
- connect(d->selectWeek, SIGNAL(clicked()), SLOT(selectWeekClicked()));
+ connect(d->selectWeek, SIGNAL(activated(int)), SLOT(weekSelected(int)));
+ connect(d->todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
@@ -133,6 +154,7 @@ void KDatePicker::init( const QDate &dt
topLayout->addWidget(table);
QBoxLayout * bottomLayout = new QHBoxLayout(topLayout);
+ bottomLayout->addWidget(d->todayButton);
bottomLayout->addWidget(line);
bottomLayout->addWidget(d->selectWeek);
}
@@ -175,8 +197,9 @@ KDatePicker::dateChangedSlot(QDate date)
const KCalendarSystem * calendar = KGlobal::locale()->calendar();
line->setText(KGlobal::locale()->formatDate(date, true));
- d->selectWeek->setText(i18n("Week %1").arg(calendar->weekNumber(date)));
selectMonth->setText(calendar->monthName(date, false));
+ d->fillWeeksCombo(date);
+ d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
selectYear->setText(QString().setNum(calendar->year(date)));
emit(dateChanged(date));
@@ -211,8 +234,9 @@ KDatePicker::setDate(const QDate& date)
QString temp;
// -----
table->setDate(date);
- d->selectWeek->setText(i18n("Week %1").arg(calendar->weekNumber(date)));
- selectMonth->setText(calendar->monthName(date, false));
+ selectMonth->setText(calendar->monthName(date, false));
+ d->fillWeeksCombo(date);
+ d->selectWeek->setCurrentItem(calendar->weekNumber(date) - 1);
temp.setNum(calendar->year(date));
selectYear->setText(temp);
line->setText(KGlobal::locale()->formatDate(date, true));
@@ -259,75 +283,55 @@ KDatePicker::yearBackwardClicked()
setDate( temp );
}
+void KDatePicker::selectWeekClicked() {} // ### in 3.2 obsolete; kept for binary \
compatibility +
void
-KDatePicker::selectWeekClicked()
+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);
- KPopupFrame* popup = new KPopupFrame(this);
- KDateInternalWeekSelector* picker = new KDateInternalWeekSelector(popup);
- picker->setMaxWeek(calendar->weeksInYear(calendar->year(date)));
- // -----
- picker->resize(picker->sizeHint());
- popup->setMainWidget(picker);
- connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
- picker->setFocus();
- if(popup->exec(d->selectWeek->mapToGlobal(QPoint(0, d->selectWeek->height()))))
- {
- int week = picker->getWeek();
- 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);
- 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);
- // date is now first day in week 1 some day in week 1
- date = calendar->addDays(date, (week - calendar->weekNumber(date)) * 7);
-
- setDate(date);
- }
- else
- {
- KNotifyClient::beep();
- }
-
- delete popup;
+ 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 = new QPopupMenu(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; // cancelled +
+ 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);
- int month;
- KPopupFrame* popup = new KPopupFrame(this);
- KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(table->getDate(), \
popup);
- // -----
- picker->resize(picker->sizeHint());
- popup->setMainWidget(picker);
- picker->setFocus();
- connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
- if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
- {
- QDate date;
- int day;
- // -----
- month=picker->getResult();
- date=table->getDate();
- 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);
- } else {
- KNotifyClient::beep();
- }
delete popup;
}
@@ -395,6 +399,12 @@ KDatePicker::lineEnterPressed()
KNotifyClient::beep();
kdDebug(298) << "KDatePicker::lineEnterPressed: invalid date entered." << \
endl; }
+}
+
+void
+KDatePicker::todayButtonClicked()
+{
+ setDate(QDate::currentDate());
}
QSize
Index: kdatepicker.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kdatepicker.h,v
retrieving revision 1.34
diff -u -3 -p -r1.34 kdatepicker.h
--- kdatepicker.h 15 Feb 2003 03:14:01 -0000 1.34
+++ kdatepicker.h 15 Aug 2003 15:07:09 -0000
@@ -184,10 +184,14 @@ protected slots:
void yearForwardClicked();
void yearBackwardClicked();
/// @since 3.1
- void selectWeekClicked();
+ void selectWeekClicked(); // ### in 3.2 obsolete; kept for binary compatibility
void selectMonthClicked();
void selectYearClicked();
void lineEnterPressed();
+ /// @since 3.2
+ void todayButtonClicked();
+ void weekSelected(int);
+
signals:
/** This signal is emitted each time the selected date is changed.
* Usually, this does not mean that the date has been entered,
["today.png" (image/png)]
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic