Merge pull request #24 from pepe82sh/master
Fixing issues with displays smaller than the window size
This commit is contained in:
@@ -23,6 +23,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||||
|
|
||||||
|
setAttribute(Qt::WA_AcceptTouchEvents);
|
||||||
|
|
||||||
QTimer::singleShot(5, this, SLOT(showFullScreen()));
|
QTimer::singleShot(5, this, SLOT(showFullScreen()));
|
||||||
QApplication::setOverrideCursor(Qt::BlankCursor);
|
QApplication::setOverrideCursor(Qt::BlankCursor);
|
||||||
QLabel *label = this->findChild<QLabel*>("image");
|
QLabel *label = this->findChild<QLabel*>("image");
|
||||||
@@ -47,6 +49,59 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
|
|||||||
QWidget::keyPressEvent(event);
|
QWidget::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isTouchEvent(const QEvent &event)
|
||||||
|
{
|
||||||
|
if(event.type() == QEvent::TouchBegin)
|
||||||
|
return true;
|
||||||
|
if(event.type() == QEvent::TouchUpdate)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isQuitCombination(const QTouchEvent &touchEvent)
|
||||||
|
{
|
||||||
|
bool topLeftTouched = false;
|
||||||
|
bool topRightTouched = false;
|
||||||
|
bool bottomLeftTouched = false;
|
||||||
|
bool bottomRightTouched = false;
|
||||||
|
for(const auto &touchPoint : touchEvent.touchPoints())
|
||||||
|
{
|
||||||
|
const qreal normalizedCornerSize = 0.1;
|
||||||
|
const qreal x = touchPoint.normalizedPos().x();
|
||||||
|
const qreal y = touchPoint.normalizedPos().y();
|
||||||
|
if(x < normalizedCornerSize)
|
||||||
|
{
|
||||||
|
if(y < normalizedCornerSize)
|
||||||
|
topLeftTouched = true;
|
||||||
|
else if(y > 1-normalizedCornerSize)
|
||||||
|
bottomLeftTouched = true;
|
||||||
|
}
|
||||||
|
else if(x > 1-normalizedCornerSize)
|
||||||
|
{
|
||||||
|
if(y < normalizedCornerSize)
|
||||||
|
topRightTouched = true;
|
||||||
|
else if(y > 1-normalizedCornerSize)
|
||||||
|
bottomRightTouched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return topLeftTouched && topRightTouched
|
||||||
|
&& bottomLeftTouched && bottomRightTouched;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::event(QEvent* event)
|
||||||
|
{
|
||||||
|
if(isTouchEvent(*event))
|
||||||
|
{
|
||||||
|
if(isQuitCombination(dynamic_cast<QTouchEvent&>(*event)))
|
||||||
|
QCoreApplication::quit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QMainWindow::event(event);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
QMainWindow::resizeEvent(event);
|
QMainWindow::resizeEvent(event);
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ class MainWindow : public QMainWindow
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
void keyPressEvent(QKeyEvent* event);
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void resizeEvent(QResizeEvent* event);
|
bool event(QEvent* event) override;
|
||||||
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
void setImage(std::string path);
|
void setImage(std::string path);
|
||||||
void setBlurRadius(unsigned int blurRadius);
|
void setBlurRadius(unsigned int blurRadius);
|
||||||
|
|||||||
Reference in New Issue
Block a user