141 lines
3.6 KiB
C++
Executable File
141 lines
3.6 KiB
C++
Executable File
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "lts_widgets_export.h"
|
|
|
|
#include <QDate>
|
|
#include <QWidget>
|
|
#include <functional>
|
|
|
|
class QDateTime;
|
|
|
|
namespace Ui
|
|
{
|
|
class LtsDateTimeEdit;
|
|
}
|
|
|
|
class QShortcut;
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
class LTSWIDGETS_EXPORT LtsDateTimeEdit : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool autoForward READ getAutoForward WRITE setAutoForward)
|
|
Q_PROPERTY(bool editTimezone READ getEditTimezone WRITE setEditTimezone)
|
|
Q_PROPERTY(bool withButtons READ getWithButtons WRITE setWithButtons)
|
|
Q_PROPERTY(bool withSlider READ getWithSlider WRITE setWithSlider)
|
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
|
Q_PROPERTY(bool withNowButton READ withNowButton WRITE setWithNowButton)
|
|
Q_PROPERTY(bool withCheckBox READ withCheckBox WRITE setWithCheckBox)
|
|
|
|
public:
|
|
using CurrentTimeCallback = std::function<qint64()>;
|
|
explicit LtsDateTimeEdit(QWidget *parent = nullptr, bool withNowButton = true, bool withCheckBox = false);
|
|
~LtsDateTimeEdit();
|
|
|
|
qint64 msecsSinceEpoch() const;
|
|
bool isEmpty() const { return msecsSinceEpoch() == 0; }
|
|
|
|
void setAutoForward(const bool af) { m_autoForward = af; }
|
|
bool getAutoForward() const { return m_autoForward; }
|
|
|
|
void setEditTimezone(const bool edit) { m_editTimezone = edit; }
|
|
bool getEditTimezone() const { return m_editTimezone; }
|
|
|
|
void setWithButtons(const bool buttons) { m_withButtons = buttons; }
|
|
bool getWithButtons() const { return m_withButtons; }
|
|
|
|
void setWithSlider(const bool slider) { m_withSlider = slider; }
|
|
bool getWithSlider() const { return m_withSlider; }
|
|
|
|
void setReadOnly(const bool readOnly) { m_readOnly = readOnly; }
|
|
bool isReadOnly() const { return m_readOnly; }
|
|
|
|
bool withCheckBox() const { return m_withCheckBox; }
|
|
void setCheckBoxChecked(bool bChecked);
|
|
bool isCheckBoxChecked() const;
|
|
|
|
bool withNowButton() const { return m_withNowButton; }
|
|
void setDateTime(const QDateTime &datetime);
|
|
|
|
|
|
void setMinimumTimeMSec(qint64 msec);
|
|
qint64 minimumTimeMSec() const;
|
|
|
|
|
|
void setMaximumTimeMSec(qint64 msec);
|
|
qint64 maximumTimeMSec() const { return m_maxTimeMSec; };
|
|
|
|
void setMinMaxTimeMSec(qint64 min, qint64 max) { setMinimumTimeMSec(min); setMaximumTimeMSec(max); }
|
|
|
|
void setRetrieveCurrentTimeCallback(const CurrentTimeCallback &cb);
|
|
void updateDateTimeType();
|
|
|
|
bool setTimezone(char tz);
|
|
char getTimezone() const;
|
|
|
|
|
|
void setSubWidgetsProperties(QString name, QVariant value);
|
|
|
|
bool isValidDate() const
|
|
{
|
|
|
|
return m_dateTime.isValid();
|
|
}
|
|
|
|
private:
|
|
QDateTime dateTime() const;
|
|
void setMinMaxMonth(int minMonth, int maxMonth);
|
|
|
|
public slots:
|
|
void setWithCheckBox(bool checkBoxEnabled);
|
|
void setWithNowButton(bool nowButton);
|
|
void setMsecsSinceEpoch(qint64 mSecsSinceEpoch);
|
|
void clear();
|
|
|
|
void onSetFixedDateTime();
|
|
void onSetOffsetDateTime();
|
|
|
|
public slots:
|
|
void onDateTimeChanged();
|
|
|
|
signals:
|
|
void dateTimeChanged();
|
|
void withCheckBoxChanged(bool checkBoxEnabled);
|
|
void withNowButtonChanged(bool nowButton);
|
|
|
|
private slots:
|
|
void onCheckBoxChanged(bool checked);
|
|
void onTimeZoneChanged();
|
|
void onMonthChanged(int month);
|
|
|
|
private:
|
|
|
|
qint64 m_minTimeMSec = 0;
|
|
qint64 m_maxTimeMSec = 0;
|
|
qint64 m_curTimeMSec = -1;
|
|
|
|
bool m_editTimezone = true;
|
|
bool m_autoForward = true;
|
|
bool m_withButtons = false;
|
|
bool m_withSlider = false;
|
|
bool m_readOnly = false;
|
|
bool m_withCheckBox = false;
|
|
bool m_withNowButton = false;
|
|
|
|
int m_tzOffset;
|
|
int m_minMonth;
|
|
int m_maxMonth;
|
|
QShortcut *m_scFixed;
|
|
QShortcut *m_scOffset;
|
|
QDateTime m_dateTime;
|
|
CurrentTimeCallback m_getCurrentTimeCallback;
|
|
Ui::LtsDateTimeEdit *m_ui;
|
|
};
|
|
|
|
}
|