Beispiel #1
0
VolumeSlider::VolumeSlider(QWidget *p)
    : QSlider(p)
    , lineWidth(0)
    , shown(false)
    , down(false)
    , fadingStop(false)
    , muteAction(0)
    , menu(0)
{
    widthStep=Utils::touchFriendly() ? 5 : 4;
    setRange(0, 100);
    setPageStep(Settings::self()->volumeStep());
    lineWidth=Utils::scaleForDpi(1);

    int w=lineWidth*widthStep*19;
    int h=lineWidth*constHeightStep*10;
    setFixedHeight(h+1);
    setFixedWidth(w);
    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    setOrientation(Qt::Horizontal);
    setFocusPolicy(Qt::NoFocus);
    setStyle(new VolumeSliderProxyStyle());
    setStyleSheet(QString("QSlider::groove:horizontal {border: 0px;} "
                          "QSlider::sub-page:horizontal {border: 0px;} "
                          "QSlider::handle:horizontal {width: 0px; height:0px; margin:0;}"));
    textCol=clampColor(palette().color(QPalette::Active, QPalette::Text));
    generatePixmaps();
}
Beispiel #2
0
void VolumeSlider::showEvent(QShowEvent *ev)
{
    if (!shown) {
        shown=true;
        QLabel lbl(parentWidget());
        lbl.ensurePolished();
        QColor col=clampColor(lbl.palette().text().color());

        if (col!=textCol) {
            textCol=col;
            generatePixmaps();
        }
    }
    QSlider::showEvent(ev);
}
Beispiel #3
0
void BoxStyle::optimizedPaint(QPainter* painter, int xOffset, int yOffset, int contentBoxWidth,
				int contentBoxHeight) const
{
	qreal scaleFactor = painter->worldTransform().m11();
	int outlineWidth = outline_.style()==Qt::SolidLine ? outline_.width() : 0;
	int halfOutline = std::ceil(outlineWidth/2.0);

	if (corner_ == CornerType::RightAngle || cornerRadius_*scaleFactor <= 1.0 )
	{
		int innerWidth = contentBoxWidth - 2*halfOutline;
		int innerHieght = contentBoxHeight - 2*halfOutline;

		// Note that the half of the outline overlaps the background.

		// Draw a simplified version
		if (background_.style() == Qt::SolidPattern)
			painter->fillRect(xOffset + halfOutline, yOffset + halfOutline, innerWidth, innerHieght, background_.color());

		// Paint outline
		if (outline_.style() == Qt::SolidLine)
		{
			//Top
			painter->fillRect(xOffset, yOffset, contentBoxWidth, outlineWidth, outline_.color());
			//Left
			painter->fillRect(xOffset, yOffset + outlineWidth, outlineWidth,
					contentBoxHeight-2*outlineWidth, outline_.color());
			//Bottom
			painter->fillRect(xOffset, yOffset + contentBoxHeight - outlineWidth, contentBoxWidth,
					outlineWidth, outline_.color());
			//Right
			painter->fillRect(xOffset + contentBoxWidth - outlineWidth, yOffset + outlineWidth,
					outlineWidth, contentBoxHeight-2*outlineWidth, outline_.color());
		}

		return;
	}

	int subImageSize = cornerRadius_ + halfOutline;

	// Paint corners
	if (cornerRadius_ > 0)
	{
		if (scaleFactor*cornerRadius_ >= 1)
		{
			// Draw the corners in case there are at least one pixel
			bool hasScale = topLeftCorner_.paint(painter, xOffset, yOffset);
			if (!hasScale)
			{
				generatePixmaps(scaleFactor, painter);
				topLeftCorner_.paint(painter, xOffset, yOffset);
			}

			int rightCornerStart = contentBoxWidth - subImageSize;
			int bottomCornerStart = contentBoxHeight - subImageSize;

			topRightCorner_.paint(painter, xOffset + rightCornerStart, yOffset);
			bottomLeftCorner_.paint(painter, xOffset, yOffset + bottomCornerStart);
			bottomRightCorner_.paint(painter, xOffset + rightCornerStart, yOffset + bottomCornerStart);
		}
	}

	int innerWidth = contentBoxWidth - 2*subImageSize;
	int innerHeight = contentBoxHeight - 2*subImageSize;

	// Paint background
	if (background_.style() == Qt::SolidPattern)
	{
		// vertical middle
		painter->fillRect(xOffset + subImageSize, yOffset + outlineWidth,
				innerWidth, contentBoxHeight - 2*outlineWidth, background_.color());
		// left
		painter->fillRect(xOffset + outlineWidth, yOffset + subImageSize,
				subImageSize - outlineWidth, innerHeight, background_.color());
		// right
		painter->fillRect(xOffset + contentBoxWidth - subImageSize, yOffset + subImageSize,
				subImageSize - outlineWidth, innerHeight, background_.color());
	}

	// Paint outline
	if (outline_.style() == Qt::SolidLine)
	{
		// top
		painter->fillRect(xOffset + subImageSize, yOffset,
				innerWidth, outlineWidth, outline_.color());
		// bottom
		painter->fillRect(xOffset + subImageSize, yOffset + contentBoxHeight - outlineWidth,
				innerWidth, outlineWidth, outline_.color());
		// left
		painter->fillRect(xOffset , yOffset + subImageSize,
				outlineWidth, innerHeight, outline_.color());
		// right
		painter->fillRect(xOffset + contentBoxWidth - outlineWidth, yOffset + subImageSize,
				outlineWidth, innerHeight, outline_.color());
	}
}