createMessageGroupBox(); createActions(); createTrayIcon(); ui->action_DialogSuuport->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); connect (ui->action_DialogSuuport, SIGNAL(triggered()), this, SLOT(dialogSupp())); connect(trayIcon , SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this , SLOT(iconActivated(QSystemTrayIcon::ActivationReason))) ; QVBoxLayout *mainLayout = new QVBoxLayout ; mainLayout->addWidget(messageGroupBox); setLayout(mainLayout) ; QIcon icon_tray (":/sysTray/iconSysTray/tray_02.png"); trayIcon->setIcon(icon_tray); trayIcon->setToolTip(tr("АРМ моніторингу хворих фенілкетонурією ")); trayIcon->show();
void ARM::createTrayIcon(){ trayIconMenu = new QMenu (this) ; trayIconMenu->addAction(restoreAction) ; trayIconMenu->addSeparator(); trayIconMenu->addAction(quit_Action) ; trayIcon = new QSystemTrayIcon(this) ; trayIcon->setContextMenu(trayIconMenu); return;}void ARM::createActions(){ restoreAction = new QAction(tr("&Відновити"), this) ; restoreAction->setIcon(QIcon(":/sysTray/iconSysTray/restore_1.jpg")); connect(restoreAction ,SIGNAL(triggered()),this , SLOT(showMaximized())) ; quit_Action = new QAction(tr("&Вихід") , this) ; quit_Action->setIcon(QIcon(":/sysTray/iconSysTray/exit.jpg")); connect(quit_Action , SIGNAL(triggered()) , qApp , SLOT(quit())) ; return;}void ARM::createMessageGroupBox(){ messageGroupBox = new QGroupBox(tr("00000000")) ; durationSpinBox = new QSpinBox ; durationSpinBox->setValue(10); titleEdit = new QLineEdit (tr("АРМ моніторингу хворих фенілкетонурією")); bodyEdit = new QTextEdit ; bodyEdit->setPlainText(tr("Програма знаходиться в системному треї")); QGridLayout *messageLayout = new QGridLayout(0) ; messageLayout->addWidget(durationSpinBox , 1, 1); messageLayout->addWidget(titleEdit ,2,1,1,4); messageLayout->addWidget(bodyEdit , 3,1,2,4); messageLayout->setColumnStretch(3,1); messageLayout->setRowStretch(4,1);return;}void ARM::messageClicked(){ QMessageBox::information(0 , tr("Системний трей") , tr ("АРМ моніторингу хворих фенілкетонурією ")); return ;}void ARM::showMessage(){ QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information ; trayIcon->showMessage(titleEdit->text() , bodyEdit->toPlainText(), icon , durationSpinBox->value() * 1000); return;}//---------------------------------------------------------------------------------------void ARM::iconActivated(QSystemTrayIcon::ActivationReason reason){ switch (reason) { case QSystemTrayIcon::Trigger: case QSystemTrayIcon::DoubleClick: this->show(); break; case QSystemTrayIcon::MiddleClick: showMessage(); break; default: ; } return;}void ARM::setVisible(bool visible){ restoreAction->setEnabled(isMaximized() || !visible); QMainWindow::setVisible(visible); if (visible == true) { this->restoreAction->setEnabled(false); } else this->restoreAction->setEnabled(true) ; return;}//press closevoid ARM::closeEvent(QCloseEvent *event){ //this->showMessage () ; QMessageBox MsB(0); QString ds; MsB.setWindowTitle(tr("Системний трей")); MsB.setText(tr("Програма буде продовжувати працювати" "в системному треї . \n Для завершення роботи" " натисніть 'Вихід' в \n контексному меню трея")); MsB.setStandardButtons(QMessageBox::Yes); MsB.setButtonText(QMessageBox::Yes,tr("Так")); MsB.setDefaultButton(QMessageBox::Yes); MsB.setIcon(QMessageBox::Information); QIcon icon_Msb(":/sysTray/iconSysTray/info_02.jpg"); MsB.setWindowIcon(icon_Msb); int r = MsB.exec(); switch(r) { case QMessageBox::Yes: { if(trayIcon->isVisible()) { hide() ; event->ignore(); this->showMessage(); } } default: break; } return; }