• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi/contact

  • akonadi
  • contact
  • editor
kdatepickerpopup.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "kdatepickerpopup_p.h"
23
24#include <KDatePicker>
25#include <KLocalizedString>
26
27#include <QtCore/QDateTime>
28#include <QWidgetAction>
29
30class KDatePickerAction : public QWidgetAction
31{
32public:
33 KDatePickerAction(KDatePicker *widget, QObject *parent)
34 : QWidgetAction(parent)
35 , mDatePicker(widget)
36 , mOriginalParent(widget->parentWidget())
37 {
38 }
39
40protected:
41 QWidget *createWidget(QWidget *parent)
42 {
43 mDatePicker->setParent(parent);
44 return mDatePicker;
45 }
46
47 void deleteWidget(QWidget *widget)
48 {
49 if (widget != mDatePicker) {
50 return;
51 }
52
53 mDatePicker->setParent(mOriginalParent);
54 }
55
56private:
57 KDatePicker *mDatePicker;
58 QWidget *mOriginalParent;
59};
60
61KDatePickerPopup::KDatePickerPopup(Items items, const QDate &date, QWidget *parent)
62 : QMenu(parent)
63{
64 mItems = items;
65 mDate = date;
66 mDatePicker = new KDatePicker(this);
67 mDatePicker->setCloseButton(false);
68
69 connect(mDatePicker, SIGNAL(dateEntered(QDate)),
70 SLOT(slotDateChanged(QDate)));
71 connect(mDatePicker, SIGNAL(dateSelected(QDate)),
72 SLOT(slotDateChanged(QDate)));
73
74 mDatePicker->setDate(date);
75
76 buildMenu();
77}
78
79void KDatePickerPopup::buildMenu()
80{
81 if (isVisible()) {
82 return;
83 }
84 clear();
85
86 if (mItems & DatePicker) {
87 addAction(new KDatePickerAction(mDatePicker, this));
88
89 if ((mItems & NoDate) || (mItems & Words)) {
90 addSeparator();
91 }
92 }
93
94 if (mItems & Words) {
95 addAction(i18nc("@option today", "&Today"), this, SLOT(slotToday()));
96 addAction(i18nc("@option tomorrow", "To&morrow"), this, SLOT(slotTomorrow()));
97 addAction(i18nc("@option next week", "Next &Week"), this, SLOT(slotNextWeek()));
98 addAction(i18nc("@option next month", "Next M&onth"), this, SLOT(slotNextMonth()));
99
100 if (mItems & NoDate) {
101 addSeparator();
102 }
103 }
104
105 if (mItems & NoDate) {
106 addAction(i18nc("@option do not specify a date", "No Date"), this, SLOT(slotNoDate()));
107 }
108}
109
110KDatePicker *KDatePickerPopup::datePicker() const
111{
112 return mDatePicker;
113}
114
115void KDatePickerPopup::setDate(const QDate &date)
116{
117 mDatePicker->setDate(date);
118}
119
120#if 0
121void KDatePickerPopup::setItems(int items)
122{
123 mItems = items;
124 buildMenu();
125}
126#endif
127
128void KDatePickerPopup::slotDateChanged(const QDate &date)
129{
130 if (date != mDate) {
131 emit dateChanged(date);
132 }
133 hide();
134}
135
136void KDatePickerPopup::slotToday()
137{
138 emit dateChanged(QDate::currentDate());
139}
140
141void KDatePickerPopup::slotTomorrow()
142{
143 emit dateChanged(QDate::currentDate().addDays(1));
144}
145
146void KDatePickerPopup::slotNoDate()
147{
148 emit dateChanged(QDate());
149}
150
151void KDatePickerPopup::slotNextWeek()
152{
153 emit dateChanged(QDate::currentDate().addDays(7));
154}
155
156void KDatePickerPopup::slotNextMonth()
157{
158 emit dateChanged(QDate::currentDate().addMonths(1));
159}
160
161#include "moc_kdatepickerpopup_p.cpp"
KDatePickerPopup::datePicker
KDatePicker * datePicker() const
Definition: kdatepickerpopup.cpp:110
KDatePickerPopup::dateChanged
void dateChanged(const QDate &date)
This signal emits the new date (selected with datepicker or other menu-items).
KDatePickerPopup::items
int items() const
Definition: kdatepickerpopup_p.h:87
KDatePickerPopup::KDatePickerPopup
KDatePickerPopup(Items items=DatePicker, const QDate &date=QDate::currentDate(), QWidget *parent=0)
A constructor for the KDatePickerPopup.
Definition: kdatepickerpopup.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal