2023-02-16 13:51:55 +08:00
|
|
|
// Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
#ifndef DATETIMEDISPLAYER_H
|
|
|
|
#define DATETIMEDISPLAYER_H
|
|
|
|
|
|
|
|
#include "constants.h"
|
|
|
|
|
2022-11-18 17:08:32 +08:00
|
|
|
#include "org_deepin_dde_timedate1.h"
|
2022-09-16 20:12:52 +00:00
|
|
|
|
2022-05-12 17:09:10 +08:00
|
|
|
#include <QWidget>
|
|
|
|
#include <QFont>
|
|
|
|
|
2023-10-17 13:48:10 +08:00
|
|
|
#include <dtkcore_global.h>
|
|
|
|
|
2022-05-20 11:11:45 +08:00
|
|
|
namespace Dock { class TipsWidget; }
|
2022-08-16 09:39:43 +00:00
|
|
|
|
2022-05-20 11:11:45 +08:00
|
|
|
class DockPopupWindow;
|
2022-08-16 09:39:43 +00:00
|
|
|
class QMenu;
|
2023-10-17 13:48:10 +08:00
|
|
|
DCORE_BEGIN_NAMESPACE
|
|
|
|
class DConfig;
|
|
|
|
DCORE_END_NAMESPACE
|
2022-05-20 11:11:45 +08:00
|
|
|
|
2022-11-18 17:08:32 +08:00
|
|
|
using Timedate = org::deepin::dde::Timedate1;
|
2022-05-12 17:09:10 +08:00
|
|
|
|
|
|
|
class DateTimeDisplayer : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct DateTimeInfo {
|
|
|
|
QString m_time;
|
|
|
|
QString m_date;
|
|
|
|
QRect m_timeRect;
|
|
|
|
QRect m_dateRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2022-10-19 03:50:12 +00:00
|
|
|
explicit DateTimeDisplayer(bool showMultiRow, QWidget *parent = nullptr);
|
2022-05-12 17:09:10 +08:00
|
|
|
~DateTimeDisplayer() override;
|
2022-05-17 20:57:09 +08:00
|
|
|
void setPositon(Dock::Position position);
|
2022-05-20 11:11:45 +08:00
|
|
|
void setOneRow(bool oneRow);
|
2022-08-25 19:31:31 +00:00
|
|
|
QSize suitableSize() const;
|
|
|
|
QSize suitableSize(const Dock::Position &position) const;
|
2022-05-17 20:57:09 +08:00
|
|
|
|
2022-05-20 11:11:45 +08:00
|
|
|
Q_SIGNALS:
|
2022-08-16 09:39:43 +00:00
|
|
|
void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸
|
2023-03-09 16:46:07 +08:00
|
|
|
void requestDrawBackground(const QRect &rect);
|
2022-05-20 11:11:45 +08:00
|
|
|
|
2022-05-17 20:57:09 +08:00
|
|
|
protected:
|
2022-08-16 09:39:43 +00:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
2022-05-17 20:57:09 +08:00
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2022-05-20 11:11:45 +08:00
|
|
|
void enterEvent(QEvent *event) override;
|
|
|
|
void leaveEvent(QEvent *event) override;
|
2023-04-13 11:15:05 +08:00
|
|
|
bool event(QEvent *event) override;
|
2022-05-17 20:57:09 +08:00
|
|
|
|
|
|
|
private:
|
2022-05-20 11:11:45 +08:00
|
|
|
void updatePolicy();
|
2022-08-25 19:31:31 +00:00
|
|
|
DateTimeInfo dateTimeInfo(const Dock::Position &position) const;
|
2022-05-20 11:11:45 +08:00
|
|
|
void updateLastData(const DateTimeInfo &info);
|
|
|
|
|
2023-08-30 16:05:02 +08:00
|
|
|
inline QString getTimeString() const;
|
2022-08-25 19:31:31 +00:00
|
|
|
QString getTimeString(const Dock::Position &position) const;
|
2023-08-30 16:05:02 +08:00
|
|
|
inline QString getDateString() const;
|
2022-08-25 19:31:31 +00:00
|
|
|
QString getDateString(const Dock::Position &position) const;
|
2022-05-20 11:11:45 +08:00
|
|
|
|
|
|
|
QPoint tipsPoint() const;
|
2023-08-30 16:05:02 +08:00
|
|
|
void updateFont() const;
|
2022-05-17 20:57:09 +08:00
|
|
|
|
2022-08-16 09:39:43 +00:00
|
|
|
void createMenuItem();
|
2022-10-19 03:50:12 +00:00
|
|
|
QRect textRect(const QRect &sourceRect) const;
|
2022-08-16 09:39:43 +00:00
|
|
|
|
2022-05-20 11:11:45 +08:00
|
|
|
private Q_SLOTS:
|
|
|
|
void onTimeChanged();
|
|
|
|
void onDateTimeFormatChanged();
|
2022-05-17 20:57:09 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Timedate *m_timedateInter;
|
|
|
|
Dock::Position m_position;
|
2023-05-10 20:51:18 +08:00
|
|
|
mutable QFont m_dateFont;
|
|
|
|
mutable QFont m_timeFont;
|
2022-05-20 11:11:45 +08:00
|
|
|
Dock::TipsWidget *m_tipsWidget;
|
2022-08-16 09:39:43 +00:00
|
|
|
QMenu *m_menu;
|
2022-05-20 11:11:45 +08:00
|
|
|
QSharedPointer<DockPopupWindow> m_tipPopupWindow;
|
|
|
|
QTimer *m_tipsTimer;
|
|
|
|
QString m_lastDateString;
|
|
|
|
QString m_lastTimeString;
|
|
|
|
int m_currentSize;
|
|
|
|
bool m_oneRow;
|
2022-10-19 03:50:12 +00:00
|
|
|
bool m_showMultiRow;
|
2023-04-04 13:58:07 +08:00
|
|
|
int m_shortDateFormat;
|
|
|
|
bool m_use24HourFormat;
|
2023-10-17 13:48:10 +08:00
|
|
|
DTK_CORE_NAMESPACE::DConfig *m_config;
|
|
|
|
QString m_shortDateFormatStr;
|
|
|
|
QString m_shortTimeFormatStr;
|
|
|
|
QLocale m_locale;
|
2022-05-12 17:09:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DATETIMEDISPLAYER_H
|