mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #3533
Nils Fenner (2): fix(screen-grabber): fix crash refactor(chatform): cleanup if block and use positive comparison
This commit is contained in:
commit
d1da8a9ba4
|
@ -67,7 +67,6 @@
|
||||||
|
|
||||||
ChatForm::ChatForm(Friend* chatFriend)
|
ChatForm::ChatForm(Friend* chatFriend)
|
||||||
: f(chatFriend)
|
: f(chatFriend)
|
||||||
, screenshotGrabber(nullptr)
|
|
||||||
, isTyping(false)
|
, isTyping(false)
|
||||||
{
|
{
|
||||||
Core* core = Core::getInstance();
|
Core* core = Core::getInstance();
|
||||||
|
@ -797,8 +796,8 @@ void ChatForm::onScreenshotClicked()
|
||||||
|
|
||||||
void ChatForm::doScreenshot()
|
void ChatForm::doScreenshot()
|
||||||
{
|
{
|
||||||
if (!screenshotGrabber)
|
// note: grabber is self-managed and will destroy itself when done
|
||||||
screenshotGrabber = new ScreenshotGrabber(this);
|
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber;
|
||||||
|
|
||||||
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken,
|
connect(screenshotGrabber, &ScreenshotGrabber::screenshotTaken,
|
||||||
this, &ChatForm::onScreenshotTaken);
|
this, &ChatForm::onScreenshotTaken);
|
||||||
|
@ -821,26 +820,22 @@ void ChatForm::onScreenshotTaken(const QPixmap &pixmap) {
|
||||||
|
|
||||||
QFile file(filepath);
|
QFile file(filepath);
|
||||||
|
|
||||||
if (!file.open(QFile::ReadWrite))
|
if (file.open(QFile::ReadWrite))
|
||||||
|
{
|
||||||
|
pixmap.save(&file, "PNG");
|
||||||
|
|
||||||
|
qint64 filesize = file.size();
|
||||||
|
file.close();
|
||||||
|
QFileInfo fi(file);
|
||||||
|
|
||||||
|
emit sendFile(f->getFriendID(), fi.fileName(), fi.filePath(), filesize);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this,
|
QMessageBox::warning(this,
|
||||||
tr("Failed to open temporary file", "Temporary file for screenshot"),
|
tr("Failed to open temporary file", "Temporary file for screenshot"),
|
||||||
tr("qTox wasn't able to save the screenshot"));
|
tr("qTox wasn't able to save the screenshot"));
|
||||||
|
|
||||||
delete screenshotGrabber;
|
|
||||||
screenshotGrabber = nullptr;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap.save(&file, "PNG");
|
|
||||||
|
|
||||||
qint64 filesize = file.size();
|
|
||||||
file.close();
|
|
||||||
QFileInfo fi(file);
|
|
||||||
|
|
||||||
emit sendFile(f->getFriendID(), fi.fileName(), fi.filePath(), filesize);
|
|
||||||
delete screenshotGrabber;
|
|
||||||
screenshotGrabber = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onLoadHistory()
|
void ChatForm::onLoadHistory()
|
||||||
|
|
|
@ -121,7 +121,6 @@ private:
|
||||||
QAction* loadHistoryAction;
|
QAction* loadHistoryAction;
|
||||||
QAction* copyStatusAction;
|
QAction* copyStatusAction;
|
||||||
|
|
||||||
ScreenshotGrabber* screenshotGrabber;
|
|
||||||
QHash<uint, FileTransferInstance*> ftransWidgets;
|
QHash<uint, FileTransferInstance*> ftransWidgets;
|
||||||
CallConfirmWidget *callConfirm;
|
CallConfirmWidget *callConfirm;
|
||||||
bool isTyping;
|
bool isTyping;
|
||||||
|
|
|
@ -158,7 +158,8 @@ void AVForm::on_videoModescomboBox_currentIndexChanged(int index)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber(this);
|
// note: grabber is self-managed and will destroy itself when done
|
||||||
|
ScreenshotGrabber* screenshotGrabber = new ScreenshotGrabber;
|
||||||
|
|
||||||
auto onGrabbed = [screenshotGrabber, devName, this] (QRect region)
|
auto onGrabbed = [screenshotGrabber, devName, this] (QRect region)
|
||||||
{
|
{
|
||||||
|
@ -170,7 +171,6 @@ void AVForm::on_videoModescomboBox_currentIndexChanged(int index)
|
||||||
Settings::getInstance().setScreenGrabbed(true);
|
Settings::getInstance().setScreenGrabbed(true);
|
||||||
|
|
||||||
open(devName, mode);
|
open(devName, mode);
|
||||||
delete screenshotGrabber;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(screenshotGrabber, &ScreenshotGrabber::regionChosen, this, onGrabbed, Qt::QueuedConnection);
|
connect(screenshotGrabber, &ScreenshotGrabber::regionChosen, this, onGrabbed, Qt::QueuedConnection);
|
||||||
|
|
|
@ -35,14 +35,13 @@
|
||||||
#include "toolboxgraphicsitem.h"
|
#include "toolboxgraphicsitem.h"
|
||||||
#include "src/widget/widget.h"
|
#include "src/widget/widget.h"
|
||||||
|
|
||||||
ScreenshotGrabber::ScreenshotGrabber(QObject* parent)
|
ScreenshotGrabber::ScreenshotGrabber()
|
||||||
: QObject(parent)
|
: QObject()
|
||||||
, mKeysBlocked(false)
|
, mKeysBlocked(false)
|
||||||
, scene(0)
|
, scene(0)
|
||||||
, mQToxVisible(true)
|
, mQToxVisible(true)
|
||||||
{
|
{
|
||||||
window = new QGraphicsView (scene); // Top-level widget
|
window = new QGraphicsView (scene); // Top-level widget
|
||||||
window->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
|
window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
|
||||||
window->setContentsMargins(0, 0, 0, 0);
|
window->setContentsMargins(0, 0, 0, 0);
|
||||||
window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
@ -71,6 +70,7 @@ void ScreenshotGrabber::reInit()
|
||||||
ScreenshotGrabber::~ScreenshotGrabber()
|
ScreenshotGrabber::~ScreenshotGrabber()
|
||||||
{
|
{
|
||||||
delete scene;
|
delete scene;
|
||||||
|
delete window;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenshotGrabber::eventFilter(QObject* object, QEvent* event)
|
bool ScreenshotGrabber::eventFilter(QObject* object, QEvent* event)
|
||||||
|
@ -134,9 +134,10 @@ void ScreenshotGrabber::acceptRegion()
|
||||||
emit regionChosen(rect);
|
emit regionChosen(rect);
|
||||||
qDebug() << "Screenshot accepted, chosen region" << rect;
|
qDebug() << "Screenshot accepted, chosen region" << rect;
|
||||||
QPixmap pixmap = this->screenGrab.copy(rect);
|
QPixmap pixmap = this->screenGrab.copy(rect);
|
||||||
this->window->close();
|
|
||||||
restoreHiddenWindows();
|
restoreHiddenWindows();
|
||||||
emit screenshotTaken(pixmap);
|
emit screenshotTaken(pixmap);
|
||||||
|
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenshotGrabber::setupScene()
|
void ScreenshotGrabber::setupScene()
|
||||||
|
@ -210,9 +211,8 @@ void ScreenshotGrabber::adjustTooltipPosition()
|
||||||
|
|
||||||
void ScreenshotGrabber::reject()
|
void ScreenshotGrabber::reject()
|
||||||
{
|
{
|
||||||
qDebug() << "Rejected screenshot";
|
|
||||||
this->window->close();
|
|
||||||
restoreHiddenWindows();
|
restoreHiddenWindows();
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap ScreenshotGrabber::grabScreen()
|
QPixmap ScreenshotGrabber::grabScreen()
|
||||||
|
|
|
@ -39,7 +39,7 @@ class ScreenshotGrabber : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit ScreenshotGrabber(QObject* parent);
|
ScreenshotGrabber();
|
||||||
~ScreenshotGrabber() override;
|
~ScreenshotGrabber() override;
|
||||||
|
|
||||||
bool eventFilter(QObject* object, QEvent* event) override;
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user