Browse Source

Add a key event to the program to simulate system suspension

master
mliad 2 weeks ago
parent
commit
886499c6bb
  1. 16
      MainWindow.cpp
  2. 9
      MainWindow.h
  3. 2
      main.cpp

16
MainWindow.cpp

@ -1,9 +1,11 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QKeyEvent>
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, openCLManager(new OpenCLManager())
{
ui->setupUi(this);
}
@ -11,5 +13,19 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
delete ui;
delete openCLManager;
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
if(event->key() == Qt::Key_1)
{
std::cout << "Simulating system suspend..." << std::endl;
openCLManager->handleSuspendResume(true); //Simulate suspend
}
else if(event->key() == Qt::Key_2)
{
std::cout << "Simulating system resume..." << std::endl;
openCLManager->handleSuspendResume(false); //Simulate resume
}
}

9
MainWindow.h

@ -2,9 +2,11 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include "OpenCLManager.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
namespace Ui { class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
@ -15,7 +17,12 @@ public:
MainWindow(QWidget* parent = nullptr);
~MainWindow();
protected:
void keyPressEvent(QKeyEvent* event) override;
private:
Ui::MainWindow* ui;
OpenCLManager* openCLManager;
};
#endif //MAINWINDOW_H

2
main.cpp

@ -13,7 +13,7 @@
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
OpenCLManager openCLManager;
//OpenCLManager openCLManager;
MainWindow w;
w.show();

Loading…
Cancel
Save