diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 2a491b86..74f81512 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -539,6 +539,7 @@ install( Plasma/ToolTipContent Plasma/ToolTipManager Plasma/TreeView + Plasma/CalendarWidget Plasma/Version Plasma/View Plasma/Wallpaper diff --git a/includes/Plasma/CalendarWidget b/includes/Plasma/CalendarWidget new file mode 100644 index 00000000..32614a39 --- /dev/null +++ b/includes/Plasma/CalendarWidget @@ -0,0 +1 @@ +#include "../../plasma/widgets/calendarwidget.h" diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt index da1bb3e1..75065909 100644 --- a/plasma/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -138,6 +138,7 @@ set(plasma_LIB_SRCS widgets/textbrowser.cpp widgets/treeview.cpp widgets/textedit.cpp + widgets/calendarwidget.cpp ) set_source_files_properties( @@ -256,6 +257,7 @@ install( widgets/textbrowser.h widgets/treeview.h widgets/textedit.h + widgets/calendarwidget.h DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}/plasma/widgets ) diff --git a/plasma/widgets/calendarwidget.cpp b/plasma/widgets/calendarwidget.cpp new file mode 100644 index 00000000..ae3bea05 --- /dev/null +++ b/plasma/widgets/calendarwidget.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2023 Ivailo Monev + * + * This program 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, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "calendarwidget.h" +#include "private/style_p.h" +#include "kcalendarwidget.h" + +namespace Plasma +{ + +class CalendarWidgetPrivate +{ +public: + Plasma::Style::Ptr style; +}; + +CalendarWidget::CalendarWidget(QGraphicsWidget *parent) + : QGraphicsProxyWidget(parent), + d(new CalendarWidgetPrivate()) +{ + KCalendarWidget *native = new KCalendarWidget(); + setWidget(native); + native->setWindowIcon(QIcon()); + native->setAttribute(Qt::WA_NoSystemBackground); + // the popup of the navigation bar does not inherit the WA_NoSystemBackground attribute + native->setNavigationBarVisible(false); + connect(native, SIGNAL(clicked(QDate)), this, SIGNAL(clicked(QDate))); + connect(native, SIGNAL(activated(QDate)), this, SIGNAL(activated(QDate))); + + d->style = Plasma::Style::sharedStyle(); + native->setStyle(d->style.data()); +} + +CalendarWidget::~CalendarWidget() +{ + delete d; + Plasma::Style::doneWithSharedStyle(); +} + +void CalendarWidget::setSelectedDate(const QDate &date) +{ + nativeWidget()->setSelectedDate(date); +} + +QDate CalendarWidget::selectedDate() const +{ + return nativeWidget()->selectedDate(); +} + +void CalendarWidget::setStyleSheet(const QString &stylesheet) +{ + widget()->setStyleSheet(stylesheet); +} + +QString CalendarWidget::styleSheet() +{ + return widget()->styleSheet(); +} + +KCalendarWidget *CalendarWidget::nativeWidget() const +{ + return static_cast(widget()); +} + +} + +#include "moc_calendarwidget.cpp" diff --git a/plasma/widgets/calendarwidget.h b/plasma/widgets/calendarwidget.h new file mode 100644 index 00000000..0bcb3b78 --- /dev/null +++ b/plasma/widgets/calendarwidget.h @@ -0,0 +1,90 @@ +/* + * Copyright 2023 Ivailo Monev + * + * This program 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, 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 Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef PLASMA_CALENDARWIDGET_H +#define PLASMA_CALENDARWIDGET_H + +#include + +#include + +class KCalendarWidget; + +namespace Plasma +{ + +class CalendarWidgetPrivate; + +/** + * @class CalendarWidget plasma/widgets/calendarwidget.h + * + * @short Provides a plasma-themed KCalendarWidget. + */ +class PLASMA_EXPORT CalendarWidget : public QGraphicsProxyWidget +{ + Q_OBJECT + + Q_PROPERTY(QDate selectedDate READ selectedDate WRITE setSelectedDate) + Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget) + Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet) + Q_PROPERTY(KCalendarWidget *nativeWidget READ nativeWidget) + +public: + explicit CalendarWidget(QGraphicsWidget *parent = 0); + ~CalendarWidget(); + + /** + * @return the date selected + */ + QDate selectedDate() const; + + /** + * Sets the selected data + * + * @param model the model to display + */ + void setSelectedDate(const QDate &date); + + /** + * Sets the stylesheet used to control the visual display of this CalendarWidget + * + * @param stylesheet a CSS string + */ + void setStyleSheet(const QString &stylesheet); + + /** + * @return the stylesheet currently used with this widget + */ + QString styleSheet(); + + /** + * @return the native widget wrapped by this CalendarWidget + */ + KCalendarWidget *nativeWidget() const; + +Q_SIGNALS: + void clicked(QDate); + void activated(QDate); + +private: + CalendarWidgetPrivate *const d; +}; + +} +#endif // multiple inclusion guard