File indexing completed on 2024-11-24 04:39:32

0001 /*
0002     This file is part of Contact Editor.
0003 
0004     SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QDate>
0012 #include <QLineEdit>
0013 #include <QWidget>
0014 
0015 class KDatePickerPopup;
0016 
0017 class QContextMenuEvent;
0018 class QToolButton;
0019 
0020 class DateView : public QLineEdit
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit DateView(QWidget *parent = nullptr);
0026 
0027 Q_SIGNALS:
0028     void resetDate();
0029 
0030 protected:
0031     void contextMenuEvent(QContextMenuEvent *event) override;
0032 
0033 private:
0034     void emitSignal();
0035 };
0036 
0037 class DateEditWidget : public QWidget
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     enum Type { General, Birthday, Anniversary };
0043 
0044     explicit DateEditWidget(Type type = General, QWidget *parent = nullptr);
0045     ~DateEditWidget() override;
0046 
0047     void setDate(const QDate &date);
0048     [[nodiscard]] QDate date() const;
0049 
0050     void setReadOnly(bool readOnly);
0051 
0052 private:
0053     void dateSelected(const QDate &date);
0054     void resetDate();
0055     void updateView();
0056     DateView *mView = nullptr;
0057     QToolButton *mSelectButton = nullptr;
0058     QToolButton *mClearButton = nullptr;
0059     KDatePickerPopup *mMenu = nullptr;
0060     QDate mDate;
0061     bool mReadOnly = false;
0062 };