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

View File

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