Warning, file /office/skrooge/skgbasegui/kdatepickerpopup.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of libkdepim. 0003 0004 Copyright (c) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include "kdatepickerpopup.h" 0023 0024 #include <kdatepicker.h> 0025 #include <klocalizedstring.h> 0026 0027 #include <qdatetime.h> 0028 #include <qwidgetaction.h> 0029 0030 using namespace KPIM; 0031 0032 class KDatePickerAction : public QWidgetAction // clazy:exclude=missing-qobject-macro 0033 { 0034 public: 0035 KDatePickerAction(KDatePicker* widget, QObject* iParent) 0036 : QWidgetAction(iParent), 0037 mDatePicker(widget), mOriginalParent(widget->parentWidget()) 0038 { 0039 } 0040 0041 protected: 0042 QWidget* createWidget(QWidget* iParent) override 0043 { 0044 mDatePicker->setParent(iParent); 0045 return mDatePicker; 0046 } 0047 0048 void deleteWidget(QWidget* widget) override 0049 { 0050 if (widget != mDatePicker) { 0051 return; 0052 } 0053 0054 mDatePicker->setParent(mOriginalParent); 0055 } 0056 0057 private: 0058 KDatePicker* mDatePicker; 0059 QWidget* mOriginalParent; 0060 }; 0061 0062 KDatePickerPopup::KDatePickerPopup(Items iItems, QDate iDate, QWidget* iParent) 0063 : QMenu(iParent) 0064 { 0065 mItems = iItems; 0066 0067 mDatePicker = new KDatePicker(this); 0068 mDatePicker->setCloseButton(false); 0069 0070 connect(mDatePicker, &KDatePicker::dateEntered, this, &KDatePickerPopup::slotDateChanged); 0071 connect(mDatePicker, &KDatePicker::dateSelected, this, &KDatePickerPopup::slotDateChanged); 0072 0073 mDatePicker->setDate(iDate); 0074 0075 buildMenu(); 0076 } 0077 0078 void KDatePickerPopup::buildMenu() 0079 { 0080 if (isVisible()) { 0081 return; 0082 } 0083 clear(); 0084 0085 if ((mItems & DatePicker) != 0u) { 0086 addAction(new KDatePickerAction(mDatePicker, this)); 0087 0088 if ((mItems & NoDate) != 0u || (mItems & Words) != 0u) { 0089 addSeparator(); 0090 } 0091 } 0092 0093 if ((mItems & Words) != 0u) { 0094 addAction(i18nc("@option yesterday", "&Yesterday"), this, &KDatePickerPopup::slotYesterday); 0095 addAction(i18nc("@option today", "&Today"), this, &KDatePickerPopup::slotToday); 0096 addAction(i18nc("@option tomorrow", "To&morrow"), this, &KDatePickerPopup::slotTomorrow); 0097 addAction(i18nc("@option next week", "Next &Week"), this, &KDatePickerPopup::slotNextWeek); 0098 addAction(i18nc("@option next month", "Next M&onth"), this, &KDatePickerPopup::slotNextMonth); 0099 0100 if ((mItems & NoDate) != 0u) { 0101 addSeparator(); 0102 } 0103 } 0104 0105 if ((mItems & NoDate) != 0u) { 0106 addAction(i18nc("@option do not specify a date", "No Date"), this, &KDatePickerPopup::slotNoDate); 0107 } 0108 } 0109 0110 KDatePicker* KDatePickerPopup::datePicker() const 0111 { 0112 return mDatePicker; 0113 } 0114 0115 void KDatePickerPopup::setDate(QDate date) 0116 { 0117 mDatePicker->setDate(date); 0118 } 0119 0120 #if 0 0121 void KDatePickerPopup::setItems(int items) 0122 { 0123 mItems = items; 0124 buildMenu(); 0125 } 0126 #endif 0127 0128 void KDatePickerPopup::slotDateChanged(QDate date) 0129 { 0130 emit dateChanged(date); 0131 hide(); 0132 } 0133 0134 void KDatePickerPopup::slotYesterday() 0135 { 0136 emit dateChanged(QDate::currentDate().addDays(-1)); 0137 } 0138 0139 void KDatePickerPopup::slotToday() 0140 { 0141 emit dateChanged(QDate::currentDate()); 0142 } 0143 0144 void KDatePickerPopup::slotTomorrow() 0145 { 0146 emit dateChanged(QDate::currentDate().addDays(1)); 0147 } 0148 0149 void KDatePickerPopup::slotNoDate() 0150 { 0151 emit dateChanged(QDate()); 0152 } 0153 0154 void KDatePickerPopup::slotNextWeek() 0155 { 0156 emit dateChanged(QDate::currentDate().addDays(7)); 0157 } 0158 0159 void KDatePickerPopup::slotNextMonth() 0160 { 0161 emit dateChanged(QDate::currentDate().addMonths(1)); 0162 } 0163 0164