Add DX11Widget::setBackgroundColor

Change-Id: I8ed55c5209c33354e0c6b07502261108c457abdb
This commit is contained in:
Iceyer 2016-04-26 09:45:24 +08:00
parent 8547cd8905
commit 68df7998cb
Notes: Deepin Code Review 2017-07-26 13:08:52 +08:00
Code-Review+1: zccrs <ccrr1314@live.com>
Verified+1: Anonymous Coward #1000004
Code-Review+2: Iceyer <me@iceyer.net>
Submitted-by: Iceyer <me@iceyer.net>
Submitted-at: Tue, 26 Apr 2016 10:10:09 +0800
Reviewed-on: https://cr.deepin.io/12339
Project: dtkwidget
Branch: refs/heads/master
3 changed files with 29 additions and 5 deletions

View File

@ -596,7 +596,7 @@ void DX11WidgetPrivate::init()
m_Border = WindowsBorder;
m_MousePressed = false;
m_Shadow = nullptr;
m_backgroundColor = BackgroundTopColor;
rootLayout = new QVBoxLayout;
rootLayout->setMargin(0);
rootLayout->setSpacing(0);
@ -836,6 +836,24 @@ void DX11Widget::setShadowWidth(int r)
d->m_Radius = r;
}
QColor DX11Widget::backgroundColor() const
{
D_DC(DX11Widget);
return d->m_backgroundColor;
}
void DX11Widget::setBackgroundColor(QColor backgroundColor)
{
D_D(DX11Widget);
if (d->m_backgroundColor == backgroundColor) {
return;
}
d->m_backgroundColor = backgroundColor;
emit backgroundColorChanged(backgroundColor);
}
int DX11Widget::border() const
{
@ -996,14 +1014,14 @@ void DX11Widget::paintEvent(QPaintEvent */*e*/)
border.addRoundedRect(rect, radius, radius);
QLinearGradient linearGradient(topLeft, QPoint(topLeft.x(), bottomRight.y()));
linearGradient.setColorAt(0.0, BackgroundTopColor);
linearGradient.setColorAt(0.2, BackgroundBottonColor);
linearGradient.setColorAt(1.0, BackgroundBottonColor);
linearGradient.setColorAt(0.0, d->m_backgroundColor);
linearGradient.setColorAt(0.2, d->m_backgroundColor);
linearGradient.setColorAt(1.0, d->m_backgroundColor);
QPen borderPen(BorderColor);
painter.setBrush(QBrush(linearGradient));
painter.strokePath(border, borderPen);
painter.fillPath(border, palette().background());
painter.fillPath(border, /*palette().background()*/QBrush(linearGradient));
}
}

View File

@ -23,6 +23,7 @@ public:
Q_PROPERTY(int border READ border WRITE setBorder)
Q_PROPERTY(int titlebarHeight READ titlebarHeight WRITE setTitlebarFixedHeight)
Q_PROPERTY(QPixmap backgroundImage READ backgroundImage WRITE setBackgroundImage)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Qt::WindowFlags windowFlags();
void setWindowFlags(Qt::WindowFlags type);
@ -66,6 +67,8 @@ public:
void adjustSize();
QColor backgroundColor() const;
protected:
void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
@ -81,11 +84,13 @@ public slots:
void showFullScreen();
void showNormal();
void setBackgroundColor(QColor backgroundColor);
protected:
void setShadow();
Q_SIGNALS:
void optionClicked();
void backgroundColorChanged(QColor backgroundColor);
private:

View File

@ -44,6 +44,7 @@ public:
DTitlebar *titlebar;
QWidget *contentWidget;
DGraphicsGlowEffect *m_Shadow;
QColor m_backgroundColor;
};