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

akonadi/contact

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
30 class KDatePickerAction : public QWidgetAction
31 {
32 public:
33  KDatePickerAction(KDatePicker *widget, QObject *parent)
34  : QWidgetAction(parent)
35  , mDatePicker(widget)
36  , mOriginalParent(widget->parentWidget())
37  {
38  }
39 
40 protected:
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 
56 private:
57  KDatePicker *mDatePicker;
58  QWidget *mOriginalParent;
59 };
60 
61 KDatePickerPopup::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 
79 void 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 
110 KDatePicker *KDatePickerPopup::datePicker() const
111 {
112  return mDatePicker;
113 }
114 
115 void KDatePickerPopup::setDate(const QDate &date)
116 {
117  mDatePicker->setDate(date);
118 }
119 
120 #if 0
121 void KDatePickerPopup::setItems(int items)
122 {
123  mItems = items;
124  buildMenu();
125 }
126 #endif
127 
128 void KDatePickerPopup::slotDateChanged(const QDate &date)
129 {
130  if (date != mDate) {
131  emit dateChanged(date);
132  }
133  hide();
134 }
135 
136 void KDatePickerPopup::slotToday()
137 {
138  emit dateChanged(QDate::currentDate());
139 }
140 
141 void KDatePickerPopup::slotTomorrow()
142 {
143  emit dateChanged(QDate::currentDate().addDays(1));
144 }
145 
146 void KDatePickerPopup::slotNoDate()
147 {
148  emit dateChanged(QDate());
149 }
150 
151 void KDatePickerPopup::slotNextWeek()
152 {
153  emit dateChanged(QDate::currentDate().addDays(7));
154 }
155 
156 void KDatePickerPopup::slotNextMonth()
157 {
158  emit dateChanged(QDate::currentDate().addMonths(1));
159 }
160 
161 #include "moc_kdatepickerpopup_p.cpp"
QWidget
KDatePickerPopup::dateChanged
void dateChanged(const QDate &date)
This signal emits the new date (selected with datepicker or other menu-items).
QMenu::addAction
void addAction(QAction *action)
QWidget::isVisible
bool isVisible() const
KDatePickerPopup::datePicker
KDatePicker * datePicker() const
Definition: kdatepickerpopup.cpp:110
QWidget::setParent
void setParent(QWidget *parent)
QMenu::clear
void clear()
QAction::parentWidget
QWidget * parentWidget() const
QWidgetAction
QObject
KDatePickerPopup::KDatePickerPopup
KDatePickerPopup(Items items=DatePicker, const QDate &date=QDate::currentDate(), QWidget *parent=0)
A constructor for the KDatePickerPopup.
Definition: kdatepickerpopup.cpp:61
QDate
QMenu::addSeparator
QAction * addSeparator()
QWidget::hide
void hide()
QMenu
QWidgetAction::createWidget
virtual QWidget * createWidget(QWidget *parent)
QDate::currentDate
QDate currentDate()
QWidgetAction::deleteWidget
virtual void deleteWidget(QWidget *widget)
KDatePickerPopup::items
int items() const
Definition: kdatepickerpopup_p.h:87
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:19 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs 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

Search



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