📄 fader.cpp
字号:
*groovePixmap(), buttonMargin + buttonPixmap()->width(), aboveButton, width() - buttonMargin - buttonPixmap()->width(), buttonPixmap()->height()); } else { //... update int leftOfButton = (m_sliderMax - m_sliderMin) - position - buttonPixmap()->width() / 2; int rightOfButton = position - buttonPixmap()->width() / 2; if (leftOfButton > 0) { paint.drawPixmap(0, 0, *groovePixmap(), 0, 0, leftOfButton, groovePixmap()->height()); } if (rightOfButton > 0) { paint.drawPixmap(rightOfButton + buttonPixmap()->width(), 0, *groovePixmap(), groovePixmap()->width() - rightOfButton, 0, rightOfButton, groovePixmap()->height()); } paint.drawPixmap(leftOfButton, 0, *buttonPixmap()); } paint.end();}voidFader::mousePressEvent(QMouseEvent *e){ m_clickMousePos = -1; if (e->button() == LeftButton) { if (e->type() == QEvent::MouseButtonDblClick) { setFader(0); return ; } if (m_vertical) { int buttonPosition = value_to_position(m_value); int clickPosition = height() - e->y() - m_sliderMin; if (clickPosition < buttonPosition + buttonPixmap()->height() / 2 && clickPosition > buttonPosition - buttonPixmap()->height() / 2) { m_clickMousePos = clickPosition; m_clickButtonPos = value_to_position(m_value); showFloatText(); } } }}voidFader::mouseReleaseEvent(QMouseEvent *e){ mouseMoveEvent(e); m_clickMousePos = -1;}voidFader::mouseMoveEvent(QMouseEvent *e){ if (m_clickMousePos >= 0) { if (m_vertical) { int mousePosition = height() - e->y() - m_sliderMin; int delta = mousePosition - m_clickMousePos; int buttonPosition = m_clickButtonPos + delta; if (buttonPosition < 0) buttonPosition = 0; if (buttonPosition > m_sliderMax - m_sliderMin) { buttonPosition = m_sliderMax - m_sliderMin; } setFader(position_to_value(buttonPosition)); showFloatText(); } }}voidFader::wheelEvent(QWheelEvent *e){ int buttonPosition = value_to_position(m_value); if (e->state() & ShiftButton) { if (e->delta() > 0) buttonPosition += 10; else buttonPosition -= 10; } else { if (e->delta() > 0) buttonPosition += 1; else buttonPosition -= 1; } RG_DEBUG << "Fader::wheelEvent - button position = " << buttonPosition << endl; setFader(position_to_value(buttonPosition)); RG_DEBUG << "Fader::wheelEvent - value = " << m_value << endl; showFloatText();}voidFader::showFloatText(){ // draw on the float text QString text; if (m_integral) { text = QString("%1").arg(int(m_value)); } else if (m_value == AudioLevel::DB_FLOOR) { text = "Off"; } else { float v = fabs(m_value); text = QString("%1%2.%3%4%5 dB") .arg(m_value < 0 ? '-' : '+') .arg(int(v)) .arg(int(v * 10) % 10) .arg(int(v * 100) % 10) .arg(int(v * 1000) % 10); } m_float->setText(text); // Reposition - we need to sum the relative positions up to the // topLevel or dialog to please move(). // QWidget *par = parentWidget(); QPoint totalPos = this->pos(); while (par->parentWidget() && !par->isTopLevel() && !par->isDialog()) { totalPos += par->pos(); par = par->parentWidget(); } // Move just top/right // m_float->move(totalPos + QPoint(width() + 2, 0)); // Show m_float->show(); // one shot, 500ms m_floatTimer->start(500, true);}voidFader::slotFloatTimeout(){ m_float->hide();}voidFader::calculateGroovePixmap(){ QPixmap *& map = m_pixmapCache[SizeRec(width(), height())].first[m_outlineColour.pixel()]; delete map; map = new QPixmap(width(), height()); map->fill(colorGroup().background()); QPainter paint(map); paint.setBrush(colorGroup().background()); if (m_vertical) { paint.setPen(m_outlineColour); paint.drawRect(0, 0, width(), height()); if (m_integral) { //... } else { for (int dB = -70; dB <= 10; ) { int position = value_to_position(float(dB)); if (position >= 0 && position < m_sliderMax - m_sliderMin) { if (dB == 0) paint.setPen(colorGroup().dark()); else paint.setPen(colorGroup().midlight()); paint.drawLine(1, (m_sliderMax - position), width() - 2, (m_sliderMax - position)); } if (dB < -10) dB += 10; else dB += 2; } } paint.setPen(colorGroup().dark()); paint.setBrush(colorGroup().mid()); paint.drawRect(width() / 2 - 3, height() - m_sliderMax, 6, m_sliderMax - m_sliderMin); paint.end(); } else { //... }}voidFader::calculateButtonPixmap(){ PixmapCache::iterator i = m_pixmapCache.find(SizeRec(width(), height())); if (i != m_pixmapCache.end() && i->second.second) return ; QPixmap *& map = m_pixmapCache[SizeRec(width(), height())].second; if (m_vertical) { int buttonHeight = height() / 7; buttonHeight /= 10; ++buttonHeight; buttonHeight *= 10; ++buttonHeight; int buttonWidth = width() * 2 / 3; buttonWidth /= 5; ++buttonWidth; buttonWidth *= 5; if (buttonWidth > width() - 2) buttonWidth = width() - 2; map = new QPixmap(buttonWidth, buttonHeight); map->fill(colorGroup().background()); int x = 0; int y = 0; QPainter paint(map); paint.setPen(colorGroup().light()); paint.drawLine(x + 1, y, x + buttonWidth - 2, y); paint.drawLine(x, y + 1, x, y + buttonHeight - 2); paint.setPen(colorGroup().midlight()); paint.drawLine(x + 1, y + 1, x + buttonWidth - 2, y + 1); paint.drawLine(x + 1, y + 1, x + 1, y + buttonHeight - 2); paint.setPen(colorGroup().mid()); paint.drawLine(x + 2, y + buttonHeight - 2, x + buttonWidth - 2, y + buttonHeight - 2); paint.drawLine(x + buttonWidth - 2, y + 2, x + buttonWidth - 2, y + buttonHeight - 2); paint.setPen(colorGroup().dark()); paint.drawLine(x + 1, y + buttonHeight - 1, x + buttonWidth - 2, y + buttonHeight - 1); paint.drawLine(x + buttonWidth - 1, y + 1, x + buttonWidth - 1, y + buttonHeight - 2); paint.setPen(colorGroup().shadow()); paint.drawLine(x + 1, y + buttonHeight / 2, x + buttonWidth - 2, y + buttonHeight / 2); paint.setPen(colorGroup().mid()); paint.drawLine(x + 1, y + buttonHeight / 2 - 1, x + buttonWidth - 2, y + buttonHeight / 2 - 1); paint.drawPoint(x, y + buttonHeight / 2); paint.setPen(colorGroup().light()); paint.drawLine(x + 1, y + buttonHeight / 2 + 1, x + buttonWidth - 2, y + buttonHeight / 2 + 1); paint.setPen(colorGroup().button()); paint.setBrush(colorGroup().button()); paint.drawRect(x + 2, y + 2, buttonWidth - 4, buttonHeight / 2 - 4); paint.drawRect(x + 2, y + buttonHeight / 2 + 2, buttonWidth - 4, buttonHeight / 2 - 4); paint.end(); } else { //... }}}#include "Fader.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -