mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Fixing deprecation for future Qt 6 support (#3962)
* Replace foreach * Replace QRegExp with QRegularExpression * Replace QApplication::fontMetrics * Replace QColor::isValidColor * Replace canConvert(QVariant) * Replace QString::midRef and QCharRef * Add TODO for replacing QDesktopWidget for Qt 6 * Add TODO for replacing QTextCodec for Qt 6 * Fix QWidget::enterEvent for Qt 6 * qRegisterMetaTypeStreamOperators done automatically in Qt 6 * Fix QWidget::mapToGlobal for Qt 6 * Migrate QDesktopWidget replacement from old qt6 branch * Drop Qt 5 support
This commit is contained in:
@@ -36,6 +36,15 @@ set(PROJECT_NAME_CAPITALIZED "Flameshot")
|
|||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
#Must be set before fetching external content
|
||||||
|
#QT_DEFAULT_MAJOR_VERSION used by "SingleApplication"
|
||||||
|
#QT_VERSION_MAJOR used by Flameshot and "QtColorWidgets"
|
||||||
|
set(QT_DEFAULT_MAJOR_VERSION 6 CACHE STRING "")
|
||||||
|
set(QT_VERSION_MAJOR 6 CACHE STRING "")
|
||||||
|
|
||||||
|
#Needed due to linker error with QtColorWidget
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
qtColorWidgets
|
qtColorWidgets
|
||||||
GIT_REPOSITORY https://gitlab.com/mattbas/Qt-Color-Widgets.git
|
GIT_REPOSITORY https://gitlab.com/mattbas/Qt-Color-Widgets.git
|
||||||
@@ -120,7 +129,7 @@ if(USE_EXTERNAL_SINGLEAPPLICATION)
|
|||||||
# package dev-qt/qtsingleapplication provides no symlink to current version
|
# package dev-qt/qtsingleapplication provides no symlink to current version
|
||||||
set(qtsingleapplication_libs libQt5Solutions_SingleApplication-2.6 Qt5Solutions_SingleApplication-2.6)
|
set(qtsingleapplication_libs libQt5Solutions_SingleApplication-2.6 Qt5Solutions_SingleApplication-2.6)
|
||||||
find_library(QTSINGLEAPPLICATION_LIBRARY NAMES ${qtsingleapplication_libs})
|
find_library(QTSINGLEAPPLICATION_LIBRARY NAMES ${qtsingleapplication_libs})
|
||||||
message(STATUS "Using external SingleApplication library")
|
message(STATUS "Using external QtSingleApplication library")
|
||||||
else()
|
else()
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
singleApplication
|
singleApplication
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
find_package(
|
find_package(
|
||||||
Qt5
|
Qt${QT_VERSION_MAJOR}
|
||||||
CONFIG
|
CONFIG
|
||||||
REQUIRED
|
REQUIRED
|
||||||
Core
|
Core
|
||||||
|
Core5Compat
|
||||||
Gui
|
Gui
|
||||||
Widgets
|
Widgets
|
||||||
Network
|
Network
|
||||||
Svg
|
Svg
|
||||||
DBus
|
DBus
|
||||||
LinguistTools)
|
LinguistTools
|
||||||
|
Core5Compat #To be removed once QTextCodec has been replaced with the equivalent in Qt 6
|
||||||
|
)
|
||||||
|
|
||||||
if (USE_WAYLAND_CLIPBOARD)
|
if (USE_WAYLAND_CLIPBOARD)
|
||||||
find_package(KF5GuiAddons)
|
find_package(KF5GuiAddons)
|
||||||
@@ -136,9 +139,9 @@ set(FLAMESHOT_TS_FILES
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (GENERATE_TS)
|
if (GENERATE_TS)
|
||||||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${FLAMESHOT_TS_FILES})
|
qt6_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${FLAMESHOT_TS_FILES})
|
||||||
else ()
|
else ()
|
||||||
qt5_add_translation(QM_FILES ${FLAMESHOT_TS_FILES})
|
qt6_add_translation(QM_FILES ${FLAMESHOT_TS_FILES})
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
target_sources(
|
target_sources(
|
||||||
@@ -210,13 +213,13 @@ target_link_libraries(
|
|||||||
flameshot
|
flameshot
|
||||||
project_warnings
|
project_warnings
|
||||||
project_options
|
project_options
|
||||||
Qt5::Svg
|
Qt${QT_VERSION_MAJOR}::Svg
|
||||||
Qt5::DBus
|
Qt${QT_VERSION_MAJOR}::DBus
|
||||||
Qt5::Network
|
Qt${QT_VERSION_MAJOR}::Network
|
||||||
Qt5::Widgets
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
|
Qt${QT_VERSION_MAJOR}::Core5Compat #To be removed once QTextCodec has been replaced with the equivalent in Qt 6
|
||||||
${QTSINGLEAPPLICATION_LIBRARY}
|
${QTSINGLEAPPLICATION_LIBRARY}
|
||||||
QtColorWidgets
|
QtColorWidgets
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (USE_WAYLAND_CLIPBOARD)
|
if (USE_WAYLAND_CLIPBOARD)
|
||||||
|
|||||||
@@ -170,7 +170,11 @@ void ColorPickerEditor::updatePreset()
|
|||||||
|
|
||||||
void ColorPickerEditor::onAddPreset()
|
void ColorPickerEditor::onAddPreset()
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
if (QColor::isValidColor(m_colorInput->text())) {
|
if (QColor::isValidColor(m_colorInput->text())) {
|
||||||
|
#else
|
||||||
|
if (QColor::isValidColorName(m_colorInput->text())) {
|
||||||
|
#endif
|
||||||
m_color = QColor(m_colorInput->text());
|
m_color = QColor(m_colorInput->text());
|
||||||
m_colorInput->setText(m_color.name(QColor::HexRgb));
|
m_colorInput->setText(m_color.name(QColor::HexRgb));
|
||||||
} else {
|
} else {
|
||||||
@@ -196,7 +200,11 @@ void ColorPickerEditor::onDeletePreset()
|
|||||||
|
|
||||||
void ColorPickerEditor::onUpdatePreset()
|
void ColorPickerEditor::onUpdatePreset()
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
if (QColor::isValidColor(m_colorEdit->text())) {
|
if (QColor::isValidColor(m_colorEdit->text())) {
|
||||||
|
#else
|
||||||
|
if (QColor::isValidColorName(m_colorEdit->text())) {
|
||||||
|
#endif
|
||||||
QColor c = QColor(m_colorEdit->text());
|
QColor c = QColor(m_colorEdit->text());
|
||||||
m_colorEdit->setText(c.name(QColor::HexRgb));
|
m_colorEdit->setText(c.name(QColor::HexRgb));
|
||||||
} else {
|
} else {
|
||||||
@@ -206,4 +214,4 @@ void ColorPickerEditor::onUpdatePreset()
|
|||||||
|
|
||||||
updatePreset();
|
updatePreset();
|
||||||
m_colorpicker->updateWidget();
|
m_colorpicker->updateWidget();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec> // TODO: Qt 6 - Replace QTextCodec with Qt 6 solution; temporary include Core5Compat
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
GeneralConf::GeneralConf(QWidget* parent)
|
GeneralConf::GeneralConf(QWidget* parent)
|
||||||
@@ -188,6 +188,8 @@ void GeneralConf::importConfiguration()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
|
// TODO: Qt 6 - Replace QTextCodec with Qt 6 solution
|
||||||
|
// Temporary: Include Core5Compat when compiling with Qt 6
|
||||||
QTextCodec* codec = QTextCodec::codecForLocale();
|
QTextCodec* codec = QTextCodec::codecForLocale();
|
||||||
if (!file.open(QFile::ReadOnly)) {
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
QMessageBox::about(this, tr("Error"), tr("Unable to read file."));
|
QMessageBox::about(this, tr("Error"), tr("Unable to read file."));
|
||||||
@@ -566,7 +568,7 @@ void GeneralConf::initSaveAfterCopy()
|
|||||||
m_setSaveAsFileExtension = new QComboBox(this);
|
m_setSaveAsFileExtension = new QComboBox(this);
|
||||||
|
|
||||||
QStringList imageFormatList;
|
QStringList imageFormatList;
|
||||||
foreach (auto mimeType, QImageWriter::supportedImageFormats())
|
for (const auto& mimeType : QImageWriter::supportedImageFormats())
|
||||||
imageFormatList.append(mimeType);
|
imageFormatList.append(mimeType);
|
||||||
|
|
||||||
m_setSaveAsFileExtension->addItems(imageFormatList);
|
m_setSaveAsFileExtension->addItems(imageFormatList);
|
||||||
|
|||||||
@@ -7,21 +7,18 @@
|
|||||||
#include "src/core/qguiappcurrentscreen.h"
|
#include "src/core/qguiappcurrentscreen.h"
|
||||||
#include "src/utils/globalvalues.h"
|
#include "src/utils/globalvalues.h"
|
||||||
#include "toolfactory.h"
|
#include "toolfactory.h"
|
||||||
|
#include <QCursor>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QRect>
|
||||||
|
#include <QScreen>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
||||||
#include <QCursor>
|
|
||||||
#include <QRect>
|
|
||||||
#include <QScreen>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
@@ -29,12 +26,10 @@ ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
|||||||
setWindowIcon(QIcon(GlobalValues::iconPath()));
|
setWindowIcon(QIcon(GlobalValues::iconPath()));
|
||||||
setWindowTitle(tr("Hot Keys"));
|
setWindowTitle(tr("Hot Keys"));
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
||||||
QRect position = frameGeometry();
|
QRect position = frameGeometry();
|
||||||
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
|
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
|
||||||
position.moveCenter(screen->availableGeometry().center());
|
position.moveCenter(screen->availableGeometry().center());
|
||||||
move(position.topLeft());
|
move(position.topLeft());
|
||||||
#endif
|
|
||||||
|
|
||||||
m_layout = new QVBoxLayout(this);
|
m_layout = new QVBoxLayout(this);
|
||||||
m_layout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
m_layout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ UIcolorEditor::UIcolorEditor(QWidget* parent)
|
|||||||
m_hLayout = new QHBoxLayout;
|
m_hLayout = new QHBoxLayout;
|
||||||
m_vLayout = new QVBoxLayout;
|
m_vLayout = new QVBoxLayout;
|
||||||
|
|
||||||
const int space = QApplication::fontMetrics().lineSpacing();
|
const int space = QFontMetrics(qApp->font()).lineSpacing();
|
||||||
m_hLayout->addItem(new QSpacerItem(space, space, QSizePolicy::Expanding));
|
m_hLayout->addItem(new QSpacerItem(space, space, QSizePolicy::Expanding));
|
||||||
m_vLayout->setAlignment(Qt::AlignVCenter);
|
m_vLayout->setAlignment(Qt::AlignVCenter);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -53,6 +52,7 @@ Flameshot::Flameshot()
|
|||||||
// permissions on the first run. Otherwise it will be hidden under the
|
// permissions on the first run. Otherwise it will be hidden under the
|
||||||
// CaptureWidget
|
// CaptureWidget
|
||||||
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
||||||
|
// TODO: Qt 6 - QApplication::desktop() not avialable
|
||||||
currentScreen->grabWindow(QApplication::desktop()->winId(), 0, 0, 1, 1);
|
currentScreen->grabWindow(QApplication::desktop()->winId(), 0, 0, 1, 1);
|
||||||
|
|
||||||
// set global shortcuts for MacOS
|
// set global shortcuts for MacOS
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "qguiappcurrentscreen.h"
|
#include "qguiappcurrentscreen.h"
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
@@ -49,15 +48,6 @@ QScreen* QGuiAppCurrentScreen::currentScreen(const QPoint& pos)
|
|||||||
|
|
||||||
QScreen* QGuiAppCurrentScreen::screenAt(const QPoint& pos)
|
QScreen* QGuiAppCurrentScreen::screenAt(const QPoint& pos)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
||||||
m_currentScreen = qGuiApp->screenAt(pos);
|
m_currentScreen = qGuiApp->screenAt(pos);
|
||||||
#else
|
|
||||||
for (QScreen* const screen : QGuiApplication::screens()) {
|
|
||||||
m_currentScreen = screen;
|
|
||||||
if (screen->geometry().contains(pos)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return m_currentScreen;
|
return m_currentScreen;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,9 +153,6 @@ int main(int argc, char* argv[])
|
|||||||
wayland_hacks();
|
wayland_hacks();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// required for the button serialization
|
|
||||||
// TODO: change to QVector in v1.0
|
|
||||||
qRegisterMetaTypeStreamOperators<QList<int>>("QList<int>");
|
|
||||||
QCoreApplication::setApplicationVersion(APP_VERSION);
|
QCoreApplication::setApplicationVersion(APP_VERSION);
|
||||||
QCoreApplication::setApplicationName(QStringLiteral("flameshot"));
|
QCoreApplication::setApplicationName(QStringLiteral("flameshot"));
|
||||||
QCoreApplication::setOrganizationName(QStringLiteral("flameshot"));
|
QCoreApplication::setOrganizationName(QStringLiteral("flameshot"));
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
|
||||||
@@ -128,11 +129,12 @@ void AppLauncherWidget::launch(const QModelIndex& index)
|
|||||||
QStringList prog_args = command.split(" ");
|
QStringList prog_args = command.split(" ");
|
||||||
#endif
|
#endif
|
||||||
// no quotes because it is going in an array!
|
// no quotes because it is going in an array!
|
||||||
|
static const QRegularExpression regexp("(\\%.)");
|
||||||
if (command.contains("%")) {
|
if (command.contains("%")) {
|
||||||
// but that means we need to substitute IN the array not the string!
|
// but that means we need to substitute IN the array not the string!
|
||||||
for (auto& i : prog_args) {
|
for (auto& i : prog_args) {
|
||||||
if (i.contains("%"))
|
if (i.contains("%"))
|
||||||
i.replace(QRegExp("(\\%.)"), m_tempFile);
|
i.replace(regexp, m_tempFile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we really should append the file name if there
|
// we really should append the file name if there
|
||||||
@@ -174,7 +176,9 @@ void AppLauncherWidget::searchChanged(const QString& text)
|
|||||||
m_tabWidget->hide();
|
m_tabWidget->hide();
|
||||||
m_filterList->show();
|
m_filterList->show();
|
||||||
m_filterList->clear();
|
m_filterList->clear();
|
||||||
QRegExp regexp(text, Qt::CaseInsensitive, QRegExp::Wildcard);
|
const QRegularExpression regexp(
|
||||||
|
QRegularExpression::wildcardToRegularExpression(text),
|
||||||
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
QVector<DesktopAppData> apps;
|
QVector<DesktopAppData> apps;
|
||||||
|
|
||||||
for (auto const& i : catIconNames.toStdMap()) {
|
for (auto const& i : catIconNames.toStdMap()) {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ bool PinWidget::scrollEvent(QWheelEvent* event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinWidget::enterEvent(QEvent*)
|
void PinWidget::enterEvent(QEnterEvent*)
|
||||||
{
|
{
|
||||||
m_shadowEffect->setColor(m_hoverColor);
|
m_shadowEffect->setColor(m_hoverColor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ protected:
|
|||||||
void mousePressEvent(QMouseEvent*) override;
|
void mousePressEvent(QMouseEvent*) override;
|
||||||
void mouseMoveEvent(QMouseEvent*) override;
|
void mouseMoveEvent(QMouseEvent*) override;
|
||||||
void keyPressEvent(QKeyEvent*) override;
|
void keyPressEvent(QKeyEvent*) override;
|
||||||
void enterEvent(QEvent*) override;
|
void enterEvent(QEnterEvent*) override;
|
||||||
void leaveEvent(QEvent*) override;
|
void leaveEvent(QEvent*) override;
|
||||||
|
|
||||||
bool event(QEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ AbstractLogger& AbstractLogger::sendMessage(const QString& msg, Channel channel)
|
|||||||
msg, messageHeader(channel, Notification), m_notificationPath);
|
msg, messageHeader(channel, Notification), m_notificationPath);
|
||||||
}
|
}
|
||||||
if (!m_textStreams.isEmpty()) {
|
if (!m_textStreams.isEmpty()) {
|
||||||
foreach (auto* stream, m_textStreams) {
|
for (auto* stream : m_textStreams) {
|
||||||
*stream << messageHeader(channel, String) << msg << "\n";
|
*stream << messageHeader(channel, String) << msg << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ QString ConfigHandler::filenamePatternDefault()
|
|||||||
|
|
||||||
void ConfigHandler::setDefaultSettings()
|
void ConfigHandler::setDefaultSettings()
|
||||||
{
|
{
|
||||||
foreach (const QString& key, m_settings.allKeys()) {
|
for (const auto& key : m_settings.allKeys()) {
|
||||||
if (isShortcut(key)) {
|
if (isShortcut(key)) {
|
||||||
// Do not reset Shortcuts
|
// Do not reset Shortcuts
|
||||||
continue;
|
continue;
|
||||||
@@ -486,25 +486,15 @@ void ConfigHandler::resetValue(const QString& key)
|
|||||||
|
|
||||||
QSet<QString>& ConfigHandler::recognizedGeneralOptions()
|
QSet<QString>& ConfigHandler::recognizedGeneralOptions()
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
||||||
auto keys = ::recognizedGeneralOptions.keys();
|
auto keys = ::recognizedGeneralOptions.keys();
|
||||||
static QSet<QString> options = QSet<QString>(keys.begin(), keys.end());
|
static QSet<QString> options = QSet<QString>(keys.begin(), keys.end());
|
||||||
#else
|
|
||||||
static QSet<QString> options =
|
|
||||||
QSet<QString>::fromList(::recognizedGeneralOptions.keys());
|
|
||||||
#endif
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<QString>& ConfigHandler::recognizedShortcutNames()
|
QSet<QString>& ConfigHandler::recognizedShortcutNames()
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
||||||
auto keys = recognizedShortcuts.keys();
|
auto keys = recognizedShortcuts.keys();
|
||||||
static QSet<QString> names = QSet<QString>(keys.begin(), keys.end());
|
static QSet<QString> names = QSet<QString>(keys.begin(), keys.end());
|
||||||
#else
|
|
||||||
static QSet<QString> names =
|
|
||||||
QSet<QString>::fromList(recognizedShortcuts.keys());
|
|
||||||
#endif
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
int GlobalValues::buttonBaseSize()
|
int GlobalValues::buttonBaseSize()
|
||||||
{
|
{
|
||||||
return QApplication::fontMetrics().lineSpacing() * 2.2;
|
return QFontMetrics(qApp->font()).lineSpacing() * 2.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GlobalValues::versionInfo()
|
QString GlobalValues::versionInfo()
|
||||||
@@ -32,4 +32,4 @@ QString GlobalValues::iconPathPNG()
|
|||||||
#else
|
#else
|
||||||
return { ":img/app/flameshot.png" };
|
return { ":img/app/flameshot.png" };
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const QList<QString>& History::history()
|
|||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
int max = ConfigHandler().uploadHistoryMax();
|
int max = ConfigHandler().uploadHistoryMax();
|
||||||
m_thumbs.clear();
|
m_thumbs.clear();
|
||||||
foreach (QString fileName, images) {
|
for (const auto& fileName : images) {
|
||||||
if (++cnt <= max) {
|
if (++cnt <= max) {
|
||||||
m_thumbs.append(fileName);
|
m_thumbs.append(fileName);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "src/utils/filenamehandler.h"
|
#include "src/utils/filenamehandler.h"
|
||||||
#include "src/utils/systemnotification.h"
|
#include "src/utils/systemnotification.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
@@ -141,10 +140,12 @@ void ScreenGrabber::freeDesktopPortal(bool& ok, QPixmap& res)
|
|||||||
QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
|
QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
|
||||||
{
|
{
|
||||||
ok = true;
|
ok = true;
|
||||||
|
int wid = 0;
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
||||||
QPixmap screenPixmap(
|
QPixmap screenPixmap(
|
||||||
currentScreen->grabWindow(QApplication::desktop()->winId(),
|
currentScreen->grabWindow(wid,
|
||||||
currentScreen->geometry().x(),
|
currentScreen->geometry().x(),
|
||||||
currentScreen->geometry().y(),
|
currentScreen->geometry().y(),
|
||||||
currentScreen->geometry().width(),
|
currentScreen->geometry().width(),
|
||||||
@@ -205,13 +206,8 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
|
|||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) || defined(Q_OS_WIN)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) || defined(Q_OS_WIN)
|
||||||
QRect geometry = desktopGeometry();
|
QRect geometry = desktopGeometry();
|
||||||
QPixmap p(QApplication::primaryScreen()->grabWindow(
|
QPixmap p(QApplication::primaryScreen()->grabWindow(
|
||||||
QApplication::desktop()->winId(),
|
wid, geometry.x(), geometry.y(), geometry.width(), geometry.height()));
|
||||||
geometry.x(),
|
QScreen* screen = qApp->screenAt(QCursor::pos());
|
||||||
geometry.y(),
|
|
||||||
geometry.width(),
|
|
||||||
geometry.height()));
|
|
||||||
auto screenNumber = QApplication::desktop()->screenNumber();
|
|
||||||
QScreen* screen = QApplication::screens()[screenNumber];
|
|
||||||
p.setDevicePixelRatio(screen->devicePixelRatio());
|
p.setDevicePixelRatio(screen->devicePixelRatio());
|
||||||
return p;
|
return p;
|
||||||
#endif
|
#endif
|
||||||
@@ -251,11 +247,8 @@ QPixmap ScreenGrabber::grabScreen(QScreen* screen, bool& ok)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ok = true;
|
ok = true;
|
||||||
return screen->grabWindow(QApplication::desktop()->winId(),
|
return screen->grabWindow(
|
||||||
geometry.x(),
|
0, geometry.x(), geometry.y(), geometry.width(), geometry.height());
|
||||||
geometry.y(),
|
|
||||||
geometry.width(),
|
|
||||||
geometry.height());
|
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ QString ShowSaveFileDialog(const QString& title, const QString& directory)
|
|||||||
|
|
||||||
// Build string list of supported image formats
|
// Build string list of supported image formats
|
||||||
QStringList mimeTypeList;
|
QStringList mimeTypeList;
|
||||||
foreach (auto mimeType, QImageWriter::supportedMimeTypes()) {
|
for (const auto& mimeType : QImageWriter::supportedMimeTypes()) {
|
||||||
// image/heif has several aliases and they cause glitch in save dialog
|
// image/heif has several aliases and they cause glitch in save dialog
|
||||||
// It is necessary to keep the image/heif (otherwise HEIF plug-in from
|
// It is necessary to keep the image/heif (otherwise HEIF plug-in from
|
||||||
// kimageformats will not work) but the aliases could be filtered out.
|
// kimageformats will not work) but the aliases could be filtered out.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QImageWriter>
|
#include <QImageWriter>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
@@ -96,8 +97,13 @@ Color::Color(QColor def)
|
|||||||
bool Color::check(const QVariant& val)
|
bool Color::check(const QVariant& val)
|
||||||
{
|
{
|
||||||
QString str = val.toString();
|
QString str = val.toString();
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
bool validColor = QColor::isValidColor(str);
|
||||||
|
#else
|
||||||
|
bool validColor = QColor::isValidColorName(str);
|
||||||
|
#endif
|
||||||
// Disable #RGB, #RRRGGGBBB and #RRRRGGGGBBBB formats that QColor supports
|
// Disable #RGB, #RRRGGGBBB and #RRRRGGGGBBBB formats that QColor supports
|
||||||
return QColor::isValidColor(str) &&
|
return validColor &&
|
||||||
(str[0] != '#' ||
|
(str[0] != '#' ||
|
||||||
(str.length() != 4 && str.length() != 10 && str.length() != 13));
|
(str.length() != 4 && str.length() != 10 && str.length() != 13));
|
||||||
}
|
}
|
||||||
@@ -235,8 +241,7 @@ QVariant KeySequence::process(const QVariant& val)
|
|||||||
}
|
}
|
||||||
if (str.length() > 0) {
|
if (str.length() > 0) {
|
||||||
// Make the "main" key in sequence (last one) lower-case.
|
// Make the "main" key in sequence (last one) lower-case.
|
||||||
const QCharRef& lastChar = str[str.length() - 1];
|
str[str.length() - 1] = str[str.length() - 1].toLower();
|
||||||
str.replace(str.length() - 1, 1, lastChar.toLower());
|
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -245,7 +250,7 @@ QVariant KeySequence::process(const QVariant& val)
|
|||||||
|
|
||||||
bool ExistingDir::check(const QVariant& val)
|
bool ExistingDir::check(const QVariant& val)
|
||||||
{
|
{
|
||||||
if (!val.canConvert(QVariant::String) || val.toString().isEmpty()) {
|
if (!val.canConvert<QString>() || val.toString().isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
QFileInfo info(val.toString());
|
QFileInfo info(val.toString());
|
||||||
@@ -396,11 +401,15 @@ bool UserColors::check(const QVariant& val)
|
|||||||
if (!val.isValid()) {
|
if (!val.isValid()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!val.canConvert(QVariant::StringList)) {
|
if (!val.canConvert<QStringList>()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (const QString& str : val.toStringList()) {
|
for (const QString& str : val.toStringList()) {
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
if (!QColor::isValidColor(str) && str != "picker") {
|
if (!QColor::isValidColor(str) && str != "picker") {
|
||||||
|
#else
|
||||||
|
if (!QColor::isValidColorName(str) && str != "picker") {
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,7 +479,7 @@ QVariant UserColors::representation(const QVariant& val)
|
|||||||
|
|
||||||
bool SaveFileExtension::check(const QVariant& val)
|
bool SaveFileExtension::check(const QVariant& val)
|
||||||
{
|
{
|
||||||
if (!val.canConvert(QVariant::String) || val.toString().isEmpty()) {
|
if (!val.canConvert<QString>() || val.toString().isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -481,7 +490,7 @@ bool SaveFileExtension::check(const QVariant& val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QStringList imageFormatList;
|
QStringList imageFormatList;
|
||||||
foreach (auto imageFormat, QImageWriter::supportedImageFormats())
|
for (const auto& imageFormat : QImageWriter::supportedImageFormats())
|
||||||
imageFormatList.append(imageFormat);
|
imageFormatList.append(imageFormat);
|
||||||
|
|
||||||
if (!imageFormatList.contains(extension)) {
|
if (!imageFormatList.contains(extension)) {
|
||||||
@@ -533,32 +542,33 @@ QVariant Region::process(const QVariant& val)
|
|||||||
return ScreenGrabber().desktopGeometry();
|
return ScreenGrabber().desktopGeometry();
|
||||||
} else if (str.startsWith("screen")) {
|
} else if (str.startsWith("screen")) {
|
||||||
bool ok;
|
bool ok;
|
||||||
int number = str.midRef(6).toInt(&ok);
|
int number = str.mid(6).toInt(&ok);
|
||||||
if (!ok || number < 0) {
|
if (!ok || number < 0) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return ScreenGrabber().screenGeometry(qApp->screens()[number]);
|
return ScreenGrabber().screenGeometry(qApp->screens()[number]);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegExp regex("(-{,1}\\d+)" // number (any sign)
|
static const QRegularExpression regex(
|
||||||
"[x,\\.\\s]" // separator ('x', ',', '.', or whitespace)
|
"(-{,1}\\d+)" // number (any sign)
|
||||||
"(-{,1}\\d+)" // number (any sign)
|
"[x,\\.\\s]" // separator ('x', ',', '.', or whitespace)
|
||||||
"[\\+,\\.\\s]*" // separator ('+',',', '.', or whitespace)
|
"(-{,1}\\d+)" // number (any sign)
|
||||||
"(-{,1}\\d+)" // number (non-negative)
|
"[\\+,\\.\\s]*" // separator ('+',',', '.', or whitespace)
|
||||||
"[\\+,\\.\\s]*" // separator ('+', ',', '.', or whitespace)
|
"(-{,1}\\d+)" // number (non-negative)
|
||||||
"(-{,1}\\d+)" // number (non-negative)
|
"[\\+,\\.\\s]*" // separator ('+', ',', '.', or whitespace)
|
||||||
|
"(-{,1}\\d+)" // number (non-negative)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!regex.exactMatch(str)) {
|
if (!regex.match(str).hasMatch()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int w, h, x, y;
|
int w, h, x, y;
|
||||||
bool w_ok, h_ok, x_ok, y_ok;
|
bool w_ok, h_ok, x_ok, y_ok;
|
||||||
w = regex.cap(1).toInt(&w_ok);
|
w = regex.match(str).captured(1).toInt(&w_ok);
|
||||||
h = regex.cap(2).toInt(&h_ok);
|
h = regex.match(str).captured(2).toInt(&h_ok);
|
||||||
x = regex.cap(3).toInt(&x_ok);
|
x = regex.match(str).captured(3).toInt(&x_ok);
|
||||||
y = regex.cap(4).toInt(&y_ok);
|
y = regex.match(str).captured(4).toInt(&y_ok);
|
||||||
|
|
||||||
if (!(w_ok && h_ok && x_ok && y_ok)) {
|
if (!(w_ok && h_ok && x_ok && y_ok)) {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -1221,10 +1220,6 @@ void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion,
|
|||||||
}
|
}
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
int ax = (width() - m_updateNotificationWidget->width()) / 2;
|
int ax = (width() - m_updateNotificationWidget->width()) / 2;
|
||||||
#elif (defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
|
|
||||||
QRect helpRect = QGuiApplication::primaryScreen()->geometry();
|
|
||||||
int ax = helpRect.left() +
|
|
||||||
((helpRect.width() - m_updateNotificationWidget->width()) / 2);
|
|
||||||
#else
|
#else
|
||||||
QRect helpRect;
|
QRect helpRect;
|
||||||
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen();
|
||||||
@@ -1279,7 +1274,7 @@ void CaptureWidget::initSelection()
|
|||||||
if (!initialSelection.isNull()) {
|
if (!initialSelection.isNull()) {
|
||||||
const qreal scale = m_context.screenshot.devicePixelRatio();
|
const qreal scale = m_context.screenshot.devicePixelRatio();
|
||||||
initialSelection.moveTopLeft(initialSelection.topLeft() -
|
initialSelection.moveTopLeft(initialSelection.topLeft() -
|
||||||
mapToGlobal({}));
|
mapToGlobal(QPoint(0, 0)));
|
||||||
initialSelection.setTop(initialSelection.top() / scale);
|
initialSelection.setTop(initialSelection.top() / scale);
|
||||||
initialSelection.setBottom(initialSelection.bottom() / scale);
|
initialSelection.setBottom(initialSelection.bottom() / scale);
|
||||||
initialSelection.setLeft(initialSelection.left() / scale);
|
initialSelection.setLeft(initialSelection.left() / scale);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ NotifierBox::NotifierBox(QWidget* parent)
|
|||||||
setFixedSize(QSize(size, size));
|
setFixedSize(QSize(size, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifierBox::enterEvent(QEvent*)
|
void NotifierBox::enterEvent(QEnterEvent*)
|
||||||
{
|
{
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
explicit NotifierBox(QWidget* parent = nullptr);
|
explicit NotifierBox(QWidget* parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void enterEvent(QEvent*) override;
|
void enterEvent(QEnterEvent*) override;
|
||||||
virtual void paintEvent(QPaintEvent*) override;
|
virtual void paintEvent(QPaintEvent*) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ OverlayMessage::OverlayMessage(QWidget* parent, const QRect& targetArea)
|
|||||||
setStyleSheet(
|
setStyleSheet(
|
||||||
QStringLiteral("QLabel { color: %1; }").arg(m_textColor.name()));
|
QStringLiteral("QLabel { color: %1; }").arg(m_textColor.name()));
|
||||||
|
|
||||||
setMargin(QApplication::fontMetrics().height() / 2);
|
setMargin(QFontMetrics(qApp->font()).height() / 2);
|
||||||
QWidget::hide();
|
QWidget::hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,10 @@ InfoWindow::InfoWindow(QWidget* parent)
|
|||||||
connect(
|
connect(
|
||||||
ui->CopyInfoButton, &QPushButton::clicked, this, &InfoWindow::copyInfo);
|
ui->CopyInfoButton, &QPushButton::clicked, this, &InfoWindow::copyInfo);
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
||||||
QRect position = frameGeometry();
|
QRect position = frameGeometry();
|
||||||
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
|
QScreen* screen = QGuiAppCurrentScreen().currentScreen();
|
||||||
position.moveCenter(screen->availableGeometry().center());
|
position.moveCenter(screen->availableGeometry().center());
|
||||||
move(position.topLeft());
|
move(position.topLeft());
|
||||||
#endif
|
|
||||||
|
|
||||||
show();
|
show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ LoadSpinner::LoadSpinner(QWidget* parent)
|
|||||||
, m_growing(true)
|
, m_growing(true)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
const int size = QApplication::fontMetrics().height() * 8;
|
const int size = QFontMetrics(qApp->font()).height() * 8;
|
||||||
setFixedSize(size, size);
|
setFixedSize(size, size);
|
||||||
updateFrame();
|
updateFrame();
|
||||||
// init timer
|
// init timer
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent)
|
|||||||
&SidePanelWidget::onToolSizeChanged);
|
&SidePanelWidget::onToolSizeChanged);
|
||||||
// color hex editor sigslots
|
// color hex editor sigslots
|
||||||
connect(m_colorHex, &QLineEdit::editingFinished, this, [=]() {
|
connect(m_colorHex, &QLineEdit::editingFinished, this, [=]() {
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
if (!QColor::isValidColor(m_colorHex->text())) {
|
if (!QColor::isValidColor(m_colorHex->text())) {
|
||||||
|
#else
|
||||||
|
if (!QColor::isValidColorName(m_colorHex->text())) {
|
||||||
|
#endif
|
||||||
m_colorHex->setText(m_color.name(QColor::HexRgb));
|
m_colorHex->setText(m_color.name(QColor::HexRgb));
|
||||||
} else {
|
} else {
|
||||||
emit colorChanged(m_colorHex->text());
|
emit colorChanged(m_colorHex->text());
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "uploadlineitem.h"
|
#include "uploadlineitem.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
@@ -37,7 +36,6 @@ UploadHistory::UploadHistory(QWidget* parent)
|
|||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
resize(QDesktopWidget().availableGeometry(this).size() * 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UploadHistory::loadHistory()
|
void UploadHistory::loadHistory()
|
||||||
@@ -50,7 +48,7 @@ void UploadHistory::loadHistory()
|
|||||||
if (historyFiles.isEmpty()) {
|
if (historyFiles.isEmpty()) {
|
||||||
setEmptyMessage();
|
setEmptyMessage();
|
||||||
} else {
|
} else {
|
||||||
foreach (QString fileName, historyFiles) {
|
for (const auto& fileName : historyFiles) {
|
||||||
addLine(history.path(), fileName);
|
addLine(history.path(), fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user