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

View File

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