mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
bugfix: preview no hover-border and preview's close button show in initialization
Change-Id: Ie3a3ce665d297f56f2ee061fa0cd3059785a995f
This commit is contained in:
parent
586fefcb8f
commit
0c9e70f95e
Notes:
Deepin Code Review
2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: <mr.asianwang@gmail.com> Submitted-by: <mr.asianwang@gmail.com> Submitted-at: Mon, 31 Aug 2015 14:18:27 +0800 Reviewed-on: https://cr.deepin.io/6667 Project: dde/dde-dock Branch: refs/heads/master
@ -46,7 +46,7 @@ QLabel#ClassicModeTitle {
|
||||
color: rgba(255,255,255,1);
|
||||
}
|
||||
|
||||
QWidget#AppPreview:hover {
|
||||
QFrame#WindowPreview[isHover="true"] {
|
||||
border-radius: 3px;
|
||||
border-width: 3px;
|
||||
border-style: solid;
|
||||
|
@ -16,12 +16,11 @@ AppPreviewFrame::~AppPreviewFrame()
|
||||
|
||||
void AppPreviewFrame::addPreview(int xid)
|
||||
{
|
||||
WindowPreview * preview = new WindowPreview(xid, this);
|
||||
preview->setObjectName("AppPreview");
|
||||
preview->resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
|
||||
m_preview = new WindowPreview(xid, this);
|
||||
m_preview->resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
|
||||
|
||||
resize(preview->width() + BUTTON_SIZE, preview->height() + BUTTON_SIZE);
|
||||
preview->move(BUTTON_SIZE / 2, BUTTON_SIZE / 2);
|
||||
resize(m_preview->width() + BUTTON_SIZE, m_preview->height() + BUTTON_SIZE);
|
||||
m_preview->move(BUTTON_SIZE / 2, BUTTON_SIZE / 2);
|
||||
}
|
||||
|
||||
void AppPreviewFrame::setTitle(const QString &t)
|
||||
@ -31,8 +30,8 @@ void AppPreviewFrame::setTitle(const QString &t)
|
||||
QFontMetrics fm(titleLabel->font());
|
||||
titleLabel->setText(fm.elidedText(t,Qt::ElideRight,width()));
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
titleLabel->resize(width() - BUTTON_SIZE, TITLE_HEIGHT);
|
||||
titleLabel->move(BUTTON_SIZE / 2, height() - titleLabel->height() - BUTTON_SIZE / 2);
|
||||
titleLabel->resize(width() - BUTTON_SIZE - PREVIEW_BORDER_WIDTH * 2, TITLE_HEIGHT);
|
||||
titleLabel->move(BUTTON_SIZE / 2 + PREVIEW_BORDER_WIDTH, height() - titleLabel->height() - BUTTON_SIZE / 2 - PREVIEW_BORDER_WIDTH);
|
||||
}
|
||||
|
||||
void AppPreviewFrame::mousePressEvent(QMouseEvent *)
|
||||
@ -42,17 +41,22 @@ void AppPreviewFrame::mousePressEvent(QMouseEvent *)
|
||||
|
||||
void AppPreviewFrame::enterEvent(QEvent *)
|
||||
{
|
||||
m_preview->setIsHover(true);
|
||||
|
||||
showCloseButton();
|
||||
}
|
||||
|
||||
void AppPreviewFrame::leaveEvent(QEvent *)
|
||||
{
|
||||
m_preview->setIsHover(false);
|
||||
|
||||
hideCloseButton();
|
||||
}
|
||||
|
||||
void AppPreviewFrame::addCloseButton()
|
||||
{
|
||||
m_cb = new CloseButton(this);
|
||||
m_cb->hide();
|
||||
connect(m_cb,&CloseButton::clicked,[=]{close(this->xidValue);});
|
||||
m_cb->resize(BUTTON_SIZE, BUTTON_SIZE);
|
||||
|
||||
|
@ -35,10 +35,12 @@ private:
|
||||
void hideCloseButton();
|
||||
|
||||
private:
|
||||
CloseButton *m_cb;
|
||||
WindowPreview * m_preview = NULL;
|
||||
CloseButton *m_cb = NULL;
|
||||
int xidValue;
|
||||
const int BUTTON_SIZE = Dock::APP_PREVIEW_CLOSEBUTTON_SIZE;
|
||||
const int TITLE_HEIGHT = 25;
|
||||
const int PREVIEW_BORDER_WIDTH = 3;
|
||||
};
|
||||
|
||||
class AppPreviews : public QWidget
|
||||
|
@ -83,10 +83,12 @@ private:
|
||||
};
|
||||
|
||||
WindowPreview::WindowPreview(WId sourceWindow, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
: QFrame(parent),
|
||||
m_sourceWindow(sourceWindow),
|
||||
m_monitor(NULL)
|
||||
{
|
||||
setObjectName("WindowPreview");
|
||||
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
|
||||
prepareRepaint();
|
||||
@ -106,11 +108,28 @@ void WindowPreview::paintEvent(QPaintEvent *)
|
||||
|
||||
QImage image = QImage::fromData(imageData, "PNG");
|
||||
QPixmap pixmap = QPixmap::fromImage(image);
|
||||
pixmap = pixmap.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
painter.drawPixmap(0, 0, pixmap);
|
||||
//ignore border
|
||||
QRect rec(m_borderWidth, m_borderWidth, width() - m_borderWidth * 2, height() - m_borderWidth * 2);
|
||||
pixmap = pixmap.scaled(rec.width(), rec.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
painter.drawPixmap(rec.x(), rec.y(), pixmap);
|
||||
|
||||
painter.end();
|
||||
}
|
||||
bool WindowPreview::isHover() const
|
||||
{
|
||||
return m_isHover;
|
||||
}
|
||||
|
||||
void WindowPreview::setIsHover(bool isHover)
|
||||
{
|
||||
m_isHover = isHover;
|
||||
|
||||
style()->unpolish(this);
|
||||
style()->polish(this);// force a stylesheet recomputation
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
void WindowPreview::installMonitor()
|
||||
{
|
||||
@ -139,6 +158,7 @@ void WindowPreview::prepareRepaint()
|
||||
|
||||
XWindowAttributes s_atts;
|
||||
Status ss = XGetWindowAttributes(dsp, m_sourceWindow, &s_atts);
|
||||
QSize contentSize(width() - m_borderWidth * 2, height() - m_borderWidth * 2);
|
||||
|
||||
if (ss != 0) {
|
||||
cairo_surface_t *source = cairo_xlib_surface_create(dsp,
|
||||
@ -148,17 +168,17 @@ void WindowPreview::prepareRepaint()
|
||||
s_atts.height);
|
||||
|
||||
cairo_surface_t * image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
|
||||
width(),
|
||||
height());
|
||||
contentSize.width(),
|
||||
contentSize.height());
|
||||
|
||||
float ratio = 0.0f;
|
||||
if (s_atts.width > s_atts.height) {
|
||||
ratio = width() * 1.0 / s_atts.width;
|
||||
ratio = contentSize.width() * 1.0 / s_atts.width;
|
||||
} else {
|
||||
ratio = height() * 1.0 / s_atts.height;
|
||||
ratio = contentSize.height() * 1.0 / s_atts.height;
|
||||
}
|
||||
int x = (width() - s_atts.width * ratio) / 2.0;
|
||||
int y = (height() - s_atts.height * ratio) / 2.0;
|
||||
int x = (contentSize.width() - s_atts.width * ratio) / 2.0;
|
||||
int y = (contentSize.height() - s_atts.height * ratio) / 2.0;
|
||||
|
||||
cairo_t * cairo = cairo_create(image_surface);
|
||||
cairo_scale(cairo, ratio, ratio);
|
||||
@ -175,3 +195,5 @@ void WindowPreview::prepareRepaint()
|
||||
this->repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,14 +2,17 @@
|
||||
#define WINDOWPREVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFrame>
|
||||
#include <QImage>
|
||||
#include <QStyle>
|
||||
#include <QByteArray>
|
||||
|
||||
class Monitor;
|
||||
class QPaintEvent;
|
||||
class WindowPreview : public QWidget
|
||||
class WindowPreview : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isHover READ isHover WRITE setIsHover)
|
||||
public:
|
||||
friend class Monitor;
|
||||
|
||||
@ -18,6 +21,9 @@ public:
|
||||
|
||||
QByteArray imageData;
|
||||
|
||||
bool isHover() const;
|
||||
void setIsHover(bool isHover);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * event);
|
||||
|
||||
@ -25,6 +31,8 @@ private:
|
||||
WId m_sourceWindow;
|
||||
|
||||
Monitor * m_monitor;
|
||||
int m_borderWidth = 3;
|
||||
bool m_isHover = false;
|
||||
|
||||
void installMonitor();
|
||||
void removeMonitor();
|
||||
|
Loading…
x
Reference in New Issue
Block a user