#include "passwordmgmt.h" #include #include #include #include #include #include #include #include #include "global.h" namespace { class CardFocusGlow : public QObject { public: CardFocusGlow(QWidget* card, const QString& normalQss, const QString& focusQss, const QColor& glow, QObject* parent = nullptr) : QObject(parent), m_card(card), m_normal(normalQss), m_focus(focusQss), m_glow(glow) {} protected: bool eventFilter(QObject* obj, QEvent* ev) override { if (ev->type() == QEvent::FocusIn) { m_card->setStyleSheet(m_focus); if (!m_card->graphicsEffect()) { QGraphicsDropShadowEffect* g = new QGraphicsDropShadowEffect(m_card); // 偏移 0 → 四周光晕 g->setBlurRadius(40); g->setOffset(0, 0); g->setColor(m_glow); m_card->setGraphicsEffect(g); } } else if (ev->type() == QEvent::FocusOut) { m_card->setStyleSheet(m_normal); QWidget* parent = m_card->parentWidget(); // 光晕溢出卡片矩形,只重绘卡片自身会留下残影,把父控件一并标脏 m_card->setGraphicsEffect(nullptr); // Qt 会删除旧效果 m_card->update(); if (parent) parent->update(parent->rect()); } return QObject::eventFilter(obj, ev); } private: QWidget* m_card; QString m_normal; QString m_focus; QColor m_glow; }; } // namespace PasswordMgmtPage::PasswordMgmtPage(AppContext* ctx, QWidget* parent) : BasePage(ctx, parent) { QVBoxLayout* root = new QVBoxLayout(this); root->addStretch(1); QWidget* col = new QWidget(this); col->setFixedWidth(700); QVBoxLayout* lay = new QVBoxLayout(col); lay->setSpacing(50); lay->setAlignment(Qt::AlignHCenter); QLabel* title = label("密码管理界面", 60, C::TEXT, true, col); title->setAlignment(Qt::AlignCenter); lay->addWidget(title); // 功能选项列表 QWidget* option = new QWidget(col); option->setProperty("card", true); const QString cardQss = QString("QWidget[card=\"true\"]{background-color:%1;border:2px solid %2;border-radius:12px;}") .arg(C::PANEL, C::BORDER); const QString cardFocusQss = QString("QWidget[card=\"true\"]{background-color:%1;border:3px solid %2;border-radius:12px;}") .arg(C::PANEL, "#8ABFFF"); option->setStyleSheet(cardQss); QVBoxLayout* optLay = new QVBoxLayout(option); m_reset = new QCheckBox("重置密码功能", option); m_reset->setChecked(true); m_reset->setStyleSheet(QString( "QCheckBox{color:%1;font-size:40px;spacing:16px;}" "QCheckBox::indicator{width:40px;height:40px;border:2px solid %2;border-radius:6px;background-color:%3;}" "QCheckBox::indicator:checked{background-color:%4;border-color:%4;image:none;}" "QCheckBox:focus{color:#FFFFFF;}" "QCheckBox:focus::indicator{border:4px solid #8ABFFF;}") .arg(C::TEXT, C::BORDER, C::BG, C::PRIMARY)); // 复选框获得焦点(Tab 选中)时点亮整个卡片 m_reset->installEventFilter(new CardFocusGlow(option, cardQss, cardFocusQss, QColor("#7FBBFF"), m_reset)); optLay->addWidget(m_reset); lay->addWidget(option); // 确认 / 退出 QHBoxLayout* btnRow = new QHBoxLayout(); btnRow->setSpacing(80); btnRow->addStretch(1); QPushButton* ok = button("确认", "", col); ok->setFixedSize(160, 120); ok->setStyleSheet("font-size:60px;"); connect(ok, &QPushButton::clicked, this, [this]() { emit navigate(PageReset); }); QPushButton* exit = button("退出", "", col); exit->setFixedSize(160, 120); exit->setStyleSheet(cancelButtonStyle(60)); // 选中时红底白字 connect(exit, &QPushButton::clicked, this, [this]() { emit navigate(PageBoot); }); btnRow->addWidget(ok); btnRow->addWidget(exit); btnRow->addStretch(1); lay->addLayout(btnRow); root->addWidget(col, 0, Qt::AlignHCenter); root->addStretch(1); }