#include "choose.h" #include "ai.h" #include "login.h" #include "marketing.h" #include #include #include #include #include #include #include #include #include #include #include #include // ================= GradientLabel ================= void GradientLabel::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QFont font = this->font(); painter.setFont(font); QRect rect = this->rect().adjusted(contentsMargins().left(), contentsMargins().top(), -contentsMargins().right(), -contentsMargins().bottom()); QString text = this->text(); QLinearGradient gradient(0, 0, rect.width(), 0); gradient.setColorAt(0, QColor("#ff9a9e")); gradient.setColorAt(0.5, QColor("#ff6a95")); gradient.setColorAt(1, QColor("#fad0c4")); painter.setPen(QPen(QBrush(gradient), 0)); painter.drawText(rect, alignment(), text); } // ================= choose 构造函数 ================= choose::choose(QWidget *parent) : QWidget(parent), aiPage(nullptr), loginPage(nullptr), marketingPage(nullptr) { // 播放背景音乐 QMediaPlaylist *musicList = new QMediaPlaylist(this); musicList->addMedia(QUrl::fromLocalFile("D:/sparking111dui/111/park/yun.wav")); QMediaPlayer *soundPlayer = new QMediaPlayer(this); soundPlayer->setPlaylist(musicList); soundPlayer->play(); musicList->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop); soundPlayer->setVolume(80); // 固定窗口大小 resize(550, 400); setMinimumSize(550, 400); setMaximumSize(550, 400); // 背景图片 photoLabel = new QLabel(this); photoLabel->setScaledContents(false); photoLabel->setGeometry(0, 0, width(), height()); photoLabel->setAlignment(Qt::AlignCenter); QPixmap pixmap(":/choose.jpg"); if (!pixmap.isNull()) { photoLabel->setPixmap(pixmap.scaled(photoLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } else { qDebug() << "图片加载失败,请检查路径"; } // 顶部渐变文字 titleLabel = new GradientLabel(this); titleLabel->setText("请选择您的角色"); QFont titleFont("微软雅黑", 25, QFont::Bold); titleLabel->setFont(titleFont); titleLabel->setAlignment(Qt::AlignVCenter); QHBoxLayout *titleLayout = new QHBoxLayout(); titleLayout->addSpacing(30); titleLayout->addWidget(titleLabel); titleLayout->addStretch(); // 公告区域使用滚动条 announcementLabel = new QLabel; announcementLabel->setWordWrap(true); announcementLabel->setText("停车场公告:\n" "1. 请规范停放,车身完全入位,勿占消防通道、应急出口及他人专属车位。\n" "2. 勿在车内存放现金、首饰等贵重物品,锁车后确认门窗是否关好。\n" "3. 场内禁鸣笛、限速5km/h,儿童与宠物需成人全程看护。\n" "4. 若遇车辆剐蹭、设备故障,联系管理员(电话:88888888)协助处理。\n" "5. 遇暴雨、大风等恶劣天气,建议选择地下停车场或空旷且安全区域,避免车辆受损。\n" "感谢您的理解与配合,祝您出行平安!"); announcementLabel->setStyleSheet( "color: #000000;" "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, " "stop:0 #fff0f2, stop:0.5 #fff5f8, stop:1 #fffafb);" "font: 11px '微软雅黑';" "padding: 5px;" "border-radius: 10px;" ); scrollArea = new QScrollArea(this); scrollArea->setWidgetResizable(true); scrollArea->setWidget(announcementLabel); scrollArea->setFixedSize(300, 140); // 公告可视区域 scrollArea->move(width() - 320, 80); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); scrollArea->setStyleSheet( "QScrollArea {" "background: transparent;" "border: none;" "border-radius: 10px;" "}" "QScrollBar:vertical {" "width: 6px;" "background: transparent;" "margin: 0px;" "}" "QScrollBar::handle:vertical {" "background: rgba(200,200,200,150);" "border-radius: 3px;" "}" ); // 按钮 btnAI = new QPushButton("车主", this); btnLogin = new QPushButton("系统管理员", this); btnMarketing = new QPushButton("系统运营商", this); QString btnStyle = R"( QPushButton { background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #ff9a9e, stop:1 #fad0c4); color: white; font: bold 15px "微软雅黑"; border-radius: 10px; padding: 8px 5px; } QPushButton:hover { background-color: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #fad0c4, stop:1 #ff9a9e); } QPushButton:pressed { background-color: #f78ca0; } )"; btnAI->setStyleSheet(btnStyle); btnLogin->setStyleSheet(btnStyle); btnMarketing->setStyleSheet(btnStyle); btnAI->setFixedSize(120,50); btnLogin->setFixedSize(120,50); btnMarketing->setFixedSize(120,50); QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->addSpacing(150); vLayout->addLayout(titleLayout); vLayout->addSpacing(42); QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->addStretch(); hLayout->addWidget(btnAI); hLayout->addSpacing(30); hLayout->addWidget(btnLogin); hLayout->addSpacing(30); hLayout->addWidget(btnMarketing); hLayout->addStretch(); vLayout->addLayout(hLayout); vLayout->addStretch(1); vLayout->setContentsMargins(0, 0, 0, 0); setLayout(vLayout); btnAI->raise(); btnLogin->raise(); btnMarketing->raise(); titleLabel->raise(); scrollArea->raise(); // 语音播报 tts = new QTextToSpeech(this); tts->say("请选择您的角色"); // 信号槽 connect(btnAI, &QPushButton::clicked, this, &choose::openAIPage); connect(btnLogin, &QPushButton::clicked, this, &choose::openLoginPage); connect(btnMarketing, &QPushButton::clicked, this, &choose::openMarketingPage); } choose::~choose() { aiPage = nullptr; loginPage = nullptr; marketingPage = nullptr; } void choose::resizeEvent(QResizeEvent *event) { photoLabel->setGeometry(0, 0, width(), height()); QPixmap pixmap(":/choose.jpg"); if (!pixmap.isNull()) { photoLabel->setPixmap(pixmap.scaled(photoLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } // 滚动公告自适应 if (scrollArea) { scrollArea->move(width() - 320, 80); } QWidget::resizeEvent(event); } // 打开子页面 void choose::openAIPage() { tts->say("您选择了车主"); if (!aiPage) aiPage = new ai(nullptr, this); aiPage->show(); this->hide(); } void choose::openLoginPage() { tts->say("您选择了系统管理员"); if (!loginPage) loginPage = new login(nullptr, this); loginPage->show(); this->hide(); } void choose::openMarketingPage() { tts->say("您选择了系统运营商"); if (!marketingPage) marketingPage = new marketing(nullptr, this); marketingPage->show(); this->hide(); } // 设置公告文本(动态修改) void choose::setAnnouncementText(const QString &text) { if (!announcementLabel) return; announcementLabel->setText(text); announcementLabel->adjustSize(); }