Пример #1
0
double Perlin::noise2(double x, double y) {
  int fX, fY;
  double dX, dY;
  double u,v;
  int a, b;

  fX = ((int)x) % _size;
  fY = ((int)y) % _size;

  dX = x - (int)x;
  dY = y - (int)y;

  u = fade(dX);
  v = fade(dY);

  a = _p[fX]   + fY;
  b = _p[fX+1] + fY;

  return lerp(v,
    lerp(u,
      gradient2(_p[a],   dX,   dY  ),
      gradient2(_p[b],   dX-1, dY  )
    ),
    lerp(u,
      gradient2(_p[a+1], dX,   dY-1),
      gradient2(_p[b+1], dX-1, dY-1)
    )
  );
}
void VesselConnectionView::paint(QPainter *painter,
                                 const QStyleOptionGraphicsItem *option,
                                 QWidget *widget)
{
	Q_UNUSED(widget);

	double lod = option->levelOfDetailFromTransform(painter->transform());
	if (lod < minLOD())
		return;

	QColor fill_color = baseColor(option);
	QColor dark_fill_color = fill_color.dark();

	QGradientStops stops;
	stops << QGradientStop(0.038, dark_fill_color)
	      << QGradientStop(0.128, fill_color)
	      << QGradientStop(0.174, fill_color)
	      << QGradientStop(0.174+0.125-0.03, dark_fill_color)
	      << QGradientStop(0.45, fill_color)
	      << QGradientStop(0.55, fill_color)

	      << QGradientStop(1-(0.174+0.125-0.03), dark_fill_color)
	      << QGradientStop(1-0.174, fill_color)
	      << QGradientStop(1-0.128, fill_color)
	      << QGradientStop(1-0.038, dark_fill_color);
	const QRectF &br = boundingRect();
	QLinearGradient gradient(QLineF(br.topLeft(), br.topRight()).pointAt(0.5),
	                         QLineF(br.bottomRight(), br.bottomLeft()).pointAt(0.5));
	gradient.setStops(stops);

	QLinearGradient gradient2(QLineF(br.topLeft(), br.bottomLeft()).pointAt(0.5),
	                          QLineF(br.topRight(), br.bottomRight()).pointAt(0.5));
	QColor transparent_color(fill_color), semi_transparent_color(fill_color);
	transparent_color.setAlpha(0);
	semi_transparent_color.setAlpha(200);

	gradient2.setStops(QGradientStops()
	                   << QGradientStop(0, transparent_color)
	                   << QGradientStop(0.45, semi_transparent_color)
	                   << QGradientStop(0.55, semi_transparent_color)
	                   << QGradientStop(1, transparent_color));

	painter->setPen(QPen(penColor(option), 32/2, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin));
	painter->drawPath(path);

	if (isClearBg()) {
		painter->fillPath(fill, Qt::white);
	}
	else {
		painter->fillPath(fill, gradient);
		painter->fillPath(fill, gradient2);
	}
}
Peg::Peg(const QPoint& hole, Board* board, QGraphicsItem* parent)
: QGraphicsEllipseItem(0, 0, 20, 20, parent),
  m_hole(hole),
  m_board(board) {
	setPen(Qt::NoPen);

	QGraphicsEllipseItem* gloss = new QGraphicsEllipseItem(3, 1.5, 14, 9, this);
	QLinearGradient gradient2(0, 0, 0, 9);
	gradient2.setColorAt(0, QColor(255, 255, 255));
	gradient2.setColorAt(1, QColor(255, 255, 255, 0));
	gloss->setBrush(gradient2);
	gloss->setPen(Qt::NoPen);

	setZValue(2);
	setPos(hole.x() * 20, hole.y() * 20);
	setFlag(QGraphicsItem::ItemIsMovable, true);
	setCursor(Qt::OpenHandCursor);
}
Пример #4
0
void PaintWidget::paintEvent(QPaintEvent *event)
{
    QLinearGradient gradient1(rect().topLeft(), rect().bottomRight());
    gradient1.setColorAt(0, QColor("#ffffcc"));
    gradient1.setColorAt(1, QColor("#ccccff"));

    QRectF ellipseRect(width()*0.25, height()*0.25, width()*0.5, height()*0.5);
    QLinearGradient gradient2(ellipseRect.topLeft(), ellipseRect.bottomRight());
    gradient2.setColorAt(0, QColor("#ccccff"));
    gradient2.setColorAt(1, QColor("#ffffcc"));

    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(rect(), QBrush(gradient1));
    painter.setBrush(QBrush(gradient2));
    painter.drawEllipse(ellipseRect);
    painter.end();
}
Пример #5
0
SocioTwitterwidget::SocioTwitterwidget(const QRectF &rect, QWidget *widget):
    DesktopWidget(rect, widget)
{


    if (SocioTwitterwidget->objectName().isEmpty())
        SocioTwitterwidget->setObjectName(QString::fromUtf8("SocioTwitterClass"));
    SocioTwitterwidget->resize(272, 415);
    QSizePolicy sizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(SocioTwitterClass->sizePolicy().hasHeightForWidth());
    SocioTwitterwidget->setSizePolicy(sizePolicy);
    SocioTwitterwidget->setCursor(QCursor(Qt::ArrowCursor));
    SocioTwitterwidget->setAcceptDrops(true);
    SocioTwitterwidget->setWindowTitle(QString::fromUtf8("SocioTwitter"));
    SocioTwitterwidget->setAutoFillBackground(false);
    SocioTwitterwidget->setStyleSheet(QString::fromUtf8("QWidget{   \n"
                                      "background:transparent;\n"
                                      "transparent-color:black;\n"
                                      "background-color:qlineargradient(spread:pad, x1:0.604, y1:0.409, x2:0.193, y2:0.938, stop:0.233503 rgba(1, 0, 		0,255))\n"
                                      "\n"
                                      "\n"
                                      "  }"));

    lineEdit = new QLineEdit(SocioTwitterwidget);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    lineEdit->setGeometry(QRect(0, 370, 271, 41));
    QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed);
    sizePolicy1.setHorizontalStretch(0);
    sizePolicy1.setVerticalStretch(0);
    sizePolicy1.setHeightForWidth(lineEdit->sizePolicy().hasHeightForWidth());

    lineEdit->setSizePolicy(sizePolicy1);
    lineEdit->setFocusPolicy(Qt::StrongFocus);
    lineEdit->setStyleSheet(QString::fromUtf8("QLineEdit {     \n"
                            " border: 1px solid gray;     \n"
                            " border-radius: 5px;     \n"
                            " padding: 0 8px;     \n"
                            " background: beige;     \n"
                            " selection-background-color: darkgray;\n"
                            "  }"));

    scrollArea = new QScrollArea(SocioTwitterwidget);
    scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
    scrollArea->setGeometry(QRect(0, 40, 271, 331));

    QSizePolicy sizePolicy2(QSizePolicy::Fixed, QSizePolicy::Fixed);

    sizePolicy2.setHorizontalStretch(10);
    sizePolicy2.setVerticalStretch(0);
    sizePolicy2.setHeightForWidth(scrollArea->sizePolicy().hasHeightForWidth());

    scrollArea->setSizePolicy(sizePolicy2);
    scrollArea->setAcceptDrops(true);
    scrollArea->setAutoFillBackground(true);
    scrollArea->setFrameShape(QFrame::NoFrame);
    scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
    scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    scrollArea->setWidgetResizable(true);
    scrollArea->setAlignment(Qt::AlignHCenter | Qt::AlignTop);

    scrollAreaWidgetContents = new QWidget();
    scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
    scrollAreaWidgetContents->setGeometry(QRect(0, 0, 267, 327));

    graphicsView = new QGraphicsView(scrollAreaWidgetContents);
    graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
    graphicsView->setGeometry(QRect(10, 20, 61, 51));
    graphicsView->setFrameShadow(QFrame::Raised);
    graphicsView->setLineWidth(1);
    graphicsView->setMidLineWidth(0);
    graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    graphicsView_2 = new QGraphicsView(scrollAreaWidgetContents);
    graphicsView_2->setObjectName(QString::fromUtf8("graphicsView_2"));
    graphicsView_2->setGeometry(QRect(10, 80, 61, 51));
    graphicsView_2->setFrameShape(QFrame::StyledPanel);

    graphicsView_3 = new QGraphicsView(scrollAreaWidgetContents);
    graphicsView_3->setObjectName(QString::fromUtf8("graphicsView_3"));
    graphicsView_3->setGeometry(QRect(10, 140, 61, 51));
    graphicsView_3->setFrameShape(QFrame::NoFrame);

    graphicsView_4 = new QGraphicsView(scrollAreaWidgetContents);
    graphicsView_4->setObjectName(QString::fromUtf8("graphicsView_4"));
    graphicsView_4->setGeometry(QRect(10, 200, 61, 51));
    graphicsView_4->setFrameShape(QFrame::StyledPanel);

    graphicsView_5 = new QGraphicsView(scrollAreaWidgetContents);
    graphicsView_5->setObjectName(QString::fromUtf8("graphicsView_5"));
    graphicsView_5->setGeometry(QRect(10, 260, 61, 51));
    graphicsView_5->setFrameShape(QFrame::NoFrame);

    textBrowser = new QTextBrowser(scrollAreaWidgetContents);
    textBrowser->setObjectName(QString::fromUtf8("textBrowser"));
    textBrowser->setGeometry(QRect(80, 20, 181, 51));
    textBrowser->setFrameShape(QFrame::Box);

    textBrowser_2 = new QTextBrowser(scrollAreaWidgetContents);
    textBrowser_2->setObjectName(QString::fromUtf8("textBrowser_2"));
    textBrowser_2->setGeometry(QRect(80, 80, 181, 51));
    textBrowser_2->setFrameShape(QFrame::NoFrame);

    textBrowser_3 = new QTextBrowser(scrollAreaWidgetContents);
    textBrowser_3->setObjectName(QString::fromUtf8("textBrowser_3"));
    textBrowser_3->setGeometry(QRect(80, 140, 181, 51));
    textBrowser_3->setFrameShape(QFrame::NoFrame);

    textBrowser_4 = new QTextBrowser(scrollAreaWidgetContents);
    textBrowser_4->setObjectName(QString::fromUtf8("textBrowser_4"));
    textBrowser_4->setGeometry(QRect(80, 200, 181, 51));
    textBrowser_4->setFrameShape(QFrame::NoFrame);

    textBrowser_5 = new QTextBrowser(scrollAreaWidgetContents);
    textBrowser_5->setObjectName(QString::fromUtf8("textBrowser_5"));
    textBrowser_5->setGeometry(QRect(80, 260, 181, 51));
    textBrowser_5->setFrameShape(QFrame::NoFrame);

    scrollArea->setWidget(scrollAreaWidgetContents);

    pushButton = new QPushButton(SocioTwitterClass);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));
    pushButton->setGeometry(QRect(10, 10, 71, 41));

    QFont font;
    font.setBold(true);
    font.setWeight(75);

    pushButton->setFont(font);
    pushButton->setCursor(QCursor(Qt::PointingHandCursor));
    pushButton->setMouseTracking(false);
    pushButton->setFocusPolicy(Qt::StrongFocus);

    OPtions = new QPushButton(SocioTwitterClass);
    OPtions->setObjectName(QString::fromUtf8("OPtions"));
    OPtions->setEnabled(true);
    OPtions->setGeometry(QRect(80, 10, 71, 41));

    QPalette palette;
    QLinearGradient gradient(0.604, 0.409, 0.193, 0.938);

    gradient.setSpread(QGradient::PadSpread);
    gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
    gradient.setColorAt(0.233503, QColor(1, 0, 0, 255));
    QBrush brush(gradient);

    palette.setBrush(QPalette::Active, QPalette::Button, brush);
    QBrush brush1(QColor(169, 169, 169, 255));
    brush1.setStyle(Qt::SolidPattern);
    palette.setBrush(QPalette::Active, QPalette::Highlight, brush1);
    QLinearGradient gradient1(0.604, 0.409, 0.193, 0.938);
    gradient1.setSpread(QGradient::PadSpread);
    gradient1.setCoordinateMode(QGradient::ObjectBoundingMode);
    gradient1.setColorAt(0.233503, QColor(1, 0, 0, 255));

    QBrush brush2(gradient1);
    palette.setBrush(QPalette::Inactive, QPalette::Button, brush2);
    palette.setBrush(QPalette::Inactive, QPalette::Highlight, brush1);
    QLinearGradient gradient2(0.604, 0.409, 0.193, 0.938);

    gradient2.setSpread(QGradient::PadSpread);
    gradient2.setCoordinateMode(QGradient::ObjectBoundingMode);
    gradient2.setColorAt(0.233503, QColor(1, 0, 0, 255));

    QBrush brush3(gradient2);
    palette.setBrush(QPalette::Disabled, QPalette::Button, brush3);
    palette.setBrush(QPalette::Disabled, QPalette::Highlight, brush1);
    OPtions->setPalette(palette);

    QFont font1;
    font1.setFamily(QString::fromUtf8("Sans Serif"));
    font1.setPointSize(10);
    font1.setBold(true);
    font1.setWeight(75);

    OPtions->setFont(font1);
    OPtions->setCursor(QCursor(Qt::PointingHandCursor));
    OPtions->setAutoDefault(false);
    OPtions->setDefault(false);
    OPtions->setFlat(false);

    retranslateUi(SocioTwitterClass);

    QMetaObject::connectSlotsByName(SocioTwitterClass);
}
Пример #6
0
void UBGraphicsTriangle::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->setPen(Qt::NoPen);

    QPolygonF polygon;

    QLinearGradient gradient1(QPointF(A1.x(), 0), QPointF(A2.x(), 0));
    gradient1.setColorAt(0, edgeFillColor());
    gradient1.setColorAt(1, middleFillColor());
    painter->setBrush(gradient1);
    polygon << A1 << A2 << B2 << B1;
    painter->drawPolygon(polygon);
    polygon.clear();

    QLinearGradient gradient2(QPointF(0, B1.y()), QPointF(0, B2.y()));
    gradient2.setColorAt(0, edgeFillColor());
    gradient2.setColorAt(1, middleFillColor());
    painter->setBrush(gradient2);
    polygon << B1 << B2 << C2 << C1;
    painter->drawPolygon(polygon);
    polygon.clear();

    QLinearGradient gradient3(CC, C2);
    gradient3.setColorAt(0, edgeFillColor());
    gradient3.setColorAt(1, middleFillColor());
    painter->setBrush(gradient3);
    polygon << C1 << C2 << A2 << A1;
    painter->drawPolygon(polygon);
    polygon.clear();


    painter->setBrush(Qt::NoBrush);
    painter->setPen(drawColor());

    polygon << A1 << B1 << C1;
    painter->drawPolygon(polygon);
    polygon.clear();

    polygon << A2 << B2 << C2;
    painter->drawPolygon(polygon);

    paintGraduations(painter);

    mAntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom());
    QTransform antiScaleTransform;
    antiScaleTransform.scale(mAntiScaleRatio, mAntiScaleRatio);

    mCloseSvgItem->setTransform(antiScaleTransform);
    mHFlipSvgItem->setTransform(antiScaleTransform);
    mVFlipSvgItem->setTransform(antiScaleTransform);
    mRotateSvgItem->setTransform(antiScaleTransform);

    mCloseSvgItem->setPos(closeButtonRect().topLeft());
    mHFlipSvgItem->setPos(hFlipRect().topLeft());
    mVFlipSvgItem->setPos(vFlipRect().topLeft());
    mRotateSvgItem->setPos(rotateRect().topLeft());

    if (mShowButtons || mResizing1 || mResizing2)
    {
        painter->setBrush(QColor(0, 0, 0));
        if (mShowButtons || mResizing1)
            painter->drawPolygon(resize1Polygon());
        if (mShowButtons || mResizing2)
            painter->drawPolygon(resize2Polygon());
    }
}
Пример #7
0
void QScriptEdit::extraAreaPaintEvent(QPaintEvent *e)
{
    QRect rect = e->rect();
    QPalette pal = palette();
    pal.setCurrentColorGroup(QPalette::Active);
    QPainter painter(m_extraArea);
    painter.fillRect(rect, Qt::lightGray);
    const QFontMetrics fm(fontMetrics());

    int markWidth = fm.lineSpacing();
    int extraAreaWidth = m_extraArea->width();

    QLinearGradient gradient(QPointF(extraAreaWidth - 10, 0), QPointF(extraAreaWidth, 0));
    gradient.setColorAt(0, pal.color(QPalette::Background));
    gradient.setColorAt(1, pal.color(QPalette::Base));
    painter.fillRect(rect, gradient);

    QLinearGradient gradient2(QPointF(0, 0), QPointF(markWidth, 0));
    gradient2.setColorAt(0, pal.color(QPalette::Dark));
    gradient2.setColorAt(1, pal.color(QPalette::Background));
    painter.fillRect(rect.intersected(QRect(rect.x(), rect.y(), markWidth, rect.height())), gradient2);

    painter.setPen(QPen(pal.color(QPalette::Background), 2));
    if (isLeftToRight())
        painter.drawLine(rect.x() + extraAreaWidth-1, rect.top(), rect.x() + extraAreaWidth-1, rect.bottom());
    else
        painter.drawLine(rect.x(), rect.top(), rect.x(), rect.bottom());
    painter.setRenderHint(QPainter::Antialiasing);

    QTextBlock block = firstVisibleBlock();
    int blockNumber = block.blockNumber();
    qreal top = blockBoundingGeometry(block).translated(contentOffset()).top();
    qreal bottom = top + blockBoundingRect(block).height();

    QString imagesPath = QString::fromLatin1(":/qt/scripttools/debugging/images");
    QString imageExt;
// SVGs don't work on all platforms, even when QT_NO_SVG is not defined, so disable SVG usage for now.
// #ifndef QT_NO_SVG
#if 0
    imageExt = QString::fromLatin1("svg");
#else
    imageExt = QString::fromLatin1("png");
#endif

    while (block.isValid() && top <= rect.bottom()) {
        if (block.isVisible() && bottom >= rect.top()) {

            int lineNumber = blockNumber + m_baseLineNumber;
            if (m_breakpoints.contains(lineNumber)) {
                int radius = fm.lineSpacing() - 1;
                QRect r(rect.x(), (int)top, radius, radius);
                QIcon icon(m_breakpoints[lineNumber].enabled
                           ? QString::fromLatin1("%0/breakpoint.%1").arg(imagesPath).arg(imageExt)
                           : QString::fromLatin1("%0/d_breakpoint.%1").arg(imagesPath).arg(imageExt));
                icon.paint(&painter, r, Qt::AlignCenter);
            }
            if (m_executionLineNumber == lineNumber) {
                int radius = fm.lineSpacing() - 1;
                QRect r(rect.x(), (int)top, radius, radius);
                QIcon icon(QString::fromLatin1("%0/location.%1").arg(imagesPath).arg(imageExt));
                icon.paint(&painter, r, Qt::AlignCenter);
            }

            if (!isExecutableLine(lineNumber))
                painter.setPen(pal.color(QPalette::Mid));
            else
                painter.setPen(QColor(Qt::darkCyan));
            QString number = QString::number(lineNumber);
            painter.drawText(rect.x() + markWidth, (int)top, rect.x() + extraAreaWidth - markWidth - 4,
                             fm.height(), Qt::AlignRight, number);
        }

        block = block.next();
        top = bottom;
        bottom = top + blockBoundingRect(block).height();
        ++blockNumber;
    }
}
Пример #8
0
SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
                          char *psz_colors, int max )
                        : QAbstractSlider( _parent )
{
    qreal scalingFactorX = static_cast<qreal>(logicalDpiX()) / DPI_REF_VALUE;
    qreal scalingFactorY = static_cast<qreal>(logicalDpiY()) / DPI_REF_VALUE;

    wlength = WLENGTH_BASE * scalingFactorX;
    wheight = WHEIGHT_BASE * scalingFactorY;

    f_step = (float)(_i_step * 10000)
           / (float)((max - SOUNDMIN) * AOUT_VOLUME_DEFAULT);
    setRange( SOUNDMIN, max);
    setMouseTracking( true );
    isSliding = false;
    b_mouseOutside = true;
    b_isMuted = false;

    const QPixmap pixOutsideRaw(Helper::getIconPath("volume-slider-outside.png"));
    const QSize pixOutsideSize(
                static_cast<qreal>(pixOutsideRaw.width()) * scalingFactorX,
                static_cast<qreal>(pixOutsideRaw.height()) * scalingFactorY
            );
    pixOutside = pixOutsideRaw.scaled(pixOutsideSize);

    const QPixmap tempRaw(Helper::getIconPath("volume-slider-inside.png"));
    const QSize tempSize(
                    static_cast<qreal>(tempRaw.width()) * scalingFactorX,
                    static_cast<qreal>(tempRaw.height()) * scalingFactorY
            );
    const QPixmap temp = tempRaw.scaled(tempSize);

    const QBitmap mask( temp.createHeuristicMask() );

    setFixedSize( pixOutside.size() );

    pixGradient = QPixmap( mask.size() );
    pixGradient2 = QPixmap( mask.size() );

    /* Gradient building from the preferences */
    QLinearGradient gradient( paddingL, 2, wlength + paddingL , 2 );
    QLinearGradient gradient2( paddingL, 2, wlength + paddingL , 2 );

    QStringList colorList = qfu( psz_colors ).split( ";" );
    free( psz_colors );

    /* Fill with 255 if the list is too short */
    if( colorList.count() < 12 )
        for( int i = colorList.count(); i < 12; i++)
            colorList.append( "255" );

    background = palette().color( QPalette::Active, QPalette::Window );
    foreground = palette().color( QPalette::Active, QPalette::WindowText );
    foreground.setHsv( foreground.hue(),
                    ( background.saturation() + foreground.saturation() ) / 2,
                    ( background.value() + foreground.value() ) / 2 );

    textfont.setPointSize( 9 );
    textrect.setRect( 0, 0, 34.0*scalingFactorX, 15.0*scalingFactorY );

    /* Regular colors */
#define c(i) colorList.at(i).toInt()
#define add_color(gradient, range, c1, c2, c3) \
    gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );

    /* Desaturated colors */
#define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
#define add_desaturated_color(gradient, range, c1, c2, c3) \
    foo = new QColor( c(c1), c(c2), c(c3) );\
    desaturate( foo ); gradient.setColorAt( range, *foo );\
    delete foo;

    /* combine the two helpers */
#define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
    add_color( gradient1, range, c1, c2, c3 ); \
    add_desaturated_color( gradient2, range, c1, c2, c3 );

    float f_mid_point = ( 100.0 / maximum() );
    QColor * foo;
    add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
    if (f_mid_point + 0.05 <= 1.0) {
        add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
        add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
    }
    add_colors( gradient, gradient2, 1.0, 9, 10, 11 );

    painter.begin( &pixGradient );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient );
    painter.drawRect( pixGradient.rect() );
    painter.end();

    painter.begin( &pixGradient2 );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient2 );
    painter.drawRect( pixGradient2.rect() );
    painter.end();

    pixGradient.setMask( mask );
    pixGradient2.setMask( mask );
}
Пример #9
0
SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
                          char *psz_colors )
                        : QAbstractSlider( _parent )
{
    f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
    setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX  );
    setMouseTracking( true );
    isSliding = false;
    b_mouseOutside = true;
    b_isMuted = false;

    pixOutside = QPixmap( ":/toolbar/volslide-outside" );

    const QPixmap temp( ":/toolbar/volslide-inside" );
    const QBitmap mask( temp.createHeuristicMask() );

    setFixedSize( pixOutside.size() );

    pixGradient = QPixmap( mask.size() );
    pixGradient2 = QPixmap( mask.size() );

    /* Gradient building from the preferences */
    QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
    QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );

    QStringList colorList = qfu( psz_colors ).split( ";" );
    free( psz_colors );

    /* Fill with 255 if the list is too short */
    if( colorList.count() < 12 )
        for( int i = colorList.count(); i < 12; i++)
            colorList.append( "255" );

    background = palette().color( QPalette::Active, QPalette::Background );
    foreground = palette().color( QPalette::Active, QPalette::WindowText );
    foreground.setHsv( foreground.hue(),
                    ( background.saturation() + foreground.saturation() ) / 2,
                    ( background.value() + foreground.value() ) / 2 );

    textfont.setPixelSize( 9 );
    textrect.setRect( 0, 0, 34, 15 );

    /* Regular colors */
#define c(i) colorList.at(i).toInt()
#define add_color(gradient, range, c1, c2, c3) \
    gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );

    /* Desaturated colors */
#define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
#define add_desaturated_color(gradient, range, c1, c2, c3) \
    foo = new QColor( c(c1), c(c2), c(c3) );\
    desaturate( foo ); gradient.setColorAt( range, *foo );\
    delete foo;

    /* combine the two helpers */
#define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
    add_color( gradient1, range, c1, c2, c3 ); \
    add_desaturated_color( gradient2, range, c1, c2, c3 );

    float f_mid_point = ( 100.0 / maximum() );
    QColor * foo;
    add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
    add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
    add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
    add_colors( gradient, gradient2, 1.0, 9, 10, 11 );

    painter.begin( &pixGradient );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient );
    painter.drawRect( pixGradient.rect() );
    painter.end();

    painter.begin( &pixGradient2 );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient2 );
    painter.drawRect( pixGradient2.rect() );
    painter.end();

    pixGradient.setMask( mask );
    pixGradient2.setMask( mask );
}