View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000579 | Scribus | Styles | public | 2004-05-02 19:24 | 2019-11-08 06:26 |
Reporter | linuxlingam | Assigned To | ale | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | assigned | Resolution | open | ||
Platform | AthlonXP | OS | Fedora | OS Version | Core 1 |
Product Version | 1.3 | ||||
Summary | 0000579: [PATCH] right-click paragraph, save as paragraph style | ||||
Description | typesetting for body, headline, etc, usually done by hand initially. so once done, wanna right-click and save it as a paragraph style. should prompt for name. | ||||
Tags | #rottenpatch, discussion | ||||
Patch | Yes | ||||
|
To be considered with 1.3+ |
|
Should also be available for other styles, if possible. |
|
I take this opportunity to explain further what I have in mind when I talk about a button named "Create style". While it is very efficient to test various type settings from the PP and immediately see the result in the real text frame of your job (as opposed to the sample text that is in the Edit > Paragraph Styles dialog) it is clumsy to have to go to the Edit > Paragraph Styles dialog to enter again those values when you're satisfied with the result and want that as a Style. The trip to this dialog is time consuming and not very efficient. What I suggest is this button that would allow to immediately create a Style from the settings of the PP (provided as mentionned in an earlier bug report that we harmonize the PP and the Edit > Par Styles dialog). Once hit, we would be offered a small dialog asking for a Style Name and a Keyboard Shortcut (as an option) and voilĂ ! I sincerely think this would be a great plus for productivity and creationness! Not a gadget, a real plus in the PP. Consider the fact that afaik Scribus is alone in its category to allow such mousewheel settings combined with ctrl and shift keys to make the finest settings at your fingertip, including changing fonts, typesize, linespacing, kerning... etc. Given all those goodies that are really super-efficient, I am incline to think that a "Create Style" button would be in fact the cherry on the cake, the final touch to the text tab in the PP! Am I too enthusiastic? |
|
I completely stand by what I was writing. I agree with the poster that we need that. That was back in 2004, May 2. Wow! I wonder how difficult is it to implement since we have all the settings available. We only want a button, or a right-click, with a dialog so small... prompt for a name and a keyboard shortcut. |
|
style_from_cpos.patch (12,081 bytes)
Index: scribus/scribus.cpp =================================================================== --- scribus/scribus.cpp (wersja 16619) +++ scribus/scribus.cpp (kopia robocza) @@ -212,6 +212,7 @@ #include "util_ghostscript.h" #include "util_icon.h" #include "util_math.h" +#include "util_text.h" #include "vruler.h" #include "loadsaveplugin.h" @@ -7447,6 +7448,60 @@ } } +void ScribusMainWindow::setPStyleCPos() +{ + PageItem *currItem = doc->m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(doc->currentStyle); + newStyle.setName(getUniquePStyleName(doc, newStyle.parent())); + bool ok=false; + while (!ok) + { + QString newPSname = QInputDialog::getText(this, tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newStyle.name(), &ok); + if (ok) + { + QString uniqueName = getUniquePStyleName(doc, newPSname); + newStyle.setName(uniqueName); + if (uniqueName != newPSname) + ok = false; + } + else + return; + } + tmpStyles_.create(newStyle); + doc->redefineStyles(tmpStyles_); + doc->changed(); + styleMgr()->setDoc(doc); + propertiesPalette->paraStyleCombo->updateFormatList(); +} + +void ScribusMainWindow::updatePStyleCPos() +{ + PageItem *currItem = doc->m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(doc->currentStyle); + newStyle.setName(newStyle.parent()); + tmpStyles_.create(newStyle); + doc->redefineStyles(tmpStyles_); + doc->changed(); + doc->view()->DrawNew(); + styleMgr()->setDoc(doc); +} + void ScribusMainWindow::setNewCharStyle(const QString& name) { if (HaveDoc) @@ -7466,7 +7521,66 @@ setTBvals(currItem); } } +void ScribusMainWindow::setChStyleCPos() +{ + PageItem *currItem = doc->m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + StyleSet<CharStyle> tmpStyles_; + CharStyle newStyle; + newStyle.setStyle(doc->currentStyle.charStyle()); + newStyle.setName(getUniqueChStyleName(doc, newStyle.parent())); + bool ok=false; + while (!ok) + { + QString newChSname = QInputDialog::getText(this, tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newStyle.name(), &ok); + if (ok) + { + QString uniqueName = getUniqueChStyleName(doc, newChSname); + newStyle.setName(uniqueName); + if (uniqueName != newChSname) + ok = false; + } + else + return; + } + tmpStyles_.create(newStyle); + doc->redefineCharStyles(tmpStyles_); + doc->changed(); + styleMgr()->setDoc(doc); + propertiesPalette->charStyleCombo->updateFormatList(); +} + +void ScribusMainWindow::updateChStyleCPos() +{ + PageItem *currItem = doc->m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + CharStyle newStyle; + newStyle.setStyle(doc->currentStyle.charStyle()); + newStyle.setName(newStyle.parent()); + + if (findCharStyle(doc, newStyle.name()) == -1) + setChStyleCPos(); + else + { + StyleSet<CharStyle> tmpStyles_; + tmpStyles_.create(newStyle); + doc->redefineCharStyles(tmpStyles_); + doc->changed(); + doc->view()->DrawNew(); + styleMgr()->setDoc(doc); + } +} + void ScribusMainWindow::setAbsValue(int a) { // doc->currentStyle = doc->docParagraphStyles[a]; Index: scribus/util_text.cpp =================================================================== --- scribus/util_text.cpp (wersja 16619) +++ scribus/util_text.cpp (kopia robocza) @@ -50,3 +50,63 @@ assert(false); return -1; } + +int findCharStyle(ScribusDoc* doc, const QString &name) +{ + for (int i=0; i < doc->charStyles().count(); ++i) + { + if (name == doc->charStyles()[i].name()) { + return i; + } + } + assert(false); + return -1; +} + +QString getUniquePStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->paragraphStyles().count(); ++i) + { + if (doc->paragraphStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} + +QString getUniqueChStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->charStyles().count(); ++i) + { + if (doc->charStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} Index: scribus/util_text.h =================================================================== --- scribus/util_text.h (wersja 16619) +++ scribus/util_text.h (kopia robocza) @@ -13,12 +13,16 @@ #include "styles/charstyle.h" #include "styles/paragraphstyle.h" #include "scribusapi.h" +#include <QString> class ScribusDoc; #ifndef NLS_CONFORMANCE int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle); int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name); +int SCRIBUS_API findCharStyle(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniquePStyleName(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniqueChStyleName(ScribusDoc* doc, const QString &name); #endif Index: scribus/actionmanager.cpp =================================================================== --- scribus/actionmanager.cpp (wersja 16619) +++ scribus/actionmanager.cpp (kopia robocza) @@ -474,6 +474,15 @@ name="itemConvertToTextFrame"; scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + connect( (*scrActions)["itemDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItem()) ); connect( (*scrActions)["itemMulDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItemMulti()) ); connect( (*scrActions)["itemGroup"], SIGNAL(triggered()), mainWindow, SLOT(GroupObj()) ); @@ -485,6 +494,11 @@ connect( (*scrActions)["itemAttributes"], SIGNAL(triggered()), mainWindow, SLOT(objectAttributes()) ); connect( (*scrActions)["itemShapeEdit"], SIGNAL(triggered()), mainWindow, SLOT(toggleNodeEdit()) ); connect( (*scrActions)["itemImageInfo"], SIGNAL(triggered()), mainWindow, SLOT(getImageInfo()) ); + + connect( (*scrActions)["itemPStyleFromTextNew"], SIGNAL(triggered()), mainWindow, SLOT(setPStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextUpdate"], SIGNAL(triggered()), mainWindow, SLOT(updatePStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextNew"], SIGNAL(triggered()), mainWindow, SLOT(setChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextUpdate"], SIGNAL(triggered()), mainWindow, SLOT(updateChStyleCPos()) ); } void ActionManager::initInsertMenuActions() @@ -1383,6 +1397,10 @@ (*scrActions)["itemConvertToOutlines"]->setTexts( tr("&Outlines", "Convert to oulines")); (*scrActions)["itemConvertToPolygon"]->setTexts( tr("&Polygon")); (*scrActions)["itemConvertToTextFrame"]->setTexts( tr("&Text Frame")); + (*scrActions)["itemPStyleFromTextNew"]->setTexts( tr("Create paragraph style with style at cursor position")); + (*scrActions)["itemPStyleFromTextUpdate"]->setTexts( tr("Update paragraph style with style at cursor position")); + (*scrActions)["itemChStyleFromTextNew"]->setTexts( tr("Create character style with style at cursor position")); + (*scrActions)["itemChStyleFromTextUpdate"]->setTexts( tr("Update character style with style at cursor position")); //Insert Menu (*scrActions)["insertFrame"]->setTexts( tr("&Frame...")); @@ -1764,7 +1782,7 @@ itmenu->second << "typeEffectNormal" << "typeEffectUnderline" << "typeEffectUnderlineWords" << "typeEffectStrikeThrough" << "typeEffectAllCaps" << "typeEffectSmallCaps" << "typeEffectSuperscript" << "typeEffectSubscript" << "typeEffectOutline" << "typeEffectShadow" << "styleImageEffects" << "styleTabulators"; //Item ++itmenu; - itmenu->second << "itemDuplicate" << "itemMulDuplicate" << "itemDelete" << "itemGroup" << "itemUngroup" << "itemLock" << "itemLockSize" << "itemImageIsVisible" << "itemUpdateImage" << "itemAdjustFrameToImage" << "itemAdjustImageToFrame" << "itemExtendedImageProperties" << "itemPreviewLow" << "itemPreviewNormal" << "itemPreviewFull" << "itemRaise" << "itemLower" << "itemRaiseToTop" << "itemLowerToBottom" << "itemSendToPattern" << "itemAttributes" << "itemPDFIsAnnotation" << "itemPDFIsBookmark" << "itemPDFAnnotationProps" << "itemPDFFieldProps" << "itemShapeEdit" << "itemConvertToBezierCurve" << "itemConvertToImageFrame" << "itemConvertToOutlines" << "itemConvertToPolygon" << "itemConvertToTextFrame" << "itemAttachTextToPath" << "itemDetachTextFromPath" << "itemCombinePolygons" << "itemSplitPolygons"; + itmenu->second << "itemDuplicate" << "itemMulDuplicate" << "itemDelete" << "itemGroup" << "itemUngroup" << "itemLock" << "itemLockSize" << "itemImageIsVisible" << "itemUpdateImage" << "itemAdjustFrameToImage" << "itemAdjustImageToFrame" << "itemExtendedImageProperties" << "itemPreviewLow" << "itemPreviewNormal" << "itemPreviewFull" << "itemRaise" << "itemLower" << "itemRaiseToTop" << "itemLowerToBottom" << "itemSendToPattern" << "itemAttributes" << "itemPDFIsAnnotation" << "itemPDFIsBookmark" << "itemPDFAnnotationProps" << "itemPDFFieldProps" << "itemShapeEdit" << "itemConvertToBezierCurve" << "itemConvertToImageFrame" << "itemConvertToOutlines" << "itemConvertToPolygon" << "itemConvertToTextFrame" << "itemAttachTextToPath" << "itemDetachTextFromPath" << "itemCombinePolygons" << "itemSplitPolygons" << "itemPStyleFromTextNew" << "itemPStyleFromTextUpdate" << "itemChStyleFromTextNew" << "itemChStyleFromTextUpdate"; //Insert ++itmenu; itmenu->second Index: scribus/scribus.h =================================================================== --- scribus/scribus.h (wersja 16619) +++ scribus/scribus.h (kopia robocza) @@ -485,7 +485,11 @@ // void saveStyles(StilFormate *dia); //still required for style save from SE void setNewAlignment(int a); void setNewParStyle(const QString& name); + void setPStyleCPos(); + void updatePStyleCPos(); void setNewCharStyle(const QString& name); + void setChStyleCPos(); + void updateChStyleCPos(); void setAbsValue(int a); void selectItemsFromOutlines(PageItem *ite); void selectItemsFromOutlines(int Page, int Item, bool single = false); Index: scribus/contextmenu.cpp =================================================================== --- scribus/contextmenu.cpp (wersja 16619) +++ scribus/contextmenu.cpp (kopia robocza) @@ -174,6 +174,13 @@ addSeparator(); addAction(m_AP->scrActions["toolsEditWithStoryEditor"]); } + if (currItem->asTextFrame()) + { + addAction(m_AP->scrActions["itemPStyleFromTextNew"]); + addAction(m_AP->scrActions["itemPStyleFromTextUpdate"]); + addAction(m_AP->scrActions["itemChStyleFromTextNew"]); + addAction(m_AP->scrActions["itemChStyleFromTextUpdate"]); + } addSeparator(); if (m_actionList.contains("fileImportImage")) addAction(m_AP->scrActions["fileImportImage"]); |
|
My patch solving this issue, I hope... |
|
My initial concerns with this lie with the code added to the ScribusMainWindow.. I will review and see if we can get that out of there (we want to remove all function document code from the main window) |
|
Tell me where and I will move it for you... |
|
Looking again, I think they should at least be in ScribusDoc, at least, it is a better place than the main window. You can connect actions dynamically to the doc.. see actionmanager.cpp and functions like connectNewSelectionActions() |
|
basically: it works :-) just one thing: the labels in the context menu are too long... i would create one single context menu with submenus style > create from selection (paragraph) update from selection (paragraph) create from selection (character) update from selection (character) i'm still not really happy... i wonder it would not be better to have a button "from selection" in the style manager... or adding it to the PP... i guess i'll ask claudia if she has better ideas! |
|
In PP ok, but invoking style manager for such simply task is against rule "smallest number of clicks". For me context menu is good place, maybe all these entries should be in submenu "Styles" in there. |
|
style_from_cpos_v2.patch (13,331 bytes)
Index: scribus/util_text.cpp =================================================================== --- scribus/util_text.cpp (wersja 16619) +++ scribus/util_text.cpp (kopia robocza) @@ -50,3 +50,63 @@ assert(false); return -1; } + +int findCharStyle(ScribusDoc* doc, const QString &name) +{ + for (int i=0; i < doc->charStyles().count(); ++i) + { + if (name == doc->charStyles()[i].name()) { + return i; + } + } + assert(false); + return -1; +} + +QString getUniquePStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->paragraphStyles().count(); ++i) + { + if (doc->paragraphStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} + +QString getUniqueChStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->charStyles().count(); ++i) + { + if (doc->charStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} Index: scribus/util_text.h =================================================================== --- scribus/util_text.h (wersja 16619) +++ scribus/util_text.h (kopia robocza) @@ -13,12 +13,16 @@ #include "styles/charstyle.h" #include "styles/paragraphstyle.h" #include "scribusapi.h" +#include <QString> class ScribusDoc; #ifndef NLS_CONFORMANCE int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle); int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name); +int SCRIBUS_API findCharStyle(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniquePStyleName(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniqueChStyleName(ScribusDoc* doc, const QString &name); #endif Index: scribus/scribusdoc.cpp =================================================================== --- scribus/scribusdoc.cpp (wersja 16626) +++ scribus/scribusdoc.cpp (kopia robocza) @@ -35,6 +35,7 @@ #include <QPainter> #include <QPixmap> #include <QProgressBar> +#include <QInputDialog> #include "canvas.h" #include "cmserrorhandling.h" @@ -62,6 +63,7 @@ #include "pagestructs.h" #include "prefsfile.h" #include "prefsmanager.h" +#include "propertiespalette.h" #include "resourcecollection.h" #include "sccolorengine.h" #include "scmessagebox.h" @@ -77,6 +79,7 @@ #include "selection.h" #include "serializer.h" #include "storyeditor.h" +#include "stylemanager.h" #include "text/nlsconfig.h" #include "undomanager.h" #include "undostate.h" @@ -84,9 +87,9 @@ #include "util.h" #include "util_icon.h" #include "util_math.h" +#include "util_text.h" - // static const bool FRAMESELECTION_EDITS_DEFAULTSTYLE = false; @@ -1219,7 +1222,164 @@ } } +void ScribusDoc::setPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(currentStyle); + newStyle.setName(getUniquePStyleName(this, newStyle.parent())); + bool ok=false; + while (!ok) + { + QString newPSname = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newStyle.name(), &ok); + if (ok) + { + QString uniqueName = getUniquePStyleName(this, newPSname); + newStyle.setName(uniqueName); + // name was changed, let user decide it is good for him + if (uniqueName != newPSname) + ok = false; + } + else + return; + } + tmpStyles_.create(newStyle); + redefineStyles(tmpStyles_); + changed(); + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); +} + +void ScribusDoc::updatePStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(currentStyle); + newStyle.setName(newStyle.parent()); + tmpStyles_.create(newStyle); + redefineStyles(tmpStyles_); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + +void ScribusDoc::defaultPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(currentStyle); + newStyle.setName(CommonStrings::DefaultParagraphStyle); + newStyle.setDefaultStyle(true); + + tmpStyles_.create(newStyle); + redefineStyles(tmpStyles_); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + +void ScribusDoc::setChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + StyleSet<CharStyle> tmpStyles_; + CharStyle newStyle; + newStyle.setStyle(currentStyle.charStyle()); + newStyle.setName(getUniqueChStyleName(this, newStyle.parent())); + bool ok=false; + while (!ok) + { + QString newChSname = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newStyle.name(), &ok); + if (ok) + { + QString uniqueName = getUniqueChStyleName(this, newChSname); + newStyle.setName(uniqueName); + // name was changed, let user decide it is good for him + if (uniqueName != newChSname) + ok = false; + } + else + return; + } + tmpStyles_.create(newStyle); + redefineCharStyles(tmpStyles_); + changed(); + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); +} + +void ScribusDoc::updateChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + CharStyle newStyle; + newStyle.setStyle(currentStyle.charStyle()); + newStyle.setName(newStyle.parent()); + + if (findCharStyle(this, newStyle.name()) == -1) + setChStyleCPos(); + else + { + StyleSet<CharStyle> tmpStyles_; + tmpStyles_.create(newStyle); + redefineCharStyles(tmpStyles_); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); + } +} + +void ScribusDoc::defaultChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + CharStyle newStyle; + newStyle.setStyle(currentStyle.charStyle()); + newStyle.setName(CommonStrings::DefaultCharacterStyle); + newStyle.setDefaultStyle(true); + + StyleSet<CharStyle> tmpStyles_; + tmpStyles_.create(newStyle); + redefineCharStyles(tmpStyles_); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + void ScribusDoc::lockGuides(bool isLocked) { if (GuideLock == isLocked) Index: scribus/scribusdoc.h =================================================================== --- scribus/scribusdoc.h (wersja 16619) +++ scribus/scribusdoc.h (kopia robocza) @@ -1232,6 +1232,17 @@ void updatePict(QString name); void updatePictDir(QString name); void removePict(QString name); + + /** + * @brief Create or update par/char styles by current style at cursor position + * @param or from frame current style if not in edit mode + */ + void setPStyleCPos(); + void updatePStyleCPos(); + void defaultPStyleCPos(); + void setChStyleCPos(); + void updateChStyleCPos(); + void defaultChStyleCPos(); }; Q_DECLARE_METATYPE(ScribusDoc*); Index: scribus/actionmanager.cpp =================================================================== --- scribus/actionmanager.cpp (wersja 16619) +++ scribus/actionmanager.cpp (kopia robocza) @@ -474,6 +474,19 @@ name="itemConvertToTextFrame"; scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + connect( (*scrActions)["itemDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItem()) ); connect( (*scrActions)["itemMulDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItemMulti()) ); connect( (*scrActions)["itemGroup"], SIGNAL(triggered()), mainWindow, SLOT(GroupObj()) ); @@ -1048,7 +1061,12 @@ disconnect( (*scrActions)["itemDelete"], 0, 0, 0); disconnect( (*scrActions)["extrasHyphenateText"], 0, 0, 0 ); disconnect( (*scrActions)["extrasDeHyphenateText"], 0, 0, 0 ); - + disconnect( (*scrActions)["itemPStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextSaveDefault"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextSaveDefault"], 0, 0, 0 ); } void ActionManager::connectNewDocActions(ScribusDoc *currDoc) @@ -1068,6 +1086,12 @@ connect( (*scrActions)["itemDelete"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_DeleteItem()) ); connect( (*scrActions)["itemAdjustFrameToImage"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrametoImageSize()) ); connect( (*scrActions)["itemAdjustImageToFrame"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustImagetoFrameSize()) ); + connect( (*scrActions)["itemPStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setPStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updatePStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultPStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updateChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultChStyleCPos()) ); } void ActionManager::disconnectNewViewActions() @@ -1383,6 +1407,12 @@ (*scrActions)["itemConvertToOutlines"]->setTexts( tr("&Outlines", "Convert to oulines")); (*scrActions)["itemConvertToPolygon"]->setTexts( tr("&Polygon")); (*scrActions)["itemConvertToTextFrame"]->setTexts( tr("&Text Frame")); + (*scrActions)["itemPStyleFromTextNew"]->setTexts( tr("Create paragraph style")); + (*scrActions)["itemPStyleFromTextUpdate"]->setTexts( tr("Update paragraph style")); + (*scrActions)["itemPStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Paragraph Style")); + (*scrActions)["itemChStyleFromTextNew"]->setTexts( tr("Create character style")); + (*scrActions)["itemChStyleFromTextUpdate"]->setTexts( tr("Update character style")); + (*scrActions)["itemChStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Character Style")); //Insert Menu (*scrActions)["insertFrame"]->setTexts( tr("&Frame...")); Index: scribus/contextmenu.cpp =================================================================== --- scribus/contextmenu.cpp (wersja 16619) +++ scribus/contextmenu.cpp (kopia robocza) @@ -90,6 +90,7 @@ QMenu *menuLevel = new QMenu(this); QMenu *menuPDF = new QMenu(this); QMenu *menuResolution = new QMenu(this); + QMenu *menuStyles = new QMenu(this); //<-- Add Info //Test new method with image frames first @@ -174,6 +175,17 @@ addSeparator(); addAction(m_AP->scrActions["toolsEditWithStoryEditor"]); } + if (currItem->asTextFrame()) + { + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextSaveDefault"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextSaveDefault"]); + QAction *act = addMenu(menuStyles); + act->setText( ScribusView::tr("Styles from selection")); + } addSeparator(); if (m_actionList.contains("fileImportImage")) addAction(m_AP->scrActions["fileImportImage"]); |
|
New version of my patch - functions moved into ScribusDoc as cbradney was suggesting - in UI all functions are in submenu "Styles from selection" in context menu - add function for saving current style as Default Paragraph/Character Style Remember to add option -l (small L) while applying my patches (QtCreator has problem with spaces and tabs) |
|
Cezary.. looks good, I think.. I guess my next observation is.. how does this run programmatically, or via scripter or headless.. void ScribusDoc::setChStyleCPos() calls for GUI interaction. Perhaps such functions could take a string paramter for the name if the GUI is not in use.. or to force a name (and if a duplicate, then just append _s until it is unique or similar).. I am asking Jean to review too |
|
It calls GUI interaction because styles name changes need update in PP and SM. Maybe it should be splited into function for headless operation and separately into function for GUI updates. I will try to do it... And done in v3... |
|
style_from_cpos_v3.patch (12,961 bytes)
Index: scribus/util_text.cpp =================================================================== --- scribus/util_text.cpp (wersja 16619) +++ scribus/util_text.cpp (kopia robocza) @@ -50,3 +50,63 @@ assert(false); return -1; } + +int findCharStyle(ScribusDoc* doc, const QString &name) +{ + for (int i=0; i < doc->charStyles().count(); ++i) + { + if (name == doc->charStyles()[i].name()) { + return i; + } + } + assert(false); + return -1; +} + +QString getUniquePStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->paragraphStyles().count(); ++i) + { + if (doc->paragraphStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} + +QString getUniqueChStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->charStyles().count(); ++i) + { + if (doc->charStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} Index: scribus/util_text.h =================================================================== --- scribus/util_text.h (wersja 16619) +++ scribus/util_text.h (kopia robocza) @@ -13,12 +13,16 @@ #include "styles/charstyle.h" #include "styles/paragraphstyle.h" #include "scribusapi.h" +#include <QString> class ScribusDoc; #ifndef NLS_CONFORMANCE int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle); int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name); +int SCRIBUS_API findCharStyle(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniquePStyleName(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniqueChStyleName(ScribusDoc* doc, const QString &name); #endif Index: scribus/scribusdoc.cpp =================================================================== --- scribus/scribusdoc.cpp (wersja 16626) +++ scribus/scribusdoc.cpp (kopia robocza) @@ -35,6 +35,7 @@ #include <QPainter> #include <QPixmap> #include <QProgressBar> +#include <QInputDialog> #include "canvas.h" #include "cmserrorhandling.h" @@ -62,6 +63,7 @@ #include "pagestructs.h" #include "prefsfile.h" #include "prefsmanager.h" +#include "propertiespalette.h" #include "resourcecollection.h" #include "sccolorengine.h" #include "scmessagebox.h" @@ -77,6 +79,7 @@ #include "selection.h" #include "serializer.h" #include "storyeditor.h" +#include "stylemanager.h" #include "text/nlsconfig.h" #include "undomanager.h" #include "undostate.h" @@ -84,9 +87,9 @@ #include "util.h" #include "util_icon.h" #include "util_math.h" +#include "util_text.h" - // static const bool FRAMESELECTION_EDITS_DEFAULTSTYLE = false; @@ -1219,7 +1222,147 @@ } } +void ScribusDoc::PStyleFromStyle(QString newName, ParagraphStyle currStyle, bool defStyle) +{ + StyleSet<ParagraphStyle> tmpStyles_; + ParagraphStyle newStyle; + newStyle.setStyle(currStyle); + newStyle.setName(newName); + if (defStyle) + newStyle.setDefaultStyle(true); + tmpStyles_.create(newStyle); + redefineStyles(tmpStyles_); +} +void ScribusDoc::setPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + QString newName = getUniquePStyleName(this, currentStyle.parent()); + bool ok=false; + while (!ok) + { + newName = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newName, &ok); + if (ok) + { + QString newName2 = getUniquePStyleName(this, newName); + // name was changed, let user decide it is good for him + if (newName2 != newName) + ok = false; + newName = newName2; + } + else + return; + } + PStyleFromStyle(newName, currentStyle); + changed(); + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); +} + +void ScribusDoc::updatePStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + PStyleFromStyle(currentStyle.parent(), currentStyle); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + +void ScribusDoc::defaultPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + PStyleFromStyle(CommonStrings::DefaultParagraphStyle, currentStyle, true); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + +void ScribusDoc::ChStyleFromStyle(QString newName, CharStyle currStyle, bool defStyle) +{ + StyleSet<CharStyle> tmpStyles_; + CharStyle newStyle; + newStyle.setStyle(currStyle); + newStyle.setName(newName); + if (defStyle) + newStyle.setDefaultStyle(true); + tmpStyles_.create(newStyle); + redefineCharStyles(tmpStyles_); +} + +void ScribusDoc::setChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + QString newName = getUniqueChStyleName(this, currentStyle.charStyle().parent()); + bool ok=false; + while (!ok) + { + newName = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newName, &ok); + if (ok) + { + QString newName2 = getUniquePStyleName(this, newName); + // name was changed, let user decide it is good for him + if (newName2 != newName) + ok = false; + newName = newName2; + } + else + return; + } + ChStyleFromStyle(newName, currentStyle.charStyle()); + changed(); + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); +} + +void ScribusDoc::updateChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + + ChStyleFromStyle(currentStyle.charStyle().parent(), currentStyle.charStyle()); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + +void ScribusDoc::defaultChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->CPos >= currItem->itemText.length()) + return; + ChStyleFromStyle(CommonStrings::DefaultCharacterStyle, currentStyle.charStyle(), true); + changed(); + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); +} + void ScribusDoc::lockGuides(bool isLocked) { if (GuideLock == isLocked) Index: scribus/scribusdoc.h =================================================================== --- scribus/scribusdoc.h (wersja 16619) +++ scribus/scribusdoc.h (kopia robocza) @@ -1232,6 +1232,21 @@ void updatePict(QString name); void updatePictDir(QString name); void removePict(QString name); + + /** + * @brief Create or update par/char styles by current style at cursor position + * @param or from frame current style if not in edit mode + */ + void setPStyleCPos(); + void updatePStyleCPos(); + void defaultPStyleCPos(); + void setChStyleCPos(); + void updateChStyleCPos(); + void defaultChStyleCPos(); + /** functions for creating or update styles without GUI interaction */ + void PStyleFromStyle(QString, ParagraphStyle, bool defStyle=false); + void ChStyleFromStyle(QString, CharStyle, bool defStyle=false); + }; Q_DECLARE_METATYPE(ScribusDoc*); Index: scribus/actionmanager.cpp =================================================================== --- scribus/actionmanager.cpp (wersja 16619) +++ scribus/actionmanager.cpp (kopia robocza) @@ -474,6 +474,19 @@ name="itemConvertToTextFrame"; scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + connect( (*scrActions)["itemDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItem()) ); connect( (*scrActions)["itemMulDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItemMulti()) ); connect( (*scrActions)["itemGroup"], SIGNAL(triggered()), mainWindow, SLOT(GroupObj()) ); @@ -1048,7 +1061,12 @@ disconnect( (*scrActions)["itemDelete"], 0, 0, 0); disconnect( (*scrActions)["extrasHyphenateText"], 0, 0, 0 ); disconnect( (*scrActions)["extrasDeHyphenateText"], 0, 0, 0 ); - + disconnect( (*scrActions)["itemPStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextSaveDefault"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextSaveDefault"], 0, 0, 0 ); } void ActionManager::connectNewDocActions(ScribusDoc *currDoc) @@ -1068,6 +1086,12 @@ connect( (*scrActions)["itemDelete"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_DeleteItem()) ); connect( (*scrActions)["itemAdjustFrameToImage"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrametoImageSize()) ); connect( (*scrActions)["itemAdjustImageToFrame"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustImagetoFrameSize()) ); + connect( (*scrActions)["itemPStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setPStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updatePStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultPStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updateChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultChStyleCPos()) ); } void ActionManager::disconnectNewViewActions() @@ -1383,6 +1407,12 @@ (*scrActions)["itemConvertToOutlines"]->setTexts( tr("&Outlines", "Convert to oulines")); (*scrActions)["itemConvertToPolygon"]->setTexts( tr("&Polygon")); (*scrActions)["itemConvertToTextFrame"]->setTexts( tr("&Text Frame")); + (*scrActions)["itemPStyleFromTextNew"]->setTexts( tr("Create paragraph style")); + (*scrActions)["itemPStyleFromTextUpdate"]->setTexts( tr("Update paragraph style")); + (*scrActions)["itemPStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Paragraph Style")); + (*scrActions)["itemChStyleFromTextNew"]->setTexts( tr("Create character style")); + (*scrActions)["itemChStyleFromTextUpdate"]->setTexts( tr("Update character style")); + (*scrActions)["itemChStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Character Style")); //Insert Menu (*scrActions)["insertFrame"]->setTexts( tr("&Frame...")); Index: scribus/contextmenu.cpp =================================================================== --- scribus/contextmenu.cpp (wersja 16619) +++ scribus/contextmenu.cpp (kopia robocza) @@ -90,6 +90,7 @@ QMenu *menuLevel = new QMenu(this); QMenu *menuPDF = new QMenu(this); QMenu *menuResolution = new QMenu(this); + QMenu *menuStyles = new QMenu(this); //<-- Add Info //Test new method with image frames first @@ -174,6 +175,18 @@ addSeparator(); addAction(m_AP->scrActions["toolsEditWithStoryEditor"]); } + if (currItem->asTextFrame()) + { + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextSaveDefault"]); + menuStyles->addSeparator(); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextSaveDefault"]); + QAction *act = addMenu(menuStyles); + act->setText( ScribusView::tr("Style from selection")); + } addSeparator(); if (m_actionList.contains("fileImportImage")) addAction(m_AP->scrActions["fileImportImage"]); |
|
This feature would be gold. "typesetting for body, headline, etc, usually done by hand initially. so once done, wanna right-click and save it as a paragraph style. should prompt for name." +1 |
|
stefanm, just apply the patches, test it and give feedback... |
|
@ale patching didnt work, dont know why: hunk errors etc. I checked out svn trunk and 2 older working copies from within QT Creator and tried patch -p1 < style_from_cpos_v3.patch |
|
Adding -l (small L) option may help, but major problem is that in the meantime CPos field of PageItem is no longer used, and patch need refactoring it to itemText->cursorPosition() method. When I end current work I try to prepare new version of patch for latest revisions. |
|
use the "-l" parameter for patch (this is an el and not an one...) |
|
@cezaryece Is a patch available for testing? |
|
and what about that patch commit? |
|
@cezaryece I see only patches from May here, in (0026529) you said "When I end current work I try to prepare new version of patch for latest revisions." I'm waiting patiently :-) Thank you very much for your work with scribus. |
|
ups.. my fault... will try today what I promise |
|
stylesFromCPos.patch (17,344 bytes)
Index: scribus/styles/charstyle.cpp =================================================================== --- scribus/styles/charstyle.cpp (wersja 17211) +++ scribus/styles/charstyle.cpp (kopia robocza) @@ -409,6 +407,17 @@ updateFeatures(); } +void CharStyle::updateAttr(const CharStyle& other) +{ +#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \ + inh_##attr_NAME = other.inh_##attr_NAME; \ + m_##attr_NAME = other.m_##attr_NAME; +#include "charstyle.attrdefs.cxx" +#undef ATTRDEF + updateFeatures(); +} + + void CharStyle::getNamedResources(ResourceCollection& lists) const { for (const Style* sty = parentStyle(); sty != NULL; sty = sty->parentStyle()) Index: scribus/styles/charstyle.h =================================================================== --- scribus/styles/charstyle.h (wersja 17211) +++ scribus/styles/charstyle.h (kopia robocza) @@ -137,6 +137,7 @@ void applyCharStyle(const CharStyle & other); void eraseCharStyle(const CharStyle & other); void setStyle(const CharStyle & other); + void updateAttr(const CharStyle & other); void erase() { eraseCharStyle(*this); } void eraseDirectFormatting(); Index: scribus/styles/paragraphstyle.cpp =================================================================== --- scribus/styles/paragraphstyle.cpp (wersja 17211) +++ scribus/styles/paragraphstyle.cpp (kopia robocza) @@ -229,7 +229,17 @@ #undef ATTRDEF } +void ParagraphStyle::updateAttr(const ParagraphStyle & other) +{ + other.validate(); + cstyle.applyCharStyle(other.charStyle()); +#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \ + m_##attr_NAME = other.m_##attr_NAME; +#include "paragraphstyle.attrdefs.cxx" +#undef ATTRDEF +} + void ParagraphStyle::getNamedResources(ResourceCollection& lists) const { for (const Style *sty = parentStyle(); sty != NULL; sty = sty->parentStyle()) Index: scribus/styles/paragraphstyle.h =================================================================== --- scribus/styles/paragraphstyle.h (wersja 17211) +++ scribus/styles/paragraphstyle.h (kopia robocza) @@ -89,6 +89,7 @@ void applyStyle(const ParagraphStyle& other); void eraseStyle(const ParagraphStyle& other); void setStyle(const ParagraphStyle& other); + void updateAttr(const ParagraphStyle & other); //only copy attributes values void erase() { eraseStyle(*this); } StyleContext* charStyleContext() { return & cstyleContext; } Index: scribus/util_text.cpp =================================================================== --- scribus/util_text.cpp (wersja 17211) +++ scribus/util_text.cpp (kopia robocza) @@ -50,3 +50,62 @@ assert(false); return -1; } +int findCharStyle(ScribusDoc* doc, const QString &name) +{ + for (int i=0; i < doc->charStyles().count(); ++i) + { + if (name == doc->charStyles()[i].name()) { + return i; + } + } + assert(false); + return -1; +} + +QString getUniquePStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->paragraphStyles().count(); ++i) + { + if (doc->paragraphStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} + +QString getUniqueChStyleName(ScribusDoc* doc, const QString &name) +{ + int id = 0; + bool done = false; + QString s(name); + + while (!done) + { +start: + ++id; + for (int i = 0; i < doc->charStyles().count(); ++i) + { + if (doc->charStyles()[i].name() == s) + { + s = name + " (" + QString::number(id) + ")"; + goto start; + } + } + done = true; + } + + return s; +} Index: scribus/util_text.h =================================================================== --- scribus/util_text.h (wersja 17211) +++ scribus/util_text.h (kopia robocza) @@ -19,6 +19,9 @@ #ifndef NLS_CONFORMANCE int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const ParagraphStyle& parStyle); int SCRIBUS_API findParagraphStyle(ScribusDoc* doc, const QString &name); +int SCRIBUS_API findCharStyle(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniquePStyleName(ScribusDoc* doc, const QString &name); +QString SCRIBUS_API getUniqueChStyleName(ScribusDoc* doc, const QString &name); #endif Index: scribus/scribusdoc.cpp =================================================================== --- scribus/scribusdoc.cpp (wersja 17211) +++ scribus/scribusdoc.cpp (kopia robocza) @@ -35,6 +35,7 @@ #include <QPainter> #include <QPixmap> #include <QProgressBar> +#include <QInputDialog> #include "canvas.h" #include "cmserrorhandling.h" @@ -62,6 +63,7 @@ #include "pagestructs.h" #include "prefsfile.h" #include "prefsmanager.h" +#include "propertiespalette.h" #include "resourcecollection.h" #include "sccolorengine.h" #include "scmessagebox.h" @@ -77,6 +79,7 @@ #include "selection.h" #include "serializer.h" #include "storyeditor.h" +#include "stylemanager.h" #include "text/nlsconfig.h" #include "undomanager.h" #include "undostate.h" @@ -84,6 +87,7 @@ #include "util.h" #include "util_icon.h" #include "util_math.h" +#include "util_text.h" @@ -1284,7 +1288,215 @@ } } +void ScribusDoc::PStyleFromStyle(QString newName, ParagraphStyle currStyle, bool update, bool defStyle) +{ + ParagraphStyle newStyle; + if (update) + { + if (currStyle.name().isEmpty() && currStyle.hasParent()) + newStyle = *((ParagraphStyle*) currStyle.parentStyle()); + else if (!currStyle.name().isEmpty()) + newStyle = currStyle; + else + { + //FIX ME: name is empty and has not any parent = default style? + PStyleFromStyle(newName, currStyle, false, true); + return; + } + newStyle.updateAttr(currStyle); + } + else + { + newStyle.setStyle(currStyle); + newStyle.setName(newName); + if (defStyle) + newStyle.setDefaultStyle(true); + } + StyleSet<ParagraphStyle> tmpStyles_; + tmpStyles_.create(newStyle); + redefineStyles(tmpStyles_); +} +QString ScribusDoc::setPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return ""; + + QString newName = getUniquePStyleName(this, currItem->currentStyle().parent()); + if (ScCore->usingGUI()) + { + bool ok=false; + while (!ok) + { + newName = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newName, &ok); + if (ok) + { + QString newName2 = getUniquePStyleName(this, newName); + // name was changed, let user decide it is good for him + if (newName2 != newName) + ok = false; + newName = newName2; + } + else + return ""; + } + } + ParagraphStyle curStyle = currItem->currentStyle(); + curStyle.charStyle().applyCharStyle(currItem->currentCharStyle()); + PStyleFromStyle(newName, curStyle, false); + changed(); + if (ScCore->usingGUI()) + { + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); + } + return newName; +} + +void ScribusDoc::updatePStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + ParagraphStyle curStyle = currItem->currentStyle(); + curStyle.charStyle().applyCharStyle(currItem->currentCharStyle()); + QString newPName; + if (currItem->currentStyle().hasParent()) + newPName = currItem->itemText.paragraphStyle().parent(); + else if (currItem->itemText.paragraphStyle().hasName()) + newPName = currItem->itemText.paragraphStyle().name(); + else + newPName = CommonStrings::DefaultParagraphStyle; + PStyleFromStyle(newPName, curStyle, true); + changed(); + if (ScCore->usingGUI()) + { + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); + } +} + +void ScribusDoc::defaultPStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + ParagraphStyle curStyle = currItem->currentStyle(); + curStyle.charStyle().applyCharStyle(currItem->currentCharStyle()); + PStyleFromStyle(CommonStrings::DefaultParagraphStyle, curStyle, false, true); + changed(); + if (ScCore->usingGUI()) + { + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); + } +} + +void ScribusDoc::ChStyleFromStyle(QString newName, CharStyle currStyle, bool update, bool defStyle) +{ + CharStyle newStyle; + if (update) + { + if (currStyle.name().isEmpty() && currStyle.hasParent()) + newStyle = *((CharStyle*) currStyle.parentStyle()); + else if (!currStyle.name().isEmpty()) + newStyle = currStyle; + else + { + //FIX ME: name is empty and has not any parent = default style? + ChStyleFromStyle(newName, currStyle, false, true); + return; + } + newStyle.updateAttr(currStyle); + } + else + { + newStyle.setStyle(currStyle); + newStyle.setName(newName); + if (defStyle) + newStyle.setDefaultStyle(true); + } + + StyleSet<CharStyle> tmpStyles_; + tmpStyles_.create(newStyle); + redefineCharStyles(tmpStyles_); +} + +QString ScribusDoc::setChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return ""; + if (currItem->itemText.cursorPosition() >= currItem->itemText.length()) + return ""; + + QString newName = getUniqueChStyleName(this, currItem->currentCharStyle().parent()); + if (ScCore->usingGUI()) + { + bool ok=false; + while (!ok) + { + newName = QInputDialog::getText(scMW(), tr("Set name for new Paragraph Style"), + tr("Name:"), QLineEdit::Normal, + newName, &ok); + if (ok) + { + QString newName2 = getUniquePStyleName(this, newName); + // name was changed, let user decide it is good for him + if (newName2 != newName) + ok = false; + newName = newName2; + } + else + return ""; + } + } + ChStyleFromStyle(newName, currItem->currentCharStyle(), false); + changed(); + if (ScCore->usingGUI()) + { + scMW()->styleMgr()->setDoc(this); + scMW()->propertiesPalette->paraStyleCombo->updateFormatList(); + } + return newName; +} + +void ScribusDoc::updateChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->itemText.cursorPosition() >= currItem->itemText.length()) + return; + + ChStyleFromStyle(currItem->currentCharStyle().parent(), currItem->currentCharStyle(), true); + changed(); + if (ScCore->usingGUI()) + { + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); + } +} + +void ScribusDoc::defaultChStyleCPos() +{ + PageItem *currItem = m_Selection->itemAt(0); + if (!currItem->isTextFrame()) + return; + if (currItem->itemText.cursorPosition() >= currItem->itemText.length()) + return; + ChStyleFromStyle(CommonStrings::DefaultCharacterStyle, currItem->currentCharStyle(), false, true); + changed(); + if (ScCore->usingGUI()) + { + view()->DrawNew(); + scMW()->styleMgr()->setDoc(this); + } +} + void ScribusDoc::lockGuides(bool isLocked) { if (GuideLock == isLocked) Index: scribus/scribusdoc.h =================================================================== --- scribus/scribusdoc.h (wersja 17211) +++ scribus/scribusdoc.h (kopia robocza) @@ -479,8 +479,23 @@ * @param newNameForOld a map which maps the name of any style to remove to a new stylename */ void replaceCharStyles(const QMap<QString,QString>& newNameForOld); - /** + * @brief Create or update par/char styles by current style at cursor position + * @param or from frame current style if not in edit mode + */ +public slots: + QString setPStyleCPos(); + void updatePStyleCPos(); + void defaultPStyleCPos(); + QString setChStyleCPos(); + void updateChStyleCPos(); + void defaultChStyleCPos(); +private: + /** functions for creating or update styles without GUI interaction */ + void PStyleFromStyle(QString, ParagraphStyle, bool update, bool defStyle=false); + void ChStyleFromStyle(QString, CharStyle, bool update, bool defStyle=false); +public: + /** * @brief Should guides be locked or not * @param isLocked If true guides on pages cannot be moved if false they * can be dragged to new positions. Index: scribus/actionmanager.cpp =================================================================== --- scribus/actionmanager.cpp (wersja 17211) +++ scribus/actionmanager.cpp (kopia robocza) @@ -474,6 +474,20 @@ name="itemConvertToTextFrame"; scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + //create styles from current local style + name="itemPStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemPStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextNew"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextUpdate"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + name="itemChStyleFromTextSaveDefault"; + scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow)); + connect( (*scrActions)["itemDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItem()) ); connect( (*scrActions)["itemMulDuplicate"], SIGNAL(triggered()), mainWindow, SLOT(duplicateItemMulti()) ); connect( (*scrActions)["itemGroup"], SIGNAL(triggered()), mainWindow, SLOT(GroupObj()) ); @@ -1048,7 +1062,12 @@ disconnect( (*scrActions)["itemDelete"], 0, 0, 0); disconnect( (*scrActions)["extrasHyphenateText"], 0, 0, 0 ); disconnect( (*scrActions)["extrasDeHyphenateText"], 0, 0, 0 ); - + disconnect( (*scrActions)["itemPStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemPStyleFromTextSaveDefault"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextNew"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextUpdate"], 0, 0, 0 ); + disconnect( (*scrActions)["itemChStyleFromTextSaveDefault"], 0, 0, 0 ); } void ActionManager::connectNewDocActions(ScribusDoc *currDoc) @@ -1068,6 +1087,12 @@ connect( (*scrActions)["itemDelete"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_DeleteItem()) ); connect( (*scrActions)["itemAdjustFrameToImage"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustFrametoImageSize()) ); connect( (*scrActions)["itemAdjustImageToFrame"], SIGNAL(triggered()), currDoc, SLOT(itemSelection_AdjustImagetoFrameSize()) ); + connect( (*scrActions)["itemPStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setPStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updatePStyleCPos()) ); + connect( (*scrActions)["itemPStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultPStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextNew"], SIGNAL(triggered()), currDoc, SLOT(setChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextUpdate"], SIGNAL(triggered()), currDoc, SLOT(updateChStyleCPos()) ); + connect( (*scrActions)["itemChStyleFromTextSaveDefault"], SIGNAL(triggered()), currDoc, SLOT(defaultChStyleCPos()) ); } void ActionManager::disconnectNewViewActions() @@ -1383,6 +1408,12 @@ (*scrActions)["itemConvertToOutlines"]->setTexts( tr("&Outlines", "Convert to oulines")); (*scrActions)["itemConvertToPolygon"]->setTexts( tr("&Polygon")); (*scrActions)["itemConvertToTextFrame"]->setTexts( tr("&Text Frame")); + (*scrActions)["itemPStyleFromTextNew"]->setTexts( tr("Create paragraph style")); + (*scrActions)["itemPStyleFromTextUpdate"]->setTexts( tr("Update paragraph style")); + (*scrActions)["itemPStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Paragraph Style")); + (*scrActions)["itemChStyleFromTextNew"]->setTexts( tr("Create character style")); + (*scrActions)["itemChStyleFromTextUpdate"]->setTexts( tr("Update character style")); + (*scrActions)["itemChStyleFromTextSaveDefault"]->setTexts( tr("Save as Default Character Style")); //Insert Menu (*scrActions)["insertFrame"]->setTexts( tr("&Frames...")); Index: scribus/contextmenu.cpp =================================================================== --- scribus/contextmenu.cpp (wersja 17211) +++ scribus/contextmenu.cpp (kopia robocza) @@ -90,6 +90,7 @@ QMenu *menuLevel = new QMenu(this); QMenu *menuPDF = new QMenu(this); QMenu *menuResolution = new QMenu(this); + QMenu *menuStyles = new QMenu(this); //<-- Add Info //Test new method with image frames first @@ -181,6 +182,18 @@ if (QApplication::clipboard()->mimeData()->hasImage()) addAction(m_AP->scrActions["editPasteImageFromClipboard"]); } + if (currItem->asTextFrame()) + { + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemPStyleFromTextSaveDefault"]); + menuStyles->addSeparator(); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextNew"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextUpdate"]); + menuStyles->addAction(m_AP->scrActions["itemChStyleFromTextSaveDefault"]); + QAction *act = addMenu(menuStyles); + act->setText( ScribusView::tr("Style from selection")); + } if (m_actionList.contains("itemAdjustFrameToImage")) addAction(m_AP->scrActions["itemAdjustFrameToImage"]); if (m_actionList.contains("itemAdjustImageToFrame")) |
|
Sorry for late, but bettter late than never. stylesFromCPos.patch is new version with solution for 1.4.1.svn Enjoy! |
|
Here it is 2016 and I'm wondering if this feature request is likely to be added? As a designer I have found this feature to be very helpful in other similar applications. |
|
2019, i will work on this and update the patch to the current code. but i will avoid using the context menu, since it's already a mess. one must be using the text palette anyway for formatting. we can add context menus, once we have sorted out how to make those usable again. my target implementation is: - a button next to the styles list in the text palette - a small input dialog asking for a new name. |
|
ale, only a proposal There is a "Edit" button in the style window. The "Edit" button has no meaning (opens and closes the window). What's the point? Please consider removing this button and the style window let it be always full size. |
|
hi peter that's a different matter. personally, i would avoid changing the current style manager, the goal being to create in the future one new manager where you can see and edit multiple styles at a a time. on top of it paragraph style should not have character formatting, but link to a paragraph style (that's the main reason why you will need to have multiple style open at the same time). for now, it's about creating a style based on the current selection : - ) |
|
i got some working code (i can create a new style based on the current selection), but 0015781 is bugging me... it's heavily based on cezary's code, just much simpler (at least for now) |
|
i'm almost there... it's a bit harder than i thought to get everything right... but i'm almost there : - ) |
|
So happy, that this gets picked up again in 2019. Thank you @ale for your work. This feature would be tremendously helpful! |
|
here is the pull request: https://gitlab.com/scribus/scribus/merge_requests/4 jean, this time i think that we really should the review on gitlab: - the insert seems to work ok to me - but the update does not work... can you look at it and give me hint how to fix it? (you can give comments inline...) |
|
an appimage with the patch can be downloaded here: https://gitlab.com/a.l.e/scribus/-/jobs/287538744/artifacts/file/Scribus-nightly-x86_64.AppImage (works on most linux computers) |
|
HI ale Update button don't work. Is it intentional? |
|
...and there are other problems. |
|
thanks peter for checking it. it's written above that the update does not work yet and i need jean's feedback / help : - ) i will have a look at the very long style name and see what i can do there... (i must admit that i've mainly tested with "red" and "abc" and "def"...) |
Date Modified | Username | Field | Change |
---|---|---|---|
2004-05-02 19:24 | linuxlingam | New Issue | |
2004-05-02 19:28 | cbradney | Note Added: 0001319 | |
2006-02-06 17:35 | jo-hannes | Status | new => acknowledged |
2006-02-06 17:35 | jo-hannes | Product Version | 1.1.6 => 1.3 |
2007-05-06 21:05 | christoph_s | Note Added: 0016115 | |
2007-05-06 21:06 | christoph_s | Relationship added | has duplicate 0005642 |
2008-02-14 19:04 | louisdesjardins | Note Added: 0018965 | |
2009-12-13 11:51 | jghali | Relationship added | has duplicate 0008637 |
2010-06-25 01:52 | louisdesjardins | Note Added: 0024210 | |
2011-05-23 13:39 | cezaryece | File Added: style_from_cpos.patch | |
2011-05-23 13:39 | cezaryece | Note Added: 0026230 | |
2011-05-23 20:53 | cbradney | Note Added: 0026231 | |
2011-05-24 05:15 | cezaryece | Note Added: 0026234 | |
2011-05-24 21:27 | cbradney | Note Added: 0026250 | |
2011-05-24 21:44 | ale | Note Added: 0026253 | |
2011-05-25 06:34 | cezaryece | Note Added: 0026257 | |
2011-05-25 09:17 | cezaryece | File Added: style_from_cpos_v2.patch | |
2011-05-25 09:36 | cezaryece | Note Added: 0026258 | |
2011-05-25 21:30 | cbradney | Note Added: 0026262 | |
2011-05-26 05:37 | cezaryece | Note Added: 0026265 | |
2011-05-26 11:10 | cezaryece | File Added: style_from_cpos_v3.patch | |
2011-06-02 05:15 | cezaryece | Note Edited: 0026265 | |
2011-06-27 10:29 | StefanM | Note Added: 0026486 | |
2011-06-27 11:45 | ale | Note Added: 0026490 | |
2011-07-04 10:07 | StefanM | Note Added: 0026527 | |
2011-07-04 11:04 | cezaryece | Note Added: 0026529 | |
2011-07-04 11:07 | cezaryece | Note Edited: 0026529 | |
2011-07-04 11:27 | ale | Note Added: 0026532 | |
2011-09-02 09:28 | StefanM | Note Added: 0026823 | |
2011-10-12 05:26 | cezaryece | Note Added: 0027007 | |
2011-10-12 07:17 | StefanM | Note Added: 0027009 | |
2011-10-12 11:41 | cezaryece | Note Added: 0027010 | |
2012-01-18 10:49 | cezaryece | File Added: stylesFromCPos.patch | |
2012-01-18 10:51 | cezaryece | Note Added: 0027554 | |
2016-05-19 18:46 | Kunda | Patch | => Yes |
2016-05-19 18:46 | Kunda | Tag Attached: discussion | |
2016-11-05 12:42 | jghali | Relationship added | has duplicate 0014352 |
2016-11-06 04:12 | StevenD | Note Added: 0042327 | |
2016-11-06 10:57 | JLuc | Tag Attached: #rottenpatch | |
2019-08-20 12:11 | ale | Note Added: 0046501 | |
2019-08-20 17:36 | PeterBenedek | Note Added: 0046503 | |
2019-08-20 17:37 | PeterBenedek | Note Edited: 0046503 | |
2019-08-20 18:31 | ale | Note Added: 0046505 | |
2019-08-21 15:20 | ale | Note Added: 0046506 | |
2019-08-24 09:34 | ale | Note Added: 0046531 | |
2019-09-03 07:31 | serve_chilled | Note Added: 0046617 | |
2019-09-04 14:08 | ale | Note Added: 0046623 | |
2019-09-04 15:25 | ale | Note Added: 0046624 | |
2019-09-04 15:52 | PeterBenedek | Note Added: 0046625 | |
2019-09-04 16:04 | PeterBenedek | File Added: CreateNewStyle.gif | |
2019-09-04 16:04 | PeterBenedek | Note Added: 0046626 | |
2019-09-04 16:40 | ale | Note Added: 0046627 | |
2019-09-07 15:57 | ale | Summary | right-click paragraph, save as paragraph style => [PATCH] right-click paragraph, save as paragraph style |
2019-11-08 06:26 | ale | Assigned To | => ale |
2019-11-08 06:26 | ale | Status | acknowledged => assigned |