Commit e8cb7dcc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Move kdatepickerpopup from libkdepim

parent 51c621e5
Pipeline #23523 passed with stage
in 19 minutes and 29 seconds
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.14.42")
set(PIM_VERSION "5.14.43")
project(calendarsupport VERSION ${PIM_VERSION})
......
......@@ -22,6 +22,7 @@ set(calendarsupport_LIB_SRCS
tagcache.cpp
plugin.cpp
urihandler.cpp
kdatepickerpopup.cpp
printing/calprintpluginbase.cpp
printing/calprintdefaultplugins.cpp
......@@ -107,6 +108,7 @@ ecm_generate_headers(CalendarSupport_CamelCase_HEADERS
MessageWidget
ArchiveDialog
NoteEditDialog
KDatePickerPopup
UriHandler
REQUIRED_HEADERS CalendarSupport_HEADERS
PREFIX CalendarSupport
......
/*
This file is part of libkdepim.
Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
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 "kdatepickerpopup.h"
#include <KDatePicker>
#include <KLocalizedString>
#include <QDateTime>
#include <QWidgetAction>
using namespace CalendarSupport;
class KDatePickerAction : public QWidgetAction
{
public:
KDatePickerAction(KDatePicker *widget, QObject *parent)
: QWidgetAction(parent)
, mDatePicker(widget)
, mOriginalParent(widget->parentWidget())
{
}
protected:
QWidget *createWidget(QWidget *parent) override
{
mDatePicker->setParent(parent);
return mDatePicker;
}
void deleteWidget(QWidget *widget) override
{
if (widget != mDatePicker) {
return;
}
mDatePicker->setParent(mOriginalParent);
}
private:
KDatePicker *mDatePicker = nullptr;
QWidget *mOriginalParent = nullptr;
};
class Q_DECL_HIDDEN KDatePickerPopup::Private
{
public:
Private(KDatePickerPopup *qq)
: q(qq)
, mDatePicker(nullptr)
{
}
void buildMenu();
void slotDateChanged(const QDate &);
void slotToday();
void slotTomorrow();
void slotNextWeek();
void slotNextMonth();
void slotNoDate();
KDatePickerPopup *q = nullptr;
KDatePicker *mDatePicker = nullptr;
Modes mModes;
};
void KDatePickerPopup::Private::buildMenu()
{
if (q->isVisible()) {
return;
}
q->clear();
if (mModes & DatePicker) {
q->addAction(new KDatePickerAction(mDatePicker, q));
if ((mModes & NoDate) || (mModes & Words)) {
q->addSeparator();
}
}
if (mModes & Words) {
q->addAction(i18nc("@option today", "&Today"), q, [this]() {
slotToday();
});
q->addAction(i18nc("@option tomorrow", "To&morrow"), q, [this]() {
slotTomorrow();
});
q->addAction(i18nc("@option next week", "Next &Week"), q, [this]() {
slotNextWeek();
});
q->addAction(i18nc("@option next month", "Next M&onth"), q, [this]() {
slotNextMonth();
});
if (mModes & NoDate) {
q->addSeparator();
}
}
if (mModes & NoDate) {
q->addAction(i18nc("@option do not specify a date", "No Date"), q, [this]() {
slotNoDate();
});
}
}
void KDatePickerPopup::Private::slotDateChanged(const QDate &date)
{
Q_EMIT q->dateChanged(date);
q->hide();
}
void KDatePickerPopup::Private::slotToday()
{
Q_EMIT q->dateChanged(QDate::currentDate());
}
void KDatePickerPopup::Private::slotTomorrow()
{
Q_EMIT q->dateChanged(QDate::currentDate().addDays(1));
}
void KDatePickerPopup::Private::slotNoDate()
{
Q_EMIT q->dateChanged(QDate());
}
void KDatePickerPopup::Private::slotNextWeek()
{
Q_EMIT q->dateChanged(QDate::currentDate().addDays(7));
}
void KDatePickerPopup::Private::slotNextMonth()
{
Q_EMIT q->dateChanged(QDate::currentDate().addMonths(1));
}
KDatePickerPopup::KDatePickerPopup(Modes modes, const QDate &date, QWidget *parent)
: QMenu(parent)
, d(new Private(this))
{
d->mModes = modes;
d->mDatePicker = new KDatePicker(this);
d->mDatePicker->setCloseButton(false);
connect(d->mDatePicker, &KDatePicker::dateEntered, this, [this](const QDate &date) {
d->slotDateChanged(date);
});
connect(d->mDatePicker, &KDatePicker::dateSelected, this, [this](const QDate &date) {
d->slotDateChanged(date);
});
d->mDatePicker->setDate(date);
d->buildMenu();
}
KDatePickerPopup::~KDatePickerPopup()
{
delete d;
}
KDatePicker *KDatePickerPopup::datePicker() const
{
return d->mDatePicker;
}
void KDatePickerPopup::setDate(const QDate &date)
{
d->mDatePicker->setDate(date);
}
#include "moc_kdatepickerpopup.cpp"
/*
This file is part of libkdepim.
Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
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 CALENDARSUPPORT_KDATEPICKERPOPUP_H
#define CALENDARSUPPORT_KDATEPICKERPOPUP_H
#include "calendarsupport_export.h"
#include <QDate>
#include <QMenu>
class KDatePicker;
namespace CalendarSupport {
/**
* @short This menu helps the user to select a date quickly.
*
* This menu helps the user to select a date quickly. It offers various
* modes of selecting, e.g. with a KDatePicker or with words like "Tomorrow".
*
* The available modes are:
*
* @li NoDate: A menu-item with "No Date". If chosen, the datepicker will emit
* a null QDate.
* @li DatePicker: Shows a KDatePicker-widget.
* @li Words: Shows items like "Today", "Tomorrow" or "Next Week".
*
* @author Bram Schoenmakers <bram_s@softhome.net>
*/
class CALENDARSUPPORT_EXPORT KDatePickerPopup : public QMenu
{
Q_OBJECT
public:
/**
* Describes the available selection modes.
*/
enum Mode {
NoDate = 1, ///< A menu-item with "No Date". Will always return an invalid date.
DatePicker = 2, ///< A menu-item with a KDatePicker.
Words = 4 ///< A menu-item with list of words that describe a date.
};
/**
* Describes the a set of combined modes.
*/
Q_DECLARE_FLAGS(Modes, Mode)
/**
* Creates a new date picker popup.
*
* @param modes The selection modes that shall be offered
* @param date The initial date of date picker widget.
* @param parent The parent object.
*/
explicit KDatePickerPopup(Modes modes = DatePicker, const QDate &date = QDate::currentDate(), QWidget *parent = nullptr);
/**
* Destroys the date picker popup.
*/
~KDatePickerPopup();
/**
* Returns the used KDatePicker object.
*/
Q_REQUIRED_RESULT KDatePicker *datePicker() const;
public Q_SLOTS:
/**
* Sets the current @p date.
*/
void setDate(const QDate &date);
Q_SIGNALS:
/**
* This signal is emitted whenever the user has selected a new date.
*
* @param date The new date.
*/
void dateChanged(const QDate &date);
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KDatePickerPopup::Modes)
}
#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