void GraphicsBoard::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); QRectF rect(m_rect.topLeft(), QSizeF(m_squareSize, m_squareSize)); const qreal rLeft = rect.left(); // paint squares for (int y = 0; y < m_ranks; y++) { rect.moveLeft(rLeft); for (int x = 0; x < m_files; x++) { if ((x % 2) == (y % 2)) painter->fillRect(rect, m_lightColor); else painter->fillRect(rect, m_darkColor); rect.moveLeft(rect.left() + m_squareSize); } rect.moveTop(rect.top() + m_squareSize); } auto font = painter->font(); font.setPointSizeF(font.pointSizeF() * 0.7); painter->setFont(font); // paint file coordinates const QString alphabet = "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < m_files; i++) { const qreal tops[] = {m_rect.top() - m_coordSize, m_rect.bottom()}; for (const auto top : tops) { rect = QRectF(m_rect.left() + (m_squareSize * i), top, m_squareSize, m_coordSize); int file = m_flipped ? m_files - i - 1 : i; painter->drawText(rect, Qt::AlignCenter, alphabet[file]); } } // paint rank coordinates for (int i = 0; i < m_ranks; i++) { const qreal lefts[] = {m_rect.left() - m_coordSize, m_rect.right()}; for (const auto left : lefts) { rect = QRectF(left, m_rect.top() + (m_squareSize * i), m_coordSize, m_squareSize); int rank = m_flipped ? i + 1 : m_ranks - i; const auto num = QString::number(rank); painter->drawText(rect, Qt::AlignCenter, num); } } }
void knob::setLabel( const QString & _txt ) { m_label = _txt; if( m_knobPixmap ) { setFixedSize( qMax<int>( m_knobPixmap->width(), QFontMetrics( pointSizeF( font(), 6.5) ).width( m_label ) ), m_knobPixmap->height() + 10 ); } update(); }
void EffectView::paintEvent( QPaintEvent * ) { QPainter p( this ); p.drawPixmap( 0, 0, m_bg ); QFont f = pointSizeF( font(), 7.5f ); f.setBold( true ); p.setFont( f ); p.setPen( palette().shadow().color() ); p.drawText( 6, 55, model()->displayName() ); p.setPen( palette().text().color() ); p.drawText( 5, 54, model()->displayName() ); }
void LcdWidget::updateSize() { int margin = 1; if (m_label.isEmpty()) { setFixedSize( m_cellWidth * m_numDigits + 2*(margin+m_marginWidth), m_cellHeight + (2*margin) ); } else { setFixedSize( qMax<int>( m_cellWidth * m_numDigits + 2*(margin+m_marginWidth), QFontMetrics( pointSizeF( font(), 6.5 ) ).width( m_label ) ), m_cellHeight + (2*margin) + 9 ); } update(); }
static void drawFxLine( QPainter* p, const QWidget *fxLine, const QString& name, bool isActive, bool sendToThis ) { int width = fxLine->rect().width(); int height = fxLine->rect().height(); QColor bg_color = QApplication::palette().color( QPalette::Active, QPalette::Background ); QColor sh_color = QApplication::palette().color( QPalette::Active, QPalette::Shadow ); QColor te_color = QApplication::palette().color( QPalette::Active, QPalette::Text ); QColor bt_color = QApplication::palette().color( QPalette::Active, QPalette::BrightText ); p->fillRect( fxLine->rect(), isActive ? bg_color.lighter(130) : bg_color ); p->setPen( bg_color.darker(130) ); p->drawRect( 0, 0, width-2, height-2 ); p->setPen( bg_color.lighter(150) ); p->drawRect( 1, 1, width-2, height-2 ); p->setPen( isActive ? sh_color : bg_color.darker(130) ); p->drawRect( 0, 0, width-1, height-1 ); // draw the mixer send background if( sendToThis ) { p->drawPixmap(2, 0, 28, 56, embed::getIconPixmap("send_bg_arrow", 28, 56)); } // draw the channel name p->rotate( -90 ); p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); p->setPen( sh_color ); p->drawText( -146, 21, name ); p->setPen( isActive ? bt_color : te_color ); p->drawText( -145, 20, name ); }
void knob::paintEvent( QPaintEvent * _me ) { QPainter p( this ); drawKnob( &p ); if( !m_label.isEmpty() ) { p.setFont( pointSizeF( p.font(), 6.5 ) ); /* p.setPen( QColor( 64, 64, 64 ) ); p.drawText( width() / 2 - p.fontMetrics().width( m_label ) / 2 + 1, height() - 1, m_label );*/ p.setPen( QColor( 255, 255, 255 ) ); p.drawText( width() / 2 - p.fontMetrics().width( m_label ) / 2, height() - 2, m_label ); } }
void FxLine::drawFxLine( QPainter* p, const FxLine *fxLine, const QString& name, bool isActive, bool sendToThis, bool receiveFromThis ) { int width = fxLine->rect().width(); int height = fxLine->rect().height(); QColor sh_color = QApplication::palette().color( QPalette::Active, QPalette::Shadow ); QColor te_color = p->pen().brush().color(); QColor bt_color = QApplication::palette().color( QPalette::Active, QPalette::BrightText ); p->fillRect( fxLine->rect(), isActive ? fxLine->backgroundActive() : p->background() ); p->setPen( QColor( 255, 255, 255, isActive ? 100 : 50 ) ); p->drawRect( 1, 1, width-3, height-3 ); p->setPen( isActive ? sh_color : QColor( 0, 0, 0, 50 ) ); p->drawRect( 0, 0, width-1, height-1 ); // draw the mixer send background if( sendToThis ) { p->drawPixmap( 2, 0, 29, 56, *s_sendBgArrow ); } else if( receiveFromThis ) { p->drawPixmap( 2, 0, 29, 56, *s_receiveBgArrow ); } // draw the channel name p->rotate( -90 ); p->setFont( pointSizeF( fxLine->font(), 7.5f ) ); p->setPen( sh_color ); p->drawText( -146, 21, name ); p->setPen( isActive ? bt_color : te_color ); p->drawText( -145, 20, name ); }
void ControllerView::paintEvent( QPaintEvent * ) { QPainter p( this ); p.drawPixmap( 0, 0, m_bg ); QFont f = pointSizeF( font(), 7.5f ); f.setBold( true ); p.setFont( f ); Controller * c = castModel<Controller>(); p.setPen( QColor( 64, 64, 64 ) ); p.drawText( 7, 13, c->displayName() ); p.setPen( Qt::white ); p.drawText( 6, 12, c->displayName() ); f.setBold( false ); p.setFont( f ); p.drawText( 8, 26, c->name() ); }
FileBrowserTreeWidget::FileBrowserTreeWidget(QWidget * parent ) : QTreeWidget( parent ), m_mousePressed( false ), m_pressPos(), m_previewPlayHandle( NULL ), m_pphMutex( QMutex::Recursive ), m_contextMenuItem( NULL ) { setColumnCount( 1 ); headerItem()->setHidden( true ); setSortingEnabled( false ); setFont( pointSizeF( font(), 7.5f ) ); connect( this, SIGNAL( itemDoubleClicked( QTreeWidgetItem *, int ) ), SLOT( activateListItem( QTreeWidgetItem *, int ) ) ); connect( this, SIGNAL( itemCollapsed( QTreeWidgetItem * ) ), SLOT( updateDirectory( QTreeWidgetItem * ) ) ); connect( this, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), SLOT( updateDirectory( QTreeWidgetItem * ) ) ); }
void LcdWidget::paintEvent( QPaintEvent* ) { QPainter p( this ); QSize cellSize( m_cellWidth, m_cellHeight ); QRect cellRect( 0, 0, m_cellWidth, m_cellHeight ); int margin = 1; // QStyle::PM_DefaultFrameWidth; //int lcdWidth = m_cellWidth * m_numDigits + (margin*m_marginWidth)*2; // p.translate( width() / 2 - lcdWidth / 2, 0 ); p.save(); p.translate( margin, margin ); // Left Margin p.drawPixmap( cellRect, *m_lcdPixmap, QRect( QPoint( charsPerPixmap*m_cellWidth, isEnabled()?0:m_cellHeight ), cellSize ) ); p.translate( m_marginWidth, 0 ); // Padding for( int i=0; i < m_numDigits - m_display.length(); i++ ) { p.drawPixmap( cellRect, *m_lcdPixmap, QRect( QPoint( 10 * m_cellWidth, isEnabled()?0:m_cellHeight) , cellSize ) ); p.translate( m_cellWidth, 0 ); } // Digits for( int i=0; i < m_display.length(); i++ ) { int val = m_display[i].digitValue(); if( val < 0 ) { if( m_display[i] == '-' ) val = 11; else val = 10; } p.drawPixmap( cellRect, *m_lcdPixmap, QRect( QPoint( val*m_cellWidth, isEnabled()?0:m_cellHeight ), cellSize ) ); p.translate( m_cellWidth, 0 ); } // Right Margin p.drawPixmap( QRect( 0, 0, m_marginWidth-1, m_cellHeight ), *m_lcdPixmap, QRect( charsPerPixmap*m_cellWidth, isEnabled()?0:m_cellHeight, m_cellWidth / 2, m_cellHeight ) ); p.restore(); // Border QStyleOptionFrame opt; opt.initFrom( this ); opt.state = QStyle::State_Sunken; opt.rect = QRect( 0, 0, m_cellWidth * m_numDigits + (margin+m_marginWidth)*2 - 1, m_cellHeight + (margin*2) ); style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this ); p.resetTransform(); // Label if( !m_label.isEmpty() ) { p.setFont( pointSizeF( p.font(), 6.5 ) ); p.setPen( QColor( 64, 64, 64 ) ); p.drawText( width() / 2 - p.fontMetrics().width( m_label ) / 2 + 1, height(), m_label ); p.setPen( QColor( 255, 255, 255 ) ); p.drawText( width() / 2 - p.fontMetrics().width( m_label ) / 2, height() - 1, m_label ); } }
Knob::Knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) : DEFAULT_KNOB_INITIALIZER_LIST, m_knobNum( _knob_num ) { initUi( _name ); } Knob::Knob( QWidget * _parent, const QString & _name ) : DEFAULT_KNOB_INITIALIZER_LIST, m_knobNum( knobBright_26 ) { initUi( _name ); } #undef DEFAULT_KNOB_INITIALIZER_LIST void Knob::initUi( const QString & _name ) { if( s_textFloat == NULL ) { s_textFloat = new TextFloat; } setWindowTitle( _name ); onKnobNumUpdated(); setTotalAngle( 270.0f ); setInnerRadius( 1.0f ); setOuterRadius( 10.0f ); setFocusPolicy( Qt::ClickFocus ); // This is a workaround to enable style sheets for knobs which are not styled knobs. // // It works as follows: the palette colors that are assigned as the line color previously // had been hard coded in the drawKnob method for the different knob types. Now the // drawKnob method uses the line color to draw the lines. By assigning the palette colors // as the line colors here the knob lines will be drawn in this color unless the stylesheet // overrides that color. switch (knobNum()) { case knobSmall_17: case knobBright_26: case knobDark_28: setlineColor(QApplication::palette().color( QPalette::Active, QPalette::WindowText )); break; case knobVintage_32: setlineColor(QApplication::palette().color( QPalette::Active, QPalette::Shadow )); break; default: break; } doConnections(); } void Knob::onKnobNumUpdated() { if( m_knobNum != knobStyled ) { QString knobFilename; switch (m_knobNum) { case knobDark_28: knobFilename = "knob01"; break; case knobBright_26: knobFilename = "knob02"; break; case knobSmall_17: knobFilename = "knob03"; break; case knobVintage_32: knobFilename = "knob05"; break; case knobStyled: // only here to stop the compiler from complaining break; } // If knobFilename is still empty here we should get the fallback pixmap of size 1x1 m_knobPixmap = new QPixmap( embed::getIconPixmap( knobFilename.toUtf8().constData() ) ); setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() ); } } Knob::~Knob() { if( m_knobPixmap ) { delete m_knobPixmap; } } void Knob::setLabel( const QString & txt ) { m_label = txt; if( m_knobPixmap ) { setFixedSize( qMax<int>( m_knobPixmap->width(), QFontMetrics( pointSizeF( font(), 6.5) ).width( m_label ) ), m_knobPixmap->height() + 10 ); } update(); }
FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : QWidget( _parent ), m_mv( _mv ), m_channelIndex( _channelIndex ), m_backgroundActive( Qt::SolidPattern ), m_strokeOuterActive( 0, 0, 0 ), m_strokeOuterInactive( 0, 0, 0 ), m_strokeInnerActive( 0, 0, 0 ), m_strokeInnerInactive( 0, 0, 0 ), m_inRename( false ) { if( !s_sendBgArrow ) { s_sendBgArrow = new QPixmap( embed::getIconPixmap( "send_bg_arrow", 29, 56 ) ); } if( !s_receiveBgArrow ) { s_receiveBgArrow = new QPixmap( embed::getIconPixmap( "receive_bg_arrow", 29, 56 ) ); } setFixedSize( 33, FxLineHeight ); setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); // mixer sends knob m_sendKnob = new Knob( knobBright_26, this, tr( "Channel send amount" ) ); m_sendKnob->move( 3, 22 ); m_sendKnob->setVisible( false ); // send button indicator m_sendBtn = new SendButtonIndicator( this, this, m_mv ); m_sendBtn->move( 2, 2 ); // channel number m_lcd = new LcdWidget( 2, this ); m_lcd->setValue( m_channelIndex ); m_lcd->move( 4, 58 ); m_lcd->setMarginWidth( 1 ); setWhatsThis( tr( "The FX channel receives input from one or more instrument tracks.\n " "It in turn can be routed to multiple other FX channels. LMMS automatically " "takes care of preventing infinite loops for you and doesn't allow making " "a connection that would result in an infinite loop.\n\n" "In order to route the channel to another channel, select the FX channel " "and click on the \"send\" button on the channel you want to send to. " "The knob under the send button controls the level of signal that is sent " "to the channel.\n\n" "You can remove and move FX channels in the context menu, which is accessed " "by right-clicking the FX channel.\n" ) ); QString name = Engine::fxMixer()->effectChannel( m_channelIndex )->m_name; setToolTip( name ); m_renameLineEdit = new QLineEdit(); m_renameLineEdit->setText( name ); m_renameLineEdit->setFixedWidth( 65 ); m_renameLineEdit->setFont( pointSizeF( font(), 7.5f ) ); m_renameLineEdit->setReadOnly( true ); QGraphicsScene * scene = new QGraphicsScene(); scene->setSceneRect( 0, 0, 33, FxLineHeight ); m_view = new QGraphicsView( this ); m_view->setStyleSheet( "border-style: none; background: transparent;" ); m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_view->setAttribute( Qt::WA_TransparentForMouseEvents, true ); m_view->setScene( scene ); QGraphicsProxyWidget * proxyWidget = scene->addWidget( m_renameLineEdit ); proxyWidget->setRotation( -90 ); proxyWidget->setPos( 8, 145 ); connect( m_renameLineEdit, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) ); }
AudioEqualizerDialog::AudioEqualizerDialog(QWidget *parent) : QDialog(parent), d(new Data) { d->p = this; auto vbox = new QVBoxLayout; auto hbox = new QHBoxLayout; hbox->addWidget(new QLabel(tr("Preset"))); d->presets = new QComboBox; d->presets->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); for (int i = 0; i < Eq::MaxPreset; ++i) d->presets->addItem(AudioEqualizer::name((Preset)i), i); auto sig = static_cast<Signal<QComboBox, int>>(&QComboBox::currentIndexChanged); auto load = [=] () { auto data = d->presets->currentData(); if (data.type() == (int)QMetaType::Int) setEqualizer(Eq(Preset(data.toInt()))); }; connect(d->presets, sig, this, load); hbox->addWidget(d->presets); auto button = new QPushButton(tr("Load")); connect(button, &QPushButton::clicked, this, load); hbox->addWidget(button); vbox->addLayout(hbox); hbox = new QHBoxLayout; auto font = this->font(); font.setPointSizeF(font.pointSizeF()*0.8); const int w = QFontMetrics(font).width(u"+20.0dB"_q) + 2; for (int i = 0; i < Eq::bands(); ++i) { auto s = d->sliders[i] = new QSlider; s->setOrientation(Qt::Vertical); s->setRange(Eq::min() * Factor, Eq::max() * Factor); s->setFixedWidth(w); auto vbox = new QVBoxLayout; const auto f = Eq::freqeuncy(i); const QString fq = f < 999.9 ? (QString::number(f) % "Hz"_a) : (QString::number(f/1000.0) % "kHz"_a); auto label = new QLabel(fq); label->setFont(font); label->setAlignment(Qt::AlignCenter); vbox->addWidget(label); vbox->addWidget(s); auto dB = new QLabel("0.0dB"_a); dB->setFont(font); dB->setAlignment(Qt::AlignCenter); vbox->addWidget(dB); hbox->addLayout(vbox); connect(s, &QSlider::valueChanged, this, [=] () { const auto v = s->value()/(double)Factor; dB->setText((v > 0 ? "+"_a : ""_a) % QString::number(v, 'f', 1) % "dB"_a); if (_Change(d->eq[i], v) && d->update) d->update(d->eq); }); } vbox->addLayout(hbox); setLayout(vbox); _SetWindowTitle(this, tr("Audio Equalizer")); }
FxLine::FxLine( QWidget * _parent, FxMixerView * _mv, int _channelIndex ) : QWidget( _parent ), m_mv( _mv ), m_channelIndex( _channelIndex ), m_backgroundActive( Qt::SolidPattern ), m_strokeOuterActive( 0, 0, 0 ), m_strokeOuterInactive( 0, 0, 0 ), m_strokeInnerActive( 0, 0, 0 ), m_strokeInnerInactive( 0, 0, 0 ), m_inRename( false ) { if( !s_sendBgArrow ) { s_sendBgArrow = new QPixmap( embed::getIconPixmap( "send_bg_arrow", 29, 56 ) ); } if( !s_receiveBgArrow ) { s_receiveBgArrow = new QPixmap( embed::getIconPixmap( "receive_bg_arrow", 29, 56 ) ); } setFixedSize( 33, FxLineHeight ); setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); // mixer sends knob m_sendKnob = new Knob( knobBright_26, this, tr( "Channel send amount" ) ); m_sendKnob->move( 3, 22 ); m_sendKnob->setVisible( false ); // send button indicator m_sendBtn = new SendButtonIndicator( this, this, m_mv ); m_sendBtn->move( 2, 2 ); // channel number m_lcd = new LcdWidget( 2, this ); m_lcd->setValue( m_channelIndex ); m_lcd->move( 4, 58 ); m_lcd->setMarginWidth( 1 ); QString name = Engine::fxMixer()->effectChannel( m_channelIndex )->m_name; setToolTip( name ); m_renameLineEdit = new QLineEdit(); m_renameLineEdit->setText( name ); m_renameLineEdit->setFixedWidth( 65 ); m_renameLineEdit->setFont( pointSizeF( font(), 7.5f ) ); m_renameLineEdit->setReadOnly( true ); m_renameLineEdit->installEventFilter( this ); QGraphicsScene * scene = new QGraphicsScene(); scene->setSceneRect( 0, 0, 33, FxLineHeight ); m_view = new QGraphicsView( this ); m_view->setStyleSheet( "border-style: none; background: transparent;" ); m_view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); m_view->setAttribute( Qt::WA_TransparentForMouseEvents, true ); m_view->setScene( scene ); QGraphicsProxyWidget * proxyWidget = scene->addWidget( m_renameLineEdit ); proxyWidget->setRotation( -90 ); proxyWidget->setPos( 8, 145 ); connect( m_renameLineEdit, SIGNAL( editingFinished() ), this, SLOT( renameFinished() ) ); }