oneshadow.cpp 927 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "oneshadow.h"
  2. #include "imageblur.h"
  3. OneShadow::OneShadow(QSize contentSize,int radius,QColor shadowColor)
  4. {
  5. /* 图片(阴影)宽和高 */
  6. int imageWidth = contentSize.width()+radius*2;
  7. int imageHeight = contentSize.height()+radius*2;
  8. m_image = new QImage(imageWidth, imageHeight, QImage::Format_ARGB32);
  9. m_image->fill(shadowColor);
  10. //边框设为透明
  11. for(int x= 0 ;x < m_image->width();x++)
  12. {
  13. for(int y=0;y<m_image->height();y++)
  14. {
  15. /* 设置阴影圈部分透明 */
  16. if(x>=radius && x<(m_image->width()-radius) && y>=radius && y<(m_image->height()-radius)) continue;
  17. m_image->setPixelColor(QPoint(x,y), Qt::transparent);
  18. }
  19. }
  20. /* 通过高斯模糊来设置阴影 */
  21. GaussBlur::Blur(*m_image, radius);
  22. }
  23. OneShadow::~OneShadow()
  24. {
  25. delete m_image;
  26. }
  27. QImage& OneShadow::image()
  28. {
  29. return *m_image;
  30. }