feat: implement AI schedule app with multi-device sync
- Qt 6 desktop client with day/month/year views, AI scheduling, and TOML settings\n- Go sync server with SQLite change stream, WebSocket notifications, and Docker deployment\n- Client outbox/LWW sync, offline retry, and dual-client integration tests\n- Linux fcitx5 setup, validation reports, and Windows MinGW preset
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
#include "TodayPanel.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLayoutItem>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "ElaScrollArea.h"
|
||||
#include "ElaText.h"
|
||||
#include "TodayItemCard.h"
|
||||
|
||||
TodayPanel::TodayPanel(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setMinimumWidth(272);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
|
||||
auto* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(12, 10, 12, 12);
|
||||
root->setSpacing(10);
|
||||
|
||||
auto* header = new QHBoxLayout();
|
||||
header->setContentsMargins(2, 0, 2, 0);
|
||||
header->setSpacing(6);
|
||||
m_titleLabel = new ElaText(QStringLiteral("当日任务"), 15, this);
|
||||
QFont titleFont = m_titleLabel->font();
|
||||
titleFont.setWeight(QFont::DemiBold);
|
||||
m_titleLabel->setFont(titleFont);
|
||||
m_countLabel = new ElaText(this);
|
||||
m_countLabel->setTextPixelSize(11);
|
||||
header->addWidget(m_titleLabel);
|
||||
header->addStretch(1);
|
||||
header->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
||||
root->addLayout(header);
|
||||
|
||||
m_scrollArea = new ElaScrollArea(this);
|
||||
m_scrollArea->setWidgetResizable(true);
|
||||
m_scrollArea->setFrameShape(QFrame::NoFrame);
|
||||
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_scrollArea->setStyleSheet(QStringLiteral("QScrollArea{background:transparent;border:none;}"));
|
||||
m_scrollArea->viewport()->setAutoFillBackground(false);
|
||||
m_scrollArea->viewport()->setStyleSheet(QStringLiteral("background:transparent;"));
|
||||
|
||||
m_listWidget = new QWidget(m_scrollArea);
|
||||
m_listWidget->setAutoFillBackground(false);
|
||||
m_listWidget->setStyleSheet(QStringLiteral("background:transparent;"));
|
||||
m_listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
m_listLayout = new QVBoxLayout(m_listWidget);
|
||||
m_listLayout->setContentsMargins(0, 0, 2, 0);
|
||||
m_listLayout->setSpacing(8);
|
||||
m_listLayout->addStretch(1);
|
||||
m_scrollArea->setWidget(m_listWidget);
|
||||
root->addWidget(m_scrollArea, 1);
|
||||
}
|
||||
|
||||
void TodayPanel::setTokens(const ThemeTokens& tokens)
|
||||
{
|
||||
m_tokens = tokens;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void TodayPanel::setDate(const QDate& date)
|
||||
{
|
||||
if (!m_titleLabel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!date.isValid() || date == QDate::currentDate())
|
||||
{
|
||||
m_titleLabel->setText(QStringLiteral("今日任务"));
|
||||
return;
|
||||
}
|
||||
m_titleLabel->setText(QStringLiteral("%1月%2日任务").arg(date.month()).arg(date.day()));
|
||||
}
|
||||
|
||||
void TodayPanel::setItems(const QVector<ScheduleItem>& items, const QDateTime& now)
|
||||
{
|
||||
m_items = items;
|
||||
m_now = now;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void TodayPanel::clearLayout(QVBoxLayout* layout)
|
||||
{
|
||||
while (QLayoutItem* item = layout->takeAt(0))
|
||||
{
|
||||
if (QWidget* widget = item->widget())
|
||||
{
|
||||
delete widget;
|
||||
}
|
||||
// addLayout 时 QLayout 本身即 QLayoutItem,直接 delete 可避免二次释放。
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void TodayPanel::rebuild()
|
||||
{
|
||||
if (!m_listLayout)
|
||||
{
|
||||
return;
|
||||
}
|
||||
clearLayout(m_listLayout);
|
||||
|
||||
const QDateTime now = m_now.isValid() ? m_now : QDateTime::currentDateTime();
|
||||
|
||||
int activeCount = 0;
|
||||
int overdueCount = 0;
|
||||
for (const ScheduleItem& item : m_items)
|
||||
{
|
||||
if (item.block.status == QStringLiteral("scheduled") || item.block.status == QStringLiteral("in_progress"))
|
||||
{
|
||||
++activeCount;
|
||||
if (item.block.endAt < now)
|
||||
{
|
||||
++overdueCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (overdueCount > 0)
|
||||
{
|
||||
m_countLabel->setText(QStringLiteral("%1 项待办 · %2 项超时").arg(activeCount).arg(overdueCount));
|
||||
}
|
||||
else if (activeCount > 0)
|
||||
{
|
||||
m_countLabel->setText(QStringLiteral("%1 项待办").arg(activeCount));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_countLabel->setText(QStringLiteral("全部完成"));
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> sorted = m_items;
|
||||
std::sort(sorted.begin(), sorted.end(), [&now](const ScheduleItem& a, const ScheduleItem& b) {
|
||||
const auto rank = [&now](const ScheduleItem& item) {
|
||||
const QString& status = item.block.status;
|
||||
if (status == QStringLiteral("dropped") || status == QStringLiteral("missed"))
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
if (status == QStringLiteral("done"))
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
if (item.block.endAt < now)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (status == QStringLiteral("in_progress"))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
};
|
||||
const int rankA = rank(a);
|
||||
const int rankB = rank(b);
|
||||
if (rankA != rankB)
|
||||
{
|
||||
return rankA < rankB;
|
||||
}
|
||||
if (a.block.startAt != b.block.startAt)
|
||||
{
|
||||
return a.block.startAt < b.block.startAt;
|
||||
}
|
||||
return a.block.id < b.block.id;
|
||||
});
|
||||
|
||||
if (sorted.isEmpty())
|
||||
{
|
||||
auto* empty = new ElaText(QStringLiteral("今天还没有安排\n双击时间网格即可新建"), 13, m_listWidget);
|
||||
empty->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
empty->setMinimumHeight(120);
|
||||
empty->setTextStyle(ElaTextType::Caption);
|
||||
m_listLayout->addWidget(empty);
|
||||
m_listLayout->addStretch(1);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ScheduleItem& item : sorted)
|
||||
{
|
||||
auto* card = new TodayItemCard(item, m_tokens, now, m_listWidget);
|
||||
connect(card, &TodayItemCard::clicked, this, &TodayPanel::focusRequested);
|
||||
connect(card, &TodayItemCard::editRequested, this, &TodayPanel::editRequested);
|
||||
connect(card, &TodayItemCard::statusChangeRequested, this, &TodayPanel::statusChangeRequested);
|
||||
connect(card, &TodayItemCard::postponeRequested, this, &TodayPanel::postponeRequested);
|
||||
connect(card, &TodayItemCard::deleteRequested, this, &TodayPanel::deleteRequested);
|
||||
m_listLayout->addWidget(card);
|
||||
}
|
||||
m_listLayout->addStretch(1);
|
||||
}
|
||||
Reference in New Issue
Block a user