/* * Main function for handling the "set" command for setting pieces on the board during the settings stage. * * @return: -1 if the input tile, color or piece type were not formatted legally * -2 if the input tile is not a possible position on the board * -8 if the specified piece cannot be added there are already * too many pieces of this type on the board * 0 otherwise */ int setPiece(char* command){ int x, y; char tile[6]; char colorString[6]; char pieceString[7]; if (sscanf(command, "set %5s %5s %6s", tile, colorString, pieceString) != 3){ return -1; } if (readTile(tile, &x, &y) == -1){ return -1; } if (!Board_isInRange(x, y)){ return -2; } int color = stringToColor(colorString); char piece = stringToPiece(pieceString, color); if (piece == 0 || color == -1){ return -1; } if (PieceCounter_isAtMax(counter, piece, x, y)){ return -8; } if ((piece == Board_BLACK_PAWN || piece == Board_WHITE_PAWN) && Board_isFurthestRowForPlayer(color, y)){ return -8; } char removedPiece = Board_getPiece(&board, x, y); PieceCounter_update(counter, removedPiece, -1, x, y); PieceCounter_update(counter, piece, 1, x, y); Board_setPiece(&board, x, y, piece); Board_updateKingPosition(&board, x, y); return 0; }
void DisplayMap(std::ostream & out, const std::map<T, T2> &m, const std::string &delim=" ") { auto *no_color = zkr::cc::fore::console; for(auto var : m) { out << stringToColor(var.first) << var.first << delim << var.second << no_color << endl; } }
static Bool kconfigStringToValue (CompObject *object, QString str, CompOptionType type, CompOptionValue *value) { switch (type) { case CompOptionTypeBool: value->b = str.toInt () ? TRUE : FALSE; break; case CompOptionTypeFloat: value->f = str.toFloat (); break; case CompOptionTypeString: value->s = strdup (str.ascii ()); if (!value->s) return FALSE; break; case CompOptionTypeColor: if (!stringToColor (str.ascii (), value->c)) return FALSE; break; case CompOptionTypeKey: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToKeyAction (GET_CORE_DISPLAY (object), str.ascii (), &value->action); break; case CompOptionTypeButton: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToButtonAction (GET_CORE_DISPLAY (object), str.ascii (), &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask (str.ascii ()); break; case CompOptionTypeBell: value->action.bell = str.toInt () ? TRUE : FALSE; break; case CompOptionTypeMatch: matchInit (&value->match); matchAddFromString (&value->match, str.ascii ()); break; default: return FALSE; } return TRUE; }
/* * Main function for handling the "next_player" command for setting who's turn is first during the settings stage. * * @return: -1 if the input was not formatted legally * 0 otherwise */ int setFirstPlayer(char* command){ char colorString[6]; if(sscanf(command, "next_player %5s", colorString) != 1){ return -1; } int color = stringToColor(colorString); if (color == -1){ return -1; } first = color; return 0; }
void PrivateConsoleLogHandler::coloredLog(const qi::LogLevel verb, const qi::os::timeval date, const char *category, const char *msg, const char *file, const char *fct, const int line) { int context = qi::log::context(); boost::mutex::scoped_lock scopedLock(_mutex, boost::defer_lock_t()); if (_useLock) scopedLock.lock(); if (context & qi::LogContextAttr_Verbosity) { header(verb); } if (context & qi::LogContextAttr_ShortVerbosity) { header(verb, false); } if (context & qi::LogContextAttr_Date) printf("%s ", qi::detail::dateToString(date).c_str()); if (context & qi::LogContextAttr_Tid) { int tidColor = intToColor(qi::os::gettid()); textColorBG(tidColor); textColorFG(InvertConsoleColor[tidColor]); printf("%s", qi::detail::tidToString().c_str()); textColorAttr(reset); printf(" "); } if (context & qi::LogContextAttr_Category) { textColorFG(stringToColor(category)); printf("%s: ", category); textColorAttr(qi::log::PrivateConsoleLogHandler::reset); } if (context & qi::LogContextAttr_File) { printf("%s", file); if (line != 0) printf("(%i)", line); printf(" "); } if (context & qi::LogContextAttr_Function) printf("%s() ", fct); if (context & qi::LogContextAttr_Return) printf("\n"); std::string ss = msg; ss.reserve(qi::detail::rtrim(msg)); printf("%s\n", ss.c_str()); }
static void renderThumbText (CompScreen *s, Thumbnail *t, Bool freeThumb) { CompTextAttrib tA; if (freeThumb) freeThumbText (s, t); tA.maxWidth = t->width; tA.maxHeight = 100; const BananaValue * option_font_size = bananaGetOption (bananaIndex, "font_size", s->screenNum); unsigned short color[] = { 0, 0, 0, 0 }; const BananaValue * option_font_color = bananaGetOption (bananaIndex, "font_color", s->screenNum); stringToColor (option_font_color->s, color); tA.size = option_font_size->i; tA.color[0] = color[0]; tA.color[1] = color[1]; tA.color[2] = color[2]; tA.color[3] = color[3]; tA.flags = CompTextFlagEllipsized; const BananaValue * option_font_bold = bananaGetOption (bananaIndex, "font_bold", s->screenNum); if (option_font_bold->b) tA.flags |= CompTextFlagStyleBold; const BananaValue * option_font_family = bananaGetOption(bananaIndex, "font_family", s->screenNum); tA.family = option_font_family->s; t->textData = textRenderWindowTitle (s, t->win, FALSE, &tA); }
/* * Main function for handling the "user_color" command for setting the human player's color during the settings stage. * Using this command is legal only if playing in game mode 2 (player vs. AI). * * @return: -1 if the input was not formatted legally or if the current game mode is not player vs. AI * 0 otherwise */ int setUserColor(char* command){ if (gameMode != 2){ return -1; } char colorString[6]; if (sscanf(command, "user_color %5s", colorString) != 1){ return -1; } int color = stringToColor(colorString); if (color == -1){ return -1; } player1 = color; return 0; }
void BorderFilter::readParameters(const FilterAction& action) { d->settings.borderPath = action.parameter(QLatin1String("borderPath")).toString(); d->settings.borderPercent = action.parameter(QLatin1String("borderPercent")).toDouble(); d->settings.borderType = action.parameter(QLatin1String("borderType")).toInt(); d->settings.borderWidth1 = action.parameter(QLatin1String("borderWidth1")).toInt(); d->settings.borderWidth2 = action.parameter(QLatin1String("borderWidth2")).toInt(); d->settings.borderWidth3 = action.parameter(QLatin1String("borderWidth3")).toInt(); d->settings.borderWidth4 = action.parameter(QLatin1String("borderWidth4")).toInt(); d->settings.preserveAspectRatio = action.parameter(QLatin1String("preserveAspectRatio")).toBool(); d->settings.orgHeight = action.parameter(QLatin1String("orgHeight")).toInt(); d->settings.orgWidth = action.parameter(QLatin1String("orgWidth")).toInt(); d->settings.solidColor = stringToColor(action.parameter(QLatin1String("solidColor")).toString()); d->settings.niepceBorderColor = stringToColor(action.parameter(QLatin1String("niepceBorderColor")).toString()); d->settings.niepceLineColor = stringToColor(action.parameter(QLatin1String("niepceLineColor")).toString()); d->settings.bevelUpperLeftColor = stringToColor(action.parameter(QLatin1String("bevelUpperLeftColor")).toString()); d->settings.bevelLowerRightColor = stringToColor(action.parameter(QLatin1String("bevelLowerRightColor")).toString()); d->settings.decorativeFirstColor = stringToColor(action.parameter(QLatin1String("decorativeFirstColor")).toString()); d->settings.decorativeSecondColor = stringToColor(action.parameter(QLatin1String("decorativeSecondColor")).toString()); }
/* * groupPaintSelectionOutline * */ static void groupPaintSelectionOutline (CompScreen *s, const ScreenPaintAttrib *sa, const CompTransform *transform, CompOutput *output, Bool transformed) { int x1, x2, y1, y2; GROUP_SCREEN (s); x1 = MIN (gs->x1, gs->x2); y1 = MIN (gs->y1, gs->y2); x2 = MAX (gs->x1, gs->x2); y2 = MAX (gs->y1, gs->y2); const BananaValue * option_fill_color = bananaGetOption (bananaIndex, "fill_color", s->screenNum); const BananaValue * option_line_color = bananaGetOption (bananaIndex, "line_color", s->screenNum); unsigned short fill_color[] = { 0, 0, 0, 0 }; unsigned short line_color[] = { 0, 0, 0, 0 }; stringToColor (option_fill_color->s, fill_color); stringToColor (option_line_color->s, line_color); if (gs->grabState == ScreenGrabSelect) { CompTransform sTransform = *transform; if (transformed) { (*s->applyScreenTransform)(s, sa, output, &sTransform); transformToScreenSpace (s, output, -sa->zTranslate, &sTransform); } else transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnable (GL_BLEND); glColor4usv (fill_color); glRecti (x1, y2, x2, y1); glColor4usv (line_color); glBegin (GL_LINE_LOOP); glVertex2i (x1, y1); glVertex2i (x2, y1); glVertex2i (x2, y2); glVertex2i (x1, y2); glEnd (); glColor4usv (defaultColor); glDisable (GL_BLEND); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glPopMatrix (); } }
bool Document::loadMOJ(QString fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { return false; } QXmlStreamReader reader; // check if it is a gzipped moj QByteArray s = file.read(2); if (s.size() == 2) { if (s.at(0) == static_cast<char>(0x1f) && s.at(1) == static_cast<char>(0x8b)) { // this is a gzipped file file.reset(); QByteArray compressedData = file.readAll(); QByteArray uncompressedData; if (!QCompressor::gzipDecompress(compressedData, uncompressedData)) { return false; } reader.addData(uncompressedData); } else { file.reset(); reader.setDevice(&file); } } else { return false; } pages.clear(); int strokeCount = 0; while (!reader.atEnd()) { reader.readNext(); if (reader.name() == "MrWriter" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef docversion = attributes.value("document-version"); if (docversion.toInt() > DOC_VERSION) { // TODO warn about newer document version } } if (reader.name() == "page" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef width = attributes.value("", "width"); QStringRef height = attributes.value("", "height"); Page newPage; newPage.setWidth(width.toDouble()); newPage.setHeight(height.toDouble()); pages.append(newPage); } if (reader.name() == "background" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef color = attributes.value("", "color"); QColor newColor = stringToColor(color.toString()); pages.last().setBackgroundColor(newColor); } if (reader.name() == "stroke" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef tool = attributes.value("", "tool"); if (tool == "pen") { Stroke newStroke; newStroke.pattern = MrDoc::solidLinePattern; QStringRef color = attributes.value("", "color"); newStroke.color = stringToColor(color.toString()); QStringRef style = attributes.value("", "style"); if (style.toString().compare("solid") == 0) { newStroke.pattern = MrDoc::solidLinePattern; } else if (style.toString().compare("dash") == 0) { newStroke.pattern = MrDoc::dashLinePattern; } else if (style.toString().compare("dashdot") == 0) { newStroke.pattern = MrDoc::dashDotLinePattern; } else if (style.toString().compare("dot") == 0) { newStroke.pattern = MrDoc::dotLinePattern; } else { newStroke.pattern = MrDoc::solidLinePattern; } QStringRef strokeWidth = attributes.value("", "width"); newStroke.penWidth = strokeWidth.toDouble(); QString elementText = reader.readElementText(); QStringList elementTextList = elementText.trimmed().split(" "); for (int i = 0; i + 1 < elementTextList.size(); i = i + 2) { newStroke.points.append(QPointF(elementTextList.at(i).toDouble(), elementTextList.at(i + 1).toDouble())); } QStringRef pressures = attributes.value("pressures"); QStringList pressuresList = pressures.toString().trimmed().split(" "); for (int i = 0; i < pressuresList.length(); ++i) { if (pressuresList.length() == 0) { newStroke.pressures.append(1.0); } else { newStroke.pressures.append(pressuresList.at(i).toDouble()); } } if (newStroke.pressures.size() != newStroke.points.size()) { return false; } pages.last().appendStroke(newStroke); strokeCount++; qDebug() << strokeCount; } } } QFileInfo fileInfo(file); file.close(); for (auto &page : pages) { page.clearDirtyRect(); } if (reader.hasError()) { return false; } else { m_path = fileInfo.absolutePath(); m_docName = fileInfo.completeBaseName(); return true; } }
static Bool fuseInitValueFromString(CompObject *object, CompOptionValue *value, CompOptionType type, char *str) { switch (type) { case CompOptionTypeBool: value->b = strcmp(str, "true") ? FALSE : TRUE; break; case CompOptionTypeInt: value->i = atoi(str); break; case CompOptionTypeFloat: value->f = strtod(str, NULL); break; case CompOptionTypeString: value->s = strdup(str); break; case CompOptionTypeColor: if (!stringToColor(str, value->c)) return FALSE; break; case CompOptionTypeKey: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToKeyAction(GET_CORE_DISPLAY(object), str, &value->action); break; case CompOptionTypeButton: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToButtonAction(GET_CORE_DISPLAY(object), str, &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask(str); break; case CompOptionTypeBell: value->action.bell = strcmp(str, "true") ? FALSE : TRUE; break; case CompOptionTypeMatch: matchInit(&value->match); matchAddFromString(&value->match, str); break; default: return FALSE; } return TRUE; }
static void thumbPaintThumb (CompScreen *s, Thumbnail *t, const CompTransform *transform) { AddWindowGeometryProc oldAddWindowGeometry; CompWindow *w = t->win; int wx = t->x; int wy = t->y; float width = t->width; float height = t->height; WindowPaintAttrib sAttrib; unsigned int mask = PAINT_WINDOW_TRANSFORMED_MASK | PAINT_WINDOW_TRANSLUCENT_MASK; THUMB_SCREEN (s); if (!w) return; sAttrib = w->paint; if (t->textData) height += t->textData->height + TEXT_DISTANCE; /* Wrap drawWindowGeometry to make sure the general drawWindowGeometry function is used */ oldAddWindowGeometry = s->addWindowGeometry; s->addWindowGeometry = addWindowGeometry; if (w->texture->pixmap) { int off = t->offset; GLenum filter = display.textureFilter; FragmentAttrib fragment; CompTransform wTransform = *transform; glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisableClientState (GL_TEXTURE_COORD_ARRAY); const BananaValue * option_window_like = bananaGetOption (bananaIndex, "window_like", s->screenNum); if (option_window_like->b) { glColor4f (1.0, 1.0, 1.0, t->opacity); enableTexture (s, &ts->windowTexture, COMP_TEXTURE_FILTER_GOOD); } else { unsigned short color[] = { 0, 0, 0, 0 }; const BananaValue * option_thumb_color = bananaGetOption (bananaIndex, "thumb_color", s->screenNum); stringToColor (option_thumb_color->s, color); glColor4us (color[0], color[1], color[2], color[3] * t->opacity); enableTexture (s, &ts->glowTexture, COMP_TEXTURE_FILTER_GOOD); } glBegin (GL_QUADS); glTexCoord2f (1, 0); glVertex2f (wx, wy); glVertex2f (wx, wy + height); glVertex2f (wx + width, wy + height); glVertex2f (wx + width, wy); glTexCoord2f (0, 1); glVertex2f (wx - off, wy - off); glTexCoord2f (0, 0); glVertex2f (wx - off, wy); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 1); glVertex2f (wx, wy - off); glTexCoord2f (1, 1); glVertex2f (wx + width, wy - off); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy); glTexCoord2f (0, 1); glVertex2f (wx + width + off, wy - off); glTexCoord2f (0, 0); glVertex2f (wx - off, wy + height); glTexCoord2f (0, 1); glVertex2f (wx - off, wy + height + off); glTexCoord2f (1, 1); glVertex2f (wx, wy + height + off); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (1, 1); glVertex2f (wx + width, wy + height + off); glTexCoord2f (0, 1); glVertex2f (wx + width + off, wy + height + off); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy + height); glTexCoord2f (1, 1); glVertex2f (wx, wy - off); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (1, 1); glVertex2f (wx + width, wy - off); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 1); glVertex2f (wx, wy + height + off); glTexCoord2f (1, 1); glVertex2f (wx + width, wy + height + off); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (0, 0); glVertex2f (wx - off, wy); glTexCoord2f (0, 0); glVertex2f (wx - off, wy + height); glTexCoord2f (1, 0); glVertex2f (wx, wy + height); glTexCoord2f (1, 0); glVertex2f (wx, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy); glTexCoord2f (1, 0); glVertex2f (wx + width, wy + height); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy + height); glTexCoord2f (0, 0); glVertex2f (wx + width + off, wy); glEnd (); if (option_window_like->b) { disableTexture (s, &ts->windowTexture); } else { disableTexture (s, &ts->glowTexture); } glColor4usv (defaultColor); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if (t->textData) { float ox = 0.0; if (t->textData->width < width) ox = (width - (int)t->textData->width) / 2.0; textDrawText (s, t->textData, wx + ox, wy + height, t->opacity); } glEnableClientState (GL_TEXTURE_COORD_ARRAY); glDisable (GL_BLEND); screenTexEnvMode (s, GL_REPLACE); glColor4usv (defaultColor); sAttrib.opacity *= t->opacity; sAttrib.yScale = t->scale; sAttrib.xScale = t->scale; sAttrib.xTranslate = wx - w->attrib.x + w->input.left * sAttrib.xScale; sAttrib.yTranslate = wy - w->attrib.y + w->input.top * sAttrib.yScale; const BananaValue * option_mipmap = bananaGetOption (bananaIndex, "mipmap", s->screenNum); if (option_mipmap->b) display.textureFilter = GL_LINEAR_MIPMAP_LINEAR; initFragmentAttrib (&fragment, &sAttrib); matrixTranslate (&wTransform, w->attrib.x, w->attrib.y, 0.0f); matrixScale (&wTransform, sAttrib.xScale, sAttrib.yScale, 1.0f); matrixTranslate (&wTransform, sAttrib.xTranslate / sAttrib.xScale - w->attrib.x, sAttrib.yTranslate / sAttrib.yScale - w->attrib.y, 0.0f); glPushMatrix (); glLoadMatrixf (wTransform.m); (*s->drawWindow) (w, &wTransform, &fragment, &infiniteRegion, mask); glPopMatrix (); display.textureFilter = filter; } s->addWindowGeometry = oldAddWindowGeometry; }
QColor BaseStateAbstract::readColor(QStringRef val) { return stringToColor(val); }
void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText ) { scene->clear(); mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer ); QDomDocument doc; QString data = QString::fromUtf8(templateXml); QString replacementText = QString::fromUtf8(templateText); doc.setContent(data); QDomElement title = doc.documentElement(); // Check for invalid title if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return; // Check title locale if ( title.hasAttribute( "LC_NUMERIC" ) ) { QString locale = title.attribute( "LC_NUMERIC" ); QLocale::setDefault( locale ); } int originalWidth; int originalHeight; if ( title.hasAttribute("width") ) { originalWidth = title.attribute("width").toInt(); originalHeight = title.attribute("height").toInt(); scene->setSceneRect(0, 0, originalWidth, originalHeight); } else { originalWidth = scene->sceneRect().width(); originalHeight = scene->sceneRect().height(); } if ( title.hasAttribute( "out" ) ) { mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() ); } else { mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) ); } mlt_properties_set_int( producer_props, "_original_width", originalWidth ); mlt_properties_set_int( producer_props, "_original_height", originalHeight ); QDomNode node; QDomNodeList items = title.elementsByTagName("item"); for ( int i = 0; i < items.count(); i++ ) { QGraphicsItem *gitem = NULL; node = items.item( i ); QDomNamedNodeMap nodeAttributes = node.attributes(); int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt(); if ( zValue > -1000 ) { if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" ) { QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes(); QFont font( txtProperties.namedItem( "font" ).nodeValue() ); QDomNode propsNode = txtProperties.namedItem( "font-bold" ); if ( !propsNode.isNull() ) { // Old: Bold/Not bold. font.setBold( propsNode.nodeValue().toInt() ); } else { // New: Font weight (QFont::) font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() ); } font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() ); font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() ); // Older Kdenlive version did not store pixel size but point size if ( txtProperties.namedItem( "font-pixel-size" ).isNull() ) { QFont f2; f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() ); font.setPixelSize( QFontInfo( f2 ).pixelSize() ); } else font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() ); QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) ); QString text = node.namedItem( "content" ).firstChild().nodeValue(); if ( !replacementText.isEmpty() ) { text = text.replace( "%s", replacementText ); } QGraphicsTextItem *txt = scene->addText(text, font); if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){ QTextDocument *doc = txt->document(); // Make sure some that the text item does not request refresh by itself doc->blockSignals(true); QTextCursor cursor(doc); cursor.select(QTextCursor::Document); QTextCharFormat format; format.setTextOutline( QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ), txtProperties.namedItem("font-outline").nodeValue().toDouble(), Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin) ); format.setForeground(QBrush(col)); cursor.mergeCharFormat(format); } else { txt->setDefaultTextColor( col ); } // Effects if (!txtProperties.namedItem( "typewriter" ).isNull()) { // typewriter effect mlt_properties_set_int( producer_props, "_animated", 1 ); QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue(); txt->setData(0, effetData); if ( !txtProperties.namedItem( "textwidth" ).isNull() ) txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() ); } if ( txtProperties.namedItem( "alignment" ).isNull() == false ) { txt->setTextWidth( txt->boundingRect().width() ); QTextOption opt = txt->document()->defaultTextOption (); opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() ); txt->document()->setDefaultTextOption (opt); } if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() ) { //txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt()); } if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() ) { //txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt()); } gitem = txt; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" ) { QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue(); QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue(); QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue(); double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble(); QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) ); gitem = rec; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" ) { const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue(); const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue(); QImage img; if (base64.isEmpty()){ img.load(url); }else{ img.loadFromData(QByteArray::fromBase64(base64.toAscii())); } ImageItem *rec = new ImageItem(img); scene->addItem( rec ); gitem = rec; } else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" ) { QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue(); QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue(); QGraphicsSvgItem *rec = NULL; if (base64.isEmpty()){ rec = new QGraphicsSvgItem(url); }else{ rec = new QGraphicsSvgItem(); QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec ); rec->setSharedRenderer(renderer); } if (rec){ scene->addItem(rec); gitem = rec; } } } //pos and transform if ( gitem ) { QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(), node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() ); gitem->setPos( p ); gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) ); int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt(); gitem->setZValue( zValue ); #if QT_VERSION >= 0x040600 // effects QDomNode eff = items.item(i).namedItem("effect"); if (!eff.isNull()) { QDomElement e = eff.toElement(); if (e.attribute("type") == "blur") { QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(); blur->setBlurRadius(e.attribute("blurradius").toInt()); gitem->setGraphicsEffect(blur); } else if (e.attribute("type") == "shadow") { QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(); shadow->setBlurRadius(e.attribute("blurradius").toInt()); shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt()); gitem->setGraphicsEffect(shadow); } } #endif } } QDomNode n = title.firstChildElement("background"); if (!n.isNull()) { QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) ); if (color.alpha() > 0) { QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) ); rec->setZValue(-1100); } } QString startRect; n = title.firstChildElement( "startviewport" ); // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport if (!n.isNull() && !n.toElement().hasAttribute("x")) { startRect = n.attributes().namedItem( "rect" ).nodeValue(); } n = title.firstChildElement( "endviewport" ); // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport if (!n.isNull() && !n.toElement().hasAttribute("x")) { QString rect = n.attributes().namedItem( "rect" ).nodeValue(); if (startRect != rect) mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() ); } if (!startRect.isEmpty()) { mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() ); } return; }
static Bool tdPaintWindowWithDepth (CompWindow *w, const WindowPaintAttrib *attrib, const CompTransform *transform, Region region, unsigned int mask) { //Bool wasCulled; Bool status; int wx, wy, ww, wh; int bevel, cull, cullInv, temp; CompScreen *s = w->screen; CompVector point, tPoint; unsigned short c[4]; TD_SCREEN (s); TD_WINDOW (w); CUBE_SCREEN (s); //wasCulled = glIsEnabled (GL_CULL_FACE); wx = w->attrib.x - w->input.left; wy = w->attrib.y - w->input.top; ww = w->width + w->input.left + w->input.right; wh = w->height + w->input.top + w->input.bottom; const BananaValue * option_bevel = bananaGetOption (bananaIndex, "bevel", s->screenNum); bevel = option_bevel->i; glGetIntegerv (GL_CULL_FACE_MODE, &cull); cullInv = (cull == GL_BACK)? GL_FRONT : GL_BACK; if (ww && wh && !(mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) && ((cs->paintOrder == FTB && tdw->ftb) || (cs->paintOrder == BTF && !tdw->ftb))) { /* Paint window depth. */ glPushMatrix (); glLoadIdentity (); if (cs->paintOrder == BTF) glCullFace (cullInv); glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (w->id == display.activeWindow) { const BananaValue * option_width_color = bananaGetOption (bananaIndex, "width_color", s->screenNum); stringToColor (option_width_color->s, c); } else { const BananaValue * option_width_color_inactive = bananaGetOption (bananaIndex, "width_color_inactive", s->screenNum); stringToColor (option_width_color_inactive->s, c); } temp = c[3] * w->paint.opacity; temp /= 0xffff; glColor4us (c[0], c[1], c[2], temp); point.z = 0.0f; point.w = 1.0f; glBegin (GL_QUADS); /* Top */ ADDQUAD (wx + ww - dobevel ("bevel_topleft", bevel), wy + 0.01, wx + dobevel ("bevel_topright", bevel), wy + 0.01); /* Bottom */ ADDQUAD ( wx + dobevel ("bevel_bottomleft", bevel), wy + wh - 0.01, wx + ww - dobevel ("bevel_bottomright", bevel), wy + wh - 0.01); /* Left */ ADDQUAD (wx + 0.01, wy + dobevel ("bevel_topleft", bevel), wx + 0.01, wy + wh - dobevel ("bevel_bottomleft", bevel)); /* Right */ ADDQUAD (wx + ww - 0.01, wy + wh - dobevel ("bevel_topright", bevel), wx + ww - 0.01, wy + dobevel ("bevel_bottomright", bevel)); const BananaValue * option_bevel_topleft = bananaGetOption (bananaIndex, "bevel_topleft", s->screenNum); /* Top left bevel */ if (option_bevel_topleft->b) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx, wy + bevel, &tds->bTransform, transform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + bevel - bevel / 1.2f, wx + bevel, wy, transform, &tds->bTransform); } const BananaValue * option_bevel_bottomleft = bananaGetOption (bananaIndex, "bevel_bottomleft", s->screenNum); /* Bottom left bevel */ if (option_bevel_bottomleft->b) { ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx, wy + wh - bevel, transform, &tds->bTransform); ADDBEVELQUAD (wx + bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + bevel, wy + wh, &tds->bTransform, transform); } const BananaValue * option_bevel_bottomright = bananaGetOption (bananaIndex, "bevel_bottomright", s->screenNum); /* Bottom right bevel */ if (option_bevel_bottomright->b) { ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww - bevel, wy + wh, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww - bevel / 2.0f, wy + wh - bevel + bevel / 1.2f, wx + ww, wy + wh - bevel, &tds->bTransform, transform); } const BananaValue * option_bevel_topright = bananaGetOption (bananaIndex, "bevel_topright", s->screenNum); /* Top right bevel */ if (option_bevel_topright->b) { ADDBEVELQUAD (wx + ww - bevel, wy, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, transform, &tds->bTransform); ADDBEVELQUAD (wx + ww, wy + bevel, wx + ww - bevel / 2.0f, wy + bevel - bevel / 1.2f, &tds->bTransform, transform); } glEnd (); glColor4usv (defaultColor); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glPopMatrix (); if (cs->paintOrder == BTF) glCullFace (cull); } UNWRAP(tds, s, paintWindow); if (cs->paintOrder == BTF) status = (*s->paintWindow) (w, attrib, transform, region, mask); else status = (*s->paintWindow) (w, attrib, &tds->bTransform, region, mask | PAINT_WINDOW_TRANSFORMED_MASK); WRAP (tds, s, paintWindow, tdPaintWindow); return status; }
static Bool iniLoadOptionsFromFile (FILE *optionFile, CompObject *object, const char *plugin, Bool *reSave) { CompOption *option = NULL, *o; CompPlugin *p = NULL; CompOptionValue value; char *optionName = NULL, *optionValue = NULL; char tmp[MAX_OPTION_LENGTH]; int nOption, nOptionRead = 0; Bool status = FALSE, hasValue = FALSE; if (plugin) { p = findActivePlugin (plugin); if (!p) { compLogMessage ("ini", CompLogLevelWarn, "Could not find running plugin " \ "%s (iniLoadOptionsFromFile)", plugin); return FALSE; } } else { return FALSE; } if (p->vTable->getObjectOptions) option = (*p->vTable->getObjectOptions) (p, object, &nOption); while (fgets (tmp, MAX_OPTION_LENGTH, optionFile) != NULL) { status = FALSE; if (!iniParseLine (tmp, &optionName, &optionValue)) { compLogMessage ("ini", CompLogLevelWarn, "Ignoring line '%s' in %s", tmp, plugin); continue; } if (option) { o = compFindOption (option, nOption, optionName, 0); if (o) { value = o->value; switch (o->type) { case CompOptionTypeBool: hasValue = TRUE; value.b = (Bool) atoi (optionValue); break; case CompOptionTypeInt: hasValue = TRUE; value.i = atoi (optionValue); break; case CompOptionTypeFloat: hasValue = TRUE; value.f = atof (optionValue); break; case CompOptionTypeString: hasValue = TRUE; value.s = strdup (optionValue); break; case CompOptionTypeColor: hasValue = stringToColor (optionValue, value.c); break; case CompOptionTypeKey: hasValue = TRUE; stringToKeyAction (GET_CORE_DISPLAY (object), optionValue, &value.action); break; case CompOptionTypeButton: hasValue = TRUE; stringToButtonAction (GET_CORE_DISPLAY (object), optionValue, &value.action); break; case CompOptionTypeEdge: hasValue = TRUE; value.action.edgeMask = stringToEdgeMask (optionValue); break; case CompOptionTypeBell: hasValue = TRUE; value.action.bell = (Bool) atoi (optionValue); break; case CompOptionTypeList: hasValue = csvToList (GET_CORE_DISPLAY (object), optionValue, &value.list, value.list.type); break; case CompOptionTypeMatch: hasValue = TRUE; matchInit (&value.match); matchAddFromString (&value.match, optionValue); break; default: break; } if (hasValue) { status = (*core.setOptionForPlugin) (object, plugin, optionName, &value); if (o->type == CompOptionTypeMatch) { matchFini (&value.match); } } nOptionRead++; } } /* clear up */ if (optionName) free (optionName); if (optionValue) free (optionValue); } if (nOption != nOptionRead) { *reSave = TRUE; } return TRUE; }
static void wsnamesRenderNameText (CompScreen *s) { CompTextAttrib attrib; char *name; int ox1, ox2, oy1, oy2; WSNAMES_SCREEN (s); wsnamesFreeText (s); name = wsnamesGetCurrentWSName (s); if (!name) return; getCurrentOutputExtents (s, &ox1, &oy1, &ox2, &oy2); /* 75% of the output device as maximum width */ attrib.maxWidth = (ox2 - ox1) * 3 / 4; attrib.maxHeight = 100; const BananaValue * option_font_size = bananaGetOption (bananaIndex, "font_size", s->screenNum); const BananaValue * option_font_family = bananaGetOption(bananaIndex, "font_family", s->screenNum); attrib.family = option_font_family->s; attrib.size = option_font_size->i; const BananaValue * option_font_color = bananaGetOption (bananaIndex, "font_color", s->screenNum); unsigned short color[] = { 0, 0, 0, 0 }; stringToColor (option_font_color->s, color); attrib.color[0] = color[0]; attrib.color[1] = color[1]; attrib.color[2] = color[2]; attrib.color[3] = color[3]; const BananaValue * option_bold_text = bananaGetOption (bananaIndex, "bold_text", s->screenNum); attrib.flags = CompTextFlagWithBackground | CompTextFlagEllipsized; if (option_bold_text->b) attrib.flags |= CompTextFlagStyleBold; attrib.bgHMargin = 15; attrib.bgVMargin = 15; const BananaValue * option_back_color = bananaGetOption (bananaIndex, "back_color", s->screenNum); unsigned short back_color[] = { 0, 0, 0, 0 }; stringToColor (option_back_color->s, back_color); attrib.bgColor[0] = back_color[0]; attrib.bgColor[1] = back_color[1]; attrib.bgColor[2] = back_color[2]; attrib.bgColor[3] = back_color[3]; ws->textData = textRenderText (s, name, &attrib); }
QColor BaseStateAbstract::stringToColor(QStringRef val) { return stringToColor(val.toString()); }
bool Document::loadXOJ(QString fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { return false; } QXmlStreamReader reader; // check if it is a gzipped xoj QByteArray s = file.read(2); if (s.size() == 2) { if (s.at(0) == static_cast<char>(0x1f) && s.at(1) == static_cast<char>(0x8b)) { // this is a gzipped file file.reset(); QByteArray compressedData = file.readAll(); QByteArray uncompressedData; if (!QCompressor::gzipDecompress(compressedData, uncompressedData)) { return false; } reader.addData(uncompressedData); } else { file.reset(); reader.setDevice(&file); } } else { return false; } pages.clear(); int strokeCount = 0; while (!reader.atEnd()) { reader.readNext(); if (reader.name() == "page" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef width = attributes.value("", "width"); QStringRef height = attributes.value("", "height"); Page newPage; newPage.setWidth(width.toDouble()); newPage.setHeight(height.toDouble()); pages.append(newPage); } if (reader.name() == "background" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef color = attributes.value("", "color"); QColor newColor = stringToColor(color.toString()); pages.last().setBackgroundColor(newColor); } if (reader.name() == "stroke" && reader.tokenType() == QXmlStreamReader::StartElement) { QXmlStreamAttributes attributes = reader.attributes(); QStringRef tool = attributes.value("", "tool"); if (tool == "pen") { Stroke newStroke; newStroke.pattern = MrDoc::solidLinePattern; QStringRef color = attributes.value("", "color"); newStroke.color = stringToColor(color.toString()); QStringRef strokeWidth = attributes.value("", "width"); QStringList strokeWidthList = strokeWidth.toString().split(" "); newStroke.penWidth = strokeWidthList.at(0).toDouble(); newStroke.pressures.append(newStroke.penWidth / strokeWidthList.at(0).toDouble()); for (int i = 1; i < strokeWidthList.size(); ++i) { newStroke.pressures.append(2 * strokeWidthList.at(i).toDouble() / newStroke.penWidth - newStroke.pressures.at(i - 1)); } QString elementText = reader.readElementText(); QStringList elementTextList = elementText.split(" "); for (int i = 0; i + 1 < elementTextList.size(); i = i + 2) { newStroke.points.append(QPointF(elementTextList.at(i).toDouble(), elementTextList.at(i + 1).toDouble())); } while (newStroke.points.size() > newStroke.pressures.size()) { newStroke.pressures.append(1.0); } pages.last().appendStroke(newStroke); strokeCount++; qDebug() << strokeCount; } } } // QFileInfo fileInfo(file); file.close(); for (auto &page : pages) { page.clearDirtyRect(); } if (reader.hasError()) { return false; } else { setDocumentChanged(true); return true; } }