File indexing completed on 2024-05-12 05:14:38
0001 /* 0002 * alarmtimewidget.h - alarm date/time entry widget 0003 * Program: kalarm 0004 * SPDX-FileCopyrightText: 2001-2023 David Jarvie <djarvie@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "kalarmcalendar/datetime.h" 0012 0013 #include <QFrame> 0014 0015 class QAbstractButton; 0016 class KDateComboBox; 0017 class ButtonGroup; 0018 class ComboBox; 0019 class RadioButton; 0020 class CheckBox; 0021 class PushButton; 0022 class TimeEdit; 0023 class TimePeriod; 0024 class TimeSpinBox; 0025 class TimeZoneCombo; 0026 0027 using namespace KAlarmCal; 0028 0029 0030 class AlarmTimeWidget : public QFrame 0031 { 0032 Q_OBJECT 0033 public: 0034 enum Mode { // 'mode' values for constructor 0035 AT_TIME = 0x01, // "At ..." 0036 DEFER_TIME = 0x02, // "Defer to ..." 0037 DEFER_ANY_TIME = DEFER_TIME | 0x04 // "Defer to ..." with 'any time' option 0038 }; 0039 AlarmTimeWidget(const QString& groupBoxTitle, Mode, QWidget* parent = nullptr); 0040 explicit AlarmTimeWidget(Mode, QWidget* parent = nullptr); 0041 KADateTime getDateTime(bool checkExpired = true, bool showErrorMessage = true, QWidget** errorWidget = nullptr) const 0042 { return getDateTime(nullptr, checkExpired, showErrorMessage, errorWidget); } 0043 KADateTime getDateTime(int* minsFromNow) const 0044 { return getDateTime(minsFromNow, true, true, nullptr); } 0045 void setDateTime(const DateTime&); 0046 void setMinDateTimeIsCurrent(); 0047 void setMinDateTime(const KADateTime& = KADateTime()); 0048 void setMaxDateTime(const DateTime& = DateTime()); 0049 const KADateTime& maxDateTime() const { return mMaxDateTime; } 0050 KADateTime::Spec timeSpec() const { return mTimeSpec; } 0051 void setReadOnly(bool); 0052 bool anyTime() const { return mAnyTime; } 0053 bool anyTimeSelected() const; 0054 void enableAnyTime(bool enable); 0055 0056 /** Select/deselect 'Time from now' option. 0057 * @param minutes Value to set in 'Time from now', or 0058 * if < 0, select 'At date/time' option. 0059 */ 0060 void selectTimeFromNow(int minutes = 0); 0061 void focusTimeFromNow(); 0062 void showMoreOptions(bool); 0063 QSize sizeHint() const override { return minimumSizeHint(); } 0064 0065 static QString i18n_TimeAfterPeriod(); 0066 static const int maxDelayTime; // maximum time from now 0067 0068 Q_SIGNALS: 0069 void changed(const KAlarmCal::KADateTime&); 0070 void dateOnlyToggled(bool anyTime); 0071 void pastMax(); 0072 0073 private Q_SLOTS: 0074 void updateTimes(); 0075 void slotButtonSet(QAbstractButton*); 0076 void dateTimeChanged(); 0077 void delayTimeChanged(int); 0078 void slotPresetSelected(int); 0079 void slotAnyTimeToggled(bool); 0080 void slotTimeZoneChanged(); 0081 void showTimeZoneSelector(); 0082 0083 private: 0084 void init(Mode, const QString& groupBoxTitle = QString()); 0085 KADateTime getDateTime(int* minsFromNow, bool checkExpired, bool showErrorMessage, QWidget** errorWidget) const; 0086 void setAnyTime(); 0087 void setMaxDelayTime(const KADateTime& now); 0088 void setMaxMinTimeIf(const KADateTime& now); 0089 0090 ButtonGroup* mButtonGroup; 0091 RadioButton* mAtTimeRadio; 0092 RadioButton* mAfterTimeRadio; 0093 CheckBox* mAnyTimeCheckBox; 0094 KDateComboBox* mDateEdit; 0095 TimeEdit* mTimeEdit; 0096 TimeSpinBox* mDelayTimeEdit{nullptr}; 0097 TimePeriod* mDelayTimePeriod{nullptr}; 0098 ComboBox* mPresetsCombo{nullptr}; 0099 PushButton* mTimeZoneButton; 0100 QWidget* mTimeZoneBox; // contains label and time zone combo box 0101 TimeZoneCombo* mTimeZone; 0102 KADateTime mMinDateTime; // earliest allowed date/time 0103 KADateTime mMaxDateTime; // latest allowed date/time 0104 KADateTime::Spec mTimeSpec; // time spec used 0105 int mAnyTime; // 0 = date/time is specified, 1 = only a date, -1 = uninitialised 0106 bool mAnyTimeAllowed; // 'mAnyTimeCheckBox' is enabled 0107 bool mDeferring; // being used to enter a deferral time 0108 bool mMinDateTimeIsNow {false}; // earliest allowed date/time is the current time 0109 bool mPastMax {false}; // current time is past the maximum date/time 0110 bool mMinMaxTimeSet {false}; // limits have been set for the time edit control 0111 }; 0112 0113 // vim: et sw=4: