Skip to content

Commit

Permalink
refactor: Optimize painter fill rect mode[583467]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Jun 28, 2023
1 parent 30a37ed commit a805601
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 30 deletions.
14 changes: 4 additions & 10 deletions TTKModule/TTKWidget/musicCoreKits/musiccutsliderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,13 @@ void MusicCutSliderWidget::paintEvent(QPaintEvent *event)
QPainter painter(this);

const int lineStartHeight = (m_height - (PAINT_SLIDER_HEIGHT + PAINT_BUTTON_WIDTH)) / 2;
painter.setBrush(QBrush(QColor(220, 220, 220)));
painter.drawRect(0, lineStartHeight, m_width, PAINT_SLIDER_HEIGHT);
painter.fillRect(0, lineStartHeight, m_width, PAINT_SLIDER_HEIGHT, QColor(220, 220, 220));
painter.fillRect(0, lineStartHeight, m_position, PAINT_SLIDER_HEIGHT, QColor(150, 150, 150));

painter.setBrush(QBrush(QColor(150, 150, 150)));
painter.drawRect(0, lineStartHeight, m_position, PAINT_SLIDER_HEIGHT);

painter.setBrush(QBrush(QColor(TTK::UI::Color01)));
const int leftX = m_leftControl->geometry().x();
const int rightX = m_rightControl->geometry().x();
painter.drawRect(leftX < rightX ? leftX + PAINT_BUTTON_WIDTH / 2 : rightX + PAINT_BUTTON_WIDTH / 2, lineStartHeight, abs(leftX -rightX), PAINT_SLIDER_HEIGHT);

painter.setBrush(QBrush(QColor(0, 0, 0)));
painter.drawRect(m_position - PAINT_HANDER / 2, lineStartHeight + (PAINT_SLIDER_HEIGHT - PAINT_HANDER) / 2, PAINT_HANDER, PAINT_HANDER);
painter.fillRect(leftX < rightX ? leftX + PAINT_BUTTON_WIDTH / 2 : rightX + PAINT_BUTTON_WIDTH / 2, lineStartHeight, abs(leftX -rightX), PAINT_SLIDER_HEIGHT, QColor(TTK::UI::Color01));
painter.fillRect(m_position - PAINT_HANDER / 2, lineStartHeight + (PAINT_SLIDER_HEIGHT - PAINT_HANDER) / 2, PAINT_HANDER, PAINT_HANDER, QColor(0, 0, 0));

}

Expand Down
8 changes: 2 additions & 6 deletions TTKModule/TTKWidget/musicCoreKits/musictextsliderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ void MusicTextSliderWidget::paintEvent(QPaintEvent *event)
QWidget::paintEvent(event);
QPainter painter(this);

painter.setPen(QColor(200, 200, 200, 70));
painter.setBrush(QColor(200, 200, 200, 70));
painter.drawRect(0, 0, width(), 25);
painter.fillRect(0, 0, width(), 25, QColor(200, 200, 200, 70));

if(m_currentValue != 0)
{
painter.setPen(QColor(100, 100, 100, 70));
painter.setBrush(QColor(100, 100, 100, 70));
painter.drawRect(0, 0, m_currentValue * 1.0 / m_maxValue * width(), 20);
painter.fillRect(0, 0, m_currentValue * 1.0 / m_maxValue * width(), 20, QColor(100, 100, 100, 70));
}

painter.setPen(QColor(50, 50, 50));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void MusicLrcPhotoItem::paintEvent(QPaintEvent *event)
if(m_isSelected)
{
QPainter painter(this);
painter.setBrush(QColor(0, 0, 0, 155));
painter.drawRect(rect());
painter.fillRect(rect(), QColor(0, 0, 0, 155));
painter.drawPixmap(width() - 16 - 4, height() - 16 - 4, 16, 16, QPixmap(":/lrc/lb_photo_checked"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,7 @@ void MusicSongsToolBoxMaskWidget::paintEvent(QPaintEvent *event)
gradient.setFinalStop(0, height());
gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
gradient.setColorAt(0.9, QColor(180, 180, 180, 50));

painter.setPen(Qt::transparent);
painter.setBrush(gradient);
painter.drawRect(0, 32, width(), height());
painter.fillRect(0, 32, width(), height(), gradient);

const QPixmap pix(MusicTopAreaWidget::instance()->rendererPixmap());
painter.drawPixmap(0, 0, width(), height() - 3, pix.copy(1, 91, width(), height() - 3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ void MusicBackgroundListItem::paintEvent(QPaintEvent *event)
if(m_printMask)
{
QPainter painter(this);
painter.setBrush(QColor(0, 0, 0, 155));
painter.drawRect(rect());
painter.fillRect(rect(), QColor(0, 0, 0, 155));

QFont font = painter.font();
font.setPixelSize(13);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ void MusicPlayedListTopContainerWidget::paintEvent(QPaintEvent *event)
gradient.setFinalStop(0, height());
gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
gradient.setColorAt(0.9, QColor(180, 180, 180, 50));

painter.setPen(Qt::transparent);
painter.setBrush(gradient);
painter.drawRect(0, 32, width(), height());
painter.fillRect(0, 32, width(), height(), gradient);

painter.fillRect(QRect(0, 0, width(), height() - 3), QColor(0xED, 0xF8, 0xFE));
}
Expand Down
3 changes: 1 addition & 2 deletions TTKThirdParty/TTKExtras/qrencode/qrcodewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ void QRCodeQWidget::paintEvent(QPaintEvent *event)
{
unsigned char *point = qrcode->data;
painter.setPen(Qt::NoPen);
painter.setBrush(d->m_background);
painter.drawRect(0, 0, width(), height());
painter.fillRect(0, 0, width(), height(), d->m_background);

const double scale = (width () - 2.0 * d->m_margin) / qrcode->width;
painter.setBrush(d->m_foreground);
Expand Down

0 comments on commit a805601

Please sign in to comment.