MCPcopy Create free account
hub / github.com/Liniyous/ElaWidgetTools / paintEvent

Method paintEvent

ElaWidgetTools/ElaRoller.cpp:260–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258{
259 Q_D(ElaRoller);
260 d->_mousePoint = QPoint();
261 update();
262 QWidget::leaveEvent(event);
263}
264
265void ElaRoller::paintEvent(QPaintEvent* event)
266{
267 Q_D(ElaRoller);
268 QPainter painter(this);
269 painter.save();
270 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
271 // 背景绘制
272 QRect foregroundRect(d->_penBorderWidth, d->_penBorderWidth, width() - 2 * d->_penBorderWidth, height() - 2 * d->_penBorderWidth - 1);
273 if (!d->_pIsContainer)
274 {
275 painter.setPen(QPen(ElaThemeColor(d->_themeMode, BasicBorder), d->_penBorderWidth));
276 painter.setBrush(ElaColorAnimation::getColor(this, isEnabled() ? ElaThemeColor(d->_themeMode, BasicBase) : ElaThemeColor(d->_themeMode, BasicDisable), "Background"));
277 painter.drawRoundedRect(foregroundRect, d->_pBorderRadius, d->_pBorderRadius);
278 }
279 painter.setClipRect(foregroundRect);
280 // 中心指示区域绘制
281 painter.setPen(Qt::NoPen);
282 painter.setBrush(ElaColorAnimation::getColor(this, ElaThemeColor(d->_themeMode, PrimaryNormal), "Indicator"));
283 bool isEven = d->_pMaxVisibleItems % 2 == 0;
284 if (isEven)
285 {
286 painter.drawRoundedRect(QRect(d->_indicatorMargin, d->_pItemHeight * d->_pMaxVisibleItems / 2 + d->_indicatorMargin, width() - 2 * d->_indicatorMargin, d->_pItemHeight - 2 * d->_indicatorMargin), d->_pBorderRadius, d->_pBorderRadius);
287 }
288 else
289 {
290 painter.drawRoundedRect(QRect(d->_indicatorMargin, (height() - d->_pItemHeight) / 2 + d->_indicatorMargin, width() - 2 * d->_indicatorMargin, d->_pItemHeight - 2 * d->_indicatorMargin), d->_pBorderRadius, d->_pBorderRadius);
291 }
292
293 int yStart = -d->_pItemHeight;
294 int yEnd = height();
295 int centerYStart = isEven ? d->_pItemHeight * d->_pMaxVisibleItems / 2 : height() / 2 - d->_pItemHeight;
296 int centerYEnd = isEven ? d->_pItemHeight * d->_pMaxVisibleItems / 2 + d->_pItemHeight / 2 : height() / 2;
297 int startIndexOffset = d->_pMaxVisibleItems / 2;
298 for (int i = 0; i < d->_pItemList.size(); i++)
299 {
300 qreal y = (i + startIndexOffset) * d->_pItemHeight - d->_pScrollOffset;
301 // 范围控制
302 if (d->_pIsEnableLoop)
303 {
304 while (y <= yStart)
305 {
306 y += d->_pItemList.size() * d->_pItemHeight;
307 }
308 while (y >= yEnd)
309 {
310 y -= d->_pItemList.size() * d->_pItemHeight;
311 }
312 }
313 // 可见区域绘制
314 if (y >= yStart && y <= yEnd)
315 {
316 painter.save();
317 painter.translate(0, y);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected