basedialog.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "basedialog.h"
  2. #include "qmovewindowmanager.h"
  3. #include "qpainter.h"
  4. #include <QtMath>
  5. CBaseDialog::CBaseDialog(QWidget *parent)
  6. : QDialog(parent)
  7. {
  8. setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
  9. setAttribute(Qt::WA_TranslucentBackground);
  10. base_ui.setupUi(this);
  11. base_ui.widget_title->installEventFilter(new QMoveWindowManager(this));
  12. base_ui.widget_sysbutton->setMaxVisible(false);
  13. base_ui.widget_sysbutton->setMinVisible(false);
  14. base_ui.widget_sysbutton->setControlWidget(this);
  15. }
  16. CBaseDialog::~CBaseDialog()
  17. {
  18. }
  19. void CBaseDialog::paintEvent(QPaintEvent * event)
  20. {
  21. QDialog::paintEvent(event);
  22. const int border_width = 6;
  23. const int alpha_max = 100;
  24. double alpha_speed = border_width > 1 ? alpha_max / qSqrt(border_width) : alpha_max;
  25. QPainter painter(this);
  26. painter.setRenderHint(QPainter::Antialiasing, true);
  27. painter.fillRect(border_width, border_width, width() - border_width * 2, height() - border_width * 2, QBrush(Qt::white));
  28. QColor color(0, 0, 0, 50);
  29. for (int i = 0; i < border_width; i++)
  30. {
  31. color.setAlpha(alpha_max - qSqrt(i)*alpha_speed);
  32. painter.setPen(color);
  33. QRect rc(border_width - i, border_width - i, this->width() - (border_width - i) * 2, this->height() - (border_width - i) * 2);
  34. painter.drawRoundedRect(rc, i + 0.5, i + 0.5);
  35. }
  36. }