[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KDatePicker improvements
From:       Jakob Petsovits <jpetso () gmx ! at>
Date:       2007-11-22 14:05:33
Message-ID: 200711221505.33636.jpetso () gmx ! at
[Download RAW message or body]

On Thursday, 22. November 2007, Hans Meine wrote:
> Am Donnerstag, 22. November 2007 14:24:35 schrieb Torsten Rahn:
> > By far most people won't look for the "Week number" but just want to know
> >
> > Year, month, day.
> >
> > So "Week" shouldn't have the same Importance and prominence as other
> > items.
>
> Right.
>
> Also, it stands out quite much depending on the UI style - maybe it should
> be more like the month display, which is functionally a combobox, but only
> appears after clicking.  In contrast to that, the week is a regular
> combobox.

Good point... I'll think some more about that.
I believe this is because there are a lot more weeks in there, as opposed to 
only twelve months which have no problem to fit on the screen.

Also, I'll ask the usability list about the "<- month -> <- year ->" approach 
as it seems this is still better than the current one and doable with minimal 
code changes. Let's consider the current patch stalled for now.

> (Maybe it should even be more like the year, where you would just 
> enter a number?  Or even add spinbox controls to that lineedit, also for
> year then?)

That was actually my first attempt - I had a much easier patch working which 
had the year widget as a spinbox, but the conclusion was that it's not ideal 
because horizontal month navigation (left/right) doesn't make a good fit for 
vertical year navigation (up/down).

The bugfixes have been applied - expect me to come back soon with the rest of 
the pending items. For completeness, here's the updated patch that only 
includes the functional changes and leaves out the fixes.

Wishes,
  Jakob

["kdatepicker-usability-attempt-try4.diff" (text/x-diff)]

Index: kdatepicker.h
===================================================================
--- kdatepicker.h	(revision 739813)
+++ kdatepicker.h	(working copy)
@@ -172,6 +172,7 @@
     void selectMonthClicked();
     void selectYearClicked();
     void lineEnterPressed();
+    void copyDateButtonClicked();
     void todayButtonClicked();
     void weekSelected( int );
 
Index: kdatepicker_p.h
===================================================================
--- kdatepicker_p.h	(revision 739813)
+++ kdatepicker_p.h	(working copy)
@@ -3,6 +3,7 @@
     Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
               (C) 1998-2001 Mirko Boehm (mirko@kde.org)
               (C) 1998-2001 Mirko Boehm (john@layt.net)
+              (C) 2007 Jakob Petsovits <jpetso@gmx.at>
     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
@@ -24,9 +25,9 @@
 
 #include <kcalendarsystem.h>
 
-#include <QtCore/QDate>
 #include <QtGui/QLineEdit>
 #include <QtGui/QValidator>
+#include <QtGui/QToolButton>
 
 /** Year selection widget.
 * @internal
@@ -38,23 +39,21 @@
     Q_OBJECT
 
 public:
-    KDatePickerPrivateYearSelector( const KCalendarSystem *calendar, const \
                QDate &currentDate, QWidget *parent = 0 );
-    int year();
-    void setYear( int year );
+    KDatePickerPrivateYearSelector( QToolButton *selectYear, QWidget \
*parent = 0 ); +    void setCalendar( const KCalendarSystem *calendar );
+    virtual QSize sizeHint() const;
 
-public Q_SLOTS:
-    void yearEnteredSlot();
+protected:
+    virtual void focusOutEvent( QFocusEvent *e );
 
 Q_SIGNALS:
-    void closeMe( int );
+    void yearEntered();
 
 protected:
     QIntValidator *val;
-    int result;
 
 private:
-    const KCalendarSystem *calendar;
-    QDate oldDate;
+    QToolButton *selectYear;
 
     Q_DISABLE_COPY( KDatePickerPrivateYearSelector )
 };
Index: kdatepicker.cpp
===================================================================
--- kdatepicker.cpp	(revision 740078)
+++ kdatepicker.cpp	(working copy)
@@ -3,6 +3,7 @@
     Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
               (C) 1998-2001 Mirko Boehm (mirko@kde.org)
               (C) 2007 John Layt <john@layt.net>
+              (C) 2007 Jakob Petsovits <jpetso@gmx.at>
     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
@@ -30,19 +31,20 @@
 #include <QtGui/QMenu>
 #include <QtGui/QPainter>
 #include <QtGui/QStyle>
+#include <QtGui/QLineEdit>
 #include <QtGui/QToolButton>
 #include <QtGui/QDoubleValidator>
+#include <QtGui/QClipboard>
 
 #include <kcalendarsystem.h>
 #include <kcombobox.h>
-#include <kdebug.h>
 #include <kdialog.h>
 #include <kglobal.h>
 #include <kicon.h>
 #include <kiconloader.h>
-#include <klineedit.h>
 #include <klocale.h>
 #include <knotification.h>
+#include <kmenu.h>
 
 #include "kdatepicker.moc"
 #include "kdatepicker_p.moc"
@@ -50,75 +52,52 @@
 // Week numbers are defined by ISO 8601
 // See http://www.merlyn.demon.co.uk/weekinfo.htm for details
 
-KDatePickerPrivateYearSelector::KDatePickerPrivateYearSelector(
-                                const KCalendarSystem *cal, const QDate \
                &currentDate, QWidget* parent )
-                              : QLineEdit( parent ), val( new \
QIntValidator( this ) ), result( 0 ) \
+KDatePickerPrivateYearSelector::KDatePickerPrivateYearSelector( \
QToolButton *selectYear, QWidget* parent ) +          : QLineEdit( parent \
), val( new QIntValidator( this ) ), selectYear( selectYear )  {
-    calendar = cal;
-    oldDate = currentDate;
-
-    QFont font;
-    font = KGlobalSettings::generalFont();
-    setFont( font );
-
+    connect( this, SIGNAL( editingFinished() ), SIGNAL( yearEntered() ) );
     setFrame( false );
-
-    val->setRange( calendar->year( calendar->earliestValidDate() ),
-                   calendar->year( calendar->latestValidDate() ) );
-    setValidator( val );
-
-    connect( this, SIGNAL( returnPressed() ), SLOT( yearEnteredSlot() ) );
+    setAlignment( Qt::AlignHCenter );
 }
 
-void KDatePickerPrivateYearSelector::yearEnteredSlot()
+void KDatePickerPrivateYearSelector::focusOutEvent( QFocusEvent * )
 {
-    bool ok;
-    int newYear;
-    QDate newDate;
-
-    // check if entered value is a number
-    newYear = text().toInt( &ok );
-    if( !ok ) {
-        KNotification::beep();
-        return;
-    }
-
-    // check if new year will lead to a valid date
-    if ( calendar->setDate( newDate, newYear, calendar->month( oldDate ), \
                calendar->day( oldDate ) ) ) {
-        result = newYear;
-        emit( closeMe( 1 ) );
-    } else {
-        KNotification::beep();
-    }
-
+    emit yearEntered();
 }
 
-int KDatePickerPrivateYearSelector::year()
+void KDatePickerPrivateYearSelector::setCalendar( const KCalendarSystem \
*calendar )  {
-    return result;
+    val->setRange( calendar->year( calendar->earliestValidDate() ),
+                   calendar->year( calendar->latestValidDate() ) );
+    setValidator( val );
 }
 
-void KDatePickerPrivateYearSelector::setYear( int year )
+QSize KDatePickerPrivateYearSelector::sizeHint() const
 {
-    setText( QString::number( year ) );
+    return ( selectYear == 0 ) ? QLineEdit::sizeHint() : \
selectYear->size();  }
 
 class KDatePicker::KDatePickerPrivate
 {
 public:
     KDatePickerPrivate( KDatePicker *q ) :
-             q( q ), closeButton( 0L ), selectWeek( 0L ), todayButton( 0 \
), navigationLayout( 0 ) +             q( q ), closeButton( 0 ), \
selectWeek( 0 ), copyDateButton( 0 ), +             todayButton( 0 ), \
navigationLayout( 0 ), yearForward( 0 ), +             yearBackward( 0 ), \
monthForward( 0 ), monthBackward( 0 ), +             selectMonth( 0 ), \
selectYear( 0 ), yearLine( 0 ), table( 0 )  {
     }
 
     void fillWeeksCombo();
     QDate validDateInYearMonth( int year, int month );
 
+public:
     /// the date table
     KDatePicker *q;
 
     QToolButton *closeButton;
-    KComboBox *selectWeek;
+    QComboBox *selectWeek;
+    QToolButton *copyDateButton;
     QToolButton *todayButton;
     QBoxLayout *navigationLayout;
 
@@ -132,12 +111,10 @@
     QToolButton *monthBackward;
     /// the button for selecting the month directly
     QToolButton *selectMonth;
-    /// the button for selecting the year directly
+    /// the button for showing the year selection line edit
     QToolButton *selectYear;
-    /// the line edit to enter the date directly
-    QLineEdit *line;
-    /// the validator for the line edit:
-    KDateValidator *val;
+    /// the line edit to enter the year directly
+    KDatePickerPrivateYearSelector *yearLine;
     /// the date table
     KDateTable *table;
     /// the widest month string in pixels:
@@ -262,7 +239,6 @@
 
 void KDatePicker::init( const QDate &date_ )
 {
-
     QBoxLayout * topLayout = new QVBoxLayout( this );
     topLayout->setSpacing( 0 );
     topLayout->setMargin( 0 );
@@ -271,48 +247,78 @@
     d->navigationLayout->setSpacing( 0 );
     d->navigationLayout->setMargin( 0 );
     topLayout->addLayout( d->navigationLayout );
-    d->navigationLayout->addStretch();
+
+    QBoxLayout * leftLayout = new QVBoxLayout();
+    leftLayout->setSpacing( 0 );
+    leftLayout->setMargin( 0 );
+    d->navigationLayout->addLayout( leftLayout );
+
+    QBoxLayout * yearLayout = new QHBoxLayout();
+    yearLayout->setSpacing( 0 );
+    yearLayout->setMargin( 0 );
+    leftLayout->addLayout( yearLayout );
+
+    yearLayout->addStretch();
     d->yearBackward = new QToolButton( this );
     d->yearBackward->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->yearBackward );
-    d->monthBackward = new QToolButton( this );
-    d->monthBackward ->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->monthBackward );
-    d->navigationLayout->addSpacing( KDialog::spacingHint() );
-
-    d->selectMonth = new QToolButton( this );
-    d->selectMonth ->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->selectMonth );
+    yearLayout->addWidget( d->yearBackward );
     d->selectYear = new QToolButton( this );
-    d->selectYear->setCheckable( true );
     d->selectYear->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->selectYear );
-    d->navigationLayout->addSpacing( KDialog::spacingHint() );
+    yearLayout->addWidget( d->selectYear );
+    d->yearLine = new KDatePickerPrivateYearSelector( d->selectYear, this \
); +    d->yearLine->installEventFilter( this );
+    d->yearLine->setVisible( false );
+    yearLayout->addWidget( d->yearLine );
+    d->yearForward = new QToolButton( this );
+    d->yearForward->setAutoRaise( true );
+    yearLayout->addWidget( d->yearForward );
+    yearLayout->addStretch();
 
+    QBoxLayout * monthLayout = new QHBoxLayout();
+    monthLayout->setSpacing( 0 );
+    monthLayout->setMargin( 0 );
+    leftLayout->addLayout( monthLayout );
+
+    monthLayout->addStretch();
+    d->monthBackward = new QToolButton( this );
+    d->monthBackward->setAutoRaise( true );
+    monthLayout->addWidget( d->monthBackward );
+    d->selectMonth = new QToolButton( this );
+    d->selectMonth->setAutoRaise( true );
+    monthLayout->addWidget( d->selectMonth );
     d->monthForward = new QToolButton( this );
-    d->monthForward ->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->monthForward );
-    d->yearForward = new QToolButton( this );
-    d->yearForward ->setAutoRaise( true );
-    d->navigationLayout->addWidget( d->yearForward );
-    d->navigationLayout->addStretch();
+    d->monthForward->setAutoRaise( true );
+    monthLayout->addWidget( d->monthForward );
+    monthLayout->addStretch();
 
-    d->line = new KLineEdit( this );
-    d->val = new KDateValidator( this );
-    d->table = new KDateTable( this );
-    setFocusProxy( d->table );
+    QBoxLayout * rightLayout = new QVBoxLayout();
+    rightLayout->setSpacing( 0 );
+    rightLayout->setMargin( 0 );
+    d->navigationLayout->addLayout( rightLayout );
 
-    d->fontsize = KGlobalSettings::generalFont().pointSize();
-    if ( d->fontsize == -1 ) {
-        d->fontsize = QFontInfo( KGlobalSettings::generalFont() \
                ).pointSize();
-    }
+    QBoxLayout * weekLayout = new QHBoxLayout();
+    weekLayout->setSpacing( 0 );
+    weekLayout->setMargin( 0 );
+    rightLayout->addLayout( weekLayout );
 
-    d->fontsize++; // Make a little bigger
+    d->selectWeek = new QComboBox( this );  // read only week selection
+    d->selectWeek->setFocusPolicy( Qt::NoFocus );
+    weekLayout->addWidget( d->selectWeek );
 
-    d->selectWeek = new KComboBox( this );  // read only week selection
-    d->selectWeek->setFocusPolicy( Qt::NoFocus );
+    QBoxLayout * buttonLayout = new QHBoxLayout();
+    buttonLayout->setMargin( 0 );
+    buttonLayout->setSpacing( 0 );
+    rightLayout->addLayout( buttonLayout );
+
+    buttonLayout->addStretch();
+    buttonLayout->addSpacing( KDialog::spacingHint() );
+
+    d->copyDateButton = new QToolButton( this );
+    d->copyDateButton->setAutoRaise( true );
+    buttonLayout->addWidget( d->copyDateButton );
     d->todayButton = new QToolButton( this );
-    d->todayButton->setIcon( KIcon( "go-jump-today" ) );
+    d->todayButton->setAutoRaise( true );
+    buttonLayout->addWidget( d->todayButton );
 
     d->yearForward->setToolTip( i18n( "Next year" ) );
     d->yearBackward->setToolTip( i18n( "Previous year" ) );
@@ -321,24 +327,35 @@
     d->selectWeek->setToolTip( i18n( "Select a week" ) );
     d->selectMonth->setToolTip( i18n( "Select a month" ) );
     d->selectYear->setToolTip( i18n( "Select a year" ) );
+    d->copyDateButton->setToolTip( i18n( "Copy date to clipboard" ) );
     d->todayButton->setToolTip( i18n( "Select the current day" ) );
 
-    // -----
-    setFontSize( d->fontsize );
-    d->line->setValidator( d->val );
-    d->line->installEventFilter( this );
     if ( QApplication::isRightToLeft() ) {
-        d->yearForward->setIcon( KIcon( QLatin1String( "arrow-left-double" \
                ) ) );
-        d->yearBackward->setIcon( KIcon( QLatin1String( \
                "arrow-right-double" ) ) );
-        d->monthForward->setIcon( KIcon( QLatin1String( "arrow-left" ) ) \
                );
-        d->monthBackward->setIcon( KIcon( QLatin1String( "arrow-right" ) ) \
); +        d->yearForward->setIcon( KIcon( "go-next-rtl" ) );
+        d->yearBackward->setIcon( KIcon( "go-previous-rtl" ) );
+        d->monthForward->setIcon( KIcon( "go-next-rtl" ) );
+        d->monthBackward->setIcon( KIcon( "go-previous-rtl" ) );
     } else {
-        d->yearForward->setIcon( KIcon( QLatin1String( \
                "arrow-right-double" ) ) );
-        d->yearBackward->setIcon( KIcon( QLatin1String( \
                "arrow-left-double" ) ) );
-        d->monthForward->setIcon( KIcon( QLatin1String( "arrow-right" ) ) \
                );
-        d->monthBackward->setIcon( KIcon( QLatin1String( "arrow-left" ) ) \
); +        d->yearForward->setIcon( KIcon( "go-next" ) );
+        d->yearBackward->setIcon( KIcon( "go-previous" ) );
+        d->monthForward->setIcon( KIcon( "go-next" ) );
+        d->monthBackward->setIcon( KIcon( "go-previous" ) );
     }
+    d->copyDateButton->setIcon( KIcon( "edit-copy" ) );
+    d->todayButton->setIcon( KIcon( "go-jump-today" ) );
 
+    d->table = new KDateTable( this );
+    setFocusProxy( d->table );
+    topLayout->addWidget( d->table );
+
+    // -----
+    d->fontsize = KGlobalSettings::generalFont().pointSize();
+    if ( d->fontsize == -1 ) {
+        d->fontsize = QFontInfo( KGlobalSettings::generalFont() \
).pointSize(); +    }
+    d->fontsize++; // Make a little bigger
+    setFontSize( d->fontsize );
+
     connect( d->table, SIGNAL( dateChanged( const QDate& ) ), SLOT( \
                dateChangedSlot( const QDate& ) ) );
     connect( d->table, SIGNAL( tableClicked() ), SLOT( tableClickedSlot() \
                ) );
     connect( d->monthForward, SIGNAL( clicked() ), SLOT( \
monthForwardClicked() ) ); @@ -346,24 +363,14 @@
     connect( d->yearForward, SIGNAL( clicked() ), SLOT( \
                yearForwardClicked() ) );
     connect( d->yearBackward, SIGNAL( clicked() ), SLOT( \
                yearBackwardClicked() ) );
     connect( d->selectWeek, SIGNAL( activated( int ) ), SLOT( \
weekSelected( int ) ) ); +    connect( d->copyDateButton, SIGNAL( clicked() \
                ), SLOT( copyDateButtonClicked() ) );
     connect( d->todayButton, SIGNAL( clicked() ), SLOT( \
                todayButtonClicked() ) );
     connect( d->selectMonth, SIGNAL( clicked() ), SLOT( \
                selectMonthClicked() ) );
-    connect( d->selectYear, SIGNAL( toggled( bool ) ), SLOT( \
                selectYearClicked() ) );
-    connect( d->line, SIGNAL( returnPressed() ), SLOT( lineEnterPressed() \
) ); +    connect( d->selectYear, SIGNAL( clicked() ), SLOT( \
selectYearClicked() ) ); +    connect( d->yearLine, SIGNAL( yearEntered() \
), SLOT( lineEnterPressed() ) );  
-
-    topLayout->addWidget( d->table );
-
-    QBoxLayout * bottomLayout = new QHBoxLayout();
-    bottomLayout->setMargin( 0 );
-    bottomLayout->setSpacing( 0 );
-    topLayout->addLayout( bottomLayout );
-
-    bottomLayout->addWidget( d->todayButton );
-    bottomLayout->addWidget( d->line );
-    bottomLayout->addWidget( d->selectWeek );
-
     d->table->setDate( date_ );
+    d->yearLine->setCalendar( calendar() );
     dateChangedSlot( date_ );  // needed because table emits changed only \
when newDate != oldDate  }
 
@@ -396,7 +403,6 @@
 
 void KDatePicker::dateChangedSlot( const QDate &date_ )
 {
-    d->line->setText( calendar()->formatDate( date_, KLocale::ShortDate ) \
                );
     d->selectMonth->setText( calendar()->monthName( date_, \
KCalendarSystem::LongName ) );  d->fillWeeksCombo();
 
@@ -412,8 +418,11 @@
     }
     d->selectWeek->setCurrentIndex( ( calendar()->dayOfYear( date_ ) + \
calendar()->dayOfWeek( firstDay ) - 2 ) /  calendar()->daysInWeek( date_ ) \
                );
-    d->selectYear->setText( calendar()->yearString( date_, \
KCalendarSystem::LongFormat ) );  
+    QString year = calendar()->yearString( date_, \
KCalendarSystem::LongFormat ); +    d->selectYear->setText( year );
+    d->yearLine->setText( year );
+
     emit( dateChanged( date_ ) );
 }
 
@@ -536,43 +545,12 @@
 
 void KDatePicker::selectYearClicked()
 {
-    QDate newDate;
+    d->yearLine->adjustSize();
+    d->yearLine->selectAll();
 
-    if ( !d->selectYear->isChecked() ) {
-        return;
-    }
-
-    KPopupFrame *popup = new KPopupFrame( this );
-    KDatePickerPrivateYearSelector *picker = new \
                KDatePickerPrivateYearSelector( calendar(), date(), popup \
                );
-    picker->resize( picker->sizeHint() );
-    picker->setYear( calendar()->year( date() ) );
-    picker->selectAll();
-    popup->setMainWidget( picker );
-    connect( picker, SIGNAL( closeMe( int ) ), popup, SLOT( close( int ) ) \
                );
-    picker->setFocus();
-
-    if( popup->exec( d->selectYear->mapToGlobal( QPoint( 0, \
                d->selectMonth->height() ) ) ) ) {
-        // We need to create a valid date in the year/month selected so we \
                can find out how many
-        // days are in the month.
-        newDate = d->validDateInYearMonth( picker->year(), \
                calendar()->month( date() ) );
-
-        // If we have succeeded in creating a date in the new month, then \
                try to create the new
-        // date, checking we don't set a day after the last day of the \
                month
-        if ( calendar()->isValid( newDate ) ) {
-            calendar()->setDate( newDate,
-                picker->year(), calendar()->month( date() ),
-                qMin( calendar()->day( date() ), calendar()->daysInMonth( \
                newDate ) )
-            );
-        }
-    }
-
-    // Set the date, if it's invalid in any way then alert user and don't \
                update
-    if ( ! setDate( newDate ) ) {
-        KNotification::beep();
-    }
-
-    d->selectYear->setChecked( false );
-    delete popup;
+    d->selectYear->setVisible( false );
+    d->yearLine->setVisible( true );
+    d->yearLine->setFocus();
 }
 
 
@@ -581,9 +559,10 @@
 void KDatePicker::setEnabled( bool enable )
 {
     QWidget * widgets[] = {
-                              d->yearForward, d->yearBackward, \
                d->monthForward, d->monthBackward,
-                              d->selectMonth, d->selectYear,
-                              d->line, d->table, d->selectWeek, \
d->todayButton +                              d->yearForward, \
d->yearBackward, d->monthForward, +                              \
d->monthBackward, d->selectMonth, d->selectYear, +                          \
d->yearLine, d->selectWeek, d->copyDateButton, +                            \
d->todayButton, d->table  };
     const int Size = sizeof( widgets ) / sizeof( widgets[0] );
     int count;
@@ -601,17 +580,67 @@
 
 void KDatePicker::lineEnterPressed()
 {
-    QDate newDate = calendar()->readDate( d->line->text() );
+    bool ok;
+    int newYear;
+    QDate newDate;
 
+    // check if entered value is a number
+    newYear = d->yearLine->text().toInt( &ok );
+    if( !ok ) {
+        KNotification::beep();
+        return;
+    }
+
+    // We need to create a valid date in the year/month selected so we can \
find out how many +    // days are in the month.
+    newDate = d->validDateInYearMonth( newYear, calendar()->month( date() \
) ); +
+    // If we have succeeded in creating a date in the new month, then try \
to create the new +    // date, checking we don't set a day after the last \
day of the month  if ( calendar()->isValid( newDate ) ) {
-        emit( dateEntered( newDate ) );
-        setDate( newDate );
+        calendar()->setDate( newDate,
+            newYear, calendar()->month( date() ),
+            qMin( calendar()->day( date() ), calendar()->daysInMonth( \
newDate ) ) +        );
+    }
+
+    // Set the date, if it's invalid in any way then alert user and don't \
update +    if ( setDate( newDate ) ) {
+        d->yearLine->setVisible( false );
+        d->selectYear->setVisible( true );
         d->table->setFocus();
     } else {
         KNotification::beep();
     }
 }
 
+void KDatePicker::copyDateButtonClicked()
+{
+    d->table->setFocus();
+
+    QString items[] = {
+        calendar()->formatDate( date(), KLocale::ShortDate ),
+        calendar()->formatDate( date(), KLocale::LongDate ),
+    };
+    const int NoOfItems = sizeof( items ) / sizeof( items[0] );
+
+    KMenu popup( d->copyDateButton );
+    popup.addTitle( i18n( "Copy to clipboard" ) );
+
+    for ( int i = 0; i < NoOfItems; i++ ) {
+        popup.addAction( items[i] )->setData(i);
+    }
+
+    QAction *item;
+    QPoint openPos = QPoint( 0, d->copyDateButton->size().height() );
+    if ( ( item = popup.exec( d->copyDateButton->mapToGlobal( openPos ) ) \
) == 0 ) { +        return; // cancelled
+    }
+
+    QString data = items[item->data().toInt()];
+    QApplication::clipboard()->setText( data );
+}
+
 void KDatePicker::todayButtonClicked()
 {
     setDate( QDate::currentDate() );
@@ -625,20 +654,21 @@
 
 void KDatePicker::setFontSize( int s )
 {
-    QWidget * buttons[] = {
+    QWidget * widgets[] = {
                               d->selectMonth,
                               d->selectYear,
+                              d->yearLine
                           };
-    const int NoOfButtons = sizeof( buttons ) / sizeof( buttons[0] );
+    const int NoOfButtons = sizeof( widgets ) / sizeof( widgets[0] );
     int count;
     QFont font;
     QRect r;
     // -----
     d->fontsize = s;
     for( count = 0; count < NoOfButtons; ++count ) {
-        font = buttons[count]->font();
+        font = widgets[count]->font();
         font.setPointSize( s );
-        buttons[count]->setFont( font );
+        widgets[count]->setFont( font );
     }
     d->table->setFontSize( s );
 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic