Ejemplo n.º 1
0
EchonestSteerer::EchonestSteerer( QWidget* parent )
    : QWidget( parent )
    , m_layout( new QHBoxLayout )
    , m_amplifier( 0 )
    , m_field( 0 )
    , m_description( 0 )
    , m_textL( new QVBoxLayout )
    , m_steerTop( 0 )
    , m_steerBottom( 0 )
    , m_reset( 0 )
    , m_expanding( true )
    
{
    m_layout->setContentsMargins( 8, 8, 8, 8 );
    
    m_textL->setSpacing( 0 );
    m_steerTop = new QLabel( tr( "Steer this station:" ), this );
    QFont f = m_steerTop->font();
    f.setPointSize( f.pointSize() + 2 );
    f.setBold( true );
    m_steerTop->setFont( f );
    m_textL->addWidget( m_steerTop );
    m_steerBottom = new QLabel( tr( "Takes effect on track change" ), this );
    f.setPointSize( f.pointSize() - 3 );
    m_steerBottom->setFont( f );
    m_textL->addWidget( m_steerBottom );
    
    m_layout->addLayout( m_textL, 1 );
    
    m_amplifier = new QComboBox( this );
    m_amplifier->addItem( tr( "Much less" ), "^.1" );
    m_amplifier->addItem( tr( "Less" ), "^.5" );
    m_amplifier->addItem( tr( "A bit less" ), "^.75" );
    m_amplifier->addItem( tr( "Keep at current", "" ) );
    m_amplifier->addItem( tr( "A bit more" ), "^1.25" );
    m_amplifier->addItem( tr( "More" ), "^1.5" );
    m_amplifier->addItem( tr( "Much more" ), "^2" );
    m_amplifier->setCurrentIndex( 3 );
    m_field = new QComboBox( this );
    m_field->addItem( tr( "Tempo" ), "tempo");
    m_field->addItem( tr( "Loudness" ), "loudness");
    m_field->addItem( tr( "Danceability" ), "danceability");
    m_field->addItem( tr( "Energy" ), "energy");
    m_field->addItem( tr( "Song Hotttnesss" ), "tempo");
    m_field->addItem( tr( "Artist Hotttnesss" ), "artist_hotttnesss");
    m_field->addItem( tr( "Artist Familiarity" ), "artist_familiarity");
    m_field->addItem( tr( "By Description" ), "desc");
    m_layout->addWidget( m_amplifier );
    m_layout->addWidget( m_field );
    
    connect( m_amplifier, SIGNAL( currentIndexChanged( int ) ), this, SLOT( changed() ) );
    connect( m_field, SIGNAL( currentIndexChanged( int ) ), this, SLOT( changed() ) );
    
    m_description = new QLineEdit( this );
    m_description->setPlaceholderText( tr( "Enter a description" ) );
    m_description->hide();
    
    connect( m_description, SIGNAL( textChanged( QString ) ), this, SLOT( changed() ) );
    
    m_reset = initButton( this );
    m_reset->setIcon( QIcon( RESPATH "images/view-refresh.png" ) );
    m_reset->setToolTip( tr( "Reset all steering commands" ) );
    m_layout->addWidget( m_reset );
        
    connect( m_reset, SIGNAL( clicked( bool ) ), this, SLOT( resetSteering( bool ) ) );
    
    setLayout( m_layout );
    setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
    
    m_resizeAnim.setDuration( ANIM_DURATION );
    m_resizeAnim.setEasingCurve( QEasingCurve::InOutQuad );
    m_resizeAnim.setDirection( QTimeLine::Forward );
    m_resizeAnim.setUpdateInterval( 8 );
    
    connect( &m_resizeAnim, SIGNAL( frameChanged( int ) ), this, SLOT( resizeFrame( int ) ) );
    
    
    m_fadeAnim = new QPropertyAnimation( this, "opacity", this );
    m_fadeAnim->setDuration( ANIM_DURATION );
    m_fadeAnim->setStartValue( 0 );
    m_fadeAnim->setEndValue( .86 );
    resize( sizeHint() );
}
Ejemplo n.º 2
0
void PkItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt(option);

    const int gHeight = (opt.rect.height() > GROUP_ROW_HEIGHT) ? opt.rect.height() : GROUP_ROW_HEIGHT;
    const int iHeight = (opt.rect.height() > ITEM_ROW_HEIGHT) ? opt.rect.height() : ITEM_ROW_HEIGHT;
    const int ROW_HEIGHT = index.data(PolkitKde::PoliciesModel::IsGroupRole).toBool() ? gHeight : iHeight;

    QStyle *style = QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

    QPixmap pixmap(opt.rect.size());
    pixmap.fill(Qt::transparent);
    QPainter p(&pixmap);
    p.translate(-opt.rect.topLeft());

    QRect clipRect(opt.rect);
    p.setClipRect(clipRect);

    // here we draw the icon
    KIcon icon(qvariant_cast<QIcon>(index.data(Qt::DecorationRole)));

    QIcon::Mode iconMode = QIcon::Normal;

    if (opt.state & QStyle::State_MouseOver) {
        iconMode = QIcon::Active;
    }

    QRect iconRect(opt.rect.topLeft(), QSize(ICON_SIZE, ICON_SIZE));
    const QRect iconPlaceRect(opt.rect.topLeft(), QSize(ROW_HEIGHT, ROW_HEIGHT));
    iconRect.moveCenter(iconPlaceRect.center());
    icon.paint(&p, iconRect, Qt::AlignCenter, iconMode);

    QColor foregroundColor = (opt.state.testFlag(QStyle::State_Selected)) ?
                             opt.palette.color(QPalette::HighlightedText) : opt.palette.color(QPalette::Text);

    p.setPen(foregroundColor);

    // here we draw the action description
    clipRect.setSize(QSize(opt.rect.width() - ROW_HEIGHT - MARGIN, ROW_HEIGHT / 2));
    clipRect.translate(ROW_HEIGHT + MARGIN, 0);
    p.setClipRect(clipRect);

    QFont descriptionFont = opt.font;
    if (index.model()->hasChildren(index)) {
        descriptionFont.setBold(true);
    }
    descriptionFont.setPointSize(descriptionFont.pointSize());
    p.setFont(descriptionFont);

    // let's differ groups from items
    if (index.data(PolkitKde::PoliciesModel::IsGroupRole).toBool()) { // it is a group item
        clipRect.setSize(QSize(clipRect.width(), GROUP_ROW_HEIGHT));
        p.setClipRect(clipRect);
        p.drawText(clipRect, Qt::AlignLeft | Qt::AlignVCenter, index.data(Qt::DisplayRole).toString());
    } else { // it is a normal item
        p.drawText(clipRect, Qt::AlignLeft | Qt::AlignBottom, index.data(Qt::DisplayRole).toString());

        // here we draw the action raw name
        clipRect.translate(0, qApp->fontMetrics().height());
        p.setClipRect(clipRect);

        QFont actionNameFont = KGlobalSettings::smallestReadableFont();
        actionNameFont.setItalic(true);
        p.setFont(actionNameFont);
        p.drawText(clipRect, Qt::AlignLeft | Qt::AlignVCenter, index.data(PolkitKde::PoliciesModel::PathRole).toString());
    }

    p.end();

    painter->drawPixmap(opt.rect.topLeft(), pixmap);
}
  void Plotter2DDisplay::drawPlot()
  {
    QColor fg_color(fg_color_);
    QColor bg_color(bg_color_);
    
    fg_color.setAlpha(fg_alpha_);
    bg_color.setAlpha(bg_alpha_);

    if (auto_color_change_) {
      double r
        = std::min(std::max((buffer_[buffer_.size() - 1] - min_value_) / (max_value_ - min_value_),
                            0.0), 1.0);
      if (r > 0.3) {
        double r2 = (r - 0.3) / 0.7;
        fg_color.setRed((max_color_.red() - fg_color_.red()) * r2
                        + fg_color_.red());
        fg_color.setGreen((max_color_.green() - fg_color_.green()) * r2
                          + fg_color_.green());
        fg_color.setBlue((max_color_.blue() - fg_color_.blue()) * r2
                         + fg_color_.blue());
      }
    }
    
    {
      ScopedPixelBuffer buffer = overlay_->getBuffer();
      QImage Hud = buffer.getQImage(*overlay_);
      // initilize by the background color
      for (int i = 0; i < overlay_->getTextureWidth(); i++) {
        for (int j = 0; j < overlay_->getTextureHeight(); j++) {
          Hud.setPixel(i, j, bg_color.rgba());
        }
      }
      // paste in HUD speedometer. I resize the image and offset it by 8 pixels from
      // the bottom left edge of the render window
      QPainter painter( &Hud );
      painter.setRenderHint(QPainter::Antialiasing, true);
      painter.setPen(QPen(fg_color, line_width_, Qt::SolidLine));
      
      uint16_t w = overlay_->getTextureWidth();
      uint16_t h = overlay_->getTextureHeight() - caption_offset_;

      double margined_max_value = max_value_ + (max_value_ - min_value_) / 2;
      double margined_min_value = min_value_ - (max_value_ - min_value_) / 2;
      
      for (size_t i = 1; i < buffer_length_; i++) {
        double v_prev = (margined_max_value - buffer_[i - 1]) / (margined_max_value - margined_min_value);
        double v = (margined_max_value - buffer_[i]) / (margined_max_value - margined_min_value);
        double u_prev = (i - 1) / (float)buffer_length_;
        double u = i / (float)buffer_length_;

        // chop within 0 ~ 1
        v_prev = std::max(std::min(v_prev, 1.0), 0.0);
        u_prev = std::max(std::min(u_prev, 1.0), 0.0);
        v = std::max(std::min(v, 1.0), 0.0);
        u = std::max(std::min(u, 1.0), 0.0);
        
        uint16_t x_prev = (int)(u_prev * w);
        uint16_t x = (int)(u * w);
        uint16_t y_prev = (int)(v_prev * h);
        uint16_t y = (int)(v * h);
        painter.drawLine(x_prev, y_prev, x, y);
      }
      // draw border
      if (show_border_) {
        painter.drawLine(0, 0, 0, h);
        painter.drawLine(0, h, w, h);
        painter.drawLine(w, h, w, 0);
        painter.drawLine(w, 0, 0, 0);
      }
      // draw caption
      if (show_caption_) {
        QFont font = painter.font();
        font.setPointSize(text_size_);
        font.setBold(true);
        painter.setFont(font);
        painter.drawText(0, h, w, caption_offset_,
                         Qt::AlignCenter | Qt::AlignVCenter,
                         getName());
      }
      if (show_value_) {
        QFont font = painter.font();
        font.setPointSize(w / 4);
        font.setBold(true);
        painter.setFont(font);
        std::ostringstream ss;
        ss << std::fixed << std::setprecision(2) << buffer_[buffer_.size() - 1];
        painter.drawText(0, 0, w, h,
                         Qt::AlignCenter | Qt::AlignVCenter,
                         ss.str().c_str());
      }
      
      // done
      painter.end();
    }
  }
Ejemplo n.º 4
0
void PKLAItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                           const QModelIndex &index) const
{
    QStyleOptionViewItemV4 opt(option);

    QStyle *style = QApplication::style();
    style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget);

    QPixmap pixmap(opt.rect.size());
    pixmap.fill(Qt::transparent);
    QPainter p(&pixmap);
    p.translate(-opt.rect.topLeft());

    QRect clipRect(opt.rect);
    p.setClipRect(clipRect);

    QIcon::Mode iconMode = QIcon::Normal;

    if (opt.state & QStyle::State_MouseOver) {
        iconMode = QIcon::Active;
    }

    const int height = (opt.rect.height() > ITEM_ROW_HEIGHT) ? opt.rect.height() : ITEM_ROW_HEIGHT;

    QRect iconRect(opt.rect.topLeft(), QSize(ICON_SIZE, ICON_SIZE));
    const QRect iconPlaceRect(opt.rect.topLeft(), QSize(height, height));
    iconRect.moveCenter(iconPlaceRect.center());
    m_passwordIcon.paint(&p, iconRect, Qt::AlignCenter, iconMode);

    QColor foregroundColor = (opt.state.testFlag(QStyle::State_Selected)) ?
                             opt.palette.color(QPalette::HighlightedText) : opt.palette.color(QPalette::Text);

    p.setPen(foregroundColor);

    // here we draw the action description
    clipRect.setSize(QSize(opt.rect.width() - height - MARGIN, height / 2));
    clipRect.translate(height + MARGIN, 0);
    p.setClipRect(clipRect);

    QFont descriptionFont = opt.font;
    if (index.model()->hasChildren(index)) {
        descriptionFont.setBold(true);
    }
    descriptionFont.setPointSize(descriptionFont.pointSize());
    p.setFont(descriptionFont);

    p.drawText(clipRect, Qt::AlignLeft | Qt::AlignBottom, index.data(Qt::DisplayRole).toString());

    // here we draw the action raw name
    clipRect.translate(0, qApp->fontMetrics().height());
    p.setClipRect(clipRect);

    QFont actionNameFont = KGlobalSettings::smallestReadableFont();
    actionNameFont.setItalic(true);
    p.setFont(actionNameFont);
    p.drawText(clipRect, Qt::AlignLeft | Qt::AlignVCenter, index.data(Qt::UserRole).toString());

    p.end();

    painter->drawPixmap(opt.rect.topLeft(), pixmap);
}