View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0014936 | Scribus | General | public | 2017-08-04 07:37 | 2020-10-14 15:45 |
Reporter | ale | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | new | Resolution | open | ||
Product Version | 1.5.4.svn | ||||
Summary | 0014936: [PATCH] simplify the lorem ipsum (sample text) | ||||
Description | the current implementation of the sample text gives too much choices at insert time. the sample text should be directly inserted by the "content > sample text" command and no dialog shown. proposed changes: - reduce the number of languages presented: - the "standard" lorem ipsum for all latin language (the default choice). - one sample text for each (type of) language that is not based on the latin alphabet. - a free text where one can paste her own text. - the choice between those options is done in the preferences / document settings. - the other options in the dialog can probably be replaced by a new "fit the text in the frame" option. - if the frame is selected, the text is replaced, if the text is being edited, the text is added at the cursor. i will update this description based on the comments in this ticket. | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
in my eyes, if somebody needs a one time different lorem ipsum, it will be more comfortable to switch to the browser for that specific task (and copy paste the text from the internet) instead having to "ok"-click the dialog each time a standard text is needed. |
|
a few years later: - inserting a lorem ipsum is still a "long" process that distract too much from the task the user really wants to perform. - now we that we have a text language, i suggest that the dialog should only show a choice between the standard lorem ipsum and the one from the specific language. - the number of paragraphs is also a distracting feature. what about giving the choice between: - 3/4 line - 1 line - fill frame - full text - keep the last choice and / or do an intelligent choice depending on the height / proportions of the frame. |
|
there is already a setting in 'preferences' → 'miscellaneous' → 'lorem ipsum'. years ago i checked 'always use standard lorem ipsum text' and for the length i chose '4 paragraphs'. with this settings there is no dialog when i need some sample text… |
|
yes, utnik you're 100% right but... that setting is hard to find and... just a few times a year i prefer to use a localized lorem ipsum... and i often need short (single line) lorem ipsum and i would love to have those ones to very fast to apply... (i don't mind to need some more time when i need to fill 20 pages of lorem ipsums...) i'm tempted to make a patch... |
|
i agree. making it easier is a good idea. i was just reading the bug report as there wouldn't be a setting to avoid the dialog… |
|
i'm working on a patch. it won't contain the list of all available ipsums and will defaut to the latin one if the current language does not have a sample text. personally, i don't see the interest in showing the detail information each time the dialog is opened. i suggest to move it to the about or resources dialogs. if you want it to be shown... |
|
|
|
here is a patch that: - removes the list of languages - defaults to the standard lorem ipsum (it's called standard because, well, it's the standard...) - uses the current language to pick the matching localized sample text (and defaults to the "latin" lorem ipsum if no matching sample text is found) while reviewing the patch, i've finally found out how to use the current dialog in an efficient way... (just type s and t...) but i still think that it's worth to simplify the dialog. finally, if the patch is accepted, i think that it would be better to remove the setting for inserting the lorem ipsum without asking any question: it's too well hidden and if the user can get the same effect by simply pressing the enter key, it's probably fast enough. and the code gets slightly simpler... lorem.diff (13,986 bytes)
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp index 792763a73..730632c47 100644 --- a/scribus/scribus.cpp +++ b/scribus/scribus.cpp @@ -8551,7 +8551,7 @@ void ScribusMainWindow::insertSampleText() } if (loremMgr.exec()) - loremMgr.insertLoremIpsum(loremMgr.getName(), loremMgr.paragraphCount(), loremMgr.randomize()); + loremMgr.insertLoremIpsum(); } void ScribusMainWindow::iconSetChange() diff --git a/scribus/ui/loremipsum.cpp b/scribus/ui/loremipsum.cpp index d9fbfb2bd..f0a2ffa03 100644 --- a/scribus/ui/loremipsum.cpp +++ b/scribus/ui/loremipsum.cpp @@ -14,22 +14,21 @@ for which a new license (GPL+exception) is in place. ***************************************************************************/ #include "loremipsum.h" +#include <QCheckBox> #include <QDir> #include <QDomDocument> #include <QEvent> #include <QFile> -#include <QGridLayout> +#include <QFileInfo> #include <QHBoxLayout> -#include <QHeaderView> +#include <QGroupBox> #include <QLabel> #include <QPushButton> #include <QSpacerItem> #include <QSpinBox> -#include <QCheckBox> +#include <QRadioButton> #include <QString> #include <QStringList> -#include <QTreeWidget> -#include <QTreeWidgetItem> #include <QVBoxLayout> #include "appmodes.h" @@ -137,117 +136,87 @@ LoremManager::LoremManager(ScribusDoc* doc, QWidget* parent) : QDialog( parent ) setModal(true); setWindowTitle( tr( "Lorem Ipsum" ) ); setWindowIcon(IconManager::instance().loadIcon("AppIcon.png")); - LoremManagerLayout = new QGridLayout(this) ; - LoremManagerLayout->setMargin(10); - LoremManagerLayout->setSpacing(5); - - layout3 = new QVBoxLayout; - layout3->setMargin(0); - layout3->setSpacing(5); - - loremList = new QTreeWidget( this ); - loremList->setRootIsDecorated(true); - loremList->setColumnCount(1); - loremList->setHeaderLabel( tr("Select Lorem Ipsum")); - loremList->header()->setSectionsClickable( false ); - loremList->header()->setSectionResizeMode( QHeaderView::ResizeToContents ); - loremList->setSelectionMode(QAbstractItemView::SingleSelection); - layout3->addWidget( loremList ); - - layout2 = new QHBoxLayout; - layout2->setMargin(0); - layout2->setSpacing(5); - - paraLabel = new QLabel( this ); - layout2->addWidget( paraLabel ); - - paraBox = new QSpinBox( this ); - paraBox->setMinimum( 1 ); - paraBox->setValue(PrefsManager::instance().appPrefs.miscPrefs.paragraphsLI); - layout2->addWidget( paraBox ); - - paraSpacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum ); - layout2->addItem( paraSpacer ); - layout3->addLayout( layout2 ); + + auto loremManagerLayout = new QVBoxLayout(this); + loremManagerLayout->setMargin(10); + loremManagerLayout->setSpacing(5); + + standardRadioButton = new QRadioButton(this); + standardRadioButton->setChecked(true); + loremManagerLayout->addWidget(standardRadioButton); + localizedRadioButton = new QRadioButton(this); + loremManagerLayout->addWidget(localizedRadioButton); + + auto groupBoxLayout = new QVBoxLayout; + groupBoxLayout->addStretch(1); + + { + auto layout = new QHBoxLayout; + layout->setMargin(0); + layout->setSpacing(5); + + paraLabel = new QLabel(this); + layout->addWidget(paraLabel); + + paraBox = new QSpinBox(this); + paraBox->setMinimum(1); + paraBox->setValue(PrefsManager::instance().appPrefs.miscPrefs.paragraphsLI); + layout->addWidget(paraBox); + + layout->addItem(new QSpacerItem(2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum)); + groupBoxLayout->addLayout(layout); + } randomCheckBox = new QCheckBox(this); randomCheckBox->setChecked(true); - layout3->addWidget( randomCheckBox ); + groupBoxLayout->addWidget(randomCheckBox); appendCheckBox = new QCheckBox(this); appendCheckBox->setChecked(false); - layout3->addWidget( appendCheckBox ); - -// layout3->addLayout( layout4 ); + groupBoxLayout->addWidget(appendCheckBox); - layout1 = new QHBoxLayout; - layout1->setMargin(0); - layout1->setSpacing(5); - buttonSpacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum ); - layout1->addItem( buttonSpacer ); + { + auto layout = new QHBoxLayout; + layout->setMargin(0); + layout->setSpacing(5); + layout->addItem(new QSpacerItem(2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum)); + + okButton = new QPushButton(this); + layout->addWidget(okButton); + cancelButton = new QPushButton(this); + layout->addWidget(cancelButton); + groupBoxLayout->addLayout(layout); + } - okButton = new QPushButton( this ); - layout1->addWidget( okButton ); + auto groupBox = new QGroupBox(tr("Settings"), this); + groupBox->setLayout(groupBoxLayout); - cancelButton = new QPushButton( this ); - layout1->addWidget( cancelButton ); - layout3->addLayout( layout1 ); + loremManagerLayout->addWidget(groupBox); - LoremManagerLayout->addLayout( layout3, 0, 0 ); languageChange(); - // reading lorems - QDir d(getLoremLocation(QString()), "*.xml"); - - QFileInfoList list = d.entryInfoList(); - QListIterator<QFileInfo> it(list); - QFileInfo fi; - LanguageManager * langmgr( LanguageManager::instance() ); -// langmgr->init(false); + // signals and slots connections + connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); + connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); +} - while (it.hasNext()) +const QString LoremManager::getSampleFileName(const QString& langCode) const { + auto xmlPath = getLoremLocation(langCode+".xml"); + QFileInfo fileInfo(xmlPath); + if (!fileInfo.exists()) { - fi = it.next(); - if (langmgr->getLangFromAbbrev(fi.baseName(), false).isEmpty()) - continue; - LoremParser *parser = new LoremParser(fi.fileName()); - if (!parser->correct) + if (langCode.contains('_')) { + auto code = langCode.split('_')[0]; + qDebug() << "code" << code; + xmlPath = getLoremLocation(code+".xml"); + fileInfo = QFileInfo(xmlPath); + } + if (!fileInfo.exists()) { - delete parser; - continue; + xmlPath = getLoremLocation("la.xml"); + fileInfo = QFileInfo(xmlPath); } - availableLorems[parser->name] = fi.fileName(); - QTreeWidgetItem *item = new QTreeWidgetItem(loremList); - if (parser->name=="la") - item->setText(0, standardloremtext); - else - item->setText(0, langmgr->getLangFromAbbrev(parser->name, true)); - QTreeWidgetItem *subItem; - subItem = new QTreeWidgetItem(item); - subItem->setText(0, tr("Author:") + " " + parser->author); - subItem = new QTreeWidgetItem(item); - subItem->setText(0, tr("Get More:") + " " + parser->url); - subItem = new QTreeWidgetItem(item); - subItem->setText(0, tr("XML File:") + " " + fi.fileName()); - delete parser; } - loremList->sortItems(0, Qt::AscendingOrder); - loremList->setSortingEnabled(false); - resize( QSize(320, 340).expandedTo(minimumSizeHint()) ); - QList<QTreeWidgetItem *> defItem; - defItem.clear(); - defItem = loremList->findItems(langmgr->getLangFromAbbrev(m_Doc->language(), true), Qt::MatchExactly); - if (defItem.count() == 0) - defItem = loremList->findItems(standardloremtext, Qt::MatchExactly); - if (defItem.count() != 0) - { - loremList->setCurrentItem(defItem[0]); - defItem[0]->setSelected(true); - } - // signals and slots connections - connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) ); - connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) ); - connect( loremList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(accept())); - + return fileInfo.fileName(); } void LoremManager::changeEvent(QEvent *e) @@ -263,6 +232,8 @@ void LoremManager::changeEvent(QEvent *e) void LoremManager::languageChange() { setWindowTitle( tr( "Lorem Ipsum" ) ); + standardRadioButton->setText(tr("Standard Lorem Ipsum")); + localizedRadioButton->setText(tr("Localized sample text")); paraLabel->setText( tr( "Paragraphs:" ) ); randomCheckBox->setText( tr("Random Paragraphs")); appendCheckBox->setText( tr("Append to existing text")); @@ -270,28 +241,28 @@ void LoremManager::languageChange() okButton->setShortcut( QKeySequence( tr( "Alt+O" ) ) ); cancelButton->setText( CommonStrings::tr_Cancel ); cancelButton->setShortcut( QKeySequence( tr( "Alt+C" ) ) ); - standardloremtext = tr("Standard Lorem Ipsum"); paraBox->setToolTip( tr( "Number of paragraphs of selected sample text to insert" ) ); - loremList->setToolTip( tr( "List of languages available to insert sample text in" ) ); +} + +void LoremManager::insertLoremIpsum() +{ + const auto lang = localizedRadioButton->isChecked() ? getName() : "la.xml"; + insertLoremIpsum(lang, paraBox->value(), randomCheckBox->isChecked()); } void LoremManager::insertLoremIpsum(const QString& name, int paraCount, bool random) { //CB: Avox please make insertText for text frame to nuke all this // is it really applied? -// bool done = false; for (int i = 0; i < m_Doc->m_Selection->count(); ++i) { PageItem* currItem = m_Doc->m_Selection->itemAt(i); if (currItem == nullptr) continue; - //do not insert lorem ipsum text into notes frames + // do not insert lorem ipsum text into notes frames if (currItem->isNoteFrame()) continue; - //removing marks and notes from current text -// if (currItem->isTextFrame() && !currItem->asTextFrame()->removeMarksFromText(!m_Doc->hasGUI())) -// continue; PageItem *i2 = currItem; if (m_Doc->appMode == modeEditTable) i2 = currItem->asTable()->activeCell().textFrame(); @@ -304,10 +275,6 @@ void LoremManager::insertLoremIpsum(const QString& name, int paraCount, bool ran activeTransaction = undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::AddLoremIpsum, "", Um::ICreate); i2->itemText.selectAll(); i2->asTextFrame()->deleteSelectedTextFromFrame(); - //We don't need to open a dialog box as the user can undo this action. - //Selection tempSelection(this, false); - //tempSelection.addItem(i2, true); - //m_Doc->itemSelection_ClearItem(&tempSelection); /* ClearItem() doesn't return true or false so the following test has to be done */ if (i2->itemText.length() != 0) @@ -327,7 +294,7 @@ void LoremManager::insertLoremIpsum(const QString& name, int paraCount, bool ran SimpleState *ss = new SimpleState(Um::AddLoremIpsum,"",Um::ICreate); ss->set("LOREM_FRAMETEXT"); ss->set("ETEA", QString("insert_frametext")); - ss->set("TEXT_STR",sampleText); + ss->set("TEXT_STR", sampleText); ss->set("START", i2->itemText.length()); undoManager->action(i2, ss); } @@ -347,33 +314,16 @@ void LoremManager::insertLoremIpsum(const QString& name, int paraCount, bool ran QString LoremManager::loremIpsum() { - LoremParser lp(getName()); + const auto lang = localizedRadioButton->isChecked() ? getName() : "la.xml"; + LoremParser lp(lang); return lp.createLorem(paraBox->value(), randomCheckBox->isChecked()); } -int LoremManager::paragraphCount() -{ - return paraBox->value(); -} - -bool LoremManager::randomize() -{ - return randomCheckBox->isChecked(); -} - QString LoremManager::getName() { - QTreeWidgetItem *li; - if (loremList->currentItem()->parent() == nullptr) - li = loremList->currentItem(); - else - li = loremList->currentItem()->parent(); - - QString name; - if (li->text(0)==standardloremtext) - name="la"; - else - name=LanguageManager::instance()->getAbbrevFromLang(li->text(0), false); - - return availableLorems[name]; + const auto currItem = m_Doc->m_Selection->itemAt(0)->asTextFrame(); + const auto lang = currItem->itemText.length() > 0 ? + currItem->currentCharStyle().language() : + currItem->itemText.defaultStyle().charStyle().language(); + return getSampleFileName(lang); } diff --git a/scribus/ui/loremipsum.h b/scribus/ui/loremipsum.h index 09aaf312a..f4e09d80f 100644 --- a/scribus/ui/loremipsum.h +++ b/scribus/ui/loremipsum.h @@ -22,16 +22,13 @@ for which a new license (GPL+exception) is in place. #include "scribusapi.h" class QEvent; -class QGridLayout; -class QHBoxLayout; class QLabel; class QPushButton; -class QSpacerItem; class QSpinBox; class QCheckBox; +class QRadioButton; class QString; class QStringList; -class QTreeWidget; class QVBoxLayout; class ScribusDoc; @@ -89,47 +86,36 @@ public: /*! Reads all XML files in cfg directory. */ LoremManager(ScribusDoc* doc, QWidget* parent = nullptr); - /*! Apply created LI into a frame + //! Insert the sample text as defined in the dialog + void insertLoremIpsum(); + /*! Insert the sample text according to the parameters \param name filename of the selected LI \param paraCount count of the paragraphs */ void insertLoremIpsum(const QString& name, int paraCount, bool random = true); - //! Lorem Ipsum as QString + //! Lorem Ipsum as QString (for the Story Editor) QString loremIpsum(); - //! Count of the paragraphs selected in GUI - int paragraphCount(); - - //! Name of the Lorem Ipsum file including extension. - QString getName(); - - //! Flag if use "random" paragraphs, taken from GUI. - bool randomize(); - protected: void changeEvent(QEvent *e) override; private: + QRadioButton* standardRadioButton {nullptr}; + QRadioButton* localizedRadioButton {nullptr}; QCheckBox* appendCheckBox {nullptr}; QCheckBox* randomCheckBox {nullptr}; - QGridLayout* LoremManagerLayout {nullptr}; - QHBoxLayout* layout1 {nullptr}; - QHBoxLayout* layout2 {nullptr}; QLabel* paraLabel {nullptr}; QPushButton* cancelButton {nullptr}; QPushButton* okButton {nullptr}; - QSpacerItem* buttonSpacer {nullptr}; - QSpacerItem* paraSpacer {nullptr}; QSpinBox* paraBox {nullptr}; - QString standardloremtext; - QTreeWidget* loremList {nullptr}; - QVBoxLayout* layout3 {nullptr}; ScribusDoc* m_Doc {nullptr}; UndoManager* undoManager {nullptr}; - //! all lorems with Public Name -> filename structure - QMap<QString,QString> availableLorems; + //! Name of the Lorem Ipsum file including extension. + QString getName(); + //! Name of the Lorem Ipsum file including extension. + const QString getSampleFileName(const QString& langCode) const; protected slots: void languageChange(); |
Date Modified | Username | Field | Change |
---|---|---|---|
2017-08-04 07:37 | ale | New Issue | |
2017-08-04 07:39 | ale | Note Added: 0044254 | |
2017-08-04 07:40 | ale | Description Updated | |
2017-08-04 19:33 | jghali | Category | - => General |
2020-10-13 07:51 | ale | Note Added: 0048164 | |
2020-10-13 13:53 | utnik | Note Added: 0048165 | |
2020-10-13 16:05 | ale | Note Added: 0048166 | |
2020-10-13 16:15 | utnik | Note Added: 0048167 | |
2020-10-14 08:51 | ale | Note Added: 0048169 | |
2020-10-14 15:27 | ale | File Added: lorem.gif | |
2020-10-14 15:45 | ale | File Added: lorem.diff | |
2020-10-14 15:45 | ale | File Added: lorem.png | |
2020-10-14 15:45 | ale | Note Added: 0048170 | |
2020-10-14 15:45 | ale | Summary | simplify the lorem ipsum (sample text) => [PATCH] simplify the lorem ipsum (sample text) |
2020-10-14 15:45 | ale | Patch | No => Yes |