#ifndef CALENDARTABLE_H_
#define CALENDARTABLE_H_
#include <QDate>
#include <QEvent>
#include <QLabel>
#include <QPushButton>
#include <QSignalMapper>
#include <QStackedLayout>
#include <QStackedWidget>
#include <QStyledItemDelegate>
#include <QTableWidget>
#include <QTimer>
class DrawBaseDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
DrawBaseDelegate(QObject* parent);
protected:
void drawBackgroud(QPainter* painter, const QRect& rect, const QColor& color) const;
void drawBorder(QPainter* painter, const QRect& rect, const QColor& color) const;
void drawText(QPainter* painter, const QRect& rect, const QColor& color, const QString& text,
const Qt::AlignmentFlag align = Qt::AlignCenter) const;
void drawPoint(QPainter* painter, const QRect& rect, const QColor& color) const;
};
class CalendarDelegate : public DrawBaseDelegate
{
Q_OBJECT
public:
CalendarDelegate(QAbstractItemView* parent);
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
bool eventFilter(QObject* obj, QEvent* ev) override;
private:
bool colorByRole(const QModelIndex& model_index, int role, double alpha, QColor& tmp_color) const;
private:
QAbstractItemView* parent_view_;
QModelIndex hover_index_;
};
class CalendarTable : public QTableWidget
{
Q_OBJECT
public:
CalendarTable(QWidget* parent, int year = QDate::currentDate().year(), int month = QDate::currentDate().month());
enum CalendarRoleType
{
kDate = Qt::UserRole,
kBgColor,
kBorderColor,
kHoverBorderColor,
kFontColor,
kPointColor,
kAlpha, // 整体不透明度
};
enum CalendarSelectionMode
{
kNoSelection,
kSingleSelection,
kMultiSelection,
kRangeSelection
};
public:
bool setYearMonth(int year, int month);
void setFristDayOnWeek(int first_day_on_week);
void setSelMode(CalendarSelectionMode select_mode);
void setSpecialDate(const QList<QDate>& dates);
void addSelectedDate(const QDate& date);
void deleteSelectedDate(const QDate& date);
void clearSelectedDate();
void setMaxDate(const QDate& date);
void setMinDate(const QDate& date);
void setDateRange(const QDate& start_date, const QDate& end_date);
int year() { return year_; }
int month() { return month_; }
int first_day_on_week() { return first_day_on_week_; }
CalendarSelectionMode select_mode() { return select_mode_; }
QList<QDate> selected_date() { return selected_dates_; }
QDate max_date() { return max_date_; }
QDate min_date() { return min_date_; }
signals:
void refresh(int year, int month);
void selectionChanged();
void selectionAdded(const QDate& date);
void selectionDeleted(const QDate& date);
void maxDateChanged(const QDate& date);
void minDateChanged(const QDate& date);
void dateDoubleClicked(const QDate& date);
protected:
bool eventFilter(QObject* obj, QEvent* ev) override;
private slots:
void itemClicked(QTableWidgetItem* item);
void itemDoubleClicked(QTableWidgetItem* item);
void clicked();
private:
void refreshCalendar();
void refreshCalendarHeader();
void refreshSelection();
void refreshSpecialDate();
void refreshTodayDate();
void startRefreshTimer();
bool appendSelection(const QDate& date);
bool removeSelection(const QDate& date);
private:
int year_;
int month_;
int first_day_on_week_;
QDate max_date_;
QDate min_date_;
QDate cliked_date_;
bool is_double_clicked_;
QTimer* date_timer_;
QList<QDate> selected_dates_;
QList<QDate> special_dates_;
CalendarSelectionMode select_mode_;
};
class CalendarButtonGruop : public QWidget
{
Q_OBJECT
public:
explicit CalendarButtonGruop(QWidget* parent = nullptr)
: QWidget(parent){};
void setSelection(int id);
protected:
QList<QPushButton*> button_group_;
QSignalMapper* signal_mapper_;
};
class YearButtonGroup : public CalendarButtonGruop
{
Q_OBJECT
public:
explicit YearButtonGroup(int year, QWidget* parent = nullptr);
void toPreYearPage(int current_year);
void toNextYearPage(int current_year);
signals:
void yearClicked(int year);
private:
void refreshYearPage(int show_year, int current_year);
};
class MonthButtonGroup : public CalendarButtonGruop
{
Q_OBJECT
public:
explicit MonthButtonGroup(QWidget* parent = nullptr);
signals:
void monthClicked(int month);
};
#endif // CALENDARTABLE_H_
孙春泉
- 粉丝: 14
- 资源: 11
最新资源
- 基于C++ / QT的模拟进程管理系统的设计与实现课程设计
- 大模型部署-基于TensorRT-LLM部署Qwen1.5大语言模型-附项目源码+流程教程-优质项目实战.zip
- 大模型部署-基于Rust+CUDA加速部署LLaMA-7b-附项目源码+流程教程-优质项目实战.zip
- 车牌识别-基于YOLOv8实现车牌检测+车牌识别算法-附项目源码+详细流程教程-优质项目实战.zip
- 车牌识别-基于Pytorch实现的MTCNN+LPRNet两阶段轻量级高性能车牌识别算法-附项目源码-优质项目实战.zip
- C#中委托与事件详解及其面向对象编程应用
- 【STM32开发之寄存器版】(十一-附)-DMA和串口空闲中断实现不定长数据接收
- Python面向对象编程详解及其实战应用
- 基于python特征脸方法以及局部二值模式方法初步实现了人脸识别的功能课程设计
- C#编程基础及其高级特性详解
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈