Пример #1
0
static bool pulse(QBrush& ref, bool pulse)
{
  bool invert = false;
  auto col = ref.color();
  auto alpha = col.alphaF();
  if (pulse)
  {
    alpha += 0.02;
    if (alpha >= 1)
    {
      invert = true;
      alpha = 1;
    }
    col.setAlphaF(alpha);
  }
  else
  {
    alpha -= 0.02;
    if (alpha <= 0.5)
    {
      invert = true;
      alpha = 0.5;
    }
    col.setAlphaF(alpha);
  }
  ref.setColor(col);
  return invert;
}
Пример #2
0
void DeviceExplorerView::paintEvent(QPaintEvent* event)
{
  QTreeView::paintEvent(event);
  if (model() && model()->rowCount(rootIndex()) > 0)
    return;

  QPainter p{this->viewport()};
  const auto& skin = score::Skin::instance();
  auto font = skin.Bold12Pt;
  font.setPointSize(24);
  p.setFont(font);
  auto pen = p.pen();
  auto col = pen.color();
  col.setAlphaF(0.5);
  pen.setColor(col);
  p.setPen(pen);
  p.drawText(rect(), Qt::AlignCenter, "Right-click\nto add a device");
}
Пример #3
0
void ColorView::mouseMoveEvent(QMouseEvent *e)
{
    if (e->buttons() & Qt::LeftButton) {
        if ((e->pos() - dragStartPos_).manhattanLength() >= QApplication::startDragDistance()) {
            QDrag *drag = new QDrag(this);
            QMimeData *mimeData = new QMimeData;

            mimeData->setColorData(value_);
            drag->setMimeData(mimeData);

            QPixmap pix(20, 20);
            auto size = pix.size();
            {
                QPainter p(&pix);

                for (int x = 0; x < size.width(); x += 5) {
                    for (int y = 0; y < size.height(); y += 5) {
                        p.fillRect(x, y, 5, 5, ((x + y) / 5 & 1) ? QColor(255, 255, 255) : QColor(192, 192, 192));
                    }
                }

                p.fillRect(0, 0, size.width(), size.height(), value_);
                auto v2 = value_;
                v2.setAlphaF(1.f);
                p.fillRect(0, 0, size.width() / 2, size.height(), v2);

                p.setPen(QColor(0, 0, 0));
                p.drawRect(0, 0, size.width() - 1, size.height() - 1);
                p.setPen(QColor(255, 255, 255));
                p.drawRect(1, 1, size.width() - 3, size.height() - 3);
            }

            drag->setPixmap(pix);
            drag->exec(Qt::CopyAction | Qt::MoveAction);
            return;
        }
    }

    QAbstractButton::mouseMoveEvent(e);
}
Пример #4
0
void ColorView::paintEvent(QPaintEvent *)
{
    QPainter p(this);
    QSize size = this->size();

    for (int x = 0; x < size.width(); x += 10) {
        for (int y = 0; y < size.height(); y += 10) {
            p.fillRect(x, y, 10, 10, ((x + y) / 10 & 1) ? QColor(255, 255, 255) : QColor(192, 192, 192));
        }
    }

    p.fillRect(0, 0, size.width(), size.height(), value_);
    auto v2 = value_;
    v2.setAlphaF(1.f);
    p.fillRect(0, 0, size.width() / 2, size.height(), v2);

    p.setPen(QColor(0, 0, 0));
    p.drawRect(0, 0, size.width() - 1, size.height() - 1);
    p.setPen(QColor(255, 255, 255));
    p.drawRect(1, 1, size.width() - 3, size.height() - 3);

}
Пример #5
0
	void PlotItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*)
	{
		const auto& rect = option->rect;
#else
	void PlotItem::paint (QPainter *painter)
	{
		const auto& rect = contentsBoundingRect ().toRect ();
#endif

		QwtPlot plot;
		plot.setFrameShape (QFrame::NoFrame);
		plot.enableAxis (QwtPlot::yLeft, LeftAxisEnabled_);
		plot.enableAxis (QwtPlot::xBottom, BottomAxisEnabled_);
		plot.setAxisTitle (QwtPlot::yLeft, LeftAxisTitle_);
		plot.setAxisTitle (QwtPlot::xBottom, BottomAxisTitle_);
		plot.resize (rect.size ());

		auto setPaletteColor = [&plot] (const QColor& color, QPalette::ColorRole role) -> void
		{
			if (!color.isValid ())
				return;

			auto pal = plot.palette ();
			pal.setColor (role, { color });
			plot.setPalette (pal);
		};

		setPaletteColor (BackgroundColor_, QPalette::Window);
		setPaletteColor (TextColor_, QPalette::WindowText);
		setPaletteColor (TextColor_, QPalette::Text);

		if (!PlotTitle_.isEmpty ())
			plot.setTitle (QwtText { PlotTitle_ });

		if (MinYValue_ < MaxYValue_)
		{
			plot.setAxisAutoScale (QwtPlot::yLeft, false);
			plot.setAxisScale (QwtPlot::yLeft, MinYValue_, MaxYValue_);
		}
		plot.setAutoFillBackground (false);
		plot.setCanvasBackground (Qt::transparent);

		if (YGridEnabled_)
		{
			auto grid = new QwtPlotGrid;
			grid->enableYMin (YMinorGridEnabled_);
			grid->enableX (false);
#if QWT_VERSION >= 0x060100
			grid->setMajorPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinorPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#else
			grid->setMajPen (QPen (GridLinesColor_, 1, Qt::SolidLine));
			grid->setMinPen (QPen (GridLinesColor_, 1, Qt::DashLine));
#endif
			grid->attach (&plot);
		}

		auto items = Multipoints_;
		if (items.isEmpty ())
			items.push_back ({ Color_, Points_ });

		if (MinXValue_ < MaxXValue_)
			plot.setAxisScale (QwtPlot::xBottom, MinXValue_, MaxXValue_);
		else if (const auto ptsCount = items.first ().Points_.size ())
			plot.setAxisScale (QwtPlot::xBottom, 0, ptsCount - 1);

		std::vector<std::unique_ptr<QwtPlotCurve>> curves;
		for (const auto& item : items)
		{
			curves.emplace_back (new QwtPlotCurve);
			const auto curve = curves.back ().get ();

			curve->setPen (QPen (item.Color_));
			auto transpColor = item.Color_;
			transpColor.setAlphaF (Alpha_);
			curve->setBrush (transpColor);

			curve->setRenderHint (QwtPlotItem::RenderAntialiased);
			curve->attach (&plot);

			curve->setSamples (item.Points_.toVector ());
		}

		plot.replot ();

		QwtPlotRenderer {}.render (&plot, painter, rect);

		const auto xExtent = CalcXExtent (plot);
		const auto yExtent = CalcYExtent (plot);
		if (xExtent != XExtent_ || yExtent != YExtent_)
		{
			XExtent_ = xExtent;
			YExtent_ = yExtent;
			emit extentsChanged ();
		}
	}
Пример #6
0
Color::Color(float red, float green, float blue, float alpha) {
    setRedF(red);
    setGreenF(green);
    setBlueF(blue);
    setAlphaF(alpha);
}