diff --git a/popupdialog.cpp b/popupdialog.cpp index d53d68b529ec80149a9eabb0dd82dc3f795c3144..ed38dd642676dac01d76cfd840c684541ac5c6eb 100644 --- a/popupdialog.cpp +++ b/popupdialog.cpp @@ -22,12 +22,14 @@ #include "utils.h" #include <QMouseEvent> +#include <QPainter> PopupDialog::PopupDialog(QWidget *parent, QColor spikeColor, SpikeLabelAlignment spikeAlignment) : QDialog(parent), - ui(new Ui::PopupDialog) + ui(new Ui::PopupDialog), + spikeColor_(spikeColor) { ui->setupUi(this); @@ -79,3 +81,14 @@ PopupDialog::mousePressEvent(QMouseEvent* event) } QDialog::mousePressEvent(event); } + +void +PopupDialog::paintEvent(QPaintEvent * event) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + + // draw rounded corner + Utils::fillRoundRectPath(painter, spikeColor_, ui->containerWidget->rect(), cornerRadius_); + QDialog::paintEvent(event); +} diff --git a/popupdialog.h b/popupdialog.h index 64f903c462ab4071690a4853a7fc7ff31e6b68c4..8283f8c820912216980e35bedffb4d712c68856e 100644 --- a/popupdialog.h +++ b/popupdialog.h @@ -48,9 +48,12 @@ signals: protected: void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); private: Ui::PopupDialog *ui; + QColor spikeColor_; + constexpr static qreal cornerRadius_ = 10.0f; void setSpikeLabelAlignment(SpikeLabelAlignment spikeAlignment); }; diff --git a/previewwidget.cpp b/previewwidget.cpp index 8d876303ddd3b2aa03102229785f64b859bb2fc4..3e2ac120a5b0fb4e43ed180cebd3e41f9a7035ef 100644 --- a/previewwidget.cpp +++ b/previewwidget.cpp @@ -282,34 +282,17 @@ VideoRecordPreviewWidget::paintEvent(QPaintEvent* e) scaledPreview = previewImage->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio); scaledPreviewImage_ = scaledPreview; + scaledPreviewImageXOffset_ = xOffset; + scaledPreviewImageYOffset_ = yOffset; // draw rounded corner image - QBrush brush(scaledPreview); - brush.setTransform(QTransform::fromTranslate( - this->rect().x() + xOffset, - this->rect().y() + yOffset)); - QPainterPath previewPath; - previewPath.addRoundRect(this->rect(), cornerRadius_); - painter.fillPath(previewPath, brush); + Utils::fillRoundRectPath(painter, scaledPreview, rect(), cornerRadius_, xOffset, yOffset); } else { if (paintBackground_) { - paintBackground(&painter); + Utils::fillRoundRectPath(painter, QColor(Qt::black), rect(), cornerRadius_); scaledPreviewImage_ = QImage(); } else if (drawLastFrame_) { - QBrush brush(scaledPreviewImage_); - brush.setTransform(QTransform::fromTranslate(this->rect().x(), this->rect().y())); - QPainterPath previewPath; - previewPath.addRoundRect(this->rect(), cornerRadius_); - painter.fillPath(previewPath, brush); + Utils::fillRoundRectPath(painter, scaledPreviewImage_, rect(), cornerRadius_, scaledPreviewImageXOffset_, scaledPreviewImageYOffset_); } } } - -void -VideoRecordPreviewWidget::paintBackground(QPainter * painter) -{ - QBrush brush(Qt::black); - QPainterPath path; - path.addRoundRect(this->rect(), cornerRadius_); - painter->fillPath(path, brush); -} diff --git a/previewwidget.h b/previewwidget.h index ad73ae2649d556070b88fa34c3e63a799325d4d4..0c9eb23afc6bbb2430d675c191d95705ac84c695 100644 --- a/previewwidget.h +++ b/previewwidget.h @@ -104,9 +104,10 @@ public: protected: void paintEvent(QPaintEvent* e) override; - void paintBackground(QPainter* painter) override; private: + int scaledPreviewImageXOffset_{ 0 }; + int scaledPreviewImageYOffset_{ 0 }; constexpr static qreal cornerRadius_ = 10.0f; QImage scaledPreviewImage_; diff --git a/stylesheet.css b/stylesheet.css index 28bcac9d48c469365053d1d3d841a1d09e794692..d15134287aed04c43e176461a7d031bf21ad2b4e 100644 --- a/stylesheet.css +++ b/stylesheet.css @@ -829,12 +829,6 @@ QPushButton#panelButton_9:pressed, QPushButton#panelButton_hash:pressed, QPushBu background: #58b; } -QWidget#containerWidget { - border-radius: 10px; - border: solid 1px transparent; - background-color: white; -} - QProgressBar#audioInputMeter { border: 0px solid #606060; background: lightgrey; diff --git a/utils.h b/utils.h index ca9b8f16de6eb9cef4ebbe02ef532544b04310a6..d8774a7d63702925dd1944f68165670f3f43068f 100644 --- a/utils.h +++ b/utils.h @@ -108,6 +108,20 @@ QImage scaleAndFrame(const QImage photo, const QSize& size = IMAGE_SIZE); QImage accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& size = IMAGE_SIZE); QImage cropImage(const QImage& img); +// rounded corner +template<typename T> +void +fillRoundRectPath(QPainter& painter, const T& brushType, const QRect& rectToDraw, qreal cornerRadius, int xTransFormOffset = 0, int yTransFormOffset = 0) +{ + QBrush brush(brushType); + brush.setTransform(QTransform::fromTranslate( + rectToDraw.x() + xTransFormOffset, + rectToDraw.y() + yTransFormOffset)); + QPainterPath painterPath; + painterPath.addRoundRect(rectToDraw, cornerRadius); + painter.fillPath(painterPath, brush); +} + // time QString formattedTime(int seconds); diff --git a/widgethelpers.cpp b/widgethelpers.cpp index 4ee68210e54116705d5be7d48f77db1f53cbce6b..c3d0f36af788ae08594b44082506760bc32df3b5 100644 --- a/widgethelpers.cpp +++ b/widgethelpers.cpp @@ -18,6 +18,8 @@ #include "widgethelpers.h" +#include "utils.h" + FadeOutable::FadeOutable(QWidget* parent) : QWidget(parent) { @@ -162,16 +164,8 @@ VignetteWidget::paintEvent(QPaintEvent *event) gradient.setColorAt(0.5, QColor(0, 0, 0, 32)); gradient.setColorAt(1, Qt::transparent); - // draw rounded corner - if (drawRoundedCorner_) { - QBrush brush(gradient); - brush.setTransform(QTransform::fromTranslate(this->rect().x(), this->rect().y())); - QPainterPath previewPath; - previewPath.addRoundRect(this->rect(), cornerRadius_); - painter.fillPath(previewPath, brush); - } else { - painter.fillRect(rect(), gradient); - } + // draw upper rounded corner or just gradient itself + fillRoundRectPath(painter, gradient); // bottom gradient.setStart(0, rect().bottom() - height_); @@ -180,15 +174,17 @@ VignetteWidget::paintEvent(QPaintEvent *event) gradient.setColorAt(0.5, QColor(0, 0, 0, 32)); gradient.setColorAt(1, QColor(0, 0, 0, 96)); - // draw rounded corner + // draw bottom rounded corner or just gradient itself + fillRoundRectPath(painter, gradient); + +} + +void +VignetteWidget::fillRoundRectPath(QPainter& painter, const QLinearGradient & gradient) +{ if (drawRoundedCorner_) { - QBrush brush(gradient); - brush.setTransform(QTransform::fromTranslate(this->rect().x(), this->rect().y())); - QPainterPath previewPath; - previewPath.addRoundRect(this->rect(), cornerRadius_); - painter.fillPath(previewPath, brush); + Utils::fillRoundRectPath(painter, gradient, rect(), cornerRadius_); } else { painter.fillRect(rect(), gradient); } - } diff --git a/widgethelpers.h b/widgethelpers.h index 8c6587ee39c6f97a845c2837366dda8b5d3f264c..ba684e63771a6bc6521dadaf40b4c9b572aa454f 100644 --- a/widgethelpers.h +++ b/widgethelpers.h @@ -106,6 +106,8 @@ protected: void paintEvent(QPaintEvent *event) override; private: + void fillRoundRectPath(QPainter& painter, const QLinearGradient& gradient); + FadeAnimation* fadeOutAnimation_; constexpr static qreal cornerRadius_ = 10.0f; quint64 height_{ 128 };