diff --git a/.gitignore b/.gitignore index 10816b9..415fca4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,80 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +.qmake.cache +.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + +# DBus tmp files +agent_adaptor.* +agent_interface.* + +# Build +/Build/ *.2-pre1 *.autosave -*.pro.* \ No newline at end of file diff --git a/dialogs/optionsdialog.cpp b/dialogs/optionsdialog.cpp index 30e0cc3..f3b2a1e 100644 --- a/dialogs/optionsdialog.cpp +++ b/dialogs/optionsdialog.cpp @@ -424,7 +424,7 @@ void OptionsDialog::updatePreview() options.dateFormat = settings()->value("options/naming/dateFormat", "yyyy-MM-dd").toString(); if (ui.fileGroupBox->isChecked()) { // Only change the naming button when file options are enabled. - ui.namingOptionsButton->setDisabled((options.naming == Screenshot::Empty)); + ui.namingOptionsButton->setDisabled((options.naming == Screenshot::Naming::N_Empty)); } QString preview = Screenshot::getName(options, diff --git a/lightscreen.pro b/lightscreen.pro index dfbe2a0..0f403d6 100644 --- a/lightscreen.pro +++ b/lightscreen.pro @@ -2,6 +2,24 @@ TEMPLATE = app TARGET = lightscreen DEFINES += QT_DEPRECATED_WARNINGS +DESTDIR = $${PWD}/Build +BUILDDIR = $${DESTDIR}/.tmp/$${TARGET} + +CONFIG(debug, debug|release) { + win32: BUILDDIR = $${BUILDDIR}/win32-debug + linux: BUILDDIR = $${BUILDDIR}/linux-debug +} else { + win32: BUILDDIR = $${BUILDDIR}/win32-release + linux: BUILDDIR = $${BUILDDIR}/linux-release +} + +MOC_DIR += $${BUILDDIR} +OBJECTS_DIR += $${BUILDDIR}/obj +UI_DIR += $${BUILDDIR} +RCC_DIR += $${BUILDDIR} + +INCLUDEPATH += $${UI_DIR} + HEADERS += dialogs/areadialog.h \ dialogs/historydialog.h \ dialogs/namingdialog.h \ diff --git a/lightscreenwindow.cpp b/lightscreenwindow.cpp index ac83cc5..ed3f618 100644 --- a/lightscreenwindow.cpp +++ b/lightscreenwindow.cpp @@ -62,7 +62,7 @@ LightscreenWindow::LightscreenWindow(QWidget *parent) : mReviveMain(false), mWasVisible(true), mLastMessage(0), - mLastMode(Screenshot::None), + mLastMode(Screenshot::Mode::M_None), mLastScreenshot(), mHasTaskbarButton(false) { @@ -140,7 +140,7 @@ LightscreenWindow::~LightscreenWindow() void LightscreenWindow::action(int mode) { - if (mode <= Screenshot::SelectedWindow) { + if (mode <= static_cast(Screenshot::Mode::M_SelectedWindow)) { screenshotAction((Screenshot::Mode)mode); } else if (mode == ShowMainWindow) { show(); @@ -153,7 +153,7 @@ void LightscreenWindow::action(int mode) void LightscreenWindow::areaHotkey() { - screenshotAction(Screenshot::SelectedArea); + screenshotAction(Screenshot::Mode::M_SelectedArea); } void LightscreenWindow::checkForUpdates() @@ -206,7 +206,7 @@ void LightscreenWindow::cleanup(const Screenshot::Options &options) } if (settings()->value("options/playSound", false).toBool()) { - if (options.result == Screenshot::Success) { + if (options.result == Screenshot::Result::R_Success) { QSound::play("sounds/ls.screenshot.wav"); } else { #ifdef Q_OS_WIN @@ -220,7 +220,7 @@ void LightscreenWindow::cleanup(const Screenshot::Options &options) updateStatus(); - if (options.result != Screenshot::Success) { + if (options.result != Screenshot::Result::R_Success) { return; } @@ -343,13 +343,13 @@ void LightscreenWindow::executeArgument(const QString &message) os::setForegroundWindow(this); qApp->alert(this, 2000); } else if (message == "--screen") { - screenshotAction(Screenshot::WholeScreen); + screenshotAction(Screenshot::Mode::M_WholeScreen); } else if (message == "--area") { - screenshotAction(Screenshot::SelectedArea); + screenshotAction(Screenshot::Mode::M_SelectedArea); } else if (message == "--activewindow") { - screenshotAction(Screenshot::ActiveWindow); + screenshotAction(Screenshot::Mode::M_ActiveWindow); } else if (message == "--pickwindow") { - screenshotAction(Screenshot::SelectedWindow); + screenshotAction(Screenshot::Mode::M_SelectedWindow); } else if (message == "--folder") { action(OpenScreenshotFolder); } else if (message == "--uploadlast") { @@ -379,7 +379,7 @@ void LightscreenWindow::executeArguments(const QStringList &arguments) void LightscreenWindow::notify(const Screenshot::Result &result) { switch (result) { - case Screenshot::Success: + case Screenshot::Result::R_Success: mTrayIcon->setIcon(QIcon(":/icons/lightscreen.yes")); if (mHasTaskbarButton) { @@ -388,7 +388,7 @@ void LightscreenWindow::notify(const Screenshot::Result &result) setWindowTitle(tr("Success!")); break; - case Screenshot::Failure: + case Screenshot::Result::R_Failure: mTrayIcon->setIcon(QIcon(":/icons/lightscreen.no")); setWindowTitle(tr("Failed!")); @@ -397,7 +397,7 @@ void LightscreenWindow::notify(const Screenshot::Result &result) } break; - case Screenshot::Cancel: + case Screenshot::Result::R_Cancel: setWindowTitle(tr("Cancelled!")); break; } @@ -503,7 +503,7 @@ void LightscreenWindow::screenshotAction(Screenshot::Mode mode) // The delayed functions works using the static variable lastMode // which keeps the argument so a QTimer can call this function again. if (delayms > 0) { - if (mLastMode == Screenshot::None) { + if (mLastMode == Screenshot::Mode::M_None) { mLastMode = mode; QTimer::singleShot(delayms, this, [&] { @@ -512,7 +512,7 @@ void LightscreenWindow::screenshotAction(Screenshot::Mode mode) return; } else { mode = mLastMode; - mLastMode = Screenshot::None; + mLastMode = Screenshot::Mode::M_None; } } @@ -555,7 +555,7 @@ void LightscreenWindow::screenshotAction(Screenshot::Mode mode) mDoCache = true; } - options.mode = mode; + options.mode = static_cast(mode); ScreenshotManager::instance()->take(options); } @@ -567,7 +567,7 @@ void LightscreenWindow::screenshotActionTriggered(QAction *action) void LightscreenWindow::screenHotkey() { - screenshotAction(Screenshot::WholeScreen); + screenshotAction(Screenshot::Mode::M_WholeScreen); } void LightscreenWindow::showHotkeyError(const QStringList &hotkeys) @@ -639,7 +639,7 @@ void LightscreenWindow::showOptions() void LightscreenWindow::showScreenshotMessage(const Screenshot::Result &result, const QString &fileName) { - if (result == Screenshot::Cancel) { + if (result == Screenshot::Result::R_Cancel) { return; } @@ -647,7 +647,7 @@ void LightscreenWindow::showScreenshotMessage(const Screenshot::Result &result, QString title; QString message; - if (result == Screenshot::Success) { + if (result == Screenshot::Result::R_Success) { title = QFileInfo(fileName).fileName(); if (settings()->value("file/target").toString().isEmpty()) { @@ -673,7 +673,7 @@ void LightscreenWindow::showUploaderError(const QString &error) mTrayIcon->showMessage(tr("Upload error"), error); } - notify(Screenshot::Failure); + notify(Screenshot::Result::R_Failure); } void LightscreenWindow::showUploaderMessage(const QString &fileName, const QString &url) @@ -813,12 +813,12 @@ void LightscreenWindow::uploadProgress(int progress) void LightscreenWindow::windowHotkey() { - screenshotAction(Screenshot::ActiveWindow); + screenshotAction(Screenshot::Mode::M_ActiveWindow); } void LightscreenWindow::windowPickerHotkey() { - screenshotAction(Screenshot::SelectedWindow); + screenshotAction(Screenshot::Mode::M_SelectedWindow); } void LightscreenWindow::applySettings() @@ -847,7 +847,7 @@ void LightscreenWindow::connectHotkeys() { const QStringList actions = {"screen", "window", "area", "windowPicker", "open", "directory"}; QStringList failed; - size_t id = Screenshot::WholeScreen; + size_t id = static_cast(Screenshot::Mode::M_WholeScreen); for (auto action : actions) { if (settings()->value("actions/" + action + "/enabled").toBool()) { @@ -879,16 +879,16 @@ void LightscreenWindow::createTrayIcon() connect(hideAction, &QAction::triggered, this, &LightscreenWindow::toggleVisibility); auto screenAction = new QAction(os::icon("screen"), tr("&Screen"), mTrayIcon); - screenAction->setData(QVariant::fromValue(Screenshot::WholeScreen)); + screenAction->setData(QVariant::fromValue(Screenshot::Mode::M_WholeScreen)); auto windowAction = new QAction(os::icon("window"), tr("Active &Window"), this); - windowAction->setData(QVariant::fromValue(Screenshot::ActiveWindow)); + windowAction->setData(QVariant::fromValue(Screenshot::Mode::M_ActiveWindow)); auto windowPickerAction = new QAction(os::icon("pickWindow"), tr("&Pick Window"), this); - windowPickerAction->setData(QVariant::fromValue(Screenshot::SelectedWindow)); + windowPickerAction->setData(QVariant::fromValue(Screenshot::Mode::M_SelectedWindow)); auto areaAction = new QAction(os::icon("area"), tr("&Area"), mTrayIcon); - areaAction->setData(QVariant::fromValue(Screenshot::SelectedArea)); + areaAction->setData(QVariant::fromValue(Screenshot::Mode::M_SelectedArea)); auto screenshotGroup = new QActionGroup(mTrayIcon); screenshotGroup->addAction(screenAction); @@ -975,7 +975,7 @@ bool LightscreenWindow::event(QEvent *event) if (event->type() == QEvent::Show) { QPoint savedPosition = settings()->value("position").toPoint(); - if (!savedPosition.isNull() && qApp->desktop()->availableGeometry().contains(QRect(savedPosition, size()))) { + if (!savedPosition.isNull() && qApp->desktop()->screenGeometry(this).contains(QRect(savedPosition, size()))) { move(savedPosition); } diff --git a/lightscreenwindow.h b/lightscreenwindow.h index d830421..4b9e8af 100644 --- a/lightscreenwindow.h +++ b/lightscreenwindow.h @@ -66,7 +66,7 @@ public slots: void quit(); void restoreNotification(); void setStatus(QString status = ""); - void screenshotAction(Screenshot::Mode mode = Screenshot::None); + void screenshotAction(Screenshot::Mode mode = Screenshot::Mode::M_None); void screenshotActionTriggered(QAction *action); void screenHotkey(); void showHotkeyError(const QStringList &hotkeys); diff --git a/tools/screenshot.cpp b/tools/screenshot.cpp index 21e5eba..edc228f 100644 --- a/tools/screenshot.cpp +++ b/tools/screenshot.cpp @@ -53,7 +53,7 @@ Screenshot::Screenshot(QObject *parent, Screenshot::Options options): mUnloaded(false), mUnloadFilename() { - if (mOptions.format == Screenshot::PNG) { + if (mOptions.format == Format::F_PNG) { mOptions.quality = 80; } } @@ -77,7 +77,7 @@ QString Screenshot::getName(const NamingOptions &options, const QString &prefix, } switch (options.naming) { - case Screenshot::Numeric: // Numeric + case Naming::N_Numeric: // Numeric // Iterating through the folder to find the largest numeric naming. for (auto file : directory.entryList(QDir::Files)) { if (file.contains(prefix)) { @@ -100,13 +100,13 @@ QString Screenshot::getName(const NamingOptions &options, const QString &prefix, naming = naming.arg(naming_largest + 1); } break; - case Screenshot::Date: // Date + case Naming::N_Date: // Date naming = naming.arg(QLocale().toString(QDateTime::currentDateTime(), options.dateFormat)); break; - case Screenshot::Timestamp: // Timestamp + case Naming::N_Timestamp: // Timestamp naming = naming.arg(QDateTime::currentDateTime().toTime_t()); break; - case Screenshot::Empty: + case Naming::N_Empty: naming = naming.arg(""); break; } @@ -136,7 +136,7 @@ void Screenshot::confirm(bool result) if (result) { save(); } else { - mOptions.result = Screenshot::Cancel; + mOptions.result = Result::R_Cancel; emit finished(); } @@ -205,7 +205,7 @@ void Screenshot::save() { QString name = ""; QString fileName = ""; - Screenshot::Result result = Screenshot::Failure; + Result result = Result::R_Failure; if (mOptions.file && !mOptions.saveAs) { name = newFileName(); @@ -247,7 +247,7 @@ void Screenshot::save() QApplication::clipboard()->setPixmap(mPixmap, QClipboard::Clipboard); if (!mOptions.file) { - result = Screenshot::Success; + result = Result::R_Success; } } @@ -255,24 +255,24 @@ void Screenshot::save() fileName = name % extension(); if (name.isEmpty()) { - result = Screenshot::Cancel; + result = Result::R_Cancel; } else if (mUnloaded) { - result = (QFile::rename(mUnloadFilename, fileName)) ? Screenshot::Success : Screenshot::Failure; + result = (QFile::rename(mUnloadFilename, fileName)) ? Result::R_Success : Result::R_Failure; } else if (mPixmap.save(fileName, 0, mOptions.quality)) { - result = Screenshot::Success; + result = Result::R_Success; } else { - result = Screenshot::Failure; + result = Result::R_Failure; } } mOptions.fileName = fileName; mOptions.result = result; - if (!mOptions.result) { + if (mOptions.result == Result::R_Success) { emit finished(); } - if (mOptions.format == Screenshot::PNG && mOptions.optimize && mOptions.file) { + if (mOptions.format == Format::F_PNG && mOptions.optimize && mOptions.file) { if (!mOptions.upload) { ScreenshotManager::instance()->saveHistory(mOptions.fileName); } @@ -301,22 +301,24 @@ void Screenshot::setPixmap(const QPixmap &pixmap) void Screenshot::take() { - switch (mOptions.mode) { - case Screenshot::WholeScreen: + switch (static_cast(mOptions.mode)) { + case Mode::M_WholeScreen: wholeScreen(); break; - case Screenshot::SelectedArea: + case Mode::M_SelectedArea: selectedArea(); break; - case Screenshot::ActiveWindow: + case Mode::M_ActiveWindow: activeWindow(); break; - case Screenshot::SelectedWindow: + case Mode::M_SelectedWindow: selectedWindow(); break; + default: + break; } if (mPixmapDelay) { @@ -386,17 +388,17 @@ void Screenshot::activeWindow() const QString Screenshot::extension() const { - switch (mOptions.format) { - case Screenshot::PNG: + switch (static_cast(mOptions.format)) { + case Format::F_PNG: return QStringLiteral(".png"); break; - case Screenshot::BMP: + case Format::F_BMP: return QStringLiteral(".bmp"); break; - case Screenshot::WEBP: + case Format::F_WEBP: return QStringLiteral(".webp"); break; - case Screenshot::JPEG: + case Format::F_JPEG: return QStringLiteral(".jpg"); break; } @@ -439,7 +441,7 @@ void Screenshot::grabDesktop() QPainter painter(&mPixmap); auto cursorInfo = os::cursor(); auto cursorPixmap = cursorInfo.first; - cursorPixmap.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio()); + cursorPixmap.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio()); #if 0 // Debug cursor position helper painter.setBrush(QBrush(Qt::darkRed)); diff --git a/tools/screenshot.h b/tools/screenshot.h index 608c14c..91624e3 100644 --- a/tools/screenshot.h +++ b/tools/screenshot.h @@ -28,35 +28,35 @@ class Screenshot : public QObject Q_OBJECT public: - enum Format { - PNG = 0, - JPEG = 1, - BMP = 2, - WEBP = 3 + enum class Format { + F_PNG, + F_JPEG, + F_BMP , + F_WEBP, }; Q_ENUM(Format) - enum Naming { - Numeric = 0, - Date = 1, - Timestamp = 2, - Empty = 3 + enum class Naming { + N_Numeric, + N_Date, + N_Timestamp, + N_Empty, }; Q_ENUM(Naming) - enum Mode { - None = 0, - WholeScreen = 1, - ActiveWindow = 2, - SelectedArea = 3, - SelectedWindow = 4 + enum class Mode { + M_None, + M_WholeScreen, + M_ActiveWindow, + M_SelectedArea, + M_SelectedWindow, }; Q_ENUM(Mode) - enum Result { - Failure = 0, - Success = 1, - Cancel = 2 + enum class Result { + R_Failure, + R_Success, + R_Cancel, }; Q_ENUM(Result)