Пример #1
1
void QgsProjectFileTransform::convertRasterProperties( QDomDocument& doc, QDomNode& parentNode,
    QDomElement& rasterPropertiesElem, QgsRasterLayer* rlayer )
{
  //no data
  //TODO: We would need to set no data on all bands, but we don't know number of bands here
  QDomNode noDataNode = rasterPropertiesElem.namedItem( "mNoDataValue" );
  QDomElement noDataElement = noDataNode.toElement();
  if ( !noDataElement.text().isEmpty() )
  {
    QgsDebugMsg( "mNoDataValue = " + noDataElement.text() );
    QDomElement noDataElem = doc.createElement( "noData" );

    QDomElement noDataRangeList = doc.createElement( "noDataRangeList" );
    noDataRangeList.setAttribute( "bandNo", 1 );

    QDomElement noDataRange =  doc.createElement( "noDataRange" );
    noDataRange.setAttribute( "min", noDataElement.text() );
    noDataRange.setAttribute( "max", noDataElement.text() );
    noDataRangeList.appendChild( noDataRange );

    noDataElem.appendChild( noDataRangeList );

    parentNode.appendChild( noDataElem );
  }

  QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
  //convert general properties

  //invert color
  rasterRendererElem.setAttribute( "invertColor", "0" );
  QDomElement  invertColorElem = rasterPropertiesElem.firstChildElement( "mInvertColor" );
  if ( !invertColorElem.isNull() )
  {
    if ( invertColorElem.text() == "true" )
    {
      rasterRendererElem.setAttribute( "invertColor", "1" );
    }
  }

  //opacity
  rasterRendererElem.setAttribute( "opacity", "1" );
  QDomElement transparencyElem = parentNode.firstChildElement( "transparencyLevelInt" );
  if ( !transparencyElem.isNull() )
  {
    double transparency = transparencyElem.text().toInt();
    rasterRendererElem.setAttribute( "opacity", QString::number( transparency / 255.0 ) );
  }

  //alphaBand was not saved until now (bug)
  rasterRendererElem.setAttribute( "alphaBand", -1 );

  //gray band is used for several renderers
  int grayBand = rasterBandNumber( rasterPropertiesElem, "mGrayBandName", rlayer );

  //convert renderer specific properties
  QString drawingStyle = rasterPropertiesElem.firstChildElement( "mDrawingStyle" ).text();

  // While PalettedColor should normaly contain only integer values, usually
  // color palette 0-255, it may happen (Tim, issue #7023) that it contains
  // colormap classification with double values and text labels
  // (which should normaly only appear in SingleBandPseudoColor drawingStyle)
  // => we have to check first the values and change drawingStyle if necessary
  if ( drawingStyle == "PalettedColor" )
  {
    QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
    QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( "colorRampEntry" );

    for ( int i = 0; i < colorRampEntryList.size(); ++i )
    {
      QDomElement colorRampEntryElem = colorRampEntryList.at( i ).toElement();
      QString strValue = colorRampEntryElem.attribute( "value" );
      double value = strValue.toDouble();
      if ( value < 0 || value > 10000 || value != ( int )value )
      {
        QgsDebugMsg( QString( "forcing SingleBandPseudoColor value = %1" ).arg( value ) );
        drawingStyle = "SingleBandPseudoColor";
        break;
      }
    }
  }

  if ( drawingStyle == "SingleBandGray" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandgray" );
    rasterRendererElem.setAttribute( "grayBand", grayBand );
    transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
  }
  else if ( drawingStyle == "SingleBandPseudoColor" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandpseudocolor" );
    rasterRendererElem.setAttribute( "band", grayBand );
    QDomElement newRasterShaderElem = doc.createElement( "rastershader" );
    QDomElement newColorRampShaderElem = doc.createElement( "colorrampshader" );
    newRasterShaderElem.appendChild( newColorRampShaderElem );
    rasterRendererElem.appendChild( newRasterShaderElem );

    //switch depending on mColorShadingAlgorithm
    QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( "mColorShadingAlgorithm" ).text();
    if ( colorShadingAlgorithm == "PseudoColorShader" || colorShadingAlgorithm == "FreakOutShader" )
    {
      newColorRampShaderElem.setAttribute( "colorRampType", "INTERPOLATED" );

      //get minmax from rasterlayer
      QgsRasterBandStats rasterBandStats = rlayer->dataProvider()->bandStatistics( grayBand );
      double minValue = rasterBandStats.minimumValue;
      double maxValue = rasterBandStats.maximumValue;
      double breakSize = ( maxValue - minValue ) / 3;

      QStringList colorList;
      if ( colorShadingAlgorithm == "FreakOutShader" )
      {
        colorList << "#ff00ff" << "#00ffff" << "#ff0000" << "#00ff00";
      }
      else //pseudocolor
      {
        colorList << "#0000ff" << "#00ffff" << "#ffff00" << "#ff0000";
      }
      QStringList::const_iterator colorIt = colorList.constBegin();
      double boundValue = minValue;
      for ( ; colorIt != colorList.constEnd(); ++colorIt )
      {
        QDomElement newItemElem = doc.createElement( "item" );
        newItemElem.setAttribute( "value", QString::number( boundValue ) );
        newItemElem.setAttribute( "label", QString::number( boundValue ) );
        newItemElem.setAttribute( "color", *colorIt );
        newColorRampShaderElem.appendChild( newItemElem );
        boundValue += breakSize;
      }
    }
    else if ( colorShadingAlgorithm == "ColorRampShader" )
    {
      QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
      QString type = customColorRampElem.firstChildElement( "colorRampType" ).text();
      newColorRampShaderElem.setAttribute( "colorRampType", type );
      QDomNodeList colorNodeList = customColorRampElem.elementsByTagName( "colorRampEntry" );

      QString value, label;
      QColor newColor;
      int red, green, blue;
      QDomElement currentItemElem;
      for ( int i = 0; i < colorNodeList.size(); ++i )
      {
        currentItemElem = colorNodeList.at( i ).toElement();
        value = currentItemElem.attribute( "value" );
        label = currentItemElem.attribute( "label" );
        red = currentItemElem.attribute( "red" ).toInt();
        green = currentItemElem.attribute( "green" ).toInt();
        blue = currentItemElem.attribute( "blue" ).toInt();
        newColor = QColor( red, green, blue );
        QDomElement newItemElem = doc.createElement( "item" );
        newItemElem.setAttribute( "value", value );
        newItemElem.setAttribute( "label", label );
        newItemElem.setAttribute( "color", newColor.name() );
        newColorRampShaderElem.appendChild( newItemElem );
      }
    }
  }
  else if ( drawingStyle == "PalettedColor" )
  {
    rasterRendererElem.setAttribute( "type", "paletted" );
    rasterRendererElem.setAttribute( "band", grayBand );
    QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
    QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( "colorRampEntry" );
    QDomElement newColorPaletteElem = doc.createElement( "colorPalette" );

    int red = 0;
    int green = 0;
    int blue = 0;
    int value = 0;
    QDomElement colorRampEntryElem;
    for ( int i = 0; i < colorRampEntryList.size(); ++i )
    {
      colorRampEntryElem = colorRampEntryList.at( i ).toElement();
      QDomElement newPaletteElem = doc.createElement( "paletteEntry" );
      value = ( int )( colorRampEntryElem.attribute( "value" ).toDouble() );
      newPaletteElem.setAttribute( "value", value );
      red = colorRampEntryElem.attribute( "red" ).toInt();
      green = colorRampEntryElem.attribute( "green" ).toInt();
      blue = colorRampEntryElem.attribute( "blue" ).toInt();
      newPaletteElem.setAttribute( "color", QColor( red, green, blue ).name() );
      QString label = colorRampEntryElem.attribute( "label" );
      if ( !label.isEmpty() )
      {
        newPaletteElem.setAttribute( "label", label );
      }
      newColorPaletteElem.appendChild( newPaletteElem );
    }
    rasterRendererElem.appendChild( newColorPaletteElem );
  }
  else if ( drawingStyle == "MultiBandColor" )
  {
    rasterRendererElem.setAttribute( "type", "multibandcolor" );

    //red band, green band, blue band
    int redBand = rasterBandNumber( rasterPropertiesElem, "mRedBandName", rlayer );
    int greenBand = rasterBandNumber( rasterPropertiesElem, "mGreenBandName", rlayer );
    int blueBand = rasterBandNumber( rasterPropertiesElem, "mBlueBandName", rlayer );
    rasterRendererElem.setAttribute( "redBand", redBand );
    rasterRendererElem.setAttribute( "greenBand", greenBand );
    rasterRendererElem.setAttribute( "blueBand", blueBand );

    transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
  }
  else
  {
    return;
  }

  //replace rasterproperties element with rasterrenderer element
  if ( !parentNode.isNull() )
  {
    parentNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
  }
}
Пример #2
0
void QgsLabelPropertyDialog::on_mBufferColorButton_colorChanged( const QColor &color )
{
  insertChangedValue( QgsPalLayerSettings::BufferColor, color.name() );
}
Пример #3
0
static QString colorToString(const QColor &color)
{
    if (color.alpha() != 255)
        return color.name(QColor::HexArgb);
    return color.name();
}
static inline QColor normalizeColor(const QColor &color)
{
    QColor newColor = QColor(color.name());
    newColor.setAlpha(color.alpha());
    return newColor;
}
Пример #5
0
bool QLCCapability::saveXML(QXmlStreamWriter *doc)
{
    Q_ASSERT(doc != NULL);

    /* QLCCapability entry */
    doc->writeStartElement(KXMLQLCCapability);

    /* Min limit attribute */
    doc->writeAttribute(KXMLQLCCapabilityMin, QString::number(m_min));

    /* Max limit attribute */
    doc->writeAttribute(KXMLQLCCapabilityMax, QString::number(m_max));

    /* Preset attribute if not custom */
    if (m_preset != Custom)
        doc->writeAttribute(KXMLQLCCapabilityPreset, presetToString(m_preset));

    /* Resource attributes */
    for (int i = 0; i < m_resources.count(); i++)
    {
        switch (presetType())
        {
            case Picture:
            {
                QString modFilename = resource(i).toString();
                QDir dir = QDir::cleanPath(QLCFile::systemDirectory(GOBODIR).path());

                if (modFilename.contains(dir.path()))
                {
                    modFilename.remove(dir.path());
                    // The following line is a dirty workaround for an issue raised on Windows
                    // When building with MinGW, dir.path() is something like "C:/QLC+/Gobos"
                    // while QDir::separator() returns "\"
                    // So, to avoid any string mismatch I remove the first character
                    // no matter what it is
                    modFilename.remove(0, 1);
                }

                doc->writeAttribute(KXMLQLCCapabilityRes1, modFilename);
            }
            break;
            case SingleColor:
            case DoubleColor:
            {
                QColor col = resource(i).value<QColor>();
                if (i == 0 && col.isValid())
                    doc->writeAttribute(KXMLQLCCapabilityRes1, col.name());
                else if (i == 1 && col.isValid())
                    doc->writeAttribute(KXMLQLCCapabilityRes2, col.name());
            }
            break;
            case SingleValue:
            case DoubleValue:
            {
                if (i == 0)
                    doc->writeAttribute(KXMLQLCCapabilityRes1, QString::number(resource(i).toFloat()));
                else if (i == 1)
                    doc->writeAttribute(KXMLQLCCapabilityRes2, QString::number(resource(i).toFloat()));
            }
            break;
            default:
            break;
        }
    }

    /* Name */
    if (m_aliases.isEmpty())
        doc->writeCharacters(m_name);
    else
        doc->writeCharacters(QString("%1\n   ").arg(m_name)); // to preserve indentation

    /* Aliases */
    foreach (AliasInfo info, m_aliases)
    {
        doc->writeStartElement(KXMLQLCCapabilityAlias);
        doc->writeAttribute(KXMLQLCCapabilityAliasMode, info.targetMode);
        doc->writeAttribute(KXMLQLCCapabilityAliasSourceName, info.sourceChannel);
        doc->writeAttribute(KXMLQLCCapabilityAliasTargetName, info.targetChannel);
        doc->writeEndElement();
    }
Пример #6
0
QPixmap markerPixmap(const QColor& color, const QColor& bgColor) {
	// create unique string-name for color combinations
	QString cacheName(color.name()+bgColor.name());
	QPixmap px(16, 16);

	// The method signature was changed: it's
	// bool QPixmapCache::find ( const QString & key, QPixmap & pm ) in Qt <= 4.5
	// and
	// bool QPixmapCache::find ( const QString & key, QPixmap * pm ) in Qt >= 4.6
#if QT_VERSION >= 0x040600
	if ( QPixmapCache::find(cacheName, &px) ) {
#else
	if ( QPixmapCache::find(cacheName, px) ) {
#endif
		return px;
	}

	px.fill(bgColor);

	QPainter p(&px);
	// As we are using pixmap cache for most pixmap access
	// we can use more resource and time consuming rendering
	// to get better results (smooth rounded bullet in this case).
	// Remember: painting is performed only once per running juffed
	//           in the ideal case.
	p.setRenderHint(QPainter::Antialiasing);

	int red   = color.red();
	int green = color.green();
	int blue  = color.blue();

	QColor light(red + (255 - red) / 2, green + (255 - green) / 2, blue + (255 - blue) / 2);
	QColor dark(red / 2, green / 2, blue / 2);

	QRadialGradient gr(0.4, 0.4, 0.5, 0.4, 0.4);
	gr.setCoordinateMode(QGradient::ObjectBoundingMode);
	gr.setColorAt(0, light);
	gr.setColorAt(1, dark);
	p.setPen(dark);
	p.setBrush(gr);
	p.drawEllipse(1, 1, 14, 14);

	p.end();

	QPixmapCache::insert(cacheName, px);
	return px;
}

class SciDoc::Interior {
public:
	Interior(QWidget* w) {
//		LOGGER;

		curEdit_ = NULL;

		spl_ = new QSplitter(Qt::Vertical);
		QVBoxLayout* vBox = new QVBoxLayout();
		vBox->setContentsMargins(0, 0, 0, 0);
		vBox->addWidget(spl_);
		w->setLayout(vBox);

		edit1_ = createEdit();
		edit2_ = createEdit();
		spl_->addWidget(edit1_);
		spl_->addWidget(edit2_);
		edit1_->setDocument(edit2_->document());
		w->setFocusProxy(spl_);
		spl_->setSizes(QList<int>() << 0 << spl_->height());
		
		hlTimer_ = new QTimer( w );
		hlTimer_->setSingleShot( true );
		connect(hlTimer_, SIGNAL(timeout()), w, SLOT(highlightWord()));
	}

	JuffScintilla* createEdit() {
//		LOGGER;
		JuffScintilla* edit = new JuffScintilla();
		edit->setFocusPolicy(Qt::ClickFocus);
		edit->setUtf8(true);
		edit->setFolding(QsciScintilla::BoxedTreeFoldStyle);
		edit->setAutoIndent(true);
		edit->setBraceMatching(QsciScintilla::SloppyBraceMatch);

		// margins
		edit->setMarginLineNumbers(0, false);
		edit->setMarginLineNumbers(1, true);
		edit->setMarginSensitivity(0, true);
		edit->setMarginWidth(0, 20);
		edit->setMarginWidth(2, 12);

		// markers
		edit->markerDefine(QsciScintilla::Background, 2);
		//	Set the 0th margin accept markers numbered 1 and 2
		//	Binary mask for markers 1 and 2 is 00000110 ( == 6 )
		edit->setMarginMarkerMask(0, 6);
		edit->setMarginMarkerMask(1, 0);

		return edit;
	}

	void setCurrentEdit(JuffScintilla* edit) {
//		LOGGER;

		curEdit_ = edit;
		spl_->setFocusProxy(edit);
	}

	JuffScintilla* edit1_;
	JuffScintilla* edit2_;
	JuffScintilla* curEdit_;
	QString syntax_;
	QSplitter* spl_;
	QTimer* hlTimer_;
};

SciDoc::SciDoc(const QString& fileName) : Juff::Document(fileName) {
//	LOGGER;

	int_ = new Interior(this);

	JuffScintilla* edits[] = { int_->edit1_, int_->edit2_ };
	for ( int i = 0; i < 2; ++i) {
		JuffScintilla* edit = edits[i];
		connect(edit, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(onCursorMoved(int, int)));
	//	connect(int_->edit1_, SIGNAL(contextMenuCalled(int, int)), this, SIGNAL(contextMenuCalled(int, int)));
		connect(edit, SIGNAL(marginClicked(int, int, Qt::KeyboardModifiers)), SLOT(onMarginClicked(int, int, Qt::KeyboardModifiers)));
		connect(edit, SIGNAL(focusReceived()), SLOT(onEditFocused()));
		connect(edit, SIGNAL(markersMenuRequested(const QPoint&)), SIGNAL(markersMenuRequested(const QPoint&)));
		connect(edit, SIGNAL(escapePressed()), SIGNAL(escapePressed()));
	}
	connect(int_->edit1_, SIGNAL(modificationChanged(bool)), this, SIGNAL(modified(bool)));
	connect(int_->edit1_, SIGNAL(linesChanged()), SLOT(onLineCountChanged()));
	connect(int_->edit1_, SIGNAL(textChanged()), this, SIGNAL(textChanged()));

	QString lexName = "none";
	SciDoc::Eol eol = guessEol(fileName);
	std::pair<bool,int> indentation = guessIndentation(fileName);
	if ( !fileName.isEmpty() && !isNoname() ) {
		QString codecName = Document::guessCharset(fileName);
		if ( !codecName.isEmpty() )
			setCharset(codecName);
		readFile();
		setEol(eol);
		setIndentationsUseTabs(indentation.first);
		setTabWidth(indentation.second);
		int_->edit1_->setModified(false);

		//	syntax highlighting
		lexName = LexerStorage::instance()->lexerName(fileName);
	}
	else {
		setEol(eol);
		setIndentationsUseTabs(indentation.first);
		setTabWidth(indentation.second);
	}
	
	
	
	
	setLexer(lexName);

	applySettings();

	QAction* hlWordAct = new QAction("", this);
	hlWordAct->setShortcut(QKeySequence("Ctrl+H"));
	connect(hlWordAct, SIGNAL(triggered()), SLOT(highlightWord()));
	addAction(hlWordAct);
}

/*SciDoc::SciDoc(Juff::Document* doc) : Juff::Document(doc) {
	SciDoc* d = qobject_cast<SciDoc*>(doc);
	if ( d != 0 ) {
		int_->edit1_->setDocument(d->int_->edit1_->document());
		int_->edit2_->setDocument(d->int_->edit2_->document());
	}
}*/

SciDoc::~SciDoc() {
	delete int_;
}

QString SciDoc::type() const {
	return "QSci";
}

bool SciDoc::supportsAction(Juff::ActionID id) const {
	switch (id) {
		case Juff::FileClone : return true;
		default :              return Juff::Document::supportsAction(id);
	}
}

/*Juff::Document* SciDoc::createClone() {
	if ( hasClone() )
		return NULL;
	else
		return new SciDoc(this);
}

void SciDoc::updateClone() {
	LOGGER;

//	SciDoc* cln = qobject_cast<SciDoc*>(clone());
//	if ( cln != 0 ) {
//		if ( cln->int_->syntax_ != int_->syntax_ ) {
//			cln->int_->syntax_ = int_->syntax_;
//			QsciLexer* lexer = LexerStorage::instance()->lexer(int_->syntax_);
//			cln->int_->edit1_->setLexer(lexer);
//			cln->int_->edit2_->setLexer(lexer);
//		}
//	}

	Juff::Document::updateClone();
}*/

void SciDoc::init() {
	int_->setCurrentEdit(int_->edit2_);
}
Пример #7
0
QString LC_List::getStrData(Plug_Entity *ent) {
    QHash<int, QVariant> data;
    QString str;
    double numA, numB, numC;
    QPointF ptA, ptB, ptC;
    //common entity data
    if (ent == 0)
        return QString("Empty Entity\n\n");
    ent->getData(&data);
    str = "Layer: " + data.value(DPI::LAYER).toString();
    QColor color = data.value(DPI::COLOR).value<QColor>();
    str.append("\n Color: " + color.name());
    str.append(" Line type: " + data.value(DPI::LTYPE).toString());
    str.append( "\n Line thickness: " + data.value(DPI::LWIDTH).toString());
    str.append( QString("\n ID: %1\n").arg(data.value(DPI::EID).toLongLong()));
    int et = data.value(DPI::ETYPE).toInt();

    //specific entity data
    switch (et) {
    case DPI::POINT:
        str.append( QString("     in point: X=%1 Y=%2\n\n").arg(
                d->realToStr(data.value(DPI::STARTX).toDouble()) ).arg(
                d->realToStr(data.value(DPI::STARTY).toDouble()) ) );
        return QString("POINT: ").append(str);
        break;
    case DPI::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() );
        str.append( QString("     from point: X=%1 Y=%2\n     to point: X=%3 Y=%4\n").arg(
                    d->realToStr(ptA.x()) ).arg( d->realToStr(ptA.y()) ).arg(
                    d->realToStr(ptB.x()) ).arg( d->realToStr(ptB.y()) ) );
        ptC = ptB - ptA;
        numA = sqrt( (ptC.x()*ptC.x())+ (ptC.y()*ptC.y()));
        str.append( QString("   length: %1,").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;
        str.append( QString("  Angle in XY plane: %1\n").arg(d->realToStr(numC)) );
        str.append( QString("  Inc. X = %1,  Inc. Y = %2\n\n").arg(
                            d->realToStr(ptC.x()) ).arg( d->realToStr(ptC.y()) ));
         return QString("LINE: ").append(str);
       break;
    case DPI::ARC:
        str.append( QString("   certer point: X=%1 Y=%2\n").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();
        str.append( QString("   radius: %1\n").arg(d->realToStr(numA)) );
        str.append( QString("   initial angle: %1\n").arg(d->realToStr(numB*180/M_PI)) );
        str.append( QString("   final angle: %1\n").arg(d->realToStr(numC*180/M_PI)) );
        str.append( QString("   length: %1\n").arg( d->realToStr((numC-numB)*numA) ) );
        return QString("ARC: ").append(str);
        break;
    case DPI::CIRCLE:
        str.append( QString("   certer point: X=%1 Y=%2\n").arg(
                d->realToStr(data.value(DPI::STARTX).toDouble()) ).arg(
                d->realToStr(data.value(DPI::STARTY).toDouble()) ) );
        numA = data.value(DPI::RADIUS).toDouble();
        str.append( QString("   radius: %1\n").arg(d->realToStr(numA)) );
        str.append( QString("   circumference: %1\n").arg(
                d->realToStr(numA*2*M_PI) ) );
        str.append( QString("   area: %1\n\n").arg(
                d->realToStr(numA*numA*M_PI) ) );
        return QString("CIRCLE: ").append(str);
        break;
    case DPI::ELLIPSE://toy aqui
        str.append( QString("   certer point: X=%1 Y=%2\n").arg(
                d->realToStr(data.value(DPI::STARTX).toDouble()) ).arg(
                d->realToStr(data.value(DPI::STARTY).toDouble()) ) );
        str.append( QString("   major axis: X=%1 Y=%2\n").arg(
                d->realToStr(data.value(DPI::ENDX).toDouble()) ).arg(
                d->realToStr(data.value(DPI::ENDY).toDouble()) ) );
/*        str.append( QString("   minor axis: X=%1 Y=%2\n").arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        str.append( QString("   start point: X=%1 Y=%2\n").arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        str.append( QString("   end point: X=%1 Y=%2\n").arg(
                data.value(DPI::ENDX).toDouble()).arg(
                data.value(DPI::ENDY).toDouble() ) );
        str.append( QString("   initial angle: %1\n").arg(numB*180/M_PI) );
        str.append( QString("   final angle: %1\n").arg(numC*180/M_PI) );
        str.append( QString("   radius ratio: %1\n").arg(numC*180/M_PI) );*/
        return QString("ELLIPSE: ").append(str);
        break;

    case DPI::CONSTRUCTIONLINE:
        return QString("CONSTRUCTIONLINE: ").append(str);
        break;
    case DPI::OVERLAYBOX:
        return QString("OVERLAYBOX: ").append(str);
        break;
    case DPI::SOLID:
        return QString("SOLID: ").append(str);
        break;
//container entities
    case DPI::MTEXT:
        return QString("MTEXT: ").append(str);
        break;
    case DPI::TEXT:
        return QString("TEXT: ").append(str);
        break;
    case DPI::INSERT:
        ptA.setX( data.value(DPI::STARTX).toDouble() );
        ptA.setY( data.value(DPI::STARTY).toDouble() );
        str.append( QString("   Name: %1\n").arg( data.value(DPI::BLKNAME).toString()) );
        str.append( QString("   Insertion point: X=%1 Y=%2\n").arg(
                d->realToStr(ptA.x()) ).arg( d->realToStr(ptA.y()) ) );
        return QString("INSERT: ").append(str);
        break;
    case DPI::POLYLINE: {
        if (data.value(DPI::CLOSEPOLY).toInt() == 0 )
            str.append( QString("     Opened\n") );
        else
            str.append( QString("     Closed\n") );
        str.append( QString("     Vertex:\n"));
        QList<Plug_VertexData> vl;
        ent->getPolylineData(&vl);
        for (int i = 0; i < vl.size(); ++i) {
            str.append( QString("     in point: X=%1 Y=%2\n").arg(
                           d->realToStr(vl.at(i).point.x()) ).arg( d->realToStr(vl.at(i).point.y()) ) );
            if (vl.at(i).bulge != 0)
            str.append( QString("     curvature: %1\n").arg( d->realToStr(vl.at(i).bulge)) );
        }
        return QString("POLYLINE: ").append(str);
        break; }
    case DPI::IMAGE:
        return QString("IMAGE: ").append(str);
        break;
    case DPI::SPLINE:
        return QString("SPLINE: ").append(str);
        break;
    case DPI::HATCH:
        return QString("HATCH: ").append(str);
        break;
    case DPI::DIMLEADER:
        return QString("DIMLEADER: ").append(str);
        break;
    case DPI::DIMALIGNED:
        return QString("DIMALIGNED: ").append(str);
        break;
    case DPI::DIMLINEAR:
        return QString("DIMLINEAR: ").append(str);
        break;
    case DPI::DIMRADIAL:
        return QString("DIMRADIAL: ").append(str);
        break;
    case DPI::DIMDIAMETRIC:
        return QString("DIMDIAMETRIC: ").append(str);
        break;
    case DPI::DIMANGULAR:
        return QString("DIMANGULAR: ").append(str);
        break;
    default:
        break;
    }
        return QString("UNKNOWN: ").append(str);
}
Пример #8
0
void HtmlEditor::formatBackgroundColor()
{
    QColor color = QColorDialog::getColor(Qt::white, this);
    if (color.isValid())
        execCommand("hiliteColor", color.name());
}
Пример #9
0
SetColorDialog::SetColorDialog(const QString & message, QColor & currentColor, QColor & standardColor, bool askPrefs, QWidget *parent) : QDialog(parent) 
{
	m_prefsCheckBox = NULL;
	m_message = message;
	m_currentColor = m_selectedColor = currentColor;
	m_standardColor = standardColor;

	this->setWindowTitle(tr("Set %1 Color...").arg(message));

	QVBoxLayout * vLayout = new QVBoxLayout(this);

	QLabel * label = new QLabel(tr("Choose a new %1 color.").arg(message.toLower()));
	vLayout->addWidget(label);

	QFrame * f1 = new QFrame();
	QHBoxLayout * hLayout1 = new QHBoxLayout(f1);
	QPushButton *button1 = new QPushButton("Choose");
	button1->setFixedWidth(BUTTON_WIDTH);
	connect(button1, SIGNAL(clicked()), this, SLOT(selectCurrent()));
	hLayout1->addWidget(button1);
	m_currentColorLabel = new ClickableLabel(tr("current %1 color (%2)").arg(message.toLower()).arg(currentColor.name()), this);
	connect(m_currentColorLabel, SIGNAL(clicked()), this, SLOT(selectCurrent()));
	m_currentColorLabel->setPalette(QPalette(currentColor));
	m_currentColorLabel->setAutoFillBackground(true);
	m_currentColorLabel->setMargin(MARGIN);
	hLayout1->addWidget(m_currentColorLabel);
	vLayout->addWidget(f1);

	QFrame * f2 = new QFrame();
	QHBoxLayout * hLayout2 = new QHBoxLayout(f2);
	QPushButton *button2 = new QPushButton("Choose");
	button2->setFixedWidth(BUTTON_WIDTH);
	connect(button2, SIGNAL(clicked()), this, SLOT(selectStandard()));
	hLayout2->addWidget(button2);
	m_standardColorLabel = new ClickableLabel(tr("standard %1 color (%2)").arg(message.toLower()).arg(standardColor.name()), this);
	connect(m_standardColorLabel, SIGNAL(clicked()), this, SLOT(selectStandard()));
	m_standardColorLabel->setPalette(QPalette(standardColor));
	m_standardColorLabel->setAutoFillBackground(true);
	m_standardColorLabel->setMargin(MARGIN);
	hLayout2->addWidget(m_standardColorLabel);
	vLayout->addWidget(f2);

	QFrame * f3 = new QFrame();
	QHBoxLayout * hLayout3 = new QHBoxLayout(f3);
	QPushButton *button3 = new QPushButton("Custom color ...");
	button3->setFixedWidth(BUTTON_WIDTH);
	connect(button3, SIGNAL(clicked()), this, SLOT(selectCustom()));
	hLayout3->addWidget(button3);
	m_customColorLabel = new ClickableLabel("", this);
	connect(m_customColorLabel, SIGNAL(clicked()), this, SLOT(selectLastCustom()));
	setCustomColor(currentColor);
	m_customColorLabel->setMargin(MARGIN);
	hLayout3->addWidget(m_customColorLabel);
	vLayout->addWidget(f3);

	QSpacerItem * spacerItem = new QSpacerItem( 0, 10 );
	vLayout->addSpacerItem(spacerItem);

	QFrame * f4 = new QFrame();
	QHBoxLayout * hLayout4 = new QHBoxLayout(f4);
	m_selectedColorLabel = new QLabel();
	setColor(currentColor);
	hLayout4->addWidget(m_selectedColorLabel);
	m_selectedColorLabel->setMargin(4);
	vLayout->addWidget(f4);

	if (askPrefs) {
		QFrame * f5 = new QFrame();
		QHBoxLayout * hLayout5 = new QHBoxLayout(f5);
		m_prefsCheckBox = new QCheckBox(tr("Make this the default %1 color").arg(message.toLower()));
		hLayout5->addWidget(m_prefsCheckBox);
		vLayout->addWidget(f5);
	}

    QDialogButtonBox * buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
	buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
	buttonBox->button(QDialogButtonBox::Ok)->setText(tr("OK"));
    connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

	vLayout->addWidget(buttonBox);

	this->setLayout(vLayout);
}
Пример #10
0
void SetColorDialog::setColor(const QColor & color) {
	m_selectedColor = color;
	m_selectedColorLabel->setText(tr("selected color (%1)").arg(color.name()));
	m_selectedColorLabel->setPalette(QPalette(color));
	m_selectedColorLabel->setAutoFillBackground(true);
}
Пример #11
0
void PresentationPropertyHolder::onUpdateContent(QColor content)
{
    setContent(content.name());
}
Пример #12
0
/**
 * Adds a log entry
 */
void LogWidget::log(LogWidget::LogType logType, QString text) {
    // ignore "libpng sRGB profile" and "QXcbConnection: XCB error: 8" warnings
    if (logType == WarningLogType &&
        (text.contains("libpng warning: iCCP: known incorrect sRGB profile") ||
         text.contains("QXcbConnection: XCB error:"))) {
        return;
    }

#ifndef INTEGRATION_TESTS
    // log to the log file
    logToFileIfAllowed(logType, text);

    // return if logging wasn't enabled or if widget is not visible
    if (!qApp->property("loggingEnabled").toBool() || !isVisible()) {
        return;
    }

    QString type = logTypeText(logType);
    QColor color = QColor(Qt::black);

    switch (logType) {
        case DebugLogType:
            if (!ui->debugCheckBox->isChecked()) {
                return;
            }

            // print debug messages to stderr if in release-mode but debug
            // logging is enabled in the log panel
#ifndef QT_DEBUG
            fprintf(stderr, "Debug: %s\n", text.toLocal8Bit().constData());
#endif

            // gray
            color = QColor(98, 98, 98);
            break;
        case InfoLogType:
            if (!ui->infoCheckBox->isChecked()) {
                return;
            }
            color = QColor(Qt::darkBlue);
            break;
        case WarningLogType:
            if (!ui->warningCheckBox->isChecked()) {
                return;
            }

            // this is a "fix" for crashes that occur when a network goes away
            // and this message should be printed, I haven't managed to get
            // around this crash with other methods
            if (text.contains(
                    "/org/freedesktop/NetworkManager/ActiveConnection")) {
                return;
            }

            // orange
            color = QColor(255, 128, 0);
            break;
        case CriticalLogType:
            if (!ui->criticalCheckBox->isChecked()) {
                return;
            }
            // light red
            color = QColor(192, 0, 0);
            break;
        case FatalLogType:
            if (!ui->fatalCheckBox->isChecked()) {
                return;
            }
            // lighter red
            color = QColor(210, 0, 0);
            break;
        case StatusLogType:
            if (!ui->statusCheckBox->isChecked()) {
                return;
            }
            // green
            color = QColor(0, 128, 0);
            break;
        case ScriptingLogType:
            if (!ui->scriptingCheckBox->isChecked()) {
                return;
            }
            // blue
            color = QColor(0, 102, 255);
            break;
    }

    QDateTime dateTime = QDateTime::currentDateTime();
//    text.prepend("[" + dateTime.toString("hh:mm:ss") + "] [" + type + "] ");
//    text.append("\n");

    QString html = QString("<div style=\"color: %1\">[%2] [%3] %4</div>")
            .arg(color.name(), dateTime.toString("hh:mm:ss"), type,
                 text.toHtmlEscaped());

    QScrollBar *scrollBar = ui->logTextEdit->verticalScrollBar();

    // we want to scroll down later if the scrollbar is near the bottom
    bool scrollDown = scrollBar->value() >=
            (scrollBar->maximum() - scrollBar->singleStep());

    // return if logging isn't enabled any more
    if (!qApp->property("loggingEnabled").toBool()) {
        return;
    }

    const QSignalBlocker blocker(ui->logTextEdit);
    Q_UNUSED(blocker);

    // insert the text at the end
    ui->logTextEdit->appendHtml(html.trimmed());

    if (scrollDown) {
        // move the text cursor to the end
        ui->logTextEdit->moveCursor(QTextCursor::End);
//        scrollBar->setValue(scrollBar->maximum());
    }
#else
    Q_UNUSED(logType);
    Q_UNUSED(text);
#endif
}
Пример #13
0
void QgsProjectFileTransform::convertRasterProperties( QDomDocument& doc, QDomNode& parentNode,
    QDomElement& rasterPropertiesElem, QgsRasterLayer* rlayer )
{
  QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
  //convert general properties

  //invert color
  rasterRendererElem.setAttribute( "invertColor", "0" );
  QDomElement  invertColorElem = rasterPropertiesElem.firstChildElement( "mInvertColor" );
  if ( !invertColorElem.isNull() )
  {
    if ( invertColorElem.text() == "true" )
    {
      rasterRendererElem.setAttribute( "invertColor", "1" );
    }
  }

  //opacity
  rasterRendererElem.setAttribute( "opacity", "1" );
  QDomElement transparencyElem = parentNode.firstChildElement( "transparencyLevelInt" );
  if ( !transparencyElem.isNull() )
  {
    double transparency = transparencyElem.text().toInt();
    rasterRendererElem.setAttribute( "opacity", QString::number( transparency / 255.0 ) );
  }

  //alphaBand was not saved until now (bug)
  rasterRendererElem.setAttribute( "alphaBand", -1 );

  //gray band is used for several renderers
  int grayBand = rasterBandNumber( rasterPropertiesElem, "mGrayBandName", rlayer );

  //convert renderer specific properties
  QString drawingStyle = rasterPropertiesElem.firstChildElement( "mDrawingStyle" ).text();
  if ( drawingStyle == "SingleBandGray" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandgray" );
    rasterRendererElem.setAttribute( "grayBand", grayBand );
    transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
  }
  else if ( drawingStyle == "SingleBandPseudoColor" )
  {
    rasterRendererElem.setAttribute( "type", "singlebandpseudocolor" );
    rasterRendererElem.setAttribute( "band", grayBand );
    QDomElement newRasterShaderElem = doc.createElement( "rastershader" );
    QDomElement newColorRampShaderElem = doc.createElement( "colorrampshader" );
    newRasterShaderElem.appendChild( newColorRampShaderElem );
    rasterRendererElem.appendChild( newRasterShaderElem );

    //switch depending on mColorShadingAlgorithm
    QString colorShadingAlgorithm = rasterPropertiesElem.firstChildElement( "mColorShadingAlgorithm" ).text();
    if ( colorShadingAlgorithm == "PseudoColorShader" || colorShadingAlgorithm == "FreakOutShader" )
    {
      newColorRampShaderElem.setAttribute( "colorRampType", "INTERPOLATED" );

      //get minmax from rasterlayer
      QgsRasterBandStats rasterBandStats = rlayer->dataProvider()->bandStatistics( grayBand );
      double minValue = rasterBandStats.minimumValue;
      double maxValue = rasterBandStats.maximumValue;
      double breakSize = ( maxValue - minValue ) / 3;

      QStringList colorList;
      if ( colorShadingAlgorithm == "FreakOutShader" )
      {
        colorList << "#ff00ff" << "#00ffff" << "#ff0000" << "#00ff00";
      }
      else //pseudocolor
      {
        colorList << "#0000ff" << "#00ffff" << "#ffff00" << "#ff0000";
      }
      QStringList::const_iterator colorIt = colorList.constBegin();
      double boundValue = minValue;
      for ( ; colorIt != colorList.constEnd(); ++colorIt )
      {
        QDomElement newItemElem = doc.createElement( "item" );
        newItemElem.setAttribute( "value", QString::number( boundValue ) );
        newItemElem.setAttribute( "label", QString::number( boundValue ) );
        newItemElem.setAttribute( "color", *colorIt );
        newColorRampShaderElem.appendChild( newItemElem );
        boundValue += breakSize;
      }
    }
    else if ( colorShadingAlgorithm == "ColorRampShader" )
    {
      QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
      QString type = customColorRampElem.firstChildElement( "colorRampType" ).text();
      newColorRampShaderElem.setAttribute( "colorRampType", type );
      QDomNodeList colorNodeList = customColorRampElem.elementsByTagName( "colorRampEntry" );

      QString value, label;
      QColor newColor;
      int red, green, blue;
      QDomElement currentItemElem;
      for ( int i = 0; i < colorNodeList.size(); ++i )
      {
        currentItemElem = colorNodeList.at( i ).toElement();
        value = currentItemElem.attribute( "value" );
        label = currentItemElem.attribute( "label" );
        red = currentItemElem.attribute( "red" ).toInt();
        green = currentItemElem.attribute( "green" ).toInt();
        blue = currentItemElem.attribute( "blue" ).toInt();
        newColor = QColor( red, green, blue );
        QDomElement newItemElem = doc.createElement( "item" );
        newItemElem.setAttribute( "value", value );
        newItemElem.setAttribute( "label", label );
        newItemElem.setAttribute( "color", newColor.name() );
        newColorRampShaderElem.appendChild( newItemElem );
      }
    }
  }
  else if ( drawingStyle == "PalettedColor" )
  {
    rasterRendererElem.setAttribute( "type", "paletted" );
    rasterRendererElem.setAttribute( "band", grayBand );
    QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
    QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( "colorRampEntry" );
    QDomElement newColorPaletteElem = doc.createElement( "colorPalette" );

    int red = 0;
    int green = 0;
    int blue = 0;
    int value = 0;
    QDomElement colorRampEntryElem;
    for ( int i = 0; i < colorRampEntryList.size(); ++i )
    {
      colorRampEntryElem = colorRampEntryList.at( i ).toElement();
      QDomElement newPaletteElem = doc.createElement( "paletteEntry" );
      value = ( int )( colorRampEntryElem.attribute( "value" ).toDouble() );
      newPaletteElem.setAttribute( "value", value );
      red = colorRampEntryElem.attribute( "red" ).toInt();
      green = colorRampEntryElem.attribute( "green" ).toInt();
      blue = colorRampEntryElem.attribute( "blue" ).toInt();
      newPaletteElem.setAttribute( "color", QColor( red, green, blue ).name() );
      newColorPaletteElem.appendChild( newPaletteElem );
    }
    rasterRendererElem.appendChild( newColorPaletteElem );
  }
  else if ( drawingStyle == "MultiBandColor" )
  {
    rasterRendererElem.setAttribute( "type", "multibandcolor" );

    //red band, green band, blue band
    int redBand = rasterBandNumber( rasterPropertiesElem, "mRedBandName", rlayer );
    int greenBand = rasterBandNumber( rasterPropertiesElem, "mGreenBandName", rlayer );
    int blueBand = rasterBandNumber( rasterPropertiesElem, "mBlueBandName", rlayer );
    rasterRendererElem.setAttribute( "redBand", redBand );
    rasterRendererElem.setAttribute( "greenBand", greenBand );
    rasterRendererElem.setAttribute( "blueBand", blueBand );

    transformContrastEnhancement( doc, rasterPropertiesElem, rasterRendererElem );
  }
  else
  {
    return;
  }

  //replace rasterproperties element with rasterrenderer element
  if ( !parentNode.isNull() )
  {
    parentNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
  }
}
Пример #14
0
void WBigBmpGraphicsView::updatePixelInfo(int x, int y, QColor color)
{
	QString info = QString(tr("Pixel(%0,%1)-%2")).
				   arg(x).arg(y).arg(color.name());
	pixelInfoLabel->setText(info);
}
Пример #15
0
void ShapePlug::parseGroup(QDomNode &DOC)
{
    QString tmp = "";
    QString FillCol = "White";
    QString StrokeCol = "Black";
    QString defFillCol = "White";
    QString defStrokeCol = "Black";
    QColor stroke = Qt::black;
    QColor fill = Qt::white;
//	Qt::PenStyle Dash = Qt::SolidLine;
    Qt::PenCapStyle LineEnd = Qt::FlatCap;
    Qt::PenJoinStyle LineJoin = Qt::MiterJoin;
//	int fillStyle = 1;
    double strokewidth = 0.1;
//	bool poly = false;
    while(!DOC.isNull())
    {
        double x1, y1, x2, y2;
        StrokeCol = defStrokeCol;
        FillCol = defFillCol;
        stroke = Qt::black;
        fill = Qt::white;
        //	fillStyle = 1;
        strokewidth = 1.0;
        //	Dash = Qt::SolidLine;
        LineEnd = Qt::FlatCap;
        LineJoin = Qt::MiterJoin;
        FPointArray PoLine;
        PoLine.resize(0);
        QDomElement pg = DOC.toElement();
        QString STag = pg.tagName();
        QString style = pg.attribute( "style", "" ).simplified();
        if (style.isEmpty())
            style = pg.attribute( "svg:style", "" ).simplified();
        QStringList substyles = style.split(';', QString::SkipEmptyParts);
        for( QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it )
        {
            QStringList substyle = (*it).split(':', QString::SkipEmptyParts);
            QString command(substyle[0].trimmed());
            QString params(substyle[1].trimmed());
            if (command == "fill")
            {
                if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default") || (params == "inverse")))
                {
                    if (params == "nofill")
                        FillCol = CommonStrings::None;
                    else
                    {
                        fill.setNamedColor( params );
                        FillCol = "FromDia"+fill.name();
                        ScColor tmp;
                        tmp.fromQColor(fill);
                        tmp.setSpotColor(false);
                        tmp.setRegistrationColor(false);
                        QString fNam = m_Doc->PageColors.tryAddColor(FillCol, tmp);
                        if (fNam == FillCol)
                            importedColors.append(FillCol);
                        FillCol = fNam;
                    }
                }
            }
            else if (command == "stroke")
            {
                if (!((params == "foreground") || (params == "background") || (params == "fg") || (params == "bg") || (params == "none") || (params == "default")) || (params == "inverse"))
                {
                    stroke.setNamedColor( params );
                    StrokeCol = "FromDia"+stroke.name();
                    ScColor tmp;
                    tmp.fromQColor(stroke);
                    tmp.setSpotColor(false);
                    tmp.setRegistrationColor(false);
                    QString fNam = m_Doc->PageColors.tryAddColor(StrokeCol, tmp);
                    if (fNam == StrokeCol)
                        importedColors.append(StrokeCol);
                    StrokeCol = fNam;
                }
            }
            else if (command == "stroke-width")
                strokewidth = ScCLocale::toDoubleC(params);
            else if( command == "stroke-linejoin" )
            {
                if( params == "miter" )
                    LineJoin = Qt::MiterJoin;
                else if( params == "round" )
                    LineJoin = Qt::RoundJoin;
                else if( params == "bevel" )
                    LineJoin = Qt::BevelJoin;
            }
            else if( command == "stroke-linecap" )
            {
                if( params == "butt" )
                    LineEnd = Qt::FlatCap;
                else if( params == "round" )
                    LineEnd = Qt::RoundCap;
                else if( params == "square" )
                    LineEnd = Qt::SquareCap;
            }
        }
        if (STag == "svg:line")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x1")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y1")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("x2")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("y2")) * Conversion;
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x1, y1);
            PoLine.addPoint(x2, y2);
            PoLine.addPoint(x2, y2);
            int z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:rect")
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("x")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("y")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("width")) * Conversion;
            y2 = ScCLocale::toDoubleC(pg.attribute("height")) * Conversion;
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->setLineJoin(LineJoin);
            m_Doc->Items->at(z)->setLineEnd(LineEnd);
            finishItem(m_Doc->Items->at(z));
        }
        else if ((STag == "svg:polygon") || (STag == "svg:polyline"))
        {
            bool bFirst = true;
            double x = 0.0;
            double y = 0.0;
            QString points = pg.attribute( "points" ).simplified().replace(',', " ");
            QStringList pointList = points.split(' ', QString::SkipEmptyParts);
            FirstM = true;
            for( QStringList::Iterator it = pointList.begin(); it != pointList.end(); it++ )
            {
                x = ScCLocale::toDoubleC(*(it++));
                y = ScCLocale::toDoubleC(*it);
                if( bFirst )
                {
                    svgMoveTo(x * Conversion, y * Conversion);
                    bFirst = false;
                    WasM = true;
                }
                else
                {
                    svgLineTo(&PoLine, x * Conversion, y * Conversion);
                }
            }
            if (STag == "svg:polygon")
                svgClosePath(&PoLine);
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
            int z;
            if (STag == "svg:polygon")
                z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol);
            else
                z = m_Doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, CommonStrings::None, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if ((STag == "svg:circle") || (STag == "svg:ellipse"))
        {
            x1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            y1 = ScCLocale::toDoubleC(pg.attribute("r")) * Conversion;
            x2 = ScCLocale::toDoubleC(pg.attribute("cx")) * Conversion - x1;
            y2 = ScCLocale::toDoubleC(pg.attribute("cy")) * Conversion - y1;
            x1 *= 2.0;
            y1 *= 2.0;
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Ellipse, baseX + x1, baseY + y1, x2, y2, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->setLineJoin(LineJoin);
            m_Doc->Items->at(z)->setLineEnd(LineEnd);
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:path")
        {
            //	poly =
            parseSVG( pg.attribute( "d" ), &PoLine );
            if (PoLine.size() < 4)
            {
                DOC = DOC.nextSibling();
                continue;
            }
            int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, baseX, baseY, 10, 10, strokewidth, FillCol, StrokeCol);
            m_Doc->Items->at(z)->PoLine = PoLine.copy();
            finishItem(m_Doc->Items->at(z));
        }
        else if (STag == "svg:g")
        {
            int z = m_Doc->itemAdd(PageItem::Group, PageItem::Rectangle, baseX, baseX, 1, 1, 0, CommonStrings::None, CommonStrings::None);
            PageItem *neu = m_Doc->Items->at(z);
            Elements.append(neu);
            if (groupStack.count() > 0)
                groupStack.top().append(neu);
            QList<PageItem*> gElements;
            groupStack.push(gElements);
            QDomNode child = DOC.firstChild();
            parseGroup(child);
            if (gElements.count() == 0)
            {
                groupStack.pop();
                Elements.removeAll(neu);
                groupStack.top().removeAll(neu);
                Selection tmpSelection(m_Doc, false);
                tmpSelection.addItem(neu);
                m_Doc->itemSelection_DeleteItem(&tmpSelection);
            }
            else
            {
                QList<PageItem*> gElem = groupStack.pop();
                double minx =  std::numeric_limits<double>::max();
                double miny =  std::numeric_limits<double>::max();
                double maxx = -std::numeric_limits<double>::max();
                double maxy = -std::numeric_limits<double>::max();
                for (int gr = 0; gr < gElements.count(); ++gr)
                {
                    PageItem* currItem = gElem.at(gr);
                    double x1, x2, y1, y2;
                    currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
                    minx = qMin(minx, x1);
                    miny = qMin(miny, y1);
                    maxx = qMax(maxx, x2);
                    maxy = qMax(maxy, y2);
                }
                double gx = minx;
                double gy = miny;
                double gw = maxx - minx;
                double gh = maxy - miny;
                neu->setXYPos(gx, gy, true);
                neu->setWidthHeight(gw, gh, true);
                neu->SetRectFrame();
                neu->Clip = FlattenPath(neu->PoLine, neu->Segments);
                neu->setItemName( tr("Group%1").arg(m_Doc->GroupCounter));
                neu->AutoName = false;
                neu->gXpos = neu->xPos() - gx;
                neu->gYpos = neu->yPos() - gy;
                neu->groupWidth = gw;
                neu->groupHeight = gh;
                for (int gr = 0; gr < gElem.count(); ++gr)
                {
                    PageItem* currItem = gElem.at(gr);
                    currItem->gXpos = currItem->xPos() - gx;
                    currItem->gYpos = currItem->yPos() - gy;
                    currItem->gWidth = gw;
                    currItem->gHeight = gh;
                    currItem->Parent = neu;
                    neu->groupItemList.append(currItem);
                    m_Doc->Items->removeAll(currItem);
                    Elements.removeAll(currItem);
                }
                neu->setRedrawBounding();
                neu->setTextFlowMode(PageItem::TextFlowDisabled);
                m_Doc->GroupCounter++;
            }
        }
        DOC = DOC.nextSibling();
    }
}
void
AppConfigGroup::setOption(const QString &optionName, const QColor &value)
{
	setOption(optionName, value.name());
}
Пример #17
0
void HtmlEditor::formatTextColor()
{
    QColor color = QColorDialog::getColor(Qt::black, this);
    if (color.isValid())
        execCommand("foreColor", color.name());
}
void GestureWidget::changeButtonColor(QColor c)
{
    buttonColor->setStyleSheet("background-color : " + c.name());
}
Пример #19
0
void storeColor(QJsonObject& parent, const QColor& color)
{
  parent[QStringLiteral("color")] = color.name(QColor::HexRgb);
}
Пример #20
0
void ExecutionLog::addLogMessage(const Log::Msg &msg)
{
    QString text;
    QDateTime time = QDateTime::fromMSecsSinceEpoch(msg.timestamp);
    QColor color;

    switch (msg.type) {
    case Log::INFO:
        color.setNamedColor("blue");
        break;
    case Log::WARNING:
        color.setNamedColor("orange");
        break;
    case Log::CRITICAL:
        color.setNamedColor("red");
        break;
    default:
        color = QApplication::palette().color(QPalette::WindowText);
    }

    text = "<font color='grey'>" + time.toString(Qt::SystemLocaleShortDate) + "</font> - <font color='" + color.name() + "'>" + msg.message + "</font>";
    m_msgList->appendLine(text);
}
Пример #21
0
void GraphPropertiesWidget::setNodeDefaultColor( QColor c )
{
    emit nodeDefaultColorSetted( c.name() );
}
Пример #22
0
QVariant MapToVariantConverter::toVariant(const Tileset &tileset,
                                          int firstGid) const
{
    QVariantMap tilesetVariant;

    if (firstGid > 0)
        tilesetVariant[QLatin1String("firstgid")] = firstGid;
    else
        tilesetVariant[QLatin1String("version")] = 1.2; // external tileset

    const QString &fileName = tileset.fileName();
    if (!fileName.isEmpty() && firstGid > 0) {
        QString source = mMapDir.relativeFilePath(fileName);
        tilesetVariant[QLatin1String("source")] = source;

        // Tileset is external, so no need to write any of the stuff below
        return tilesetVariant;
    }

    // Include a 'type' property if we are writing the tileset to its own file
    if (firstGid == 0)
        tilesetVariant[QLatin1String("type")] = QLatin1String("tileset");

    tilesetVariant[QLatin1String("name")] = tileset.name();
    tilesetVariant[QLatin1String("tilewidth")] = tileset.tileWidth();
    tilesetVariant[QLatin1String("tileheight")] = tileset.tileHeight();
    tilesetVariant[QLatin1String("spacing")] = tileset.tileSpacing();
    tilesetVariant[QLatin1String("margin")] = tileset.margin();
    tilesetVariant[QLatin1String("tilecount")] = tileset.tileCount();
    tilesetVariant[QLatin1String("columns")] = tileset.columnCount();

    const QColor bgColor = tileset.backgroundColor();
    if (bgColor.isValid())
        tilesetVariant[QLatin1String("backgroundcolor")] = colorToString(bgColor);

    addProperties(tilesetVariant, tileset.properties());

    const QPoint offset = tileset.tileOffset();
    if (!offset.isNull()) {
        QVariantMap tileOffset;
        tileOffset[QLatin1String("x")] = offset.x();
        tileOffset[QLatin1String("y")] = offset.y();
        tilesetVariant[QLatin1String("tileoffset")] = tileOffset;
    }

    if (tileset.orientation() != Tileset::Orthogonal || tileset.gridSize() != tileset.tileSize()) {
        QVariantMap grid;
        grid[QLatin1String("orientation")] = Tileset::orientationToString(tileset.orientation());
        grid[QLatin1String("width")] = tileset.gridSize().width();
        grid[QLatin1String("height")] = tileset.gridSize().height();
        tilesetVariant[QLatin1String("grid")] = grid;
    }

    // Write the image element
    const QUrl &imageSource = tileset.imageSource();
    if (!imageSource.isEmpty()) {
        const QString rel = toFileReference(imageSource, mMapDir);

        tilesetVariant[QLatin1String("image")] = rel;

        const QColor transColor = tileset.transparentColor();
        if (transColor.isValid())
            tilesetVariant[QLatin1String("transparentcolor")] = transColor.name();

        tilesetVariant[QLatin1String("imagewidth")] = tileset.imageWidth();
        tilesetVariant[QLatin1String("imageheight")] = tileset.imageHeight();
    }

    // Write the properties, terrain, external image, object group and
    // animation for those tiles that have them.
    QVariantList tilesVariant;
    for (const Tile *tile  : tileset.tiles()) {
        const Properties properties = tile->properties();
        QVariantMap tileVariant;

        addProperties(tileVariant, properties);

        if (!tile->type().isEmpty())
            tileVariant[QLatin1String("type")] = tile->type();
        if (tile->terrain() != 0xFFFFFFFF) {
            QVariantList terrainIds;
            for (int j = 0; j < 4; ++j)
                terrainIds << QVariant(tile->cornerTerrainId(j));
            tileVariant[QLatin1String("terrain")] = terrainIds;
        }
        if (tile->probability() != 1.0)
            tileVariant[QLatin1String("probability")] = tile->probability();
        if (!tile->imageSource().isEmpty()) {
            const QString rel = toFileReference(tile->imageSource(), mMapDir);
            tileVariant[QLatin1String("image")] = rel;

            const QSize tileSize = tile->size();
            if (!tileSize.isNull()) {
                tileVariant[QLatin1String("imagewidth")] = tileSize.width();
                tileVariant[QLatin1String("imageheight")] = tileSize.height();
            }
        }
        if (tile->objectGroup())
            tileVariant[QLatin1String("objectgroup")] = toVariant(*tile->objectGroup());
        if (tile->isAnimated()) {
            QVariantList frameVariants;
            for (const Frame &frame : tile->frames()) {
                QVariantMap frameVariant;
                frameVariant[QLatin1String("tileid")] = frame.tileId;
                frameVariant[QLatin1String("duration")] = frame.duration;
                frameVariants.append(frameVariant);
            }
            tileVariant[QLatin1String("animation")] = frameVariants;
        }

        if (!tileVariant.empty()) {
            tileVariant[QLatin1String("id")] = tile->id();
            tilesVariant << tileVariant;
        }
    }
    if (!tilesVariant.empty())
        tilesetVariant[QLatin1String("tiles")] = tilesVariant;

    // Write terrains
    if (tileset.terrainCount() > 0) {
        QVariantList terrainsVariant;
        for (int i = 0; i < tileset.terrainCount(); ++i) {
            Terrain *terrain = tileset.terrain(i);
            const Properties &properties = terrain->properties();
            QVariantMap terrainVariant;
            terrainVariant[QLatin1String("name")] = terrain->name();
            terrainVariant[QLatin1String("tile")] = terrain->imageTileId();
            addProperties(terrainVariant, properties);
            terrainsVariant << terrainVariant;
        }
        tilesetVariant[QLatin1String("terrains")] = terrainsVariant;
    }

    return tilesetVariant;
}
Пример #23
0
void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth )
{
  if ( elem.isNull() )
  {
    return;
  }

  //go through attributes
  QDomNamedNodeMap attributes = elem.attributes();
  int nAttributes = attributes.count();
  for ( int i = 0; i < nAttributes; ++i )
  {
    QDomAttr attribute = attributes.item( i ).toAttr();
    //e.g. style="fill:param(fill);param(stroke)"
    if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
    {
      //entries separated by ';'
      QString newAttributeString;

      QStringList entryList = attribute.value().split( ';' );
      QStringList::const_iterator entryIt = entryList.constBegin();
      for ( ; entryIt != entryList.constEnd(); ++entryIt )
      {
        QStringList keyValueSplit = entryIt->split( ':' );
        if ( keyValueSplit.size() < 2 )
        {
          continue;
        }
        QString key = keyValueSplit.at( 0 );
        QString value = keyValueSplit.at( 1 );
        if ( value.startsWith( "param(fill" ) )
        {
          value = fill.name();
        }
        else if ( value.startsWith( "param(outline)" ) )
        {
          value = outline.name();
        }
        else if ( value.startsWith( "param(outline-width)" ) )
        {
          value = QString::number( outlineWidth );
        }

        if ( entryIt != entryList.constBegin() )
        {
          newAttributeString.append( ";" );
        }
        newAttributeString.append( key + ":" + value );
      }
      elem.setAttribute( attribute.name(), newAttributeString );
    }
    else
    {
      QString value = attribute.value();
      if ( value.startsWith( "param(fill)" ) )
      {
        elem.setAttribute( attribute.name(), fill.name() );
      }
      else if ( value.startsWith( "param(outline)" ) )
      {
        elem.setAttribute( attribute.name(), outline.name() );
      }
      else if ( value.startsWith( "param(outline-width)" ) )
      {
        elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
      }
    }
  }

  QDomNodeList childList = elem.childNodes();
  int nChildren = childList.count();
  for ( int i = 0; i < nChildren; ++i )
  {
    QDomElement childElem = childList.at( i ).toElement();
    replaceElemParams( childElem, fill, outline, outlineWidth );
  }
}
Пример #24
0
void QTlenConfigDialog::setMyColor()
{
	QColor color = QColorDialog::getColor(QColor(settings->value("/preferences/sent/color", "#000000").toString()), this);
	if (color.isValid())
		settings->setValue("/preferences/sent/color", color.name());
}
Пример #25
0
int TALIB::indicatorPrefDialog (QWidget *w)
{
  const TA_FuncHandle *handle;
  const TA_FuncInfo *theInfo;
 
  // open a TALIB handle
  QString ts = "method";
  QString ts2;
  parms.getData(ts, ts2);
  TA_RetCode retCode = TA_GetFuncHandle(ts2, &handle);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::indicatorPrefDialog:can't open handle");
    return FALSE;
  }

  // get info on the function
  retCode = TA_GetFuncInfo(handle, &theInfo);
  if (retCode != TA_SUCCESS)
  {
    qDebug("TALIB::indicatorPrefDialog:can't get function info");
    return FALSE;
  }

  QString pl = QObject::tr("Parms");
  PrefDialog *dialog = new PrefDialog(w);
  dialog->setCaption(QObject::tr("TALIB Indicator"));
  dialog->createPage (pl);
  dialog->setHelpFile(helpFile);

  QStringList mal;
  getMATypes(mal);
  mal.remove("Wilder");

  // get the input parms
  const TA_OptInputParameterInfo *optInfo;
  int loop;
  for (loop = 0; loop < (int) theInfo->nbOptInput; loop++ )
  {
    TA_GetOptInputParameterInfo(theInfo->handle, loop, &optInfo);
    QString s = optInfo->displayName;
    switch (optInfo->type)
    {
      case TA_OptInput_RealRange:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addDoubleItem(s, pl, (double) optInfo->defaultValue, 0, 99999999);
          ts = QString::number((double) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addDoubleItem(s, pl, parms.getDouble(s), 0, 99999999);
        break;
      case TA_OptInput_IntegerRange:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addIntItem(s, pl, (int) optInfo->defaultValue, 1, 999999);
          ts = QString::number((int) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addIntItem(s, pl, parms.getInt(s), 1, 999999);
        break;
      case TA_OptInput_IntegerList:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addComboItem(s, pl, mal, (int) optInfo->defaultValue);
          ts = QString::number((int) optInfo->defaultValue);
          parms.setData(s, ts);
        }
        else
          dialog->addComboItem(s, pl, mal, parms.getInt(s));
        break;
      case TA_OptInput_RealList:
        break;
      default:
        break;
    }
  }

  // check for any array inputs
  const TA_InputParameterInfo *inputParms;
  for (loop = 0; loop < (int) theInfo->nbInput; loop++ )
  {
    QString s = QObject::tr("input") + QString::number(loop + 1);
    TA_GetInputParameterInfo(theInfo->handle, loop, &inputParms);
    switch (inputParms->type)
    {
      case TA_Input_Real:
        parms.getData(s, ts);
        if (! ts.length())
        {
          dialog->addComboItem(s, pl, inputTypeList, (int) BarData::Close);
          ts = QString::number(BarData::Close);
          parms.setData(s, ts);
        }
        else
          dialog->addComboItem(s, pl, inputTypeList, parms.getInt(s));
        break;
      default:
        break;
    }
  }

  // setup the output plots
  const TA_OutputParameterInfo *outInfo;
  for (loop = 0; loop < (int) theInfo->nbOutput; loop++ )
  {
    TA_GetOutputParameterInfo(theInfo->handle, loop, &outInfo);

    pl = outInfo->paramName;
    pl = pl.right(pl.length() - 3);
    if (! pl.left(4).compare("Real"))
      pl = pl.right(pl.length() - 4);
    if (! pl.left(7).compare("Integer"))
      pl = pl.right(pl.length() - 7);
    if (! pl.length())
      pl = QObject::tr("Plot");
    dialog->createPage (pl);

    QString s = pl + " " + QObject::tr("Color");
    QColor color;
    if (loop == 0)
      color.setNamedColor("red");
    else
    {
      if (loop == 1)
        color.setNamedColor("yellow");
      else
        color.setNamedColor("blue");
    }
    parms.getData(s, ts);
    if (! ts.length())
    {
      dialog->addColorItem(s, pl, color);
      ts = color.name();
      parms.setData(s, ts);
    }
    else
    {
      parms.getData(s, ts);
      color.setNamedColor(ts);
      dialog->addColorItem(s, pl, color);
    }

    s = pl + " " + QObject::tr("Label");
    parms.getData(s, ts);
    if (! ts.length())
    {
      dialog->addTextItem(s, pl, pl);
      parms.setData(s, pl);
    }
    else
    {
      parms.getData(s, ts);
      dialog->addTextItem(s, pl, ts);
    }

    s = pl + " " + QObject::tr("Line Type");
    parms.getData(s, ts);
    if (! ts.length()) 
    {
      switch (outInfo->flags)
      {
        case TA_OUT_DOT_LINE:
          ts = QString::number(PlotLine::Dot);
          break;
        case TA_OUT_DASH_LINE:
          ts = QString::number(PlotLine::Dash);
          break;
        case TA_OUT_HISTO:
          ts = QString::number(PlotLine::Histogram);
          break;
        default:
          ts = QString::number(PlotLine::Line);
          break;
      }

      dialog->addComboItem(s, pl, lineTypes, ts.toInt());
      parms.setData(s, ts);
    }
    else
      dialog->addComboItem(s, pl, lineTypes, parms.getInt(s));
  }

  int rc = dialog->exec();
  
  if (rc == QDialog::Accepted)
  {
    QStringList l;
    parms.getKeyList(l);
    int loop;
    for (loop = 0; loop < (int) l.count(); loop++)
    {
      QString s;
      dialog->getItem(l[loop], s);
      if (s.length())
        parms.setData(l[loop], s);
    }

    rc = TRUE;
  }
  else
    rc = FALSE;
  
  delete dialog;
  return rc;
}
Пример #26
0
void QTlenConfigDialog::setChatBg()
{
	QColor color = QColorDialog::getColor(QColor(settings->value("/preferences/received/bground", "#ffffff").toString()), this);
	if (color.isValid())
		settings->setValue("/preferences/received/bground", color.name());
}
Пример #27
0
/**
 * @brief Builds stylesheet for this WorkAreaTabBar widget.
 */
QString WorkAreaTabBar::buildStyleSheet()
{
    QColor background = palette().window().color();
    QColor gradientZero = QColor("#ffffff");//Qt::white;//.lighter(103);
    QColor gradientOne =  background.lighter(104);//Qt::white;//.lighter(103);
    QColor gradientTwo =  background.lighter(108);//.lighter(103);
    QColor selectedBorder = background.darker(103);

    QString aga1 = gradientOne.name();
    QString aga2 = gradientTwo.name();
    QString aga3 = background.name();

    QString styles = QString(
        "QTabBar::tab:first {"
            "margin-left: 4px;"
        "}  "
        "QTabBar::tab:last {"
            "margin-right: 1px;"
        "}  "
        "QTabBar::close-button { "
            "image: url(:/robomongo/icons/close_2_16x16.png);"
            "width: 10px;"
            "height: 10px;"
        "}"
        "QTabBar::close-button:hover { "
              "image: url(:/robomongo/icons/close_hover_16x16.png);"
              "width: 15px;"
              "height: 15px;"
        "}"
        "QTabBar::tab {"
            "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
                                        "stop: 0 #F0F0F0, stop: 0.4 #DEDEDE,"
                                        "stop: 0.5 #E6E6E6, stop: 1.0 #E1E1E1);"
            "border: 1px solid #C4C4C3;"
            "border-bottom-color: #B8B7B6;" // #C2C7CB same as the pane color
            "border-top-left-radius: 6px;"
            "border-top-right-radius: 6px;"
//            "min-width: 8ex;"
            "max-width: 200px;"
            "padding: 4px 0px 5px 0px;"
            "margin: 0px;"
            "margin-left: 1px;"
            "margin-right: -3px;"  // it should be -(tab:first:margin-left + tab:last:margin-left) to fix incorrect text elidement
        "}"

        "QTabBar::tab:selected, QTabBar::tab:hover {"
            "background: qlineargradient(x1: 0, y1: 1, x2: 0, y2: 0,"
                                        "stop: 0 %1, stop: 0.3 %2,"    //#fafafa, #f4f4f4
                                        "stop: 0.6 %3, stop: 1.0 %4);" //#e7e7e7, #fafafa
        "}"

        "QTabBar::tab:selected {"
            "border-color: #9B9B9B;" //
            "border-bottom-color: %4;" //#fafafa
        "}"

        "QTabBar::tab:!selected {"
            "margin-top: 2px;" // make non-selected tabs look smaller
        "}  "
        "QTabBar::tab:only-one { margin-top: 2px; margin-left:4px; }"
    ).arg(gradientZero.name(), gradientOne.name(), gradientTwo.name(), "#ffffff");

    QString aga = palette().window().color().name();

    return styles;
}
Пример #28
0
void toSqlText::setHighlighter(HighlighterTypeEnum h)
{
    using namespace ToConfiguration;

    // TODO handle bgthread working here
    QsciLexer *lexer = super::lexer();
    highlighterType = h;
    switch (highlighterType)
    {
        case None:
            if (m_analyzerNL == NULL)
                m_analyzerNL = new toSyntaxAnalyzerNL(this);
            m_currentAnalyzer = m_analyzerNL;
            m_worker->setAnalyzer(m_currentAnalyzer);
            setLexer(NULL);
            break;
        case QsciSql:
            if (m_analyzerNL == NULL)
                m_analyzerNL = new toSyntaxAnalyzerNL(this);
            m_currentAnalyzer = m_analyzerNL;
            m_worker->setAnalyzer(m_currentAnalyzer);
            setLexer(m_currentAnalyzer ? m_currentAnalyzer->createLexer(this) : NULL);
            break;
        case Oracle:
            if ( m_analyzerOracle == NULL)
                m_analyzerOracle = new toSyntaxAnalyzerOracle(this);
            m_currentAnalyzer = m_analyzerOracle;
            m_worker->setAnalyzer(m_currentAnalyzer);
            setLexer(m_currentAnalyzer ? m_currentAnalyzer->createLexer(this) : NULL);
            break;
#ifdef TORA_EXPERIMENTAL
        case MySQL:
            if ( m_analyzerMySQL == NULL)
            	m_analyzerMySQL = new toSyntaxAnalyzerMysql(this);
            m_currentAnalyzer = m_analyzerMySQL;
            m_worker->setAnalyzer(m_analyzerMySQL);
            setLexer(m_currentAnalyzer ? m_currentAnalyzer->createLexer(this) : NULL);
            break;
        case PostgreSQL:
            if ( m_analyzerPostgreSQL == NULL)
            	m_analyzerPostgreSQL = new toSyntaxAnalyzerPostgreSQL(this);
        	m_currentAnalyzer = m_analyzerPostgreSQL;
        	m_worker->setAnalyzer(m_analyzerPostgreSQL);
            setLexer(m_currentAnalyzer ? m_currentAnalyzer->createLexer(this) : NULL);
            break;
#endif
    }
#ifdef QT_DEBUG
	if (super::lexer())
	{
		QString txt = QLatin1String(ENUM_NAME(toSqlText, HighlighterTypeEnum, highlighterType));
		TLOG(8, toDecorator, __HERE__) << " Lexer: " << txt << std::endl;

		QMetaEnum m_enum = toSyntaxAnalyzer::staticMetaObject.enumerator(toSyntaxAnalyzer::staticMetaObject.indexOfEnumerator("WordClassEnum"));
		QString fontName = super::lexer()->font(0).toString();
		for (int idx = 0; idx < m_enum.keyCount(); idx++)
		{
			unsigned ival = m_enum.value(idx);
			QString  sval = m_enum.key(idx);
			TLOG(8, toNoDecorator, __HERE__) << "  Analyzer:" << sval << '(' << ival << ')' << std::endl;
			if (super::lexer() == NULL)
				break;
			QColor c = super::lexer()->color(ival);
			QColor p = super::lexer()->paper(ival);
			QFont  f = super::lexer()->font(ival);
			TLOG(8, toNoDecorator, __HERE__) << "  Style:" << sval << std::endl
				<< "   Fore:" << c.name() << '(' << c.red() << ' ' << c.green() << ' ' << c.blue() << ' ' << c.alpha() << ')' << std::endl
				<< "   Back:" << p.name() << '(' << p.red() << ' ' << p.green() << ' ' << p.blue() << ' ' << p.alpha() << ')' << std::endl
				<< "   Font:" << f.toString() << std::endl;
		}
	}
#endif

    if (lexer) // delete the "old" lexer - if any
        delete lexer;

    if (super::lexer())
    {
    	QPalette const& palette = QApplication::palette();
        declareStyle(Default,
                     QColor(Qt::black),
                     palette.color(QPalette::AlternateBase),
                     mono);
    	declareStyle(OneLine,
                     QColor(Qt::black),
                     QColor(toSqlText::lightCyan),
                     mono);
        declareStyle(OneLineAlt,
                     QColor(Qt::black),
                     QColor(toSqlText::lightMagenta),
                     mono);
    }

    setFont(Utils::toStringToFont(toConfigurationNewSingle::Instance().option(Editor::ConfCodeFont).toString()));
    //update(); gets called by setFont
}
Пример #29
0
QWidget* QmitkPropertyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option
  , const QModelIndex &index) const
{
  QVariant data = index.data(Qt::EditRole);
  QVariant displayData = index.data(Qt::DisplayRole);
  QString name = index.model()->data(index.model()->index(index.row(), index.column()-1)).value<QString>();

  if(data.isValid())
  {

    QWidget* editorWidget = NULL;

    if(data.type() == QVariant::Color)
    {
      QPushButton* colorBtn = new QPushButton(parent);
      QColor color = data.value<QColor>();

      QColor result = QColorDialog::getColor(color);
      if(result.isValid())
      {
        QPalette palette = colorBtn->palette();
        palette.setColor(QPalette::Button, result);
        colorBtn->setPalette(palette);
        colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(result.name()));
      }
      // QColorDialog closed by 'Cancel' button, use the old property color
      else
      {
        QPalette palette = colorBtn->palette();
        palette.setColor(QPalette::Button, color);
        colorBtn->setPalette(palette);
        colorBtn->setStyleSheet(QString("background-color: %1;foreground-color: %1; border-style: none;").arg(color.name()));

      }

      connect(colorBtn, SIGNAL(pressed()), this, SLOT(commitAndCloseEditor()));

      editorWidget = colorBtn;
    }

    else if(data.type() == QVariant::Int)
    {
      QSpinBox* spinBox = new QSpinBox(parent);
      spinBox->setSingleStep(1);
      spinBox->setMinimum(std::numeric_limits<int>::min());
      spinBox->setMaximum(std::numeric_limits<int>::max());
      editorWidget = spinBox;
    }
    // see qt documentation. cast is correct, it would be obsolete if we
    // store doubles
    else if(static_cast<QMetaType::Type>(data.type()) == QMetaType::Float)
    {
      QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
      spinBox->setDecimals(2);
      spinBox->setSingleStep(0.1);
      if(name == "opacity")
      {
        spinBox->setMinimum(0.0);
        spinBox->setMaximum(1.0);
      }
      else
      {
        spinBox->setMinimum(std::numeric_limits<float>::min());
        spinBox->setMaximum(std::numeric_limits<float>::max());
      }

      editorWidget = spinBox;
    }

    else if(data.type() == QVariant::StringList)
    {
      QStringList entries = data.value<QStringList>();
      QComboBox* comboBox = new QComboBox(parent);
      comboBox->setEditable(false);
      comboBox->addItems(entries);

      editorWidget = comboBox;
    }


    else
    {
      editorWidget = QStyledItemDelegate::createEditor(parent, option, index);
    }

    if ( editorWidget )
    {
      // install event filter
      editorWidget->installEventFilter( const_cast<QmitkPropertyDelegate*>(this) );
    }

    return editorWidget;

  }
  else
    return new QLabel(displayData.toString(), parent);

}
Пример #30
0
QString PaceZones::summarize(int rnum, QVector<double> &time_in_zone, QColor color) const
{

    assert(rnum < ranges.size());
    const PaceZoneRange &range = ranges[rnum];
    if (time_in_zone.size() != range.zones.size()) time_in_zone.resize(range.zones.size());

    // are we in metric or imperial ?
    bool metric = appsettings->value(this, GC_PACE, true).toBool();
    QString cvunit = metric ? "kph" : "mph";
    double cvfactor = metric ? 1.0f : KM_PER_MILE;
    QString paceunit = this->paceUnits(metric);

    QString summary;
    if(range.cv > 0) {
        summary += "<table align=\"center\" width=\"70%\" border=\"0\">";
        summary += "<tr><td align=\"center\">";
        summary += tr("Critical Velocity: %3%4 (%2%1)").arg(cvunit).arg(range.cv / cvfactor, 0, 'f', 2)
                                                        .arg(this->kphToPaceString(range.cv, metric))
                                                        .arg(paceunit);
        summary += "</td></tr></table>";
    }
    summary += "<table align=\"center\" width=\"70%\" ";
    summary += "border=\"0\">";
    summary += "<tr>";
    summary += tr("<td align=\"center\">Zone</td>");
    summary += tr("<td align=\"center\">Description</td>");
    summary += tr("<td align=\"center\">Low (%1)</td>").arg(paceunit);
    summary += tr("<td align=\"center\">High (%1)</td>").arg(paceunit);
    summary += tr("<td align=\"center\">Time</td>");
    summary += tr("<td align=\"center\">%</td>");
    summary += "</tr>";

    double duration = 0;
    foreach(double v, time_in_zone) {
        duration += v;
    }

    for (int zone = 0; zone < time_in_zone.size(); ++zone) {

        if (time_in_zone[zone] > 0.0) {
            QString name, desc;
            double lo, hi;
            zoneInfo(rnum, zone, name, desc, lo, hi);
            if (zone % 2 == 0)
                summary += "<tr bgcolor='" + color.name() + "'>"; else
                summary += "<tr>"; summary += QString("<td align=\"center\">%1</td>").arg(name);
            summary += QString("<td align=\"center\">%1</td>").arg(desc);
            summary += QString("<td align=\"center\">%1</td>").arg(this->kphToPaceString(lo, metric));
            if (hi == INT_MAX)
                summary += "<td align=\"center\">MAX</td>"; else
                summary += QString("<td align=\"center\">%1</td>").arg(this->kphToPaceString(hi, metric));
                summary += QString("<td align=\"center\">%1</td>").arg(time_to_string((unsigned) round(time_in_zone[zone])));
            summary += QString("<td align=\"center\">%1</td>")
                       .arg((double)time_in_zone[zone]/duration * 100, 0, 'f', 0);
            summary += "</tr>";
        }
    }
    summary += "</table>";
    return summary;
}