Fix a few screen capture bugs for some multiconfig

Thanks to @lclc98 we worked around a bug in Qt<5.9 and made KShare work on weird multi monitor configurations where they for example overlap, also screens are now in proper positions despite what order they are in xrandr, for example.

Thanks again to @lclc98!
This commit is contained in:
ArsenArsen 2017-07-03 15:43:28 +02:00
parent bb6b41f762
commit fcf5ac0269
6 changed files with 20 additions and 16 deletions

View File

@ -32,12 +32,13 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
color = pItem->pixmap().toImage().pixelColor(QCursor::pos()); color = pItem->pixmap().toImage().pixelColor(QCursor::pos());
text->setPlainText(color.name()); text->setPlainText(color.name());
ellipse->setBrush(color); ellipse->setBrush(color);
image = pixmap.toImage();
show(); show();
} }
void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
color = pItem->pixmap().toImage().pixelColor(event->scenePos().toPoint()); color = image.pixelColor(event->scenePos().toPoint());
text->setPlainText(color.name()); text->setPlainText(color.name());
ellipse->setBrush(color); ellipse->setBrush(color);
@ -61,9 +62,6 @@ void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
ellipse->setRect(QRectF(scopePoint, QSize(20, 20))); ellipse->setRect(QRectF(scopePoint, QSize(20, 20)));
text->setPos(resPoint); text->setPos(resPoint);
textBackground->setPos(text->pos()); textBackground->setPos(text->pos());
// How does this work? I have no clue....
// I mean.. It kinda makes sense when you look through it carefully
// But it's still a mess.
} }
void ColorPickerScene::keyPressEvent(QKeyEvent *event) { void ColorPickerScene::keyPressEvent(QKeyEvent *event) {

View File

@ -17,10 +17,11 @@ public:
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
static void showPicker() { static void showPicker() {
ColorPickerScene(screenshotutil::fullscreen(), 0); new ColorPickerScene(screenshotutil::fullscreen(), 0);
} }
private: private:
QImage image;
QColor color; QColor color;
QGraphicsEllipseItem *ellipse = 0; QGraphicsEllipseItem *ellipse = 0;
QGraphicsPixmapItem *pItem = 0; QGraphicsPixmapItem *pItem = 0;

View File

@ -211,7 +211,7 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
if (drawingSelection) if (drawingSelection)
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; }); if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
} else if (settings::settings().value("quickMode", false).toBool()) } else if (settings::settings().value("quickMode", false).toBool())
done(); done(true);
prevButtons = Qt::NoButton; prevButtons = Qt::NoButton;
} }
@ -257,7 +257,8 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) {
} }
void CropScene::keyReleaseEvent(QKeyEvent *event) { void CropScene::keyReleaseEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Escape) done(); if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter || event->key() == Qt::Key_Escape)
done(event->key() != Qt::Key_Escape);
} }
void CropScene::updateMag(QPointF scenePos) { void CropScene::updateMag(QPointF scenePos) {
@ -311,8 +312,8 @@ void CropScene::initMagnifierGrid() {
} }
} }
void CropScene::done() { void CropScene::done(bool notEsc) {
if (rect) { if (notEsc && rect) {
rect->setPen(QPen(Qt::NoPen)); rect->setPen(QPen(Qt::NoPen));
magnifier->setVisible(false); magnifier->setVisible(false);
magnifierBox->setVisible(false); magnifierBox->setVisible(false);

View File

@ -54,7 +54,7 @@ private:
void updateMag(QPointF scenePos); void updateMag(QPointF scenePos);
void initMagnifierGrid(); void initMagnifierGrid();
void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item); void addDrawingAction(QMenu &menu, QString name, std::function<DrawItem *()> item);
void done(); void done(bool notEsc);
bool fullscreen; bool fullscreen;
std::function<DrawItem *()> drawingSelectionMaker; std::function<DrawItem *()> drawingSelectionMaker;
QFlags<Qt::MouseButton> prevButtons; QFlags<Qt::MouseButton> prevButtons;

View File

@ -80,7 +80,7 @@
</widget> </widget>
<widget class="QMenu" name="menuRecording"> <widget class="QMenu" name="menuRecording">
<property name="title"> <property name="title">
<string>Recording</string> <string>&amp;Recording</string>
</property> </property>
<addaction name="actionStart"/> <addaction name="actionStart"/>
<addaction name="actionStop"/> <addaction name="actionStop"/>

View File

@ -2,6 +2,7 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QDebug>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QScreen> #include <QScreen>
@ -10,9 +11,9 @@
QPixmap screenshotutil::fullscreen(bool cursor) { QPixmap screenshotutil::fullscreen(bool cursor) {
int height = 0, width = 0; int height = 0, width = 0;
for (QScreen *screen : QApplication::screens()) { for (QScreen *screen : QApplication::screens()) {
width += screen->size().width(); QRect geo = screen->geometry();
int h = screen->size().height(); width = qMax(geo.right() + geo.width(), width);
height = h > height ? h : height; height = qMax(geo.bottom() + geo.height(), height);
} }
QPixmap image(width, height); QPixmap image(width, height);
image.fill(Qt::transparent); image.fill(Qt::transparent);
@ -20,7 +21,10 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
width = 0; width = 0;
for (QScreen *screen : QApplication::screens()) { for (QScreen *screen : QApplication::screens()) {
QPixmap currentScreen = window(0, screen); QPixmap currentScreen = window(0, screen);
painter.drawPixmap(width, 0, currentScreen); // Hack for https://bugreports.qt.io/browse/QTBUG-58110
QStringList qVer = QString(qVersion()).split('.');
if (qVer.at(0).toInt() == 5 && qVer.at(1).toInt() < 9) currentScreen = currentScreen.copy(screen->geometry());
painter.drawPixmap(screen->geometry().topLeft(), currentScreen);
width += screen->size().width(); width += screen->size().width();
} }
#ifdef PLATFORM_CAPABILITY_CURSOR #ifdef PLATFORM_CAPABILITY_CURSOR
@ -28,8 +32,8 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
auto cursorData = PlatformBackend::inst().getCursor(); auto cursorData = PlatformBackend::inst().getCursor();
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData)); painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
} }
painter.end();
#endif #endif
painter.end();
return image; return image;
} }