resolving merge conflicts

This commit is contained in:
Jeremy Borgman
2021-01-08 09:58:52 -06:00
90 changed files with 7190 additions and 3036 deletions

View File

@@ -12,6 +12,7 @@ target_sources(
notificationwidget.h
orientablepushbutton.h
historywidget.h
updatenotificationwidget.h
)
target_sources(
@@ -24,4 +25,5 @@ target_sources(
notificationwidget.cpp
orientablepushbutton.cpp
historywidget.cpp
updatenotificationwidget.cpp
)

View File

@@ -115,27 +115,32 @@ void CaptureToolButton::setColor(const QColor& c)
QColor CaptureToolButton::m_mainColor = ConfigHandler().uiMainColorValue();
static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder{
static std::map<CaptureToolButton::ButtonType, int> buttonTypeOrder
{
{ CaptureToolButton::TYPE_PENCIL, 0 },
{ CaptureToolButton::TYPE_DRAWER, 1 },
{ CaptureToolButton::TYPE_ARROW, 2 },
{ CaptureToolButton::TYPE_SELECTION, 3 },
{ CaptureToolButton::TYPE_RECTANGLE, 4 },
{ CaptureToolButton::TYPE_CIRCLE, 5 },
{ CaptureToolButton::TYPE_MARKER, 6 },
{ CaptureToolButton::TYPE_TEXT, 7 },
{ CaptureToolButton::TYPE_PIXELATE, 8 },
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
{ CaptureToolButton::TYPE_UNDO, 12 },
{ CaptureToolButton::TYPE_REDO, 13 },
{ CaptureToolButton::TYPE_COPY, 14 },
{ CaptureToolButton::TYPE_SAVE, 15 },
{ CaptureToolButton::TYPE_EXIT, 16 },
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 17 },
{ CaptureToolButton::TYPE_OPEN_APP, 18 },
{ CaptureToolButton::TYPE_PIN, 19 },
{ CaptureToolButton::TYPE_DRAWER, 1 },
{ CaptureToolButton::TYPE_ARROW, 2 },
{ CaptureToolButton::TYPE_SELECTION, 3 },
{ CaptureToolButton::TYPE_RECTANGLE, 4 },
{ CaptureToolButton::TYPE_CIRCLE, 5 },
{ CaptureToolButton::TYPE_MARKER, 6 },
{ CaptureToolButton::TYPE_TEXT, 7 },
{ CaptureToolButton::TYPE_PIXELATE, 8 },
{ CaptureToolButton::TYPE_CIRCLECOUNT, 9 },
{ CaptureToolButton::TYPE_SELECTIONINDICATOR, 10 },
{ CaptureToolButton::TYPE_MOVESELECTION, 11 },
{ CaptureToolButton::TYPE_UNDO, 12 },
{ CaptureToolButton::TYPE_REDO, 13 },
{ CaptureToolButton::TYPE_COPY, 14 },
{ CaptureToolButton::TYPE_SAVE, 15 },
{ CaptureToolButton::TYPE_IMAGEUPLOADER, 16 },
#if not(defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
{ CaptureToolButton::TYPE_OPEN_APP, 17 },
{ CaptureToolButton::TYPE_EXIT, 18 }, { CaptureToolButton::TYPE_PIN, 19 },
#else
{ CaptureToolButton::TYPE_EXIT, 17 }, { CaptureToolButton::TYPE_PIN, 18 },
#endif
};
int CaptureToolButton::getPriorityByButton(CaptureToolButton::ButtonType b)
@@ -164,7 +169,10 @@ QVector<CaptureToolButton::ButtonType>
CaptureToolButton::TYPE_SAVE,
CaptureToolButton::TYPE_EXIT,
CaptureToolButton::TYPE_IMAGEUPLOADER,
#if not(defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
CaptureToolButton::TYPE_OPEN_APP,
#endif
CaptureToolButton::TYPE_PIN,
CaptureToolButton::TYPE_CIRCLECOUNT,
};

View File

@@ -53,8 +53,7 @@ public:
TYPE_REDO = 16,
TYPE_PIN = 17,
TYPE_TEXT = 18,
TYPE_CIRCLECOUNT = 19,
TYPE_CIRCLECOUNT = 19
};
Q_ENUM(ButtonType)

View File

@@ -36,7 +36,9 @@
#include "src/widgets/capture/notifierbox.h"
#include "src/widgets/orientablepushbutton.h"
#include "src/widgets/panel/sidepanelwidget.h"
#include "src/widgets/updatenotificationwidget.h"
#include <QApplication>
#include <QDateTime>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QPaintEvent>
@@ -70,6 +72,8 @@ CaptureWidget::CaptureWidget(const uint id,
, m_toolWidget(nullptr)
, m_mouseOverHandle(SelectionWidget::NO_SIDE)
, m_id(id)
, m_lastMouseWheel(0)
, m_updateNotificationWidget(nullptr)
{
// Base config of the widget
m_eventFilter = new HoverEventFilter(this);
@@ -88,7 +92,8 @@ CaptureWidget::CaptureWidget(const uint id,
initContext(savePath, fullScreen);
initShortcuts();
m_context.circleCount = 1;
#ifdef Q_OS_WIN
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_MAC64) || \
defined(Q_OS_MACOS) || defined(Q_OS_MACX))
// Top left of the whole set of screens
QPoint topLeft(0, 0);
#endif
@@ -102,7 +107,7 @@ CaptureWidget::CaptureWidget(const uint id,
}
m_context.origScreenshot = m_context.screenshot;
#ifdef Q_OS_WIN
#if defined(Q_OS_WIN)
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint |
Qt::Popup);
@@ -117,11 +122,24 @@ CaptureWidget::CaptureWidget(const uint id,
}
}
move(topLeft);
resize(pixmap().size());
#elif (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
// Emulate fullscreen mode
// setWindowFlags(Qt::WindowStaysOnTopHint |
// Qt::BypassWindowManagerHint |
// Qt::FramelessWindowHint |
// Qt::NoDropShadowWindowHint | Qt::ToolTip |
// Qt::Popup
// );
QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos());
move(currentScreen->geometry().x(), currentScreen->geometry().y());
resize(currentScreen->size());
#else
setWindowFlags(Qt::BypassWindowManagerHint | Qt::WindowStaysOnTopHint |
Qt::FramelessWindowHint | Qt::Tool);
#endif
resize(pixmap().size());
#endif
}
// Create buttons
m_buttonHandler = new ButtonHandler(this);
@@ -132,7 +150,7 @@ CaptureWidget::CaptureWidget(const uint id,
QRect r = screen->geometry();
r.moveTo(r.x() / screen->devicePixelRatio(),
r.y() / screen->devicePixelRatio());
#ifdef Q_OS_WIN
#if defined(Q_OS_WIN)
r.moveTo(r.topLeft() - topLeft);
#endif
areas.append(r);
@@ -304,7 +322,19 @@ void CaptureWidget::paintEvent(QPaintEvent*)
painter.setClipRect(rect());
if (m_showInitialMsg) {
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
QRect helpRect;
QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos());
if (currentScreen) {
helpRect = currentScreen->geometry();
} else {
helpRect = QGuiApplication::primaryScreen()->geometry();
}
#else
QRect helpRect = QGuiApplication::primaryScreen()->geometry();
#endif
helpRect.moveTo(mapFromGlobal(helpRect.topLeft()));
QString helpTxt =
@@ -606,7 +636,36 @@ void CaptureWidget::keyReleaseEvent(QKeyEvent* e)
void CaptureWidget::wheelEvent(QWheelEvent* e)
{
m_context.thickness += e->angleDelta().y() / 120;
/* Mouse scroll usually gives value 120, not more or less, just how many
* times.
* Touchpad gives the value 2 or more (usually 2-8), it doesn't give
* too big values like mouse wheel on normal scrolling, so it is almost
* impossible to scroll. It's easier to calculate number of requests and do
* not accept events faster that one in 200ms.
* */
int thicknessOffset = 0;
if (e->angleDelta().y() >= 60) {
// mouse scroll (wheel) increment
thicknessOffset = 1;
} else if (e->angleDelta().y() <= -60) {
// mouse scroll (wheel) decrement
thicknessOffset = -1;
} else {
// touchpad scroll
qint64 current = QDateTime::currentMSecsSinceEpoch();
if ((current - m_lastMouseWheel) > 200) {
if (e->angleDelta().y() > 0) {
thicknessOffset = 1;
} else if (e->angleDelta().y() < 0) {
thicknessOffset = -1;
}
m_lastMouseWheel = current;
} else {
return;
}
}
m_context.thickness += thicknessOffset;
m_context.thickness = qBound(0, m_context.thickness, 100);
QPoint topLeft =
qApp->desktop()
@@ -681,10 +740,19 @@ void CaptureWidget::initPanel()
}
m_panel = new UtilityPanel(this);
m_panel->hide();
makeChild(m_panel);
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos());
panelRect.moveTo(mapFromGlobal(panelRect.topLeft()));
m_panel->setFixedWidth(m_colorPicker->width() * 1.5);
m_panel->setFixedHeight(currentScreen->geometry().height());
#else
panelRect.moveTo(mapFromGlobal(panelRect.topLeft()));
panelRect.setWidth(m_colorPicker->width() * 1.5);
m_panel->setGeometry(panelRect);
#endif
SidePanelWidget* sidePanel = new SidePanelWidget(&m_context.screenshot);
connect(sidePanel,
@@ -711,6 +779,26 @@ void CaptureWidget::initPanel()
m_panel->pushWidget(new QUndoView(&m_undoStack, this));
}
void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion,
const QString& appLatestUrl)
{
if (nullptr == m_updateNotificationWidget) {
m_updateNotificationWidget =
new UpdateNotificationWidget(this, appLatestVersion, appLatestUrl);
}
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
int ax = (width() - m_updateNotificationWidget->width()) / 2;
#else
QRect helpRect = QGuiApplication::primaryScreen()->geometry();
int ax = helpRect.left() +
((helpRect.width() - m_updateNotificationWidget->width()) / 2);
#endif
m_updateNotificationWidget->move(ax, 0);
makeChild(m_updateNotificationWidget);
m_updateNotificationWidget->show();
}
void CaptureWidget::initSelection()
{
m_selection = new SelectionWidget(m_uiColor, this);
@@ -1101,6 +1189,10 @@ void CaptureWidget::copyScreenshot()
void CaptureWidget::saveScreenshot()
{
#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \
defined(Q_OS_MACX))
showNormal();
#endif
m_captureDone = true;
if (m_activeTool != nullptr) {
QPainter painter(&m_context.screenshot);

View File

@@ -44,6 +44,7 @@ class QNetworkReply;
class ColorPicker;
class NotifierBox;
class HoverEventFilter;
class UpdateNotificationWidget;
class CaptureWidget : public QWidget
{
@@ -58,6 +59,8 @@ public:
void updateButtons();
QPixmap pixmap();
void showAppUpdateNotification(const QString& appLatestVersion,
const QString& appLatestUrl);
public slots:
bool commitCurrentTool();
@@ -149,6 +152,8 @@ private:
QRect extendedRect(QRect* r) const;
private:
UpdateNotificationWidget* m_updateNotificationWidget;
quint64 m_lastMouseWheel;
QUndoStack m_undoStack;
QPointer<CaptureToolButton> m_sizeIndButton;
// Last pressed button

View File

@@ -73,6 +73,8 @@ bool DraggableWidgetMaker::eventFilter(QObject* obj, QEvent* event)
return true;
}
} break;
default:
break;
}
return QObject::eventFilter(obj, event);

View File

@@ -100,6 +100,8 @@ void HistoryWidget::addLine(const QString& path, const QString& fileName)
QPixmap pixmap;
pixmap.load(fullFileName, "png");
// TODO - remove much later, it is still required to keep old previews works
// fine
if (pixmap.height() / HISTORYPIXMAP_MAX_PREVIEW_HEIGHT >=
pixmap.width() / HISTORYPIXMAP_MAX_PREVIEW_WIDTH) {
pixmap = pixmap.scaledToHeight(HISTORYPIXMAP_MAX_PREVIEW_HEIGHT);

View File

@@ -1,9 +1,6 @@
#ifndef HISTORYWIDGET_H
#define HISTORYWIDGET_H
#define HISTORYPIXMAP_MAX_PREVIEW_WIDTH 160
#define HISTORYPIXMAP_MAX_PREVIEW_HEIGHT 90
#include <QDialog>
#include <QObject>
#include <QString>

View File

@@ -43,7 +43,10 @@ UtilityPanel::UtilityPanel(QWidget* parent)
m_internalPanel,
&QWidget::hide);
hide();
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_MAC64) || \
defined(Q_OS_MACOS) || defined(Q_OS_MACX))
move(0, 0);
#endif
}
QWidget* UtilityPanel::toolWidget() const
@@ -83,6 +86,10 @@ void UtilityPanel::show()
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
m_internalPanel->show();
m_showAnimation->start();
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_MAC64) || \
defined(Q_OS_MACOS) || defined(Q_OS_MACX))
move(0, 0);
#endif
QWidget::show();
}
@@ -134,9 +141,5 @@ void UtilityPanel::initInternalPanel()
m_hide->setText(tr("Hide"));
m_upLayout->addWidget(m_hide);
connect(m_hide, SIGNAL(clicked()), this, SLOT(slotHidePanel()));
}
void UtilityPanel::slotHidePanel()
{
hide();
m_internalPanel->hide();
}

View File

@@ -38,13 +38,8 @@ public:
void hide();
void show();
signals:
void mouseEnter();
void mouseLeave();
public slots:
void toggle();
void slotHidePanel();
private:
void initInternalPanel();

View File

@@ -0,0 +1,144 @@
//
// Created by yuriypuchkov on 09.12.2020.
//
#include "updatenotificationwidget.h"
#include "src/utils/confighandler.h"
#include <QDesktopServices>
#include <QLabel>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QScrollArea>
#include <QTimer>
#include <QVBoxLayout>
#include <QWheelEvent>
UpdateNotificationWidget::UpdateNotificationWidget(
QWidget* parent,
const QString& appLatestVersion,
const QString& appLatestUrl)
: QWidget(parent)
, m_appLatestVersion(appLatestVersion)
, m_appLatestUrl(appLatestUrl)
, m_layout(nullptr)
{
setMinimumSize(400, 100);
initInternalPanel();
setAttribute(Qt::WA_TransparentForMouseEvents);
setCursor(Qt::ArrowCursor);
m_showAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
m_showAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_showAnimation->setDuration(300);
m_hideAnimation = new QPropertyAnimation(m_internalPanel, "geometry", this);
m_hideAnimation->setEasingCurve(QEasingCurve::InOutQuad);
m_hideAnimation->setDuration(300);
connect(m_hideAnimation,
&QPropertyAnimation::finished,
m_internalPanel,
&QWidget::hide);
setAppLatestVersion(appLatestVersion);
}
void UpdateNotificationWidget::show()
{
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(0, -height(), width(), height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
m_internalPanel->show();
m_showAnimation->start();
QWidget::show();
}
void UpdateNotificationWidget::hide()
{
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(0, -height(), 0, height()));
m_hideAnimation->start();
m_internalPanel->hide();
QWidget::hide();
}
void UpdateNotificationWidget::setAppLatestVersion(const QString& latestVersion)
{
m_appLatestVersion = latestVersion;
QString newVersion =
tr("New Flameshot version %1 is available").arg(latestVersion);
m_notification->setText(newVersion);
}
void UpdateNotificationWidget::laterButton()
{
hide();
}
void UpdateNotificationWidget::ignoreButton()
{
ConfigHandler().setIgnoreUpdateToVersion(m_appLatestVersion);
hide();
}
void UpdateNotificationWidget::updateButton()
{
QDesktopServices::openUrl(m_appLatestUrl);
hide();
if (parentWidget()) {
parentWidget()->close();
}
}
void UpdateNotificationWidget::initInternalPanel()
{
m_internalPanel = new QScrollArea(this);
m_internalPanel->setAttribute(Qt::WA_NoMousePropagation);
QWidget* widget = new QWidget();
m_internalPanel->setWidget(widget);
m_internalPanel->setWidgetResizable(true);
QColor bgColor = palette().window().color();
bgColor.setAlphaF(0.0);
m_internalPanel->setStyleSheet(
QStringLiteral("QScrollArea {background-color: %1}").arg(bgColor.name()));
m_internalPanel->hide();
//
m_layout = new QVBoxLayout();
widget->setLayout(m_layout);
// caption
m_notification = new QLabel(m_appLatestVersion, this);
m_layout->addWidget(m_notification);
// buttons layout
QHBoxLayout* buttonsLayout = new QHBoxLayout();
QSpacerItem* bottonsSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding);
buttonsLayout->addSpacerItem(bottonsSpacer);
m_layout->addLayout(buttonsLayout);
// ignore
QPushButton* ignoreBtn = new QPushButton(tr("Ignore"), this);
buttonsLayout->addWidget(ignoreBtn);
connect(ignoreBtn,
&QPushButton::clicked,
this,
&UpdateNotificationWidget::ignoreButton);
// later
QPushButton* laterBtn = new QPushButton(tr("Later"), this);
buttonsLayout->addWidget(laterBtn);
connect(laterBtn,
&QPushButton::clicked,
this,
&UpdateNotificationWidget::laterButton);
// update
QPushButton* updateBtn = new QPushButton(tr("Update"), this);
buttonsLayout->addWidget(updateBtn);
connect(updateBtn,
&QPushButton::clicked,
this,
&UpdateNotificationWidget::updateButton);
}

View File

@@ -0,0 +1,47 @@
//
// Created by yuriypuchkov on 09.12.2020.
//
#ifndef FLAMESHOT_UPDATENOTIFICATIONWIDGET_H
#define FLAMESHOT_UPDATENOTIFICATIONWIDGET_H
#include <QPointer>
#include <QWidget>
class QVBoxLayout;
class QPropertyAnimation;
class QScrollArea;
class QPushButton;
class QLabel;
class UpdateNotificationWidget : public QWidget
{
Q_OBJECT
public:
explicit UpdateNotificationWidget(QWidget* parent,
const QString& appLatestVersion,
const QString& appLatestUrl);
void setAppLatestVersion(const QString& latestVersion);
void hide();
void show();
public slots:
void ignoreButton();
void laterButton();
void updateButton();
private:
void initInternalPanel();
// class members
QString m_appLatestVersion;
QString m_appLatestUrl;
QVBoxLayout* m_layout;
QLabel* m_notification;
QScrollArea* m_internalPanel;
QPropertyAnimation* m_showAnimation;
QPropertyAnimation* m_hideAnimation;
};
#endif // FLAMESHOT_UPDATENOTIFICATIONWIDGET_H