dde-dock/frame/window/components/datetimedisplayer.h
tsic404 f0108d1c41 fix: timedate size issue
when the sum of the pixel dimensions of the time font and the date font is the same as the height,
leave some space so the text doesn't look too crowded.

log: adjust timedate size
2023-05-11 14:03:29 +08:00

94 lines
2.4 KiB
C++

// 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
#ifndef DATETIMEDISPLAYER_H
#define DATETIMEDISPLAYER_H
#include "constants.h"
#include "org_deepin_dde_timedate1.h"
#include <QWidget>
#include <QFont>
namespace Dock { class TipsWidget; }
class DockPopupWindow;
class QMenu;
using Timedate = org::deepin::dde::Timedate1;
class DateTimeDisplayer : public QWidget
{
Q_OBJECT
private:
struct DateTimeInfo {
QString m_time;
QString m_date;
QRect m_timeRect;
QRect m_dateRect;
};
public:
explicit DateTimeDisplayer(bool showMultiRow, QWidget *parent = nullptr);
~DateTimeDisplayer() override;
void setPositon(Dock::Position position);
void setOneRow(bool oneRow);
QSize suitableSize() const;
QSize suitableSize(const Dock::Position &position) const;
Q_SIGNALS:
void requestUpdate(); // 当日期时间格式发生变化的时候,需要通知外面来更新窗口尺寸
void requestDrawBackground(const QRect &rect);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void paintEvent(QPaintEvent *e) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
bool event(QEvent *event) override;
private:
void updatePolicy();
DateTimeInfo dateTimeInfo(const Dock::Position &position) const;
void updateLastData(const DateTimeInfo &info);
QString getTimeString() const;
QString getTimeString(const Dock::Position &position) const;
QString getDateString() const;
QString getDateString(const Dock::Position &position) const;
QPoint tipsPoint() const;
QFont timeFont() const;
void createMenuItem();
QRect textRect(const QRect &sourceRect) const;
private Q_SLOTS:
void onTimeChanged();
void onDateTimeFormatChanged();
private:
Timedate *m_timedateInter;
Dock::Position m_position;
mutable QFont m_dateFont;
mutable QFont m_timeFont;
Dock::TipsWidget *m_tipsWidget;
QMenu *m_menu;
QSharedPointer<DockPopupWindow> m_tipPopupWindow;
QTimer *m_tipsTimer;
QString m_lastDateString;
QString m_lastTimeString;
int m_currentSize;
bool m_oneRow;
bool m_showMultiRow;
int m_shortDateFormat;
bool m_use24HourFormat;
};
#endif // DATETIMEDISPLAYER_H