diff --git a/src/tools/pin/pinwidget.cpp b/src/tools/pin/pinwidget.cpp index b173d4ff7f..a315b4c092 100644 --- a/src/tools/pin/pinwidget.cpp +++ b/src/tools/pin/pinwidget.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later // SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors - #include +#include #include #include "pinwidget.h" @@ -35,10 +35,10 @@ 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); - 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); @@ -165,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)) { @@ -189,6 +216,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 +314,20 @@ 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..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; @@ -38,6 +39,9 @@ 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 };