12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "basedialog.h"
- #include "qmovewindowmanager.h"
- #include "qpainter.h"
- #include <QtMath>
- CBaseDialog::CBaseDialog(QWidget *parent)
- : QDialog(parent)
- {
- setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
- setAttribute(Qt::WA_TranslucentBackground);
- base_ui.setupUi(this);
- base_ui.widget_title->installEventFilter(new QMoveWindowManager(this));
- base_ui.widget_sysbutton->setMaxVisible(false);
- base_ui.widget_sysbutton->setMinVisible(false);
- base_ui.widget_sysbutton->setControlWidget(this);
- }
- CBaseDialog::~CBaseDialog()
- {
- }
- void CBaseDialog::paintEvent(QPaintEvent * event)
- {
- QDialog::paintEvent(event);
- const int border_width = 6;
- const int alpha_max = 100;
- double alpha_speed = border_width > 1 ? alpha_max / qSqrt(border_width) : alpha_max;
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing, true);
- painter.fillRect(border_width, border_width, width() - border_width * 2, height() - border_width * 2, QBrush(Qt::white));
- QColor color(0, 0, 0, 50);
- for (int i = 0; i < border_width; i++)
- {
- color.setAlpha(alpha_max - qSqrt(i)*alpha_speed);
- painter.setPen(color);
- QRect rc(border_width - i, border_width - i, this->width() - (border_width - i) * 2, this->height() - (border_width - i) * 2);
- painter.drawRoundedRect(rc, i + 0.5, i + 0.5);
- }
- }
|