Example #1
0
static
QString
qcolor_to_qstring(const QColor& col)
{
    return QString::fromUtf8("rgb(%1,%2,%3)").arg( col.red() ).arg( col.green() ).arg( col.blue() );
}
Example #2
0
void MainWindow::lineWorld()
{
	QColor color;
	Mat image;
	std::default_random_engine generator;
	std::normal_distribution<double> onDistribution(30.0,10.0);
	std::normal_distribution<double> offDistribution(10.0,5.0);
	int x, y;

	int number = 0;
	bool onOff = false;

	int width = 100;
	int height = 100;

	int stepSizeX = 11;
	int stepSizeY = 12;

	QFileDialog *dialog = new QFileDialog();
	dialog->setNameFilter("PNG Files (*.png)");
	dialog->setOption(QFileDialog::ReadOnly);
	//dialog->setOption(QFileDialog::DontUseNativeDialog);
	dialog->setDirectory(".");
	QStringList fileNames;
	if (dialog->exec()) {
		fileNames = dialog->selectedFiles();
		QString fileName = fileNames.at(0);
		image = imread(fileName.toStdString(), CV_LOAD_IMAGE_COLOR);
		height = image.rows;
		width = image.cols;


			motorControl.openShutter();
			for (y=0;y!=height;++y) {
				for(x=0;x!=width; x++) {
					motorControl.setLedColor(color);
					if (number<=0) {
						if(onOff) {
							color.setRed(0);
							color.setGreen(0);
							color.setBlue(0);
							motorControl.setLedColor(color);
							onOff = false;
							number = int(offDistribution(generator));
						} else {
							onOff = true;
							number = int(onDistribution(generator));
						}
					}

					if(onOff) {
						color.setBlue( image.data[((y*image.cols)+x)*3] );
						color.setGreen( image.data[((y*image.cols)+x)*3+1] );
						color.setRed( image.data[((y*image.cols)+x)*3+2] );
						motorControl.setLedColor(color);
					}

					motorControl.commandMotor1(3, -stepSizeX);


					number--;

				}
				motorControl.setLedColor(QColor(0,0,0));
				motorControl.commandMotor1(3, stepSizeX * width);		

				motorControl.commandMotor2(6, -stepSizeY);
			}
			motorControl.closeShutter();


			// Reset x axis to initial position if the width is uneven
			if( width%2 != 0) {
				motorControl.commandMotor1(6, stepSizeX * width);
			}

			// Reset y axis to initial position
			motorControl.commandMotor2(6, stepSizeY * height);

			motorControl.releaseMotor1();
			motorControl.releaseMotor2();


	}
}
Example #3
0
void MainWindow::colorLinesFull()
{
	QColor color;
	QColor *pColor;
	Mat image;
	std::default_random_engine generator;
	std::normal_distribution<double> onDistribution(30.0,10.0);

	QVector<QColor*> *colorVector;
	colorVector = computeGoldenRatioColors(0.01,0.99,1,100);

	int x, y;

	int number = 0;

	int width, height;

	int stepSizeX = 11;
	int stepSizeY = 12;

	QFileDialog *dialog = new QFileDialog();
	dialog->setNameFilter("PNG Files (*.png)");
	dialog->setOption(QFileDialog::ReadOnly);
	//dialog->setOption(QFileDialog::DontUseNativeDialog);
	dialog->setDirectory(".");
	QStringList fileNames;
	if (dialog->exec()) {
		fileNames = dialog->selectedFiles();
		QString fileName = fileNames.at(0);
		image = imread(fileName.toStdString(), CV_LOAD_IMAGE_COLOR);
		height = image.rows;
		width = image.cols;


			motorControl.openShutter();
			motorControl.commandMotor1(3, 5);  // Go a few steps back
			for (y=0;y!=height;++y) {
				motorControl.commandMotor1(3, -5);  // Go a few steps forth
				for(x=0;x!=width; x++) {
					motorControl.setLedColor(color);
					if (number<=0) {
						number = int(onDistribution(generator));
						pColor = colorVector->at(rand() % 100);
					}

					
					color.setBlue((image.data[((y*image.cols)+x)*3] / 6 * 5) + ( pColor->blue() / 6 ));
					color.setGreen((image.data[((y*image.cols)+x)*3+1] / 6 * 5)  + ( pColor->green() / 6));
					color.setRed((image.data[((y*image.cols)+x)*3+2] / 6 * 5) + ( pColor->red() / 6));
					motorControl.setLedColor(color);
					

					motorControl.commandMotor1(3, -stepSizeX);


					number--;

				}
				motorControl.setLedColor(QColor(0,0,0));
				motorControl.commandMotor1(3, stepSizeX * width);
				motorControl.commandMotor1(3, 5);  // Go a few steps back

				motorControl.commandMotor2(6, -stepSizeY);
			}
			motorControl.closeShutter();


			// Reset x axis to initial position if the width is uneven
			if( width%2 != 0) {
				motorControl.commandMotor1(6, stepSizeX * width);
			}

			// Reset y axis to initial position
			motorControl.commandMotor2(6, stepSizeY * height);

			motorControl.releaseMotor1();
			motorControl.releaseMotor2();


	}
}
Example #4
0
/**
  \todo fix b├ęzier interpolation
  \code
      C prev
     /   /
    /   /
   /   /
  A curr
   \
    \
     B next (can be NULL)
  \endcode
  */
void Interpolate_sV::bezierFlow(const QImage &prev, const QImage &right, const FlowField_sV *flowPrevCurr, const FlowField_sV *flowCurrNext, float pos, QImage &output)
{
    const float Wmax = prev.width()-1.0001;
    const float Hmax = prev.height()-1.0001;

    Vector_sV a, b, c;
    Vector_sV Ta, Sa;
    float dist;

    QColor colOut;

    for (int y = 0; y < prev.height(); y++) {
        for (int x = 0; x < prev.width(); x++) {

            a = Vector_sV(x, y);
            // WHY minus?
            c = a + Vector_sV(flowPrevCurr->x(x, y), flowPrevCurr->y(x, y));
            if (flowCurrNext != NULL) {
                b = a + Vector_sV(flowCurrNext->x(x,y), flowCurrNext->y(x,y));
            } else {
                b = a;
            }

            dist = (b-a).length() + (c-a).length();
            if (dist > 0) {
                Ta = b + ( (b-a).length() / dist ) * (c-b);
                Sa = (Ta - a).rotate90();
                Sa = a + Sa;

            } else {
                Sa = a;
            }
#ifdef DEBUG_I
            Sa = a;
#endif

            QPointF position = BezierTools_sV::interpolate(pos, c.toQPointF(), c.toQPointF(), Sa.toQPointF(), a.toQPointF());
            position.rx() = x - pos*flowPrevCurr->x(x,y);
            position.ry() = y - pos*flowPrevCurr->y(x,y);
            position.rx() = CLAMP(position.x(), 0, Wmax);
            position.ry() = CLAMP(position.y(), 0, Hmax);

#ifdef DEBUG_I
//            if (x == 100 && y == 100 && false) {
//                qDebug() << "Interpolated from " << toString(c.toQPointF()) << ", " << toString(a.toQPointF()) << ", "
//                         << toString(b.toQPointF()) << " at " << pos << ": " << toString(position);
//            }
            if (y % 4 == 0) {
                position.rx() = x;
                position.ry() = y;
            }
#endif

            colOut = interpolate(prev, position.x(), position.y());

#ifdef DEBUG_I
            if (y % 4 == 1 && x % 2 == 0) {
                colOut = right.pixel(x, y);
            }
#endif
            output.setPixel(x,y, colOut.rgb());

        }
    }

    /*
    for (int y = 0; y < prev.height(); y++) {
        for (int x = 1; x < prev.width()-1; x++) {
            if (qAlpha(output.pixel(x,y)) == 0
                    && qAlpha(output.pixel(x-1,y)) > 0
                    && qAlpha(output.pixel(x+1,y)) > 0) {
                output.setPixel(x,y, qRgba(
                                    (qRed(output.pixel(x-1,y)) + qRed(output.pixel(x+1,y)))/2,
                                    (qGreen(output.pixel(x-1,y)) + qGreen(output.pixel(x+1,y)))/2,
                                    (qBlue(output.pixel(x-1,y)) + qBlue(output.pixel(x+1,y)))/2,
                                    (qAlpha(output.pixel(x-1,y)) + qAlpha(output.pixel(x+1,y)))/2
                                    ));
            }
        }
    }
    for (int x = 0; x < prev.width(); x++) {
        for (int y = 1; y < prev.height()-1; y++) {
            if (qAlpha(output.pixel(x,y)) == 0
                    && qAlpha(output.pixel(x,y-1)) > 0
                    && qAlpha(output.pixel(x,y+1)) > 0) {
                output.setPixel(x,y, qRgba(
                                    (qRed(output.pixel(x,y-1)) + qRed(output.pixel(x,y+1)))/2,
                                    (qGreen(output.pixel(x,y-1)) + qGreen(output.pixel(x,y+1)))/2,
                                    (qBlue(output.pixel(x,y-1)) + qBlue(output.pixel(x,y+1)))/2,
                                    (qAlpha(output.pixel(x,y-1)) + qAlpha(output.pixel(x,y+1)))/2
                                    ));
            }
        }
    }
    */
}
void DcelManager::on_wireframeColorDcelButton_clicked() {
    QColor color = QColorDialog::getColor(Qt::white, this);

    drawableDcel->setWireframeColor(color.redF(), color.greenF(), color.blueF());
    mainWindow->updateGlCanvas();
}
Example #6
0
//tools
void SliceEditView::SelectPenColor()
{
	QColor newColor = QColorDialog::getColor(Qt::white);
     if (newColor.isValid())
         pDrawingContext->SetPenColor(newColor);
}
Example #7
0
void tabosd::setOSDShadowColor(QColor i){
    shadowColor = i;
    ui->value_osd_shadow_color->setText(QString('"').append(i.name(QColor::HexArgb)).append('"'));
}
const QColor& KisColorSelectorSimple::colorAt(int x, int y)
{
    if (x < 0) x = 0;
    if (x > width()) x = width();
    if (y < 0) y = 0;
    if (y > width()) y = height();

    qreal xRel = x/qreal(width());
    qreal yRel = 1.-y/qreal(height());
    qreal relPos;
    if(height()>width())
        relPos = 1.-y/qreal(height());
    else
        relPos = x/qreal(width());

    QColor color;
    color.setHsvF(m_hue, 1.0, 1.0);
    
    switch(m_parameter) {
    case KisColorSelector::SL:
        m_qcolor.setHslF(m_hue, xRel, yRel);
        break;
    case KisColorSelector::SV:
        m_qcolor.setHsvF(m_hue, xRel, yRel);
        break;
    case KisColorSelector::SV2:
        m_qcolor.setHsvF(m_hue, xRel, xRel + (1.0-xRel)*yRel);
        break;
    case KisColorSelector::hsvSH:
        m_qcolor.setHsvF(xRel, yRel, m_value);
        break;
    case KisColorSelector::hslSH:
        m_qcolor.setHslF(xRel, yRel, m_lightness);
        break;
    case KisColorSelector::VH:
        m_qcolor.setHsvF(xRel, m_hsvSaturation, yRel);
        break;
    case KisColorSelector::LH:
        m_qcolor.setHslF(xRel, m_hslSaturation, yRel);
        break;
    case KisColorSelector::H:
        m_qcolor.setHsvF(relPos, 1, 1);
        break;
    case KisColorSelector::hsvS:
        m_qcolor.setHsvF(m_hue, relPos, m_value);
        break;
    case KisColorSelector::hslS:
        m_qcolor.setHslF(m_hue, relPos, m_lightness);
        break;
    case KisColorSelector::V:
        m_qcolor.setHsvF(m_hue, m_hsvSaturation, relPos);
        break;
    case KisColorSelector::L:
        m_qcolor.setHslF(m_hue, m_hslSaturation, relPos);
        break;
    default:
        Q_ASSERT(false);
        m_qcolor = QColor();
        return m_qcolor;
    }

    return m_qcolor;
}
void KisColorSelectorSimple::setColor(const QColor &c)
{
    switch (m_parameter) {
    case KisColorSelector::SL:
        m_lastClickPos.setX(c.hslSaturationF());
        m_lastClickPos.setY(1.-c.lightnessF());
        emit paramChanged(-1, -1, -1, c.hslSaturationF(), c.lightnessF());
        break;
    case KisColorSelector::LH:
        m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
        m_lastClickPos.setY(1.-c.lightnessF());
        emit paramChanged(c.hueF(), -1, -1, -1, c.lightnessF());
        break;
    case KisColorSelector::SV:
        m_lastClickPos.setX(c.saturationF());
        m_lastClickPos.setY(1-c.valueF());
        emit paramChanged(-1, c.saturationF(), c.valueF(), -1, -1);
        break;
    case KisColorSelector::SV2: {
        qreal xRel = c.hsvSaturationF();
        qreal yRel = 0.5;
        
        if(xRel != 1.0)
            yRel = 1.0 - qBound<qreal>(0.0, (c.valueF() - xRel) / (1.0 - xRel), 1.0);
        
        m_lastClickPos.setX(xRel);
        m_lastClickPos.setY(yRel);
        emit paramChanged(-1, -1, -1, xRel, yRel);
        break;
    }
    case KisColorSelector::VH:
        m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
        m_lastClickPos.setY(c.valueF());
        emit paramChanged(c.hueF(), -1, c.valueF(), -1, -1);
        break;
    case KisColorSelector::hsvSH:
        m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
        m_lastClickPos.setY(1-c.saturationF());
        emit paramChanged(c.hueF(), c.saturationF(), -1, -1, -1);
        break;
    case KisColorSelector::hslSH:
        m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
        m_lastClickPos.setY(1-c.hslSaturationF());
        emit paramChanged(c.hueF(), -1, -1, c.hslSaturationF(), -1);
        break;
    case KisColorSelector::L:
        m_lastClickPos.setX(c.lightnessF());
        emit paramChanged(-1, -1, -1, -1, c.lightnessF());
        break;
    case KisColorSelector::V:
        m_lastClickPos.setX(c.valueF());
        emit paramChanged(-1, -1, c.valueF(), -1, -1);
        break;
    case KisColorSelector::hsvS:
        m_lastClickPos.setX(c.saturationF());
        emit paramChanged(-1, c.saturationF(), -1, -1, -1);
        break;
    case KisColorSelector::hslS:
        m_lastClickPos.setX(c.hslSaturationF());
        emit paramChanged(-1, -1, -1, c.hslSaturationF(), -1);
        break;
    case KisColorSelector::H:
        m_lastClickPos.setX(qBound<qreal>(0., c.hueF(), 1.));
        emit paramChanged(c.hueF(), -1, -1, -1, -1);
        break;
    default:
        Q_ASSERT(false);
        break;
    }
    emit update();
}
Example #10
0
   void SettingsDialog::setBrushColor(){
	 QColor color = QColorDialog::getColor(brushPB->palette().color(QPalette::Active,QPalette::Window), this);
     if (color.isValid()) {
	 brushPB->setPalette(QPalette(color)); 
     }
	}
Example #11
0
	  void SettingsDialog::setSheetPenColor(){
	 QColor color = QColorDialog::getColor(sheetPenPB->palette().color(QPalette::Active,QPalette::Window), this);
     if (color.isValid()) {
	 sheetPenPB->setPalette(QPalette(color)); 
     }
	}
Example #12
0
QVariant Util::decorationForVariant(const QVariant &value)
{
  switch (value.type()) {
  case QVariant::Brush:
  {
    const QBrush b = value.value<QBrush>();
    if (b.style() != Qt::NoBrush) {
      QPixmap p(16, 16);
      p.fill(QColor(0, 0, 0, 0));
      QPainter painter(&p);
      painter.setBrush(b);
      painter.drawRect(0, 0, p.width() - 1, p.height() - 1);
      return p;
    }
  }
  case QVariant::Color:
  {
    const QColor c = value.value<QColor>();
    if (c.isValid()) {
      QPixmap p(16, 16);
      QPainter painter(&p);
      painter.setBrush(QBrush(c));
      painter.drawRect(0, 0, p.width() - 1, p.height() - 1);
      return p;
    }
  }
  case QVariant::Cursor:
  {
    const QCursor c = value.value<QCursor>();
    if (!c.pixmap().isNull()) {
      return c.pixmap().scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation);
    }
  }
  case QVariant::Icon:
  {
    return value;
  }
  case QVariant::Pen:
  {
    const QPen pen = value.value<QPen>();
    if (pen.style() != Qt::NoPen) {
      QPixmap p(16, 16);
      p.fill(QColor(0, 0, 0, 0));
      QPainter painter(&p);
      painter.setPen(pen);
      painter.translate(0, 8 - pen.width() / 2);
      painter.drawLine(0, 0, p.width(), 0);
      return p;
    }
  }
  case QVariant::Pixmap:
  {
    const QPixmap p = value.value<QPixmap>();
    if(!p.isNull()) {
      return QVariant::fromValue(p.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation));
    }
  }
  default: break;
  }

  return QVariant();
}
Example #13
0
void SourceCodeView::showSourceCode(const QString &absFileName, const int lineNum)
{
    QString fileText = fileHash.value(absFileName);

    if (fileText.isNull()) { // File not in hash
        m_currentFileName.clear();

        // Assume fileName is relative to directory
        QFile file(absFileName);

        if (!file.exists()) {
            clear();
            appendHtml(tr("<i>File %1 not available</i>").arg(absFileName));
            return;
        }
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            clear();
            appendHtml(tr("<i>File %1 not readable</i>").arg(absFileName));
            return;
        }
        fileText = QString::fromUtf8(file.readAll());
        fileHash.insert(absFileName, fileText);
    }


    if (m_currentFileName != absFileName) {
        setPlainText(fileText);
        m_currentFileName = absFileName;
    }

    QTextCursor cursor = textCursor();
    cursor.setPosition(document()->findBlockByNumber(lineNum - 1).position());
    setTextCursor(cursor);
    centerCursor();
    cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
    cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);

    QTextEdit::ExtraSelection selectedLine;
    selectedLine.cursor = cursor;

    // Define custom color for line selection
    const QColor fg = palette().color(QPalette::Highlight);
    const QColor bg = palette().color(QPalette::Base);
    QColor col;
    const qreal ratio = 0.25;
    col.setRedF(fg.redF() * ratio + bg.redF() * (1 - ratio));
    col.setGreenF(fg.greenF() * ratio + bg.greenF() * (1 - ratio));
    col.setBlueF(fg.blueF() * ratio + bg.blueF() * (1 - ratio));

    selectedLine.format.setBackground(col);
    selectedLine.format.setProperty(QTextFormat::FullWidthSelection, true);
    setExtraSelections(QList<QTextEdit::ExtraSelection>() << selectedLine);
}
Example #14
0
QString LC_List::getStrData(Plug_Entity *ent) {
    if( NULL == ent)
        return QString("%1\n").arg(tr("Empty Entity"));

    QHash<int, QVariant> data;
    QString strData(""),
            strEntity("%1\n"),
            strCommon("  %1: %2\n"),
            strSpecific("    %1: %2\n"),
            strSpecificXY( QString("    %1: %2=%3 %4=%5\n").arg("%1",tr("X"),"%2",tr("Y"),"%3"));
    double numA, numB, numC;
    QPointF ptA, ptB, ptC;

    //common entity data
    ent->getData(&data);
    strData  = strCommon.arg(tr("Layer")).arg(data.value(DPI::LAYER).toString());
    QColor color = data.value(DPI::COLOR).value<QColor>();
    strData.append( strCommon.arg(tr("Color")).arg(color.name()));
    strData.append( strCommon.arg(tr("Line type")).arg(data.value(DPI::LTYPE).toString()));
    strData.append( strCommon.arg(tr("Line thickness")).arg(data.value(DPI::LWIDTH).toString()));
    strData.append( strCommon.arg(tr("ID")).arg(data.value(DPI::EID).toLongLong()));

    //specific entity data
    int et = data.value(DPI::ETYPE).toInt();
    switch (et) {
    case DPI::POINT:
        strData.prepend( strEntity.arg(tr("POINT")));
        strData.append( strSpecificXY.arg(tr("in point")).
                        arg(d->realToStr(data.value(DPI::STARTX).toDouble())).
                        arg(d->realToStr(data.value(DPI::STARTY).toDouble())));
        break;
    case DPI::LINE:
        strData.prepend( strEntity.arg(tr("LINE")));
        ptA.setX( data.value(DPI::STARTX).toDouble());
        ptA.setY( data.value(DPI::STARTY).toDouble());
        ptB.setX( data.value(DPI::ENDX).toDouble());
        ptB.setY( data.value(DPI::ENDY).toDouble());
        strData.append( strSpecificXY.arg(tr("from point")).
                        arg(d->realToStr(ptA.x())).
                        arg(d->realToStr(ptA.y())));
        strData.append( strSpecificXY.arg(tr("to point")).
                        arg(d->realToStr(ptB.x())).
                        arg(d->realToStr(ptB.y())));
        ptC = ptB - ptA;
        numA = sqrt( (ptC.x()*ptC.x())+ (ptC.y()*ptC.y()));
        strData.append( strSpecific.arg(tr("length")).arg( d->realToStr(numA)));
        numB = asin(ptC.y() / numA);
        numC = numB*180/M_PI;
        if (ptC.x() < 0) numC = 180 - numC;
        if (numC < 0) numC = 360 + numC;
        strData.append( strSpecific.arg(tr("Angle in XY plane")).arg(d->realToStr(numC)));
        strData.append( strSpecificXY.arg(tr("Inc.")).
                        arg(d->realToStr(ptC.x())).
                        arg(d->realToStr(ptC.y())));
        break;
    case DPI::ARC:
        strData.prepend( strEntity.arg(tr("ARC")));
        strData.append( strSpecificXY.arg(tr("center point")).
                        arg(d->realToStr(data.value(DPI::STARTX).toDouble())).
                        arg(d->realToStr(data.value(DPI::STARTY).toDouble())));
        numA = data.value(DPI::RADIUS).toDouble();
        numB = data.value(DPI::STARTANGLE).toDouble();
        numC = data.value(DPI::ENDANGLE).toDouble();
        strData.append( strSpecific.arg(tr("radius")).arg(d->realToStr(numA)));
        strData.append( strSpecific.arg(tr("initial angle")).arg(d->realToStr(numB*180/M_PI)));
        strData.append( strSpecific.arg(tr("final angle")).arg(d->realToStr(numC*180/M_PI)));
        if( numB > numC) {
            numB -= 2.0 * M_PI;
        }
        strData.append( strSpecific.arg(tr("length")).arg( d->realToStr((numC-numB)*numA)));
        break;
    case DPI::CIRCLE:
        strData.prepend( strEntity.arg(tr("CIRCLE")));
        strData.append( strSpecificXY.arg(tr("center point")).
                        arg(d->realToStr(data.value(DPI::STARTX).toDouble())).
                        arg(d->realToStr(data.value(DPI::STARTY).toDouble())));
        numA = data.value(DPI::RADIUS).toDouble();
        strData.append( strSpecific.arg(tr("radius")).arg(d->realToStr(numA)));
        strData.append( strSpecific.arg(tr("circumference")).arg(d->realToStr(numA*2*M_PI)));
        strData.append( strSpecific.arg(tr("area")).arg(d->realToStr(numA*numA*M_PI)));
        break;
    case DPI::ELLIPSE://toy aqui
        strData.prepend( strEntity.arg(tr("ELLIPSE")));
        strData.append( strSpecificXY.arg(tr("center point")).
                        arg(d->realToStr(data.value(DPI::STARTX).toDouble())).
                        arg(d->realToStr(data.value(DPI::STARTY).toDouble())));
        strData.append( strSpecificXY.arg(tr("major axis")).
                        arg(d->realToStr(data.value(DPI::ENDX).toDouble())).
                        arg(d->realToStr(data.value(DPI::ENDY).toDouble())));
/*        strData.append( QString(tr("   minor axis: X=%1 Y=%2\n")).arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        strData.append( QString(tr("   start point: X=%1 Y=%2\n")).arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        strData.append( QString(tr("   end point: X=%1 Y=%2\n")).arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        strData.append( QString(tr("   initial angle: %1\n")).arg(numB*180/M_PI) );
        strData.append( QString(tr("   final angle: %1\n")).arg(numC*180/M_PI) );
        strData.append( QString(tr("   radius ratio: %1\n")).arg(numC*180/M_PI) );*/
        break;

    case DPI::CONSTRUCTIONLINE:
        strData.prepend( strEntity.arg(tr("CONSTRUCTIONLINE")));
        break;
    case DPI::OVERLAYBOX:
        strData.prepend( strEntity.arg(tr("OVERLAYBOX")));
        break;
    case DPI::SOLID:
        strData.prepend( strEntity.arg(tr("SOLID")));
        break;
//container entities
    case DPI::MTEXT:
        strData.prepend( strEntity.arg(tr("MTEXT")));
        break;
    case DPI::TEXT:
        strData.prepend( strEntity.arg(tr("TEXT")));
        break;
    case DPI::INSERT:
        strData.prepend( strEntity.arg(tr("INSERT")));
        ptA.setX( data.value(DPI::STARTX).toDouble());
        ptA.setY( data.value(DPI::STARTY).toDouble());
        strData.append( strSpecific.arg(tr("Name")).arg( data.value(DPI::BLKNAME).toString()));
        strData.append( strSpecificXY.arg(tr("Insertion point")).
                        arg(d->realToStr(ptA.x())).
                        arg(d->realToStr(ptA.y())));
        break;
    case DPI::POLYLINE: {
        strData.prepend( strEntity.arg(tr("POLYLINE")));
        strData.append( strSpecific.arg(tr("Closed")).
                        arg( (0 == data.value(DPI::CLOSEPOLY).toInt()) ? tr("No") : tr("Yes")));
                strData.append( strSpecific.arg(tr("Vertices")).arg(""));
        QList<Plug_VertexData> vl;
        ent->getPolylineData(&vl);
        int iVertices = vl.size();
        for (int i = 0; i < iVertices; ++i) {
            strData.append( strSpecificXY.arg(tr("in point")).
                            arg(d->realToStr(vl.at(i).point.x())).
                            arg(d->realToStr(vl.at(i).point.y())));
            if ( 0 != vl.at(i).bulge) {
                strData.append( strSpecific.arg(tr("radius")).arg( d->realToStr(polylineRadius(vl.at(i), vl.at((i+1) % iVertices)))));
            }
        }
        break; }
    case DPI::IMAGE:
        strData.prepend( strEntity.arg(tr("IMAGE")));
        break;
    case DPI::SPLINE:
        strData.prepend( strEntity.arg(tr("SPLINE")));
        break;
    case DPI::HATCH:
        strData.prepend( strEntity.arg(tr("HATCH")));
        break;
    case DPI::DIMLEADER:
        strData.prepend( strEntity.arg(tr("DIMLEADER")));
        break;
    case DPI::DIMALIGNED:
        strData.prepend( strEntity.arg(tr("DIMALIGNED")));
        break;
    case DPI::DIMLINEAR:
        strData.prepend( strEntity.arg(tr("DIMLINEAR")));
        break;
    case DPI::DIMRADIAL:
        strData.prepend( strEntity.arg(tr("DIMRADIAL")));
        break;
    case DPI::DIMDIAMETRIC:
        strData.prepend( strEntity.arg(tr("DIMDIAMETRIC")));
        break;
    case DPI::DIMANGULAR:
        strData.prepend( strEntity.arg(tr("DIMANGULAR")));
        break;
    default:
        strData.prepend( strEntity.arg(tr("UNKNOWN")));
        break;
    }

    return strData;
}
Example #15
0
void SampleTCOView::paintEvent( QPaintEvent * pe )
{
	QPainter painter( this );

	if( !needsUpdate() )
	{
		painter.drawPixmap( 0, 0, m_paintPixmap );
		return;
	}

	setNeedsUpdate( false );

	if (m_paintPixmap.isNull() || m_paintPixmap.size() != size())
	{
		m_paintPixmap = QPixmap(size());
	}

	QPainter p( &m_paintPixmap );

	QLinearGradient lingrad( 0, 0, 0, height() );
	QColor c;
	bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();

	// state: selected, muted, normal
	c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor() 
		: painter.background().color() );

	lingrad.setColorAt( 1, c.darker( 300 ) );
	lingrad.setColorAt( 0, c );

	// paint a black rectangle under the pattern to prevent glitches with transparent backgrounds
	p.fillRect( rect(), QColor( 0, 0, 0 ) );

	if( gradient() )
	{
		p.fillRect( rect(), lingrad );
	}
	else
	{
		p.fillRect( rect(), c );
	}

	p.setPen( !muted ? painter.pen().brush().color() : mutedColor() );

	const int spacing = TCO_BORDER_WIDTH + 1;
	const float ppt = fixedTCOs() ?
			( parentWidget()->width() - 2 * TCO_BORDER_WIDTH )
					/ (float) m_tco->length().getTact() :
								pixelsPerTact();

	float nom = Engine::getSong()->getTimeSigModel().getNumerator();
	float den = Engine::getSong()->getTimeSigModel().getDenominator();
	float ticksPerTact = DefaultTicksPerTact * nom / den;
	
	float offset =  m_tco->startTimeOffset() / ticksPerTact * pixelsPerTact();
	QRect r = QRect( TCO_BORDER_WIDTH + offset, spacing,
			qMax( static_cast<int>( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing );
	m_tco->m_sampleBuffer->visualize( p, r, pe->rect() );

	QFileInfo fileInfo(m_tco->m_sampleBuffer->audioFile());
	QString filename = fileInfo.fileName();
	paintTextLabel(filename, p);

	// disable antialiasing for borders, since its not needed
	p.setRenderHint( QPainter::Antialiasing, false );

	// inner border
	p.setPen( c.lighter( 160 ) );
	p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH, 
		rect().bottom() - TCO_BORDER_WIDTH );

	// outer border
	p.setPen( c.darker( 300 ) );
	p.drawRect( 0, 0, rect().right(), rect().bottom() );

	// draw the 'muted' pixmap only if the pattern was manualy muted
	if( m_tco->isMuted() )
	{
		const int spacing = TCO_BORDER_WIDTH;
		const int size = 14;
		p.drawPixmap( spacing, height() - ( size + spacing ),
			embed::getIconPixmap( "muted", size, size ) );
	}

	// recording sample tracks is not possible at the moment 

	/* if( m_tco->isRecord() )
	{
		p.setFont( pointSize<7>( p.font() ) );

		p.setPen( textShadowColor() );
		p.drawText( 10, p.fontMetrics().height()+1, "Rec" );
		p.setPen( textColor() );
		p.drawText( 9, p.fontMetrics().height(), "Rec" );

		p.setBrush( QBrush( textColor() ) );
		p.drawEllipse( 4, 5, 4, 4 );
	}*/

	p.end();

	painter.drawPixmap( 0, 0, m_paintPixmap );
}
uint QColormap::pixel(const QColor &color) const
{ return color.rgba(); }
Example #17
0
void Widget::SetColor(double cosDifuse,double cosSpecular)
{

    // qDebug() << cosDifuse;
    if (cosDifuse < 0) {cosDifuse = 0;}
    if (cosSpecular < 0) {cosSpecular = 0 ;}

    double red,green,blue;
    red = color_anbient.red()/255.0+
          cosDifuse*color_diffuse.red()/255.0+
  //        pow(cosSpecular*color_specular.red()/255.0,intense);
          cosSpecular*color_specular.red()/255.0;

    color.setRed(max(0,min(red*255,255)));
    green = color_anbient.green()/255.0+
            cosDifuse*color_diffuse.green()/255.0+
           // pow(cosSpecular*color_specular.green()/255.0,intense);
          cosSpecular*color_specular.green()/255.0;

    color.setGreen(max(0,min(green*255,255)));

    blue = color_anbient.blue()/255.0+
            cosDifuse*color_diffuse.blue()/255.0+
  //          pow(cosSpecular*color_specular.blue()/255.0,intense);
          cosSpecular*color_specular.blue()/255.0;

    color.setBlue(max(0,min(blue*255,255)));


}
Example #18
0
void Palette::setColor(const QColor &color)
{
	if (color.isValid())
		color.getHsvF(&_h, &_s, &_v, &_a);
}
Example #19
0
void tabosd::setOSDBorderColor(QColor i){
    borderColor = i;
    ui->value_osd_border_color->setText(QString('"').append(i.name(QColor::HexArgb)).append('"'));
}
Example #20
0
void NodeBackDrop::initialize(const QString& name,bool requestedByLoad,QVBoxLayout *dockContainer)
{
    
    _imp->menu = new QMenu(_imp->graph);
    
    QString tooltip("The node backdrop is useful to group nodes and identify them in the node graph. You can also "
                    "move all the nodes inside the backdrop.");
    _imp->settingsPanel = new DockablePanel(_imp->graph->getGui(), //< pointer to the gui
                                            this, //< pointer to the knob holder (this)
                                            dockContainer, //< pointer to the layout that will contain this settings panel
                                            DockablePanel::FULLY_FEATURED, //< use a fully featured header with editable text
                                            false, //< don't use scroll areas for tabs
                                            name, //< initial name
                                            Qt::convertFromPlainText(tooltip,Qt::WhiteSpaceNormal), //< help tooltip
                                            false, //< no default page
                                            "BackDrop", //< default page name
                                            dockContainer->parentWidget());
    
    
    ///initialize knobs here
    initializeKnobsPublic();
    
    QObject::connect(_imp->settingsPanel,SIGNAL(nameChanged(QString)),this,SLOT(onNameChanged(QString)));
    QObject::connect(_imp->settingsPanel,SIGNAL(colorChanged(QColor)),this,SLOT(onColorChanged(QColor)));
    dockContainer->addWidget(_imp->settingsPanel);
    
    if (!requestedByLoad) {
        _imp->graph->getGui()->putSettingsPanelFirst(_imp->settingsPanel);
        _imp->graph->getGui()->addVisibleDockablePanel(_imp->settingsPanel);
    } else {
        _imp->settingsPanel->setClosed(true);
    }
    
    
    
    setZValue(-10);
    
    _imp->header = new QGraphicsRectItem(this);
    _imp->header->setZValue(-9);
    
    _imp->name = new QGraphicsTextItem(name,this);
    _imp->name->setDefaultTextColor(QColor(0,0,0,255));
    _imp->name->setZValue(-8);
    
    _imp->label = new QGraphicsTextItem("",this);
    _imp->label->setDefaultTextColor(QColor(0,0,0,255));
    _imp->label->setZValue(-7);
    
    
    _imp->resizeHandle = new QGraphicsPolygonItem(this);
    _imp->resizeHandle->setZValue(-7);
    
    
    ///initialize knobs gui now
    _imp->settingsPanel->initializeKnobs();
    
    float r,g,b;
    appPTR->getCurrentSettings()->getDefaultBackDropColor(&r, &g, &b);
    QColor color;
    color.setRgbF(r, g, b);
    _imp->setColorInternal(color);
    
    _imp->setNameInternal(name);


    
}
Example #21
0
void tabosd::setOSDBackColor(QColor i){
    fontColor = i;
    ui->value_osd_back_color->setText(QString('"').append(i.name(QColor::HexArgb)).append('"'));
}
Example #22
0
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, const QColor &col) const
{
    uptr_t wParam = (col.blue() << 16) | (col.green() << 8) | col.red();

    return sci->WndProc(msg, wParam, static_cast<sptr_t>(0));
}
Example #23
0
void GameVariantDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {

	QColor bkgColor;

	// Calculate item's column num in list-view. Add 1 in odd-numbered rows.
	int nItemsPerRow = qMax (m_viewport->width() / option.rect.width(), 1);
	int oddColumn = index.row() % nItemsPerRow;
	oddColumn = oddColumn + ((index.row() / nItemsPerRow) % 2);

	if (option.state & QStyle::State_Selected) {
		bkgColor = option.palette.color(QPalette::Highlight);
	} else if (oddColumn % 2) {
		// The shading alternates along each row in the list view and
		// each odd-numbered row starts with a shaded item, so we have
		// a checkerboard pattern, regardless of whether nItemsPerRow
		// is odd or even (see the above calculation).
		bkgColor = option.palette.color(QPalette::AlternateBase);
	} else {
		bkgColor = option.palette.color(QPalette::Base);
	}
	painter->fillRect(option.rect, bkgColor);

	QRect contentRect = option.rect.adjusted(m_leftMargin, m_separatorPixels, -m_rightMargin, -m_separatorPixels);

	// Show icon

	QPixmap iconPixmap = KIcon(icon(index), KIconLoader::global()).pixmap(m_iconWidth, m_iconHeight);
	painter->drawPixmap(contentRect.left(), (contentRect.height() - iconPixmap.height()) / 2 + contentRect.top(), iconPixmap);
	contentRect.adjust(iconPixmap.width() + m_separatorPixels*2, 0, 0, 0);

// 	// Show configuration icon
// 	if(configurable(index)) {
// 		QPixmap configPixmap = KIcon( QLatin1String( "configure" ), KIconLoader::global()).pixmap(32, 32);
// 		painter->drawPixmap(contentRect.right() - configPixmap.width(), (contentRect.height() - configPixmap.height()) / 2 + contentRect.top(), configPixmap);
// 		contentRect.adjust(0, 0, -(configPixmap.width() + separatorPixels), 0);
// 	}

	// Show Title
	QFont titleFont(painter->font());
	titleFont.setPointSize(titleFont.pointSize() + 2);
	titleFont.setWeight(QFont::Bold);

	QPen previousPen(painter->pen());
	// TODO: don't we have a function for 'color1 similar color2'
	if(previousPen.color() == bkgColor) {
		QPen p(previousPen);
		int color = bkgColor.rgb();
		color = ~color | 0xff000000;
		p.setColor(color);
		painter->setPen(p);
	}

	QFont previousFont(painter->font());
	painter->setFont(titleFont);
	QString titleStr = painter->fontMetrics().elidedText(title(index), Qt::ElideRight, contentRect.width());
	painter->drawText(contentRect, titleStr);
	contentRect.adjust(0, m_separatorPixels + painter->fontMetrics().height(), 0, 0);
	painter->setFont(previousFont);

	// Show Description
	QTextOption wrap(Qt::AlignLeft);
	wrap.setWrapMode(QTextOption::WordWrap);
	QString descrStr = description(index);
	painter->drawText(contentRect, descrStr, wrap);

	painter->setPen(previousPen);
}
Example #24
0
void Widget::optimizeColors(int polyIndex, QImage& predrawn)
{
    /*
    // Find the poly's bounding box
    int minx,miny,maxx,maxy;
    minx = maxx = poly.points[0].x();
    miny = maxy = poly.points[0].y();
    for (QPoint point : poly.points)
    {
        minx = min(minx, point.x());
        maxx = max(maxx, point.x());
        miny = min(miny, point.y());
        maxy = max(maxy, point.y());
    }
    QRect box(minx, miny, maxx-minx, maxy-miny);
    */

    int polysSize = polys.size();
    Poly& poly = polys[polyIndex];
    static QBrush brush(Qt::SolidPattern);
    int processEventsRatelimit = 0;

    // Check if the pic is better, commit and return if it is
    auto validate = [&]()
    {
        QImage newGen = predrawn;
        QPainter painter(&newGen);
        painter.setPen(QPen(Qt::NoPen));
        for (int i=polyIndex; i<polysSize; ++i)
        {
            brush.setColor(polys[i].color);
            painter.setBrush(brush);
            painter.drawPolygon(polys[i].points.data(), polys[i].points.size());
        }
        quint64 newFit = computeFitness(newGen);
        generation++;
        ui->generationLabel->setNum(generation);
        if (newFit < fitness)
        {
            // Update data
            generated = newGen;
            fitness = newFit;

            // Update GUI
            if (processEventsRatelimit==0)
            {
                ui->imgBest->setPixmap(QPixmap::fromImage(generated));
                updateGuiFitness();
            }
            return true;
        }
        else
            return false;
    };

    app->processEvents();
    int targetColor;
    for (targetColor=0; targetColor <= 8; targetColor++)
    {
        do
        {
            if (processEventsRatelimit == GUI_REFRESH_RATE) // processEvents is a massive slowdown
            {
                processEventsRatelimit=0;
                app->processEvents();
            }
            else
                processEventsRatelimit++;
            QColor color = poly.color;
            if (targetColor == 0)
                color = color.lighter(110); // Lighter
            else if (targetColor == 1)
                color = color.darker(110); // Darker
            else if (targetColor == 2)
                color.setRed(min(color.red()+N_COLOR_VAR,255)); // More red
            else if (targetColor == 3)
                color.setBlue(max(color.blue()-N_COLOR_VAR,0)); // Less blue
            else if (targetColor == 4)
                color.setGreen(min(color.green()+N_COLOR_VAR,255)); // More green
            else if (targetColor == 5)
                color.setRed(max(color.red()-N_COLOR_VAR,0)); // Less red
            else if (targetColor == 6)
                color.setBlue(min(color.blue()+N_COLOR_VAR,255)); // More blue
            else if (targetColor == 7)
                color.setGreen(max(color.green()-N_COLOR_VAR,0)); // Less green
            else if (targetColor == 8)
                color.setAlpha(max(color.alpha()-N_COLOR_VAR,0)); // Less alpha
            else if (targetColor == 9 && OPT_INCREASE_ALPHA)
                color.setAlpha(min(color.alpha()+N_COLOR_VAR,255)); // More alpha
            poly.color = color;
        } while (validate());
    }
    app->processEvents();
}
Example #25
0
void Vertex::set_mat_ambient(const QColor& mat_ambient) {
    mat_ambient_[0] = mat_ambient.redF();
    mat_ambient_[1] = mat_ambient.greenF();
    mat_ambient_[2] = mat_ambient.blueF();
    mat_ambient_[3] = mat_ambient.alphaF();
}
bool GTUtilsMSAEditorSequenceArea::checkColor(HI::GUITestOpStatus &os, const QPoint &p, const QString &expectedColor){
    QColor c = getColor(os, p);
    bool result = (expectedColor == c.name());
    GT_CHECK_RESULT(result, QString("wrong color. Expected: %1, actual: %2").arg(expectedColor).arg(c.name()), result);
    return result;
}
Example #27
0
void MainWindow::perfectImage() 
{
	QColor color;
	Mat image;

	int x, y;

	int width, height;

	int stepSizeX = 11;
	int stepSizeY = 12;

	QFileDialog *dialog = new QFileDialog();
	dialog->setNameFilter("PNG Files (*.png)");
	dialog->setOption(QFileDialog::ReadOnly);
	//dialog->setOption(QFileDialog::DontUseNativeDialog);
	dialog->setDirectory(".");
	QStringList fileNames;
	if (dialog->exec()) {
		fileNames = dialog->selectedFiles();
		QString fileName = fileNames.at(0);
		image = imread(fileName.toStdString(), CV_LOAD_IMAGE_COLOR);
		height = image.rows;
		width = image.cols;

			motorControl.commandMotor1(3, 5);  // Go a few steps back
			motorControl.openShutter();
			for (y=0;y!=height;++y) {
				motorControl.commandMotor1(3, -5);  // Go a few steps forth
				for(x=0;x!=width; x++) {
					motorControl.setLedColor(color);
					
					color.setBlue( image.data[((y*image.cols)+x)*3] );
					color.setGreen( image.data[((y*image.cols)+x)*3+1] );
					color.setRed( image.data[((y*image.cols)+x)*3+2] );
					motorControl.setLedColor(color);

					motorControl.commandMotor1(3, -stepSizeX);

				}
				motorControl.setLedColor(QColor(0,0,0));
				motorControl.commandMotor1(3, stepSizeX * width);
				motorControl.commandMotor1(3, 5);  // Go a few steps back

				motorControl.commandMotor2(6, -stepSizeY);
			}
			motorControl.closeShutter();


			// Reset x axis to initial position if the width is uneven
			if( width%2 != 0) {
				motorControl.commandMotor1(6, stepSizeX * width);
			}

			// Reset y axis to initial position
			motorControl.commandMotor2(6, stepSizeY * height);

			motorControl.releaseMotor1();
			motorControl.releaseMotor2();


	}
}
Example #28
0
void IsometricRenderer::drawMapObject(QPainter *painter,
                                      const MapObject *object,
                                      const QColor &color) const
{
    painter->save();

    QPen pen(Qt::black);

    if (object->tile()) {
        const QPixmap &img = object->tile()->image();
        QPointF paintOrigin(-img.width() / 2, -img.height());
        paintOrigin += tileToPixelCoords(object->position()).toPoint();
        painter->drawPixmap(paintOrigin, img);

        const QFontMetrics fm = painter->fontMetrics();
        QString name = fm.elidedText(object->name(), Qt::ElideRight,
                                     img.width() + 2);
        if (!name.isEmpty())
            painter->drawText(QPoint(paintOrigin.x(), paintOrigin.y() - 5 + 1), name);

        pen.setStyle(Qt::SolidLine);
        painter->setPen(pen);
        painter->drawRect(QRectF(paintOrigin, img.size()));
        pen.setStyle(Qt::DotLine);
        pen.setColor(color);
        painter->setPen(pen);
        painter->drawRect(QRectF(paintOrigin, img.size()));

        if (!name.isEmpty())
            painter->drawText(QPoint(paintOrigin.x(), paintOrigin.y() - 5), name);

    } else {
        QColor brushColor = color;
        brushColor.setAlpha(50);
        QBrush brush(brushColor);

        pen.setJoinStyle(Qt::RoundJoin);
        pen.setCapStyle(Qt::RoundCap);
        pen.setWidth(2);

        painter->setPen(pen);
        painter->setRenderHint(QPainter::Antialiasing);

        // TODO: Draw the object name
        // TODO: Do something sensible to make null-sized objects usable

        switch (object->shape()) {
        case MapObject::Ellipse: {
            QPointF topLeft(tileToPixelCoords(object->bounds().topLeft()));
            QPointF bottomLeft(tileToPixelCoords(object->bounds().bottomLeft()));
            QPointF topRight(tileToPixelCoords(object->bounds().topRight()));

            const qreal headerX = bottomLeft.x();
            const qreal headerY = topLeft.y();

            QRectF rect(bottomLeft, topRight);

            const QFontMetrics fm = painter->fontMetrics();
            QString name = fm.elidedText(object->name(), Qt::ElideRight,
                                         rect.width() + 2);

            QPolygonF polygon = tileRectToPolygon(object->bounds());

            float tw = map()->tileWidth();
            float th = map()->tileHeight();
            QPointF transformScale(1, 1);
            if (tw > th)
                transformScale = QPointF(1, th/tw);
            else
                transformScale = QPointF(tw/th, 1);

            QPointF l1 = polygon.at(1) - polygon.at(0);
            QPointF l2 = polygon.at(3) - polygon.at(0);
            QTransform trans;
            trans.scale(transformScale.x(), transformScale.y());
            trans.rotate(45);
            QTransform iTrans = trans.inverted();
            QPointF l1x = iTrans.map(l1);
            QPointF l2x = iTrans.map(l2);
            QSizeF ellipseSize(l1x.manhattanLength(), l2x.manhattanLength());

            painter->save();
            painter->setPen(pen);
            painter->translate(polygon.at(0));
            painter->scale(transformScale.x(), transformScale.y());
            painter->rotate(45);
            painter->drawEllipse(QRectF(QPointF(0, 0), ellipseSize));
            painter->restore();

            painter->setBrush(Qt::NoBrush);
            painter->drawPolygon(polygon);

            if (!name.isEmpty())
                painter->drawText(QPoint(headerX, headerY - 5), name);

            pen.setColor(color);
            painter->setPen(pen);
            painter->setBrush(Qt::NoBrush);
            painter->translate(QPointF(0, -1));
            painter->drawPolygon(polygon);

            painter->setBrush(brush);
            painter->save();
            painter->translate(polygon.at(0));
            painter->scale(transformScale.x(), transformScale.y());
            painter->rotate(45);
            painter->drawEllipse(QRectF(QPointF(0, 0), ellipseSize));
            painter->restore();

            if (!name.isEmpty())
                painter->drawText(QPoint(headerX, headerY - 5), name);
            break;
        }
        case MapObject::Rectangle: {

            QPointF topLeft(tileToPixelCoords(object->bounds().topLeft()));
            QPointF bottomLeft(tileToPixelCoords(object->bounds().bottomLeft()));
            QPointF topRight(tileToPixelCoords(object->bounds().topRight()));

            const qreal headerX = bottomLeft.x();
            const qreal headerY = topLeft.y();

            QRectF rect(bottomLeft, topRight);

            const QFontMetrics fm = painter->fontMetrics();
            QString name = fm.elidedText(object->name(), Qt::ElideRight,
                                         rect.width() + 2);

            QPolygonF polygon = tileRectToPolygon(object->bounds());
            painter->drawPolygon(polygon);
            if (!name.isEmpty())
                painter->drawText(QPoint(headerX, headerY - 5 + 1), name);

            pen.setColor(color);
            painter->setPen(pen);
            painter->setBrush(brush);
            polygon.translate(0, -1);

            painter->drawPolygon(polygon);
            if (!name.isEmpty())
                painter->drawText(QPoint(headerX, headerY - 5), name);
            break;
        }
        case MapObject::Polygon: {
            const QPointF &pos = object->position();
            const QPolygonF polygon = object->polygon().translated(pos);
            QPolygonF screenPolygon = tileToPixelCoords(polygon);

            const QRectF polygonBoundingRect = screenPolygon.boundingRect();

            const QFontMetrics fm = painter->fontMetrics();
            QString name = fm.elidedText(object->name(), Qt::ElideRight,
                                         polygonBoundingRect.width() + 2);

            if (!name.isEmpty())
                painter->drawText(QPoint(polygonBoundingRect.left(), polygonBoundingRect.top() - 5 + 1), name);

            painter->drawPolygon(screenPolygon);

            pen.setColor(color);
            painter->setPen(pen);
            painter->setBrush(brush);
            screenPolygon.translate(0, -1);

            painter->drawPolygon(screenPolygon);

            if (!name.isEmpty())
                painter->drawText(QPoint(polygonBoundingRect.left(), polygonBoundingRect.top() - 5), name);

            break;
        }
        case MapObject::Polyline: {
            const QPointF &pos = object->position();
            const QPolygonF polygon = object->polygon().translated(pos);
            QPolygonF screenPolygon = tileToPixelCoords(polygon);

            painter->drawPolyline(screenPolygon);

            pen.setColor(color);
            painter->setPen(pen);
            screenPolygon.translate(0, -1);

            painter->drawPolyline(screenPolygon);
            break;
        }
        }
    }

    painter->restore();
}
Example #29
0
void MainWindow::colorStripes()
{
	QColor color;
	int x, y;

	int number = 0;
	bool onOff = false;

	int width = 100;
	int height = 100;

	int stepSize = 16;


	std::default_random_engine generator;
	std::normal_distribution<double> onDistribution(30.0,10.0);
	std::normal_distribution<double> offDistribution(40.0,20.0);
	QVector<QColor*> *colorVector;
	colorVector = computeGoldenRatioColors(0.01,0.7,1,100);

	motorControl.openShutter();
	for (y=0;y!=height;++y) {
		for(x=0;x!=width; x++) {
			motorControl.setLedColor(color);
			if (number<=0) {
				if(onOff) {
					color.setRed(0);
					color.setGreen(0);
					color.setBlue(0);
					motorControl.setLedColor(color);
					onOff = false;
					number = int(offDistribution(generator));
				} else {
					QColor *pColor = colorVector->at(rand() % 100);
					color.setRed(pColor->red());
					color.setGreen(pColor->green());
					color.setBlue(pColor->blue());

					motorControl.setLedColor(color);
					onOff = true;
					number = int(onDistribution(generator));
				}
			}

			motorControl.commandMotor1(3, -stepSize);


			number--;

		}
		motorControl.setLedColor(QColor(0,0,0));
		motorControl.commandMotor1(3, stepSize * width);		

		motorControl.commandMotor2(6, -stepSize);
	}
	motorControl.closeShutter();


	// Reset x axis to initial position if the width is uneven
	if( width%2 != 0) {
		motorControl.commandMotor1(6, stepSize * width);
	}

	// Reset y axis to initial position
	motorControl.commandMotor2(6, stepSize * height);

	motorControl.releaseMotor1();
	motorControl.releaseMotor2();
}
void KonqComboItemDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option,
                                   const QModelIndex &index ) const
{
    QIcon icon = qvariant_cast<QIcon>( index.data( Qt::DecorationRole ) );
    QString url = index.data( Qt::DisplayRole ).toString();
    QString title = index.data( Qt::UserRole ).toString();

    QIcon::Mode mode = option.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;
    const QSize size = icon.actualSize( option.decorationSize, mode );
    QPixmap pixmap = icon.pixmap( size, mode );

    QStyleOptionViewItemV3 opt( option );

    painter->save();

    // Draw the item background

    // ### When Qt 4.4 is released we need to change this code to draw the background
    //     by calling QStyle::drawPrimitive() with PE_PanelItemViewRow.
    if ( opt.state & QStyle::State_Selected ) {
        painter->fillRect( option.rect, option.palette.brush( QPalette::Highlight ) );
        painter->setPen( QPen( option.palette.brush( QPalette::HighlightedText ), 0 ) );
    }

    int hMargin = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameHMargin );
    int vMargin = QApplication::style()->pixelMetric( QStyle::PM_FocusFrameVMargin );

    const QRect bounding = option.rect.adjusted( hMargin, vMargin, -hMargin, -vMargin );
    const QSize textSize( bounding.width() - pixmap.width() - 2, bounding.height() );
    const QRect pixmapRect = QStyle::alignedRect( option.direction, Qt::AlignLeft | Qt::AlignVCenter,
                                                  pixmap.size(), bounding );
    const QRect textRect = QStyle::alignedRect( option.direction, Qt::AlignRight, textSize, bounding );

    if ( !pixmap.isNull() )
        painter->drawPixmap( pixmapRect.topLeft(), pixmap );

    QSize titleSize( ( bounding.width() / 3 ) - 1, textRect.height() );
    if (title.isEmpty()) {
        // Don't truncate the urls when there is no title to show (e.g. local files)
        // Ideally we would do this globally for all items - reserve space for a title for all, or for none
        titleSize = QSize();
    }
    const QSize urlSize( textRect.width() - titleSize.width() - 2, textRect.height() );
    const QRect titleRect = QStyle::alignedRect( option.direction, Qt::AlignRight, titleSize, textRect );
    const QRect urlRect   = QStyle::alignedRect( option.direction, Qt::AlignLeft, urlSize, textRect );

    if ( !url.isEmpty() ) {
        QString squeezedText = option.fontMetrics.elidedText( url, Qt::ElideMiddle, urlRect.width() );
        painter->drawText( urlRect, Qt::AlignLeft | Qt::AlignVCenter, squeezedText );
    }

    if ( !title.isEmpty() ) {
        QString squeezedText = option.fontMetrics.elidedText( title, Qt::ElideRight, titleRect.width() );
        QFont font = painter->font();
        font.setItalic( true );
        painter->setFont( font );
        QColor color = painter->pen().color();
        color.setAlphaF(.75);
        painter->setPen(color);
        painter->drawText( titleRect, Qt::AlignLeft | Qt::AlignVCenter, squeezedText );
    }

    painter->restore();
}