Browse Source

Add a key event to the program to simulate system suspension

master
mliad 5 months ago
parent
commit
886499c6bb
  1. 18
      MainWindow.cpp
  2. 15
      MainWindow.h
  3. 2
      main.cpp

18
MainWindow.cpp

@ -1,9 +1,11 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "ui_MainWindow.h" #include "ui_MainWindow.h"
#include <QKeyEvent>
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent) : QMainWindow(parent)
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, openCLManager(new OpenCLManager())
{ {
ui->setupUi(this); ui->setupUi(this);
} }
@ -11,5 +13,19 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; 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
}
}

15
MainWindow.h

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

2
main.cpp

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

Loading…
Cancel
Save