mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
MaskablePixmapWidget::getPixmap: return the masked pixmap
This commit is contained in:
parent
b487fddf99
commit
8e664b5ff7
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
|
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, renderTarget(size)
|
||||||
, backgroundColor(Qt::white)
|
, backgroundColor(Qt::white)
|
||||||
, clickable(false)
|
, clickable(false)
|
||||||
{
|
{
|
||||||
@ -106,17 +107,16 @@ void MaskablePixmapWidget::setPixmap(const QPixmap &pmap)
|
|||||||
|
|
||||||
QPixmap MaskablePixmapWidget::getPixmap() const
|
QPixmap MaskablePixmapWidget::getPixmap() const
|
||||||
{
|
{
|
||||||
return pixmap;
|
return renderTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaskablePixmapWidget::paintEvent(QPaintEvent *)
|
void MaskablePixmapWidget::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPixmap tmp(width(), height());
|
renderTarget.fill(Qt::transparent);
|
||||||
tmp.fill(Qt::transparent);
|
|
||||||
|
|
||||||
QPoint offset((width() - pixmap.size().width())/2,(height() - pixmap.size().height())/2); // centering the pixmap
|
QPoint offset((width() - pixmap.size().width())/2,(height() - pixmap.size().height())/2); // centering the pixmap
|
||||||
|
|
||||||
QPainter painter(&tmp);
|
QPainter painter(&renderTarget);
|
||||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||||
painter.fillRect(0,0,width(),height(),backgroundColor);
|
painter.fillRect(0,0,width(),height(),backgroundColor);
|
||||||
painter.drawPixmap(offset,pixmap);
|
painter.drawPixmap(offset,pixmap);
|
||||||
@ -125,7 +125,7 @@ void MaskablePixmapWidget::paintEvent(QPaintEvent *)
|
|||||||
painter.end();
|
painter.end();
|
||||||
|
|
||||||
painter.begin(this);
|
painter.begin(this);
|
||||||
painter.drawPixmap(0,0,tmp);
|
painter.drawPixmap(0,0,renderTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaskablePixmapWidget::mousePressEvent(QMouseEvent*)
|
void MaskablePixmapWidget::mousePressEvent(QMouseEvent*)
|
||||||
|
@ -42,6 +42,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
QPixmap mask;
|
QPixmap mask;
|
||||||
|
QPixmap renderTarget;
|
||||||
QSize size;
|
QSize size;
|
||||||
QString maskName;
|
QString maskName;
|
||||||
QColor backgroundColor;
|
QColor backgroundColor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user