mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kdeui: replace KDatePicker/KDateTable with new KCalendarWidget class
interestingly QLocale is not used for many things but that is about to change, Katie uses it a lot internally (e.g. for QDateTime formatting and such) so instead of bolting a calendar system on top of KLocale perhaps a QLocale wrapped around in KLocale will fit the general idea of using QLocale in widgets when necessary (as does QCalendarWidget). that however means no way to specify a calendar system (in general, other than changing the widgets locale itself) but the QDateTime and related classes are tied to gregorian calendar already - the system time itself carries no information about the calendar and any conversions from one calendar to another are basically made up stuff (there is the time zone thing ofcourse but that is not a calendar) another interesting thing to note is that KLocale was written such that it is read-write - changing the date formats for example is possible because there are public KLocale methods for that. Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e84a04fa67
commit
061a11fd43
20 changed files with 98 additions and 2235 deletions
|
@ -80,8 +80,7 @@ install(
|
|||
KDebug
|
||||
KDEDModule
|
||||
KDEPrintDialog
|
||||
KDatePicker
|
||||
KDateTable
|
||||
KCalendarWidget
|
||||
KDateTime
|
||||
KDateValidator
|
||||
KDBusMenuExporter
|
||||
|
|
1
includes/KCalendarWidget
Normal file
1
includes/KCalendarWidget
Normal file
|
@ -0,0 +1 @@
|
|||
#include "../kcalendarwidget.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../kdatepicker.h"
|
|
@ -1 +0,0 @@
|
|||
#include "../kdatetable.h"
|
|
@ -1353,7 +1353,6 @@ private:
|
|||
friend class KLocalizedDate;
|
||||
friend class KLocalizedDatePrivate;
|
||||
friend class KDateTimeParser;
|
||||
friend class KDateTable;
|
||||
|
||||
// Era functions needed by friends, may be made public later if needed in KCM
|
||||
QList<KCalendarEra> *eraList() const;
|
||||
|
|
|
@ -95,11 +95,10 @@ void KTimeZonesTest::zoneinfoDir()
|
|||
|
||||
void KTimeZonesTest::abbreviation()
|
||||
{
|
||||
QDateTime gmt(QDate(2006, 3, 26), QTime(0, 59, 0), Qt::UTC);
|
||||
QDateTime bst(QDate(2006, 3, 26), QTime(1, 0, 0), Qt::UTC);
|
||||
|
||||
KTimeZone london = KSystemTimeZones::zone("Europe/London");
|
||||
QVERIFY(london.isValid());
|
||||
QDateTime gmt(QDate(2006, 3, 26), QTime(0, 59, 0), Qt::UTC);
|
||||
QDateTime bst(QDate(2006, 3, 26), QTime(1, 0, 0), Qt::UTC);
|
||||
QCOMPARE(london.abbreviation(gmt), QByteArray("GMT"));
|
||||
QCOMPARE(london.abbreviation(bst), QByteArray("BST"));
|
||||
|
||||
|
|
|
@ -206,8 +206,7 @@ set(kdeui_LIB_SRCS
|
|||
widgets/kcmodule.cpp
|
||||
widgets/kcombobox.cpp
|
||||
widgets/kcompletionbox.cpp
|
||||
widgets/kdatepicker.cpp
|
||||
widgets/kdatetable.cpp
|
||||
widgets/kcalendarwidget.cpp
|
||||
widgets/keditlistwidget.cpp
|
||||
widgets/khbox.cpp
|
||||
widgets/khelpmenu.cpp
|
||||
|
@ -506,8 +505,7 @@ install(
|
|||
util/kpixmapsequencewidget.h
|
||||
util/kimageio.h
|
||||
widgets/kactionselector.h
|
||||
widgets/kdatepicker.h
|
||||
widgets/kdatetable.h
|
||||
widgets/kcalendarwidget.h
|
||||
widgets/kcapacitybar.h
|
||||
widgets/kcmodule.h
|
||||
widgets/kcombobox.h
|
||||
|
|
|
@ -133,7 +133,7 @@ void KConfigDialogManager::initMaps()
|
|||
s_changedMap->insert( "KColorCombo", SIGNAL(activated(QColor)));
|
||||
|
||||
s_changedMap->insert( "KColorButton", SIGNAL(changed(QColor)));
|
||||
s_changedMap->insert( "KDatePicker", SIGNAL(dateSelected(QDate)));
|
||||
s_changedMap->insert( "KCalendarWidget", SIGNAL(activated(QDate)));
|
||||
s_changedMap->insert( "KEditListBox", SIGNAL(changed()));
|
||||
s_changedMap->insert( "KEditListWidget", SIGNAL(changed()));
|
||||
s_changedMap->insert( "KListWidget", SIGNAL(itemSelectionChanged()));
|
||||
|
|
49
kdeui/widgets/kcalendarwidget.cpp
Normal file
49
kdeui/widgets/kcalendarwidget.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kcalendarwidget.h"
|
||||
#include "kglobal.h"
|
||||
#include "klocale.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
static void setupCalendarWidget(KCalendarWidget *kcalendarwidget, const QDate &date)
|
||||
{
|
||||
const QString klocalelanguage = KGlobal::locale()->language();
|
||||
QLocale calendarlocale = QLocale(klocalelanguage);
|
||||
if (calendarlocale.name() == QLatin1String("C")) {
|
||||
calendarlocale = QLocale::system();
|
||||
kWarning() << "Could not create locale for" << klocalelanguage;
|
||||
}
|
||||
|
||||
kcalendarwidget->setLocale(calendarlocale);
|
||||
kcalendarwidget->setSelectedDate(date);
|
||||
}
|
||||
|
||||
KCalendarWidget::KCalendarWidget(QWidget *parent)
|
||||
: QCalendarWidget(parent)
|
||||
{
|
||||
setupCalendarWidget(this, QDate::currentDate());
|
||||
}
|
||||
|
||||
KCalendarWidget::KCalendarWidget(const QDate &date, QWidget *parent)
|
||||
: QCalendarWidget(parent)
|
||||
{
|
||||
setupCalendarWidget(this, date);
|
||||
}
|
40
kdeui/widgets/kcalendarwidget.h
Normal file
40
kdeui/widgets/kcalendarwidget.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2, as published by the Free Software Foundation.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KCALENDARWIDGET_H
|
||||
#define KCALENDARWIDGET_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QCalendarWidget>
|
||||
#include <klocale.h>
|
||||
|
||||
/*!
|
||||
Class to pick a date.
|
||||
|
||||
@since 4.23
|
||||
*/
|
||||
class KDEUI_EXPORT KCalendarWidget: public QCalendarWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KCalendarWidget(QWidget *parent = nullptr);
|
||||
KCalendarWidget(const QDate &date, QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
#endif // KCALENDARWIDGET_H
|
|
@ -1,671 +0,0 @@
|
|||
/* -*- C++ -*-
|
||||
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)
|
||||
(C) 2007 John Layt <john@layt.net>
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdatepicker.h"
|
||||
#include "kdatepicker_p.h"
|
||||
#include "kdatetable.h"
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QFont>
|
||||
#include <QtGui/QFontDatabase>
|
||||
#include <QtGui/QLayout>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QStyle>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/qvalidator.h>
|
||||
|
||||
#include <kcalendarsystem.h>
|
||||
#include <klocalizeddate.h>
|
||||
#include <kcombobox.h>
|
||||
#include <kdebug.h>
|
||||
#include <kdialog.h>
|
||||
#include <kglobal.h>
|
||||
#include <kicon.h>
|
||||
#include <kiconloader.h>
|
||||
#include <klineedit.h>
|
||||
#include <knotification.h>
|
||||
|
||||
#include "moc_kdatepicker.cpp"
|
||||
#include "moc_kdatepicker_p.cpp"
|
||||
|
||||
// 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 ¤tDate, QWidget* parent )
|
||||
: QLineEdit( parent ), val( new QIntValidator( this ) ), result( 0 )
|
||||
{
|
||||
calendar = cal;
|
||||
oldDate = currentDate;
|
||||
|
||||
setFont( KGlobalSettings::generalFont() );
|
||||
|
||||
setFrame( false );
|
||||
|
||||
val->setRange( calendar->year( calendar->earliestValidDate() ),
|
||||
calendar->year( calendar->latestValidDate() ) );
|
||||
setValidator( val );
|
||||
|
||||
connect( this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()) );
|
||||
}
|
||||
|
||||
void KDatePickerPrivateYearSelector::yearEnteredSlot()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int KDatePickerPrivateYearSelector::year()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
void KDatePickerPrivateYearSelector::setYear( int year )
|
||||
{
|
||||
setText( QString::number( year ) );
|
||||
}
|
||||
|
||||
class KDatePicker::KDatePickerPrivate
|
||||
{
|
||||
public:
|
||||
KDatePickerPrivate( KDatePicker *q ) :
|
||||
q( q ), closeButton( 0L ), selectWeek( 0L ), todayButton( 0 ), navigationLayout( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
void fillWeeksCombo();
|
||||
QDate validDateInYearMonth( int year, int month );
|
||||
|
||||
/// the date table
|
||||
KDatePicker *q;
|
||||
|
||||
QToolButton *closeButton;
|
||||
KComboBox *selectWeek;
|
||||
QToolButton *todayButton;
|
||||
QBoxLayout *navigationLayout;
|
||||
|
||||
/// 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;
|
||||
/// the validator for the line edit:
|
||||
KDateValidator *val;
|
||||
/// the date table
|
||||
KDateTable *table;
|
||||
/// the widest month string in pixels:
|
||||
QSize maxMonthRect;
|
||||
|
||||
/// the font size for the widget
|
||||
int fontsize;
|
||||
};
|
||||
|
||||
void KDatePicker::KDatePickerPrivate::fillWeeksCombo()
|
||||
{
|
||||
// every year can have a different number of weeks
|
||||
// it could be that we had 53,1..52 and now 1..53 which is the same number but different
|
||||
// so always fill with new values
|
||||
// We show all week numbers for all weeks between first day of year to last day of year
|
||||
// This of course can be a list like 53,1,2..52
|
||||
|
||||
KLocalizedDate thisDate( q->date(), q->calendar() );
|
||||
int thisYear = thisDate.year();
|
||||
KLocalizedDate day = thisDate.firstDayOfYear();
|
||||
KLocalizedDate lastDayOfYear = thisDate.lastDayOfYear();
|
||||
|
||||
selectWeek->clear();
|
||||
|
||||
// Starting from the first day in the year, loop through the year a week at a time
|
||||
// adding an entry to the week combo for each week in the year
|
||||
|
||||
for ( ; day.isValid() && day <= lastDayOfYear; day.addDaysTo( day.daysInWeek() ) ) {
|
||||
|
||||
// Get the ISO week number for the current day and what year that week is in
|
||||
// e.g. 1st day of this year may fall in week 53 of previous year
|
||||
int weekYear = thisYear;
|
||||
day.week( &weekYear );
|
||||
QString weekString = i18n( "Week %1", day.formatDate( KLocale::Week, KLocale::ShortNumber ) );
|
||||
|
||||
// show that this is a week from a different year
|
||||
if ( weekYear != thisYear ) {
|
||||
weekString += '*';
|
||||
}
|
||||
|
||||
// when the week is selected, go to the same weekday as the one
|
||||
// that is currently selected in the date table
|
||||
QDate targetDate = day.addDays( thisDate.dayOfWeek() - day.dayOfWeek() ).date();
|
||||
selectWeek->addItem( weekString, targetDate );
|
||||
|
||||
// make sure that the week of the lastDayOfYear is always inserted: in Chinese calendar
|
||||
// system, this is not always the case
|
||||
if ( day < lastDayOfYear &&
|
||||
day.daysDifference( lastDayOfYear ) < day.daysInWeek() &&
|
||||
lastDayOfYear.week() != day.week() ) {
|
||||
day = lastDayOfYear.addDays( - thisDate.daysInWeek() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QDate KDatePicker::KDatePickerPrivate::validDateInYearMonth( int year, int month )
|
||||
{
|
||||
QDate newDate;
|
||||
|
||||
// Try to create a valid date in this year and month
|
||||
// First try the first of the month, then try last of month
|
||||
if ( q->calendar()->isValid( year, month, 1 ) ) {
|
||||
q->calendar()->setDate( newDate, year, month, 1 );
|
||||
} else if ( q->calendar()->isValid( year, month + 1, 1 ) ) {
|
||||
q->calendar()->setDate( newDate, year, month, 1 );
|
||||
q->calendar()->addDays( newDate, -1 );
|
||||
} else {
|
||||
newDate = QDate::fromJulianDay( 0 );
|
||||
}
|
||||
|
||||
return newDate;
|
||||
}
|
||||
|
||||
KDatePicker::KDatePicker( QWidget* parent ) : QFrame( parent ), d( new KDatePickerPrivate( this ) )
|
||||
{
|
||||
init( QDate::currentDate() );
|
||||
}
|
||||
|
||||
KDatePicker::KDatePicker( const QDate& date_, QWidget* parent )
|
||||
: QFrame( parent ), d( new KDatePickerPrivate( this ) )
|
||||
{
|
||||
init( date_ );
|
||||
}
|
||||
|
||||
void KDatePicker::init( const QDate &date_ )
|
||||
{
|
||||
QBoxLayout * topLayout = new QVBoxLayout( this );
|
||||
topLayout->setSpacing( 0 );
|
||||
topLayout->setMargin( 0 );
|
||||
|
||||
d->navigationLayout = new QHBoxLayout();
|
||||
d->navigationLayout->setSpacing( 0 );
|
||||
d->navigationLayout->setMargin( 0 );
|
||||
topLayout->addLayout( d->navigationLayout );
|
||||
d->navigationLayout->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 );
|
||||
d->selectYear = new QToolButton( this );
|
||||
d->selectYear->setCheckable( true );
|
||||
d->selectYear->setAutoRaise( true );
|
||||
d->navigationLayout->addWidget( d->selectYear );
|
||||
d->navigationLayout->addSpacing( KDialog::spacingHint() );
|
||||
|
||||
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->line = new KLineEdit( this );
|
||||
d->val = new KDateValidator( this );
|
||||
d->table = new KDateTable( this );
|
||||
setFocusProxy( d->table );
|
||||
|
||||
QFont generalFont = KGlobalSettings::generalFont();
|
||||
d->fontsize = generalFont.pointSize();
|
||||
if ( d->fontsize == -1 ) {
|
||||
QFontDatabase fdb;
|
||||
d->fontsize = fdb.font(generalFont.family(), generalFont.styleName(), generalFont.pointSize()).pointSize();
|
||||
}
|
||||
|
||||
d->fontsize++; // Make a little bigger
|
||||
|
||||
d->selectWeek = new KComboBox( this ); // read only week selection
|
||||
d->selectWeek->setFocusPolicy( Qt::NoFocus );
|
||||
d->todayButton = new QToolButton( this );
|
||||
d->todayButton->setIcon( KIcon( "go-jump-today" ) );
|
||||
|
||||
d->yearForward->setToolTip( i18n( "Next year" ) );
|
||||
d->yearBackward->setToolTip( i18n( "Previous year" ) );
|
||||
d->monthForward->setToolTip( i18n( "Next month" ) );
|
||||
d->monthBackward->setToolTip( i18n( "Previous month" ) );
|
||||
d->selectWeek->setToolTip( i18n( "Select a week" ) );
|
||||
d->selectMonth->setToolTip( i18n( "Select a month" ) );
|
||||
d->selectYear->setToolTip( i18n( "Select a year" ) );
|
||||
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" ) ) );
|
||||
} 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" ) ) );
|
||||
}
|
||||
|
||||
connect( d->table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)) );
|
||||
connect( d->table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()) );
|
||||
connect( d->monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()) );
|
||||
connect( d->monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()) );
|
||||
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->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()) );
|
||||
|
||||
|
||||
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_ );
|
||||
dateChangedSlot( date_ ); // needed because table emits changed only when newDate != oldDate
|
||||
}
|
||||
|
||||
KDatePicker::~KDatePicker()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool KDatePicker::eventFilter( QObject *o, QEvent *e )
|
||||
{
|
||||
if ( e->type() == QEvent::KeyPress ) {
|
||||
QKeyEvent * k = ( QKeyEvent * )e;
|
||||
|
||||
if ( ( k->key() == Qt::Key_PageUp ) ||
|
||||
( k->key() == Qt::Key_PageDown ) ||
|
||||
( k->key() == Qt::Key_Up ) ||
|
||||
( k->key() == Qt::Key_Down ) ) {
|
||||
QApplication::sendEvent( d->table, e );
|
||||
d->table->setFocus();
|
||||
return true; // eat event
|
||||
}
|
||||
}
|
||||
return QFrame::eventFilter( o, e );
|
||||
}
|
||||
|
||||
void KDatePicker::resizeEvent( QResizeEvent* e )
|
||||
{
|
||||
QWidget::resizeEvent( e );
|
||||
}
|
||||
|
||||
void KDatePicker::dateChangedSlot( const QDate &date_ )
|
||||
{
|
||||
KLocalizedDate thisDate( date_, calendar() );
|
||||
d->line->setText( thisDate.formatDate( KLocale::ShortDate ) );
|
||||
d->selectMonth->setText( thisDate.formatDate( KLocale::Month, KLocale::LongName ) );
|
||||
d->fillWeeksCombo();
|
||||
|
||||
// calculate the item num in the week combo box; normalize selected day so as if 1.1. is the first day of the week
|
||||
KLocalizedDate firstDay = thisDate.firstDayOfYear();
|
||||
// If we cannot successfully create the 1st of the year, this can only mean that
|
||||
// the 1st is before the earliest valid date in the current calendar system, so use
|
||||
// the earliestValidDate as the first day.
|
||||
// In particular covers the case of Gregorian where 1/1/-4713 is not a valid QDate
|
||||
d->selectWeek->setCurrentIndex( ( thisDate.dayOfYear() + firstDay.dayOfWeek() - 2 ) /
|
||||
thisDate.daysInWeek() );
|
||||
d->selectYear->setText( thisDate.formatDate( KLocale::Year, KLocale::LongNumber ) );
|
||||
|
||||
emit( dateChanged( date_ ) );
|
||||
}
|
||||
|
||||
void KDatePicker::tableClickedSlot()
|
||||
{
|
||||
emit( dateSelected( date() ) );
|
||||
emit( tableClicked() );
|
||||
}
|
||||
|
||||
const QDate & KDatePicker::date() const
|
||||
{
|
||||
return d->table->date();
|
||||
}
|
||||
|
||||
bool KDatePicker::setDate( const QDate &date_ )
|
||||
{
|
||||
// the table setDate does validity checking for us
|
||||
// this also emits dateChanged() which then calls our dateChangedSlot()
|
||||
return d->table->setDate( date_ );
|
||||
}
|
||||
|
||||
const KCalendarSystem *KDatePicker::calendar() const
|
||||
{
|
||||
return d->table->calendar();
|
||||
}
|
||||
|
||||
bool KDatePicker::setCalendar( KCalendarSystem *calendar )
|
||||
{
|
||||
return d->table->setCalendar( calendar );
|
||||
}
|
||||
|
||||
bool KDatePicker::setCalendar( const QString &calendarType )
|
||||
{
|
||||
return d->table->setCalendar( calendarType );
|
||||
}
|
||||
|
||||
bool KDatePicker::setCalendarSystem( KLocale::CalendarSystem calendarSystem )
|
||||
{
|
||||
return d->table->setCalendarSystem( calendarSystem );
|
||||
}
|
||||
|
||||
void KDatePicker::monthForwardClicked()
|
||||
{
|
||||
if ( ! setDate( calendar()->addMonths( date(), 1 ) ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
void KDatePicker::monthBackwardClicked()
|
||||
{
|
||||
if ( ! setDate( calendar()->addMonths( date(), -1 ) ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
void KDatePicker::yearForwardClicked()
|
||||
{
|
||||
if ( ! setDate( calendar()->addYears( d->table->date(), 1 ) ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
void KDatePicker::yearBackwardClicked()
|
||||
{
|
||||
if ( ! setDate( calendar()->addYears( d->table->date(), -1 ) ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
void KDatePicker::weekSelected( int index )
|
||||
{
|
||||
QDate targetDay = d->selectWeek->itemData( index ).toDateTime().date();
|
||||
|
||||
if ( ! setDate( targetDay ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
void KDatePicker::selectMonthClicked()
|
||||
{
|
||||
KLocalizedDate thisDate( date(), calendar() );
|
||||
d->table->setFocus();
|
||||
|
||||
QMenu popup( d->selectMonth );
|
||||
// Populate the pick list with all the month names, this may change by year
|
||||
// JPL do we need to do somethng here for months that fall outside valid range?
|
||||
for ( int m = 1; m <= thisDate.monthsInYear(); m++ ) {
|
||||
popup.addAction( calendar()->monthName( m, thisDate.year() ) )->setData( m );
|
||||
}
|
||||
|
||||
QAction *item = popup.actions()[ thisDate.month() - 1 ];
|
||||
// if this happens the above should already given an assertion
|
||||
if ( item ) {
|
||||
popup.setActiveAction( item );
|
||||
}
|
||||
|
||||
// cancelled
|
||||
if ( ( item = popup.exec( d->selectMonth->mapToGlobal( QPoint( 0, 0 ) ), item ) ) == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to create a valid date in the month selected so we can find out how many days are
|
||||
// in the month.
|
||||
KLocalizedDate newDate( thisDate.year(), item->data().toInt(), 1, calendar() );
|
||||
|
||||
// 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
|
||||
newDate.setDate( newDate.year(), newDate.month(), qMin( thisDate.day(), newDate.daysInMonth() ) );
|
||||
|
||||
// Set the date, if it's invalid in any way then alert user and don't update
|
||||
if ( ! setDate( newDate.date() ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
}
|
||||
|
||||
void KDatePicker::selectYearClicked()
|
||||
{
|
||||
if ( !d->selectYear->isChecked() )
|
||||
return;
|
||||
|
||||
KLocalizedDate thisDate( date(), calendar() );
|
||||
|
||||
KPopupFrame *popup = new KPopupFrame( this );
|
||||
KDatePickerPrivateYearSelector *picker = new KDatePickerPrivateYearSelector( calendar(), date(), popup );
|
||||
picker->resize( picker->sizeHint() );
|
||||
picker->setYear( thisDate.year() );
|
||||
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.
|
||||
KLocalizedDate newDate( picker->year(), thisDate.month(), 1, calendar() );
|
||||
|
||||
// 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
|
||||
newDate.setDate( newDate.year(), newDate.month(), qMin( thisDate.day(), newDate.daysInMonth() ) );
|
||||
|
||||
// Set the date, if it's invalid in any way then alert user and don't update
|
||||
if ( ! setDate( newDate.date() ) ) {
|
||||
KNotification::beep();
|
||||
}
|
||||
}
|
||||
delete popup;
|
||||
|
||||
d->selectYear->setChecked( false );
|
||||
}
|
||||
|
||||
void KDatePicker::uncheckYearSelector()
|
||||
{
|
||||
d->selectYear->setChecked(false);
|
||||
d->selectYear->update();
|
||||
}
|
||||
|
||||
// ####### KDE4: setEnabled isn't virtual anymore, so this isn't polymorphic.
|
||||
// Better reimplement changeEvent() instead.
|
||||
void KDatePicker::setEnabled( bool enable )
|
||||
{
|
||||
QWidget * const widgets[] = {
|
||||
d->yearForward, d->yearBackward, d->monthForward, d->monthBackward,
|
||||
d->selectMonth, d->selectYear,
|
||||
d->line, d->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 );
|
||||
}
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
KDateTable *KDatePicker::dateTable() const
|
||||
{
|
||||
return d->table;
|
||||
}
|
||||
|
||||
void KDatePicker::lineEnterPressed()
|
||||
{
|
||||
QDate newDate = calendar()->readDate( d->line->text() );
|
||||
|
||||
if ( calendar()->isValid( newDate ) ) {
|
||||
emit( dateEntered( newDate ) );
|
||||
setDate( newDate );
|
||||
d->table->setFocus();
|
||||
} else {
|
||||
KNotification::beep();
|
||||
}
|
||||
}
|
||||
|
||||
void KDatePicker::todayButtonClicked()
|
||||
{
|
||||
setDate( QDate::currentDate() );
|
||||
d->table->setFocus();
|
||||
}
|
||||
|
||||
QSize KDatePicker::sizeHint() const
|
||||
{
|
||||
return QWidget::sizeHint();
|
||||
}
|
||||
|
||||
void KDatePicker::setFontSize( int s )
|
||||
{
|
||||
QWidget * const buttons[] = {
|
||||
d->selectMonth,
|
||||
d->selectYear,
|
||||
};
|
||||
const int NoOfButtons = sizeof( buttons ) / sizeof( buttons[0] );
|
||||
int count;
|
||||
QFont font;
|
||||
QRect r;
|
||||
// -----
|
||||
d->fontsize = s;
|
||||
for( count = 0; count < NoOfButtons; ++count ) {
|
||||
font = buttons[count]->font();
|
||||
font.setPointSize( s );
|
||||
buttons[count]->setFont( font );
|
||||
}
|
||||
d->table->setFontSize( s );
|
||||
|
||||
QFontMetrics metrics( d->selectMonth->fontMetrics() );
|
||||
QString longestMonth;
|
||||
|
||||
for ( int i = 1; ; ++i ) {
|
||||
QString str = calendar()->monthName( i, calendar()->year( date() ), KCalendarSystem::LongName );
|
||||
if ( str.isNull() ) {
|
||||
break;
|
||||
}
|
||||
r = metrics.boundingRect( str );
|
||||
|
||||
if ( r.width() > d->maxMonthRect.width() ) {
|
||||
d->maxMonthRect.setWidth( r.width() );
|
||||
longestMonth = str;
|
||||
}
|
||||
if ( r.height() > d->maxMonthRect.height() ) {
|
||||
d->maxMonthRect.setHeight( r.height() );
|
||||
}
|
||||
}
|
||||
|
||||
QStyleOptionToolButton opt;
|
||||
opt.initFrom( d->selectMonth );
|
||||
opt.text = longestMonth;
|
||||
|
||||
// stolen from QToolButton
|
||||
QSize textSize = metrics.size( Qt::TextShowMnemonic, longestMonth );
|
||||
textSize.setWidth( textSize.width() + metrics.width( QLatin1Char(' ') ) * 2 );
|
||||
int w = textSize.width();
|
||||
int h = textSize.height();
|
||||
opt.rect.setHeight( h ); // PM_MenuButtonIndicator depends on the height
|
||||
|
||||
QSize metricBound = style()->sizeFromContents(
|
||||
QStyle::CT_ToolButton, &opt, QSize( w, h ), d->selectMonth
|
||||
).expandedTo( QApplication::globalStrut() );
|
||||
|
||||
d->selectMonth->setMinimumSize( metricBound );
|
||||
}
|
||||
|
||||
int KDatePicker::fontSize() const
|
||||
{
|
||||
return d->fontsize;
|
||||
}
|
||||
|
||||
|
||||
void KDatePicker::setCloseButton( bool enable )
|
||||
{
|
||||
if ( enable == ( d->closeButton != 0L ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( enable ) {
|
||||
d->closeButton = new QToolButton( this );
|
||||
d->closeButton->setAutoRaise( true );
|
||||
d->navigationLayout->addSpacing( KDialog::spacingHint() );
|
||||
d->navigationLayout->addWidget( d->closeButton );
|
||||
d->closeButton->setToolTip( i18nc( "@action:button", "Close" ) );
|
||||
d->closeButton->setIcon( SmallIcon( "window-close" ) );
|
||||
connect( d->closeButton, SIGNAL(clicked()), window(), SLOT(close()) );
|
||||
} else {
|
||||
delete d->closeButton;
|
||||
d->closeButton = 0L;
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
bool KDatePicker::hasCloseButton() const
|
||||
{
|
||||
return ( d->closeButton );
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
/* -*- C++ -*-
|
||||
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)
|
||||
(C) 2007 John Layt <john@layt.net>
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDATEPICKER_H
|
||||
#define KDATEPICKER_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtGui/QFrame>
|
||||
|
||||
#include <klocale.h>
|
||||
|
||||
#include <QLineEdit>
|
||||
class KDateTable;
|
||||
class KCalendarSystem;
|
||||
|
||||
/**
|
||||
* @short A date selection widget.
|
||||
*
|
||||
* Provides a widget for calendar date input.
|
||||
*
|
||||
* Different from the
|
||||
* previous versions, it now emits two types of signals, either
|
||||
* dateSelected() or dateEntered() (see documentation for both
|
||||
* signals).
|
||||
*
|
||||
* A line edit has been added in the newer versions to allow the user
|
||||
* to select a date directly by entering numbers like 19990101
|
||||
* or 990101.
|
||||
*
|
||||
* \image html kdatepicker.png "KDE Date Widget"
|
||||
*
|
||||
* @author Tim Gilman, Mirko Boehm
|
||||
*
|
||||
**/
|
||||
class KDEUI_EXPORT KDatePicker: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QDate date READ date WRITE setDate NOTIFY dateChanged USER true )
|
||||
//FIXME Q_PROPERTY( KCalendarSystem calendar READ calendar WRITE setCalendar USER true )
|
||||
Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton )
|
||||
Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
|
||||
|
||||
public:
|
||||
/**
|
||||
* The constructor. The current date will be displayed initially.
|
||||
**/
|
||||
explicit KDatePicker( QWidget *parent = 0 );
|
||||
|
||||
/**
|
||||
* The constructor. The given date will be displayed initially.
|
||||
**/
|
||||
explicit KDatePicker( const QDate &dt, QWidget *parent = 0 );
|
||||
|
||||
/**
|
||||
* 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& date );
|
||||
|
||||
/**
|
||||
* @returns the selected date.
|
||||
*/
|
||||
const QDate &date() const;
|
||||
|
||||
/**
|
||||
* Returns the currently selected calendar system.
|
||||
*
|
||||
* @returns a KCalendarSystem object
|
||||
*/
|
||||
const KCalendarSystem *calendar() const;
|
||||
|
||||
/**
|
||||
* Changes the calendar system to use. Can use its own local locale if set.
|
||||
*
|
||||
* @param calendar the calendar system object to use, defaults to global
|
||||
*
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendar( KCalendarSystem *calendar = 0 );
|
||||
|
||||
/**
|
||||
* Changes the calendar system to use. Will always use global locale.
|
||||
*
|
||||
* @param calendarType the calendar system type to use
|
||||
*
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendar( const QString &calendarType );
|
||||
|
||||
/**
|
||||
* @since 4.6
|
||||
*
|
||||
* Changes the calendar system to use. Will always use global locale.
|
||||
*
|
||||
* @param calendarSystem the calendar system to use
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendarSystem( KLocale::CalendarSystem calendarSystem );
|
||||
|
||||
/**
|
||||
* Enables or disables the widget.
|
||||
**/
|
||||
void setEnabled( bool enable );
|
||||
|
||||
/**
|
||||
* @returns the KDateTable widget child of this KDatePicker
|
||||
* widget.
|
||||
*/
|
||||
KDateTable *dateTable() const;
|
||||
|
||||
/**
|
||||
* Sets the font size of the widgets elements.
|
||||
**/
|
||||
void setFontSize( int );
|
||||
|
||||
/**
|
||||
* Returns the font size of the widget elements.
|
||||
*/
|
||||
int fontSize() const;
|
||||
|
||||
/**
|
||||
* By calling this method with @p enable = true, KDatePicker will show
|
||||
* a little close-button in the upper button-row. Clicking the
|
||||
* close-button will cause the KDatePicker's topLevelWidget()'s close()
|
||||
* method being called. This is mostly useful for toplevel datepickers
|
||||
* without a window manager decoration.
|
||||
* @see hasCloseButton
|
||||
*/
|
||||
void setCloseButton( bool enable );
|
||||
|
||||
/**
|
||||
* @returns true if a KDatePicker shows a close-button.
|
||||
* @see setCloseButton
|
||||
*/
|
||||
bool hasCloseButton() const;
|
||||
|
||||
protected:
|
||||
/// to catch move keyEvents when QLineEdit has keyFocus
|
||||
virtual bool eventFilter( QObject *o, QEvent *e );
|
||||
/// the resize event
|
||||
virtual void resizeEvent( QResizeEvent* );
|
||||
|
||||
protected Q_SLOTS:
|
||||
void dateChangedSlot( const QDate& date );
|
||||
void tableClickedSlot();
|
||||
void monthForwardClicked();
|
||||
void monthBackwardClicked();
|
||||
void yearForwardClicked();
|
||||
void yearBackwardClicked();
|
||||
void selectMonthClicked();
|
||||
void selectYearClicked();
|
||||
void uncheckYearSelector();
|
||||
void lineEnterPressed();
|
||||
void todayButtonClicked();
|
||||
void weekSelected( int );
|
||||
|
||||
Q_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( const QDate &date );
|
||||
|
||||
/** 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( const QDate &date );
|
||||
|
||||
/** 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( const QDate &date );
|
||||
|
||||
/** This signal is emitted when the day has been selected by
|
||||
* clicking on it in the table.
|
||||
*/
|
||||
void tableClicked();
|
||||
|
||||
private:
|
||||
void init( const QDate &date );
|
||||
class KDatePickerPrivate;
|
||||
friend class KDatePickerPrivate;
|
||||
KDatePickerPrivate *const d;
|
||||
};
|
||||
|
||||
#endif // KDATEPICKER_H
|
|
@ -1,63 +0,0 @@
|
|||
/* -*- C++ -*-
|
||||
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)
|
||||
(C) 1998-2001 Mirko Boehm (john@layt.net)
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDATEPICKER_P_H
|
||||
#define KDATEPICKER_P_H
|
||||
|
||||
#include <kcalendarsystem.h>
|
||||
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QValidator>
|
||||
|
||||
/** Year selection widget.
|
||||
* @internal
|
||||
* @author Tim Gilman, Mirko Boehm, John Layt
|
||||
*/
|
||||
|
||||
class KDatePickerPrivateYearSelector : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KDatePickerPrivateYearSelector( const KCalendarSystem *calendar, const QDate ¤tDate, QWidget *parent = 0 );
|
||||
int year();
|
||||
void setYear( int year );
|
||||
|
||||
public Q_SLOTS:
|
||||
void yearEnteredSlot();
|
||||
|
||||
Q_SIGNALS:
|
||||
void closeMe( int );
|
||||
|
||||
protected:
|
||||
QIntValidator *val;
|
||||
int result;
|
||||
|
||||
private:
|
||||
const KCalendarSystem *calendar;
|
||||
QDate oldDate;
|
||||
|
||||
Q_DISABLE_COPY( KDatePickerPrivateYearSelector )
|
||||
};
|
||||
|
||||
|
||||
#endif // KDATEPICKER_P_H
|
|
@ -1,936 +0,0 @@
|
|||
/* -*- C++ -*-
|
||||
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)
|
||||
(C) 2007 John Layt <john@layt.net>
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kdatetable.h"
|
||||
|
||||
#include <kconfig.h>
|
||||
#include <kcolorscheme.h>
|
||||
#include <kglobal.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kdebug.h>
|
||||
#include <knotification.h>
|
||||
#include <kcalendarsystem.h>
|
||||
#include <klocalizeddate.h>
|
||||
#include <kshortcut.h>
|
||||
#include <kstandardshortcut.h>
|
||||
#include "kdatepicker.h"
|
||||
#include "kmenu.h"
|
||||
#include "kactioncollection.h"
|
||||
#include "kaction.h"
|
||||
#include <kdeversion.h>
|
||||
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtGui/QPen>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QStyle>
|
||||
#include <QtGui/qstyleoption.h>
|
||||
#include <QtGui/QDialog>
|
||||
#include <QtGui/qevent.h>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtGui/QApplication>
|
||||
#include <assert.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
class KDateTable::KDateTablePrivate
|
||||
{
|
||||
public:
|
||||
KDateTablePrivate( KDateTable *q ): q( q )
|
||||
{
|
||||
m_popupMenuEnabled = false;
|
||||
m_useCustomColors = false;
|
||||
m_hoveredPos = -1;
|
||||
setDate( QDate::currentDate() );
|
||||
}
|
||||
|
||||
~KDateTablePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void setDate( const QDate& date );
|
||||
void nextMonth();
|
||||
void previousMonth();
|
||||
void beginningOfMonth();
|
||||
void endOfMonth();
|
||||
void beginningOfWeek();
|
||||
void endOfWeek();
|
||||
|
||||
KDateTable *q;
|
||||
|
||||
/**
|
||||
* The font size of the displayed text.
|
||||
*/
|
||||
int fontsize;
|
||||
|
||||
/**
|
||||
* The currently selected date.
|
||||
*/
|
||||
KLocalizedDate m_date;
|
||||
// Need to keep a QDate copy as the "const QDate &date() const;" method returns a reference
|
||||
// and returning m_date.date() creates a temporary leading to crashes. Doh!
|
||||
QDate m_refDate;
|
||||
|
||||
/**
|
||||
* The weekday number of the first day in the month [1..daysInWeek()].
|
||||
*/
|
||||
int m_weekDayFirstOfMonth;
|
||||
|
||||
/**
|
||||
* The number of days in the current month.
|
||||
*/
|
||||
int m_numDaysThisMonth;
|
||||
|
||||
/**
|
||||
* Save the size of the largest used cell content.
|
||||
*/
|
||||
QRectF m_maxCell;
|
||||
|
||||
/**
|
||||
* How many week rows we are to draw.
|
||||
*/
|
||||
int m_numWeekRows;
|
||||
|
||||
/**
|
||||
* How many day columns we are to draw, i.e. days in a week.
|
||||
*/
|
||||
int m_numDayColumns;
|
||||
|
||||
bool m_popupMenuEnabled;
|
||||
bool m_useCustomColors;
|
||||
|
||||
struct DatePaintingMode
|
||||
{
|
||||
QColor fgColor;
|
||||
QColor bgColor;
|
||||
BackgroundMode bgMode;
|
||||
};
|
||||
QHash <int, DatePaintingMode> m_customPaintingModes;
|
||||
|
||||
int m_hoveredPos;
|
||||
};
|
||||
|
||||
|
||||
class KPopupFrame::KPopupFramePrivate
|
||||
{
|
||||
public:
|
||||
KPopupFramePrivate( KPopupFrame *q );
|
||||
~KPopupFramePrivate();
|
||||
|
||||
KPopupFrame *q;
|
||||
|
||||
/**
|
||||
* The result. It is returned from exec() when the popup window closes.
|
||||
*/
|
||||
int result;
|
||||
|
||||
/**
|
||||
* The only subwidget that uses the whole dialog window.
|
||||
*/
|
||||
QWidget *main;
|
||||
|
||||
// ### KDE 5: Remove this, add a hideEvent() reimplementation instead.
|
||||
class OutsideClickCatcher;
|
||||
OutsideClickCatcher *outsideClickCatcher;
|
||||
};
|
||||
|
||||
|
||||
class KPopupFrame::KPopupFramePrivate::OutsideClickCatcher
|
||||
: public QObject
|
||||
{
|
||||
public:
|
||||
OutsideClickCatcher(QObject *parent = 0)
|
||||
: QObject(parent), m_popup(0) { }
|
||||
~OutsideClickCatcher() { }
|
||||
|
||||
void setPopupFrame(KPopupFrame *popup)
|
||||
{
|
||||
m_popup = popup;
|
||||
popup->installEventFilter(this);
|
||||
}
|
||||
|
||||
KPopupFrame *m_popup;
|
||||
|
||||
bool eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
Q_UNUSED(object);
|
||||
|
||||
// To catch outside clicks, it is sufficient to check for
|
||||
// hide events on Qt::Popup type widgets
|
||||
if (event->type() == QEvent::Hide && m_popup) {
|
||||
// do not set d->result here, because the popup
|
||||
// hides itself after leaving the event loop.
|
||||
emit m_popup->leaveModality();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
KPopupFrame::KPopupFramePrivate::KPopupFramePrivate( KPopupFrame *q ):
|
||||
q( q ),
|
||||
result( 0 ), // rejected
|
||||
main( 0 ),
|
||||
outsideClickCatcher(new OutsideClickCatcher)
|
||||
{
|
||||
outsideClickCatcher->setPopupFrame(q);
|
||||
}
|
||||
|
||||
KPopupFrame::KPopupFramePrivate::~KPopupFramePrivate()
|
||||
{
|
||||
delete outsideClickCatcher;
|
||||
}
|
||||
|
||||
|
||||
KDateValidator::KDateValidator( QWidget *parent ) : QValidator( parent )
|
||||
{
|
||||
}
|
||||
|
||||
QValidator::State KDateValidator::validate( QString &text, int &unused ) const
|
||||
{
|
||||
Q_UNUSED( unused );
|
||||
|
||||
QDate temp;
|
||||
// ----- everything is tested in date():
|
||||
return date( text, temp );
|
||||
}
|
||||
|
||||
QValidator::State KDateValidator::date( const QString &text, QDate &d ) const
|
||||
{
|
||||
//FIXME This is wrong if the widget is not using the global!
|
||||
QDate tmp = KGlobal::locale()->readDate( text );
|
||||
if ( KGlobal::locale()->calendar()->isValid( tmp ) ) {
|
||||
d = tmp;
|
||||
return Acceptable;
|
||||
} else {
|
||||
return QValidator::Intermediate;
|
||||
}
|
||||
}
|
||||
|
||||
void KDateValidator::fixup( QString& ) const
|
||||
{
|
||||
}
|
||||
|
||||
KDateTable::KDateTable( const QDate& date, QWidget* parent )
|
||||
: QWidget( parent ),
|
||||
d( new KDateTablePrivate( this ) )
|
||||
{
|
||||
init( date );
|
||||
}
|
||||
|
||||
KDateTable::KDateTable( QWidget *parent )
|
||||
: QWidget( parent ),
|
||||
d( new KDateTablePrivate( this ) )
|
||||
{
|
||||
init( QDate::currentDate() );
|
||||
}
|
||||
|
||||
KDateTable::~KDateTable()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KDateTable::init( const QDate &date )
|
||||
{
|
||||
d->m_numWeekRows = 7;
|
||||
|
||||
setFontSize( 10 );
|
||||
setFocusPolicy( Qt::StrongFocus );
|
||||
setBackgroundRole(QPalette::Base);
|
||||
setAutoFillBackground(true);
|
||||
initAccels();
|
||||
setAttribute(Qt::WA_Hover, true);
|
||||
|
||||
setDate( date );
|
||||
}
|
||||
|
||||
void KDateTable::initAccels()
|
||||
{
|
||||
KActionCollection * localCollection = new KActionCollection( this );
|
||||
|
||||
KAction* next = localCollection->addAction( QLatin1String( "next" ) );
|
||||
next->setShortcuts( KStandardShortcut::next() );
|
||||
connect( next, SIGNAL(triggered(bool)), SLOT(nextMonth()) );
|
||||
|
||||
KAction* prior = localCollection->addAction( QLatin1String( "prior" ) );
|
||||
prior->setShortcuts( KStandardShortcut::prior() );
|
||||
connect( prior, SIGNAL(triggered(bool)), SLOT(previousMonth()) );
|
||||
|
||||
KAction* beginMonth = localCollection->addAction( QLatin1String( "beginMonth" ) );
|
||||
beginMonth->setShortcuts( KStandardShortcut::begin() );
|
||||
connect( beginMonth, SIGNAL(triggered(bool)), SLOT(beginningOfMonth()) );
|
||||
|
||||
KAction* endMonth = localCollection->addAction( QLatin1String( "endMonth" ) );
|
||||
endMonth->setShortcuts( KStandardShortcut::end() );
|
||||
connect( endMonth, SIGNAL(triggered(bool)), SLOT(endOfMonth()) );
|
||||
|
||||
KAction* beginWeek = localCollection->addAction( QLatin1String( "beginWeek" ) );
|
||||
beginWeek->setShortcuts( KStandardShortcut::beginningOfLine() );
|
||||
connect( beginWeek, SIGNAL(triggered(bool)), SLOT(beginningOfWeek()) );
|
||||
|
||||
KAction* endWeek = localCollection->addAction( "endWeek" );
|
||||
endWeek->setShortcuts( KStandardShortcut::endOfLine() );
|
||||
connect( endWeek, SIGNAL(triggered(bool)), SLOT(endOfWeek()) );
|
||||
|
||||
localCollection->readSettings();
|
||||
localCollection->addAssociatedWidget( this );
|
||||
foreach (QAction* action, localCollection->actions()) {
|
||||
action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
|
||||
}
|
||||
}
|
||||
|
||||
int KDateTable::posFromDate( const QDate &date )
|
||||
{
|
||||
int initialPosition = calendar()->day( date );
|
||||
int offset = ( d->m_weekDayFirstOfMonth - calendar()->weekStartDay() + d->m_numDayColumns ) % d->m_numDayColumns;
|
||||
|
||||
// make sure at least one day of the previous month is visible.
|
||||
// adjust this < 1 if more days should be forced visible:
|
||||
if ( offset < 1 ) {
|
||||
offset += d->m_numDayColumns;
|
||||
}
|
||||
|
||||
return initialPosition + offset;
|
||||
}
|
||||
|
||||
QDate KDateTable::dateFromPos( int position )
|
||||
{
|
||||
int offset = ( d->m_weekDayFirstOfMonth - calendar()->weekStartDay() + d->m_numDayColumns ) % d->m_numDayColumns;
|
||||
|
||||
// make sure at least one day of the previous month is visible.
|
||||
// adjust this < 1 if more days should be forced visible:
|
||||
if ( offset < 1 ) {
|
||||
offset += d->m_numDayColumns;
|
||||
}
|
||||
|
||||
return d->m_date.firstDayOfMonth().addDays( position - offset ).date();
|
||||
}
|
||||
|
||||
void KDateTable::paintEvent( QPaintEvent *e )
|
||||
{
|
||||
QPainter p( this );
|
||||
KColorScheme colorScheme(palette().currentColorGroup(), KColorScheme::View);
|
||||
const QRect &rectToUpdate = e->rect();
|
||||
double cellWidth = width() / ( double ) d->m_numDayColumns;
|
||||
double cellHeight = height() / ( double ) d->m_numWeekRows;
|
||||
int leftCol = ( int )std::floor( rectToUpdate.left() / cellWidth );
|
||||
int topRow = ( int )std::floor( rectToUpdate.top() / cellHeight );
|
||||
int rightCol = ( int )std::ceil( rectToUpdate.right() / cellWidth );
|
||||
int bottomRow = ( int )std::ceil( rectToUpdate.bottom() / cellHeight );
|
||||
bottomRow = qMin( bottomRow, d->m_numWeekRows - 1 );
|
||||
rightCol = qMin( rightCol, d->m_numDayColumns - 1 );
|
||||
if ( layoutDirection() == Qt::RightToLeft ) {
|
||||
p.translate( ( d->m_numDayColumns - leftCol - 1 ) * cellWidth, topRow * cellHeight );
|
||||
} else {
|
||||
p.translate( leftCol * cellWidth, topRow * cellHeight );
|
||||
}
|
||||
for ( int i = leftCol; i <= rightCol; ++i ) {
|
||||
for ( int j = topRow; j <= bottomRow; ++j ) {
|
||||
paintCell( &p, j, i, colorScheme );
|
||||
p.translate( 0, cellHeight );
|
||||
}
|
||||
if ( layoutDirection() == Qt::RightToLeft ) {
|
||||
p.translate( -cellWidth, 0 );
|
||||
} else {
|
||||
p.translate( cellWidth, 0 );
|
||||
}
|
||||
p.translate( 0, -cellHeight * ( bottomRow - topRow + 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
void KDateTable::paintCell( QPainter *painter, int row, int col, const KColorScheme &colorScheme )
|
||||
{
|
||||
double w = ( width() / ( double ) d->m_numDayColumns ) - 1;
|
||||
double h = ( height() / ( double ) d->m_numWeekRows ) - 1;
|
||||
QRectF cell = QRectF( 0, 0, w, h );
|
||||
QString cellText;
|
||||
QPen pen;
|
||||
QColor cellBackgroundColor, cellTextColor;
|
||||
QFont cellFont = KGlobalSettings::generalFont();
|
||||
bool workingDay = false;
|
||||
int cellWeekDay, pos;
|
||||
|
||||
//Calculate the position of the cell in the grid
|
||||
pos = d->m_numDayColumns * ( row - 1 ) + col;
|
||||
|
||||
//Calculate what day of the week the cell is
|
||||
if ( col + calendar()->weekStartDay() <= d->m_numDayColumns ) {
|
||||
cellWeekDay = col + calendar()->weekStartDay();
|
||||
} else {
|
||||
cellWeekDay = col + calendar()->weekStartDay() - d->m_numDayColumns;
|
||||
}
|
||||
|
||||
//FIXME This is wrong if the widget is not using the global!
|
||||
//See if cell day is normally a working day
|
||||
if ( KGlobal::locale()->workingWeekStartDay() <= KGlobal::locale()->workingWeekEndDay() ) {
|
||||
if ( cellWeekDay >= KGlobal::locale()->workingWeekStartDay() &&
|
||||
cellWeekDay <= KGlobal::locale()->workingWeekEndDay() ) {
|
||||
workingDay = true;
|
||||
}
|
||||
} else {
|
||||
if ( cellWeekDay >= KGlobal::locale()->workingWeekStartDay() ||
|
||||
cellWeekDay <= KGlobal::locale()->workingWeekEndDay() ) {
|
||||
workingDay = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( row == 0 ) {
|
||||
|
||||
//We are drawing a header cell
|
||||
|
||||
//If not a normal working day, then use "do not work today" color
|
||||
if ( workingDay ) {
|
||||
cellTextColor = palette().color(QPalette::WindowText);
|
||||
} else {
|
||||
KColorScheme colorScheme(palette().currentColorGroup(), KColorScheme::Window);
|
||||
cellTextColor = colorScheme.foreground(KColorScheme::NegativeText).color();
|
||||
}
|
||||
cellBackgroundColor = palette().color(QPalette::Window);
|
||||
|
||||
//Set the text to the short day name and bold it
|
||||
cellFont.setBold( true );
|
||||
cellText = calendar()->weekDayName( cellWeekDay, KCalendarSystem::ShortDayName );
|
||||
|
||||
} else {
|
||||
|
||||
//We are drawing a day cell
|
||||
|
||||
//Calculate the date the cell represents
|
||||
//Copy current date to get same calendar system & locale
|
||||
KLocalizedDate cellDate = d->m_date;
|
||||
cellDate = dateFromPos( pos );
|
||||
|
||||
bool validDay = cellDate.isValid();
|
||||
|
||||
// Draw the day number in the cell, if the date is not valid then we don't want to show it
|
||||
if ( validDay ) {
|
||||
cellText = cellDate.formatDate( KLocale::Day, KLocale::ShortNumber );
|
||||
} else {
|
||||
cellText = "";
|
||||
}
|
||||
|
||||
if( ! validDay || cellDate.month() != d->m_date.month() ) {
|
||||
// we are either
|
||||
// ° painting an invalid day
|
||||
// ° painting a day of the previous month or
|
||||
// ° painting a day of the following month or
|
||||
cellBackgroundColor = palette().color(backgroundRole());
|
||||
cellTextColor = colorScheme.foreground(KColorScheme::InactiveText).color();
|
||||
} else {
|
||||
//Paint a day of the current month
|
||||
|
||||
// Background Colour priorities will be (high-to-low):
|
||||
// * Selected Day Background Colour
|
||||
// * Customized Day Background Colour
|
||||
// * Normal Day Background Colour
|
||||
|
||||
// Background Shape priorities will be (high-to-low):
|
||||
// * Customized Day Shape
|
||||
// * Normal Day Shape
|
||||
|
||||
// Text Colour priorities will be (high-to-low):
|
||||
// * Customized Day Colour
|
||||
// * Day of Pray Colour (Red letter)
|
||||
// * Selected Day Colour
|
||||
// * Normal Day Colour
|
||||
|
||||
//Determine various characteristics of the cell date
|
||||
bool selectedDay = ( cellDate == date() );
|
||||
bool currentDay = ( cellDate == QDate::currentDate() );
|
||||
bool dayOfPray = ( cellDate.dayOfWeek() == calendar()->locale()->weekDayOfPray() );
|
||||
bool customDay = ( d->m_useCustomColors && d->m_customPaintingModes.contains(cellDate.toJulianDay()) );
|
||||
|
||||
//Default values for a normal cell
|
||||
cellBackgroundColor = palette().color( backgroundRole() );
|
||||
cellTextColor = palette().color( foregroundRole() );
|
||||
|
||||
// If we are drawing the current date, then draw it bold and active
|
||||
if ( currentDay ) {
|
||||
cellFont.setBold( true );
|
||||
cellTextColor = colorScheme.foreground(KColorScheme::ActiveText).color();
|
||||
}
|
||||
|
||||
// if we are drawing the day cell currently selected in the table
|
||||
if ( selectedDay ) {
|
||||
// set the background to highlighted
|
||||
cellBackgroundColor = palette().color( QPalette::Highlight );
|
||||
cellTextColor = palette().color( QPalette::HighlightedText );
|
||||
}
|
||||
|
||||
//If custom colors or shape are required for this date
|
||||
if ( customDay ) {
|
||||
KDateTablePrivate::DatePaintingMode mode = d->m_customPaintingModes[cellDate.toJulianDay()];
|
||||
if ( mode.bgMode != NoBgMode ) {
|
||||
if (!selectedDay) cellBackgroundColor = mode.bgColor;
|
||||
}
|
||||
cellTextColor = mode.fgColor;
|
||||
}
|
||||
|
||||
//If the cell day is the day of religious observance, then always color text red unless Custom overrides
|
||||
if ( ! customDay && dayOfPray ) {
|
||||
KColorScheme colorScheme(palette().currentColorGroup(),
|
||||
selectedDay ? KColorScheme::Selection : KColorScheme::View);
|
||||
cellTextColor = colorScheme.foreground(KColorScheme::NegativeText).color();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Draw the background
|
||||
if (row == 0) {
|
||||
painter->setPen( cellBackgroundColor );
|
||||
painter->setBrush( cellBackgroundColor );
|
||||
painter->drawRect( cell );
|
||||
} else if (cellBackgroundColor != palette().color(backgroundRole()) || pos == d->m_hoveredPos) {
|
||||
QStyleOptionViewItemV4 opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = cell.toRect();
|
||||
if (cellBackgroundColor != palette().color(backgroundRole())) {
|
||||
opt.palette.setBrush(QPalette::Highlight, cellBackgroundColor);
|
||||
opt.state |= QStyle::State_Selected;
|
||||
}
|
||||
if (pos == d->m_hoveredPos && opt.state & QStyle::State_Enabled) {
|
||||
opt.state |= QStyle::State_MouseOver;
|
||||
} else {
|
||||
opt.state &= ~QStyle::State_MouseOver;
|
||||
}
|
||||
opt.showDecorationSelected = true;
|
||||
opt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
|
||||
style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, this);
|
||||
}
|
||||
|
||||
//Draw the text
|
||||
painter->setPen( cellTextColor );
|
||||
painter->setFont( cellFont );
|
||||
painter->drawText( cell, Qt::AlignCenter, cellText, &cell );
|
||||
|
||||
//Draw the base line
|
||||
if (row == 0) {
|
||||
painter->setPen( palette().color(foregroundRole()) );
|
||||
painter->drawLine( QPointF( 0, h ), QPointF( w, h ) );
|
||||
}
|
||||
|
||||
// If the day cell we just drew is bigger than the current max cell sizes,
|
||||
// then adjust the max to the current cell
|
||||
if ( cell.width() > d->m_maxCell.width() ) d->m_maxCell.setWidth( cell.width() );
|
||||
if ( cell.height() > d->m_maxCell.height() ) d->m_maxCell.setHeight( cell.height() );
|
||||
}
|
||||
|
||||
void KDateTable::KDateTablePrivate::nextMonth()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.addMonths( 1 ).date() );
|
||||
}
|
||||
|
||||
void KDateTable::KDateTablePrivate::previousMonth()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.addMonths( -1 ).date() );
|
||||
}
|
||||
|
||||
void KDateTable::KDateTablePrivate::beginningOfMonth()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.firstDayOfMonth().date() );
|
||||
}
|
||||
|
||||
void KDateTable::KDateTablePrivate::endOfMonth()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.lastDayOfMonth().date() );
|
||||
}
|
||||
|
||||
// JPL Do these make the assumption that first day of week is weekday 1? As it may not be.
|
||||
void KDateTable::KDateTablePrivate::beginningOfWeek()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.addDays( 1 - m_date.dayOfWeek() ).date() );
|
||||
}
|
||||
|
||||
// JPL Do these make the assumption that first day of week is weekday 1? As it may not be.
|
||||
void KDateTable::KDateTablePrivate::endOfWeek()
|
||||
{
|
||||
// setDate does validity checking for us
|
||||
q->setDate( m_date.addDays( m_date.daysInWeek() - m_date.dayOfWeek() ).date() );
|
||||
}
|
||||
|
||||
void KDateTable::keyPressEvent( QKeyEvent *e )
|
||||
{
|
||||
switch( e->key() ) {
|
||||
case Qt::Key_Up:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( - d->m_numDayColumns ).date() );
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( d->m_numDayColumns ).date() );
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( -1 ).date() );
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( 1 ).date() );
|
||||
break;
|
||||
case Qt::Key_Minus:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( -1 ).date() );
|
||||
break;
|
||||
case Qt::Key_Plus:
|
||||
// setDate does validity checking for us
|
||||
setDate( d->m_date.addDays( 1 ).date() );
|
||||
break;
|
||||
case Qt::Key_N:
|
||||
// setDate does validity checking for us
|
||||
setDate( QDate::currentDate() );
|
||||
break;
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter:
|
||||
emit tableClicked();
|
||||
break;
|
||||
case Qt::Key_Control:
|
||||
case Qt::Key_Alt:
|
||||
case Qt::Key_Meta:
|
||||
case Qt::Key_Shift:
|
||||
// Don't beep for modifiers
|
||||
break;
|
||||
default:
|
||||
if ( !e->modifiers() ) { // hm
|
||||
KNotification::beep();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KDateTable::setFontSize( int size )
|
||||
{
|
||||
QFontMetricsF metrics( fontMetrics() );
|
||||
QRectF rect;
|
||||
// ----- store rectangles:
|
||||
d->fontsize = size;
|
||||
// ----- find largest day name:
|
||||
d->m_maxCell.setWidth( 0 );
|
||||
d->m_maxCell.setHeight( 0 );
|
||||
for( int weekday = 1; weekday <= d->m_date.daysInWeek(); ++weekday ) {
|
||||
rect = metrics.boundingRect( calendar()->weekDayName( weekday, KCalendarSystem::ShortDayName ) );
|
||||
d->m_maxCell.setWidth( qMax( d->m_maxCell.width(), rect.width() ) );
|
||||
d->m_maxCell.setHeight( qMax( d->m_maxCell.height(), rect.height() ) );
|
||||
}
|
||||
// ----- compare with a real wide number and add some space:
|
||||
rect = metrics.boundingRect( QLatin1String( "88" ) );
|
||||
d->m_maxCell.setWidth( qMax( d->m_maxCell.width() + 2, rect.width() ) );
|
||||
d->m_maxCell.setHeight( qMax( d->m_maxCell.height() + 4, rect.height() ) );
|
||||
}
|
||||
|
||||
void KDateTable::wheelEvent ( QWheelEvent * e )
|
||||
{
|
||||
setDate( d->m_date.addMonths( -( int )( e->delta() / 120 ) ).date() );
|
||||
e->accept();
|
||||
}
|
||||
|
||||
bool KDateTable::event(QEvent *ev)
|
||||
{
|
||||
switch (ev->type()) {
|
||||
case QEvent::HoverMove:
|
||||
{
|
||||
QHoverEvent *e = static_cast<QHoverEvent *>(ev);
|
||||
const int row = e->pos().y() * d->m_numWeekRows / height();
|
||||
int col;
|
||||
if ( layoutDirection() == Qt::RightToLeft ) {
|
||||
col = d->m_numDayColumns - ( e->pos().x() * d->m_numDayColumns / width() ) - 1;
|
||||
} else {
|
||||
col = e->pos().x() * d->m_numDayColumns / width();
|
||||
}
|
||||
|
||||
const int pos = row < 1 ? -1 : (d->m_numDayColumns * (row - 1)) + col;
|
||||
|
||||
if (pos != d->m_hoveredPos) {
|
||||
d->m_hoveredPos = pos;
|
||||
update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::HoverLeave:
|
||||
if (d->m_hoveredPos != -1) {
|
||||
d->m_hoveredPos = -1;
|
||||
update();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QWidget::event(ev);
|
||||
}
|
||||
|
||||
void KDateTable::mousePressEvent( QMouseEvent *e )
|
||||
{
|
||||
if( e->type() != QEvent::MouseButtonPress ) { // the KDatePicker only reacts on mouse press events:
|
||||
return;
|
||||
}
|
||||
|
||||
if( !isEnabled() ) {
|
||||
KNotification::beep();
|
||||
return;
|
||||
}
|
||||
|
||||
int row, col, pos;
|
||||
|
||||
QPoint mouseCoord = e->pos();
|
||||
row = mouseCoord.y() * d->m_numWeekRows / height();
|
||||
if ( layoutDirection() == Qt::RightToLeft ) {
|
||||
col = d->m_numDayColumns - ( mouseCoord.x() * d->m_numDayColumns / width() ) - 1;
|
||||
} else {
|
||||
col = mouseCoord.x() * d->m_numDayColumns / width();
|
||||
}
|
||||
|
||||
if( row < 1 || col < 0 ) { // the user clicked on the frame of the table
|
||||
return;
|
||||
}
|
||||
|
||||
// Rows and columns are zero indexed. The (row - 1) below is to avoid counting
|
||||
// the row with the days of the week in the calculation.
|
||||
|
||||
// old selected date:
|
||||
// temp = posFromDate( date() );
|
||||
|
||||
// new position and date
|
||||
pos = ( d->m_numDayColumns * ( row - 1 ) ) + col;
|
||||
QDate clickedDate = dateFromPos( pos );
|
||||
|
||||
// set the new date. If it is in the previous or next month, the month will
|
||||
// automatically be changed, no need to do that manually...
|
||||
// validity checking done inside setDate
|
||||
setDate( clickedDate );
|
||||
|
||||
// This could be optimized to only call update over the regions
|
||||
// of old and new cell, but 99% of times there is also a call to
|
||||
// setDate that already calls update() so no need to optimize that
|
||||
// much here
|
||||
update();
|
||||
|
||||
emit tableClicked();
|
||||
|
||||
if ( e->button() == Qt::RightButton && d->m_popupMenuEnabled ) {
|
||||
KMenu * menu = new KMenu();
|
||||
menu->addTitle( d->m_date.formatDate() );
|
||||
emit aboutToShowContextMenu( menu, clickedDate );
|
||||
menu->popup( e->globalPos() );
|
||||
}
|
||||
}
|
||||
|
||||
void KDateTable::KDateTablePrivate::setDate( const QDate& date )
|
||||
{
|
||||
m_date.setDate( date );
|
||||
m_refDate = date;
|
||||
m_weekDayFirstOfMonth = m_date.firstDayOfMonth().dayOfWeek();
|
||||
m_numDaysThisMonth = m_date.daysInMonth();
|
||||
m_numDayColumns = m_date.daysInWeek();
|
||||
}
|
||||
|
||||
bool KDateTable::setDate( const QDate& toDate )
|
||||
{
|
||||
if ( !calendar()->isValid( toDate ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( toDate == date() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QDate oldDate = date();
|
||||
d->setDate( toDate );
|
||||
emit( dateChanged( date(), oldDate ) );
|
||||
emit( dateChanged( date() ) );
|
||||
update();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const QDate &KDateTable::date() const
|
||||
{
|
||||
return d->m_refDate;
|
||||
}
|
||||
|
||||
const KCalendarSystem *KDateTable::calendar() const
|
||||
{
|
||||
return d->m_date.calendar();
|
||||
}
|
||||
|
||||
bool KDateTable::setCalendar( KCalendarSystem *newCalendar )
|
||||
{
|
||||
QDate oldDate = date();
|
||||
d->m_date = KLocalizedDate( oldDate, newCalendar );
|
||||
return setDate( oldDate );
|
||||
}
|
||||
|
||||
bool KDateTable::setCalendar( const QString &newCalendarType )
|
||||
{
|
||||
return setCalendarSystem( KCalendarSystem::calendarSystem( newCalendarType ) );
|
||||
}
|
||||
|
||||
bool KDateTable::setCalendarSystem( KLocale::CalendarSystem newCalendarSystem )
|
||||
{
|
||||
d->m_date.setCalendarSystem( newCalendarSystem );
|
||||
return true;
|
||||
}
|
||||
|
||||
QSize KDateTable::sizeHint() const
|
||||
{
|
||||
if( d->m_maxCell.height() > 0 && d->m_maxCell.width() > 0 ) {
|
||||
return QSize( qRound( d->m_maxCell.width() * d->m_numDayColumns ),
|
||||
( qRound( d->m_maxCell.height() + 2 ) * d->m_numWeekRows ) );
|
||||
} else {
|
||||
kDebug() << "KDateTable::sizeHint: obscure failure - ";
|
||||
return QSize( -1, -1 );
|
||||
}
|
||||
}
|
||||
|
||||
void KDateTable::setPopupMenuEnabled( bool enable )
|
||||
{
|
||||
d->m_popupMenuEnabled = enable;
|
||||
}
|
||||
|
||||
bool KDateTable::popupMenuEnabled() const
|
||||
{
|
||||
return d->m_popupMenuEnabled;
|
||||
}
|
||||
|
||||
void KDateTable::setCustomDatePainting( const QDate &date, const QColor &fgColor, BackgroundMode bgMode, const QColor &bgColor )
|
||||
{
|
||||
if ( !fgColor.isValid() ) {
|
||||
unsetCustomDatePainting( date );
|
||||
return;
|
||||
}
|
||||
|
||||
KDateTablePrivate::DatePaintingMode mode;
|
||||
mode.bgMode = bgMode;
|
||||
mode.fgColor = fgColor;
|
||||
mode.bgColor = bgColor;
|
||||
|
||||
d->m_customPaintingModes.insert( date.toJulianDay(), mode );
|
||||
d->m_useCustomColors = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void KDateTable::unsetCustomDatePainting( const QDate &date )
|
||||
{
|
||||
d->m_customPaintingModes.remove( date.toJulianDay() );
|
||||
if ( d->m_customPaintingModes.isEmpty() ) d->m_useCustomColors = false;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
// JPL Shouldn't this be in own file as is used in a couple of places? Or moved to private in KDE5?
|
||||
|
||||
KPopupFrame::KPopupFrame( QWidget* parent )
|
||||
: QFrame( parent, Qt::Popup ), d( new KPopupFramePrivate( this ) )
|
||||
{
|
||||
setFrameStyle( QFrame::Box | QFrame::Raised );
|
||||
setMidLineWidth( 2 );
|
||||
}
|
||||
|
||||
KPopupFrame::~KPopupFrame()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KPopupFrame::keyPressEvent( QKeyEvent* e )
|
||||
{
|
||||
if( e->key() == Qt::Key_Escape ) {
|
||||
d->result = 0; // rejected
|
||||
emit leaveModality();
|
||||
//qApp->exit_loop();
|
||||
}
|
||||
}
|
||||
|
||||
void KPopupFrame::close( int r )
|
||||
{
|
||||
d->result = r;
|
||||
emit leaveModality();
|
||||
//qApp->exit_loop();
|
||||
}
|
||||
|
||||
void KPopupFrame::setMainWidget( QWidget *m )
|
||||
{
|
||||
d->main = m;
|
||||
if( d->main ) {
|
||||
resize( d->main->width() + 2 * frameWidth(), d->main->height() + 2 * frameWidth() );
|
||||
}
|
||||
}
|
||||
|
||||
void KPopupFrame::resizeEvent( QResizeEvent *e )
|
||||
{
|
||||
Q_UNUSED( e );
|
||||
|
||||
if( d->main ) {
|
||||
d->main->setGeometry( frameWidth(), frameWidth(),
|
||||
width() - 2 * frameWidth(), height() - 2 * frameWidth() );
|
||||
}
|
||||
}
|
||||
|
||||
void KPopupFrame::popup( const QPoint &pos )
|
||||
{
|
||||
// Make sure the whole popup is visible.
|
||||
QRect desktopGeometry = KGlobalSettings::desktopGeometry( pos );
|
||||
|
||||
int x = pos.x();
|
||||
int y = pos.y();
|
||||
int w = width();
|
||||
int h = height();
|
||||
if ( x + w > desktopGeometry.x() + desktopGeometry.width() ) {
|
||||
x = desktopGeometry.width() - w;
|
||||
}
|
||||
if ( y + h > desktopGeometry.y() + desktopGeometry.height() ) {
|
||||
y = desktopGeometry.height() - h;
|
||||
}
|
||||
if ( x < desktopGeometry.x() ) {
|
||||
x = 0;
|
||||
}
|
||||
if ( y < desktopGeometry.y() ) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
// Pop the thingy up.
|
||||
move( x, y );
|
||||
show();
|
||||
d->main->setFocus();
|
||||
}
|
||||
|
||||
int KPopupFrame::exec( const QPoint &pos )
|
||||
{
|
||||
popup( pos );
|
||||
repaint();
|
||||
d->result = 0; // rejected
|
||||
QEventLoop eventLoop;
|
||||
connect( this, SIGNAL(leaveModality()),
|
||||
&eventLoop, SLOT(quit()) );
|
||||
eventLoop.exec();
|
||||
|
||||
hide();
|
||||
return d->result;
|
||||
}
|
||||
|
||||
int KPopupFrame::exec( int x, int y )
|
||||
{
|
||||
return exec( QPoint( x, y ) );
|
||||
}
|
||||
|
||||
#include "moc_kdatetable.cpp"
|
|
@ -1,318 +0,0 @@
|
|||
/* -*- C++ -*-
|
||||
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)
|
||||
(C) 2007 John Layt <john@layt.net>
|
||||
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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KDATETABLE_H
|
||||
#define KDATETABLE_H
|
||||
|
||||
#include <kdeui_export.h>
|
||||
|
||||
#include <QtGui/QValidator>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtCore/QDateTime>
|
||||
|
||||
#include <klocale.h>
|
||||
|
||||
class KMenu;
|
||||
class KCalendarSystem;
|
||||
class KColorScheme;
|
||||
|
||||
/**
|
||||
* Frame with popup menu behavior.
|
||||
* @author Tim Gilman, Mirko Boehm
|
||||
*/
|
||||
class KDEUI_EXPORT KPopupFrame : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
/**
|
||||
* Catch key press events.
|
||||
*/
|
||||
virtual void keyPressEvent( QKeyEvent *e );
|
||||
|
||||
public Q_SLOTS:
|
||||
/**
|
||||
* Close the popup window. This is called from the main widget, usually.
|
||||
* @p r is the result returned from exec().
|
||||
*/
|
||||
void close( int r );
|
||||
|
||||
public:
|
||||
/**
|
||||
* The contructor. Creates a dialog without buttons.
|
||||
*/
|
||||
KPopupFrame( QWidget *parent = 0 );
|
||||
|
||||
/**
|
||||
* The destructor
|
||||
*/
|
||||
~KPopupFrame();
|
||||
|
||||
/**
|
||||
* Set the main widget. You cannot set the main widget from the constructor,
|
||||
* since it must be a child of the frame itselfes.
|
||||
* Be careful: the size is set to the main widgets size. It is up to you to
|
||||
* set the main widgets correct size before setting it as the main
|
||||
* widget.
|
||||
*/
|
||||
void setMainWidget( QWidget* m );
|
||||
|
||||
/**
|
||||
* The resize event. Simply resizes the main widget to the whole
|
||||
* widgets client size.
|
||||
*/
|
||||
virtual void resizeEvent( QResizeEvent *resize );
|
||||
|
||||
/**
|
||||
* Open the popup window at position pos.
|
||||
*/
|
||||
void popup( const QPoint &pos );
|
||||
|
||||
/**
|
||||
* Execute the popup window.
|
||||
*/
|
||||
int exec( const QPoint &p );
|
||||
|
||||
/**
|
||||
* Execute the popup window.
|
||||
*/
|
||||
int exec( int x, int y );
|
||||
|
||||
Q_SIGNALS:
|
||||
void leaveModality();
|
||||
|
||||
private:
|
||||
class KPopupFramePrivate;
|
||||
friend class KPopupFramePrivate;
|
||||
KPopupFramePrivate * const d;
|
||||
|
||||
Q_DISABLE_COPY( KPopupFrame )
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates user-entered dates.
|
||||
*/
|
||||
class KDEUI_EXPORT KDateValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
KDateValidator( QWidget *parent = 0 );
|
||||
virtual State validate( QString &text, int &e ) const;
|
||||
virtual void fixup ( QString &input ) const;
|
||||
State date( const QString &text, QDate &date ) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* Date selection table.
|
||||
* This is a support class for the KDatePicker class. It just
|
||||
* draws the calendar table without titles, but could theoretically
|
||||
* be used as a standalone.
|
||||
*
|
||||
* When a date is selected by the user, it emits a signal:
|
||||
* dateSelected(QDate)
|
||||
*
|
||||
* \image html kdatetable.png "KDE Date Selection Table"
|
||||
*
|
||||
* @internal
|
||||
* @author Tim Gilman, Mirko Boehm
|
||||
*/
|
||||
class KDEUI_EXPORT KDateTable : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QDate date READ date WRITE setDate )
|
||||
//FIXME Q_PROPERTY( KCalendarSystem calendar READ calendar WRITE setCalendar USER true )
|
||||
Q_PROPERTY( bool popupMenu READ popupMenuEnabled WRITE setPopupMenuEnabled )
|
||||
|
||||
public:
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
explicit KDateTable( QWidget* parent = 0 );
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
explicit KDateTable( const QDate&, QWidget *parent = 0 );
|
||||
|
||||
/**
|
||||
* The destructor.
|
||||
*/
|
||||
~KDateTable();
|
||||
|
||||
/**
|
||||
* Returns a recommended size for the widget.
|
||||
* To save some time, the size of the largest used cell content is
|
||||
* calculated in each paintCell() call, since all calculations have
|
||||
* to be done there anyway. The size is stored in maxCell. The
|
||||
* sizeHint() simply returns a multiple of maxCell.
|
||||
*/
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
/**
|
||||
* Set the font size of the date table.
|
||||
*/
|
||||
void setFontSize( int size );
|
||||
|
||||
/**
|
||||
* Select and display this date.
|
||||
*/
|
||||
bool setDate( const QDate &date );
|
||||
|
||||
// KDE5 remove the const & from the returned QDate
|
||||
/**
|
||||
* @returns the selected date.
|
||||
*/
|
||||
const QDate &date() const;
|
||||
|
||||
/**
|
||||
* Returns the currently selected calendar system.
|
||||
*
|
||||
* @return a KCalendarSystem object
|
||||
*/
|
||||
const KCalendarSystem *calendar() const;
|
||||
|
||||
/**
|
||||
* Changes the calendar system to use. Can use its own local locale if set.
|
||||
*
|
||||
* @param calendar the calendar system object to use, defaults to global
|
||||
*
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendar( KCalendarSystem *calendar = 0 );
|
||||
|
||||
/**
|
||||
* Changes the calendar system to use. Will always use global locale.
|
||||
*
|
||||
* @param calendarType the calendar system type to use
|
||||
*
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendar( const QString &calendarType );
|
||||
|
||||
/**
|
||||
* @since 4.6
|
||||
*
|
||||
* Changes the calendar system to use. Will always use global locale.
|
||||
*
|
||||
* @param calendarSystem the calendar system to use
|
||||
* @return @c true if the calendar system was successfully set, @c false otherwise
|
||||
*/
|
||||
bool setCalendarSystem( KLocale::CalendarSystem calendarSystem );
|
||||
|
||||
/**
|
||||
* Enables a popup menu when right clicking on a date.
|
||||
*
|
||||
* When it's enabled, this object emits a aboutToShowContextMenu signal
|
||||
* where you can fill in the menu items.
|
||||
*/
|
||||
void setPopupMenuEnabled( bool enable );
|
||||
|
||||
/**
|
||||
* Returns if the popup menu is enabled or not
|
||||
*/
|
||||
bool popupMenuEnabled() const;
|
||||
|
||||
enum BackgroundMode { NoBgMode = 0, RectangleMode, CircleMode };
|
||||
|
||||
/**
|
||||
* Makes a given date be painted with a given foregroundColor, and background
|
||||
* (a rectangle, or a circle/ellipse) in a given color.
|
||||
*/
|
||||
void setCustomDatePainting( const QDate &date, const QColor &fgColor,
|
||||
BackgroundMode bgMode = NoBgMode, const QColor &bgColor = QColor() );
|
||||
|
||||
/**
|
||||
* Unsets the custom painting of a date so that the date is painted as usual.
|
||||
*/
|
||||
void unsetCustomDatePainting( const QDate &date );
|
||||
|
||||
protected:
|
||||
/**
|
||||
* calculate the position of the cell in the matrix for the given date.
|
||||
* The result is the 0-based index.
|
||||
*/
|
||||
virtual int posFromDate( const QDate &date );
|
||||
|
||||
/**
|
||||
* calculate the date that is displayed at a given cell in the matrix. pos is the
|
||||
* 0-based index in the matrix. Inverse function to posForDate().
|
||||
*/
|
||||
virtual QDate dateFromPos( int pos );
|
||||
|
||||
virtual void paintEvent( QPaintEvent *e );
|
||||
|
||||
/**
|
||||
* React on mouse clicks that select a date.
|
||||
*/
|
||||
virtual void mousePressEvent( QMouseEvent *e );
|
||||
virtual void wheelEvent( QWheelEvent *e );
|
||||
virtual void keyPressEvent( QKeyEvent *e );
|
||||
|
||||
/**
|
||||
* Cell highlight on mouse hovering
|
||||
*/
|
||||
virtual bool event(QEvent *e);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* The selected date changed.
|
||||
*/
|
||||
void dateChanged( const QDate &date );
|
||||
|
||||
/**
|
||||
* This function behaves essentially like the one above.
|
||||
* The selected date changed.
|
||||
* @param cur The current date
|
||||
* @param old The date before the date was changed
|
||||
*/
|
||||
void dateChanged( const QDate &cur, const QDate &old );
|
||||
|
||||
/**
|
||||
* A date has been selected by clicking on the table.
|
||||
*/
|
||||
void tableClicked();
|
||||
|
||||
/**
|
||||
* A popup menu for a given date is about to be shown (as when the user
|
||||
* right clicks on that date and the popup menu is enabled). Connect
|
||||
* the slot where you fill the menu to this signal.
|
||||
*/
|
||||
void aboutToShowContextMenu( KMenu *menu, const QDate &date );
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT( d, void nextMonth() )
|
||||
Q_PRIVATE_SLOT( d, void previousMonth() )
|
||||
Q_PRIVATE_SLOT( d, void beginningOfMonth() )
|
||||
Q_PRIVATE_SLOT( d, void endOfMonth() )
|
||||
Q_PRIVATE_SLOT( d, void beginningOfWeek() )
|
||||
Q_PRIVATE_SLOT( d, void endOfWeek() )
|
||||
|
||||
private:
|
||||
class KDateTablePrivate;
|
||||
friend class KDateTablePrivate;
|
||||
KDateTablePrivate * const d;
|
||||
|
||||
void init( const QDate &date );
|
||||
void initAccels();
|
||||
void paintCell( QPainter *painter, int row, int col, const KColorScheme &colorScheme );
|
||||
|
||||
Q_DISABLE_COPY( KDateTable )
|
||||
};
|
||||
|
||||
#endif // KDATETABLE_H
|
|
@ -54,15 +54,11 @@ Group=Input (KDE)
|
|||
ToolTip=Combo Box (KDE)
|
||||
Group=Input (KDE)
|
||||
|
||||
[KDatePicker]
|
||||
[KCalendarWidget]
|
||||
ToolTip=A date selection widget (KDE)
|
||||
WhatsThis=Provides a widget for calendar date input
|
||||
Group=Date/Time (KDE)
|
||||
|
||||
[KDateTable]
|
||||
IncludeFile=kdatetable.h
|
||||
Group=Date/Time (KDE)
|
||||
|
||||
[KDialog]
|
||||
IncludeFile=kdialog.h
|
||||
ToolTip=Class for simple Dialogs (KDE)
|
||||
|
|
|
@ -24,7 +24,7 @@ install(
|
|||
kgradientselector.png
|
||||
kdualcolorbutton.png
|
||||
kpushbutton.png
|
||||
kdatepicker.png
|
||||
kcalendarwidget.png
|
||||
kdialog.png
|
||||
keditlistbox.png
|
||||
kfontcombo.png
|
||||
|
@ -36,7 +36,5 @@ install(
|
|||
kkeybutton.png
|
||||
kpalettetable.png
|
||||
kactionselector.png
|
||||
kdatetable.png
|
||||
kdatetimewidget.png
|
||||
DESTINATION ${KDE4_DATA_INSTALL_DIR}/kdewidgets/pics
|
||||
)
|
||||
|
|
Before Width: | Height: | Size: 652 B After Width: | Height: | Size: 652 B |
Binary file not shown.
Before Width: | Height: | Size: 198 B |
Binary file not shown.
Before Width: | Height: | Size: 557 B |
Loading…
Add table
Reference in a new issue