mainwidget::mainwidget(QWidget *parent) : QWidget(parent), ui(new Ui::mainwidget), _isChannelWidgetShowing(false) { ui->setupUi(this); ui->pauseWidget->setVisible(false); connect(ui->pauseWidget, SIGNAL(clicked()), ui->controlWidget, SLOT(play())); exitShortcut = new QShortcut(QKeySequence::Close, this); connect(exitShortcut, SIGNAL(activated()), qApp, SLOT(quit())); pauseShortcut = new QShortcut(QKeySequence("Space"), this); connect(pauseShortcut, &QShortcut::activated, [this] () { bool visiable = ui->pauseWidget->isVisible(); if (visiable) ui->controlWidget->play(); else ui->controlWidget->pause(); ui->pauseWidget->setVisible(!visiable); }); nextShortcut = new QShortcut(QKeySequence("S"), this); connect(nextShortcut, &QShortcut::activated, [this] () { this->controlPanel()->on_nextButton_clicked(); }); deleteShortcut = new QShortcut(QKeySequence("D"), this); connect(deleteShortcut, &QShortcut::activated, [this] () { this->controlPanel()->on_trashButton_clicked(); }); likeShortcut = new QShortcut(QKeySequence("F"), this); connect(likeShortcut, &QShortcut::activated, [this] () { this->controlPanel()->on_likeButton_clicked(); }); connect(ui->channelWidget, SIGNAL(mouseLeave()), this, SLOT(animHideChannelWidget())); }
MainWidget::MainWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MainWidget), _isChannelWidgetShowing(false), _isAnimStarted(false), _isLyricWidgetShowing(false), topBorder(new QLabel(this)), bottomBorder(new QLabel(this)), systemTrayIcon(nullptr) { ui->setupUi(this); ui->lyricWidget->lower(); ui->channelWidget->raise(); ui->controlWidget->raise(); // Configure borders topBorder->setMaximumSize(this->width(), 5); topBorder->setMinimumSize(this->width(), 5); topBorder->setStyleSheet("background: qlineargradient(x1: 0, y1: 1, x2: 0, y2: 0, stop: 0 rgba(0,0,0,80), stop: 1 rgba(0,0,0,0));"); topBorder->raise(); topBorder->move(0, -topBorder->height()); bottomBorder->setMaximumSize(this->width(), 10); bottomBorder->setMinimumSize(this->width(), 10); bottomBorder->setStyleSheet("background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 rgba(0,0,0,120), stop: 1 rgba(0,0,0,0));"); bottomBorder->raise(); bottomBorder->move(0, ui->controlWidget->height()); ui->pauseWidget->raise(); ui->pauseWidget->setVisible(false); connect(ui->pauseWidget, SIGNAL(clicked()), ui->controlWidget, SLOT(play())); exitShortcut = new QShortcut(QKeySequence("Ctrl+Q"), this); connect(exitShortcut, SIGNAL(activated()), qApp, SLOT(quit())); pauseShortcut = new QShortcut(QKeySequence("Space"), this); connect(pauseShortcut, &QShortcut::activated, [this] () { bool visiable = ui->pauseWidget->isVisible(); if (visiable) ui->controlWidget->play(); else ui->controlWidget->pause(); ui->pauseWidget->setVisible(!visiable); }); nextShortcut = new QShortcut(QKeySequence("S"), this); connect(nextShortcut, SIGNAL(activated()), ui->controlWidget, SLOT(on_nextButton_clicked())); deleteShortcut = new QShortcut(QKeySequence("D"), this); connect(deleteShortcut, SIGNAL(activated()), ui->controlWidget, SLOT(on_trashButton_clicked())); likeShortcut = new QShortcut(QKeySequence("F"), this); connect(likeShortcut, SIGNAL(activated()), ui->controlWidget, SLOT(on_likeButton_clicked())); hideShortcut = new QShortcut(QKeySequence("Ctrl+W"), this); connect(hideShortcut, SIGNAL(activated()), this, SLOT(hide())); connect(ui->channelWidget, SIGNAL(mouseLeave()), this, SLOT(animHideChannelWidget())); connect(ui->controlWidget, SIGNAL(openChannelPanel()), this, SLOT(animShowChannelWidget())); connect(ui->controlWidget, SIGNAL(closeChannelPanel()), this, SLOT(animHideChannelWidget())); connect(ui->controlWidget, SIGNAL(openLyricPanel()), this, SLOT(animShowLyricWidget())); connect(ui->controlWidget, SIGNAL(closeLyricPanel()), this, SLOT(animHideLyricWidget())); // FIXME: Ubuntu doesn't support QSystemTrayIcon // Following code will cause confusing behaviour #ifdef WITH_SYSTEM_TRAY_ICON if (QSystemTrayIcon::isSystemTrayAvailable()) { systemTrayIcon = new QSystemTrayIcon(QIcon("://icon.png"), this); connect(systemTrayIcon, &QSystemTrayIcon::activated, [&] () { if (this->isHidden()) this->show(); }); QMenu *trayMenu = new QMenu(this); auto _openAction = trayMenu->addAction("打开主界面"); trayMenu->addSeparator(); auto _closeAction = trayMenu->addAction("退出"); connect(trayMenu, &QMenu::triggered, [this, _openAction, _closeAction] (QAction *action) { if (action == _openAction) this->show(); else if (action == _closeAction) qApp->quit(); }); systemTrayIcon->setContextMenu(trayMenu); systemTrayIcon->show(); } #endif }