| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include "calendarnav.h"
- #include "PaintHelper/painthelper.h"
- #include "ui_calendarnav.h"
- #include <QDebug>
- #include <QFile>
- #include "spdlog/spdlog.h"
- //#pragma execution_character_set("utf-8")
- CalendarNav::CalendarNav(QCalendarWidget *pCalendar, QWidget *parent)
- : QWidget(parent)
- , ui(new Ui::CalendarNav)
- , m_pCalendar(pCalendar)
- {
- ui->setupUi(this);
- /* 加载qss */
- // QFile file = QString(":/Calendar/qss/CalendarNav_light.qss");
- // if(!file.open(QIODevice::ReadOnly))
- // {
- // qDebug() << "CalendarNav.cpp:QSS打开失败";
- // }
- // QString ss = file.readAll();
- // this->setStyleSheet(ss);
- connect(ui->btnPrevYear, &QPushButton::clicked, m_pCalendar, &QCalendarWidget::showPreviousYear);
- connect(ui->btnPrevMonth, &QPushButton::clicked, m_pCalendar, &QCalendarWidget::showPreviousMonth);
- connect(ui->btnNextMonth, &QPushButton::clicked, m_pCalendar, &QCalendarWidget::showNextMonth);
- connect(ui->btnNextYear, &QPushButton::clicked, m_pCalendar, &QCalendarWidget::showNextYear);
-
- connect(m_pCalendar, &QCalendarWidget::currentPageChanged, this, &CalendarNav::SetYearMonth);
-
- //默认显示当天, QCalendarWidget的默认选中日期也是当天
- SetYearMonth(QDate::currentDate().year(), QDate::currentDate().month());
- // LHStyleManager::Instance()->AddWidget(this);
- setQSS();
- }
- CalendarNav::~CalendarNav()
- {
- delete ui;
- }
- void CalendarNav::hidePreYear(bool flag)
- {
- ui->btnPrevYear->setVisible(!flag);
- }
- void CalendarNav::hidePreMonth(bool flag)
- {
- ui->btnPrevMonth->setVisible(!flag);
- }
- void CalendarNav::hideNextYear(bool flag)
- {
- ui->btnNextYear->setVisible(!flag);
- }
- void CalendarNav::hideNextMonth(bool flag)
- {
- ui->btnNextMonth->setVisible(!flag);
- }
- /* 设置QSS */
- void CalendarNav::setQSS(int style)
- {
- QString qssFile;
- if(style == 0)
- {
- qssFile = ":/qss/CalendarNav_light.qss";
- }else if(style == 1)
- {
- qssFile = ":/qss/CalendarNav_dark.qss";
- }
- QFile file(qssFile);
- if(file.open(QIODevice::ReadOnly))
- {
- QString stylesheet = file.readAll();
- this->setStyleSheet(stylesheet);
- file.close();
- } else
- {
- SPDLOG_WARN("打开QSS文件失败: {}", qssFile.toStdString());
- }
- }
- void CalendarNav::SetYearMonth(int year, int month)
- {
- ui->labelYearMonth->setText(QString("%1 年 %2 月").arg(year).arg(month));
- }
|