123456789101112131415161718192021222324252627282930313233343536 |
- #include "oneshadow.h"
- #include "imageblur.h"
- OneShadow::OneShadow(QSize contentSize,int radius,QColor shadowColor)
- {
- /* 图片(阴影)宽和高 */
- int imageWidth = contentSize.width()+radius*2;
- int imageHeight = contentSize.height()+radius*2;
- m_image = new QImage(imageWidth, imageHeight, QImage::Format_ARGB32);
- m_image->fill(shadowColor);
- //边框设为透明
- for(int x= 0 ;x < m_image->width();x++)
- {
- for(int y=0;y<m_image->height();y++)
- {
- /* 设置阴影圈部分透明 */
- if(x>=radius && x<(m_image->width()-radius) && y>=radius && y<(m_image->height()-radius)) continue;
- m_image->setPixelColor(QPoint(x,y), Qt::transparent);
- }
- }
- /* 通过高斯模糊来设置阴影 */
- GaussBlur::Blur(*m_image, radius);
- }
- OneShadow::~OneShadow()
- {
- delete m_image;
- }
- QImage& OneShadow::image()
- {
- return *m_image;
- }
|