1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix hide/restore qTox windows with space key

This commit is contained in:
Nils Fenner 2015-10-10 17:54:56 +02:00
parent 6e383fa0f1
commit 073d4f0ad3
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 18 additions and 17 deletions

View File

@ -37,6 +37,7 @@
ScreenshotGrabber::ScreenshotGrabber(QObject* parent) ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
: QObject(parent) : QObject(parent)
, mKeysBlocked(false)
, scene(0) , scene(0)
, mQToxVisible(true) , mQToxVisible(true)
{ {
@ -55,9 +56,10 @@ ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
void ScreenshotGrabber::reInit() void ScreenshotGrabber::reInit()
{ {
window->resetCachedContent();
setupScene(); setupScene();
showGrabber(); showGrabber();
blocked = false; mKeysBlocked = false;
} }
ScreenshotGrabber::~ScreenshotGrabber() ScreenshotGrabber::~ScreenshotGrabber()
@ -93,23 +95,23 @@ void ScreenshotGrabber::showGrabber()
bool ScreenshotGrabber::handleKeyPress(QKeyEvent* event) bool ScreenshotGrabber::handleKeyPress(QKeyEvent* event)
{ {
if (mKeysBlocked)
return false;
if (event->key() == Qt::Key_Escape) if (event->key() == Qt::Key_Escape)
reject(); reject();
else if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) else if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
acceptRegion(); acceptRegion();
else if (event->key() == Qt::Key_Space && !blocked) // hide/show qTox window else if (event->key() == Qt::Key_Space) {
{ mKeysBlocked = true;
Widget *Widget = Widget::getInstance();
blocked = true;
if (Widget->isVisible())
Widget->setVisible(false);
else
Widget->setVisible(true);
this->window->setVisible(false);
this->window->resetCachedContent();
// Give the window manager a moment to hide windows
QTimer::singleShot(350, this, SLOT(reInit()));
if (mQToxVisible)
hideVisibleWindows();
else
restoreHiddenWindows();
window->hide();
QTimer::singleShot(350, this, &ScreenshotGrabber::reInit);
} }
else else
return false; return false;
@ -126,7 +128,7 @@ void ScreenshotGrabber::acceptRegion()
qDebug() << "Screenshot accepted, chosen region" << rect; qDebug() << "Screenshot accepted, chosen region" << rect;
emit screenshotTaken(this->screenGrab.copy(rect)); emit screenshotTaken(this->screenGrab.copy(rect));
this->window->close(); this->window->close();
Widget::getInstance()->setVisible(true); // show window if it was hidden restoreHiddenWindows();
} }
void ScreenshotGrabber::setupScene() void ScreenshotGrabber::setupScene()
@ -195,7 +197,7 @@ void ScreenshotGrabber::reject()
{ {
qDebug() << "Rejected screenshot"; qDebug() << "Rejected screenshot";
this->window->close(); this->window->close();
Widget::getInstance()->setVisible(true); // show window if it was hidden restoreHiddenWindows();
} }
QPixmap ScreenshotGrabber::grabScreen() QPixmap ScreenshotGrabber::grabScreen()

View File

@ -56,8 +56,7 @@ signals:
private: private:
friend class ScreenGrabberOverlayItem; friend class ScreenGrabberOverlayItem;
// for exception multiple handling during switching window bool mKeysBlocked;
bool blocked = false;
void setupScene(); void setupScene();