Commit 2e52e0c1 authored by Stephane Mankowski's avatar Stephane Mankowski
Browse files

BUG:325081

Add a « Yesterday » choice in the date picker
parent b9c1aa6b
......@@ -19,6 +19,7 @@ skrooge (1.8.0)
*Correction bug 323380: Minor date bug when using the stock portfolio widgets
*Correction bug 320066: Crash importing KmyMoney exported file from Skrooge
*Correction bug 324972: Import fails without an error when account is defined in CSV
*Correction bug 325081: Add a « Yesterday » choice in the date picker
*Correction: KMyMoney exports does not need a check of integrity anymore
*Correction: Addition of all icons in size 256 and 512
*Correction: Block drop of a bookmark under an other bookmark
......
......@@ -55,7 +55,6 @@ SET(skgbasegui_SRCS
kdateedit.cpp
kdatepickerpopup.cpp
kdatevalidator.cpp
skgdatepickerpopup.cpp
skgsortfilterproxymodel.cpp
skgflowlayout.cpp
skgwebview.cpp
......
......@@ -90,6 +90,7 @@ void KDatePickerPopup::buildMenu()
}
if (mItems & Words) {
addAction(i18nc("@option yesterday", "&Yesterday"), this, SLOT(slotYesterday()));
addAction(i18nc("@option today", "&Today"), this, SLOT(slotToday()));
addAction(i18nc("@option tomorrow", "To&morrow"), this, SLOT(slotTomorrow()));
addAction(i18nc("@option next week", "Next &Week"), this, SLOT(slotNextWeek()));
......@@ -129,6 +130,11 @@ void KDatePickerPopup::slotDateChanged(const QDate& date)
hide();
}
void KDatePickerPopup::slotYesterday()
{
emit dateChanged(QDate::currentDate().addDays(-1));
}
void KDatePickerPopup::slotToday()
{
emit dateChanged(QDate::currentDate());
......
......@@ -100,6 +100,7 @@ Q_SIGNALS:
protected Q_SLOTS:
void slotDateChanged(const QDate& date);
void slotYesterday();
void slotToday();
void slotTomorrow();
void slotNextWeek();
......
......@@ -27,7 +27,7 @@
#include <KLocale>
SKGDateEdit::SKGDateEdit(QWidget* iParent, const char* name)
: KPIM::KDateEdit(iParent) // TODO(Stephane MANKOWSKI): Migrate on KDateCombo
: KPIM::KDateEdit(iParent)
{
setObjectName(name);
setMode(CURRENT);
......
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
/** @file
* A date editor with more features.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgdatepickerpopup.h"
#include <KDatePicker>
#include <KLocale>
#include <QtCore/QDateTime>
#include <QtGui/QWidgetAction>
/**
* The date picker action
*/
class SKGDatePickerAction : public QWidgetAction
{
public:
/**
* Constructor
* @param widget the date picker
* @param iParent the parent
*/
explicit SKGDatePickerAction(KDatePicker* widget, QObject* iParent)
: QWidgetAction(iParent),
mDatePicker(widget), mOriginalParent(widget->parentWidget()) {
}
protected:
/**
* This function is called whenever the action is added to a container widget that supports custom widgets.
* If you don't want a custom widget to be used as representation of the action in the specified parent widget then 0 should be returned
* @param iParent the parent
* @return the date picker
*/
QWidget* createWidget(QWidget* iParent) {
mDatePicker->setParent(iParent);
return mDatePicker;
}
/**
* This function is called whenever the action is removed from a container widget that displays the action using a custom widget previously created using createWidget().
* The default implementation hides the widget and schedules it for deletion using QObject::deleteLater().
* @param widget the widget
*/
void deleteWidget(QWidget* widget) {
if (widget != mDatePicker) {
return;
}
mDatePicker->setParent(mOriginalParent);
}
private:
KDatePicker* mDatePicker;
QWidget* mOriginalParent;
};
SKGDatePickerPopup::SKGDatePickerPopup(Items iItems, const QDate& date, QWidget* iParent)
: QMenu(iParent)
{
m_items = iItems;
m_datePicker = new KDatePicker(this);
m_datePicker->setCloseButton(false);
connect(m_datePicker, SIGNAL(dateEntered(QDate)), SLOT(slotDateChanged(QDate)));
connect(m_datePicker, SIGNAL(dateSelected(QDate)), SLOT(slotDateChanged(QDate)));
m_datePicker->setDate(date);
buildMenu();
}
void SKGDatePickerPopup::buildMenu()
{
if (isVisible()) return;
clear();
if (m_items & DatePicker) {
addAction(new SKGDatePickerAction(m_datePicker, this));
if ((m_items & NoDate) || (m_items & Words)) {
addSeparator();
}
}
if (m_items & Words) {
addAction(i18nc("@option today", "Today"), this, SLOT(slotToday()));
addAction(i18nc("@option tomorrow", "Tomorrow"), this, SLOT(slotTomorrow()));
addAction(i18nc("@option next week", "Next Week"), this, SLOT(slotNextWeek()));
addAction(i18nc("@option next month", "Next Month"), this, SLOT(slotNextMonth()));
if (m_items & NoDate) {
addSeparator();
}
}
if (m_items & NoDate) {
addAction(i18nc("@option do not specify a date", "No Date"), this, SLOT(slotNoDate()));
}
}
KDatePicker* SKGDatePickerPopup::datePicker() const
{
return m_datePicker;
}
void SKGDatePickerPopup::setDate(const QDate& date)
{
if (m_datePicker) m_datePicker->setDate(date);
}
void SKGDatePickerPopup::slotDateChanged(const QDate& date)
{
Q_EMIT dateChanged(date);
hide();
}
void SKGDatePickerPopup::slotToday()
{
Q_EMIT dateChanged(QDate::currentDate());
}
void SKGDatePickerPopup::slotTomorrow()
{
Q_EMIT dateChanged(QDate::currentDate().addDays(1));
}
void SKGDatePickerPopup::slotNoDate()
{
Q_EMIT dateChanged(QDate());
}
void SKGDatePickerPopup::slotNextWeek()
{
Q_EMIT dateChanged(QDate::currentDate().addDays(7));
}
void SKGDatePickerPopup::slotNextMonth()
{
Q_EMIT dateChanged(QDate::currentDate().addMonths(1));
}
#include "skgdatepickerpopup.moc"
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#ifndef SKGDATEPICKERPOPUP_H
#define SKGDATEPICKERPOPUP_H
/** @file
* A date edit with more features.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include <QDateTime>
#include <QMenu>
#include "skgbasegui_export.h"
class KDatePicker;
/**
* This file is a date edit with more features
* based on SKGDatePickerPopup of PIM
*/
class SKGBASEGUI_EXPORT SKGDatePickerPopup: public QMenu
{
Q_OBJECT
/**
* Mode of the picker
*/
Q_ENUMS(ItemFlag)
public:
/**
* Mode of the picker
*/
enum ItemFlag {
NoDate = 1,
DatePicker = 2,
Words = 4
};
/**
* Flags for the picker
*/
Q_DECLARE_FLAGS(Items, ItemFlag)
/**
* A constructor for the SKGDatePickerPopup.
* @param iItems List of all desirable items, separated with a bitwise OR.
* @param date Initial date of datepicker-widget.
* @param iParent The object's parent.
*/
explicit SKGDatePickerPopup(Items iItems = DatePicker,
const QDate& date = QDate::currentDate(),
QWidget* iParent = 0);
/**
* Get date picker
* @return date picker
*/
KDatePicker* datePicker() const;
/**
* Set date
* @param date the date
*/
virtual void setDate(const QDate& date);
/**
* Returns items
* @return
*/
virtual int items() const {
return m_items;
}
Q_SIGNALS:
/**
* This signal emits the new date (selected with datepicker or other
* menu-items).
*/
void dateChanged(const QDate& date);
private Q_SLOTS:
void slotDateChanged(const QDate& date);
void slotToday();
void slotTomorrow();
void slotNextWeek();
void slotNextMonth();
void slotNoDate();
private:
void buildMenu();
KDatePicker* m_datePicker;
Items m_items;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(SKGDatePickerPopup::Items)
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment