18 #include "QStyleOption"
20 #include "backgroundwidget.h"
22 BackgroundWidget::BackgroundWidget(QWidget *parent) : QWidget(parent)
24 setObjectName(
"BackgroundWidget" );
28 setAttribute( Qt::WA_StaticContents );
31 BackgroundWidget::~BackgroundWidget()
39 connect(mPrefs, &PreferenceManager::optionChanged,
this, &BackgroundWidget::settingUpdated);
41 loadBackgroundStyle();
42 mHasShadow = mPrefs->isOn(SETTING::SHADOW);
47 void BackgroundWidget::settingUpdated(SETTING setting)
51 case SETTING::BACKGROUND_STYLE:
53 loadBackgroundStyle();
59 mHasShadow = mPrefs->isOn(SETTING::SHADOW);
68 void BackgroundWidget::paintEvent(QPaintEvent *)
72 QPainter painter(
this);
73 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
80 void BackgroundWidget::loadBackgroundStyle()
82 QString bgName = mPrefs->getString(SETTING::BACKGROUND_STYLE);
83 mStyle =
"background-color:white; border: 1px solid lightGrey;";
85 if ( bgName ==
"white" )
87 mStyle =
"background-color:white; border: 1px solid lightGrey;";
89 else if ( bgName ==
"grey" )
91 mStyle =
"background-color:lightGrey; border: 1px solid grey;";
93 else if ( bgName ==
"checkerboard" )
95 mStyle =
"background-image: url(:background/checkerboard.png); background-repeat: repeat-xy; border: 1px solid lightGrey;";
97 else if ( bgName ==
"dots" )
99 mStyle =
"background-image: url(:background/dots.png); background-repeat: repeat-xy; border: 1px solid lightGrey;";
101 else if ( bgName ==
"weave" )
103 mStyle =
"background-image: url(:background/weave.jpg); background-repeat: repeat-xy; border: 1px solid lightGrey;";
105 else if ( bgName ==
"grid" )
107 mStyle =
"background-image: url(:background/grid.jpg); background-repeat: repeat-xy; border: 1px solid lightGrey;";
110 setStyleSheet(mStyle);
113 void BackgroundWidget::drawShadow( QPainter& painter )
118 QColor colour = Qt::black;
119 qreal opacity = 0.15;
121 QLinearGradient shadow = QLinearGradient( 0, 0, 0, radius1 );
123 int r = colour.red();
124 int g = colour.green();
125 int b = colour.blue();
126 qreal a = colour.alphaF();
127 shadow.setColorAt( 0.0, QColor( r, g, b, qRound( a * 255 * opacity ) ) );
128 shadow.setColorAt( 1.0, QColor( r, g, b, 0 ) );
131 painter.setPen( Qt::NoPen );
132 painter.setBrush( shadow );
133 painter.drawRect( QRect( 0, 0, width(), radius1 ) );
135 shadow.setFinalStop( radius1, 0 );
136 painter.setBrush( shadow );
137 painter.drawRect( QRect( 0, 0, radius1, height() ) );
139 shadow.setStart( 0, height() );
140 shadow.setFinalStop( 0, height() - radius2 );
141 painter.setBrush( shadow );
142 painter.drawRect( QRect( 0, height() - radius2, width(), height() ) );
144 shadow.setStart( width(), 0 );
145 shadow.setFinalStop( width() - radius2, 0 );
146 painter.setBrush( shadow );
147 painter.drawRect( QRect( width() - radius2, 0, width(), height() ) );