Changed clang format to new agreement

This commit is contained in:
Jeremy Borgman
2020-09-23 20:39:30 -05:00
committed by borgmanJeremy
parent 2cbccc3d0a
commit 0d5386edd4
167 changed files with 8567 additions and 9081 deletions

View File

@@ -41,279 +41,268 @@
Controller::Controller()
: m_captureWindow(nullptr)
{
qApp->setQuitOnLastWindowClosed(false);
qApp->setQuitOnLastWindowClosed(false);
// init tray icon
// init tray icon
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if (!ConfigHandler().disabledTrayIconValue()) {
enableTrayIcon();
}
if (!ConfigHandler().disabledTrayIconValue()) {
enableTrayIcon();
}
#elif defined(Q_OS_WIN)
enableTrayIcon();
enableTrayIcon();
GlobalShortcutFilter* nativeFilter = new GlobalShortcutFilter(this);
qApp->installNativeEventFilter(nativeFilter);
connect(nativeFilter, &GlobalShortcutFilter::printPressed, this, [this]() {
this->requestCapture(CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
});
GlobalShortcutFilter* nativeFilter = new GlobalShortcutFilter(this);
qApp->installNativeEventFilter(nativeFilter);
connect(nativeFilter, &GlobalShortcutFilter::printPressed, this, [this]() {
this->requestCapture(CaptureRequest(CaptureRequest::GRAPHICAL_MODE));
});
#endif
QString StyleSheet = CaptureButton::globalStyleSheet();
qApp->setStyleSheet(StyleSheet);
QString StyleSheet = CaptureButton::globalStyleSheet();
qApp->setStyleSheet(StyleSheet);
}
Controller*
Controller::getInstance()
Controller* Controller::getInstance()
{
static Controller c;
return &c;
static Controller c;
return &c;
}
void
Controller::enableExports()
void Controller::enableExports()
{
connect(
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
connect(
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
connect(
this, &Controller::captureTaken, this, &Controller::handleCaptureTaken);
connect(
this, &Controller::captureFailed, this, &Controller::handleCaptureFailed);
}
void
Controller::requestCapture(const CaptureRequest& request)
void Controller::requestCapture(const CaptureRequest& request)
{
uint id = request.id();
m_requestMap.insert(id, request);
uint id = request.id();
m_requestMap.insert(id, request);
switch (request.captureMode()) {
case CaptureRequest::FULLSCREEN_MODE:
doLater(request.delay(), this, [this, id]() {
this->startFullscreenCapture(id);
});
break;
// TODO: Figure out the code path that gets here so the deprated warning can
// be fixed
case CaptureRequest::SCREEN_MODE: {
int&& number = request.data().toInt();
doLater(request.delay(), this, [this, id, number]() {
this->startScreenGrab(id, number);
});
break;
switch (request.captureMode()) {
case CaptureRequest::FULLSCREEN_MODE:
doLater(request.delay(), this, [this, id]() {
this->startFullscreenCapture(id);
});
break;
// TODO: Figure out the code path that gets here so the deprated warning
// can be fixed
case CaptureRequest::SCREEN_MODE: {
int&& number = request.data().toInt();
doLater(request.delay(), this, [this, id, number]() {
this->startScreenGrab(id, number);
});
break;
}
case CaptureRequest::GRAPHICAL_MODE: {
QString&& path = request.path();
doLater(request.delay(), this, [this, id, path]() {
this->startVisualCapture(id, path);
});
break;
}
default:
emit captureFailed(id);
break;
}
case CaptureRequest::GRAPHICAL_MODE: {
QString&& path = request.path();
doLater(request.delay(), this, [this, id, path]() {
this->startVisualCapture(id, path);
});
break;
}
default:
emit captureFailed(id);
break;
}
}
// creation of a new capture in GUI mode
void
Controller::startVisualCapture(const uint id, const QString& forcedSavePath)
void Controller::startVisualCapture(const uint id,
const QString& forcedSavePath)
{
if (!m_captureWindow) {
QWidget* modalWidget = nullptr;
do {
modalWidget = qApp->activeModalWidget();
if (modalWidget) {
modalWidget->close();
modalWidget->deleteLater();
}
} while (modalWidget);
if (!m_captureWindow) {
QWidget* modalWidget = nullptr;
do {
modalWidget = qApp->activeModalWidget();
if (modalWidget) {
modalWidget->close();
modalWidget->deleteLater();
}
} while (modalWidget);
m_captureWindow = new CaptureWidget(id, forcedSavePath);
// m_captureWindow = new CaptureWidget(id, forcedSavePath, false); // debug
connect(m_captureWindow,
&CaptureWidget::captureFailed,
this,
&Controller::captureFailed);
connect(m_captureWindow,
&CaptureWidget::captureTaken,
this,
&Controller::captureTaken);
m_captureWindow = new CaptureWidget(id, forcedSavePath);
// m_captureWindow = new CaptureWidget(id, forcedSavePath, false); //
// debug
connect(m_captureWindow,
&CaptureWidget::captureFailed,
this,
&Controller::captureFailed);
connect(m_captureWindow,
&CaptureWidget::captureTaken,
this,
&Controller::captureTaken);
#ifdef Q_OS_WIN
m_captureWindow->show();
m_captureWindow->show();
#else
m_captureWindow->showFullScreen();
// m_captureWindow->show(); // Debug
m_captureWindow->showFullScreen();
// m_captureWindow->show(); // Debug
#endif
} else {
emit captureFailed(id);
}
} else {
emit captureFailed(id);
}
}
void
Controller::startScreenGrab(const uint id, const int screenNumber)
void Controller::startScreenGrab(const uint id, const int screenNumber)
{
bool ok = true;
int n = screenNumber;
bool ok = true;
int n = screenNumber;
if (n < 0) {
QPoint globalCursorPos = QCursor::pos();
n = qApp->desktop()->screenNumber(globalCursorPos);
}
QPixmap p(ScreenGrabber().grabScreen(n, ok));
if (ok) {
emit captureTaken(id, p);
} else {
emit captureFailed(id);
}
if (n < 0) {
QPoint globalCursorPos = QCursor::pos();
n = qApp->desktop()->screenNumber(globalCursorPos);
}
QPixmap p(ScreenGrabber().grabScreen(n, ok));
if (ok) {
emit captureTaken(id, p);
} else {
emit captureFailed(id);
}
}
// creation of the configuration window
void
Controller::openConfigWindow()
void Controller::openConfigWindow()
{
if (!m_configWindow) {
m_configWindow = new ConfigWindow();
m_configWindow->show();
}
if (!m_configWindow) {
m_configWindow = new ConfigWindow();
m_configWindow->show();
}
}
// creation of the window of information
void
Controller::openInfoWindow()
void Controller::openInfoWindow()
{
if (!m_infoWindow) {
m_infoWindow = new InfoWindow();
}
}
void
Controller::openLauncherWindow()
{
if (!m_launcherWindow) {
m_launcherWindow = new CaptureLauncher();
}
m_launcherWindow->show();
}
void
Controller::enableTrayIcon()
{
if (m_trayIcon) {
return;
}
ConfigHandler().setDisabledTrayIcon(false);
QAction* captureAction = new QAction(tr("&Take Screenshot"), this);
connect(captureAction, &QAction::triggered, this, [this]() {
// Wait 400 ms to hide the QMenu
doLater(400, this, [this]() { this->startVisualCapture(); });
});
QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
connect(
launcherAction, &QAction::triggered, this, &Controller::openLauncherWindow);
QAction* configAction = new QAction(tr("&Configuration"), this);
connect(
configAction, &QAction::triggered, this, &Controller::openConfigWindow);
QAction* infoAction = new QAction(tr("&About"), this);
connect(infoAction, &QAction::triggered, this, &Controller::openInfoWindow);
QAction* quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
QMenu* trayIconMenu = new QMenu();
trayIconMenu->addAction(captureAction);
trayIconMenu->addAction(launcherAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(configAction);
trayIconMenu->addAction(infoAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
m_trayIcon = new QSystemTrayIcon();
m_trayIcon->setToolTip(QStringLiteral("Flameshot"));
m_trayIcon->setContextMenu(trayIconMenu);
QIcon trayicon =
QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
m_trayIcon->setIcon(trayicon);
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
if (r == QSystemTrayIcon::Trigger) {
startVisualCapture();
if (!m_infoWindow) {
m_infoWindow = new InfoWindow();
}
};
connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
m_trayIcon->show();
}
void
Controller::disableTrayIcon()
void Controller::openLauncherWindow()
{
if (!m_launcherWindow) {
m_launcherWindow = new CaptureLauncher();
}
m_launcherWindow->show();
}
void Controller::enableTrayIcon()
{
if (m_trayIcon) {
return;
}
ConfigHandler().setDisabledTrayIcon(false);
QAction* captureAction = new QAction(tr("&Take Screenshot"), this);
connect(captureAction, &QAction::triggered, this, [this]() {
// Wait 400 ms to hide the QMenu
doLater(400, this, [this]() { this->startVisualCapture(); });
});
QAction* launcherAction = new QAction(tr("&Open Launcher"), this);
connect(launcherAction,
&QAction::triggered,
this,
&Controller::openLauncherWindow);
QAction* configAction = new QAction(tr("&Configuration"), this);
connect(
configAction, &QAction::triggered, this, &Controller::openConfigWindow);
QAction* infoAction = new QAction(tr("&About"), this);
connect(infoAction, &QAction::triggered, this, &Controller::openInfoWindow);
QAction* quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
QMenu* trayIconMenu = new QMenu();
trayIconMenu->addAction(captureAction);
trayIconMenu->addAction(launcherAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(configAction);
trayIconMenu->addAction(infoAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
m_trayIcon = new QSystemTrayIcon();
m_trayIcon->setToolTip(QStringLiteral("Flameshot"));
m_trayIcon->setContextMenu(trayIconMenu);
QIcon trayicon =
QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
m_trayIcon->setIcon(trayicon);
auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
if (r == QSystemTrayIcon::Trigger) {
startVisualCapture();
}
};
connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
m_trayIcon->show();
}
void Controller::disableTrayIcon()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if (m_trayIcon) {
m_trayIcon->deleteLater();
}
ConfigHandler().setDisabledTrayIcon(true);
if (m_trayIcon) {
m_trayIcon->deleteLater();
}
ConfigHandler().setDisabledTrayIcon(true);
#endif
}
void
Controller::sendTrayNotification(const QString& text,
const QString& title,
const int timeout)
void Controller::sendTrayNotification(const QString& text,
const QString& title,
const int timeout)
{
if (m_trayIcon) {
m_trayIcon->showMessage(title, text, QSystemTrayIcon::Information, timeout);
}
if (m_trayIcon) {
m_trayIcon->showMessage(
title, text, QSystemTrayIcon::Information, timeout);
}
}
void
Controller::updateConfigComponents()
void Controller::updateConfigComponents()
{
if (m_configWindow) {
m_configWindow->updateChildren();
}
if (m_configWindow) {
m_configWindow->updateChildren();
}
}
void
Controller::startFullscreenCapture(const uint id)
void Controller::startFullscreenCapture(const uint id)
{
bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (ok) {
emit captureTaken(id, p);
} else {
emit captureFailed(id);
}
bool ok = true;
QPixmap p(ScreenGrabber().grabEntireDesktop(ok));
if (ok) {
emit captureTaken(id, p);
} else {
emit captureFailed(id);
}
}
void
Controller::handleCaptureTaken(uint id, QPixmap p)
void Controller::handleCaptureTaken(uint id, QPixmap p)
{
auto it = m_requestMap.find(id);
if (it != m_requestMap.end()) {
it.value().exportCapture(p);
m_requestMap.erase(it);
}
if (ConfigHandler().closeAfterScreenshotValue()) {
QApplication::quit();
}
auto it = m_requestMap.find(id);
if (it != m_requestMap.end()) {
it.value().exportCapture(p);
m_requestMap.erase(it);
}
if (ConfigHandler().closeAfterScreenshotValue()) {
QApplication::quit();
}
}
void
Controller::handleCaptureFailed(uint id)
void Controller::handleCaptureFailed(uint id)
{
m_requestMap.remove(id);
m_requestMap.remove(id);
if (ConfigHandler().closeAfterScreenshotValue()) {
QApplication::quit();
}
if (ConfigHandler().closeAfterScreenshotValue()) {
QApplication::quit();
}
}
void
Controller::doLater(int msec, QObject* receiver, lambda func)
void Controller::doLater(int msec, QObject* receiver, lambda func)
{
QTimer* timer = new QTimer(receiver);
QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() {
func();
timer->deleteLater();
});
timer->setInterval(msec);
timer->start();
QTimer* timer = new QTimer(receiver);
QObject::connect(timer, &QTimer::timeout, receiver, [timer, func]() {
func();
timer->deleteLater();
});
timer->setInterval(msec);
timer->start();
}