Reformat code, fix a glitch with the drawing bar

This commit is contained in:
ArsenArsen 2018-02-18 02:35:29 +01:00
parent c15ba008ff
commit 0acf727347
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
28 changed files with 74 additions and 64 deletions

View File

@ -1,11 +1,11 @@
#include "colorpickerscene.hpp" #include "colorpickerscene.hpp"
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <logger.hpp>
#include <QGraphicsEllipseItem> #include <QGraphicsEllipseItem>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QGraphicsTextItem> #include <QGraphicsTextItem>
#include <QTimer> #include <QTimer>
#include <logger.hpp>
#include <screenoverlay/screenoverlayview.hpp> #include <screenoverlay/screenoverlayview.hpp>
#include <settings.hpp> #include <settings.hpp>
@ -24,7 +24,7 @@ void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
color = image.pixelColor(cursorPos().toPoint()); color = image.pixelColor(cursorPos().toPoint());
if (event->key() == Qt::Key_Return) { if (event->key() == Qt::Key_Return) {
QApplication::clipboard()->setText(color.name()); QApplication::clipboard()->setText(color.name());
logger::info(tr("Copied hex code to clipboard.")); logger::info(tr("Copied hex code to clipboard."));
} }
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close(); if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Escape) close();
} }

View File

@ -203,9 +203,9 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
if (e->buttons() & Qt::LeftButton) newRect.setBottomLeft(cursorPos); if (e->buttons() & Qt::LeftButton) newRect.setBottomLeft(cursorPos);
} }
} }
if (!close) if (!close) {
views()[0]->setCursor(Qt::BlankCursor); views()[0]->setCursor(Qt::BlankCursor);
else { } else {
rect->setRect(newRect); rect->setRect(newRect);
prevButtons = e->buttons(); prevButtons = e->buttons();
updatePoly(); updatePoly();
@ -220,29 +220,31 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
return; return;
} }
if (buttons == Qt::LeftButton) { if (buttons == Qt::LeftButton) {
if (drawingSelection) { if (!proxyMenu->sceneBoundingRect().contains(cursorPos)) {
drawingSelection->mouseDragEvent(e, this); if (drawingSelection) {
} else { drawingSelection->mouseDragEvent(e, this);
QPointF p = cursorPos;
if (rect == nullptr) {
drawingRect = true;
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
initPos = p;
QPen pen(Qt::NoBrush, 1);
pen.setColor(highlight());
rect->setPen(pen);
rect->setZValue(1);
addItem(rect);
} else { } else {
if (prevButtons == Qt::NoButton) { QPointF p = cursorPos;
if (rect == nullptr) {
drawingRect = true;
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
initPos = p; initPos = p;
rect->setRect(p.x(), p.y(), 1, 1); QPen pen(Qt::NoBrush, 1);
pen.setColor(highlight());
rect->setPen(pen);
rect->setZValue(1);
addItem(rect);
} else { } else {
rect->setRect(QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()), if (prevButtons == Qt::NoButton) {
qAbs(initPos.y() - p.y()))); initPos = p;
rect->setRect(p.x(), p.y(), 1, 1);
} else {
rect->setRect(QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()),
qAbs(initPos.x() - p.x()), qAbs(initPos.y() - p.y())));
}
} }
updatePoly();
} }
updatePoly();
} }
} }
prevButtons = buttons; prevButtons = buttons;
@ -259,7 +261,10 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
done(true); done(true);
prevButtons = Qt::NoButton; prevButtons = Qt::NoButton;
if (e->modifiers() & Qt::ControlModifier) e->accept(); if (e->modifiers() & Qt::ControlModifier)
e->accept();
else
QGraphicsScene::mouseReleaseEvent(e);
} }
void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) { void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
@ -268,14 +273,17 @@ void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
if (item && item != proxyMenu) removeItem(item); if (item && item != proxyMenu) removeItem(item);
} }
if (e->modifiers() & Qt::ControlModifier) e->accept(); if (e->modifiers() & Qt::ControlModifier)
e->accept();
else
QGraphicsScene::mousePressEvent(e);
} }
void CropScene::addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item) { void CropScene::addDrawingAction(QMenuBar *menu, QString name, QString icon, std::function<DrawItem *()> item) {
QAction *action = menu->addAction(""); QAction *action = menu->addAction("");
action->setToolTip(name); action->setToolTip(name);
action->setIcon(QIcon(icon)); action->setIcon(QIcon(icon));
connect(action, &QAction::triggered, [this, menu, action, item, name](bool) { setDrawingSelection(name, item); }); connect(action, &QAction::triggered, [this, item, name](bool) { setDrawingSelection(name, item); });
} }
void CropScene::keyReleaseEvent(QKeyEvent *event) { void CropScene::keyReleaseEvent(QKeyEvent *event) {

View File

@ -1,8 +1,8 @@
#ifndef CROPVIEW_HPP #ifndef CROPVIEW_HPP
#define CROPVIEW_HPP #define CROPVIEW_HPP
#include <QKeyEvent>
#include <QCoreApplication> #include <QCoreApplication>
#include <QKeyEvent>
#include <screenoverlay/screenoverlayview.hpp> #include <screenoverlay/screenoverlayview.hpp>
class CropView : public ScreenOverlayView { class CropView : public ScreenOverlayView {
@ -10,6 +10,7 @@ class CropView : public ScreenOverlayView {
public: public:
CropView(QGraphicsScene *scene); CropView(QGraphicsScene *scene);
~CropView(); ~CropView();
protected: protected:
void showEvent(QShowEvent *e) override; void showEvent(QShowEvent *e) override;
}; };

View File

@ -17,8 +17,9 @@ void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
textItem->setPen(scene->pen().color()); textItem->setPen(scene->pen().color());
textItem->setBrush(scene->pen().color()); textItem->setBrush(scene->pen().color());
} else { } else {
auto ee = 180 + qRadiansToDegrees(qAtan2((textItem->pos().y() - scene->cursorPos().y()), auto ee = 180
(textItem->pos().x() - scene->cursorPos().x()))); + qRadiansToDegrees(qAtan2((textItem->pos().y() - scene->cursorPos().y()),
(textItem->pos().x() - scene->cursorPos().x())));
textItem->setRotation(ee); textItem->setRotation(ee);
} }
} }

View File

@ -13,5 +13,5 @@ namespace formats {
QString recordingFormatName(Recording format); QString recordingFormatName(Recording format);
Recording recordingFormatFromName(QString format); Recording recordingFormatFromName(QString format);
QString recordingFormatMIME(Recording format); QString recordingFormatMIME(Recording format);
} } // namespace formats
#endif // FORMATS_HPP #endif // FORMATS_HPP

View File

@ -10,6 +10,6 @@ namespace hotkeying {
bool valid(QString seq); bool valid(QString seq);
void load(QString seqName, std::function<void()> func, QString def = QString()); void load(QString seqName, std::function<void()> func, QString def = QString());
QString sequence(QString seqName); QString sequence(QString seqName);
} } // namespace hotkeying
#endif // HOTKEYING_HPP #endif // HOTKEYING_HPP

View File

@ -27,6 +27,6 @@ namespace ioutils {
QHttpMultiPart *body, QHttpMultiPart *body,
std::function<void(QByteArray, QNetworkReply *)> callback); std::function<void(QByteArray, QNetworkReply *)> callback);
QString methodString(QNetworkAccessManager::Operation operation); QString methodString(QNetworkAccessManager::Operation operation);
} } // namespace ioutils
#endif // IOUTILS_HPP #endif // IOUTILS_HPP

View File

@ -9,6 +9,6 @@ namespace logger {
void error(QString info); // Oh no - it errored, but is recoverable, and still important enough to notify void error(QString info); // Oh no - it errored, but is recoverable, and still important enough to notify
void fatal(QString info); // Unrecoverable error, procedure aborts and notifies the user void fatal(QString info); // Unrecoverable error, procedure aborts and notifies the user
void abort(QString info); // tell the user that it gonna ded void abort(QString info); // tell the user that it gonna ded
} } // namespace logger
#endif /* LOGGER_HPP */ #endif /* LOGGER_HPP */

View File

@ -16,8 +16,8 @@ HistoryDialog::HistoryDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Hist
QList<LoggedRequest> requests = requestlogging::getRequests(); QList<LoggedRequest> requests = requestlogging::getRequests();
for (LoggedRequest req : requests) { for (LoggedRequest req : requests) {
ui->treeWidget->addTopLevelItem(new QTreeWidgetItem( ui->treeWidget->addTopLevelItem(
{ req.getType(), req.getUrl(), QString::number(req.getResponseCode()), req.getTime() + " UTC" })); new QTreeWidgetItem({ req.getType(), req.getUrl(), QString::number(req.getResponseCode()), req.getTime() + " UTC" }));
} }
} }

View File

@ -41,6 +41,6 @@ namespace requestlogging {
QList<LoggedRequest> getRequests(); QList<LoggedRequest> getRequests();
void addEntry(RequestContext context); void addEntry(RequestContext context);
} } // namespace requestlogging
#endif // REQUESTLOGGING_HPP #endif // REQUESTLOGGING_HPP

View File

@ -1,5 +1,4 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include <ui_mainwindow.h>
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QDir> #include <QDir>
@ -7,6 +6,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <formatter.hpp> #include <formatter.hpp>
#include <iostream> #include <iostream>
#include <ui_mainwindow.h>
extern "C" { extern "C" {
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>

View File

@ -9,12 +9,12 @@
#include <colorpicker/colorpickerscene.hpp> #include <colorpicker/colorpickerscene.hpp>
#include <formats.hpp> #include <formats.hpp>
#include <hotkeying.hpp> #include <hotkeying.hpp>
#include <logger.hpp>
#include <logs/historydialog.hpp> #include <logs/historydialog.hpp>
#include <platformbackend.hpp> #include <platformbackend.hpp>
#include <recording/recordingformats.hpp> #include <recording/recordingformats.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <uploaders/uploadersingleton.hpp> #include <uploaders/uploadersingleton.hpp>
#include <logger.hpp>
MainWindow *MainWindow::instance; MainWindow *MainWindow::instance;

View File

@ -7,6 +7,6 @@
namespace notifications { namespace notifications {
void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information); void notify(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
void notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information); void notifyNolog(QString title, QString body, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information);
} } // namespace notifications
#endif // NOTIFICATIONS_HPP #endif // NOTIFICATIONS_HPP

View File

@ -1,7 +1,7 @@
#include "macbackend.hpp" #include "macbackend.hpp"
#include <unistd.h>
#include <pwd.h> #include <pwd.h>
#include <unistd.h>
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() { std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
#warning "TODO: Mac backend" #warning "TODO: Mac backend"
@ -21,13 +21,13 @@ bool PlatformBackend::filenameValid(QString name) {
QString PlatformBackend::getCurrentUser() { QString PlatformBackend::getCurrentUser() {
auto pwent = getpwent(); auto pwent = getpwent();
if(!pwent) { if (!pwent) {
if (qEnvironmentVariableIsSet("USER")) if (qEnvironmentVariableIsSet("USER"))
return QString::fromLocal8Bit(qgetenv("USER")); return QString::fromLocal8Bit(qgetenv("USER"));
else return QString(); else
return QString();
} }
QString ret = QString::fromLocal8Bit(pwent->pw_name); QString ret = QString::fromLocal8Bit(pwent->pw_name);
endpwent(); endpwent();
return ret; return ret;
} }

View File

@ -2,8 +2,8 @@
#include <QPixmap> #include <QPixmap>
#include <QX11Info> #include <QX11Info>
#include <unistd.h>
#include <pwd.h> #include <pwd.h>
#include <unistd.h>
#include <xcb/xcb_cursor.h> #include <xcb/xcb_cursor.h>
#include <xcb/xcb_util.h> #include <xcb/xcb_util.h>
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
@ -61,10 +61,11 @@ bool PlatformBackend::filenameValid(QString name) {
QString PlatformBackend::getCurrentUser() { QString PlatformBackend::getCurrentUser() {
auto pwent = getpwent(); auto pwent = getpwent();
if(!pwent) { if (!pwent) {
if (qEnvironmentVariableIsSet("USER")) if (qEnvironmentVariableIsSet("USER"))
return QString::fromLocal8Bit(qgetenv("USER")); return QString::fromLocal8Bit(qgetenv("USER"));
else return QString(); else
return QString();
} }
QString ret = QString::fromLocal8Bit(pwent->pw_name); QString ret = QString::fromLocal8Bit(pwent->pw_name);
endpwent(); endpwent();

View File

@ -2,12 +2,12 @@
#include <QBuffer> #include <QBuffer>
#include <QDateTime> #include <QDateTime>
#include <logger.hpp>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QStandardPaths> #include <QStandardPaths>
#include <QTimer> #include <QTimer>
#include <formats.hpp> #include <formats.hpp>
#include <logger.hpp>
#include <notifications.hpp> #include <notifications.hpp>
#include <platformbackend.hpp> #include <platformbackend.hpp>
#include <settings.hpp> #include <settings.hpp>

View File

@ -57,6 +57,5 @@ void RecordingPreview::setPixmap(QPixmap map) {
} }
void RecordingPreview::setTime(QString time, int frame) { void RecordingPreview::setTime(QString time, int frame) {
if (isVisible()) if (isVisible())
hintLabel->setText( hintLabel->setText(tr("Time: %1\nFrame: %2\nStop key: %3").arg(time).arg(frame).arg(hotkeying::sequence("recordingstop")));
tr("Time: %1\nFrame: %2\nStop key: %3").arg(time).arg(frame).arg(hotkeying::sequence("recordingstop")));
} }

View File

@ -95,8 +95,9 @@ void ScreenOverlay::setMagVisibility(bool visible) {
magnifierBox->setVisible(visible); magnifierBox->setVisible(visible);
magnifierHint->setVisible(visible); magnifierHint->setVisible(visible);
magnifierHintBox->setVisible(visible); magnifierHintBox->setVisible(visible);
for (auto *view : views()) for (auto *view : views()) {
view->setCursor(visible ? Qt::BlankCursor : Qt::ArrowCursor); view->setCursor(visible ? Qt::BlankCursor : Qt::ArrowCursor);
}
} }
void ScreenOverlay::showMag() { void ScreenOverlay::showMag() {

View File

@ -1,8 +1,8 @@
#include "screenoverlaysettings.hpp" #include "screenoverlaysettings.hpp"
#include "ui_screenoverlaysettings.h" #include "ui_screenoverlaysettings.h"
#include <settings.hpp>
#include <QColorDialog> #include <QColorDialog>
#include <settings.hpp>
ScreenOverlaySettings::ScreenOverlaySettings(ScreenOverlay *overlay, QWidget *parent) ScreenOverlaySettings::ScreenOverlaySettings(ScreenOverlay *overlay, QWidget *parent)
: QDialog(parent), ui(new Ui::ScreenOverlaySettings), overlay(overlay) { : QDialog(parent), ui(new Ui::ScreenOverlaySettings), overlay(overlay) {

View File

@ -1,15 +1,14 @@
#ifndef SCREENOVERLAYSETTINGS_H #ifndef SCREENOVERLAYSETTINGS_H
#define SCREENOVERLAYSETTINGS_H #define SCREENOVERLAYSETTINGS_H
#include <QDialog>
#include "screenoverlay.hpp" #include "screenoverlay.hpp"
#include <QDialog>
namespace Ui { namespace Ui {
class ScreenOverlaySettings; class ScreenOverlaySettings;
} }
class ScreenOverlaySettings : public QDialog class ScreenOverlaySettings : public QDialog {
{
Q_OBJECT Q_OBJECT
public: public:

View File

@ -10,6 +10,6 @@ namespace screenshotter {
void activeDelayed(); void activeDelayed();
void active(); void active();
} } // namespace screenshotter
#endif // SCREENSHOTTER_HPP #endif // SCREENSHOTTER_HPP

View File

@ -1,7 +1,7 @@
#include "settings.hpp" #include "settings.hpp"
#include <logger.hpp>
#include <QStandardPaths> #include <QStandardPaths>
#include <logger.hpp>
QSettings &settings::settings() { QSettings &settings::settings() {
static QSettings settings(dir().absoluteFilePath("settings.ini"), QSettings::IniFormat); static QSettings settings(dir().absoluteFilePath("settings.ini"), QSettings::IniFormat);

View File

@ -7,6 +7,6 @@
namespace settings { namespace settings {
QSettings &settings(); QSettings &settings();
QDir dir(); QDir dir();
} } // namespace settings
#endif // SETTINGS_HPP #endif // SETTINGS_HPP

View File

@ -38,6 +38,7 @@ private slots:
void on_fpsMax_valueChanged(int arg1); void on_fpsMax_valueChanged(int arg1);
void on_fullscreenCapture_textChanged(QString newVal); void on_fullscreenCapture_textChanged(QString newVal);
void on_focusedCapture_textChanged(QString newVal); void on_focusedCapture_textChanged(QString newVal);
private: private:
Ui::SettingsDialog *ui; Ui::SettingsDialog *ui;
}; };

View File

@ -31,9 +31,8 @@ void ImgplusUploader::doUpload(QByteArray byteArray, QString format) {
keyPart.setBody(settings::settings().value("imgplus/apikey").toString().toUtf8()); keyPart.setBody(settings::settings().value("imgplus/apikey").toString().toUtf8());
multipart->append(keyPart); multipart->append(keyPart);
ioutils::postMultipartData(QUrl("http://imgpl.us/api/upload"), ioutils::postMultipartData(QUrl("http://imgpl.us/api/upload"), { QPair<QString, QString>("Accept", "application/json") },
{ QPair<QString, QString>("Accept", "application/json") }, multipart, multipart, [](QByteArray link, QNetworkReply *) {
[](QByteArray link, QNetworkReply *) {
QApplication::clipboard()->setText(QString::fromUtf8(link)); QApplication::clipboard()->setText(QString::fromUtf8(link));
if (!link.startsWith("http")) if (!link.startsWith("http"))
qCritical() << QObject::tr("Failed to upload! Copied the response to clipboard"); qCritical() << QObject::tr("Failed to upload! Copied the response to clipboard");

View File

@ -3,12 +3,12 @@
#include "default/clipboarduploader.hpp" #include "default/clipboarduploader.hpp"
#include "default/imguruploader.hpp" #include "default/imguruploader.hpp"
#include <QBuffer> #include <QBuffer>
#include <logger.hpp>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QStandardPaths> #include <QStandardPaths>
#include <formats.hpp> #include <formats.hpp>
#include <formatter.hpp> #include <formatter.hpp>
#include <logger.hpp>
#include <notifications.hpp> #include <notifications.hpp>
#include <settings.hpp> #include <settings.hpp>
#include <uploaders/default/imgplusuploader.hpp> #include <uploaders/default/imgplusuploader.hpp>

View File

@ -136,7 +136,7 @@ void utils::externalScreenshot(std::function<void(QPixmap)> callback) {
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[callback, process, tempPath](int code, QProcess::ExitStatus) { [callback, process, tempPath](int code, QProcess::ExitStatus) {
if (code != 0) { if (code != 0) {
logger::fatal(QObject::tr("Failed to take external screenshot: \n") + process->readAllStandardError()); logger::fatal(QObject::tr("Failed to take external screenshot: \n") + process->readAllStandardError());
} else { } else {
QPixmap pixmap; QPixmap pixmap;
if (!tempPath.isEmpty()) if (!tempPath.isEmpty())
@ -167,7 +167,7 @@ void utils::externalScreenshotActive(std::function<void(QPixmap)> callback) {
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[callback, process, tempPath](int code, QProcess::ExitStatus) { [callback, process, tempPath](int code, QProcess::ExitStatus) {
if (code != 0) { if (code != 0) {
logger::fatal(QObject::tr("Failed to take external screenshot: \n") + process->readAllStandardError()); logger::fatal(QObject::tr("Failed to take external screenshot: \n") + process->readAllStandardError());
} else { } else {
QPixmap pixmap; QPixmap pixmap;
if (!tempPath.isEmpty()) if (!tempPath.isEmpty())

View File

@ -20,6 +20,6 @@ namespace utils {
void externalScreenshot(std::function<void(QPixmap)> callback); void externalScreenshot(std::function<void(QPixmap)> callback);
void externalScreenshotActive(std::function<void(QPixmap)> callback); void externalScreenshotActive(std::function<void(QPixmap)> callback);
QString randomString(int length); QString randomString(int length);
} } // namespace utils
#endif // UTILS_HPP #endif // UTILS_HPP