void WVuMeter::paintEvent(QPaintEvent *) { ScopedTimer t("WVuMeter::paintEvent"); QStyleOption option; option.initFrom(this); QStylePainter p(this); p.drawPrimitive(QStyle::PE_Widget, option); if (!m_pPixmapBack.isNull() && !m_pPixmapBack->isNull()) { // Draw background. m_pPixmapBack->draw(0, 0, &p); } if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) { int idx = static_cast<int>(getControlParameterDisplay() * m_iNoPos); // Range check if (idx > m_iNoPos) idx = m_iNoPos; else if (idx < 0) idx = 0; // Draw (part of) vu if (m_bHorizontal) { // This is a hack to fix something weird with horizontal VU meters: if (idx == 0) idx = 1; QPointF targetPoint(0, 0); QRectF sourceRect(0, 0, idx, m_pPixmapVu->height()); m_pPixmapVu->draw(targetPoint, &p, sourceRect); if(m_iPeakHoldSize > 0 && m_iPeakPos > 0) { targetPoint = QPointF(m_iPeakPos - m_iPeakHoldSize, 0); sourceRect = QRectF(m_iPeakPos - m_iPeakHoldSize, 0, m_iPeakHoldSize, m_pPixmapVu->height()); m_pPixmapVu->draw(targetPoint, &p, sourceRect); } } else { QPointF targetPoint(0, m_iNoPos - idx); QRectF sourceRect(0, m_iNoPos - idx, m_pPixmapVu->width(), idx); m_pPixmapVu->draw(targetPoint, &p, sourceRect); if (m_iPeakHoldSize > 0 && m_iPeakPos > 0) { targetPoint = QPointF(0, m_pPixmapVu->height() - m_iPeakPos); sourceRect = QRectF(0, m_pPixmapVu->height() - m_iPeakPos, m_pPixmapVu->width(), m_iPeakHoldSize); m_pPixmapVu->draw(targetPoint, &p, sourceRect); } } } }
void WDisplay::paintEvent(QPaintEvent* /*unused*/) { QStyleOption option; option.initFrom(this); QStylePainter p(this); p.drawPrimitive(QStyle::PE_Widget, option); if (m_pPixmapBack) { m_pPixmapBack->draw(rect(), &p); } // If we are disabled, use the disabled pixmaps. If not, use the regular // pixmaps. const QVector<PaintablePointer>& pixmaps = (!isEnabled() && m_bDisabledLoaded) ? m_disabledPixmaps : m_pixmaps; if (pixmaps.empty()) { return; } int idx = getPixmapForParameter(getControlParameterDisplay()); // onConnectedControlChanged uses this to detect no-ops but it does not // clamp so don't clamp. m_iCurrentPixmap = idx; // Clamp active pixmap index to valid ranges. if (idx < 0) { idx = 0; } else if (idx >= pixmaps.size()) { idx = pixmaps.size() - 1; } PaintablePointer pPixmap = pixmaps[idx]; if (pPixmap) { pPixmap->draw(rect(), &p); } }
void WPushButton::paintEvent(QPaintEvent* e) { Q_UNUSED(e); QStyleOption option; option.initFrom(this); QStylePainter p(this); p.drawPrimitive(QStyle::PE_Widget, option); double value = getControlParameterDisplay(); if (m_iNoStates == 0) { return; } const QVector<PaintablePointer>& pixmaps = m_bPressed ? m_pressedPixmaps : m_unpressedPixmaps; int idx = static_cast<int>(value) % m_iNoStates; // Just in case m_iNoStates is somehow different from pixmaps.size(). if (idx < 0){ idx = 0; } else if (idx >= pixmaps.size()) { idx = pixmaps.size() - 1; } if (m_pPixmapBack) { m_pPixmapBack->draw(0, 0, &p); } PaintablePointer pPixmap = pixmaps.at(idx); if (!pPixmap.isNull() && !pPixmap->isNull()) { pPixmap->draw(0, 0, &p); } QString text = m_text.at(idx); if (!text.isEmpty()) { p.drawText(rect(), Qt::AlignCenter, text); } }
void WKnobComposed::paintEvent(QPaintEvent* e) { Q_UNUSED(e); QStyleOption option; option.initFrom(this); QStylePainter p(this); p.setRenderHint(QPainter::Antialiasing); p.setRenderHint(QPainter::SmoothPixmapTransform); p.drawPrimitive(QStyle::PE_Widget, option); if (m_pPixmapBack) { m_pPixmapBack->draw(0, 0, &p); } if (!m_pKnob.isNull() && !m_pKnob->isNull()) { p.translate(width() / 2.0, height() / 2.0); // We update m_dCurrentAngle since onConnectedControlChanged uses it for // no-op detection. m_dCurrentAngle = m_dMinAngle + (m_dMaxAngle - m_dMinAngle) * getControlParameterDisplay(); p.rotate(m_dCurrentAngle); m_pKnob->draw(-m_pKnob->width() / 2.0, -m_pKnob->height() / 2.0, &p); } }