r14437 by cbradney - Enable new hyphenator prefs to work

scribus-commit scribus-commit at lists.scribus.net
Sun Dec 20 01:00:27 CET 2009


Revision: 14437
Author: cbradney
Date: 2009-12-19T12:17:43.049373Z
Commit message: Enable new hyphenator prefs to work

Changeset: 
M  /trunk/Scribus/scribus/ui/prefs_hyphenator.cpp
M  /trunk/Scribus/scribus/ui/preferencesdialog.cpp
M  /trunk/Scribus/scribus/ui/prefs_itemtoolsbase.ui
M  /trunk/Scribus/scribus/ui/prefs_hyphenator.h
M  /trunk/Scribus/scribus/ui/prefs_hyphenatorbase.ui

Diffs:
Index: scribus/ui/prefs_hyphenator.h
===================================================================
--- scribus/ui/prefs_hyphenator.h	(revision 14436)
+++ scribus/ui/prefs_hyphenator.h	(revision 14437)
@@ -9,15 +9,32 @@
 #define PREFS_HYPHENATOR_H
 
 #include "ui_prefs_hyphenatorbase.h"
+#include "prefs_pane.h"
 #include "scribusapi.h"
 
-class SCRIBUS_API Prefs_Hyphenator : public QWidget, Ui::Prefs_Hyphenator
+class SCRIBUS_API Prefs_Hyphenator : public Prefs_Pane, Ui::Prefs_Hyphenator
 {
 	Q_OBJECT
 
 	public:
 		Prefs_Hyphenator(QWidget* parent=0);
 		~Prefs_Hyphenator();
+		virtual void restoreDefaults(struct ApplicationPrefs *prefsData);
+		virtual void saveGuiToPrefs(struct ApplicationPrefs *prefsData) const;
+
+	public slots:
+		void languageChange();
+
+	protected slots:
+		void addToIgnoreList();
+		void editIgnoreListEntry();
+		void removeIgnoreListEntry();
+		void enableIgnoreButtons();
+		void addToExceptList();
+		void editExceptListEntry();
+		void removeExceptListEntry();
+		void enableExceptButtons();
+
 };
 
 #endif // PREFS_HYPHENATOR_H
Index: scribus/ui/prefs_itemtoolsbase.ui
===================================================================
--- scribus/ui/prefs_itemtoolsbase.ui	(revision 14436)
+++ scribus/ui/prefs_itemtoolsbase.ui	(revision 14437)
@@ -44,7 +44,7 @@
       <enum>QTabWidget::Rounded</enum>
      </property>
      <property name="currentIndex">
-      <number>3</number>
+      <number>0</number>
      </property>
      <property name="elideMode">
       <enum>Qt::ElideRight</enum>
@@ -88,8 +88,8 @@
            <rect>
             <x>0</x>
             <y>0</y>
-            <width>432</width>
-            <height>672</height>
+            <width>606</width>
+            <height>717</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_2">
Index: scribus/ui/prefs_hyphenatorbase.ui
===================================================================
--- scribus/ui/prefs_hyphenatorbase.ui	(revision 14436)
+++ scribus/ui/prefs_hyphenatorbase.ui	(revision 14437)
@@ -51,7 +51,7 @@
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
-        <widget class="QCheckBox" name="verbose">
+        <widget class="QCheckBox" name="hyphSuggestionsCheckBox">
          <property name="toolTip">
           <string>A dialog box showing all possible hyphens for each word will show up when you use the Extras, Hyphenate Text option.</string>
          </property>
@@ -61,7 +61,7 @@
         </widget>
        </item>
        <item>
-        <widget class="QCheckBox" name="input">
+        <widget class="QCheckBox" name="hyphAutoCheckBox">
          <property name="toolTip">
           <string>Enables automatic hyphenation of your text while typing.</string>
          </property>
@@ -115,12 +115,12 @@
             <string>Language:</string>
            </property>
            <property name="buddy">
-            <cstring>language</cstring>
+            <cstring>hyphLanguageComboBox</cstring>
            </property>
           </widget>
          </item>
          <item>
-          <widget class="QComboBox" name="language">
+          <widget class="QComboBox" name="hyphLanguageComboBox">
            <property name="sizePolicy">
             <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
              <horstretch>0</horstretch>
@@ -202,12 +202,12 @@
             <bool>false</bool>
            </property>
            <property name="buddy">
-            <cstring>maxCount</cstring>
+            <cstring>maxConsecutiveCountSpinBox</cstring>
            </property>
           </widget>
          </item>
          <item>
-          <widget class="QSpinBox" name="maxCount">
+          <widget class="QSpinBox" name="maxConsecutiveCountSpinBox">
            <property name="toolTip">
             <string>Maximum number of Hyphenations following each other.
 A value of 0 means unlimited hyphenations.</string>
@@ -287,24 +287,24 @@
              </spacer>
             </item>
             <item row="0" column="0" colspan="4">
-             <widget class="QListWidget" name="exceptList"/>
+             <widget class="QListWidget" name="exceptionListWidget"/>
             </item>
             <item row="1" column="0">
-             <widget class="QPushButton" name="buttonExceptAdd">
+             <widget class="QPushButton" name="exceptionAddButton">
               <property name="text">
                <string/>
               </property>
              </widget>
             </item>
             <item row="1" column="1">
-             <widget class="QPushButton" name="buttonExceptEdit">
+             <widget class="QPushButton" name="exceptionEditButton">
               <property name="text">
                <string>Edit</string>
               </property>
              </widget>
             </item>
             <item row="1" column="2">
-             <widget class="QPushButton" name="buttonExceptRemove">
+             <widget class="QPushButton" name="exceptionRemoveButton">
               <property name="text">
                <string/>
               </property>
@@ -326,7 +326,7 @@
              <number>5</number>
             </property>
             <item row="0" column="0" colspan="4">
-             <widget class="QListWidget" name="ignoreList">
+             <widget class="QListWidget" name="ignoreListWidget">
               <property name="sizePolicy">
                <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
                 <horstretch>0</horstretch>
@@ -336,21 +336,21 @@
              </widget>
             </item>
             <item row="1" column="0">
-             <widget class="QPushButton" name="buttonIgnoreAdd">
+             <widget class="QPushButton" name="ignoreAddButton">
               <property name="text">
                <string/>
               </property>
              </widget>
             </item>
             <item row="1" column="1">
-             <widget class="QPushButton" name="buttonIgnoreEdit">
+             <widget class="QPushButton" name="ignoreEditButton">
               <property name="text">
                <string>Edit</string>
               </property>
              </widget>
             </item>
             <item row="1" column="2">
-             <widget class="QPushButton" name="buttonIgnoreRemove">
+             <widget class="QPushButton" name="ignoreRemoveButton">
               <property name="text">
                <string/>
               </property>
Index: scribus/ui/prefs_hyphenator.cpp
===================================================================
--- scribus/ui/prefs_hyphenator.cpp	(revision 14436)
+++ scribus/ui/prefs_hyphenator.cpp	(revision 14437)
@@ -4,17 +4,167 @@
 a copyright and/or license notice that predates the release of Scribus 1.3.2
 for which a new license (GPL+exception) is in place.
 */
+#include <QInputDialog>
+#include <QListWidget>
 
 #include "prefs_hyphenator.h"
+#include "langmgr.h"
+#include "prefsstructs.h"
+#include "scribuscore.h" //FIXME: for the ScCore call (remove this call)
+#include "scribus.h" //FIXME: for the ScCore call (remove this call)
+#include "util_icon.h"
+#include "util.h"
 
 Prefs_Hyphenator::Prefs_Hyphenator(QWidget* parent)
-	: QWidget(parent)
+	: Prefs_Pane(parent)
 {
 	setupUi(this);
+	LanguageManager *lmg(LanguageManager::instance());
+	hyphLanguageComboBox->setInsertPolicy(QComboBox::InsertAlphabetically);
+	foreach(QString hlang, lmg->hyphLangs())
+	{
+		hyphLanguageComboBox->addItem( lmg->getLangFromAbbrev(hlang), lmg->getLangFromAbbrev(hlang,false) );
+	}
 
+	exceptionAddButton->setIcon(QIcon(loadIcon("16/list-add.png")));
+	exceptionEditButton->setEnabled(false);
+	exceptionRemoveButton->setIcon(QIcon(loadIcon("16/list-remove.png")));
+	exceptionRemoveButton->setEnabled(false);
+	ignoreAddButton->setIcon(QIcon(loadIcon("16/list-add.png")));
+	ignoreEditButton->setEnabled(false);
+	ignoreRemoveButton->setIcon(QIcon(loadIcon("16/list-remove.png")));
+	ignoreRemoveButton->setEnabled(false);
+	connect(ignoreAddButton, SIGNAL(clicked()), this, SLOT(addToIgnoreList()));
+	connect(ignoreEditButton, SIGNAL(clicked()), this, SLOT(editIgnoreListEntry()));
+	connect(ignoreRemoveButton, SIGNAL(clicked()), this, SLOT(removeIgnoreListEntry()));
+	connect(ignoreListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableIgnoreButtons()));
+	connect(exceptionAddButton, SIGNAL(clicked()), this, SLOT(addToExceptList()));
+	connect(exceptionEditButton, SIGNAL(clicked()), this, SLOT(editExceptListEntry()));
+	connect(exceptionRemoveButton, SIGNAL(clicked()), this, SLOT(removeExceptListEntry()));
+	connect(exceptionListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(enableExceptButtons()));
 }
 
 Prefs_Hyphenator::~Prefs_Hyphenator()
 {
 }
 
+void Prefs_Hyphenator::languageChange()
+{
+}
+
+void Prefs_Hyphenator::restoreDefaults(struct ApplicationPrefs *prefsData)
+{
+	hyphSuggestionsCheckBox->setChecked(!prefsData->hyphPrefs.Automatic);
+	hyphAutoCheckBox->setChecked(prefsData->hyphPrefs.AutoCheck);
+	setCurrentComboItem(hyphLanguageComboBox, LanguageManager::instance()->getTransLangFromLang(prefsData->hyphPrefs.Language));
+	smallestWordSpinBox->setValue(prefsData->hyphPrefs.MinWordLen);
+	maxConsecutiveCountSpinBox->setValue(prefsData->hyphPrefs.HyCount);
+	ignoreListWidget->addItems(prefsData->hyphPrefs.ignoredWords.toList());
+	ignoreListWidget->sortItems();
+	exceptionListWidget->addItems(prefsData->hyphPrefs.specialWords.values());
+	exceptionListWidget->sortItems();
+}
+
+void Prefs_Hyphenator::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
+{
+	prefsData->hyphPrefs.MinWordLen = smallestWordSpinBox->value();
+	 //FIXME: remove this ScCore call
+	prefsData->hyphPrefs.Language = ScCore->primaryMainWindow()->GetLang(hyphLanguageComboBox->itemData(hyphLanguageComboBox->currentIndex()).toString());
+	prefsData->hyphPrefs.Automatic = !hyphSuggestionsCheckBox->isChecked();
+	prefsData->hyphPrefs.AutoCheck = hyphAutoCheckBox->isChecked();
+	prefsData->hyphPrefs.HyCount = maxConsecutiveCountSpinBox->value();
+	QSet<QString> ignoreList;
+	for (int row = 0; row < ignoreListWidget->count(); row++)
+	{
+		ignoreList.insert(ignoreListWidget->item(row)->text());
+	}
+	prefsData->hyphPrefs.ignoredWords = ignoreList;
+	QHash<QString, QString> exceptionList;
+	for (int row = 0; row < exceptionListWidget->count(); row++)
+	{
+		exceptionList.insert(exceptionListWidget->item(row)->text().remove("-"), exceptionListWidget->item(row)->text());
+	}
+	prefsData->hyphPrefs.specialWords = exceptionList;
+}
+
+void Prefs_Hyphenator::addToIgnoreList()
+{
+	bool ok;
+	QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
+	if ((ok) && (!text.isEmpty()))
+	{
+		if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
+			ignoreListWidget->addItem(text);
+		ignoreListWidget->sortItems();
+	}
+}
+
+void Prefs_Hyphenator::editIgnoreListEntry()
+{
+	bool ok;
+	QString text = QInputDialog::getText(this, tr("Ignore List"), tr("Edit Entry"), QLineEdit::Normal, ignoreListWidget->currentItem()->text(), &ok);
+	if ((ok) && (!text.isEmpty()))
+	{
+		if (ignoreListWidget->findItems(text, Qt::MatchExactly).count() == 0)
+			ignoreListWidget->currentItem()->setText(text);
+		ignoreListWidget->sortItems();
+	}
+}
+
+void Prefs_Hyphenator::removeIgnoreListEntry()
+{
+	QListWidgetItem *item = ignoreListWidget->takeItem(ignoreListWidget->row(ignoreListWidget->currentItem()));
+	delete item;
+	if (ignoreListWidget->count() == 0)
+	{
+		ignoreEditButton->setEnabled(false);
+		ignoreRemoveButton->setEnabled(false);
+	}
+}
+
+void Prefs_Hyphenator::enableIgnoreButtons()
+{
+	ignoreEditButton->setEnabled(true);
+	ignoreRemoveButton->setEnabled(true);
+}
+
+void Prefs_Hyphenator::addToExceptList()
+{
+	bool ok;
+	QString text = QInputDialog::getText(this, tr("Exception List"), tr("Add a new Entry"), QLineEdit::Normal, "", &ok);
+	if ((ok) && (!text.isEmpty()))
+	{
+		if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
+			exceptionListWidget->addItem(text);
+		exceptionListWidget->sortItems();
+	}
+}
+
+void Prefs_Hyphenator::editExceptListEntry()
+{
+	bool ok;
+	QString text = QInputDialog::getText(this, tr("Exception List"), tr("Edit Entry"), QLineEdit::Normal, exceptionListWidget->currentItem()->text(), &ok);
+	if ((ok) && (!text.isEmpty()))
+	{
+		if (exceptionListWidget->findItems(text, Qt::MatchExactly).count() == 0)
+			exceptionListWidget->currentItem()->setText(text);
+		exceptionListWidget->sortItems();
+	}
+}
+
+void Prefs_Hyphenator::removeExceptListEntry()
+{
+	QListWidgetItem *item = exceptionListWidget->takeItem(exceptionListWidget->row(exceptionListWidget->currentItem()));
+	delete item;
+	if (exceptionListWidget->count() == 0)
+	{
+		exceptionEditButton->setEnabled(false);
+		exceptionRemoveButton->setEnabled(false);
+	}
+}
+
+void Prefs_Hyphenator::enableExceptButtons()
+{
+	exceptionEditButton->setEnabled(true);
+	exceptionRemoveButton->setEnabled(true);
+}
Index: scribus/ui/preferencesdialog.cpp
===================================================================
--- scribus/ui/preferencesdialog.cpp	(revision 14436)
+++ scribus/ui/preferencesdialog.cpp	(revision 14437)
@@ -117,6 +117,7 @@
 	prefs_Typography->restoreDefaults(&localPrefs);
 	prefs_ItemTools->restoreDefaults(&localPrefs);
 	prefs_OperatorTools->restoreDefaults(&localPrefs);
+	prefs_Hyphenator->restoreDefaults(&localPrefs);
 	prefs_Printer->restoreDefaults(&localPrefs);
 	prefs_ColorManagement->restoreDefaults(&localPrefs);
 	prefs_ColorManagement->setProfiles(&localPrefs, &ScCore->InputProfiles, &ScCore->InputProfilesCMYK, &ScCore->PrinterProfiles, &ScCore->MonitorProfiles);
@@ -134,6 +135,7 @@
 	prefs_Typography->saveGuiToPrefs(&localPrefs);
 	prefs_ItemTools->saveGuiToPrefs(&localPrefs);
 	prefs_OperatorTools->saveGuiToPrefs(&localPrefs);
+	prefs_Hyphenator->saveGuiToPrefs(&localPrefs);
 	prefs_Printer->saveGuiToPrefs(&localPrefs);
 	prefs_ColorManagement->saveGuiToPrefs(&localPrefs);
 	prefs_Scrapbook->saveGuiToPrefs(&localPrefs);




More information about the scribus-commit mailing list