예제 #1
0
void TupGradientSelector::mousePressEvent(QMouseEvent *event)
{
    bool select = false;
    for (int i = 0; i < m_arrows.count(); i++) {
         TupGradientArrow *aArrow = m_arrows[i];
         if (aArrow->contains(event->pos())) {
             m_currentArrowIndex = i;
             select = true;
             break;
         }
    }

    if (m_arrows.count() > 2 && event->button() == Qt::RightButton) {
        m_arrows.removeAt(m_currentArrowIndex);
        m_currentArrowIndex = 0;
        repaint();
    }
    else if (!select) {
             int val;
             if (orientation() == Qt::Vertical)
                 val = (maximum() - minimum()) * (height() - event->y()) / (height()) + minimum();
             else
                 val = (maximum() - minimum()) * (width() - event->x()) / width() + minimum();

             if (!m_arrows.isEmpty())
                 addArrow(calcArrowPos(val), m_arrows[m_currentArrowIndex]->color());
             else
                 addArrow(calcArrowPos(val), m_currentColor);
    }
}
예제 #2
0
void KSelector::paintEvent( QPaintEvent * )
{
  QPainter painter;
  int w = style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
  int iw = (w < ARROWSIZE) ? ARROWSIZE : w;

  painter.begin( this );

  drawContents( &painter );

  QBrush brush;

  QPoint pos = calcArrowPos( value() );
  drawArrow( &painter, pos );

  if ( indent() )
  {
    QStyleOptionFrame opt;
    opt.initFrom( this );
    opt.state = QStyle::State_Sunken;
    if ( orientation() == Qt::Vertical )
      opt.rect.adjust( 0, iw - w, -5, w - iw );
    else
      opt.rect.adjust(iw - w, 0, w - iw, -5);
    style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, this );
  }


  painter.end();
}
예제 #3
0
void TupGradientSelector::setStops(const QGradientStops &stops)
{
    m_gradient.setStops(stops);
    m_arrows.clear();

    for (int i = 0; i < stops.count(); i++)
         addArrow(calcArrowPos((int) (100 - (stops[i].first * 100)) ), stops[i].second);

    update();
}
예제 #4
0
void  TupGradientSelector::resizeEvent(QResizeEvent *event)
{
    QAbstractSlider::setRange(0,width());
    QAbstractSlider::setMaximum(width());

    m_update = true;

    for (int i =0; i < m_arrows.count(); i++)
         m_arrows[i]->moveVertical(calcArrowPos((int)m_arrows[i]->position()));

    QWidget::resizeEvent(event);
}