Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions plugins/dde-dock/datetime/calendar/pagebutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-FileCopyrightText: 2019 - 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "pagebutton.h"

#include <QMouseEvent>

Check warning on line 6 in plugins/dde-dock/datetime/calendar/pagebutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPainter>

Check warning on line 7 in plugins/dde-dock/datetime/calendar/pagebutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPainter> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QHBoxLayout>

Check warning on line 8 in plugins/dde-dock/datetime/calendar/pagebutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QHBoxLayout> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DPaletteHelper>

Check warning on line 10 in plugins/dde-dock/datetime/calendar/pagebutton.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DPaletteHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.

DGUI_USE_NAMESPACE
DWIDGET_USE_NAMESPACE

PageButton::PageButton(QWidget *parent)
: QFrame(parent)
, m_hover(false)
, m_mousePress(false)
, m_iconButton(new CommonIconButton(this))
{
initUI();
}

PageButton::~PageButton()
{
}

void PageButton::initUI()
{
setFixedSize(30, 30);
setForegroundRole(QPalette::BrightText);
m_iconButton->setFixedSize(12, 12);
m_iconButton->setForegroundRole(QPalette::BrightText);

// 居中放置图标
QHBoxLayout* hLayout = new QHBoxLayout(this);
hLayout->addWidget(m_iconButton, 0, Qt::AlignCenter);
}

void PageButton::setIcon(const QIcon &icon)
{
m_iconButton->setIcon(icon, Qt::black, Qt::white);
}

bool PageButton::event(QEvent* e)
{
switch (e->type()) {
case QEvent::Leave:
case QEvent::Enter:
m_hover = e->type() == QEvent::Enter;
update();
break;
default:
break;
}
return QWidget::event(e);
}

void PageButton::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e)
QPainter p(this);
QPalette palette = this->palette();
QColor bgColor, textColor;
if (m_mousePress) {
textColor = palette.highlight().color();
bgColor = palette.windowText().color();
bgColor.setAlphaF(0.15);
} else if(m_hover) {
textColor = palette.windowText().color();
bgColor = palette.windowText().color();
bgColor.setAlphaF(0.1);
} else {
textColor = palette.windowText().color();
bgColor = DPaletteHelper::instance()->palette(this).color(DPalette::ItemBackground);
bgColor.setAlphaF(0);
}
palette.setBrush(QPalette::BrightText, textColor);
m_iconButton->setPalette(palette);

p.setBrush(bgColor);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect(), 8, 8);
return QFrame::paintEvent(e);
}

void PageButton::mousePressEvent(QMouseEvent *event)
{
if(m_mousePress != true) {
m_mousePress = true;
update();
}
QWidget::mousePressEvent(event);
Comment thread
wjyrich marked this conversation as resolved.
}

void PageButton::mouseReleaseEvent(QMouseEvent* event)
{
if(m_mousePress == true) {
m_mousePress = false;
update();
}

if (underMouse() && this->rect().contains(event->pos())) {
Q_EMIT clicked();
}

QWidget::mouseReleaseEvent(event);
Comment thread
wjyrich marked this conversation as resolved.
}
38 changes: 38 additions & 0 deletions plugins/dde-dock/datetime/calendar/pagebutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-FileCopyrightText: 2019 - 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef PAGEBUTTON_H
#define PAGEBUTTON_H

#include "commoniconbutton.h"

Check warning on line 7 in plugins/dde-dock/datetime/calendar/pagebutton.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commoniconbutton.h" not found.

#include <QFrame>

Check warning on line 9 in plugins/dde-dock/datetime/calendar/pagebutton.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFrame> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class PageButton : public QFrame
{
Q_OBJECT
public:
explicit PageButton(QWidget *parent = nullptr);
~PageButton();

void setIcon(const QIcon &icon);

signals:
void clicked();

protected:
bool event(QEvent* e) override;
void paintEvent(QPaintEvent* e) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;

private:
void initUI();

private:
bool m_hover;
bool m_mousePress;
CommonIconButton *m_iconButton;
};

#endif // PAGEBUTTON_H
13 changes: 5 additions & 8 deletions plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include "constants.h"
#include "units.h"
#include "jumpcalendarbutton.h"
#include "pagebutton.h"
#include "regionFormat.h"

Check warning on line 10 in plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "regionFormat.h" not found.

#include <DPaletteHelper>

Check warning on line 12 in plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DPaletteHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>
#include <DFontSizeManager>
#include <DRegionMonitor>
Expand All @@ -27,8 +28,8 @@
, m_keyWidget(new QWidget(this))
, m_keyLayout(new QGridLayout)
, m_dateLabel(new QLabel(this))
, m_nextPage(new DToolButton(this))
, m_previousPage(new DToolButton(this))
, m_nextPage(new PageButton(this))
, m_previousPage(new PageButton(this))
, m_firstday(Qt::Sunday)
, m_dateTitleWidget(new DateTitleWidget(this))
, m_weekLabel(new DLabel(this))
Expand Down Expand Up @@ -85,10 +86,6 @@
DFontSizeManager::instance()->bind(m_dateLabel, DFontSizeManager::T5, 65);
m_nextPage->setIcon(DStyle().standardIcon(QStyle::SP_ArrowRight));
m_previousPage->setIcon(DStyle().standardIcon(QStyle::SP_ArrowLeft));
m_nextPage->setIconSize(QSize(12, 12));
m_previousPage->setIconSize(QSize(12, 12));
m_nextPage->setFixedSize(30, 30);
m_previousPage->setFixedSize(30, 30);

m_nextPage->setFocusPolicy(Qt::NoFocus);
m_previousPage->setFocusPolicy(Qt::NoFocus);
Expand Down Expand Up @@ -154,8 +151,8 @@
*/
void SidebarCalendarWidget::initConnection()
{
connect(m_nextPage, &QPushButton::clicked, this, &SidebarCalendarWidget::onNextPageClicked);
connect(m_previousPage, &QPushButton::clicked, this, &SidebarCalendarWidget::onPreviousPageClicked);
connect(m_nextPage, &PageButton::clicked, this, &SidebarCalendarWidget::onNextPageClicked);
connect(m_previousPage, &PageButton::clicked, this, &SidebarCalendarWidget::onPreviousPageClicked);
connect(m_manager, &CalendarManager::sidebarFirstDayChanged, this, &SidebarCalendarWidget::onFirstDayChanged);
// connect(m_manager, &CalendarManager::dateFormatChanged, this, &SidebarCalendarWidget::onDateFormatChanged);
connect(m_regionFormat, &RegionFormat::shortDateFormatChanged, this, &SidebarCalendarWidget::onShortDateFormatChanged);
Expand Down
5 changes: 3 additions & 2 deletions plugins/dde-dock/datetime/calendar/sidebarcalendarwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CalendarManager;
class SidebarCalendarKeyButton;
class JumpCalendarButton;
class RegionFormat;
class PageButton;
//小日历类
class SidebarCalendarWidget : public QWidget
{
Expand Down Expand Up @@ -99,8 +100,8 @@ private slots:
QWidget* m_keyWidget; //日期按钮区域控件
QGridLayout* m_keyLayout; //按钮布局
QLabel* m_dateLabel; //头部日期显示label
DToolButton* m_nextPage; //下一页切换按键
DToolButton* m_previousPage; //上一页切换按键
PageButton* m_nextPage; //下一页切换按键
PageButton* m_previousPage; //上一页切换按键
QList<SidebarCalendarKeyButton*> m_keyButtonList; //所有的日期按钮控件
int m_firstday;
DateTitleWidget *m_dateTitleWidget;
Expand Down