Added warning on closeEvent

This commit is contained in:
NeoTheFox 2015-03-24 16:13:43 +03:00
parent 908f49389a
commit dd59c0c54a
2 changed files with 29 additions and 0 deletions

View File

@ -952,6 +952,34 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
return QMainWindow::eventFilter(obj, event); return QMainWindow::eventFilter(obj, event);
} }
void MainWindow::closeEvent(QCloseEvent *event)
{
//If connected to printer - show warning dialog
if(opened)
{
//Create dialog
QMessageBox dialog(this);
//Set it up - different text if just connected and if printing
if(sending) dialog.setText(tr("Printer is working!\nAre you shure you want to exit?"));
else dialog.setText(tr("Printer is connected!\nAre you shure you want tot exit?"));
dialog.setIcon(QMessageBox::Warning);
//Save pointer to check what button was clicked
QPushButton *exitButton = dialog.addButton(tr("Exit"), QMessageBox::AcceptRole);
dialog.addButton(QMessageBox::Cancel);
//Show dialog
dialog.exec();
//Process responce
if(dialog.clickedButton() == exitButton) event->accept();
else event->ignore();
}
//Close immediately if not connected
else event->ignore();
}
void MainWindow::recentClicked() void MainWindow::recentClicked()
{ {
//Actually a dirty hack, but it is fast and simple //Actually a dirty hack, but it is fast and simple

View File

@ -57,6 +57,7 @@ protected:
QStringList userHistory; QStringList userHistory;
QSerialPortInfo printerinfo; QSerialPortInfo printerinfo;
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *target, QEvent *event); bool eventFilter(QObject *target, QEvent *event);
private: private: