From e4e4da9dbd8ff65f2402703edc53a6b529a324fd Mon Sep 17 00:00:00 2001 From: Jeremy Borgman Date: Mon, 10 Oct 2022 10:04:29 -0500 Subject: [PATCH 1/2] Adding pin transparency --- src/tools/pin/pinwidget.cpp | 32 +++++++++++++++++++++++++++++++- src/tools/pin/pinwidget.h | 5 +++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/tools/pin/pinwidget.cpp b/src/tools/pin/pinwidget.cpp index b173d4ff7f..114e078199 100644 --- a/src/tools/pin/pinwidget.cpp +++ b/src/tools/pin/pinwidget.cpp @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors #include +#include #include #include "pinwidget.h" @@ -38,7 +39,6 @@ PinWidget::PinWidget(const QPixmap& pixmap, // set the bottom widget background transparent setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); - ConfigHandler conf; m_baseColor = conf.uiColor(); m_hoverColor = conf.contrastUiColor(); @@ -49,6 +49,7 @@ PinWidget::PinWidget(const QPixmap& pixmap, m_shadowEffect->setBlurRadius(BLUR_RADIUS); m_shadowEffect->setOffset(0, 0); setGraphicsEffect(m_shadowEffect); + setWindowOpacity(m_opacity); m_label->setPixmap(m_pixmap); m_layout->addWidget(m_label); @@ -189,6 +190,25 @@ void PinWidget::rotateRight() m_pixmap = m_pixmap.transformed(rotateTransform); } +void PinWidget::increaseOpacity() +{ + m_opacity += 0.1; + if (m_opacity > 1.0) { + m_opacity = 1.0; + } + setWindowOpacity(m_opacity); +} + +void PinWidget::decreaseOpacity() +{ + m_opacity -= 0.1; + if (m_opacity < 0.0) { + m_opacity = 0.0; + } + + setWindowOpacity(m_opacity); +} + bool PinWidget::event(QEvent* event) { if (event->type() == QEvent::Gesture) { @@ -268,6 +288,16 @@ void PinWidget::showContextMenu(const QPoint& pos) &rotateLeftAction, &QAction::triggered, this, &PinWidget::rotateLeft); contextMenu.addAction(&rotateLeftAction); + QAction increaseOpacityAction(tr("Increase Opacity"), this); + connect( + &increaseOpacityAction, &QAction::triggered, this, &PinWidget::increaseOpacity); + contextMenu.addAction(&increaseOpacityAction); + + QAction decreaseOpacityAction(tr("Decrease Opacity"), this); + connect( + &decreaseOpacityAction, &QAction::triggered, this, &PinWidget::decreaseOpacity); + contextMenu.addAction(&decreaseOpacityAction); + QAction closePinAction(tr("Close"), this); connect(&closePinAction, &QAction::triggered, this, &PinWidget::closePin); contextMenu.addSeparator(); diff --git a/src/tools/pin/pinwidget.h b/src/tools/pin/pinwidget.h index 9bdff1fdea..603128b984 100644 --- a/src/tools/pin/pinwidget.h +++ b/src/tools/pin/pinwidget.h @@ -38,6 +38,10 @@ class PinWidget : public QWidget void rotateLeft(); void rotateRight(); + void increaseOpacity(); + void decreaseOpacity(); + + QPixmap m_pixmap; QVBoxLayout* m_layout; QLabel* m_label; @@ -48,6 +52,7 @@ class PinWidget : public QWidget bool m_expanding{ false }; qreal m_scaleFactor{ 1 }; + qreal m_opacity {1}; unsigned int m_rotateFactor{ 0 }; qreal m_currentStepScaleFactor{ 1 }; bool m_sizeChanged{ false }; From 3c24fd18f1a754a89425a997e6d1527b3e597b24 Mon Sep 17 00:00:00 2001 From: Jeremy Borgman Date: Wed, 12 Oct 2022 20:07:20 -0500 Subject: [PATCH 2/2] added hotkeys --- src/tools/pin/pinwidget.cpp | 40 ++++++++++++++++++++++++++++++++----- src/tools/pin/pinwidget.h | 4 ++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/tools/pin/pinwidget.cpp b/src/tools/pin/pinwidget.cpp index 114e078199..a315b4c092 100644 --- a/src/tools/pin/pinwidget.cpp +++ b/src/tools/pin/pinwidget.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors - #include #include #include @@ -36,6 +35,7 @@ PinWidget::PinWidget(const QPixmap& pixmap, { setWindowIcon(QIcon(GlobalValues::iconPath())); setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint); + setFocusPolicy(Qt::StrongFocus); // set the bottom widget background transparent setAttribute(Qt::WA_TranslucentBackground); setAttribute(Qt::WA_DeleteOnClose); @@ -166,6 +166,32 @@ void PinWidget::mouseMoveEvent(QMouseEvent* e) m_dragStart.y() + delta.y() - offsetH); } +void PinWidget::keyPressEvent(QKeyEvent* event) +{ + if (event->key() == Qt::Key_0) { + m_opacity = 1.0; + } else if (event->key() == Qt::Key_9) { + m_opacity = 0.9; + } else if (event->key() == Qt::Key_8) { + m_opacity = 0.8; + } else if (event->key() == Qt::Key_7) { + m_opacity = 0.7; + } else if (event->key() == Qt::Key_6) { + m_opacity = 0.6; + } else if (event->key() == Qt::Key_5) { + m_opacity = 0.5; + } else if (event->key() == Qt::Key_4) { + m_opacity = 0.4; + } else if (event->key() == Qt::Key_3) { + m_opacity = 0.3; + } else if (event->key() == Qt::Key_2) { + m_opacity = 0.2; + } else if (event->key() == Qt::Key_1) { + m_opacity = 0.1; + } + + setWindowOpacity(m_opacity); +} bool PinWidget::gestureEvent(QGestureEvent* event) { if (QGesture* pinch = event->gesture(Qt::PinchGesture)) { @@ -289,13 +315,17 @@ void PinWidget::showContextMenu(const QPoint& pos) contextMenu.addAction(&rotateLeftAction); QAction increaseOpacityAction(tr("Increase Opacity"), this); - connect( - &increaseOpacityAction, &QAction::triggered, this, &PinWidget::increaseOpacity); + connect(&increaseOpacityAction, + &QAction::triggered, + this, + &PinWidget::increaseOpacity); contextMenu.addAction(&increaseOpacityAction); QAction decreaseOpacityAction(tr("Decrease Opacity"), this); - connect( - &decreaseOpacityAction, &QAction::triggered, this, &PinWidget::decreaseOpacity); + connect(&decreaseOpacityAction, + &QAction::triggered, + this, + &PinWidget::decreaseOpacity); contextMenu.addAction(&decreaseOpacityAction); QAction closePinAction(tr("Close"), this); diff --git a/src/tools/pin/pinwidget.h b/src/tools/pin/pinwidget.h index 603128b984..1e26baff75 100644 --- a/src/tools/pin/pinwidget.h +++ b/src/tools/pin/pinwidget.h @@ -23,6 +23,7 @@ class PinWidget : public QWidget void mouseDoubleClickEvent(QMouseEvent*) override; void mousePressEvent(QMouseEvent*) override; void mouseMoveEvent(QMouseEvent*) override; + void keyPressEvent(QKeyEvent*) override; void enterEvent(QEvent*) override; void leaveEvent(QEvent*) override; @@ -41,7 +42,6 @@ class PinWidget : public QWidget void increaseOpacity(); void decreaseOpacity(); - QPixmap m_pixmap; QVBoxLayout* m_layout; QLabel* m_label; @@ -52,7 +52,7 @@ class PinWidget : public QWidget bool m_expanding{ false }; qreal m_scaleFactor{ 1 }; - qreal m_opacity {1}; + qreal m_opacity{ 1 }; unsigned int m_rotateFactor{ 0 }; qreal m_currentStepScaleFactor{ 1 }; bool m_sizeChanged{ false };