Rename utils and fix some stuff in CropScene

This commit is contained in:
ArsenArsen 2017-11-23 20:33:49 +01:00
parent 0085c7d98f
commit 56317bb7ee
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
15 changed files with 70 additions and 60 deletions

View File

@ -43,7 +43,7 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
activateWindow(); activateWindow();
setGeometry(pixmap.rect()); setGeometry(pixmap.rect());
QPoint p = screenshotutil::smallestScreenCoordinate() QPoint p = utils::smallestScreenCoordinate()
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt()); + QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
move(p.x(), p.y()); move(p.x(), p.y());
} }

View File

@ -8,7 +8,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <QTimer> #include <QTimer>
#include <screenoverlayview.hpp> #include <screenoverlayview.hpp>
#include <screenshotutil.hpp> #include <utils.hpp>
class ColorPickerScene : public QGraphicsScene, public ScreenOverlayView { class ColorPickerScene : public QGraphicsScene, public ScreenOverlayView {
Q_DECLARE_TR_FUNCTIONS(ColorPickerScene) Q_DECLARE_TR_FUNCTIONS(ColorPickerScene)
@ -18,7 +18,7 @@ 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() {
new ColorPickerScene(screenshotutil::fullscreen()); new ColorPickerScene(utils::fullscreen());
} }
private: private:

View File

@ -7,8 +7,8 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QScreen> #include <QScreen>
#include <QTimer> #include <QTimer>
#include <screenshotutil.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <utils.hpp>
CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) { CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
scene = new CropScene(parent, image); scene = new CropScene(parent, image);
@ -24,7 +24,7 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
scene->setSceneRect(image.rect()); scene->setSceneRect(image.rect());
view->resize(image.width(), image.height()); view->resize(image.width(), image.height());
view->setMinimumSize(image.size()); view->setMinimumSize(image.size());
QPoint p = screenshotutil::smallestScreenCoordinate() QPoint p = utils::smallestScreenCoordinate()
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt()); + QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
view->move(p.x(), p.y()); view->move(p.x(), p.y());
view->setWindowTitle(tr("KShare Crop Editor")); view->setWindowTitle(tr("KShare Crop Editor"));

View File

@ -1,3 +1,4 @@
// vim: set sw=4 tw=4 :
#include "cropscene.hpp" #include "cropscene.hpp"
#include "selectionrectangle.hpp" #include "selectionrectangle.hpp"
#include <QApplication> #include <QApplication>
@ -228,8 +229,8 @@ void CropScene::setVisible(bool visible) {
view->setVisible(visible); view->setVisible(visible);
if (visible) { if (visible) {
if (QApplication::screens().size() == 1) view->showFullScreen(); if (QApplication::screens().size() == 1) view->showFullScreen();
QPoint p = screenshotutil::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(), QPoint p = utils::smallestScreenCoordinate() + QPoint(settings::settings().value("cropx", 0).toInt(),
settings::settings().value("cropy", 0).toInt()); settings::settings().value("cropy", 0).toInt());
view->move(p.x(), p.y()); view->move(p.x(), p.y());
view->setWindowTitle(tr("KShare Crop Editor")); view->setWindowTitle(tr("KShare Crop Editor"));
view->activateWindow(); view->activateWindow();
@ -389,16 +390,6 @@ void CropScene::keyReleaseEvent(QKeyEvent *event) {
if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::keyReleaseEvent(event); if (!(event->modifiers() & Qt::ControlModifier)) QGraphicsScene::keyReleaseEvent(event);
} }
QPixmap extend(QPixmap img, QColor hl) {
QPixmap newImg(img.width() + 42, img.height() + 42);
QColor filler(255 - hl.red(), 255 - hl.green(), 255 - hl.blue());
newImg.fill(filler);
QPainter ptr(&newImg);
ptr.drawPixmap(21, 21, img);
ptr.end();
return newImg;
}
void CropScene::updateMag() { void CropScene::updateMag() {
QString rectStr("(-1, -1, 0, 0)"); QString rectStr("(-1, -1, 0, 0)");
if (rect) { if (rect) {
@ -414,7 +405,9 @@ void CropScene::updateMag() {
QPointF magnifierPos = cursorPos + QPointF(5, 5); QPointF magnifierPos = cursorPos + QPointF(5, 5);
magnifier->setPos(magnifierPos); magnifier->setPos(magnifierPos);
magnifier->setPixmap(extend(_pixmap, highlight()).copy(magnifierTopLeft.x() + 22, magnifierTopLeft.y() + 22, pixCnt, pixCnt).scaled(110, 110)); magnifier->setPixmap(utils::extend(_pixmap, pixCnt, utils::invertColor(highlight()))
.copy(magnifierTopLeft.x() + pixCnt, magnifierTopLeft.y() + pixCnt, pixCnt, pixCnt)
.scaled(110, 110));
QPointF bottomRight = magnifierHintBox->sceneBoundingRect().bottomRight(); QPointF bottomRight = magnifierHintBox->sceneBoundingRect().bottomRight();
if (magnifier->sceneBoundingRect().bottom() > bottomRight.y()) if (magnifier->sceneBoundingRect().bottom() > bottomRight.y())
bottomRight.setY(magnifier->sceneBoundingRect().bottom()); bottomRight.setY(magnifier->sceneBoundingRect().bottom());

View File

@ -11,7 +11,7 @@
#include <cropeditor/selectionrectangle.hpp> #include <cropeditor/selectionrectangle.hpp>
#include <functional> #include <functional>
#include <screenoverlayview.hpp> #include <screenoverlayview.hpp>
#include <screenshotutil.hpp> #include <utils.hpp>
class CropScene; class CropScene;
#include <cropeditor/drawing/drawitem.hpp> #include <cropeditor/drawing/drawitem.hpp>
@ -107,19 +107,19 @@ private:
QList<QGraphicsRectItem *> gridRectsY; QList<QGraphicsRectItem *> gridRectsY;
QGraphicsPolygonItem *cursorItem = nullptr; QGraphicsPolygonItem *cursorItem = nullptr;
QGraphicsPixmapItem *hint QGraphicsPixmapItem *hint
= new QGraphicsPixmapItem(screenshotutil::renderText(tr( // = new QGraphicsPixmapItem(utils::renderText(tr( //
"Press F1 to toggle this hint\n" "Press F1 to toggle this hint\n"
"\tHold Shift to slow the cursor down\n" "\tHold Shift to slow the cursor down\n"
"\tCtrl+Drag a thing to move it around\n" "\tCtrl+Drag a thing to move it around\n"
"\tAlt+Click a drawing to remove it\n" "\tAlt+Click a drawing to remove it\n"
"\tPress Return/Enter to finish\n" "\tPress Return/Enter to finish\n"
"\tPress ESC to cancel\n" "\tPress ESC to cancel\n"
"\tUse the menu bar to draw\n" "\tUse the menu bar to draw\n"
"\tNOTE: You must select 'Crop' before closing the editor\n" "\tNOTE: You must select 'Crop' before closing the editor\n"
"\tIf you do not it will not close."), "\tIf you do not it will not close."),
5, 5,
QColor(0, 0, 0, 125), QColor(0, 0, 0, 125),
Qt::white)); Qt::white));
}; };
#endif // CROPSCENE_HPP #endif // CROPSCENE_HPP

View File

@ -19,7 +19,6 @@ void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(scene->highlight()), Qt::NoBrush); rect = scene->addRect(QRect(scene->cursorPosition().toPoint(), QSize(1, 1)), QPen(scene->highlight()), Qt::NoBrush);
pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect())); pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
pixmap->setPos(scene->cursorPosition()); pixmap->setPos(scene->cursorPosition());
pixmap->setZValue(rect->zValue() - 0.1);
pixmap->setGraphicsEffect(effect); pixmap->setGraphicsEffect(effect);
} else { } else {
QPointF p = scene->cursorPosition(); QPointF p = scene->cursorPosition();

View File

@ -35,6 +35,8 @@ void HotkeyInputDialog::keyPressEvent(QKeyEvent *e) {
void HotkeyInputDialog::on_recordButton_clicked() { void HotkeyInputDialog::on_recordButton_clicked() {
recording = !recording; recording = !recording;
ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record")); ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record"));
if (recording) grabKeyboard(); if (recording)
else releaseKeyboard(); grabKeyboard();
else
releaseKeyboard();
} }

View File

@ -1,5 +1,4 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "screenshotutil.hpp"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>

View File

@ -1,9 +1,9 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "aboutbox.hpp" #include "aboutbox.hpp"
#include "screenshotter.hpp" #include "screenshotter.hpp"
#include "screenshotutil.hpp"
#include "settingsdialog.hpp" #include "settingsdialog.hpp"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "utils.hpp"
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QShortcut> #include <QShortcut>

View File

@ -5,10 +5,10 @@
#include <iostream> #include <iostream>
#include <mainwindow.hpp> #include <mainwindow.hpp>
#include <screenareaselector/screenareaselector.hpp> #include <screenareaselector/screenareaselector.hpp>
#include <screenshotutil.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <stdio.h> #include <stdio.h>
#include <uploaders/uploadersingleton.hpp> #include <uploaders/uploadersingleton.hpp>
#include <utils.hpp>
#include <worker/worker.hpp> #include <worker/worker.hpp>
RecordingController::RecordingController() : timer(this) { RecordingController::RecordingController() : timer(this) {
@ -102,8 +102,8 @@ void RecordingController::timeout() {
time++; time++;
int localTime = time * timer.interval() - 3000; int localTime = time * timer.interval() - 3000;
if (localTime > 0) { if (localTime > 0) {
QPixmap pp = screenshotutil::fullscreenArea(settings::settings().value("captureCursor", true).toBool(), QPixmap pp = utils::fullscreenArea(settings::settings().value("captureCursor", true).toBool(), area.x(),
area.x(), area.y(), area.width(), area.height()); area.y(), area.width(), area.height());
WorkerContext *context = new WorkerContext; WorkerContext *context = new WorkerContext;
context->consumer = _context->consumer; context->consumer = _context->consumer;
context->targetFormat = _context->format; context->targetFormat = _context->format;

View File

@ -1,20 +1,20 @@
#include "screenshotter.hpp" #include "screenshotter.hpp"
#include "cropeditor/cropeditor.hpp" #include "cropeditor/cropeditor.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "screenshotutil.hpp"
#include "uploaders/uploadersingleton.hpp" #include "uploaders/uploadersingleton.hpp"
#include "utils.hpp"
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QTimer> #include <QTimer>
#include <platformbackend.hpp> #include <platformbackend.hpp>
#include <settings.hpp> #include <settings.hpp>
void screenshotter::area() { void screenshotter::area() {
CropEditor *editor = new CropEditor(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool())); CropEditor *editor = new CropEditor(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); }); QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); });
} }
void screenshotter::fullscreen() { void screenshotter::fullscreen() {
UploaderSingleton::inst().upload(screenshotutil::fullscreen(settings::settings().value("captureCursor", true).toBool())); UploaderSingleton::inst().upload(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
} }
void screenshotter::areaDelayed() { void screenshotter::areaDelayed() {
@ -31,6 +31,6 @@ void screenshotter::activeDelayed() {
void screenshotter::active() { void screenshotter::active() {
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW #ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
UploaderSingleton::inst().upload(screenshotutil::window(PlatformBackend::inst().getActiveWID())); UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID()));
#endif #endif
} }

View File

@ -30,7 +30,7 @@ SOURCES += main.cpp\
cropeditor/cropscene.cpp \ cropeditor/cropscene.cpp \
uploaders/uploadersingleton.cpp \ uploaders/uploadersingleton.cpp \
screenshotter.cpp \ screenshotter.cpp \
screenshotutil.cpp \ utils.cpp \
uploaders/default/imguruploader.cpp \ uploaders/default/imguruploader.cpp \
io/ioutils.cpp \ io/ioutils.cpp \
settings.cpp \ settings.cpp \
@ -77,7 +77,7 @@ HEADERS += mainwindow.hpp \
uploaders/uploader.hpp \ uploaders/uploader.hpp \
uploaders/uploadersingleton.hpp \ uploaders/uploadersingleton.hpp \
screenshotter.hpp \ screenshotter.hpp \
screenshotutil.hpp \ utils.hpp \
uploaders/default/imguruploader.hpp \ uploaders/default/imguruploader.hpp \
io/ioutils.hpp \ io/ioutils.hpp \
settings.hpp \ settings.hpp \

View File

@ -8,8 +8,8 @@
#include <formats.hpp> #include <formats.hpp>
#include <io/ioutils.hpp> #include <io/ioutils.hpp>
#include <notifications.hpp> #include <notifications.hpp>
#include <screenshotutil.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <utils.hpp>
struct SegfaultWorkaround { // I'm a scrub for doing this struct SegfaultWorkaround { // I'm a scrub for doing this
SegfaultWorkaround(QByteArray a, ImgurUploader *u, QString m) : byteArray(), dis(u), mime(m) { SegfaultWorkaround(QByteArray a, ImgurUploader *u, QString m) : byteArray(), dis(u), mime(m) {
@ -49,7 +49,7 @@ private:
QByteArray byteArray; QByteArray byteArray;
ImgurUploader *dis; ImgurUploader *dis;
QString mime; QString mime;
}; }; // I feel terrible for making this. I am sorry, reader
void ImgurUploader::doUpload(QByteArray byteArray, QString format) { void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
if (byteArray.size() > 1e+7) { if (byteArray.size() > 1e+7) {
@ -88,7 +88,7 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray)
return; return;
} }
if (!result.isEmpty()) { if (!result.isEmpty()) {
screenshotutil::toClipboard(result); utils::toClipboard(result);
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!")); notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
} else { } else {
notifications::notify(tr("KShare imgur Uploader "), notifications::notify(tr("KShare imgur Uploader "),

View File

@ -1,4 +1,4 @@
#include "screenshotutil.hpp" #include "utils.hpp"
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
@ -8,7 +8,21 @@
#include <QScreen> #include <QScreen>
#include <platformbackend.hpp> #include <platformbackend.hpp>
QPixmap screenshotutil::fullscreen(bool cursor) {
QColor utils::invertColor(QColor color) {
return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue());
}
QPixmap utils::extend(QPixmap img, int extraSize, QColor hl) {
QPixmap newImg(img.width() + extraSize * 2, img.height() + extraSize * 2);
newImg.fill(hl);
QPainter ptr(&newImg);
ptr.drawPixmap(extraSize, extraSize, img);
ptr.end();
return newImg;
}
QPixmap utils::fullscreen(bool cursor) {
QPixmap image; QPixmap image;
QPainter painter; QPainter painter;
QPoint smallestCoordinate = smallestScreenCoordinate(); QPoint smallestCoordinate = smallestScreenCoordinate();
@ -54,19 +68,19 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
return image; return image;
} }
QPixmap screenshotutil::window(WId wid, QScreen *w) { QPixmap utils::window(WId wid, QScreen *w) {
return w->grabWindow(wid); return w->grabWindow(wid);
} }
void screenshotutil::toClipboard(QString value) { void utils::toClipboard(QString value) {
QApplication::clipboard()->setText(value); QApplication::clipboard()->setText(value);
} }
QPixmap screenshotutil::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) { QPixmap utils::fullscreenArea(bool cursor, qreal x, qreal y, qreal w, qreal h) {
return fullscreen(cursor).copy(x, y, w, h); return fullscreen(cursor).copy(x, y, w, h);
} }
QPoint screenshotutil::smallestScreenCoordinate() { QPoint utils::smallestScreenCoordinate() {
QPoint smallestCoordinate; QPoint smallestCoordinate;
for (QScreen *screen : QApplication::screens()) { for (QScreen *screen : QApplication::screens()) {
smallestCoordinate.rx() = qMin(smallestCoordinate.x(), screen->geometry().left()); smallestCoordinate.rx() = qMin(smallestCoordinate.x(), screen->geometry().left());
@ -75,7 +89,7 @@ QPoint screenshotutil::smallestScreenCoordinate() {
return smallestCoordinate; return smallestCoordinate;
} }
QPixmap screenshotutil::renderText(QString toRender, int padding, QColor background, QColor pen, QFont font) { QPixmap utils::renderText(QString toRender, int padding, QColor background, QColor pen, QFont font) {
QFontMetrics metric(font); QFontMetrics metric(font);
QStringList lines = toRender.replace("\r", "").split('\n'); QStringList lines = toRender.replace("\r", "").split('\n');
QSize resultingSize(0, padding * 2); QSize resultingSize(0, padding * 2);

View File

@ -1,10 +1,13 @@
#ifndef SCREENSHOTUTIL_HPP #ifndef UTILS_HPP
#define SCREENSHOTUTIL_HPP #define UTILS_HPP
#include <QApplication> #include <QApplication>
#include <QPixmap>
#include <QWidget> #include <QWidget>
namespace screenshotutil { namespace utils {
QColor invertColor(QColor color);
QPixmap extend(QPixmap pixmap, int extraSize = 25, QColor hl = Qt::transparent);
QPixmap fullscreen(bool cursor = true); QPixmap fullscreen(bool cursor = true);
QPixmap fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1); QPixmap fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1);
QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen()); QPixmap window(WId wid, QScreen *w = QApplication::primaryScreen());
@ -14,4 +17,4 @@ namespace screenshotutil {
renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont()); renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont());
} }
#endif // SCREENSHOTUTIL_HPP #endif // UTILS_HPP