mirror of
https://github.com/fergalmoran/flameshot.git
synced 2026-01-03 23:55:17 +00:00
make pin moving compatible with Wayland on Qt6 (#4000)
* make pin moving compatible with Wayland on Qt6 * found more to clean up
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <QGraphicsDropShadowEffect>
|
#include <QGraphicsDropShadowEffect>
|
||||||
#include <QGraphicsOpacityEffect>
|
#include <QGraphicsOpacityEffect>
|
||||||
#include <QPinchGesture>
|
#include <QPinchGesture>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
#include "pinwidget.h"
|
#include "pinwidget.h"
|
||||||
#include "qguiappcurrentscreen.h"
|
#include "qguiappcurrentscreen.h"
|
||||||
@@ -34,12 +35,11 @@ PinWidget::PinWidget(const QPixmap& pixmap,
|
|||||||
, m_shadowEffect(new QGraphicsDropShadowEffect(this))
|
, m_shadowEffect(new QGraphicsDropShadowEffect(this))
|
||||||
{
|
{
|
||||||
setWindowIcon(QIcon(GlobalValues::iconPath()));
|
setWindowIcon(QIcon(GlobalValues::iconPath()));
|
||||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint |
|
||||||
|
Qt::Dialog);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
// set the bottom widget background transparent
|
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
setWindowTitle("flameshot-pin");
|
|
||||||
ConfigHandler conf;
|
ConfigHandler conf;
|
||||||
m_baseColor = conf.uiColor();
|
m_baseColor = conf.uiColor();
|
||||||
m_hoverColor = conf.contrastUiColor();
|
m_hoverColor = conf.contrastUiColor();
|
||||||
@@ -69,10 +69,6 @@ PinWidget::PinWidget(const QPixmap& pixmap,
|
|||||||
static_cast<int>(static_cast<double>(MARGIN) * devicePixelRatio);
|
static_cast<int>(static_cast<double>(MARGIN) * devicePixelRatio);
|
||||||
QRect adjusted_pos = geometry + QMargins(margin, margin, margin, margin);
|
QRect adjusted_pos = geometry + QMargins(margin, margin, margin, margin);
|
||||||
setGeometry(adjusted_pos);
|
setGeometry(adjusted_pos);
|
||||||
#if defined(Q_OS_LINUX)
|
|
||||||
setWindowFlags(Qt::X11BypassWindowManagerHint);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
|
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
|
||||||
if (currentScreen != nullptr) {
|
if (currentScreen != nullptr) {
|
||||||
QPoint topLeft = currentScreen->geometry().topLeft();
|
QPoint topLeft = currentScreen->geometry().topLeft();
|
||||||
@@ -152,19 +148,13 @@ void PinWidget::mouseDoubleClickEvent(QMouseEvent*)
|
|||||||
|
|
||||||
void PinWidget::mousePressEvent(QMouseEvent* e)
|
void PinWidget::mousePressEvent(QMouseEvent* e)
|
||||||
{
|
{
|
||||||
m_dragStart = e->globalPosition();
|
if (QWindow* window = windowHandle(); window != nullptr) {
|
||||||
m_offsetX = e->position().x() / width();
|
window->startSystemMove();
|
||||||
m_offsetY = e->position().y() / height();
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinWidget::mouseMoveEvent(QMouseEvent* e)
|
void PinWidget::mouseMoveEvent(QMouseEvent* e) {}
|
||||||
{
|
|
||||||
const QPointF delta = e->globalPosition() - m_dragStart;
|
|
||||||
const int offsetW = width() * m_offsetX;
|
|
||||||
const int offsetH = height() * m_offsetY;
|
|
||||||
move(m_dragStart.x() + delta.x() - offsetW,
|
|
||||||
m_dragStart.y() + delta.y() - offsetH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PinWidget::keyPressEvent(QKeyEvent* event)
|
void PinWidget::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ private:
|
|||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
QVBoxLayout* m_layout;
|
QVBoxLayout* m_layout;
|
||||||
QLabel* m_label;
|
QLabel* m_label;
|
||||||
QPointF m_dragStart;
|
|
||||||
qreal m_offsetX{}, m_offsetY{};
|
|
||||||
QGraphicsDropShadowEffect* m_shadowEffect;
|
QGraphicsDropShadowEffect* m_shadowEffect;
|
||||||
QColor m_baseColor, m_hoverColor;
|
QColor m_baseColor, m_hoverColor;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user