r17277 by fschmid - Made the CharSelect Palette insert glyphs with the correct font into textframes.

scribus-commit scribus-commit at lists.scribus.net
Sat Feb 4 22:03:39 UTC 2012


Author: fschmid
Date: Sat Feb  4 22:03:39 2012
New Revision: 17277

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17277
Log:
Made the CharSelect Palette insert glyphs with the correct font into textframes.

Modified:
    trunk/Scribus/scribus/chartablemodel.cpp
    trunk/Scribus/scribus/chartablemodel.h
    trunk/Scribus/scribus/chartableview.cpp
    trunk/Scribus/scribus/chartableview.h
    trunk/Scribus/scribus/ui/charselect.cpp
    trunk/Scribus/scribus/ui/charselect.h
    trunk/Scribus/scribus/ui/charselectenhanced.cpp
    trunk/Scribus/scribus/ui/charselectenhanced.h
    trunk/Scribus/scribus/ui/storyeditor.cpp
    trunk/Scribus/scribus/ui/storyeditor.h

Modified: trunk/Scribus/scribus/chartablemodel.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/chartablemodel.cpp
==============================================================================
--- trunk/Scribus/scribus/chartablemodel.cpp (original)
+++ trunk/Scribus/scribus/chartablemodel.cpp Sat Feb  4 22:03:39 2012
@@ -21,6 +21,7 @@
 {
 	m_selectionModel = new QItemSelectionModel(this);
 	m_characters.clear();
+	m_fonts.clear();
 }
 
 int CharTableModel::rowCount(const QModelIndex & parent) const
@@ -40,14 +41,18 @@
 
 	int ix = index.row() * m_cols + index.column();
 	int currentChar;
+	QString currentFont = m_fontInUse;
 	if (ix < m_characters.count())
+	{
 		currentChar = m_characters[ix];
+		currentFont = m_fonts[ix];
+	}
 	else
 		return QVariant();
 
 	// for mimeData()
 	if (role == Qt::AccessibleTextRole)
-		return m_characters[ix];
+		return QString("%1#%2").arg(currentChar).arg(currentFont);
 
 	// tooltip
 	if (role == Qt::ToolTipRole)
@@ -65,7 +70,7 @@
 		QTransform chma;
 		chma.scale(baseSize/10, baseSize/10);
 
-		ScFace face = (*m_doc->AllFonts)[m_fontInUse];
+		ScFace face = (*m_doc->AllFonts)[currentFont];
 		uint gl = face.char2CMap(currentChar);
 		int size = baseSize + qRound(-face.descent() * baseSize) + 1;
 		double ww = baseSize - face.glyphWidth(gl, baseSize);
@@ -109,30 +114,56 @@
 void CharTableModel::setCharacters(CharClassDef ch)
 {
 	m_characters.clear();
+	m_fonts.clear();
 	m_characters = ch;
+	for (int a = 0; a < m_characters.count(); a++)
+	{
+		m_fonts.append(m_fontInUse);
+	}
 	reset();
 }
 
-void CharTableModel::setFontInUse(QString font)
-{
-	if (font != m_fontInUse)
-	{
-		m_fontInUse = font;
-		reset();
-	}
-}
-
-void CharTableModel::appendUnicode(const QString & s, uint base)
+void CharTableModel::addCharacter(QString ch)
 {
 	int orig = rowCount();
 	bool ok;
-	int val = s.toInt(&ok, base);
+	int a = ch.indexOf(" ");
+	QString si = ch.left(a);
+	QString sf = ch.mid(a+1);
+	int val = si.toInt(&ok, 10);
 	if (!ok)
 		return;
-
-	if (!m_characters.contains(val))
+	m_characters.append(val);
+	m_fonts.append(sf);
+	reset();
+	if (orig < rowCount())
+		emit rowAppended();
+}
+
+void CharTableModel::setFontInUse(QString font)
+{
+	if (font != m_fontInUse)
+	{
+		m_fontInUse = font;
+		reset();
+	}
+}
+
+void CharTableModel::appendUnicode(const QString & s, uint base)
+{
+	int orig = rowCount();
+	bool ok;
+	int a = s.indexOf("#");
+	QString si = s.left(a);
+	QString sf = s.mid(a+1);
+	int val = si.toInt(&ok, base);
+	if (!ok)
+		return;
+
+	if ((!m_characters.contains(val)) || (!m_fonts.contains(sf)))
 	{
 		m_characters.append(val);
+		m_fonts.append(sf);
 		reset();
 	}
 	else
@@ -154,6 +185,7 @@
 	if (index >= 0 && index < m_characters.size())
 	{
 		m_characters.removeAt(index);
+		m_fonts.removeAt(index);
 		reset();
 		return true;
 	}

Modified: trunk/Scribus/scribus/chartablemodel.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/chartablemodel.h
==============================================================================
--- trunk/Scribus/scribus/chartablemodel.h (original)
+++ trunk/Scribus/scribus/chartablemodel.h Sat Feb  4 22:03:39 2012
@@ -8,6 +8,7 @@
 #define CHARTABLEMODEL_H
 
 #include <QAbstractTableModel>
+#include <QStringList>
 
 #include "scribusapi.h"
 
@@ -44,9 +45,12 @@
 	ScFace fontFace();
 
 	void setCharacters(CharClassDef ch);
+	void addCharacter(QString ch);
 	CharClassDef characters() {
 		return m_characters;
 	};
+
+	QStringList fonts() { return m_fonts; }
 
 	//! \brief called to erase glyph at index from table.
 	bool removeCharacter(int index);
@@ -84,6 +88,7 @@
 
 	QString m_fontInUse;
 	CharClassDef m_characters;
+	QStringList m_fonts;
 
 	//! \brief Internal selection handling. See selectionChanged().
 	QItemSelectionModel * m_selectionModel;

Modified: trunk/Scribus/scribus/chartableview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/chartableview.cpp
==============================================================================
--- trunk/Scribus/scribus/chartableview.cpp (original)
+++ trunk/Scribus/scribus/chartableview.cpp Sat Feb  4 22:03:39 2012
@@ -117,7 +117,7 @@
 void CharTableView::viewDoubleClicked(const QModelIndex & /*index*/)
 {
 	if (model()->characters().count() > currenCharactersIndex())
-		emit selectChar(model()->characters()[currenCharactersIndex()]);
+		emit selectChar(model()->characters()[currenCharactersIndex()], model()->fonts()[currenCharactersIndex()]);
 }
 
 int CharTableView::currenCharactersIndex()

Modified: trunk/Scribus/scribus/chartableview.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/chartableview.h
==============================================================================
--- trunk/Scribus/scribus/chartableview.h (original)
+++ trunk/Scribus/scribus/chartableview.h Sat Feb  4 22:03:39 2012
@@ -29,7 +29,7 @@
 	CharTableView(QWidget * parent = 0);
 
 signals:
-	void selectChar(uint);
+	void selectChar(uint, QString);
 	//! \brief When user press the DELETE/BACKSPACE key
 	void delChar();
 

Modified: trunk/Scribus/scribus/ui/charselect.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/charselect.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/charselect.cpp (original)
+++ trunk/Scribus/scribus/ui/charselect.cpp Sat Feb  4 22:03:39 2012
@@ -44,8 +44,8 @@
 	m_userTable->setAcceptDrops(true);
 
 	// signals and slots connections
-	connect(m_userTable, SIGNAL(selectChar(uint)),
-	        this, SLOT(userNewChar(uint)));
+	connect(m_userTable, SIGNAL(selectChar(uint, QString)),
+			this, SLOT(userNewChar(uint, QString)));
 	connect(m_userTableModel, SIGNAL(selectionChanged(QItemSelectionModel*)),
 	        m_userTable, SLOT(modelSelectionChanged(QItemSelectionModel*)));
 	connect(m_userTableModel, SIGNAL(rowAppended()),
@@ -54,8 +54,8 @@
 	        m_userTableModel, SLOT(appendUnicode(const QString &)));
 	connect(hideButton, SIGNAL(toggled(bool)),
 	        this, SLOT(hideButton_toggled(bool)));
-	connect(this, SIGNAL(insertUserSpecialChar(QChar)),
-	        this, SLOT(slot_insertUserSpecialChar(QChar)));
+	connect(this, SIGNAL(insertUserSpecialChar(QChar, QString)),
+			this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
 	connect(uniLoadButton, SIGNAL(clicked()),
 	        this, SLOT(uniLoadButton_clicked()));
 	connect(uniSaveButton, SIGNAL(clicked()),
@@ -92,9 +92,9 @@
 	return chToIns;
 }
 
-void CharSelect::userNewChar(uint i)
-{
-	emit insertUserSpecialChar(QChar(i));
+void CharSelect::userNewChar(uint i, QString font)
+{
+	emit insertUserSpecialChar(QChar(i), font);
 }
 
 void CharSelect::slot_insertSpecialChars(const QString & chars)
@@ -137,7 +137,7 @@
 // 	delEdit();
 }
 
-void CharSelect::slot_insertUserSpecialChar(QChar ch)
+void CharSelect::slot_insertUserSpecialChar(QChar ch, QString font)
 {
 	if (!m_Item)
 		return;
@@ -150,7 +150,11 @@
 		ch = QChar(13);
 	if (ch == QChar(9))
 		ch = QChar(32);
+	int pot = m_Item->itemText.cursorPosition();
 	m_Item->itemText.insertChars(ch, true);
+	CharStyle nstyle = m_Item->itemText.charStyle(pot);
+	nstyle.setFont((*m_doc->AllFonts)[font]);
+	m_Item->itemText.applyCharStyle(pot, 1, nstyle);
 	m_doc->view()->DrawNew();
 	m_doc->changed();
 }
@@ -164,6 +168,7 @@
 	m_enhanced = new CharSelectEnhanced(this);
 	connect(m_enhanced, SIGNAL(insertSpecialChars(const QString &)),
 	        this, SLOT(slot_insertSpecialChars(const QString &)));
+	connect(m_enhanced, SIGNAL(paletteShown(bool)), hideButton, SLOT(setChecked(bool)));
 	m_enhanced->setDoc(m_doc);
 	m_enhanced->setEnabled(this->isEnabled());
 	m_enhanced->show();
@@ -181,6 +186,7 @@
 
 	disconnect(m_enhanced, SIGNAL(insertSpecialChars(const QString &)),
 	           this, SLOT(slot_insertSpecialChars(const QString &)));
+	disconnect(m_enhanced, SIGNAL(paletteShown(bool)), hideButton, SLOT(setChecked(bool)));
 	m_enhanced->close();
 	delete m_enhanced;
 	m_enhanced = 0;
@@ -236,23 +242,30 @@
 void CharSelect::loadUserContent(QString f)
 {
 //     tDebug("loadUserContent start");
-	CharClassDef newChars;
 	QFile file(f);
 	if (!file.exists())
 		return;
 	if (file.open(QIODevice::ReadOnly))
 	{
 		QTextStream stream(&file);
-		QString line;
+		QString line = stream.readLine();
+		if (line != "# Character palette file for Scribus")
+		{
+			file.close();
+			return;
+		}
+		m_userTableModel->setCharacters(CharClassDef());
 		while (!stream.atEnd())
 		{
 			bool ok = false;
 			line = stream.readLine();
 			if (line.left(1) == "#")
 				continue; // don't mess with a comment
-			int val = line.toInt(&ok, 10);
+			int a = line.indexOf(" ");
+			QString si = line.left(a);
+			si.toInt(&ok, 10);
 			if (ok)
-				newChars.append(val);
+				m_userTableModel->addCharacter(line);
 			else
 			{
 				QMessageBox::warning(this, tr("Error"),
@@ -262,7 +275,6 @@
 			}
 		}
 		file.close();
-		m_userTableModel->setCharacters(newChars);
 	}
 //     tDebug("loadUserContent end");
 }
@@ -292,9 +304,12 @@
 	{
 		QTextStream stream(&file);
 		CharClassDef chars = m_userTableModel->characters();
-		stream << "# This is a character palette file for Scribus\n";
-		for (CharClassDef::Iterator it = chars.begin(); it != chars.end(); ++it)
-			stream << (*it) << "\n";
+		QStringList fonts = m_userTableModel->fonts();
+		stream << "# Character palette file for Scribus\n";
+		for (int a = 0; a < chars.count(); a++)
+		{
+			stream << chars[a] << " " << fonts[a] << "\n";
+		}
 		file.close();
 	}
 	else

Modified: trunk/Scribus/scribus/ui/charselect.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/charselect.h
==============================================================================
--- trunk/Scribus/scribus/ui/charselect.h (original)
+++ trunk/Scribus/scribus/ui/charselect.h Sat Feb  4 22:03:39 2012
@@ -57,7 +57,7 @@
 	in StoryEditor workaround. */
 	void insertSpecialChar();
 	/*! Internal signal for one glyph only */
-	void insertUserSpecialChar(QChar);
+	void insertUserSpecialChar(QChar, QString);
 
 
 private:
@@ -81,11 +81,11 @@
 	void closeEnhanced();
 
 private slots:
-	void userNewChar(uint i);
+	void userNewChar(uint i, QString font);
 	void hideButton_toggled(bool);
 	void slot_insertSpecialChar();
 	void slot_insertSpecialChars(const QString & chars);
-	void slot_insertUserSpecialChar(QChar);
+	void slot_insertUserSpecialChar(QChar, QString font);
 	void uniLoadButton_clicked();
 	void uniSaveButton_clicked();
 	void uniClearButton_clicked();

Modified: trunk/Scribus/scribus/ui/charselectenhanced.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/charselectenhanced.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/charselectenhanced.cpp (original)
+++ trunk/Scribus/scribus/ui/charselectenhanced.cpp Sat Feb  4 22:03:39 2012
@@ -33,11 +33,11 @@
 	// signals and slots connections
 	connect(deleteButton, SIGNAL(clicked()), this, SLOT(delEdit()));
 	connect(insertButton, SIGNAL(clicked()), this, SLOT(insChar()));
-	connect(m_charTable, SIGNAL(selectChar(uint)), this, SLOT(newChar(uint)));
+	connect(m_charTable, SIGNAL(selectChar(uint, QString)), this, SLOT(newChar(uint, QString)));
 	connect(fontSelector, SIGNAL(activated(int)), this, SLOT(newFont(int)));
 	connect(rangeSelector, SIGNAL(activated(int)), this, SLOT(newCharClass(int)));
 	connect(hexLineEdit, SIGNAL(returnPressed()),
-	        this, SLOT(hexLineEdit_returnPressed()));
+			this, SLOT(hexLineEdit_returnPressed()));
 }
 
 CharSelectEnhanced::~CharSelectEnhanced()
@@ -413,7 +413,7 @@
 //     tDebug("newFont end");
 }
 
-void CharSelectEnhanced::newChar(uint i)
+void CharSelectEnhanced::newChar(uint i, QString)
 {
 	chToIns += QChar(i);
 	sample->setPixmap(FontSample((*m_doc->AllFonts)[m_fontInUse], 28, chToIns, palette().color(QPalette::Window), true));
@@ -459,7 +459,7 @@
 	bool ok = false;
 	uint code = tx.arg(hexLineEdit->text()).toUInt(&ok, 16);
 	if ((ok) && (code > 31))
-		newChar(code);
+		newChar(code, m_fontInUse);
 }
 
 void CharSelectEnhanced::changeEvent(QEvent *e)

Modified: trunk/Scribus/scribus/ui/charselectenhanced.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/charselectenhanced.h
==============================================================================
--- trunk/Scribus/scribus/ui/charselectenhanced.h (original)
+++ trunk/Scribus/scribus/ui/charselectenhanced.h Sat Feb  4 22:03:39 2012
@@ -35,7 +35,7 @@
 	void insertSpecialChars(const QString & chars);
 
 public slots:
-	void newChar(uint i);
+	void newChar(uint i, QString);
 	void delChar();
 	void newFont(int font);
 	void newCharClass(int c);

Modified: trunk/Scribus/scribus/ui/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp (original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp Sat Feb  4 22:03:39 2012
@@ -1566,7 +1566,7 @@
 	charSelect = new CharSelect(this);
 	charSelect->userTableModel()->setCharacters(ScCore->primaryMainWindow()->charPalette->userTableModel()->characters());
 	connect(charSelect, SIGNAL(insertSpecialChar()), this, SLOT(slot_insertSpecialChar()));
-	connect(charSelect, SIGNAL(insertUserSpecialChar(QChar)), this, SLOT(slot_insertUserSpecialChar(QChar)));
+	connect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)), this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
 
 	smartSelection=prefsManager->appPrefs.storyEditorPrefs.smartTextSelection;
 	seActions["settingsSmartTextSelection"]->setChecked(smartSelection);
@@ -1582,8 +1582,8 @@
 			charSelect->close();
 		disconnect(charSelect, SIGNAL(insertSpecialChar()),
 					this, SLOT(slot_insertSpecialChar()));
-		disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
-					this, SLOT(slot_insertUserSpecialChar(QChar)));
+		disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)),
+					this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
 		delete charSelect;
 		charSelect = NULL;
 	}
@@ -2690,7 +2690,7 @@
 	blockUpdate = false;
 }
 
-void StoryEditor::slot_insertUserSpecialChar(QChar c)
+void StoryEditor::slot_insertUserSpecialChar(QChar c, QString)
 {
 	blockUpdate = true;
 	Editor->insertPlainText(c);

Modified: trunk/Scribus/scribus/ui/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17277&path=/trunk/Scribus/scribus/ui/storyeditor.h
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.h (original)
+++ trunk/Scribus/scribus/ui/storyeditor.h Sat Feb  4 22:03:39 2012
@@ -475,7 +475,7 @@
 	void specialActionKeyEvent(const QString& actionName, int unicodevalue);
 	/*! \brief Slot to insert special characters from charSelect widget. */
 	void slot_insertSpecialChar();
-	void slot_insertUserSpecialChar(QChar);
+	void slot_insertUserSpecialChar(QChar, QString);
 	// 10/12/2004 - pv - #1203: wrong selection on double click
 	void doubleClick(int para, int pos);
 




More information about the scribus-commit mailing list