Rename utils and fix some stuff in CropScene
This commit is contained in:
parent
0085c7d98f
commit
56317bb7ee
@ -43,7 +43,7 @@ ColorPickerScene::ColorPickerScene(QPixmap pixmap, QWidget *parentWidget)
|
||||
|
||||
activateWindow();
|
||||
setGeometry(pixmap.rect());
|
||||
QPoint p = screenshotutil::smallestScreenCoordinate()
|
||||
QPoint p = utils::smallestScreenCoordinate()
|
||||
+ QPoint(settings::settings().value("cropx", 0).toInt(), settings::settings().value("cropy", 0).toInt());
|
||||
move(p.x(), p.y());
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QTimer>
|
||||
#include <screenoverlayview.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <utils.hpp>
|
||||
|
||||
class ColorPickerScene : public QGraphicsScene, public ScreenOverlayView {
|
||||
Q_DECLARE_TR_FUNCTIONS(ColorPickerScene)
|
||||
@ -18,7 +18,7 @@ public:
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override;
|
||||
static void showPicker() {
|
||||
new ColorPickerScene(screenshotutil::fullscreen());
|
||||
new ColorPickerScene(utils::fullscreen());
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QScreen>
|
||||
#include <QTimer>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <settings.hpp>
|
||||
#include <utils.hpp>
|
||||
|
||||
CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
|
||||
scene = new CropScene(parent, image);
|
||||
@ -24,7 +24,7 @@ CropEditor::CropEditor(QPixmap image, QObject *parent) : QObject(parent) {
|
||||
scene->setSceneRect(image.rect());
|
||||
view->resize(image.width(), image.height());
|
||||
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());
|
||||
view->move(p.x(), p.y());
|
||||
view->setWindowTitle(tr("KShare Crop Editor"));
|
||||
|
@ -1,3 +1,4 @@
|
||||
// vim: set sw=4 tw=4 :
|
||||
#include "cropscene.hpp"
|
||||
#include "selectionrectangle.hpp"
|
||||
#include <QApplication>
|
||||
@ -228,7 +229,7 @@ void CropScene::setVisible(bool visible) {
|
||||
view->setVisible(visible);
|
||||
if (visible) {
|
||||
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());
|
||||
view->move(p.x(), p.y());
|
||||
view->setWindowTitle(tr("KShare Crop Editor"));
|
||||
@ -389,16 +390,6 @@ void CropScene::keyReleaseEvent(QKeyEvent *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() {
|
||||
QString rectStr("(-1, -1, 0, 0)");
|
||||
if (rect) {
|
||||
@ -414,7 +405,9 @@ void CropScene::updateMag() {
|
||||
QPointF magnifierPos = cursorPos + QPointF(5, 5);
|
||||
|
||||
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();
|
||||
if (magnifier->sceneBoundingRect().bottom() > bottomRight.y())
|
||||
bottomRight.setY(magnifier->sceneBoundingRect().bottom());
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <cropeditor/selectionrectangle.hpp>
|
||||
#include <functional>
|
||||
#include <screenoverlayview.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <utils.hpp>
|
||||
class CropScene;
|
||||
|
||||
#include <cropeditor/drawing/drawitem.hpp>
|
||||
@ -107,7 +107,7 @@ private:
|
||||
QList<QGraphicsRectItem *> gridRectsY;
|
||||
QGraphicsPolygonItem *cursorItem = nullptr;
|
||||
QGraphicsPixmapItem *hint
|
||||
= new QGraphicsPixmapItem(screenshotutil::renderText(tr( //
|
||||
= new QGraphicsPixmapItem(utils::renderText(tr( //
|
||||
"Press F1 to toggle this hint\n"
|
||||
"\tHold Shift to slow the cursor down\n"
|
||||
"\tCtrl+Drag a thing to move it around\n"
|
||||
|
@ -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);
|
||||
pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
|
||||
pixmap->setPos(scene->cursorPosition());
|
||||
pixmap->setZValue(rect->zValue() - 0.1);
|
||||
pixmap->setGraphicsEffect(effect);
|
||||
} else {
|
||||
QPointF p = scene->cursorPosition();
|
||||
|
@ -35,6 +35,8 @@ void HotkeyInputDialog::keyPressEvent(QKeyEvent *e) {
|
||||
void HotkeyInputDialog::on_recordButton_clicked() {
|
||||
recording = !recording;
|
||||
ui->recordButton->setText(recording ? tr("Stop recording") : tr("Record"));
|
||||
if (recording) grabKeyboard();
|
||||
else releaseKeyboard();
|
||||
if (recording)
|
||||
grabKeyboard();
|
||||
else
|
||||
releaseKeyboard();
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "mainwindow.hpp"
|
||||
#include "screenshotutil.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "mainwindow.hpp"
|
||||
#include "aboutbox.hpp"
|
||||
#include "screenshotter.hpp"
|
||||
#include "screenshotutil.hpp"
|
||||
#include "settingsdialog.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "utils.hpp"
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
|
@ -5,10 +5,10 @@
|
||||
#include <iostream>
|
||||
#include <mainwindow.hpp>
|
||||
#include <screenareaselector/screenareaselector.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <settings.hpp>
|
||||
#include <stdio.h>
|
||||
#include <uploaders/uploadersingleton.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <worker/worker.hpp>
|
||||
|
||||
RecordingController::RecordingController() : timer(this) {
|
||||
@ -102,8 +102,8 @@ void RecordingController::timeout() {
|
||||
time++;
|
||||
int localTime = time * timer.interval() - 3000;
|
||||
if (localTime > 0) {
|
||||
QPixmap pp = screenshotutil::fullscreenArea(settings::settings().value("captureCursor", true).toBool(),
|
||||
area.x(), area.y(), area.width(), area.height());
|
||||
QPixmap pp = utils::fullscreenArea(settings::settings().value("captureCursor", true).toBool(), area.x(),
|
||||
area.y(), area.width(), area.height());
|
||||
WorkerContext *context = new WorkerContext;
|
||||
context->consumer = _context->consumer;
|
||||
context->targetFormat = _context->format;
|
||||
|
@ -1,20 +1,20 @@
|
||||
#include "screenshotter.hpp"
|
||||
#include "cropeditor/cropeditor.hpp"
|
||||
#include "mainwindow.hpp"
|
||||
#include "screenshotutil.hpp"
|
||||
#include "uploaders/uploadersingleton.hpp"
|
||||
#include "utils.hpp"
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QTimer>
|
||||
#include <platformbackend.hpp>
|
||||
#include <settings.hpp>
|
||||
|
||||
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); });
|
||||
}
|
||||
|
||||
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() {
|
||||
@ -31,6 +31,6 @@ void screenshotter::activeDelayed() {
|
||||
|
||||
void screenshotter::active() {
|
||||
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
|
||||
UploaderSingleton::inst().upload(screenshotutil::window(PlatformBackend::inst().getActiveWID()));
|
||||
UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID()));
|
||||
#endif
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ SOURCES += main.cpp\
|
||||
cropeditor/cropscene.cpp \
|
||||
uploaders/uploadersingleton.cpp \
|
||||
screenshotter.cpp \
|
||||
screenshotutil.cpp \
|
||||
utils.cpp \
|
||||
uploaders/default/imguruploader.cpp \
|
||||
io/ioutils.cpp \
|
||||
settings.cpp \
|
||||
@ -77,7 +77,7 @@ HEADERS += mainwindow.hpp \
|
||||
uploaders/uploader.hpp \
|
||||
uploaders/uploadersingleton.hpp \
|
||||
screenshotter.hpp \
|
||||
screenshotutil.hpp \
|
||||
utils.hpp \
|
||||
uploaders/default/imguruploader.hpp \
|
||||
io/ioutils.hpp \
|
||||
settings.hpp \
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <formats.hpp>
|
||||
#include <io/ioutils.hpp>
|
||||
#include <notifications.hpp>
|
||||
#include <screenshotutil.hpp>
|
||||
#include <settings.hpp>
|
||||
#include <utils.hpp>
|
||||
|
||||
struct SegfaultWorkaround { // I'm a scrub for doing this
|
||||
SegfaultWorkaround(QByteArray a, ImgurUploader *u, QString m) : byteArray(), dis(u), mime(m) {
|
||||
@ -49,7 +49,7 @@ private:
|
||||
QByteArray byteArray;
|
||||
ImgurUploader *dis;
|
||||
QString mime;
|
||||
};
|
||||
}; // I feel terrible for making this. I am sorry, reader
|
||||
|
||||
void ImgurUploader::doUpload(QByteArray byteArray, QString format) {
|
||||
if (byteArray.size() > 1e+7) {
|
||||
@ -88,7 +88,7 @@ void ImgurUploader::handleSend(QString auth, QString mime, QByteArray byteArray)
|
||||
return;
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
screenshotutil::toClipboard(result);
|
||||
utils::toClipboard(result);
|
||||
notifications::notify(tr("KShare imgur Uploader"), tr("Uploaded to imgur!"));
|
||||
} else {
|
||||
notifications::notify(tr("KShare imgur Uploader "),
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "screenshotutil.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
@ -8,7 +8,21 @@
|
||||
#include <QScreen>
|
||||
#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;
|
||||
QPainter painter;
|
||||
QPoint smallestCoordinate = smallestScreenCoordinate();
|
||||
@ -54,19 +68,19 @@ QPixmap screenshotutil::fullscreen(bool cursor) {
|
||||
return image;
|
||||
}
|
||||
|
||||
QPixmap screenshotutil::window(WId wid, QScreen *w) {
|
||||
QPixmap utils::window(WId wid, QScreen *w) {
|
||||
return w->grabWindow(wid);
|
||||
}
|
||||
|
||||
void screenshotutil::toClipboard(QString value) {
|
||||
void utils::toClipboard(QString 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);
|
||||
}
|
||||
|
||||
QPoint screenshotutil::smallestScreenCoordinate() {
|
||||
QPoint utils::smallestScreenCoordinate() {
|
||||
QPoint smallestCoordinate;
|
||||
for (QScreen *screen : QApplication::screens()) {
|
||||
smallestCoordinate.rx() = qMin(smallestCoordinate.x(), screen->geometry().left());
|
||||
@ -75,7 +89,7 @@ QPoint screenshotutil::smallestScreenCoordinate() {
|
||||
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);
|
||||
QStringList lines = toRender.replace("\r", "").split('\n');
|
||||
QSize resultingSize(0, padding * 2);
|
@ -1,10 +1,13 @@
|
||||
#ifndef SCREENSHOTUTIL_HPP
|
||||
#define SCREENSHOTUTIL_HPP
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPixmap>
|
||||
#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 fullscreenArea(bool cursor = true, qreal x = 0, qreal y = 0, qreal w = -1, qreal h = -1);
|
||||
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());
|
||||
}
|
||||
|
||||
#endif // SCREENSHOTUTIL_HPP
|
||||
#endif // UTILS_HPP
|
Loading…
Reference in New Issue
Block a user