瀏覽代碼

V1.6.3
1、重新修改了日期选择器

Apple 7 小時之前
父節點
當前提交
25ea92bea0
共有 42 個文件被更改,包括 2056 次插入1923 次删除
  1. 0 24
      common/DateSelect/rescalendar.qrc
  2. 19 19
      common/SelectDate/CMakeLists.txt
  3. 162 88
      common/SelectDate/calendardtedit.cpp
  4. 46 35
      common/SelectDate/calendardtedit.h
  5. 187 187
      common/SelectDate/calendarex.cpp
  6. 66 66
      common/SelectDate/calendarex.h
  7. 67 67
      common/SelectDate/calendarheader.cpp
  8. 32 32
      common/SelectDate/calendarheader.h
  9. 139 139
      common/SelectDate/calendarheader.ui
  10. 92 94
      common/SelectDate/calendarnav.cpp
  11. 33 33
      common/SelectDate/calendarnav.h
  12. 140 140
      common/SelectDate/calendarnav.ui
  13. 408 408
      common/SelectDate/calendarwidgetex.cpp
  14. 117 117
      common/SelectDate/calendarwidgetex.h
  15. 134 131
      common/SelectDate/cdate.cpp
  16. 63 63
      common/SelectDate/cdate.h
  17. 0 0
      common/SelectDate/icon/dark/nextMonth.png
  18. 0 0
      common/SelectDate/icon/dark/nextMonth_hover.png
  19. 0 0
      common/SelectDate/icon/dark/nextYear.png
  20. 0 0
      common/SelectDate/icon/dark/nextYear_hover.png
  21. 0 0
      common/SelectDate/icon/dark/preMonth.png
  22. 0 0
      common/SelectDate/icon/dark/preMonth_hover.png
  23. 0 0
      common/SelectDate/icon/dark/preYear.png
  24. 0 0
      common/SelectDate/icon/dark/preYear_hover.png
  25. 0 0
      common/SelectDate/icon/light/nextMonth.png
  26. 0 0
      common/SelectDate/icon/light/nextMonth_hover.png
  27. 0 0
      common/SelectDate/icon/light/nextYear.png
  28. 0 0
      common/SelectDate/icon/light/nextYear_hover.png
  29. 0 0
      common/SelectDate/icon/light/preMonth.png
  30. 0 0
      common/SelectDate/icon/light/preMonth_hover.png
  31. 0 0
      common/SelectDate/icon/light/preYear.png
  32. 0 0
      common/SelectDate/icon/light/preYear_hover.png
  33. 64 64
      common/SelectDate/qss/CalendarNav_dark.qss
  34. 50 50
      common/SelectDate/qss/CalendarNav_light.qss
  35. 43 0
      common/SelectDate/qss/calendardtedit_light.qss
  36. 5 5
      common/SelectDate/qss/calendarheader_dark.qss
  37. 5 5
      common/SelectDate/qss/calendarheader_light.qss
  38. 28 0
      common/SelectDate/rescalendar.qrc
  39. 63 63
      common/SelectDate/scopecalendarbtn.cpp
  40. 33 33
      common/SelectDate/scopecalendarbtn.h
  41. 34 34
      common/SelectDate/scopeselectionmodel.cpp
  42. 26 26
      common/SelectDate/scopeselectionmodel.h

+ 0 - 24
common/DateSelect/rescalendar.qrc

@@ -1,24 +0,0 @@
-<RCC>
-    <qresource prefix="/Calendar">
-        <file>icon/light/nextMonth.png</file>
-        <file>icon/light/nextMonth_hover.png</file>
-        <file>icon/light/nextYear.png</file>
-        <file>icon/light/nextYear_hover.png</file>
-        <file>icon/light/preMonth.png</file>
-        <file>icon/light/preMonth_hover.png</file>
-        <file>icon/light/preYear.png</file>
-        <file>icon/light/preYear_hover.png</file>
-        <file>icon/dark/nextMonth.png</file>
-        <file>icon/dark/nextMonth_hover.png</file>
-        <file>icon/dark/nextYear.png</file>
-        <file>icon/dark/nextYear_hover.png</file>
-        <file>icon/dark/preMonth.png</file>
-        <file>icon/dark/preMonth_hover.png</file>
-        <file>icon/dark/preYear.png</file>
-        <file>icon/dark/preYear_hover.png</file>
-        <file>qss/CalendarNav_light.qss</file>
-        <file>qss/CalendarNav_dark.qss</file>
-        <file>qss/calendarheader_light.qss</file>
-        <file>qss/calendarheader_dark.qss</file>
-    </qresource>
-</RCC>

+ 19 - 19
common/DateSelect/CMakeLists.txt → common/SelectDate/CMakeLists.txt

@@ -1,19 +1,19 @@
-cmake_minimum_required(VERSION 3.10)
-project(CDate)
-
-set(LIB_NAME CDate)
-
-include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake)
-
-file(GLOB SRC ${COMMON_SRC}
-            ${CMAKE_CURRENT_SOURCE_DIR}/*.qss
-            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.qrc
-            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.cpp
-            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.ui
-        )
-
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/date
-                    ${COMMON_INC})
-set(LIBRARY_OUTPUT_PATH ${LIB_PATH})
-#add_library(${LIB_NAME} SHARED ${SRC})
-#target_link_libraries(${LIB_NAME} PRIVATE Qt5::Widgets)
+cmake_minimum_required(VERSION 3.10)
+project(CDate)
+
+set(LIB_NAME CDate)
+
+include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake)
+
+file(GLOB SRC ${COMMON_SRC}
+            ${CMAKE_CURRENT_SOURCE_DIR}/*.qss
+            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.qrc
+            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.cpp
+            ${CMAKE_CURRENT_SOURCE_DIR}/date/*.ui
+        )
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/date
+                    ${COMMON_INC})
+set(LIBRARY_OUTPUT_PATH ${LIB_PATH})
+#add_library(${LIB_NAME} SHARED ${SRC})
+#target_link_libraries(${LIB_NAME} PRIVATE Qt5::Widgets)

+ 162 - 88
common/DateSelect/calendardtedit.cpp → common/SelectDate/calendardtedit.cpp

@@ -1,89 +1,163 @@
-#include "calendardtedit.h"
-#include <QDebug>
-#include <QApplication>
-#include <QDesktopWidget>
-#include <QKeyEvent>
-#include <QEvent>
-
-#include "calendarex.h"
-
-CalendarDTEdit::CalendarDTEdit(QWidget *parent) : QDateTimeEdit(parent)
-{
-    setCalendarPopup(false);// 阻止自带的日历窗口
-}
-
-CalendarDTEdit::~CalendarDTEdit()
-{
-}
-
-void CalendarDTEdit::CloseCalendar()
-{
-
-}
-
-/* 手动触发日期选择弹框 */
-void CalendarDTEdit::triggerCalendarPopup()
-{
-
-}
-
-/**
- * @brief 设置手动禁止修改日期区域,只能使用弹窗
- * 
- * @param value 是否禁止修改日期区域
- * @param triggerPopup 点击日期区域是否会跳出弹窗
- */
-void CalendarDTEdit::setManualDisableEdit(bool value, bool triggerPopup)
-{
-    if(value)
-    {
-        setReadOnly(true);
-        for(auto& it : children())
-        {
-            if(it->objectName() == "qt_spinbox_lineedit")
-            {
-                m_pCalendar = it;
-                m_pCalendar->installEventFilter(this);
-            }
-        }
-    }else {
-        setReadOnly(false);
-        if(m_pCalendar != nullptr)
-        {
-            m_pCalendar->removeEventFilter(this);
-            m_pCalendar = nullptr;
-        }
-    }
-    m_isPopup = triggerPopup;
-}
-
-void CalendarDTEdit::mousePressEvent(QMouseEvent *e)
-{
-    Q_UNUSED(e);
-    CalendarEx *pC = new CalendarEx(date());
-    if (nullptr == pC) return;
-    connect(pC, &CalendarEx::sig_DateChanged, this, [this](const QDate& date){
-        if (date.isValid()) {
-            setDate(date);
-        }
-    });
-    pC->show();
-    pC->positionCalendarPopup(this);
-}
-
-
-bool CalendarDTEdit::eventFilter(QObject* watched, QEvent* event)
-{
-    if(watched == m_pCalendar)
-    {
-        if(event->type() == QEvent::MouseButtonPress)
-        {
-            // qDebug() << "点击了日期区域";
-            if(m_isPopup)
-            {
-                mousePressEvent(nullptr);
-            }
-        }
-    }
-    return QDateTimeEdit::eventFilter(watched, event);
+#include "calendardtedit.h"
+#include <QDebug>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QKeyEvent>
+#include <QEvent>
+
+#include "calendarex.h"
+#include "UIStyleManager.h"
+#include "spdlog/spdlog.h"
+
+
+CalendarDTEdit::CalendarDTEdit(QWidget *parent) : QDateTimeEdit(parent)
+{
+    setCalendarPopup(false);// 阻止自带的日历窗口
+
+    setQSS();
+}
+
+CalendarDTEdit::~CalendarDTEdit()
+{
+}
+
+void CalendarDTEdit::CloseCalendar()
+{
+
+}
+
+/* 手动触发日期选择弹框 */
+void CalendarDTEdit::triggerCalendarPopup()
+{
+
+}
+
+/**
+ * @brief 设置手动禁止修改日期区域,只能使用弹窗
+ * 
+ * @param value 是否禁止修改日期区域
+ * @param triggerPopup 点击日期区域是否会跳出弹窗
+ */
+void CalendarDTEdit::setManualDisableEdit(bool value, bool triggerPopup)
+{
+    if(value)
+    {
+        setReadOnly(true);
+        for(auto& it : children())
+        {
+            if(it->objectName() == "qt_spinbox_lineedit")
+            {
+                m_pCalendar = it;
+                m_pCalendar->installEventFilter(this);
+            }
+        }
+    }else {
+        setReadOnly(false);
+        if(m_pCalendar != nullptr)
+        {
+            m_pCalendar->removeEventFilter(this);
+            m_pCalendar = nullptr;
+        }
+    }
+    m_isPopup = triggerPopup;
+}
+
+/* 设置禁用日期选择器 */
+void CalendarDTEdit::setCalendarEnabled(bool value)
+{
+    setEnabled(value);
+    m_isEnableCalendar = value;
+    
+    /* 先清空样式表 */
+    this->setProperty("disabled", !value);
+    /* 重新生效QSS */
+    this->style()->unpolish(this);
+    this->style()->polish(this);
+}
+
+/* 鼠标进入离开事件 */
+void CalendarDTEdit::enterEvent(QEvent* event)
+{
+    if(isEnabled() == false)
+    {
+        return;
+    }
+
+    this->setProperty("hover", true);
+
+    this->style()->unpolish(this);
+    this->style()->polish(this);
+    QDateTimeEdit::enterEvent(event); // 保持父类行为
+}
+
+/* 鼠标离开事件 */
+void CalendarDTEdit::leaveEvent(QEvent* event)
+{
+    if(isEnabled() == false)
+    {
+        return;
+    }
+
+    this->setProperty("hover", false);
+
+    this->style()->unpolish(this);
+    this->style()->polish(this);
+    QDateTimeEdit::leaveEvent(event); // 保持父类行为
+}
+
+void CalendarDTEdit::mousePressEvent(QMouseEvent *e)
+{
+    Q_UNUSED(e);
+    if(m_isEnableCalendar == false)
+    {
+        return;
+    }
+    CalendarEx *pC = new CalendarEx(date());
+    if (nullptr == pC) return;
+    connect(pC, &CalendarEx::sig_DateChanged, this, [this](const QDate& date){
+        if (date.isValid()) {
+            setDate(date);
+        }
+    });
+    pC->show();
+    pC->positionCalendarPopup(this);
+}
+
+/* 设置QSS */
+void CalendarDTEdit::setQSS()
+{
+    QString qssPath;
+    if(UIStyle.getUIStyle() == EUIStyle::UI_Light)
+    {
+        qssPath = QString(":/qss/calendardtedit_light.qss");
+    }else {
+        qssPath = QString(":/qss/calendardtedit_dark.qss");
+    }
+    QFile file(qssPath);
+    if(file.open(QFile::ReadOnly))
+    {
+        QString qss = file.readAll();
+        this->setStyleSheet(qss);
+        file.close();
+    } else
+    {
+        SPDLOG_WARN(nullptr, "打开QSS文件失败: {}", qssPath.toStdString());
+    }
+}
+
+
+bool CalendarDTEdit::eventFilter(QObject* watched, QEvent* event)
+{
+    if(watched == m_pCalendar)
+    {
+        if(event->type() == QEvent::MouseButtonPress)
+        {
+            // qDebug() << "点击了日期区域";
+            if(m_isPopup)
+            {
+                mousePressEvent(nullptr);
+            }
+        }
+    }
+    return QDateTimeEdit::eventFilter(watched, event);
 }

+ 46 - 35
common/DateSelect/calendardtedit.h → common/SelectDate/calendardtedit.h

@@ -1,35 +1,46 @@
-#ifndef CALENDARDTEDIT_H
-#define CALENDARDTEDIT_H
-
-#include <QWidget>
-#include <QDateTimeEdit>
-
-
-/* 需要设置这个属性,qss设置的图标才会生效
- * setCalendarPopup(true);
- */
-
-class CalendarDTEdit : public QDateTimeEdit
-{
-    Q_OBJECT
-public:
-    explicit CalendarDTEdit(QWidget *parent = nullptr);
-    virtual ~CalendarDTEdit();
-    void SetCalendarAutoClose(bool value);
-    void CloseCalendar();
-    /* 手动触发日期选择弹框 */
-    void triggerCalendarPopup();
-    /* 设置手动禁止修改日期区域,只能使用弹窗,第二个参数设置点击日期是否会出现日期选择弹框 */
-    void setManualDisableEdit(bool value, bool triggerPopup = false);
-signals:
-    void sig_SetCurrentPage(int year, int month);
-protected:
-    void mousePressEvent(QMouseEvent* e) override;
-    bool eventFilter(QObject* watched, QEvent* event) override;
-
-private:
-    QObject* m_pCalendar = nullptr;
-    bool m_isPopup = false;
-};
-
-#endif // CALENDARDTEDIT_H
+#ifndef CALENDARDTEDIT_H
+#define CALENDARDTEDIT_H
+
+#include <QWidget>
+#include <QDateTimeEdit>
+
+
+/* 需要设置这个属性,qss设置的图标才会生效
+ * setCalendarPopup(true);
+ */
+
+class CalendarDTEdit : public QDateTimeEdit
+{
+    Q_OBJECT
+public:
+    explicit CalendarDTEdit(QWidget *parent = nullptr);
+    virtual ~CalendarDTEdit();
+    void SetCalendarAutoClose(bool value);
+    void CloseCalendar();
+    /* 手动触发日期选择弹框 */
+    void triggerCalendarPopup();
+    /* 设置手动禁止修改日期区域,只能使用弹窗,第二个参数设置点击日期是否会出现日期选择弹框 */
+    void setManualDisableEdit(bool value, bool triggerPopup = false);
+    /* 设置禁用日期选择器 */
+    void setCalendarEnabled(bool value);
+
+    /* 设置QSS */
+    void setQSS();
+signals:
+    void sig_SetCurrentPage(int year, int month);
+protected:
+    /* 这里使用事件来处理hover样式,样式表的hover不生效,只能手动处理了 */
+    /* 鼠标进入离开事件 */
+    void enterEvent(QEvent* event) override;
+    /* 鼠标离开事件 */
+    void leaveEvent(QEvent* event) override;
+    void mousePressEvent(QMouseEvent* e) override;
+    bool eventFilter(QObject* watched, QEvent* event) override;
+
+private:
+    QObject* m_pCalendar = nullptr;
+    bool m_isPopup = false;
+    bool m_isEnableCalendar = true;
+};
+
+#endif // CALENDARDTEDIT_H

+ 187 - 187
common/DateSelect/calendarex.cpp → common/SelectDate/calendarex.cpp

@@ -1,187 +1,187 @@
-#include "calendarex.h"
-#include <QEvent>
-#include <QScreen>
-#include <QKeyEvent>
-#include <QApplication>
-#include <QDesktopWidget>
-#include <QHBoxLayout>
-#include <QDebug>
-#include "scopeselectionmodel.h"
-#include "PaintHelper/painthelper.h"
-
-CalendarInterface::CalendarInterface(QWidget *parent)
-    : QWidget(parent)
-    , IDropShadowable(this)
-    , m_pLayout(new QHBoxLayout)
-{
-    setWindowFlag(Qt::Popup);
-    setWindowFlag(Qt::NoDropShadowWindowHint);
-    //设置无边框属性
-    setWindowFlag(Qt::FramelessWindowHint);
-    //设置背景透明属性
-    setAttribute(Qt::WA_TranslucentBackground, true);
-    //关闭对话框时,删除自身对象
-    setAttribute(Qt::WA_DeleteOnClose, true);
-}
-
-CalendarInterface::~CalendarInterface()
-{
-    //qDebug()<<"~ScopeCalendar";
-}
-
-/**
- * @brief 这个只是坐标位移?
- * @param q
- */
-void CalendarInterface::positionCalendarPopup(QWidget *q)
-{
-    if (nullptr == m_pLayout) return;
-    QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();
-    QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();
-    pos = q->mapToGlobal(pos);
-    pos2 = q->mapToGlobal(pos2);
-    QSize size = QSize(CALENDAR_WIDTH * m_pLayout->count() + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
-    //QRect screen = QApplication::desktop()->availableGeometry(pos);
-    QRect screen = QGuiApplication::screenAt(pos)->availableGeometry();
-    //handle popup falling "off screen"
-    if (q->layoutDirection() == Qt::RightToLeft) {
-        pos.setX(pos.x()-size.width());
-        pos2.setX(pos2.x()-size.width());
-        if (pos.x() < screen.left())
-            pos.setX(qMax(pos.x(), screen.left()));
-        else if (pos.x()+size.width() > screen.right())
-            pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width()));
-    } else {
-        if (pos.x()+size.width() > screen.right())
-            pos.setX(screen.right()-size.width());
-        pos.setX(qMax(pos.x(), screen.left()));
-    }
-    if (pos.y() + size.height() > screen.bottom())
-        pos.setY(pos2.y() - size.height());
-    else if (pos.y() < screen.top())
-        pos.setY(screen.top());
-    if (pos.y() < screen.top())
-        pos.setY(screen.top());
-    if (pos.y()+size.height() > screen.bottom())
-        pos.setY(screen.bottom()-size.height());
-    pos.setX(pos.rx() - SHADOW_RADIUS);
-    pos.setY(pos.ry() - SHADOW_RADIUS + SPACING);
-    move(pos);
-}
-
-CalendarEx::CalendarEx(const QDate& defaultDate, QWidget* parent) :
-    CalendarInterface(parent),
-    m_pCalendar(nullptr)
-{
-    QHBoxLayout* pLay = new QHBoxLayout(this);
-    QWidget* pMain = new QWidget(this);
-    pMain->setLayout(m_pLayout);
-
-    pLay->addWidget(pMain);
-    pLay->setMargin(SHADOW_RADIUS);
-
-    m_pCalendar = new CalendarWidgetEx(this);
-    m_pCalendar->setStyleSheet("QCalendarView{background-color: transparent;}");
-    m_pLayout->addWidget(m_pCalendar);
-    connect(m_pCalendar, &CalendarWidgetEx::clicked, this, [this](const QDate& date){
-        emit sig_DateChanged(date);
-        close();
-    });
-
-    m_pLayout->setMargin(0);
-    pMain->resize(CALENDAR_WIDTH, CALENDAR_HEIGHT);
-    SetCalendarSync(defaultDate);
-    /* 设置大小,包含阴影的大小 */
-    resize(CALENDAR_WIDTH + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
-    /* 设置阴影 */
-    SetDropShadow(BoxShadow{0, 0, SHADOW_RADIUS, 0, QColor(0, 0, 0, 60), QSize(0, 0), QImage()}, pMain->size());
-}
-
-void CalendarEx::SetCalendarSync(const QDate &defaultDate)
-{
-    if (nullptr == m_pCalendar || !defaultDate.isValid()) return;
-
-    m_pCalendar->setCurrentPage(defaultDate.year(), defaultDate.month());
-    m_pCalendar->setSelectedDate(defaultDate);
-}
-
-ScopedCalendar::ScopedCalendar(const QDate &from, const QDate &to, QWidget *parent) :
-    CalendarInterface(parent),
-    m_pCalendar_L(nullptr),
-    m_pCalendar_R(nullptr)
-{
-    QHBoxLayout* pLay = new QHBoxLayout(this);
-    QWidget* pMain = new QWidget(this);
-    pMain->setLayout(m_pLayout);
-
-    pLay->addWidget(pMain);
-    pLay->setMargin(SHADOW_RADIUS);
-
-    ScopeSelectionModel *pDateScopeModel = new ScopeSelectionModel();
-    if(from.isValid() && to.isValid())
-    {
-        pDateScopeModel->dtFirst = from;
-        pDateScopeModel->dtSecond = to;
-        pDateScopeModel->bLocked = true;
-    }
-    m_pCalendar_L = new CalendarWidgetEx(this);
-    m_pCalendar_L->setStyleSheet("QCalendarView{background-color: transparent;}");
-    m_pCalendar_L->SetSelectMode(CalendarWidgetEx::Scope, pDateScopeModel);
-    m_pCalendar_L->hideNavigatioinButton(false, false, true, true);
-    m_pLayout->addWidget(m_pCalendar_L);
-
-    m_pCalendar_R = new CalendarWidgetEx(this);
-    m_pCalendar_R->setStyleSheet("QCalendarView{background-color: transparent;}");
-    m_pCalendar_R->SetSelectMode(CalendarWidgetEx::Scope, pDateScopeModel);
-    m_pCalendar_R->hideNavigatioinButton(true, true, false, false);
-    m_pLayout->addWidget(m_pCalendar_R);
-
-    m_pLayout->setSpacing(0);
-    m_pLayout->setMargin(0);
-    pMain->resize(2 * CALENDAR_WIDTH, CALENDAR_HEIGHT);
-    SetCalendarSync(from);
-
-    connect(pDateScopeModel, &ScopeSelectionModel::sig_ScopeSelected, this, &ScopedCalendar::OnScopeSelected);
-
-    resize(2 * CALENDAR_WIDTH + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
-    SetDropShadow(BoxShadow{0, 0, SHADOW_RADIUS, 0, QColor(0, 0, 0, 60), QSize(0, 0), QImage()}, pMain->size());
-}
-
-void ScopedCalendar::SetMinimumDate(const QDate &date)
-{
-    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R) return;
-
-    m_pCalendar_L->setMinimumDate(date);
-    m_pCalendar_R->setMinimumDate(date);
-}
-
-void ScopedCalendar::SetMaximumDate(const QDate &date)
-{
-    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R) return;
-
-    m_pCalendar_L->setMaximumDate(date);
-    m_pCalendar_R->setMaximumDate(date);
-}
-
-void ScopedCalendar::OnScopeSelected(const QDate &from, const QDate &to)
-{
-    emit sig_ScopeSelected(from, to);
-    close();
-}
-
-void ScopedCalendar::SetCalendarSync(const QDate &defaultDate)
-{
-    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R || !defaultDate.isValid()) return;
-
-    m_pCalendar_L->setCurrentPage(defaultDate.year(), defaultDate.month());
-    connect(m_pCalendar_L, &QCalendarWidget::currentPageChanged, this, [&](int year, int month) {
-        QDate nextMonth = QDate(year, month, 1).addMonths(1);
-        m_pCalendar_R->setCurrentPage(nextMonth.year(), nextMonth.month());
-    });
-
-    m_pCalendar_R->setCurrentPage(defaultDate.addMonths(1).year(), defaultDate.addMonths(1).month());
-    connect(m_pCalendar_R, &QCalendarWidget::currentPageChanged, this, [&](int year, int month) {
-        QDate prevMonth = QDate(year, month, 1).addMonths(-1);
-        m_pCalendar_L->setCurrentPage(prevMonth.year(), prevMonth.month());
-    });
-}
+#include "calendarex.h"
+#include <QEvent>
+#include <QScreen>
+#include <QKeyEvent>
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QHBoxLayout>
+#include <QDebug>
+#include "scopeselectionmodel.h"
+#include "PaintHelper/painthelper.h"
+
+CalendarInterface::CalendarInterface(QWidget *parent)
+    : QWidget(parent)
+    , IDropShadowable(this)
+    , m_pLayout(new QHBoxLayout)
+{
+    setWindowFlag(Qt::Popup);
+    setWindowFlag(Qt::NoDropShadowWindowHint);
+    //设置无边框属性
+    setWindowFlag(Qt::FramelessWindowHint);
+    //设置背景透明属性
+    setAttribute(Qt::WA_TranslucentBackground, true);
+    //关闭对话框时,删除自身对象
+    setAttribute(Qt::WA_DeleteOnClose, true);
+}
+
+CalendarInterface::~CalendarInterface()
+{
+    //qDebug()<<"~ScopeCalendar";
+}
+
+/**
+ * @brief 这个只是坐标位移?
+ * @param q
+ */
+void CalendarInterface::positionCalendarPopup(QWidget *q)
+{
+    if (nullptr == m_pLayout) return;
+    QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();
+    QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();
+    pos = q->mapToGlobal(pos);
+    pos2 = q->mapToGlobal(pos2);
+    QSize size = QSize(CALENDAR_WIDTH * m_pLayout->count() + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
+    //QRect screen = QApplication::desktop()->availableGeometry(pos);
+    QRect screen = QGuiApplication::screenAt(pos)->availableGeometry();
+    //handle popup falling "off screen"
+    if (q->layoutDirection() == Qt::RightToLeft) {
+        pos.setX(pos.x()-size.width());
+        pos2.setX(pos2.x()-size.width());
+        if (pos.x() < screen.left())
+            pos.setX(qMax(pos.x(), screen.left()));
+        else if (pos.x()+size.width() > screen.right())
+            pos.setX(qMax(pos.x()-size.width(), screen.right()-size.width()));
+    } else {
+        if (pos.x()+size.width() > screen.right())
+            pos.setX(screen.right()-size.width());
+        pos.setX(qMax(pos.x(), screen.left()));
+    }
+    if (pos.y() + size.height() > screen.bottom())
+        pos.setY(pos2.y() - size.height());
+    else if (pos.y() < screen.top())
+        pos.setY(screen.top());
+    if (pos.y() < screen.top())
+        pos.setY(screen.top());
+    if (pos.y()+size.height() > screen.bottom())
+        pos.setY(screen.bottom()-size.height());
+    pos.setX(pos.rx() - SHADOW_RADIUS);
+    pos.setY(pos.ry() - SHADOW_RADIUS + SPACING);
+    move(pos);
+}
+
+CalendarEx::CalendarEx(const QDate& defaultDate, QWidget* parent) :
+    CalendarInterface(parent),
+    m_pCalendar(nullptr)
+{
+    QHBoxLayout* pLay = new QHBoxLayout(this);
+    QWidget* pMain = new QWidget(this);
+    pMain->setLayout(m_pLayout);
+
+    pLay->addWidget(pMain);
+    pLay->setMargin(SHADOW_RADIUS);
+
+    m_pCalendar = new CalendarWidgetEx(this);
+    m_pCalendar->setStyleSheet("QCalendarView{background-color: transparent;}");
+    m_pLayout->addWidget(m_pCalendar);
+    connect(m_pCalendar, &CalendarWidgetEx::clicked, this, [this](const QDate& date){
+        emit sig_DateChanged(date);
+        close();
+    });
+
+    m_pLayout->setMargin(0);
+    pMain->resize(CALENDAR_WIDTH, CALENDAR_HEIGHT);
+    SetCalendarSync(defaultDate);
+    /* 设置大小,包含阴影的大小 */
+    resize(CALENDAR_WIDTH + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
+    /* 设置阴影 */
+    SetDropShadow(BoxShadow{0, 0, SHADOW_RADIUS, 0, QColor(0, 0, 0, 60), QSize(0, 0), QImage()}, pMain->size());
+}
+
+void CalendarEx::SetCalendarSync(const QDate &defaultDate)
+{
+    if (nullptr == m_pCalendar || !defaultDate.isValid()) return;
+
+    m_pCalendar->setCurrentPage(defaultDate.year(), defaultDate.month());
+    m_pCalendar->setSelectedDate(defaultDate);
+}
+
+ScopedCalendar::ScopedCalendar(const QDate &from, const QDate &to, QWidget *parent) :
+    CalendarInterface(parent),
+    m_pCalendar_L(nullptr),
+    m_pCalendar_R(nullptr)
+{
+    QHBoxLayout* pLay = new QHBoxLayout(this);
+    QWidget* pMain = new QWidget(this);
+    pMain->setLayout(m_pLayout);
+
+    pLay->addWidget(pMain);
+    pLay->setMargin(SHADOW_RADIUS);
+
+    ScopeSelectionModel *pDateScopeModel = new ScopeSelectionModel();
+    if(from.isValid() && to.isValid())
+    {
+        pDateScopeModel->dtFirst = from;
+        pDateScopeModel->dtSecond = to;
+        pDateScopeModel->bLocked = true;
+    }
+    m_pCalendar_L = new CalendarWidgetEx(this);
+    m_pCalendar_L->setStyleSheet("QCalendarView{background-color: transparent;}");
+    m_pCalendar_L->SetSelectMode(CalendarWidgetEx::Scope, pDateScopeModel);
+    m_pCalendar_L->hideNavigatioinButton(false, false, true, true);
+    m_pLayout->addWidget(m_pCalendar_L);
+
+    m_pCalendar_R = new CalendarWidgetEx(this);
+    m_pCalendar_R->setStyleSheet("QCalendarView{background-color: transparent;}");
+    m_pCalendar_R->SetSelectMode(CalendarWidgetEx::Scope, pDateScopeModel);
+    m_pCalendar_R->hideNavigatioinButton(true, true, false, false);
+    m_pLayout->addWidget(m_pCalendar_R);
+
+    m_pLayout->setSpacing(0);
+    m_pLayout->setMargin(0);
+    pMain->resize(2 * CALENDAR_WIDTH, CALENDAR_HEIGHT);
+    SetCalendarSync(from);
+
+    connect(pDateScopeModel, &ScopeSelectionModel::sig_ScopeSelected, this, &ScopedCalendar::OnScopeSelected);
+
+    resize(2 * CALENDAR_WIDTH + 2 * SHADOW_RADIUS, CALENDAR_HEIGHT + 2 * SHADOW_RADIUS);
+    SetDropShadow(BoxShadow{0, 0, SHADOW_RADIUS, 0, QColor(0, 0, 0, 60), QSize(0, 0), QImage()}, pMain->size());
+}
+
+void ScopedCalendar::SetMinimumDate(const QDate &date)
+{
+    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R) return;
+
+    m_pCalendar_L->setMinimumDate(date);
+    m_pCalendar_R->setMinimumDate(date);
+}
+
+void ScopedCalendar::SetMaximumDate(const QDate &date)
+{
+    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R) return;
+
+    m_pCalendar_L->setMaximumDate(date);
+    m_pCalendar_R->setMaximumDate(date);
+}
+
+void ScopedCalendar::OnScopeSelected(const QDate &from, const QDate &to)
+{
+    emit sig_ScopeSelected(from, to);
+    close();
+}
+
+void ScopedCalendar::SetCalendarSync(const QDate &defaultDate)
+{
+    if (nullptr == m_pCalendar_L || nullptr == m_pCalendar_R || !defaultDate.isValid()) return;
+
+    m_pCalendar_L->setCurrentPage(defaultDate.year(), defaultDate.month());
+    connect(m_pCalendar_L, &QCalendarWidget::currentPageChanged, this, [&](int year, int month) {
+        QDate nextMonth = QDate(year, month, 1).addMonths(1);
+        m_pCalendar_R->setCurrentPage(nextMonth.year(), nextMonth.month());
+    });
+
+    m_pCalendar_R->setCurrentPage(defaultDate.addMonths(1).year(), defaultDate.addMonths(1).month());
+    connect(m_pCalendar_R, &QCalendarWidget::currentPageChanged, this, [&](int year, int month) {
+        QDate prevMonth = QDate(year, month, 1).addMonths(-1);
+        m_pCalendar_L->setCurrentPage(prevMonth.year(), prevMonth.month());
+    });
+}

+ 66 - 66
common/DateSelect/calendarex.h → common/SelectDate/calendarex.h

@@ -1,66 +1,66 @@
-#ifndef CALENDAREX_H
-#define CALENDAREX_H
-
-#include <QWidget>
-#include "calendarwidgetex.h"
-#include "DropShadow/idropshadowable.h"
-
-class QHBoxLayout;
-
-class CalendarInterface : public QWidget, public IDropShadowable
-{
-    Q_OBJECT
-public:
-    explicit CalendarInterface(QWidget *parent = nullptr);
-    virtual ~CalendarInterface();
-    /* 弹出位置? */
-    void positionCalendarPopup(QWidget *q);
-protected:
-     virtual void SetCalendarSync(const QDate &defaultDate) = 0;
-protected:
-     QHBoxLayout* m_pLayout;
-
-     const int SHADOW_RADIUS = 16;
-     const int SPACING = 8;
-     const int CALENDAR_WIDTH = 325;
-     const int CALENDAR_HEIGHT = 350;
-};
-/**
- * @brief 带有阴影的日历
- *
- */
-class CalendarEx : public CalendarInterface
-{
-    Q_OBJECT
-public:
-    explicit CalendarEx(const QDate& defaultDate = QDate(), QWidget* parent = nullptr);
-    virtual ~CalendarEx() {}
-signals:
-    void sig_DateChanged(const QDate& date);
-private:
-    virtual void SetCalendarSync(const QDate &defaultDate);
-private:
-     CalendarWidgetEx *m_pCalendar;
-};
-
-class ScopedCalendar : public CalendarInterface
-{
-    Q_OBJECT
-public:
-    explicit ScopedCalendar(const QDate &from = QDate(), const QDate &to = QDate(), QWidget *parent = nullptr);
-    virtual ~ScopedCalendar() { };
-
-    void SetMinimumDate(const QDate &date);
-    void SetMaximumDate(const QDate &date);
-signals:
-    void sig_ScopeSelected(const QDate &from, const QDate &to);
-public slots:
-    void OnScopeSelected(const QDate &from, const QDate &to);
-private:
-    virtual void SetCalendarSync(const QDate &defaultDate);
-private:
-     CalendarWidgetEx *m_pCalendar_L;
-     CalendarWidgetEx *m_pCalendar_R;
-};
-
-#endif // CALENDAREX_H
+#ifndef CALENDAREX_H
+#define CALENDAREX_H
+
+#include <QWidget>
+#include "calendarwidgetex.h"
+#include "DropShadow/idropshadowable.h"
+
+class QHBoxLayout;
+
+class CalendarInterface : public QWidget, public IDropShadowable
+{
+    Q_OBJECT
+public:
+    explicit CalendarInterface(QWidget *parent = nullptr);
+    virtual ~CalendarInterface();
+    /* 弹出位置? */
+    void positionCalendarPopup(QWidget *q);
+protected:
+     virtual void SetCalendarSync(const QDate &defaultDate) = 0;
+protected:
+     QHBoxLayout* m_pLayout;
+
+     const int SHADOW_RADIUS = 16;
+     const int SPACING = 8;
+     const int CALENDAR_WIDTH = 325;
+     const int CALENDAR_HEIGHT = 350;
+};
+/**
+ * @brief 带有阴影的日历
+ *
+ */
+class CalendarEx : public CalendarInterface
+{
+    Q_OBJECT
+public:
+    explicit CalendarEx(const QDate& defaultDate = QDate(), QWidget* parent = nullptr);
+    virtual ~CalendarEx() {}
+signals:
+    void sig_DateChanged(const QDate& date);
+private:
+    virtual void SetCalendarSync(const QDate &defaultDate);
+private:
+     CalendarWidgetEx *m_pCalendar;
+};
+
+class ScopedCalendar : public CalendarInterface
+{
+    Q_OBJECT
+public:
+    explicit ScopedCalendar(const QDate &from = QDate(), const QDate &to = QDate(), QWidget *parent = nullptr);
+    virtual ~ScopedCalendar() { };
+
+    void SetMinimumDate(const QDate &date);
+    void SetMaximumDate(const QDate &date);
+signals:
+    void sig_ScopeSelected(const QDate &from, const QDate &to);
+public slots:
+    void OnScopeSelected(const QDate &from, const QDate &to);
+private:
+    virtual void SetCalendarSync(const QDate &defaultDate);
+private:
+     CalendarWidgetEx *m_pCalendar_L;
+     CalendarWidgetEx *m_pCalendar_R;
+};
+
+#endif // CALENDAREX_H

+ 67 - 67
common/DateSelect/calendarheader.cpp → common/SelectDate/calendarheader.cpp

@@ -1,67 +1,67 @@
-#include "calendarheader.h"
-#include "ui_calendarheader.h"
-#include "PaintHelper/painthelper.h"
-// #include "StyleManager/lhstylemanager.h"
-#include "LHQLogAPI.h"
-
-#include <QFile>
-
-CalendarHeader::CalendarHeader(QWidget *parent) :
-    QWidget(parent),
-    ui(new Ui::CalendarHeader)
-{
-    ui->setupUi(this);
-    // LHStyleManager::Instance()->AddWidget(this);
-    // setQSS();
-    setQSS(0);
-}
-
-CalendarHeader::~CalendarHeader()
-{
-    delete ui;
-}
-
-void CalendarHeader::SetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)
-{
-    ui->label1->setText(km_listWeeks.at((dayOfWeek-1+0)%km_listWeeks.count()));
-    ui->label2->setText(km_listWeeks.at((dayOfWeek-1+1)%km_listWeeks.count()));
-    
-    ui->label3->setText(km_listWeeks.at((dayOfWeek-1+2)%km_listWeeks.count()));
-    ui->label4->setText(km_listWeeks.at((dayOfWeek-1+3)%km_listWeeks.count()));
-    
-    ui->label5->setText(km_listWeeks.at((dayOfWeek-1+4)%km_listWeeks.count()));
-    ui->label6->setText(km_listWeeks.at((dayOfWeek-1+5)%km_listWeeks.count()));
-    
-    ui->label7->setText(km_listWeeks.at((dayOfWeek-1+6)%km_listWeeks.count()));
-}
-
-/* 设置QSS */
-void CalendarHeader::setQSS(int style)
-{
-    QString qssPath;
-    if(style == 0)
-    {
-        /* 亮色UI */
-        qssPath = ":/Calendar/qss/calendarheader_light.qss";
-    }
-    else if(style == 1)
-    {
-        /* 暗色UI */
-        qssPath = ":/Calendar/qss/calendarheader_dark.qss";
-    }
-    QFile qssFile(qssPath);
-    if(qssFile.open(QFile::ReadOnly))
-    {
-        QString qss = qssFile.readAll();
-        setStyleSheet(qss);
-        qssFile.close();
-    }else {
-        LH_WRITE_ERROR("open qss file failed, path: " + qssPath);
-    }
-}
-
-
-void CalendarHeader::paintEvent(QPaintEvent *)
-{
-    PainterEx painter(this);
-}
+#include "calendarheader.h"
+#include "ui_calendarheader.h"
+#include "PaintHelper/painthelper.h"
+// #include "StyleManager/lhstylemanager.h"
+#include "LHQLogAPI.h"
+
+#include <QFile>
+
+CalendarHeader::CalendarHeader(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::CalendarHeader)
+{
+    ui->setupUi(this);
+    // LHStyleManager::Instance()->AddWidget(this);
+    // setQSS();
+    setQSS(0);
+}
+
+CalendarHeader::~CalendarHeader()
+{
+    delete ui;
+}
+
+void CalendarHeader::SetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek)
+{
+    ui->label1->setText(km_listWeeks.at((dayOfWeek-1+0)%km_listWeeks.count()));
+    ui->label2->setText(km_listWeeks.at((dayOfWeek-1+1)%km_listWeeks.count()));
+    
+    ui->label3->setText(km_listWeeks.at((dayOfWeek-1+2)%km_listWeeks.count()));
+    ui->label4->setText(km_listWeeks.at((dayOfWeek-1+3)%km_listWeeks.count()));
+    
+    ui->label5->setText(km_listWeeks.at((dayOfWeek-1+4)%km_listWeeks.count()));
+    ui->label6->setText(km_listWeeks.at((dayOfWeek-1+5)%km_listWeeks.count()));
+    
+    ui->label7->setText(km_listWeeks.at((dayOfWeek-1+6)%km_listWeeks.count()));
+}
+
+/* 设置QSS */
+void CalendarHeader::setQSS(int style)
+{
+    QString qssPath;
+    if(style == 0)
+    {
+        /* 亮色UI */
+        qssPath = ":/Calendar/qss/calendarheader_light.qss";
+    }
+    else if(style == 1)
+    {
+        /* 暗色UI */
+        qssPath = ":/Calendar/qss/calendarheader_dark.qss";
+    }
+    QFile qssFile(qssPath);
+    if(qssFile.open(QFile::ReadOnly))
+    {
+        QString qss = qssFile.readAll();
+        setStyleSheet(qss);
+        qssFile.close();
+    }else {
+        LH_WRITE_ERROR("open qss file failed, path: " + qssPath);
+    }
+}
+
+
+void CalendarHeader::paintEvent(QPaintEvent *)
+{
+    PainterEx painter(this);
+}

+ 32 - 32
common/DateSelect/calendarheader.h → common/SelectDate/calendarheader.h

@@ -1,32 +1,32 @@
-#ifndef CALENDARHEADER_H
-#define CALENDARHEADER_H
-
-#include <QWidget>
-
-namespace Ui {
-class CalendarHeader;
-}
-
-class CalendarHeader : public QWidget
-{
-    Q_OBJECT
-    
-public:
-    explicit CalendarHeader(QWidget *parent = nullptr);
-    ~CalendarHeader() override;
-    void SetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
-    
-    /* 设置QSS */
-    void setQSS(int style);
-
-public slots:
-
-    
-private:
-    Ui::CalendarHeader *ui;
-    const QList<QString> km_listWeeks = {"一","二","三","四","五","六","日"};
-protected:
-    void paintEvent(QPaintEvent *) override;
-};
-
-#endif // CALENDARHEADER_H
+#ifndef CALENDARHEADER_H
+#define CALENDARHEADER_H
+
+#include <QWidget>
+
+namespace Ui {
+class CalendarHeader;
+}
+
+class CalendarHeader : public QWidget
+{
+    Q_OBJECT
+    
+public:
+    explicit CalendarHeader(QWidget *parent = nullptr);
+    ~CalendarHeader() override;
+    void SetFirstDayOfWeek(Qt::DayOfWeek dayOfWeek);
+    
+    /* 设置QSS */
+    void setQSS(int style);
+
+public slots:
+
+    
+private:
+    Ui::CalendarHeader *ui;
+    const QList<QString> km_listWeeks = {"一","二","三","四","五","六","日"};
+protected:
+    void paintEvent(QPaintEvent *) override;
+};
+
+#endif // CALENDARHEADER_H

+ 139 - 139
common/DateSelect/calendarheader.ui → common/SelectDate/calendarheader.ui

@@ -1,139 +1,139 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>CalendarHeader</class>
- <widget class="QWidget" name="CalendarHeader">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>361</width>
-    <height>19</height>
-   </rect>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>0</width>
-    <height>16</height>
-   </size>
-  </property>
-  <property name="maximumSize">
-   <size>
-    <width>16777215</width>
-    <height>19</height>
-   </size>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <layout class="QHBoxLayout" name="horizontalLayout">
-   <property name="spacing">
-    <number>0</number>
-   </property>
-   <property name="leftMargin">
-    <number>0</number>
-   </property>
-   <property name="topMargin">
-    <number>0</number>
-   </property>
-   <property name="rightMargin">
-    <number>0</number>
-   </property>
-   <property name="bottomMargin">
-    <number>0</number>
-   </property>
-   <item>
-    <widget class="QLabel" name="label1">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>日</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label2">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>一</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label3">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>二</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label4">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>三</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label5">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>四</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label6">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>五</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="label7">
-     <property name="styleSheet">
-      <string notr="true"/>
-     </property>
-     <property name="text">
-      <string>六</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CalendarHeader</class>
+ <widget class="QWidget" name="CalendarHeader">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>361</width>
+    <height>19</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>0</width>
+    <height>16</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>16777215</width>
+    <height>19</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="spacing">
+    <number>0</number>
+   </property>
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QLabel" name="label1">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>日</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label2">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>一</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label3">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>二</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label4">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>三</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label5">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>四</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label6">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>五</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label7">
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>六</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 92 - 94
common/DateSelect/calendarnav.cpp → common/SelectDate/calendarnav.cpp

@@ -1,94 +1,92 @@
-#include "calendarnav.h"
-#include "PaintHelper/painthelper.h"
-#include "ui_calendarnav.h"
-// #include "StyleManager/lhstylemanager.h"
-#include <QDebug>
-#include <QFile>
-
-
-//#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 qssPath = QApplication::applicationDirPath();
-    QString qssFile;
-    if(style == 0)
-    {
-        // qssFile = qssPath + "/white/SelectDate/calendarnav.qss";
-        qssFile = ":/Calendar/qss/CalendarNav_light.qss";
-    }else if(style == 1)
-    {
-        // qssFile = qssPath + "/black/SelectDate/calendarnav.qss";
-        qssFile = ":/Calendar/qss/CalendarNav_dark.qss";
-    }
-    QFile file(qssFile);
-    if(file.open(QIODevice::ReadOnly))
-    {
-        QString stylesheet = file.readAll();
-        this->setStyleSheet(stylesheet);
-        file.close();
-    } else
-    {
-        qDebug() << "打开文件失败:" << file.fileName();
-    }
-}
-
-void CalendarNav::SetYearMonth(int year, int month)
-{
-    ui->labelYearMonth->setText(QString("%1 年 %2 月").arg(year).arg(month));
-}
+#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));
+}

+ 33 - 33
common/DateSelect/calendarnav.h → common/SelectDate/calendarnav.h

@@ -1,33 +1,33 @@
-#ifndef CALENDARNAV_H
-#define CALENDARNAV_H
-
-#include <QWidget>
-#include <QCalendarWidget>
-
-namespace Ui {
-class CalendarNav;
-}
-
-class CalendarNav : public QWidget
-{
-    Q_OBJECT
-    
-public:
-    explicit CalendarNav(QCalendarWidget *pCalendar, QWidget *parent = nullptr);
-    ~CalendarNav() override;
-
-    void hidePreYear(bool);
-    void hidePreMonth(bool);
-    void hideNextYear(bool);
-    void hideNextMonth(bool);
-
-    /* 设置QSS */
-    void setQSS(int style = 0);
-private:
-    Ui::CalendarNav *ui;
-    QCalendarWidget *m_pCalendar;
-private slots:
-    void SetYearMonth(int year, int month);
-};
-
-#endif // CALENDARNAV_H
+#ifndef CALENDARNAV_H
+#define CALENDARNAV_H
+
+#include <QWidget>
+#include <QCalendarWidget>
+
+namespace Ui {
+class CalendarNav;
+}
+
+class CalendarNav : public QWidget
+{
+    Q_OBJECT
+    
+public:
+    explicit CalendarNav(QCalendarWidget *pCalendar, QWidget *parent = nullptr);
+    ~CalendarNav() override;
+
+    void hidePreYear(bool);
+    void hidePreMonth(bool);
+    void hideNextYear(bool);
+    void hideNextMonth(bool);
+
+    /* 设置QSS */
+    void setQSS(int style = 0);
+private:
+    Ui::CalendarNav *ui;
+    QCalendarWidget *m_pCalendar;
+private slots:
+    void SetYearMonth(int year, int month);
+};
+
+#endif // CALENDARNAV_H

+ 140 - 140
common/DateSelect/calendarnav.ui → common/SelectDate/calendarnav.ui

@@ -1,140 +1,140 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>CalendarNav</class>
- <widget class="QWidget" name="CalendarNav">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>361</width>
-    <height>39</height>
-   </rect>
-  </property>
-  <property name="minimumSize">
-   <size>
-    <width>0</width>
-    <height>39</height>
-   </size>
-  </property>
-  <property name="maximumSize">
-   <size>
-    <width>16777215</width>
-    <height>39</height>
-   </size>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <layout class="QHBoxLayout" name="horizontalLayout">
-   <property name="spacing">
-    <number>15</number>
-   </property>
-   <property name="leftMargin">
-    <number>6</number>
-   </property>
-   <property name="topMargin">
-    <number>0</number>
-   </property>
-   <property name="rightMargin">
-    <number>6</number>
-   </property>
-   <property name="bottomMargin">
-    <number>0</number>
-   </property>
-   <item>
-    <widget class="QPushButton" name="btnPrevYear">
-     <property name="minimumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="text">
-      <string/>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QPushButton" name="btnPrevMonth">
-     <property name="minimumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="text">
-      <string/>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QLabel" name="labelYearMonth">
-     <property name="minimumSize">
-      <size>
-       <width>0</width>
-       <height>0</height>
-      </size>
-     </property>
-     <property name="text">
-      <string>2020 年 8 月</string>
-     </property>
-     <property name="alignment">
-      <set>Qt::AlignCenter</set>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QPushButton" name="btnNextMonth">
-     <property name="minimumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="text">
-      <string/>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QPushButton" name="btnNextYear">
-     <property name="minimumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="maximumSize">
-      <size>
-       <width>12</width>
-       <height>12</height>
-      </size>
-     </property>
-     <property name="text">
-      <string/>
-     </property>
-    </widget>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CalendarNav</class>
+ <widget class="QWidget" name="CalendarNav">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>361</width>
+    <height>39</height>
+   </rect>
+  </property>
+  <property name="minimumSize">
+   <size>
+    <width>0</width>
+    <height>39</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>16777215</width>
+    <height>39</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <property name="spacing">
+    <number>15</number>
+   </property>
+   <property name="leftMargin">
+    <number>6</number>
+   </property>
+   <property name="topMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>6</number>
+   </property>
+   <property name="bottomMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QPushButton" name="btnPrevYear">
+     <property name="minimumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPushButton" name="btnPrevMonth">
+     <property name="minimumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="labelYearMonth">
+     <property name="minimumSize">
+      <size>
+       <width>0</width>
+       <height>0</height>
+      </size>
+     </property>
+     <property name="text">
+      <string>2020 年 8 月</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPushButton" name="btnNextMonth">
+     <property name="minimumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPushButton" name="btnNextYear">
+     <property name="minimumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="maximumSize">
+      <size>
+       <width>12</width>
+       <height>12</height>
+      </size>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 408 - 408
common/DateSelect/calendarwidgetex.cpp → common/SelectDate/calendarwidgetex.cpp

@@ -1,408 +1,408 @@
-//qcustomcalendarwidget.cpp
-#include "calendarwidgetex.h"
-#include <QPainter>
-#include <QProxyStyle>
-#include <QTableView>
-#include <QHeaderView>
-#include <QLayout>
-#include <QPushButton>
-#include <QLabel>
-#include <QDebug>
-#include <QLayoutItem>
-#include <QKeyEvent>
-#include <QPainterPath>
-
-#include "scopeselectionmodel.h"
-#include "PaintHelper/painthelper.h"
-// #include "StyleManager/lhstylemanager.h"
-//#include "utility/utility.h"
-#include "UIStyleManager.h"
-
-CalendarWidgetEx::CalendarWidgetEx(QWidget *parent)
-    : QCalendarWidget(parent)
-    , m_modeSelection(Normal)
-    , m_pDateScopeModel(nullptr)
-    , m_nLineHeight(-1)
-    , m_hasTopSplitLine(false)
-{
-    setWindowFlag(Qt::NoDropShadowWindowHint);
-    setAttribute(Qt::WA_TranslucentBackground);
-    setWindowFlag(Qt::FramelessWindowHint);
-
-    //使用固定尺寸(无法通过resize控制日历大小, 日历整体大小由layout下的控件的fixSize决定)
-    //layout()->setSizeConstraint(QLayout::SetFixedSize);
-    //禁用原有的年月导航
-    setNavigationBarVisible(false);
-    //禁用横向纵向表头
-    setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
-    setHorizontalHeaderFormat(QCalendarWidget::NoHorizontalHeader);
-    //取消聚焦虚线框
-    setStyle(new NoFocusStyle(this));
-
-    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
-    if(vBodyLayout == nullptr) return;
-
-    m_pNav = new CalendarNav(this);
-    m_pHeader = new CalendarHeader(this);
-    setFirstDayOfWeek(Qt::Sunday);
-    m_pHeader->SetFirstDayOfWeek(Qt::Sunday);
-
-    vBodyLayout->insertWidget(0, m_pNav);
-    // 导航和星期标题间距
-    vBodyLayout->insertSpacing(1, 10);
-    vBodyLayout->insertWidget(2, m_pHeader);
-
-    vBodyLayout->setSpacing(10);
-    vBodyLayout->setContentsMargins(10,0,10,10);
-
-    m_nLineHeight = vBodyLayout->itemAt(4)->widget()->mapTo(this, QPoint(0,0)).y();
-    //qDebug()<<"m_nLineHeight"<<m_nLineHeight<<vBodyLayout->itemAt(3)->widget()->height();
-
-    //开启鼠标监测
-    QTableView *pCalendarView = dynamic_cast<QTableView*>(vBodyLayout->itemAt(4)->widget());
-    if (Q_NULLPTR != pCalendarView) {
-        pCalendarView->setMouseTracking(true);
-    }
-
-    //在构造函数里取消selectionChanged, clicked事件没用, 因为执行QDateTimeEdit的setCalendarWidget方法时, 会重新绑定
-    //所以必须等setCalendarWidget执行完后再取消事件
-    //calendarWidget->disconnect(calendarWidget, &QCalendarWidget::selectionChanged, 0, 0);
-    //calendarWidget->disconnect(calendarWidget, &QCalendarWidget::clicked, 0, 0);
-
-    setMouseTracking(true);
-
-    // 设置默认字体后,修复单元格变得很宽的问题
-    for (QWidget* f : findChildren<QWidget*>()) {
-        if(f->objectName() != "qt_calendar_calendarview") continue;
-        QTableView* pView = reinterpret_cast<QTableView*>(f);
-        if (nullptr != pView && nullptr != pView->horizontalHeader()) {
-            pView->horizontalHeader()->setMaximumSectionSize(WINDOW_WIDTH / 8);
-        }
-    }
-
-    connect(this, &QCalendarWidget::clicked, this, &CalendarWidgetEx::OnClicked);
-    // initSkinColor();
-    setUIStyle();
-
-    /* 设置对象名称,加载QSS */
-    // this->setObjectName("calendarWidget");
-    this->setStyleSheet("background-color:transparent;");
-}
-
-
-void CalendarWidgetEx::SetSelectMode(SelectMode mode, ScopeSelectionModel *pDataModel)
-{
-    m_listMultiSelectDays.clear();
-    m_modeSelection = mode;
-    if(m_pDateScopeModel == nullptr)
-    {
-        m_pDateScopeModel = pDataModel;
-        connect(m_pDateScopeModel, &ScopeSelectionModel::sig_Update, this, static_cast<void(QWidget::*)()>(&QWidget::update));
-    }
-    update();
-}
-
-void CalendarWidgetEx::hideNavigatioinButton(bool bPreYear, bool bPreMon, bool bNextYear, bool bNextMon)
-{
-    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
-    if(vBodyLayout == nullptr) return;
-    CalendarNav *pNav = qobject_cast<CalendarNav*>(vBodyLayout->itemAt(0)->widget());
-    if (nullptr != pNav) {
-        pNav->hideNextMonth(bNextMon);
-        pNav->hideNextYear(bNextYear);
-        pNav->hidePreMonth(bPreMon);
-        pNav->hidePreYear(bPreYear);
-    }
-}
-
-/* 设置UI样式,0亮色,1暗色 */
-void CalendarWidgetEx::setUIStyle()
-{
-    if(EPUIStyle.getUIStyle() == enum_UIStyle::UI_Light)
-    {
-        m_style = 0;
-    }
-    else if(EPUIStyle.getUIStyle() == enum_UIStyle::UI_Dark)
-    {
-        m_style = 1;
-    }
-    initSkinColor();
-    m_pNav->setQSS(m_style);
-    m_pHeader->setQSS(m_style);
-    update();
-}
-
-void CalendarWidgetEx::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
-{
-    PainterEx *painterEx = static_cast<PainterEx*>(painter);
-    painterEx->setRenderHint(QPainter::Antialiasing);
-
-    QColor textColor;
-    {//正常
-        textColor = m_normalTextColor;
-    }
-#if 0
-    // 周六,周日特殊颜色
-    int nWeek = date.dayOfWeek();
-    if (6 == nWeek || 7 == nWeek) {
-        textColor = QColor(255,149,0);
-    }
-#endif
-    //鼠标移入
-    if(date == m_dateMouseOver)
-    {
-        QPoint center = rect.center();
-        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
-        painterEx->DrawRoundedRect(rc, 2.0, m_hoverBlockColor);
-        textColor = m_normalTextColor;
-    }
-    //当天
-    if(date == QDate::currentDate())
-    {
-        painter->save();
-        QPoint center = rect.center();
-        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
-        painter->setPen(m_todayTextColor);
-        painter->setBrush(Qt::transparent);
-        painter->drawRoundedRect(rc, 2.0, 2.0);
-        textColor = m_todayTextColor;
-        painter->restore();
-    }
-    //选中
-    if(m_modeSelection == Multi && m_listMultiSelectDays.contains(date))
-    {
-        //painterEx->DrawCircle(QRectF(rect).center(), 9, QColor(9,109,217));
-        QPoint center = rect.center();
-        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
-        painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
-        textColor = m_selectTextColor;
-    }
-    if(m_modeSelection == Normal && date == selectedDate())
-    {
-        //painterEx->DrawCircle(QRectF(rect).center(), 9, QColor(9, 109, 217));
-        QPoint center = rect.center();
-        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
-        painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
-        textColor = m_selectTextColor;
-    }
-    if(m_modeSelection == Scope && m_pDateScopeModel != nullptr && m_pDateScopeModel->dtFirst.isValid() && m_pDateScopeModel->dtSecond.isValid())
-    {
-        QDate scopeStart = qMin(m_pDateScopeModel->dtFirst, m_pDateScopeModel->dtSecond);
-        QDate scopeEnd = qMax(m_pDateScopeModel->dtFirst, m_pDateScopeModel->dtSecond);
-        if(date == qBound(scopeStart, date, scopeEnd) && date.month() == monthShown())
-        {
-            painterEx->SetBrushOnly(m_hoverBlockColor);
-            if(date == scopeStart || date == scopeEnd)
-            {
-                textColor = m_selectTextColor;
-                QPoint center = rect.center();
-                QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
-                painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
-            }
-            else
-            {
-                QRect r(0, 0, rect.width(), TEXT_WIDTH);
-                r.moveCenter(rect.center());
-                painterEx->drawRect(r);
-            }
-        }
-    }
-    //不可选的日期或非当月日期
-    if(date < minimumDate() || date > maximumDate() || date.month() != monthShown())
-    {
-        textColor = m_disableTextColor;
-    }
-
-    //当天且未选中, 加粗
-    bool isBold = (date == QDate::currentDate() && date != selectedDate());
-    QString strDay(QString("%1").arg(date.day(), 2, 10, QLatin1Char('0')));
-    painterEx->setFont(FontEx(font().family(), DEFAULT_FONT_SIZE, isBold));
-    QRect rc = rect.adjusted(-1, 0, 0, -3); // 矫正文字位置
-    painterEx->DrawText(rc, strDay, textColor, Qt::AlignCenter);
-}
-
-void CalendarWidgetEx::paintEvent(QPaintEvent *)
-{
-    PainterEx painter(this);
-
-    //边框和背景
-    painter.setPen(Qt::transparent);
-    painter.setBrush(m_bgBrushColor);
-    QRect rc(rect());
-    painter.DrawRoundedRect(rc, WINDOW_RADIUS);
-
-    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
-    if(vBodyLayout != nullptr) {
-        // 画导航栏,绘制上圆角
-        QPainterPath path;
-        path.setFillRule(Qt::WindingFill);
-        QRectF tmpRc(1, 0, WINDOW_WIDTH - WINDOW_RADIUS, 40);
-        path.addRoundedRect(tmpRc, WINDOW_RADIUS, WINDOW_RADIUS);
-        path.addRect(QRectF(tmpRc.x(), tmpRc.y() + WINDOW_RADIUS, tmpRc.width(), tmpRc.height()));
-        // painter.fillPath(path, QColor(255, 255, 255));
-        painter.fillPath(path, m_bgBrushColor);
-        //分割线
-        QWidget* pNav = vBodyLayout->itemAt(0)->widget();
-        if (nullptr != pNav) {
-            int h = pNav->mapTo(this, pNav->rect().bottomRight()).y() + 2;
-            // painter.SetPenOnly(QColor(0, 0, 0, 23));
-            painter.setPen(m_bgPenColor);
-            painter.drawLine(QPoint(0, h), QPoint(width(), h));
-        }
-    }
-}
-
-QSize CalendarWidgetEx::minimumSizeHint() const
-{
-    return QSize(WINDOW_WIDTH, WINDOW_HEIGHT);
-}
-
-void CalendarWidgetEx::mouseMoveEvent(QMouseEvent *event)
-{
-    QCalendarWidget::mouseMoveEvent(event);
-
-    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
-    if(vBodyLayout == nullptr) return;
-    QTableView *pCalendarView = dynamic_cast<QTableView*>(vBodyLayout->itemAt(4)->widget());
-    if(pCalendarView == nullptr) return;
-    QModelIndex index = pCalendarView->indexAt(pCalendarView->mapFromGlobal(event->globalPos()));
-    QDate dateMouseOver = dateForCell(index.row(), index.column());
-    if(m_dateMouseOver != dateMouseOver)
-    {
-        m_dateMouseOver = dateMouseOver;
-        if(m_pDateScopeModel != nullptr && !m_pDateScopeModel->bLocked && m_pDateScopeModel->dtFirst.isValid())
-        {
-            m_pDateScopeModel->dtSecond = dateMouseOver;
-            m_pDateScopeModel->Update();
-        }
-        update();
-    }
-}
-
-//仅适用于: 不显示纵向表头(第几周), 且不显示横向表头(周几)
-QDate CalendarWidgetEx::dateForCell(int row, int column) const
-{
-    if (row < 0 || row > 5 || column < 0 || column > 6)
-        return QDate();
-
-    const QDate refDate = referenceDate();
-    if (!refDate.isValid())
-        return QDate();
-
-    const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);
-    if (columnForFirstOfShownMonth - 0/*m_firstColumn*/ < 1)
-        row -= 1;
-
-    const int requestedDay = 7 * (row - 0/*m_firstRow*/) + column - columnForFirstOfShownMonth - refDate.day() + 1;
-    return refDate.addDays(requestedDay);
-}
-
-QDate CalendarWidgetEx::referenceDate() const
-{
-    int refDay = 1;
-    while (refDay <= 31) {
-        QDate refDate(yearShown(), monthShown(), refDay);
-        if (refDate.isValid())
-            return refDate;
-        refDay += 1;
-    }
-    return QDate();
-}
-int CalendarWidgetEx::columnForFirstOfMonth(const QDate &date) const
-{
-    return (columnForDayOfWeek(date.dayOfWeek()) - (date.day() % 7) + 8) % 7;
-}
-int CalendarWidgetEx::columnForDayOfWeek(int day) const
-{
-    if (day < 1 || day > 7)
-        return -1;
-    int column = day - firstDayOfWeek();
-    if (column < 0)
-        column += 7;
-    return column;
-}
-
-void CalendarWidgetEx::initSkinColor()
-{
-    switch (m_style) 
-    {
-    case 0:
-        m_normalTextColor = NORMAL_TEXT_BRIGHT;
-        m_todayTextColor = TODAY_TEXT_BRIGHT;
-        m_selectTextColor = SELECT_TEXT_BRIGHT;
-        m_disableTextColor = DISABLE_TEXT_BRIGHT;
-        m_splitLineColor = SPLIT_LINE_BRIGHT;
-        m_selectBlockColor = SELECT_BRIGHT;
-        m_hoverBlockColor = HOVER_BRIGHT;
-        m_bgBrushColor = BG_BRUSH_BRIGHT;
-        m_bgPenColor = BG_PEN_BRIGHT;
-        break;
-    case 1:
-        m_normalTextColor = NORMAL_TEXT_DEEP;
-        m_todayTextColor = TODAY_TEXT_DEEP;
-        m_selectTextColor = SELECT_TEXT_DEEP;
-        m_disableTextColor = DISABLE_TEXT_DEEP;
-        m_splitLineColor = SPLIT_LINE_DEEP;
-        m_selectBlockColor = SELECT_DEEP;
-        m_hoverBlockColor = HOVER_DEEP;
-        m_bgBrushColor = BG_BRUSH_DEEP;
-        m_bgPenColor = BG_PEN_DEEP;
-        break;
-    default:
-        break;
-    }
-}
-
-void CalendarWidgetEx::OnClicked(const QDate &date)
-{
-    if(m_modeSelection == Multi)
-    {
-        if(m_listMultiSelectDays.contains(date))
-        {
-            m_listMultiSelectDays.removeOne(date);
-        }
-        else
-        {
-            m_listMultiSelectDays.append(date);
-        }
-    }
-    if(m_modeSelection == Scope && m_pDateScopeModel != nullptr)
-    {
-        if(!m_pDateScopeModel->bLocked && m_pDateScopeModel->dtFirst.isValid())
-        {
-            m_pDateScopeModel->dtSecond = date;
-            m_pDateScopeModel->bLocked = true;
-            m_pDateScopeModel->Locked();
-        }
-        else
-        {
-            m_pDateScopeModel->dtFirst = date;
-            m_pDateScopeModel->dtSecond = date;
-            m_pDateScopeModel->bLocked = false;
-        }
-
-        m_pDateScopeModel->Update();
-    }
-    update();
-}
-
-void CalendarWidgetEx::leaveEvent(QEvent *)
-{
-    if(m_modeSelection != Scope)
-    {
-        //离开日历时, 清空鼠标移入状态
-        m_dateMouseOver = QDate();
-        update();
-    }
-}
-
-void NoFocusStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
-{
-    QStyleOption *viewOption = new QStyleOption(*option);
-    viewOption->state &= (~QStyle::State_HasFocus);
-    //if (element == PE_FrameFocusRect) return;
-    QProxyStyle::drawPrimitive(element, viewOption, painter, widget);
-    delete viewOption;
-}
-
-
+//qcustomcalendarwidget.cpp
+#include "calendarwidgetex.h"
+#include <QPainter>
+#include <QProxyStyle>
+#include <QTableView>
+#include <QHeaderView>
+#include <QLayout>
+#include <QPushButton>
+#include <QLabel>
+#include <QDebug>
+#include <QLayoutItem>
+#include <QKeyEvent>
+#include <QPainterPath>
+
+#include "scopeselectionmodel.h"
+#include "PaintHelper/painthelper.h"
+// #include "StyleManager/lhstylemanager.h"
+//#include "utility/utility.h"
+#include "UIStyleManager.h"
+
+CalendarWidgetEx::CalendarWidgetEx(QWidget *parent)
+    : QCalendarWidget(parent)
+    , m_modeSelection(Normal)
+    , m_pDateScopeModel(nullptr)
+    , m_nLineHeight(-1)
+    , m_hasTopSplitLine(false)
+{
+    setWindowFlag(Qt::NoDropShadowWindowHint);
+    setAttribute(Qt::WA_TranslucentBackground);
+    setWindowFlag(Qt::FramelessWindowHint);
+
+    //使用固定尺寸(无法通过resize控制日历大小, 日历整体大小由layout下的控件的fixSize决定)
+    //layout()->setSizeConstraint(QLayout::SetFixedSize);
+    //禁用原有的年月导航
+    setNavigationBarVisible(false);
+    //禁用横向纵向表头
+    setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
+    setHorizontalHeaderFormat(QCalendarWidget::NoHorizontalHeader);
+    //取消聚焦虚线框
+    setStyle(new NoFocusStyle(this));
+
+    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
+    if(vBodyLayout == nullptr) return;
+
+    m_pNav = new CalendarNav(this);
+    m_pHeader = new CalendarHeader(this);
+    setFirstDayOfWeek(Qt::Sunday);
+    m_pHeader->SetFirstDayOfWeek(Qt::Sunday);
+
+    vBodyLayout->insertWidget(0, m_pNav);
+    // 导航和星期标题间距
+    vBodyLayout->insertSpacing(1, 10);
+    vBodyLayout->insertWidget(2, m_pHeader);
+
+    vBodyLayout->setSpacing(10);
+    vBodyLayout->setContentsMargins(10,0,10,10);
+
+    m_nLineHeight = vBodyLayout->itemAt(4)->widget()->mapTo(this, QPoint(0,0)).y();
+    //qDebug()<<"m_nLineHeight"<<m_nLineHeight<<vBodyLayout->itemAt(3)->widget()->height();
+
+    //开启鼠标监测
+    QTableView *pCalendarView = dynamic_cast<QTableView*>(vBodyLayout->itemAt(4)->widget());
+    if (Q_NULLPTR != pCalendarView) {
+        pCalendarView->setMouseTracking(true);
+    }
+
+    //在构造函数里取消selectionChanged, clicked事件没用, 因为执行QDateTimeEdit的setCalendarWidget方法时, 会重新绑定
+    //所以必须等setCalendarWidget执行完后再取消事件
+    //calendarWidget->disconnect(calendarWidget, &QCalendarWidget::selectionChanged, 0, 0);
+    //calendarWidget->disconnect(calendarWidget, &QCalendarWidget::clicked, 0, 0);
+
+    setMouseTracking(true);
+
+    // 设置默认字体后,修复单元格变得很宽的问题
+    for (QWidget* f : findChildren<QWidget*>()) {
+        if(f->objectName() != "qt_calendar_calendarview") continue;
+        QTableView* pView = reinterpret_cast<QTableView*>(f);
+        if (nullptr != pView && nullptr != pView->horizontalHeader()) {
+            pView->horizontalHeader()->setMaximumSectionSize(WINDOW_WIDTH / 8);
+        }
+    }
+
+    connect(this, &QCalendarWidget::clicked, this, &CalendarWidgetEx::OnClicked);
+    // initSkinColor();
+    setUIStyle();
+
+    /* 设置对象名称,加载QSS */
+    // this->setObjectName("calendarWidget");
+    this->setStyleSheet("background-color:transparent;");
+}
+
+
+void CalendarWidgetEx::SetSelectMode(SelectMode mode, ScopeSelectionModel *pDataModel)
+{
+    m_listMultiSelectDays.clear();
+    m_modeSelection = mode;
+    if(m_pDateScopeModel == nullptr)
+    {
+        m_pDateScopeModel = pDataModel;
+        connect(m_pDateScopeModel, &ScopeSelectionModel::sig_Update, this, static_cast<void(QWidget::*)()>(&QWidget::update));
+    }
+    update();
+}
+
+void CalendarWidgetEx::hideNavigatioinButton(bool bPreYear, bool bPreMon, bool bNextYear, bool bNextMon)
+{
+    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
+    if(vBodyLayout == nullptr) return;
+    CalendarNav *pNav = qobject_cast<CalendarNav*>(vBodyLayout->itemAt(0)->widget());
+    if (nullptr != pNav) {
+        pNav->hideNextMonth(bNextMon);
+        pNav->hideNextYear(bNextYear);
+        pNav->hidePreMonth(bPreMon);
+        pNav->hidePreYear(bPreYear);
+    }
+}
+
+/* 设置UI样式,0亮色,1暗色 */
+void CalendarWidgetEx::setUIStyle()
+{
+    if(UIStyle.getUIStyle() == EUIStyle::UI_Light)
+    {
+        m_style = 0;
+    }
+    else if(UIStyle.getUIStyle() == EUIStyle::UI_Dark)
+    {
+        m_style = 1;
+    }
+    initSkinColor();
+    m_pNav->setQSS(m_style);
+    m_pHeader->setQSS(m_style);
+    update();
+}
+
+void CalendarWidgetEx::paintCell(QPainter *painter, const QRect &rect, const QDate &date) const
+{
+    PainterEx *painterEx = static_cast<PainterEx*>(painter);
+    painterEx->setRenderHint(QPainter::Antialiasing);
+
+    QColor textColor;
+    {//正常
+        textColor = m_normalTextColor;
+    }
+#if 0
+    // 周六,周日特殊颜色
+    int nWeek = date.dayOfWeek();
+    if (6 == nWeek || 7 == nWeek) {
+        textColor = QColor(255,149,0);
+    }
+#endif
+    //鼠标移入
+    if(date == m_dateMouseOver)
+    {
+        QPoint center = rect.center();
+        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
+        painterEx->DrawRoundedRect(rc, 2.0, m_hoverBlockColor);
+        textColor = m_normalTextColor;
+    }
+    //当天
+    if(date == QDate::currentDate())
+    {
+        painter->save();
+        QPoint center = rect.center();
+        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
+        painter->setPen(m_todayTextColor);
+        painter->setBrush(Qt::transparent);
+        painter->drawRoundedRect(rc, 2.0, 2.0);
+        textColor = m_todayTextColor;
+        painter->restore();
+    }
+    //选中
+    if(m_modeSelection == Multi && m_listMultiSelectDays.contains(date))
+    {
+        //painterEx->DrawCircle(QRectF(rect).center(), 9, QColor(9,109,217));
+        QPoint center = rect.center();
+        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
+        painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
+        textColor = m_selectTextColor;
+    }
+    if(m_modeSelection == Normal && date == selectedDate())
+    {
+        //painterEx->DrawCircle(QRectF(rect).center(), 9, QColor(9, 109, 217));
+        QPoint center = rect.center();
+        QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
+        painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
+        textColor = m_selectTextColor;
+    }
+    if(m_modeSelection == Scope && m_pDateScopeModel != nullptr && m_pDateScopeModel->dtFirst.isValid() && m_pDateScopeModel->dtSecond.isValid())
+    {
+        QDate scopeStart = qMin(m_pDateScopeModel->dtFirst, m_pDateScopeModel->dtSecond);
+        QDate scopeEnd = qMax(m_pDateScopeModel->dtFirst, m_pDateScopeModel->dtSecond);
+        if(date == qBound(scopeStart, date, scopeEnd) && date.month() == monthShown())
+        {
+            painterEx->SetBrushOnly(m_hoverBlockColor);
+            if(date == scopeStart || date == scopeEnd)
+            {
+                textColor = m_selectTextColor;
+                QPoint center = rect.center();
+                QRect rc(center.x() - TEXT_WIDTH / 2, center.y() - TEXT_WIDTH / 2, TEXT_WIDTH, TEXT_WIDTH);
+                painterEx->DrawRoundedRect(rc, 2.0, m_selectBlockColor);
+            }
+            else
+            {
+                QRect r(0, 0, rect.width(), TEXT_WIDTH);
+                r.moveCenter(rect.center());
+                painterEx->drawRect(r);
+            }
+        }
+    }
+    //不可选的日期或非当月日期
+    if(date < minimumDate() || date > maximumDate() || date.month() != monthShown())
+    {
+        textColor = m_disableTextColor;
+    }
+
+    //当天且未选中, 加粗
+    bool isBold = (date == QDate::currentDate() && date != selectedDate());
+    QString strDay(QString("%1").arg(date.day(), 2, 10, QLatin1Char('0')));
+    painterEx->setFont(FontEx(font().family(), DEFAULT_FONT_SIZE, isBold));
+    QRect rc = rect.adjusted(-1, 0, 0, -3); // 矫正文字位置
+    painterEx->DrawText(rc, strDay, textColor, Qt::AlignCenter);
+}
+
+void CalendarWidgetEx::paintEvent(QPaintEvent *)
+{
+    PainterEx painter(this);
+
+    //边框和背景
+    painter.setPen(Qt::transparent);
+    painter.setBrush(m_bgBrushColor);
+    QRect rc(rect());
+    painter.DrawRoundedRect(rc, WINDOW_RADIUS);
+
+    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
+    if(vBodyLayout != nullptr) {
+        // 画导航栏,绘制上圆角
+        QPainterPath path;
+        path.setFillRule(Qt::WindingFill);
+        QRectF tmpRc(1, 0, WINDOW_WIDTH - WINDOW_RADIUS, 40);
+        path.addRoundedRect(tmpRc, WINDOW_RADIUS, WINDOW_RADIUS);
+        path.addRect(QRectF(tmpRc.x(), tmpRc.y() + WINDOW_RADIUS, tmpRc.width(), tmpRc.height()));
+        // painter.fillPath(path, QColor(255, 255, 255));
+        painter.fillPath(path, m_bgBrushColor);
+        //分割线
+        QWidget* pNav = vBodyLayout->itemAt(0)->widget();
+        if (nullptr != pNav) {
+            int h = pNav->mapTo(this, pNav->rect().bottomRight()).y() + 2;
+            // painter.SetPenOnly(QColor(0, 0, 0, 23));
+            painter.setPen(m_bgPenColor);
+            painter.drawLine(QPoint(0, h), QPoint(width(), h));
+        }
+    }
+}
+
+QSize CalendarWidgetEx::minimumSizeHint() const
+{
+    return QSize(WINDOW_WIDTH, WINDOW_HEIGHT);
+}
+
+void CalendarWidgetEx::mouseMoveEvent(QMouseEvent *event)
+{
+    QCalendarWidget::mouseMoveEvent(event);
+
+    QVBoxLayout *vBodyLayout = qobject_cast<QVBoxLayout *>(layout());
+    if(vBodyLayout == nullptr) return;
+    QTableView *pCalendarView = dynamic_cast<QTableView*>(vBodyLayout->itemAt(4)->widget());
+    if(pCalendarView == nullptr) return;
+    QModelIndex index = pCalendarView->indexAt(pCalendarView->mapFromGlobal(event->globalPos()));
+    QDate dateMouseOver = dateForCell(index.row(), index.column());
+    if(m_dateMouseOver != dateMouseOver)
+    {
+        m_dateMouseOver = dateMouseOver;
+        if(m_pDateScopeModel != nullptr && !m_pDateScopeModel->bLocked && m_pDateScopeModel->dtFirst.isValid())
+        {
+            m_pDateScopeModel->dtSecond = dateMouseOver;
+            m_pDateScopeModel->Update();
+        }
+        update();
+    }
+}
+
+//仅适用于: 不显示纵向表头(第几周), 且不显示横向表头(周几)
+QDate CalendarWidgetEx::dateForCell(int row, int column) const
+{
+    if (row < 0 || row > 5 || column < 0 || column > 6)
+        return QDate();
+
+    const QDate refDate = referenceDate();
+    if (!refDate.isValid())
+        return QDate();
+
+    const int columnForFirstOfShownMonth = columnForFirstOfMonth(refDate);
+    if (columnForFirstOfShownMonth - 0/*m_firstColumn*/ < 1)
+        row -= 1;
+
+    const int requestedDay = 7 * (row - 0/*m_firstRow*/) + column - columnForFirstOfShownMonth - refDate.day() + 1;
+    return refDate.addDays(requestedDay);
+}
+
+QDate CalendarWidgetEx::referenceDate() const
+{
+    int refDay = 1;
+    while (refDay <= 31) {
+        QDate refDate(yearShown(), monthShown(), refDay);
+        if (refDate.isValid())
+            return refDate;
+        refDay += 1;
+    }
+    return QDate();
+}
+int CalendarWidgetEx::columnForFirstOfMonth(const QDate &date) const
+{
+    return (columnForDayOfWeek(date.dayOfWeek()) - (date.day() % 7) + 8) % 7;
+}
+int CalendarWidgetEx::columnForDayOfWeek(int day) const
+{
+    if (day < 1 || day > 7)
+        return -1;
+    int column = day - firstDayOfWeek();
+    if (column < 0)
+        column += 7;
+    return column;
+}
+
+void CalendarWidgetEx::initSkinColor()
+{
+    switch (m_style) 
+    {
+    case 0:
+        m_normalTextColor = NORMAL_TEXT_BRIGHT;
+        m_todayTextColor = TODAY_TEXT_BRIGHT;
+        m_selectTextColor = SELECT_TEXT_BRIGHT;
+        m_disableTextColor = DISABLE_TEXT_BRIGHT;
+        m_splitLineColor = SPLIT_LINE_BRIGHT;
+        m_selectBlockColor = SELECT_BRIGHT;
+        m_hoverBlockColor = HOVER_BRIGHT;
+        m_bgBrushColor = BG_BRUSH_BRIGHT;
+        m_bgPenColor = BG_PEN_BRIGHT;
+        break;
+    case 1:
+        m_normalTextColor = NORMAL_TEXT_DEEP;
+        m_todayTextColor = TODAY_TEXT_DEEP;
+        m_selectTextColor = SELECT_TEXT_DEEP;
+        m_disableTextColor = DISABLE_TEXT_DEEP;
+        m_splitLineColor = SPLIT_LINE_DEEP;
+        m_selectBlockColor = SELECT_DEEP;
+        m_hoverBlockColor = HOVER_DEEP;
+        m_bgBrushColor = BG_BRUSH_DEEP;
+        m_bgPenColor = BG_PEN_DEEP;
+        break;
+    default:
+        break;
+    }
+}
+
+void CalendarWidgetEx::OnClicked(const QDate &date)
+{
+    if(m_modeSelection == Multi)
+    {
+        if(m_listMultiSelectDays.contains(date))
+        {
+            m_listMultiSelectDays.removeOne(date);
+        }
+        else
+        {
+            m_listMultiSelectDays.append(date);
+        }
+    }
+    if(m_modeSelection == Scope && m_pDateScopeModel != nullptr)
+    {
+        if(!m_pDateScopeModel->bLocked && m_pDateScopeModel->dtFirst.isValid())
+        {
+            m_pDateScopeModel->dtSecond = date;
+            m_pDateScopeModel->bLocked = true;
+            m_pDateScopeModel->Locked();
+        }
+        else
+        {
+            m_pDateScopeModel->dtFirst = date;
+            m_pDateScopeModel->dtSecond = date;
+            m_pDateScopeModel->bLocked = false;
+        }
+
+        m_pDateScopeModel->Update();
+    }
+    update();
+}
+
+void CalendarWidgetEx::leaveEvent(QEvent *)
+{
+    if(m_modeSelection != Scope)
+    {
+        //离开日历时, 清空鼠标移入状态
+        m_dateMouseOver = QDate();
+        update();
+    }
+}
+
+void NoFocusStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
+{
+    QStyleOption *viewOption = new QStyleOption(*option);
+    viewOption->state &= (~QStyle::State_HasFocus);
+    //if (element == PE_FrameFocusRect) return;
+    QProxyStyle::drawPrimitive(element, viewOption, painter, widget);
+    delete viewOption;
+}
+
+

+ 117 - 117
common/DateSelect/calendarwidgetex.h → common/SelectDate/calendarwidgetex.h

@@ -1,117 +1,117 @@
-#ifndef QCUSTOMCALENDARWIDGET_H
-#define QCUSTOMCALENDARWIDGET_H
-
-#include <QCalendarWidget>
-#include <QPushButton>
-#include <QLabel>
-#include <QProxyStyle>
-
-#include "calendarheader.h"
-#include "calendarnav.h"
-
-class ScopeSelectionModel;
-
-class NoFocusStyle : public QProxyStyle
-{
-    Q_OBJECT
-public:
-    explicit NoFocusStyle(QObject *parent):QProxyStyle() { setParent(parent); }
-
-private:
-    void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
-                       QPainter *painter, const QWidget *widget) const;
-};
-/**
- * @brief The CalendarWidgetEx class
- */
-class CalendarWidgetEx : public QCalendarWidget
-{
-    Q_OBJECT
-public:
-    enum SelectMode
-    {
-        Normal,
-        Multi,
-        Scope,
-    };
-public:
-    explicit CalendarWidgetEx(QWidget *parent = nullptr);
-    ~CalendarWidgetEx() override {}
-    void SetSelectMode(SelectMode mode, ScopeSelectionModel *pDataModel = nullptr);
-    QList<QDate> GetSelectDays(){return m_listMultiSelectDays;}
-
-    void hideNavigatioinButton(bool bPreYear, bool bPreMon, bool bNextYear, bool bNextMon);
-
-    /* 设置UI样式,0亮色,1暗色 */
-    void setUIStyle();
-
-private:
-    QDate dateForCell(int row, int column) const;
-    QDate referenceDate() const;
-    int columnForFirstOfMonth(const QDate &date) const;
-    int columnForDayOfWeek(int day) const;
-    void initSkinColor();
-protected:
-    void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const override;
-    void paintEvent(QPaintEvent *) override;
-    void mouseMoveEvent(QMouseEvent *event) override;
-    void leaveEvent(QEvent *) override;
-public:
-    QSize minimumSizeHint() const override;
-private slots:
-    void OnClicked(const QDate &date);
-private:
-    int m_style = 0;
-    CalendarNav* m_pNav = nullptr;
-    CalendarHeader* m_pHeader = nullptr;
-    /* 亮色 */
-    const QColor NORMAL_TEXT_BRIGHT{QColor(58,63,99)};
-    const QColor TODAY_TEXT_BRIGHT{QColor(68,88,254)};
-    const QColor SELECT_TEXT_BRIGHT{Qt::white};
-    const QColor DISABLE_TEXT_BRIGHT{QColor(133, 142, 189)};
-    const QColor SPLIT_LINE_BRIGHT{QColor(0, 0, 0, 23)};
-    const QColor SELECT_BRIGHT{QColor(68, 88, 254)};
-    const QColor HOVER_BRIGHT{QColor(227, 238, 255)};
-    const QColor BG_BRUSH_BRIGHT{QColor(255,255,255)};      /* 背景 */
-    const QColor BG_PEN_BRIGHT{QColor(0, 0, 0, 23)};        /* 线条 */
-
-    /* 暗色 */
-    const QColor NORMAL_TEXT_DEEP{QColor(255,255,255,230)};
-    const QColor TODAY_TEXT_DEEP{Qt::black};
-    const QColor SELECT_TEXT_DEEP{Qt::black};
-    const QColor DISABLE_TEXT_DEEP{QColor(255,255,255,77)};
-    const QColor SPLIT_LINE_DEEP{QColor(255,255,255,64)};
-    const QColor SELECT_DEEP{QColor(233, 161, 18)};
-    const QColor HOVER_DEEP{QColor(132, 134, 136)};
-    
-    const QColor TODAY_DEEP{QColor(67, 142, 255)};
-    const QColor BG_PEN_DEEP{QColor(255,255,255,51)};       /* 线条 */
-    const QColor BG_BRUSH_DEEP{QColor{116,117,120}};        /* 背景 */
-    const QColor BG_SPECIAL_PEN_DEEP{QColor{27, 186, 102}}; 
-    const QColor BG_SPECIAL_BRUSH_DEEP{QColor{78, 112, 97}};
-
-
-
-    const int DEFAULT_FONT_SIZE = 16;
-    const int TEXT_WIDTH = 24;
-    const qreal WINDOW_RADIUS = 4.0;
-    const int WINDOW_WIDTH = 325;
-    const int WINDOW_HEIGHT = 350;
-
-    QDate m_dateMouseOver;
-    QList<QDate> m_listMultiSelectDays;
-    SelectMode m_modeSelection;
-    ScopeSelectionModel *m_pDateScopeModel;
-    int m_nLineHeight;      //星期和日之间的分割线的Y坐标
-    bool m_hasTopSplitLine; // 是否绘制顶部分割线
-    QColor m_normalTextColor;
-    QColor m_todayTextColor;
-    QColor m_selectTextColor;
-    QColor m_disableTextColor;
-    QColor m_splitLineColor;
-    QColor m_selectBlockColor;
-    QColor m_hoverBlockColor;
-    QColor m_bgBrushColor;          /* 背景画刷 */
-    QColor m_bgPenColor;            /* 背景画笔 */
-};
-#endif // QCUSTOMCALENDARWIDGET_H
+#ifndef QCUSTOMCALENDARWIDGET_H
+#define QCUSTOMCALENDARWIDGET_H
+
+#include <QCalendarWidget>
+#include <QPushButton>
+#include <QLabel>
+#include <QProxyStyle>
+
+#include "calendarheader.h"
+#include "calendarnav.h"
+
+class ScopeSelectionModel;
+
+class NoFocusStyle : public QProxyStyle
+{
+    Q_OBJECT
+public:
+    explicit NoFocusStyle(QObject *parent):QProxyStyle() { setParent(parent); }
+
+private:
+    void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
+                       QPainter *painter, const QWidget *widget) const;
+};
+/**
+ * @brief The CalendarWidgetEx class
+ */
+class CalendarWidgetEx : public QCalendarWidget
+{
+    Q_OBJECT
+public:
+    enum SelectMode
+    {
+        Normal,
+        Multi,
+        Scope,
+    };
+public:
+    explicit CalendarWidgetEx(QWidget *parent = nullptr);
+    ~CalendarWidgetEx() override {}
+    void SetSelectMode(SelectMode mode, ScopeSelectionModel *pDataModel = nullptr);
+    QList<QDate> GetSelectDays(){return m_listMultiSelectDays;}
+
+    void hideNavigatioinButton(bool bPreYear, bool bPreMon, bool bNextYear, bool bNextMon);
+
+    /* 设置UI样式,0亮色,1暗色 */
+    void setUIStyle();
+
+private:
+    QDate dateForCell(int row, int column) const;
+    QDate referenceDate() const;
+    int columnForFirstOfMonth(const QDate &date) const;
+    int columnForDayOfWeek(int day) const;
+    void initSkinColor();
+protected:
+    void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const override;
+    void paintEvent(QPaintEvent *) override;
+    void mouseMoveEvent(QMouseEvent *event) override;
+    void leaveEvent(QEvent *) override;
+public:
+    QSize minimumSizeHint() const override;
+private slots:
+    void OnClicked(const QDate &date);
+private:
+    int m_style = 0;
+    CalendarNav* m_pNav = nullptr;
+    CalendarHeader* m_pHeader = nullptr;
+    /* 亮色 */
+    const QColor NORMAL_TEXT_BRIGHT{QColor(58,63,99)};
+    const QColor TODAY_TEXT_BRIGHT{QColor(68,88,254)};
+    const QColor SELECT_TEXT_BRIGHT{Qt::white};
+    const QColor DISABLE_TEXT_BRIGHT{QColor(133, 142, 189)};
+    const QColor SPLIT_LINE_BRIGHT{QColor(0, 0, 0, 23)};
+    const QColor SELECT_BRIGHT{QColor(68, 88, 254)};
+    const QColor HOVER_BRIGHT{QColor(227, 238, 255)};
+    const QColor BG_BRUSH_BRIGHT{QColor(255,255,255)};      /* 背景 */
+    const QColor BG_PEN_BRIGHT{QColor(0, 0, 0, 23)};        /* 线条 */
+
+    /* 暗色 */
+    const QColor NORMAL_TEXT_DEEP{QColor(255,255,255,230)};
+    const QColor TODAY_TEXT_DEEP{Qt::black};
+    const QColor SELECT_TEXT_DEEP{Qt::black};
+    const QColor DISABLE_TEXT_DEEP{QColor(255,255,255,77)};
+    const QColor SPLIT_LINE_DEEP{QColor(255,255,255,64)};
+    const QColor SELECT_DEEP{QColor(233, 161, 18)};
+    const QColor HOVER_DEEP{QColor(132, 134, 136)};
+    
+    const QColor TODAY_DEEP{QColor(67, 142, 255)};
+    const QColor BG_PEN_DEEP{QColor(255,255,255,51)};       /* 线条 */
+    const QColor BG_BRUSH_DEEP{QColor{116,117,120}};        /* 背景 */
+    const QColor BG_SPECIAL_PEN_DEEP{QColor{27, 186, 102}}; 
+    const QColor BG_SPECIAL_BRUSH_DEEP{QColor{78, 112, 97}};
+
+
+
+    const int DEFAULT_FONT_SIZE = 16;
+    const int TEXT_WIDTH = 24;
+    const qreal WINDOW_RADIUS = 4.0;
+    const int WINDOW_WIDTH = 325;
+    const int WINDOW_HEIGHT = 350;
+
+    QDate m_dateMouseOver;
+    QList<QDate> m_listMultiSelectDays;
+    SelectMode m_modeSelection;
+    ScopeSelectionModel *m_pDateScopeModel;
+    int m_nLineHeight;      //星期和日之间的分割线的Y坐标
+    bool m_hasTopSplitLine; // 是否绘制顶部分割线
+    QColor m_normalTextColor;
+    QColor m_todayTextColor;
+    QColor m_selectTextColor;
+    QColor m_disableTextColor;
+    QColor m_splitLineColor;
+    QColor m_selectBlockColor;
+    QColor m_hoverBlockColor;
+    QColor m_bgBrushColor;          /* 背景画刷 */
+    QColor m_bgPenColor;            /* 背景画笔 */
+};
+#endif // QCUSTOMCALENDARWIDGET_H

+ 134 - 131
common/DateSelect/cdate.cpp → common/SelectDate/cdate.cpp

@@ -1,131 +1,134 @@
-#include "cdate.h"
-
-#include <QHBoxLayout>
-#include <QPainter>
-#include <QEvent>
-#include <QDebug>
-#include <QMouseEvent>
-#include <QEventLoop>
-
-#include "calendarwidgetex.h"
-#include "oneshadow.h"
-
-CDate::CDate(const QDate& defaultDate,QWidget *parent,PopupType type) :
-    QWidget{parent},
-    m_parent(parent),
-    m_type(type)
-{
-    init(defaultDate);
-}
-
-CDate::CDate(QWidget *parent,PopupType type) :
-    QWidget{parent},
-    m_parent(parent),
-    m_type(type)
-{
-//    if(type == Popup)
-//    {
-//        setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
-//    }
-    init(QDate::currentDate());
-}
-
-/* 阻塞执行 */
-QDate CDate::execShow()
-{
-    this->show();
-    QEventLoop loop;
-    connect(this, &CDate::signal_close, &loop, &QEventLoop::quit);
-    loop.exec();
-    return m_date;
-}
-
-/* 设置日期 */
-void CDate::setDate(const QDate& date)
-{
-    m_date = date;
-    m_calendarEx->setSelectedDate(date);
-}
-
-
-void CDate::paintEvent(QPaintEvent *event)
-{
-    QPainter painter(this);
-    painter.setRenderHint(QPainter::Antialiasing);
-    painter.drawImage(QPoint(0,0),m_shadow->image());
-}
-/**
- * @brief 在这里实现点击空白处隐藏或者关闭自身
- * @param watched
- * @param event
- * @return
- */
-bool CDate::eventFilter(QObject *watched, QEvent *event)
-{
-    auto me = dynamic_cast<QMouseEvent*>(event);
-    if(nullptr != me)
-    {
-        if(me->type() == QEvent::MouseButtonPress)
-        {
-            if(m_type == Popup)
-            {
-                /* 先将自身区域和鼠标坐标都转换成全局坐标 */
-                QPoint gTopLeft = this->mapToGlobal(this->rect().topLeft());
-                QRect gRect(gTopLeft.x(),gTopLeft.y(),this->width(),this->height());
-                /* 判断此时的鼠标坐标是否在这个控件中 */
-                if(!gRect.contains(me->globalPos()))
-                {
-//                    qDebug() << QTime::currentTime() << "CDate关闭了";
-                    emit signal_DateChanged(m_date);
-                    /* 发送信号,关闭自身 */
-                    emit signal_close();
-                    this->close();
-                }
-            }
-        }
-    }
-
-    return QWidget::eventFilter(watched,event);
-}
-
-
-void CDate::init(const QDate &defaultDate)
-{
-    /* 设置无边框 */
-    setWindowFlags(Qt::FramelessWindowHint);
-    /* 设置底层样式表,让最底层的透明 */
-    this->setAttribute(Qt::WA_TranslucentBackground);
-    /* 将父类的事件注册给自己 */
-    if(m_type == Popup && m_parent != nullptr)
-    {
-        m_parent->installEventFilter(this);
-    }
-    /* 设置布局,通过设置layout的Margin距离显示阴影 */
-    QHBoxLayout* layout = new QHBoxLayout(this);
-    this->setLayout(layout);
-    layout->setMargin(RADIUS);
-    this->resize(CALENDAR_WIDTH + RADIUS*2,CALENDAR_HEIGHT + RADIUS*2);
-
-    /* 设置日历组件 */
-    m_calendarEx = new CalendarWidgetEx(this);
-    m_calendarEx->resize(CALENDAR_WIDTH,CALENDAR_HEIGHT);
-    m_calendarEx->setCurrentPage(defaultDate.year(),defaultDate.month());
-    m_calendarEx->setSelectedDate(defaultDate);
-    layout->addWidget(m_calendarEx);
-
-
-    /* 设置自身时间 */
-    m_date = defaultDate;
-
-    /* 设置阴影 */
-    m_shadow = new OneShadow(QSize(m_calendarEx->width(),m_calendarEx->height()),RADIUS);
-
-
-    /* 信号和槽 */
-    connect(m_calendarEx,&CalendarWidgetEx::clicked,this,[this](const QDate& date){
-        m_date = date;
-        emit signal_DateChanged(date);
-        emit signal_close();
-        this->close();
-    });
-}
+#include "cdate.h"
+
+#include <QHBoxLayout>
+#include <QPainter>
+#include <QEvent>
+#include <QDebug>
+#include <QMouseEvent>
+#include <QEventLoop>
+
+#include "calendarwidgetex.h"
+#include "OneShadowEffect.h"
+
+CDate::CDate(const QDate& defaultDate,QWidget *parent,PopupType type) :
+    QWidget{parent},
+    m_parent(parent),
+    m_type(type)
+{
+    init(defaultDate);
+}
+
+CDate::CDate(QWidget *parent,PopupType type) :
+    QWidget{parent},
+    m_parent(parent),
+    m_type(type)
+{
+//    if(type == Popup)
+//    {
+//        setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
+//    }
+    init(QDate::currentDate());
+}
+
+/* 阻塞执行 */
+QDate CDate::execShow()
+{
+    this->show();
+    QEventLoop loop;
+    connect(this, &CDate::signal_close, &loop, &QEventLoop::quit);
+    loop.exec();
+    return m_date;
+}
+
+/* 设置日期 */
+void CDate::setDate(const QDate& date)
+{
+    m_date = date;
+    m_calendarEx->setSelectedDate(date);
+}
+
+
+void CDate::paintEvent(QPaintEvent *event)
+{
+    QPainter painter(this);
+    painter.setRenderHint(QPainter::Antialiasing);
+    // painter.drawImage(QPoint(0,0),m_shadow->image());
+}
+/**
+ * @brief 在这里实现点击空白处隐藏或者关闭自身
+ * @param watched
+ * @param event
+ * @return
+ */
+bool CDate::eventFilter(QObject *watched, QEvent *event)
+{
+    auto me = dynamic_cast<QMouseEvent*>(event);
+    if(nullptr != me)
+    {
+        if(me->type() == QEvent::MouseButtonPress)
+        {
+            if(m_type == Popup)
+            {
+                /* 先将自身区域和鼠标坐标都转换成全局坐标 */
+                QPoint gTopLeft = this->mapToGlobal(this->rect().topLeft());
+                QRect gRect(gTopLeft.x(),gTopLeft.y(),this->width(),this->height());
+                /* 判断此时的鼠标坐标是否在这个控件中 */
+                if(!gRect.contains(me->globalPos()))
+                {
+//                    qDebug() << QTime::currentTime() << "CDate关闭了";
+                    emit signal_DateChanged(m_date);
+                    /* 发送信号,关闭自身 */
+                    emit signal_close();
+                    this->close();
+                }
+            }
+        }
+    }
+
+    return QWidget::eventFilter(watched,event);
+}
+
+
+void CDate::init(const QDate &defaultDate)
+{
+    /* 设置无边框 */
+    setWindowFlags(Qt::FramelessWindowHint);
+    /* 设置底层样式表,让最底层的透明 */
+    this->setAttribute(Qt::WA_TranslucentBackground);
+    /* 将父类的事件注册给自己 */
+    if(m_type == Popup && m_parent != nullptr)
+    {
+        m_parent->installEventFilter(this);
+    }
+    /* 设置布局,通过设置layout的Margin距离显示阴影 */
+    QHBoxLayout* layout = new QHBoxLayout(this);
+    this->setLayout(layout);
+    layout->setMargin(RADIUS);
+    this->resize(CALENDAR_WIDTH + RADIUS*2,CALENDAR_HEIGHT + RADIUS*2);
+
+    /* 设置日历组件 */
+    m_calendarEx = new CalendarWidgetEx(this);
+    m_calendarEx->resize(CALENDAR_WIDTH,CALENDAR_HEIGHT);
+    m_calendarEx->setCurrentPage(defaultDate.year(),defaultDate.month());
+    m_calendarEx->setSelectedDate(defaultDate);
+    layout->addWidget(m_calendarEx);
+
+
+    /* 设置自身时间 */
+    m_date = defaultDate;
+
+    /* 设置阴影 */
+    // m_shadow = new OneShadow(QSize(m_calendarEx->width(),m_calendarEx->height()),RADIUS);
+    /*--------------------- 创建阴影 -----------------------*/
+    auto pShadow = new OneShadowEffect(this);
+    m_calendarEx->setGraphicsEffect(pShadow);
+
+
+    /* 信号和槽 */
+    connect(m_calendarEx,&CalendarWidgetEx::clicked,this,[this](const QDate& date){
+        m_date = date;
+        emit signal_DateChanged(date);
+        emit signal_close();
+        this->close();
+    });
+}

+ 63 - 63
common/DateSelect/cdate.h → common/SelectDate/cdate.h

@@ -1,63 +1,63 @@
-#ifndef CDATE_H
-#define CDATE_H
-
-
-/**
- * 使用说明
- *  1、这个是仿照TimeWidget做的一个可以点击空白处隐藏自身的日历控件
- *  2、实现方式就是将父类的事件注册到这个控件上,拦截父类的鼠标点击,判断
- *     是否在这个控件上进行隐藏,因此控件显示范围就依赖于父类空间大小了
- *  3、使用方法:
- *      1) 可以选择点击空白处隐藏或者不隐藏,设置PopuType类型就行
- *
-*/
-
-#include <QDialog>
-#include <QWidget>
-#include <QDate>
-
-class CalendarWidgetEx;
-class OneShadow;
-
-class CDate : public QWidget
-{
-    Q_OBJECT
-
-    const int RADIUS = 16;              /* 阴影范围 */
-    const int CALENDAR_WIDTH = 325;     /* 日历大小 */
-    const int CALENDAR_HEIGHT = 350;
-public:
-    enum PopupType{
-        Popup = 0,
-        NoPopup = 1
-    };
-    CDate(const QDate& defaultDate,QWidget *parent = nullptr,PopupType type = Popup);
-    CDate(QWidget *parent = nullptr,PopupType type = Popup);
-
-    /* 阻塞执行 */
-    QDate execShow();
-    /* 设置日期 */
-    void setDate(const QDate& date);
-    /* 获取日期 */
-    QDate getDate() const { return m_date; }
-
-
-signals:
-    void signal_DateChanged(const QDate& date);
-    void signal_close();
-
-protected:
-    void paintEvent(QPaintEvent *event);
-    bool eventFilter(QObject *watched, QEvent *event);
-
-private:
-    void init(const QDate& defaultDate);
-private:
-    QDate m_date;
-    CalendarWidgetEx* m_calendarEx = nullptr;
-    OneShadow* m_shadow = nullptr;
-    QWidget* m_parent = nullptr;
-    PopupType m_type;
-};
-
-#endif // CDATE_H
+#ifndef CDATE_H
+#define CDATE_H
+
+
+/**
+ * 使用说明
+ *  1、这个是仿照TimeWidget做的一个可以点击空白处隐藏自身的日历控件
+ *  2、实现方式就是将父类的事件注册到这个控件上,拦截父类的鼠标点击,判断
+ *     是否在这个控件上进行隐藏,因此控件显示范围就依赖于父类空间大小了
+ *  3、使用方法:
+ *      1) 可以选择点击空白处隐藏或者不隐藏,设置PopuType类型就行
+ *
+*/
+
+#include <QDialog>
+#include <QWidget>
+#include <QDate>
+
+class CalendarWidgetEx;
+class OneShadow;
+
+class CDate : public QWidget
+{
+    Q_OBJECT
+
+    const int RADIUS = 16;              /* 阴影范围 */
+    const int CALENDAR_WIDTH = 325;     /* 日历大小 */
+    const int CALENDAR_HEIGHT = 350;
+public:
+    enum PopupType{
+        Popup = 0,
+        NoPopup = 1
+    };
+    CDate(const QDate& defaultDate,QWidget *parent = nullptr,PopupType type = Popup);
+    CDate(QWidget *parent = nullptr,PopupType type = Popup);
+
+    /* 阻塞执行 */
+    QDate execShow();
+    /* 设置日期 */
+    void setDate(const QDate& date);
+    /* 获取日期 */
+    QDate getDate() const { return m_date; }
+
+
+signals:
+    void signal_DateChanged(const QDate& date);
+    void signal_close();
+
+protected:
+    void paintEvent(QPaintEvent *event);
+    bool eventFilter(QObject *watched, QEvent *event);
+
+private:
+    void init(const QDate& defaultDate);
+private:
+    QDate m_date;
+    CalendarWidgetEx* m_calendarEx = nullptr;
+    // OneShadow* m_shadow = nullptr;
+    QWidget* m_parent = nullptr;
+    PopupType m_type;
+};
+
+#endif // CDATE_H

+ 0 - 0
common/DateSelect/icon/dark/nextMonth.png → common/SelectDate/icon/dark/nextMonth.png


+ 0 - 0
common/DateSelect/icon/dark/nextMonth_hover.png → common/SelectDate/icon/dark/nextMonth_hover.png


+ 0 - 0
common/DateSelect/icon/dark/nextYear.png → common/SelectDate/icon/dark/nextYear.png


+ 0 - 0
common/DateSelect/icon/dark/nextYear_hover.png → common/SelectDate/icon/dark/nextYear_hover.png


+ 0 - 0
common/DateSelect/icon/dark/preMonth.png → common/SelectDate/icon/dark/preMonth.png


+ 0 - 0
common/DateSelect/icon/dark/preMonth_hover.png → common/SelectDate/icon/dark/preMonth_hover.png


+ 0 - 0
common/DateSelect/icon/dark/preYear.png → common/SelectDate/icon/dark/preYear.png


+ 0 - 0
common/DateSelect/icon/dark/preYear_hover.png → common/SelectDate/icon/dark/preYear_hover.png


+ 0 - 0
common/DateSelect/icon/light/nextMonth.png → common/SelectDate/icon/light/nextMonth.png


+ 0 - 0
common/DateSelect/icon/light/nextMonth_hover.png → common/SelectDate/icon/light/nextMonth_hover.png


+ 0 - 0
common/DateSelect/icon/light/nextYear.png → common/SelectDate/icon/light/nextYear.png


+ 0 - 0
common/DateSelect/icon/light/nextYear_hover.png → common/SelectDate/icon/light/nextYear_hover.png


+ 0 - 0
common/DateSelect/icon/light/preMonth.png → common/SelectDate/icon/light/preMonth.png


+ 0 - 0
common/DateSelect/icon/light/preMonth_hover.png → common/SelectDate/icon/light/preMonth_hover.png


+ 0 - 0
common/DateSelect/icon/light/preYear.png → common/SelectDate/icon/light/preYear.png


+ 0 - 0
common/DateSelect/icon/light/preYear_hover.png → common/SelectDate/icon/light/preYear_hover.png


+ 64 - 64
common/DateSelect/qss/CalendarNav_dark.qss → common/SelectDate/qss/CalendarNav_dark.qss

@@ -1,64 +1,64 @@
-
-
-QWidget
-{
-	color: rgba(255,255,255,0.9);
-	background-color: #747578;
-}
-
-
-QPushButton
-{
-	background: transparent;
-}
-
-QPushButton#btnPrevYear::hover
-{
-	image: url(:/Calendar/icon/dark/preYear.png);
-	border:none;
-}
-QPushButton#btnPrevYear
-{
-	image: url(:/Calendar/icon/dark/preYear_hover.png);
-	border:none;
-}
-
-QPushButton#btnPrevMonth::hover
-{
-	image: url(:/Calendar/icon/dark/preMonth.png);
-	border:none;
-}
-QPushButton#btnPrevMonth
-{
-	image: url(:/Calendar/icon/dark/preMonth_hover.png);
-	border:none;
-}
-
-QPushButton#btnNextMonth::hover
-{
-	image: url(:/Calendar/icon/dark/nextMonth.png);
-	border:none;
-}
-QPushButton#btnNextMonth
-{
-	image: url(:/Calendar/icon/dark/nextMonth_hover.png);
-	border:none;
-}
-
-QPushButton#btnNextYear::hover
-{
-	image: url(:/Calendar/icon/dark/nextYear.png);
-	border:none;
-}
-QPushButton#btnNextYear
-{
-	image: url(:/Calendar/icon/dark/nextYear_hover.png);
-	border:none;
-}
-
-QLabel 
-{
-	font-size: 14px;
-	font-weight: 500;
-	/* color: #3A3F63; */
-}
+
+
+QWidget
+{
+	color: rgba(255,255,255,0.9);
+	background-color: #747578;
+}
+
+
+QPushButton
+{
+	background: transparent;
+}
+
+QPushButton#btnPrevYear::hover
+{
+	image: url(:/Calendar/icon/dark/preYear.png);
+	border:none;
+}
+QPushButton#btnPrevYear
+{
+	image: url(:/Calendar/icon/dark/preYear_hover.png);
+	border:none;
+}
+
+QPushButton#btnPrevMonth::hover
+{
+	image: url(:/Calendar/icon/dark/preMonth.png);
+	border:none;
+}
+QPushButton#btnPrevMonth
+{
+	image: url(:/Calendar/icon/dark/preMonth_hover.png);
+	border:none;
+}
+
+QPushButton#btnNextMonth::hover
+{
+	image: url(:/Calendar/icon/dark/nextMonth.png);
+	border:none;
+}
+QPushButton#btnNextMonth
+{
+	image: url(:/Calendar/icon/dark/nextMonth_hover.png);
+	border:none;
+}
+
+QPushButton#btnNextYear::hover
+{
+	image: url(:/Calendar/icon/dark/nextYear.png);
+	border:none;
+}
+QPushButton#btnNextYear
+{
+	image: url(:/Calendar/icon/dark/nextYear_hover.png);
+	border:none;
+}
+
+QLabel 
+{
+	font-size: 14px;
+	font-weight: 500;
+	/* color: #3A3F63; */
+}

+ 50 - 50
common/DateSelect/qss/CalendarNav_light.qss → common/SelectDate/qss/CalendarNav_light.qss

@@ -1,50 +1,50 @@
-QPushButton#btnPrevYear::hover
-{
-	image: url(:/Calendar/icon/light/preYear.png);
-	border:none;
-}
-QPushButton#btnPrevYear
-{
-	image: url(:/Calendar/icon/light/preYear_hover.png);
-	border:none;
-}
-
-QPushButton#btnPrevMonth::hover
-{
-	image: url(:/Calendar/icon/light/preMonth.png);
-	border:none;
-}
-QPushButton#btnPrevMonth
-{
-	image: url(:/Calendar/icon/light/preMonth_hover.png);
-	border:none;
-}
-
-QPushButton#btnNextMonth::hover
-{
-	image: url(:/Calendar/icon/light/nextMonth.png);
-	border:none;
-}
-QPushButton#btnNextMonth
-{
-	image: url(:/Calendar/icon/light/nextMonth_hover.png);
-	border:none;
-}
-
-QPushButton#btnNextYear::hover
-{
-	image: url(:/Calendar/icon/light/nextYear.png);
-	border:none;
-}
-QPushButton#btnNextYear
-{
-	image: url(:/Calendar/icon/light/nextYear_hover.png);
-	border:none;
-}
-
-QLabel 
-{
-	font-size: 14px;
-	font-weight: 500;
-	color: #3A3F63;
-}
+QPushButton#btnPrevYear::hover
+{
+	image: url(:/Calendar/icon/light/preYear.png);
+	border:none;
+}
+QPushButton#btnPrevYear
+{
+	image: url(:/Calendar/icon/light/preYear_hover.png);
+	border:none;
+}
+
+QPushButton#btnPrevMonth::hover
+{
+	image: url(:/Calendar/icon/light/preMonth.png);
+	border:none;
+}
+QPushButton#btnPrevMonth
+{
+	image: url(:/Calendar/icon/light/preMonth_hover.png);
+	border:none;
+}
+
+QPushButton#btnNextMonth::hover
+{
+	image: url(:/Calendar/icon/light/nextMonth.png);
+	border:none;
+}
+QPushButton#btnNextMonth
+{
+	image: url(:/Calendar/icon/light/nextMonth_hover.png);
+	border:none;
+}
+
+QPushButton#btnNextYear::hover
+{
+	image: url(:/Calendar/icon/light/nextYear.png);
+	border:none;
+}
+QPushButton#btnNextYear
+{
+	image: url(:/Calendar/icon/light/nextYear_hover.png);
+	border:none;
+}
+
+QLabel 
+{
+	font-size: 14px;
+	font-weight: 500;
+	color: #3A3F63;
+}

+ 43 - 0
common/SelectDate/qss/calendardtedit_light.qss

@@ -0,0 +1,43 @@
+
+
+/* ==========================================================
+ *  日期选择器
+ * ========================================================== */
+
+QDateTimeEdit
+{
+    color: #3A3F63;
+	background: #FFFFFF;
+    border-radius: 4px;
+    padding-left:12px;
+    border: 1px solid #E6E9F4;
+}
+
+
+QDateTimeEdit[disabled="true"]
+{
+    color: #3A3F63;
+    background: rgba(0,0,0,0.04);
+    border: 1px solid #E6E9F4;
+}
+
+
+
+QDateTimeEdit[hover=true]
+{
+    border: 1px solid #4458FE;
+}
+
+QDateTimeEdit[Warn=true]
+{
+    border: 1px solid #D21F21;
+}
+
+
+QDateTimeEdit::drop-down
+{
+ 	padding-right:8px;
+	width: 16px;
+    image: url(:/icon/date_light.png);
+}
+

+ 5 - 5
common/DateSelect/qss/calendarheader_dark.qss → common/SelectDate/qss/calendarheader_dark.qss

@@ -1,6 +1,6 @@
-
-QWidget
-{
-    background: transparent;
-    color: rgba(255,255,255,0.9);
+
+QWidget
+{
+    background: transparent;
+    color: rgba(255,255,255,0.9);
 }

+ 5 - 5
common/DateSelect/qss/calendarheader_light.qss → common/SelectDate/qss/calendarheader_light.qss

@@ -1,6 +1,6 @@
-
-QWidget
-{
-    background: transparent;
-    color: #3A3F63;
+
+QWidget
+{
+    background: transparent;
+    color: #3A3F63;
 }

+ 28 - 0
common/SelectDate/rescalendar.qrc

@@ -0,0 +1,28 @@
+<!DOCTYPE RCC>
+<RCC>
+  <qresource prefix="/Calendar">
+    <file>icon/light/nextMonth.png</file>
+    <file>icon/light/nextMonth_hover.png</file>
+    <file>icon/light/nextYear.png</file>
+    <file>icon/light/nextYear_hover.png</file>
+    <file>icon/light/preMonth.png</file>
+    <file>icon/light/preMonth_hover.png</file>
+    <file>icon/light/preYear.png</file>
+    <file>icon/light/preYear_hover.png</file>
+    <file>icon/dark/nextMonth.png</file>
+    <file>icon/dark/nextMonth_hover.png</file>
+    <file>icon/dark/nextYear.png</file>
+    <file>icon/dark/nextYear_hover.png</file>
+    <file>icon/dark/preMonth.png</file>
+    <file>icon/dark/preMonth_hover.png</file>
+    <file>icon/dark/preYear.png</file>
+    <file>icon/dark/preYear_hover.png</file>
+  </qresource>
+  <qresource prefix="/">
+    <file>qss/calendarheader_dark.qss</file>
+    <file>qss/calendarheader_light.qss</file>
+    <file>qss/CalendarNav_dark.qss</file>
+    <file>qss/CalendarNav_light.qss</file>
+    <file>qss/calendardtedit_light.qss</file>
+  </qresource>
+</RCC>

+ 63 - 63
common/DateSelect/scopecalendarbtn.cpp → common/SelectDate/scopecalendarbtn.cpp

@@ -1,63 +1,63 @@
-#include "scopecalendarbtn.h"
-#include "calendarex.h"
-#include <QDebug>
-
-ScopeCalendarBtn::ScopeCalendarBtn(QWidget *parent) 
-    : QPushButton(parent)
-    , m_dtFrom(QDate::currentDate())
-    , m_dtTo(QDate::currentDate())
-    , m_dtMin(QDate(1,1,1))
-    , m_dtMax(QDate(9999,12,31))
-    , m_strFormat("%1 - %2")
-{
-    connect(this, &QPushButton::clicked, this, &ScopeCalendarBtn::OnPopBtnClicked);
-    SetScope(m_dtFrom, m_dtTo);
-}
-
-void ScopeCalendarBtn::SetMinimumDate(const QDate &date)
-{
-    m_dtMin = date;
-    m_dtMax = qMax(m_dtMin, m_dtMax);
-    m_dtFrom = qMax(m_dtMin, m_dtFrom);
-    m_dtTo = qMax(m_dtMin, m_dtTo);
-}
-
-void ScopeCalendarBtn::SetMiaxmumDate(const QDate &date)
-{
-    m_dtMax = date;
-    m_dtMin = qMin(m_dtMax, m_dtMin);
-    m_dtFrom = qMin(m_dtMax, m_dtFrom);
-    m_dtTo = qMin(m_dtMax, m_dtTo);
-}
-
-void ScopeCalendarBtn::SetScope(const QDate &from, const QDate &to)
-{
-    m_dtFrom = qBound(m_dtMin, from, m_dtMax);
-    m_dtTo = qBound(m_dtMin, to, m_dtMax);
-    QString text = QString(m_strFormat).arg(m_dtFrom.toString("yyyy-MM-dd"), m_dtTo.toString("yyyy-MM-dd"));
-    setText(text);
-}
-
-void ScopeCalendarBtn::OnPopBtnClicked()
-{
-    ScopedCalendar *pC = new ScopedCalendar(m_dtFrom, m_dtTo);
-    pC->show();
-    pC->positionCalendarPopup(this);
-    if(m_dtMin.isValid()) pC->SetMinimumDate(m_dtMin);
-    if(m_dtMax.isValid()) pC->SetMaximumDate(m_dtMax);
-    connect(pC, &ScopedCalendar::sig_ScopeSelected, this, &ScopeCalendarBtn::OnScopeSelected);
-}
-
-void ScopeCalendarBtn::OnScopeSelected(const QDate &from, const QDate &to)
-{
-    SetScope(from, to);
-    emit sig_ScopeSelected(from, to);
-}
-
-void ScopeCalendarBtn::paintEvent(QPaintEvent *event)
-{
-//    PainterEx painter(this);
-//    painter.SetBrushOnly(Qt::gray);
-//    painter.drawRect(rect());
-    QPushButton::paintEvent(event);
-}
+#include "scopecalendarbtn.h"
+#include "calendarex.h"
+#include <QDebug>
+
+ScopeCalendarBtn::ScopeCalendarBtn(QWidget *parent) 
+    : QPushButton(parent)
+    , m_dtFrom(QDate::currentDate())
+    , m_dtTo(QDate::currentDate())
+    , m_dtMin(QDate(1,1,1))
+    , m_dtMax(QDate(9999,12,31))
+    , m_strFormat("%1 - %2")
+{
+    connect(this, &QPushButton::clicked, this, &ScopeCalendarBtn::OnPopBtnClicked);
+    SetScope(m_dtFrom, m_dtTo);
+}
+
+void ScopeCalendarBtn::SetMinimumDate(const QDate &date)
+{
+    m_dtMin = date;
+    m_dtMax = qMax(m_dtMin, m_dtMax);
+    m_dtFrom = qMax(m_dtMin, m_dtFrom);
+    m_dtTo = qMax(m_dtMin, m_dtTo);
+}
+
+void ScopeCalendarBtn::SetMiaxmumDate(const QDate &date)
+{
+    m_dtMax = date;
+    m_dtMin = qMin(m_dtMax, m_dtMin);
+    m_dtFrom = qMin(m_dtMax, m_dtFrom);
+    m_dtTo = qMin(m_dtMax, m_dtTo);
+}
+
+void ScopeCalendarBtn::SetScope(const QDate &from, const QDate &to)
+{
+    m_dtFrom = qBound(m_dtMin, from, m_dtMax);
+    m_dtTo = qBound(m_dtMin, to, m_dtMax);
+    QString text = QString(m_strFormat).arg(m_dtFrom.toString("yyyy-MM-dd"), m_dtTo.toString("yyyy-MM-dd"));
+    setText(text);
+}
+
+void ScopeCalendarBtn::OnPopBtnClicked()
+{
+    ScopedCalendar *pC = new ScopedCalendar(m_dtFrom, m_dtTo);
+    pC->show();
+    pC->positionCalendarPopup(this);
+    if(m_dtMin.isValid()) pC->SetMinimumDate(m_dtMin);
+    if(m_dtMax.isValid()) pC->SetMaximumDate(m_dtMax);
+    connect(pC, &ScopedCalendar::sig_ScopeSelected, this, &ScopeCalendarBtn::OnScopeSelected);
+}
+
+void ScopeCalendarBtn::OnScopeSelected(const QDate &from, const QDate &to)
+{
+    SetScope(from, to);
+    emit sig_ScopeSelected(from, to);
+}
+
+void ScopeCalendarBtn::paintEvent(QPaintEvent *event)
+{
+//    PainterEx painter(this);
+//    painter.SetBrushOnly(Qt::gray);
+//    painter.drawRect(rect());
+    QPushButton::paintEvent(event);
+}

+ 33 - 33
common/DateSelect/scopecalendarbtn.h → common/SelectDate/scopecalendarbtn.h

@@ -1,33 +1,33 @@
-#ifndef CALENDARSCOPEBTN_H
-#define CALENDARSCOPEBTN_H
-
-#include <QDateTime>
-#include <QPushButton>
-
-class ScopeCalendarBtn : public QPushButton
-{
-    Q_OBJECT
-public:
-    explicit ScopeCalendarBtn(QWidget *parent = nullptr);
-    QDate From(){return m_dtFrom;}
-    QDate To(){return m_dtTo;}
-    void SetMinimumDate(const QDate &date);
-    void SetMiaxmumDate(const QDate &date);
-    void SetScope(const QDate &from, const QDate &to);
-    void SetFormat(const QString &format = "%1 - %2"){m_strFormat = format;}
-signals:
-    void sig_ScopeSelected(const QDate &from, const QDate &to);
-private slots:
-    void OnPopBtnClicked();
-    void OnScopeSelected(const QDate &from, const QDate &to);
-protected:
-    void paintEvent(QPaintEvent *event);
-private:
-    QDate m_dtFrom;
-    QDate m_dtTo;
-    QDate m_dtMin;
-    QDate m_dtMax;
-    QString m_strFormat;
-};
-
-#endif // CALENDARSCOPEBTN_H
+#ifndef CALENDARSCOPEBTN_H
+#define CALENDARSCOPEBTN_H
+
+#include <QDateTime>
+#include <QPushButton>
+
+class ScopeCalendarBtn : public QPushButton
+{
+    Q_OBJECT
+public:
+    explicit ScopeCalendarBtn(QWidget *parent = nullptr);
+    QDate From(){return m_dtFrom;}
+    QDate To(){return m_dtTo;}
+    void SetMinimumDate(const QDate &date);
+    void SetMiaxmumDate(const QDate &date);
+    void SetScope(const QDate &from, const QDate &to);
+    void SetFormat(const QString &format = "%1 - %2"){m_strFormat = format;}
+signals:
+    void sig_ScopeSelected(const QDate &from, const QDate &to);
+private slots:
+    void OnPopBtnClicked();
+    void OnScopeSelected(const QDate &from, const QDate &to);
+protected:
+    void paintEvent(QPaintEvent *event);
+private:
+    QDate m_dtFrom;
+    QDate m_dtTo;
+    QDate m_dtMin;
+    QDate m_dtMax;
+    QString m_strFormat;
+};
+
+#endif // CALENDARSCOPEBTN_H

+ 34 - 34
common/DateSelect/scopeselectionmodel.cpp → common/SelectDate/scopeselectionmodel.cpp

@@ -1,34 +1,34 @@
-#include "scopeselectionmodel.h"
-
-ScopeSelectionModel::ScopeSelectionModel(QObject *parent)
-    : QObject(parent)
-    , bLocked(false)
-{
-    
-}
-
-void ScopeSelectionModel::Clear()
-{
-    dtFirst = QDate();
-    dtSecond = QDate();
-    bLocked = false;
-}
-
-void ScopeSelectionModel::Update()
-{
-    emit sig_Update();
-}
-
-void ScopeSelectionModel::Locked()
-{
-    QDate from = qMin(dtFirst, dtSecond);
-    QDate to = qMax(dtFirst, dtSecond);
-    emit sig_ScopeSelected(from, to);
-}
-
-//void DateScopeModel::Lock(const QDate &date)
-//{
-//    if(bLocked || !dtFirst.isValid()) return;
-//    dtSecond = date;
-//    bLocked = true;
-//}
+#include "scopeselectionmodel.h"
+
+ScopeSelectionModel::ScopeSelectionModel(QObject *parent)
+    : QObject(parent)
+    , bLocked(false)
+{
+    
+}
+
+void ScopeSelectionModel::Clear()
+{
+    dtFirst = QDate();
+    dtSecond = QDate();
+    bLocked = false;
+}
+
+void ScopeSelectionModel::Update()
+{
+    emit sig_Update();
+}
+
+void ScopeSelectionModel::Locked()
+{
+    QDate from = qMin(dtFirst, dtSecond);
+    QDate to = qMax(dtFirst, dtSecond);
+    emit sig_ScopeSelected(from, to);
+}
+
+//void DateScopeModel::Lock(const QDate &date)
+//{
+//    if(bLocked || !dtFirst.isValid()) return;
+//    dtSecond = date;
+//    bLocked = true;
+//}

+ 26 - 26
common/DateSelect/scopeselectionmodel.h → common/SelectDate/scopeselectionmodel.h

@@ -1,26 +1,26 @@
-#ifndef DATESCOPEMODEL_H
-#define DATESCOPEMODEL_H
-
-#include <QDateTime>
-#include <QObject>
-
-class ScopeSelectionModel : public QObject
-{
-    Q_OBJECT
-public:
-    explicit ScopeSelectionModel(QObject *parent = nullptr);
-    void Clear();
-    void Update();
-    void Locked();
-signals:
-    void sig_Update();
-    void sig_ScopeSelected(const QDate &from, const QDate &to);
-    //void Lock(const QDate &date);
-public:
-    //QPair<QDate, QDate> m_pairDateScope;    //鼠标移动时的范围指示, key和value都是Qdate类型, 但是不一定哪个较大
-    QDate dtFirst;
-    QDate dtSecond;
-    bool bLocked;
-};
-
-#endif // DATESCOPEMODEL_H
+#ifndef DATESCOPEMODEL_H
+#define DATESCOPEMODEL_H
+
+#include <QDateTime>
+#include <QObject>
+
+class ScopeSelectionModel : public QObject
+{
+    Q_OBJECT
+public:
+    explicit ScopeSelectionModel(QObject *parent = nullptr);
+    void Clear();
+    void Update();
+    void Locked();
+signals:
+    void sig_Update();
+    void sig_ScopeSelected(const QDate &from, const QDate &to);
+    //void Lock(const QDate &date);
+public:
+    //QPair<QDate, QDate> m_pairDateScope;    //鼠标移动时的范围指示, key和value都是Qdate类型, 但是不一定哪个较大
+    QDate dtFirst;
+    QDate dtSecond;
+    bool bLocked;
+};
+
+#endif // DATESCOPEMODEL_H