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 <QApplication>
#include <QClipboard>
#include <logger.hpp>
#include <QGraphicsEllipseItem>
#include <QGraphicsPixmapItem>
#include <QGraphicsTextItem>
#include <QTimer>
#include <logger.hpp>
#include <screenoverlay/screenoverlayview.hpp>
#include <settings.hpp>
@ -24,7 +24,7 @@ void ColorPickerScene::keyPressEvent(QKeyEvent *event) {
color = image.pixelColor(cursorPos().toPoint());
if (event->key() == Qt::Key_Return) {
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();
}

View File

@ -203,9 +203,9 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
if (e->buttons() & Qt::LeftButton) newRect.setBottomLeft(cursorPos);
}
}
if (!close)
if (!close) {
views()[0]->setCursor(Qt::BlankCursor);
else {
} else {
rect->setRect(newRect);
prevButtons = e->buttons();
updatePoly();
@ -220,29 +220,31 @@ void CropScene::mouseMoved(QGraphicsSceneMouseEvent *e, QPointF cursorPos, QPoin
return;
}
if (buttons == Qt::LeftButton) {
if (drawingSelection) {
drawingSelection->mouseDragEvent(e, this);
} else {
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);
if (!proxyMenu->sceneBoundingRect().contains(cursorPos)) {
if (drawingSelection) {
drawingSelection->mouseDragEvent(e, this);
} else {
if (prevButtons == Qt::NoButton) {
QPointF p = cursorPos;
if (rect == nullptr) {
drawingRect = true;
rect = new SelectionRectangle(p.x(), p.y(), 1, 1);
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 {
rect->setRect(QRect(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()),
qAbs(initPos.y() - p.y())));
if (prevButtons == Qt::NoButton) {
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;
@ -259,7 +261,10 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
done(true);
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) {
@ -268,14 +273,17 @@ void CropScene::mousePressEvent(QGraphicsSceneMouseEvent *e) {
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) {
QAction *action = menu->addAction("");
action->setToolTip(name);
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) {

View File

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

View File

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

View File

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

View File

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

View File

@ -27,6 +27,6 @@ namespace ioutils {
QHttpMultiPart *body,
std::function<void(QByteArray, QNetworkReply *)> callback);
QString methodString(QNetworkAccessManager::Operation operation);
}
} // namespace ioutils
#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 fatal(QString info); // Unrecoverable error, procedure aborts and notifies the user
void abort(QString info); // tell the user that it gonna ded
}
} // namespace logger
#endif /* LOGGER_HPP */

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,6 @@
namespace notifications {
void notify(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

View File

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

View File

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

View File

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

View File

@ -57,6 +57,5 @@ void RecordingPreview::setPixmap(QPixmap map) {
}
void RecordingPreview::setTime(QString time, int frame) {
if (isVisible())
hintLabel->setText(
tr("Time: %1\nFrame: %2\nStop key: %3").arg(time).arg(frame).arg(hotkeying::sequence("recordingstop")));
hintLabel->setText(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);
magnifierHint->setVisible(visible);
magnifierHintBox->setVisible(visible);
for (auto *view : views())
for (auto *view : views()) {
view->setCursor(visible ? Qt::BlankCursor : Qt::ArrowCursor);
}
}
void ScreenOverlay::showMag() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,6 +38,7 @@ private slots:
void on_fpsMax_valueChanged(int arg1);
void on_fullscreenCapture_textChanged(QString newVal);
void on_focusedCapture_textChanged(QString newVal);
private:
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());
multipart->append(keyPart);
ioutils::postMultipartData(QUrl("http://imgpl.us/api/upload"),
{ QPair<QString, QString>("Accept", "application/json") }, multipart,
[](QByteArray link, QNetworkReply *) {
ioutils::postMultipartData(QUrl("http://imgpl.us/api/upload"), { QPair<QString, QString>("Accept", "application/json") },
multipart, [](QByteArray link, QNetworkReply *) {
QApplication::clipboard()->setText(QString::fromUtf8(link));
if (!link.startsWith("http"))
qCritical() << QObject::tr("Failed to upload! Copied the response to clipboard");

View File

@ -3,12 +3,12 @@
#include "default/clipboarduploader.hpp"
#include "default/imguruploader.hpp"
#include <QBuffer>
#include <logger.hpp>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <formats.hpp>
#include <formatter.hpp>
#include <logger.hpp>
#include <notifications.hpp>
#include <settings.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),
[callback, process, tempPath](int code, QProcess::ExitStatus) {
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 {
QPixmap pixmap;
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),
[callback, process, tempPath](int code, QProcess::ExitStatus) {
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 {
QPixmap pixmap;
if (!tempPath.isEmpty())

View File

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