logowidget.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "logowidget.h"
  2. #include "ui_logowidget.h"
  3. LogoWidget::LogoWidget(QWidget* parent) :
  4. QWidget(parent),
  5. ui(new Ui::LogoWidget)
  6. {
  7. ui->setupUi(this);
  8. setMouseTracking(true);
  9. }
  10. LogoWidget::~LogoWidget()
  11. {
  12. delete ui;
  13. }
  14. QString LogoWidget::filePath() const
  15. {
  16. return m_filePath;
  17. }
  18. void LogoWidget::setFilePath(const QString& filePath)
  19. {
  20. m_filePath = filePath;
  21. qDebug() << filePath;
  22. update();
  23. }
  24. void LogoWidget::paintEvent(QPaintEvent* event)
  25. {
  26. QPoint pt = mapFromGlobal(cursor().pos());
  27. Q_UNUSED(event)
  28. QPainter painter;
  29. painter.begin(this);
  30. painter.setRenderHints(QPainter::HighQualityAntialiasing);
  31. painter.save();
  32. QPainterPath path;
  33. path.addEllipse(6, 6, width() - 12, height() - 12);
  34. painter.setClipPath(path);
  35. if (path.contains(pt))
  36. {
  37. QPen pen;
  38. pen.setColor(QColor(173, 216, 230));
  39. pen.setWidth(2);
  40. painter.setPen(pen);
  41. }
  42. else
  43. {
  44. painter.setPen(Qt::NoPen);
  45. }
  46. QPixmap pix(m_filePath);
  47. pix = pix.scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
  48. QRect rc = QRect(0, 0, width(), height());
  49. painter.drawPixmap(rc, pix);
  50. painter.drawPath(path);
  51. painter.restore();
  52. painter.end();
  53. }
  54. void LogoWidget::focusInEvent(QFocusEvent* event)
  55. {
  56. update();
  57. }
  58. void LogoWidget::focusOutEvent(QFocusEvent* event)
  59. {
  60. update();
  61. }
  62. void LogoWidget::mouseMoveEvent(QMouseEvent* event)
  63. {
  64. update();
  65. }