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());
text->setPlainText(color.name());
ellipse->setBrush(color);
image = pixmap.toImage();
show();
}
void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
color = pItem->pixmap().toImage().pixelColor(event->scenePos().toPoint());
color = image.pixelColor(event->scenePos().toPoint());
text->setPlainText(color.name());
ellipse->setBrush(color);
@ -61,9 +62,6 @@ void ColorPickerScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
ellipse->setRect(QRectF(scopePoint, QSize(20, 20)));
text->setPos(resPoint);
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) {

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QPainter>
#include <QPixmap>
#include <QScreen>
@ -10,9 +11,9 @@
QPixmap screenshotutil::fullscreen(bool cursor) {
int height = 0, width = 0;
for (QScreen *screen : QApplication::screens()) {
width += screen->size().width();
int h = screen->size().height();
height = h > height ? h : height;
QRect geo = screen->geometry();
width = qMax(geo.right() + geo.width(), width);
height = qMax(geo.bottom() + geo.height(), height);
}
QPixmap image(width, height);
image.fill(Qt::transparent);
@ -20,7 +21,10 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
width = 0;
for (QScreen *screen : QApplication::screens()) {
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();
}
#ifdef PLATFORM_CAPABILITY_CURSOR
@ -28,8 +32,8 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
auto cursorData = PlatformBackend::inst().getCursor();
painter.drawPixmap(QCursor::pos() - std::get<0>(cursorData), std::get<1>(cursorData));
}
painter.end();
#endif
painter.end();
return image;
}