Improvement of Pin tool (#191)

- no taskbar window for pin widget
- completely ignore the window manager
- add borderless window shadow effects
This commit is contained in:
Ahmed Zetao Yang
2018-05-04 00:11:06 +08:00
committed by Dharkael
parent 801fb7ebf0
commit fe8a43a02a
3 changed files with 30 additions and 2 deletions

View File

@@ -44,7 +44,11 @@ QString PinTool::description() const {
QWidget* PinTool::widget() {
PinWidget *w = new PinWidget(m_pixmap);
w->setGeometry(m_geometry);
QRect adjusted_pos = QRect (m_geometry.left() - LAYOUT_MARGIN,
m_geometry.top() - LAYOUT_MARGIN,
m_geometry.width() + 2 * LAYOUT_MARGIN,
m_geometry.height() + 2 * LAYOUT_MARGIN);
w->setGeometry(adjusted_pos);
return w;
}

View File

@@ -26,8 +26,19 @@ PinWidget::PinWidget(const QPixmap &pixmap, QWidget *parent) :
QWidget(parent), m_pixmap(pixmap)
{
setWindowFlags(Qt::WindowStaysOnTopHint
| Qt::FramelessWindowHint);
| Qt::FramelessWindowHint
| Qt::Tool
| Qt::X11BypassWindowManagerHint);
//set the bottom widget background transparent
setAttribute(Qt::WA_TranslucentBackground);
m_shadowEffect->setColor(Qt::lightGray);
m_shadowEffect->setBlurRadius(2 * LAYOUT_MARGIN);
m_shadowEffect->setOffset(0, 0);
setGraphicsEffect(m_shadowEffect);
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(LAYOUT_MARGIN, LAYOUT_MARGIN, LAYOUT_MARGIN, LAYOUT_MARGIN);
m_label = new QLabel();
m_label->setPixmap(m_pixmap);
@@ -49,6 +60,13 @@ void PinWidget::wheelEvent(QWheelEvent *e) {
e->accept();
}
void PinWidget::enterEvent(QEvent *) {
m_shadowEffect->setColor(QColor(3, 150, 255));
}
void PinWidget::leaveEvent(QEvent *) {
m_shadowEffect->setColor(Qt::lightGray);
}
void PinWidget::mouseDoubleClickEvent(QMouseEvent *) {
close();
}

View File

@@ -18,6 +18,9 @@
#pragma once
#include <QWidget>
#include <QGraphicsDropShadowEffect>
#define LAYOUT_MARGIN 7
class QVBoxLayout;
class QLabel;
@@ -32,6 +35,8 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseMoveEvent(QMouseEvent *);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
private:
void setScaledPixmap(const QSize &size);
@@ -41,4 +46,5 @@ private:
QLabel *m_label;
QPoint m_dragStart;
qreal m_offsetX, m_offsetY;
QGraphicsDropShadowEffect *m_shadowEffect = new QGraphicsDropShadowEffect(this);
};