SVG5/dialogpowerbutton.cpp
2025-10-12 13:55:56 +09:00

97 lines
2.1 KiB
C++

#include "dialogpowerbutton.h"
#include "ui_dialogpowerbutton.h"
#include "mainwindow.h"
#include <QProcess>
#include <QKeyEvent>
DialogPowerButton::DialogPowerButton(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogPowerButton)
{
setAttribute(Qt::WA_TranslucentBackground);
//setWindowFlags(Qt::CustomizeWindowHint);
setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog | Qt::Popup);
ui->setupUi(this);
MainWindow* pMainWindow = MainWindow::GetMainWindow();
connect(this, SIGNAL(SendCaptureFootSwitch()), pMainWindow, SLOT(CaptureFootSwitch()));
ui->pushButton_shutdown->setVisible(false);
}
DialogPowerButton::~DialogPowerButton()
{
MainWindow* pMainWindow = MainWindow::GetMainWindow();
disconnect(this, SIGNAL(SendCaptureFootSwitch()), pMainWindow, SLOT(CaptureFootSwitch()));
delete ui;
}
void DialogPowerButton::on_pushButton_cancel_clicked()
{
done(QDialog::Rejected);
}
void DialogPowerButton::on_pushButton_shutdown_clicked()
{
//QProcess::execute("shutdown -P now");
QProcess process;
process.start("shutdown -P now");
process.waitForFinished();
}
void DialogPowerButton::on_pushButton_restart_clicked()
{
QProcess::execute("shutdown -r now");
}
void DialogPowerButton::paintEvent(QPaintEvent *event)
{
/*
QPainter painter(this);
QSize nSize = size();
int nPaddingLeft = 0;
QRect rectDisplay = QRect(nPaddingLeft, 0, nSize.width()-nPaddingLeft, nSize.height());
QColor colorBackground;
painter.setRenderHint(QPainter::SmoothPixmapTransform);
colorBackground = Qt::white;
if(m_pImageBackground!=NULL)
{
//painter.fillRect(QRect(0, 0, nSize.width(), nSize.height()), Qt::black);
painter.drawImage(rectDisplay, *m_pImageBackground);
painter.fillRect(QRect(0, 0, nSize.width(), nSize.height()), QColor(0, 0, 0, 128));
return;
}
*/
}
void DialogPowerButton::keyReleaseEvent(QKeyEvent *event)
{
int nKey = event->key();
if(nKey==Qt::Key_F10)
{
SendCaptureFootSwitch();
}
else if(nKey==Qt::Key_F11)
{
SendCaptureFootSwitch();
}
}