diff options
Diffstat (limited to 'scribus')
| -rw-r--r-- | scribus/charselect.cpp | 51 | ||||
| -rw-r--r-- | scribus/charselect.h | 6 | ||||
| -rw-r--r-- | scribus/charselectenhanced.cpp | 11 | ||||
| -rw-r--r-- | scribus/charselectenhanced.h | 3 | ||||
| -rw-r--r-- | scribus/chartablemodel.cpp | 51 | ||||
| -rw-r--r-- | scribus/chartablemodel.h | 5 | ||||
| -rw-r--r-- | scribus/chartableview.cpp | 4 | ||||
| -rw-r--r-- | scribus/chartableview.h | 2 | ||||
| -rw-r--r-- | scribus/storyeditor.cpp | 16 | ||||
| -rw-r--r-- | scribus/storyeditor.h | 2 |
10 files changed, 112 insertions, 39 deletions
diff --git a/scribus/charselect.cpp b/scribus/charselect.cpp index 7a6b1fc..19e9355 100644 --- a/scribus/charselect.cpp +++ b/scribus/charselect.cpp @@ -45,8 +45,8 @@ CharSelect::CharSelect(QWidget* parent) 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()), @@ -55,8 +55,8 @@ CharSelect::CharSelect(QWidget* parent) 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()), @@ -93,9 +93,9 @@ const QString & CharSelect::getCharacters() return chToIns; } -void CharSelect::userNewChar(uint i) +void CharSelect::userNewChar(uint i, QString font) { - emit insertUserSpecialChar(QChar(i)); + emit insertUserSpecialChar(QChar(i), font); } void CharSelect::slot_insertSpecialChars(const QString & chars) @@ -120,6 +120,9 @@ void CharSelect::slot_insertSpecialChar() //CB: Avox please make text->insertchar(char) so none of this happens in gui code, and item can tell doc its changed so the view and mainwindow slotdocch are not necessary QChar ch; QString txtIns; + QString fontName = m_doc->currentStyle.charStyle().font().scName(); + if (m_enhanced) + fontName = m_enhanced->getUsedFont(); m_Item->oldCPos = m_Item->itemText.cursorPosition(); for (int a=0; a<chToIns.length(); ++a) { @@ -128,7 +131,11 @@ void CharSelect::slot_insertSpecialChar() 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)[fontName]); + m_Item->itemText.applyCharStyle(pot, 1, nstyle); txtIns.append(ch); } if (m_Item->itemTextSaxed.isEmpty()) @@ -141,7 +148,7 @@ void CharSelect::slot_insertSpecialChar() // delEdit(); } -void CharSelect::slot_insertUserSpecialChar(QChar ch) +void CharSelect::slot_insertUserSpecialChar(QChar ch, QString font) { if (!m_Item) return; @@ -159,7 +166,11 @@ void CharSelect::slot_insertUserSpecialChar(QChar ch) if (ch == QChar(9)) ch = QChar(32); m_Item->oldCPos = m_Item->itemText.cursorPosition(); + 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); if (m_Item->itemTextSaxed.isEmpty()) m_Item->asTextFrame()->updateUndo(PageItem::INS, QString(ch)); else @@ -178,6 +189,7 @@ void CharSelect::openEnhanced() 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(); @@ -195,6 +207,7 @@ void CharSelect::closeEnhanced() 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; @@ -257,16 +270,24 @@ void CharSelect::loadUserContent(QString f) 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"), @@ -276,7 +297,6 @@ void CharSelect::loadUserContent(QString f) } } file.close(); - m_userTableModel->setCharacters(newChars); } // tDebug("loadUserContent end"); } @@ -306,9 +326,12 @@ void CharSelect::saveUserContent(QString f) { 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 diff --git a/scribus/charselect.h b/scribus/charselect.h index e264771..10c5347 100644 --- a/scribus/charselect.h +++ b/scribus/charselect.h @@ -57,7 +57,7 @@ signals: in StoryEditor workaround. */ void insertSpecialChar(); /*! Internal signal for one glyph only */ - void insertUserSpecialChar(QChar); + void insertUserSpecialChar(QChar, QString); private: @@ -81,11 +81,11 @@ private: void closeEnhanced(); private slots: - void userNewChar(uint i); + void userNewChar(uint i, QString); void hideButton_toggled(bool); void slot_insertSpecialChar(); void slot_insertSpecialChars(const QString & chars); - void slot_insertUserSpecialChar(QChar); + void slot_insertUserSpecialChar(QChar, QString); void uniLoadButton_clicked(); void uniSaveButton_clicked(); void uniClearButton_clicked(); diff --git a/scribus/charselectenhanced.cpp b/scribus/charselectenhanced.cpp index 581b438..941f9dd 100644 --- a/scribus/charselectenhanced.cpp +++ b/scribus/charselectenhanced.cpp @@ -33,7 +33,7 @@ CharSelectEnhanced::CharSelectEnhanced(QWidget* parent) // 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()), @@ -66,6 +66,11 @@ void CharSelectEnhanced::setDoc(ScribusDoc* doc) // tDebug("CharSelectEnhanced setDoc end"); } +QString CharSelectEnhanced::getUsedFont() +{ + return m_fontInUse; +} + void CharSelectEnhanced::scanFont() { // tDebug("scanFont start"); @@ -410,7 +415,7 @@ void CharSelectEnhanced::newFont(int font) // 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)); @@ -456,7 +461,7 @@ void CharSelectEnhanced::hexLineEdit_returnPressed() 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) diff --git a/scribus/charselectenhanced.h b/scribus/charselectenhanced.h index bb5d36e..60862fb 100644 --- a/scribus/charselectenhanced.h +++ b/scribus/charselectenhanced.h @@ -26,6 +26,7 @@ public: ~CharSelectEnhanced(); void setDoc(ScribusDoc* doc); + QString getUsedFont(); signals: /*! \brief A signall emitted when press the "Insert" button. @@ -34,7 +35,7 @@ signals: 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); diff --git a/scribus/chartablemodel.cpp b/scribus/chartablemodel.cpp index c3e8ed3..83d5f8e 100644 --- a/scribus/chartablemodel.cpp +++ b/scribus/chartablemodel.cpp @@ -21,6 +21,7 @@ CharTableModel::CharTableModel(QObject *parent, int cols, ScribusDoc * doc, cons { m_selectionModel = new QItemSelectionModel(this); m_characters.clear(); + m_fonts.clear(); } int CharTableModel::rowCount(const QModelIndex & parent) const @@ -40,14 +41,18 @@ QVariant CharTableModel::data(const QModelIndex &index, int role) const int ix = index.row() * m_cols + index.column(); int currentChar; + QString currentFont = m_fontInUse; if (ix < m_characters.count()) - currentChar = m_characters[ix]; + { + 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 @@ QVariant CharTableModel::data(const QModelIndex &index, int role) const QMatrix 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,8 +114,39 @@ ScFace CharTableModel::fontFace() 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::setCharactersAndFonts(CharClassDef ch, QStringList fonts) +{ + m_characters.clear(); + m_fonts.clear(); m_characters = ch; + m_fonts = fonts; + reset(); +} + +void CharTableModel::addCharacter(QString ch) +{ + int orig = rowCount(); + bool ok; + int a = ch.indexOf(" "); + QString si = ch.left(a); + QString sf = ch.mid(a+1); + int val = si.toInt(&ok, 10); + if (!ok) + return; + m_characters.append(val); + m_fonts.append(sf); reset(); + if (orig < rowCount()) + emit rowAppended(); } void CharTableModel::setFontInUse(QString font) @@ -126,13 +162,17 @@ void CharTableModel::appendUnicode(const QString & s, uint base) { int orig = rowCount(); bool ok; - int val = s.toInt(&ok, base); + 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)) + if ((!m_characters.contains(val)) || (!m_fonts.contains(sf))) { m_characters.append(val); + m_fonts.append(sf); reset(); } else @@ -154,6 +194,7 @@ bool CharTableModel::removeCharacter(int index) if (index >= 0 && index < m_characters.size()) { m_characters.removeAt(index); + m_fonts.removeAt(index); reset(); return true; } diff --git a/scribus/chartablemodel.h b/scribus/chartablemodel.h index 5dcd403..a4bae05 100644 --- a/scribus/chartablemodel.h +++ b/scribus/chartablemodel.h @@ -8,6 +8,7 @@ for which a new license (GPL+exception) is in place. #define CHARTABLEMODEL_H #include <QAbstractTableModel> +#include <QStringList> #include "scribusapi.h" @@ -44,9 +45,12 @@ public: ScFace fontFace(); void setCharacters(CharClassDef ch); + void setCharactersAndFonts(CharClassDef ch, QStringList fonts); + 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 @@ private: QString m_fontInUse; CharClassDef m_characters; + QStringList m_fonts; //! \brief Internal selection handling. See selectionChanged(). QItemSelectionModel * m_selectionModel; diff --git a/scribus/chartableview.cpp b/scribus/chartableview.cpp index bbc16eb..94497bf 100644 --- a/scribus/chartableview.cpp +++ b/scribus/chartableview.cpp @@ -77,7 +77,7 @@ void CharTableView::mousePressEvent(QMouseEvent* e) int index = currenCharactersIndex(); int currentChar = -1; - if (index < model()->characters().count()) + if ((index < model()->characters().count()) && (model()->characters().count() > 0)) currentChar = model()->characters()[index]; if (e->button() == Qt::RightButton && currentChar > -1) @@ -117,7 +117,7 @@ void CharTableView::mouseReleaseEvent(QMouseEvent* e) 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() diff --git a/scribus/chartableview.h b/scribus/chartableview.h index 8a67f29..1be1eb3 100644 --- a/scribus/chartableview.h +++ b/scribus/chartableview.h @@ -29,7 +29,7 @@ public: CharTableView(QWidget * parent = 0); signals: - void selectChar(uint); + void selectChar(uint, QString); //! \brief When user press the DELETE/BACKSPACE key void delChar(); diff --git a/scribus/storyeditor.cpp b/scribus/storyeditor.cpp index 4fb4b8b..3859a25 100644 --- a/scribus/storyeditor.cpp +++ b/scribus/storyeditor.cpp @@ -1570,12 +1570,11 @@ StoryEditor::~StoryEditor() void StoryEditor::showEvent(QShowEvent *) { charSelect = new CharSelect(this); - charSelect->userTableModel()->setCharacters( - ScCore->primaryMainWindow()->charPalette->userTableModel()->characters()); + charSelect->userTableModel()->setCharactersAndFonts(ScCore->primaryMainWindow()->charPalette->userTableModel()->characters(), ScCore->primaryMainWindow()->charPalette->userTableModel()->fonts()); 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))); } void StoryEditor::hideEvent(QHideEvent *) @@ -1584,15 +1583,14 @@ void StoryEditor::hideEvent(QHideEvent *) { if (charSelectUsed) { - ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharacters( - charSelect->userTableModel()->characters()); + ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharactersAndFonts(charSelect->userTableModel()->characters(), charSelect->userTableModel()->fonts()); } if (charSelect->isVisible()) 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; } @@ -2684,7 +2682,7 @@ void StoryEditor::slot_insertSpecialChar() blockUpdate = false; } -void StoryEditor::slot_insertUserSpecialChar(QChar c) +void StoryEditor::slot_insertUserSpecialChar(QChar c, QString) { blockUpdate = true; Editor->insertPlainText(c); diff --git a/scribus/storyeditor.h b/scribus/storyeditor.h index bef85ee..2d94f22 100644 --- a/scribus/storyeditor.h +++ b/scribus/storyeditor.h @@ -472,7 +472,7 @@ protected slots: 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); |
