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

simplify graphics scene initialization

This commit is contained in:
Nils Fenner 2015-10-10 17:39:59 +02:00
parent b5493178e7
commit 75ba20cb06
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 15 additions and 24 deletions

View File

@ -37,22 +37,24 @@
ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
: QObject(parent)
, scene(0)
{
scene = new QGraphicsScene;
window = new QGraphicsView (scene); // Top-level widget
setupWindow();
setupScene(scene);
window->setAttribute(Qt::WA_DeleteOnClose);
window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
window->setContentsMargins(0, 0, 0, 0);
window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
window->setFrameShape(QFrame::NoFrame);
window->installEventFilter(this);
setupScene();
installEventFilter(this);
}
void ScreenshotGrabber::reInit()
{
delete scene;
scene = new QGraphicsScene;
window = new QGraphicsView(scene); // Top-level widget
setupWindow();
setupScene(scene);
setupScene();
showGrabber();
blocked = false;
}
@ -120,28 +122,18 @@ void ScreenshotGrabber::acceptRegion()
if (rect.width() < 1 || rect.height() < 1)
return;
//
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
}
void ScreenshotGrabber::setupWindow()
void ScreenshotGrabber::setupScene()
{
this->window->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
this->window->setAttribute(Qt::WA_DeleteOnClose);
this->window->setContentsMargins(0, 0, 0, 0);
this->window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->window->setFrameShape(QFrame::NoFrame);
delete scene;
scene = new QGraphicsScene;
window->setScene(scene);
connect(this->window, &QObject::destroyed, this, &QObject::deleteLater);
this->window->installEventFilter(this);
}
void ScreenshotGrabber::setupScene(QGraphicsScene* scene)
{
this->overlay = new ScreenGrabberOverlayItem(this);
this->helperToolbox = new ToolBoxGraphicsItem;

View File

@ -58,8 +58,7 @@ private:
// for exception multiple handling during switching window
bool blocked = false;
void setupWindow();
void setupScene(QGraphicsScene* scene);
void setupScene();
void useNothingSelectedTooltip();
void useRegionSelectedTooltip();