idropshadowable.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef IDROPSHADOWABLE_H
  2. #define IDROPSHADOWABLE_H
  3. #include <QList>
  4. #include <QSize>
  5. #include <QColor>
  6. #include <QWidget>
  7. #include <QDebug>
  8. /**
  9. * @brief 这是个数据结构,存储阴影相关的参数
  10. */
  11. struct BoxShadow
  12. {
  13. int x;
  14. int y;
  15. int radius; /* 一边阴影的宽度 */
  16. int spread; /* */
  17. QColor color;
  18. QSize boxSize;
  19. QImage image;
  20. //BoxShadow():x(0),y(0),radius(0),spread(0),color(QColor()),boxSize(QSize()){}
  21. bool operator==(const BoxShadow &rhs) const
  22. {
  23. return (this->radius == rhs.radius)
  24. &&(this->spread == rhs.spread)
  25. &&(this->color == rhs.color)
  26. &&(this->boxSize == rhs.boxSize);
  27. }
  28. bool operator<(const BoxShadow &rhs) const
  29. {
  30. /*----------------------------------------------------------------
  31. * QMap中通过<运算符来比较两个参数是否相等
  32. * 即通过a<b来判断是否相等,若小于成立,则说明不相等,便会插入;
  33. * 若小于不成立,则说明要么大于,要么等于;
  34. * 然后再反过来比较一次,即b<a,若这次小于成立,则b>a,则说明它们不相等,便会插入,否则相等。
  35. ----------------------------------------------------------------*/
  36. if((this->radius == rhs.radius)
  37. &&(this->spread == rhs.spread)
  38. &&(this->color == rhs.color)
  39. &&(this->boxSize == rhs.boxSize))
  40. {
  41. return false;
  42. }
  43. else
  44. {
  45. return true;
  46. }
  47. //return this->radius < rhs.radius;
  48. }
  49. friend QDebug operator<<(QDebug debug, const BoxShadow &boxShadow)
  50. {
  51. // QString info = QString("[x: %1][y: %2][radius: %3][spread: %4][size: (%5,%6)]")
  52. // .arg(boxShadow.x).arg(boxShadow.y).arg(boxShadow.radius).arg(boxShadow.spread)
  53. // .arg(boxShadow.boxSize.width()).arg(boxShadow.boxSize.height());
  54. debug << QString("(%1,%2)").arg(boxShadow.x).arg(boxShadow.y)
  55. <<boxShadow.color<<boxShadow.radius<<boxShadow.spread<<boxShadow.boxSize;
  56. return debug;
  57. }
  58. };
  59. Q_DECLARE_METATYPE(BoxShadow);
  60. /**
  61. * @brief
  62. */
  63. class IDropShadowable
  64. {
  65. public:
  66. IDropShadowable(){}
  67. IDropShadowable(QWidget *selfWidget);
  68. protected:
  69. void SetDropShadow(const BoxShadow &boxShadow, const QSize &size);
  70. void SetDropShadows(const QList<BoxShadow> &shadows, const QSize &size);
  71. void ClearDropShadow();
  72. private:
  73. QWidget *m_pSelfWidget;
  74. QList<BoxShadow> m_listShadows;
  75. public:
  76. void PaintShadows();
  77. };
  78. #endif // IDROPSHADOWABLE_H