void gtAction:: setCharStyleAttributes(gtFont *font, CharStyle& style) { int flags = font->getFlags(); style.erase(); if ((flags & gtFont::familyWasSet) || (flags & gtFont::weightWasSet) || (flags & gtFont::slantWasSet)) style.setFont(validateFont(font)); if (flags & gtFont::sizeWasSet) style.setFontSize(font->getSize()); if (flags & gtFont::effectWasSet) style.setFeatures(static_cast<StyleFlag>(font->getEffectsValue()).featureList()); if (flags & gtFont::fillColorWasSet) style.setFillColor(parseColor(font->getColor())); if (flags & gtFont::fillShadeWasSet) style.setFillShade(font->getShade()); if (flags & gtFont::strokeColorWasSet) style.setStrokeColor(parseColor(font->getStrokeColor())); if (flags & gtFont::strokeShadeWasSet) style.setStrokeShade(font->getStrokeShade()); if (flags & gtFont::hscaleWasSet) style.setScaleH(font->getHscale()); if (flags & gtFont::kerningWasSet) style.setTracking(font->getKerning()); }
/*! 03.01.2007 - 05.01.2007 : Joachim Neu : Create a char style. Special thanks go to avox for helping me! */ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject* keywords) { char* keywordargs[] = { const_cast<char*>("name"), const_cast<char*>("font"), const_cast<char*>("fontsize"), const_cast<char*>("features"), const_cast<char*>("fillcolor"), const_cast<char*>("fillshade"), const_cast<char*>("strokecolor"), const_cast<char*>("strokeshade"), const_cast<char*>("baselineoffset"), const_cast<char*>("shadowxoffset"), const_cast<char*>("shadowyoffset"), const_cast<char*>("outlinewidth"), const_cast<char*>("underlineoffset"), const_cast<char*>("underlinewidth"), const_cast<char*>("strikethruoffset"), const_cast<char*>("strikethruwidth"), const_cast<char*>("scaleh"), const_cast<char*>("scalev"), const_cast<char*>("tracking"), const_cast<char*>("language"), NULL}; char *Name = const_cast<char*>(""), *Font = const_cast<char*>("Times"), *Features = const_cast<char*>("inherit"), *FillColor = const_cast<char*>("Black"), *StrokeColor = const_cast<char*>("Black"), *Language = const_cast<char*>(""); double FontSize = 200, FillShade = 1, StrokeShade = 1, ScaleH = 1, ScaleV = 1, BaselineOffset = 0, ShadowXOffset = 0, ShadowYOffset = 0, OutlineWidth = 0, UnderlineOffset = 0, UnderlineWidth = 0, StrikethruOffset = 0, StrikethruWidth = 0, Tracking = 0; if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddes", keywordargs, "utf-8", &Name, "utf-8", &Font, &FontSize, "utf-8", &Features, "utf-8", &FillColor, &FillShade, "utf-8", &StrokeColor, &StrokeShade, &BaselineOffset, &ShadowXOffset, &ShadowYOffset, &OutlineWidth, &UnderlineOffset, &UnderlineWidth, &StrikethruOffset, &StrikethruWidth, &ScaleH, &ScaleV, &Tracking, "utf-8", &Language)) return NULL; if(!checkHaveDocument()) return NULL; if(Name == EMPTY_STRING) { PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty char style name.","python error").toLocal8Bit().constData()); return NULL; } QStringList FeaturesList = QString(Features).split(QString(",")); CharStyle TmpCharStyle; TmpCharStyle.setName(Name); TmpCharStyle.setFont((*ScCore->primaryMainWindow()->doc->AllFonts)[QString(Font)]); TmpCharStyle.setFontSize(FontSize * 10); TmpCharStyle.setFeatures(FeaturesList); TmpCharStyle.setFillColor(QString(FillColor)); TmpCharStyle.setFillShade(FillShade * 100); TmpCharStyle.setStrokeColor(QString(StrokeColor)); TmpCharStyle.setStrokeShade(StrokeShade * 100); TmpCharStyle.setBaselineOffset(BaselineOffset); TmpCharStyle.setShadowXOffset(ShadowXOffset); TmpCharStyle.setShadowYOffset(ShadowYOffset); TmpCharStyle.setOutlineWidth(OutlineWidth); TmpCharStyle.setUnderlineOffset(UnderlineOffset); TmpCharStyle.setUnderlineWidth(UnderlineWidth); TmpCharStyle.setStrikethruOffset(StrikethruOffset); TmpCharStyle.setStrikethruWidth(StrikethruWidth); TmpCharStyle.setScaleH(ScaleH * 1000); TmpCharStyle.setScaleV(ScaleV * 1000); TmpCharStyle.setTracking(Tracking); TmpCharStyle.setLanguage(QString(Language)); StyleSet<CharStyle> TmpStyleSet; TmpStyleSet.create(TmpCharStyle); ScCore->primaryMainWindow()->doc->redefineCharStyles(TmpStyleSet, false); // PV - refresh the Style Manager window. // I thought that this can work but it doesn't: // ScCore->primaryMainWindow()->styleMgr()->reloadStyleView(); // So the brute force setDoc is called... ScCore->primaryMainWindow()->styleMgr()->setDoc(ScCore->primaryMainWindow()->doc); Py_RETURN_NONE; }
void SearchReplace::slotDoReplace() { if (m_itemMode) { QString repl, sear; int cs, cx; int textLen = 0; if (RText->isChecked()) { repl = RTextVal->text(); sear = STextVal->text(); textLen = m_item->itemText.lengthOfSelection(); if (textLen == repl.length()) { for (cs = 0; cs < textLen; ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); } else { if (textLen < repl.length()) { for (cs = 0; cs < textLen; ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); for (cx = cs; cx < repl.length(); ++cx) m_item->itemText.insertChars(m_replStart+cx, repl.mid(cx,1), true); } else { for (cs = 0; cs < repl.length(); ++cs) m_item->itemText.replaceChar(m_replStart+cs, repl[cs]); m_item->itemText.removeChars(m_replStart+cs, textLen - cs); } } m_item->itemText.deselectAll(); if (repl.length() > 0) { m_item->itemText.select(m_replStart, repl.length()); m_item->itemText.setCursorPosition(m_replStart + repl.length()); } } if (RStyle->isChecked()) { int oldMode = m_doc->appMode; m_doc->appMode = modeEdit; m_doc->itemSelection_SetNamedParagraphStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name()); m_doc->appMode = oldMode; } if (RAlign->isChecked()) { int oldMode = m_doc->appMode; m_doc->appMode = modeEdit; m_doc->itemSelection_SetAlignment(RAlignVal->currentIndex()); m_doc->appMode = oldMode; } if (RFill->isChecked()) m_doc->itemSelection_SetFillColor(RFillVal->currentText()); if (RFillS->isChecked()) m_doc->itemSelection_SetFillShade(RFillSVal->getValue()); if (RStroke->isChecked()) m_doc->itemSelection_SetStrokeColor(RStrokeVal->currentText()); if (RStrokeS->isChecked()) m_doc->itemSelection_SetStrokeShade(RStrokeSVal->getValue()); if (RFont->isChecked()) m_doc->itemSelection_SetFont(RFontVal->currentText()); if (RSize->isChecked()) m_doc->itemSelection_SetFontSize(qRound(RSizeVal->value() * 10.0)); if (REffect->isChecked() && (m_item->itemText.lengthOfSelection() > 0)) { int s = REffVal->getStyle() & ScStyle_UserStyles; m_doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(s).featureList()); // ??? for (int a = 0; a < m_item->itemText.length(); ++a) { if (m_item->itemText.selected(a)) { // StyleFlag fl = m_item->itemText.charStyle(a).effects(); // fl &= static_cast<StyleFlag>(~1919); // fl |= static_cast<StyleFlag>(s); // m_item->itemText.item(a)->setFeatures(fl.featureList()); CharStyle newFeatures; newFeatures.setFeatures(static_cast<StyleFlag>(s).featureList()); m_item->itemText.applyCharStyle(a, 1, newFeatures); } } } m_item->itemText.deselectAll(); } else if (m_doc->scMW()->CurrStED != NULL) { StoryEditor* se = m_doc->scMW()->CurrStED; if (RText->isChecked()) { disconnect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps())); int SelStart = se->Editor->textCursor().selectionStart(); int SelEnd = se->Editor->textCursor().selectionEnd(); // se->Editor->insChars(RTextVal->text()); se->Editor->textCursor().setPosition(SelStart); se->Editor->textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor); se->Editor->textCursor().removeSelectedText(); //FIXME se->Editor->setEffects(se->Editor->CurrentEffects); QString newText = RTextVal->text(); se->Editor->insertPlainText(newText); if (newText.length() > 0) { QTextCursor textCursor = se->Editor->textCursor(); textCursor.setPosition(SelStart); textCursor.setPosition(SelStart + newText.length(), QTextCursor::KeepAnchor); se->Editor->setTextCursor(textCursor); } connect(se->Editor, SIGNAL(cursorPositionChanged()), se, SLOT(updateProps())); // se->newAlign(se->Editor->currentParaStyle); } if (RStyle->isChecked()) se->newStyle(m_doc->paragraphStyles()[RStyleVal->currentIndex()].name()); if (RAlign->isChecked()) se->newAlign(RAlignVal->currentIndex()); if (RFill->isChecked()) se->newTxFill(RFillVal->currentIndex(), -1); if (RFillS->isChecked()) se->newTxFill(-1, RFillSVal->getValue()); if (RStroke->isChecked()) se->newTxStroke(RStrokeVal->currentIndex(), -1); if (RStrokeS->isChecked()) se->newTxStroke(-1, RStrokeSVal->getValue()); if (RFont->isChecked()) se->newTxFont(RFontVal->currentText()); if (RSize->isChecked()) se->newTxSize(RSizeVal->value()); if (REffect->isChecked()) se->newTxStyle(REffVal->getStyle()); QTextCursor textCursor = se->Editor->textCursor(); int selStart = textCursor.selectionStart(); int selEnd = textCursor.selectionEnd(); int selPos = qMax(selStart, selEnd); textCursor.setPosition(selPos); se->Editor->setTextCursor(textCursor); } DoReplace->setEnabled(false); AllReplace->setEnabled(false); slotDoSearch(); }