Back to index

scribus-ng  1.3.4.dfsg+svn20071115
charselect.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include <qtable.h>
00008 #include <qgroupbox.h>
00009 #include <qlayout.h>
00010 #include <qcheckbox.h>
00011 
00012 #include "scconfig.h"
00013 #include "scribuscore.h"
00014 #include "scribusdoc.h"
00015 #include "scribusview.h"
00016 #include "fontcombo.h"
00017 #include "sccombobox.h"
00018 #include "scpainter.h"
00019 #include "unicodesearch.h"
00020 #include "selection.h"
00021 #include "commonstrings.h"
00022 #include "fonts/scfontmetrics.h"
00023 #include "util.h"
00024 #include "scpaths.h"
00025 
00026 #include "charselect.h"
00027 #include "charselect.moc"
00028 
00029 
00030 CharSelect::CharSelect(QWidget* parent)
00031        : ScrPaletteBase(parent, "CharSelect"),
00032        m_doc(0),
00033        m_Item(0)
00034 {
00035        installEventFilter(this);
00036 
00037        setCaption( tr("Character Palette"));
00038        paletteFileMask = tr("Scribus Char Palette (*.ucp);;All Files (*)");
00039 
00040        QHBoxLayout* mainLayout = new QHBoxLayout(this);
00041        mainLayout->setSpacing(6);
00042        mainLayout->setMargin(11);
00043 
00044        // big table related
00045        m_bigPalette = new QGroupBox(0, Qt::Vertical, tr("Enhanced Palette"), this, "m_bigPalette");
00046        m_bigPalette->layout()->setSpacing(5);
00047        m_bigPalette->layout()->setMargin(10);
00048        QGridLayout* bigLayout = new QGridLayout(m_bigPalette->layout());
00049 
00050        // combos
00051        QHBoxLayout* combosLayout = new QHBoxLayout();
00052        fontLabel = new QLabel(m_bigPalette, "fontLabel");
00053        fontLabel->setText( tr("Font:"));
00054 
00055        fontSelector = new FontCombo(m_bigPalette);
00056        fontSelector->setMaximumSize(190, 30);
00057 
00058        rangeLabel = new QLabel(m_bigPalette, "fontLabel");
00059        rangeLabel->setText( tr("Character Class:"));
00060 
00061        rangeSelector = new ScComboBox(false, m_bigPalette, "rangeSelector");
00062        m_characterClass = 0;
00063 
00064        combosLayout->addWidget(fontLabel);
00065        combosLayout->addWidget(fontSelector);
00066        combosLayout->addWidget(rangeLabel);
00067        combosLayout->addWidget(rangeSelector);
00068 
00069        bigLayout->addLayout(combosLayout, 0, 0);
00070 
00071        m_charTable = new CharTable(m_bigPalette, 16, m_doc, m_fontInUse);
00072        m_charTable->enableDrops(false);
00073 
00074        bigLayout->addWidget(m_charTable, 1, 0);
00075 
00076        sample = new QLabel(m_bigPalette, "sample");
00077        sample->setFrameShape(QFrame::Box);
00078        sample->setPaletteBackgroundColor(paletteBackgroundColor());
00079        sample->setMinimumHeight(48);
00080        sample->setMinimumWidth(460);
00081 
00082        bigLayout->addWidget(sample, 2, 0);
00083 
00084        insertButton = new QPushButton( tr("&Insert"), m_bigPalette, "insertButton");
00085        deleteButton = new QPushButton( tr("C&lear"), m_bigPalette, "deleteButton");
00086 
00087        QHBoxLayout* buttonLayout = new QHBoxLayout();
00088        QSpacerItem* buttonSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
00089        buttonLayout->addItem(buttonSpacer);
00090        buttonLayout->addWidget(insertButton);
00091        buttonLayout->addWidget(deleteButton);
00092 
00093        bigLayout->addLayout(buttonLayout, 3, 0);
00094 
00095        // quick table
00096        m_quickPalette = new QGroupBox(0, Qt::Vertical, tr("Quick Palette"), this, "m_quickPalette");
00097        m_quickPalette->layout()->setSpacing(5);
00098        m_quickPalette->layout()->setMargin(10);
00099        QGridLayout* quickLayout = new QGridLayout(m_quickPalette->layout());
00100 
00101        hideCheck = new QCheckBox( tr("Hide Enhanced"), m_quickPalette, "hideCheck");
00102        quickLayout->addWidget(hideCheck, 0, 0);
00103 
00104        unicodeButton = new UnicodeChooseButton(m_quickPalette, "unicodeButton");
00105 
00106        quickLayout->addWidget(unicodeButton, 1, 0);
00107 
00108        uniLoadButton = new QPushButton(m_quickPalette, "uniLoadButton");
00109        uniLoadButton->setPixmap(loadIcon("22/document-open.png"));
00110        uniSaveButton = new QPushButton(m_quickPalette, "uniSaveButton");
00111        uniSaveButton->setPixmap(loadIcon("22/document-save.png"));
00112        uniClearButton = new QPushButton(m_quickPalette, "uniClearButton");
00113        uniClearButton->setPixmap(loadIcon("22/document-new.png"));
00114        QHBoxLayout *fileLayout = new QHBoxLayout();
00115        fileLayout->addWidget(uniLoadButton);
00116        fileLayout->addWidget(uniSaveButton);
00117        fileLayout->addWidget(uniClearButton);
00118 
00119        quickLayout->addLayout(fileLayout, 2, 0);
00120 
00121        m_userTable = new CharTable(m_quickPalette, 2, m_doc, m_fontInUse);
00122        m_userTable->setMaximumWidth(120);
00123        m_userTable->setMinimumWidth(120);
00124        m_userTable->enableDrops(true);
00125 
00126        quickLayout->addWidget(m_userTable, 3, 0);
00127 
00128        // main layout
00129        mainLayout->addWidget(m_bigPalette);
00130        mainLayout->addWidget(m_quickPalette);
00131 
00132        //tooltips
00133        QToolTip::add(insertButton, "<qt>" + tr("Insert the characters at the cursor in the text") + "</qt>");
00134        QToolTip::add(deleteButton, "<qt>" + tr("Delete the current selection(s).") + "</qt>");
00135        QToolTip::add(m_charTable, "<qt>" + tr("You can see a thumbnail if you press and hold down the right mouse button. The Insert key inserts a Glyph into the Selection below and the Delete key removes the last inserted one") + "</qt>");
00136        // signals and slots connections
00137        connect(deleteButton, SIGNAL(clicked()), this, SLOT(delEdit()));
00138        connect(insertButton, SIGNAL(clicked()), this, SLOT(insChar()));
00139        connect(m_charTable, SIGNAL(selectChar(uint)), this, SLOT(newChar(uint)));
00140        connect(m_charTable, SIGNAL(delChar()), this, SLOT(delChar()));
00141        connect(m_userTable, SIGNAL(selectChar(uint)), this, SLOT(userNewChar(uint)));
00142        connect(m_userTable, SIGNAL(delChar()), this, SLOT(delChar()));
00143        connect(unicodeButton, SIGNAL(chosenUnicode(QString)), m_userTable, SLOT(appendUnicode(QString)));
00144        connect(fontSelector, SIGNAL(activated(int)), this, SLOT(newFont(int)));
00145        connect(rangeSelector, SIGNAL(activated(int)), this, SLOT(newCharClass(int)));
00146        connect(hideCheck, SIGNAL(clicked()), this, SLOT(hideCheck_clicked()));
00147        connect(this, SIGNAL(insertSpecialChar()), this, SLOT(slot_insertSpecialChar()));
00148        connect(this, SIGNAL(insertUserSpecialChar(QChar)), this, SLOT(slot_insertUserSpecialChar(QChar)));
00149        connect(uniLoadButton, SIGNAL(clicked()), this, SLOT(uniLoadButton_clicked()));
00150        connect(uniSaveButton, SIGNAL(clicked()), this, SLOT(uniSaveButton_clicked()));
00151        connect(uniClearButton, SIGNAL(clicked()), this, SLOT(uniClearButton_clicked()));
00152        //
00153        loadUserContent(ScPaths::getApplicationDataDir() + "charpalette.ucp");
00154 }
00155 
00156 CharSelect::~CharSelect()
00157 {
00158 }
00159 
00160 void CharSelect::setDoc(ScribusDoc* doc)
00161 {
00162        if (m_doc != doc)
00163        {
00164               m_doc = doc;
00165               m_charTable->setDoc(m_doc);
00166               m_userTable->setDoc(m_doc);
00167               delEdit();
00168               setupRangeCombo();
00169               newCharClass(0);
00170        }
00171 
00172        if (!m_doc)
00173        {
00174               saveUserContent(ScPaths::getApplicationDataDir() + "charpalette.ucp");
00175               return;
00176        }
00177 
00178        QString oldFont(m_fontInUse);
00179        m_fontInUse = m_doc->currentStyle.charStyle().font().scName();
00180        if (oldFont != m_fontInUse && !m_fontInUse.isEmpty())
00181        {
00182               fontSelector->setCurrentText(m_fontInUse);
00183               newFont(fontSelector->currentItem());
00184               unicodeButton->setFont((*m_doc->AllFonts)[m_fontInUse]);
00185        }
00186 }
00187 
00188 const QString & CharSelect::getCharacters()
00189 {
00190 //     return m_characters;
00191        return chToIns;
00192 }
00193 
00194 void CharSelect::scanFont()
00195 {
00196        uint  charcode;
00197        uint   gindex;
00198        QString   gname;
00199        allClasses.clear();
00200        charactersFull.clear();
00201        charactersLatin1.clear();
00202        charactersLatin1Supplement.clear();
00203        charactersLatinExtendedA.clear();
00204        charactersLatinExtendedB.clear();
00205        charactersGeneralPunctuation.clear();
00206        charactersSuperSubscripts.clear();
00207        charactersCurrencySymbols.clear();
00208        charactersLetterlikeSymbols.clear();
00209        charactersNumberForms.clear();
00210        charactersArrows.clear();
00211        charactersMathematicalOperators.clear();
00212        charactersBoxDrawing.clear();
00213        charactersBlockElements.clear();
00214        charactersGeometricShapes.clear();
00215        charactersMiscellaneousSymbols.clear();
00216        charactersDingbats.clear();
00217        charactersSmallFormVariants.clear();
00218        charactersAlphabeticPresentationForms.clear();
00219        charactersSpecial.clear();
00220        charactersGreek.clear();
00221        charactersGreekExtended.clear();
00222        charactersCyrillic.clear();
00223        charactersCyrillicSupplement.clear();
00224        charactersArabic.clear();
00225        charactersArabicPresentationFormsA.clear();
00226        charactersArabicPresentationFormsB.clear();
00227        charactersHebrew.clear();
00228        QMap<uint, std::pair<QChar, QString> > glyphs;
00229        (*m_doc->AllFonts)[m_fontInUse].glyphNames(glyphs);
00230        for (QMap<uint, std::pair<QChar, QString> >::iterator it=glyphs.begin();
00231                it != glyphs.end(); ++it)
00232        {
00233               charcode = it.data().first.unicode();
00234               gindex = it.key();
00235               gname = it.data().second;
00236               charactersFull.append(charcode);
00237               if ((charcode >= 0x0020) && (charcode <= 0x007F))
00238                      charactersLatin1.append(charcode);
00239               else if ((charcode >= 0x0080) && (charcode <= 0x00FF))
00240                      charactersLatin1Supplement.append(charcode);
00241               else if ((charcode >= 0x0100) && (charcode <= 0x017F))
00242                      charactersLatinExtendedA.append(charcode);
00243               else if ((charcode >= 0x0180) && (charcode <= 0x024F))
00244                      charactersLatinExtendedB.append(charcode);
00245               else if ((charcode >= 0x0370) && (charcode <= 0x03FF))
00246                      charactersGreek.append(charcode);
00247               else if ((charcode >= 0x0400) && (charcode <= 0x04FF))
00248                      charactersCyrillic.append(charcode);
00249               else if ((charcode >= 0x0500) && (charcode <= 0x052F))
00250                      charactersCyrillicSupplement.append(charcode);
00251               else if ((charcode >= 0x0590) && (charcode <= 0x05FF))
00252                      charactersHebrew.append(charcode);
00253               else if ((charcode >= 0x0600) && (charcode <= 0x06FF))
00254                      charactersArabic.append(charcode);
00255               else if ((charcode >= 0x1F00) && (charcode <= 0x1FFF))
00256                      charactersGreekExtended.append(charcode);
00257               else if ((charcode >= 0x2000) && (charcode <= 0x206F))
00258                      charactersGeneralPunctuation.append(charcode);
00259               else if ((charcode >= 0x2070) && (charcode <= 0x209F))
00260                      charactersSuperSubscripts.append(charcode);
00261               else if ((charcode >= 0x20A0) && (charcode <= 0x20CF))
00262                      charactersCurrencySymbols.append(charcode);
00263               else if ((charcode >= 0x2100) && (charcode <= 0x214F))
00264                      charactersLetterlikeSymbols.append(charcode);
00265               else if ((charcode >= 0x2150) && (charcode <= 0x218F))
00266                      charactersNumberForms.append(charcode);
00267               else if ((charcode >= 0x2190) && (charcode <= 0x2190))
00268                      charactersArrows.append(charcode);
00269               else if ((charcode >= 0x2200) && (charcode <= 0x22FF))
00270                      charactersMathematicalOperators.append(charcode);
00271               else if ((charcode >= 0x2500) && (charcode <= 0x257F))
00272                      charactersBoxDrawing.append(charcode);
00273               else if ((charcode >= 0x2580) && (charcode <= 0x259F))
00274                      charactersBlockElements.append(charcode);
00275               else if ((charcode >= 0x25A0) && (charcode <= 0x25FF))
00276                      charactersGeometricShapes.append(charcode);
00277               else if ((charcode >= 0x2600) && (charcode <= 0x26FF))
00278                      charactersMiscellaneousSymbols.append(charcode);
00279               else if ((charcode >= 0x2700) && (charcode <= 0x27BF))
00280                      charactersDingbats.append(charcode);
00281               else if ((charcode >= 0xFE50) && (charcode <= 0xFE6F))
00282                      charactersSmallFormVariants.append(charcode);
00283               else if ((charcode >= 0xFB00) && (charcode <= 0xFB4F))
00284                      charactersAlphabeticPresentationForms.append(charcode);
00285               else if ((charcode >= 0xFB50) && (charcode <= 0xFDFF))
00286                      charactersArabicPresentationFormsA.append(charcode);
00287               else if ((charcode >= 0xFE70) && (charcode <= 0xFEFF))
00288                      charactersArabicPresentationFormsB.append(charcode);
00289               else if ((charcode >= 0xFFF0) && (charcode <= 0xFFFF))
00290                      charactersSpecial.append(charcode);
00291        }
00292        allClasses.append(charactersFull);
00293        allClasses.append(charactersLatin1);
00294        allClasses.append(charactersLatin1Supplement);
00295        allClasses.append(charactersLatinExtendedA);
00296        allClasses.append(charactersLatinExtendedB);
00297        allClasses.append(charactersGeneralPunctuation);
00298        allClasses.append(charactersSuperSubscripts);
00299        allClasses.append(charactersCurrencySymbols);
00300        allClasses.append(charactersLetterlikeSymbols);
00301        allClasses.append(charactersNumberForms);
00302        allClasses.append(charactersArrows);
00303        allClasses.append(charactersMathematicalOperators);
00304        allClasses.append(charactersBoxDrawing);
00305        allClasses.append(charactersBlockElements);
00306        allClasses.append(charactersGeometricShapes);
00307        allClasses.append(charactersMiscellaneousSymbols);
00308        allClasses.append(charactersDingbats);
00309        allClasses.append(charactersSmallFormVariants);
00310        allClasses.append(charactersAlphabeticPresentationForms);
00311        allClasses.append(charactersSpecial);
00312        allClasses.append(charactersGreek);
00313        allClasses.append(charactersGreekExtended);
00314        allClasses.append(charactersCyrillic);
00315        allClasses.append(charactersCyrillicSupplement);
00316        allClasses.append(charactersArabic);
00317        allClasses.append(charactersArabicPresentationFormsA);
00318        allClasses.append(charactersArabicPresentationFormsB);
00319        allClasses.append(charactersHebrew);
00320 }
00321 
00322 void CharSelect::setupRangeCombo()
00323 {
00324        disconnect(rangeSelector, SIGNAL(activated(int)), this, SLOT(newCharClass(int)));
00325        int counter = 0;
00326        rangeSelector->clear();
00327        rangeSelector->insertItem( tr("Full Character Set"));
00328        usedCharClasses.insert(counter, 0);
00329        counter++;
00330        if (charactersLatin1.count() != 0)
00331        {
00332               rangeSelector->insertItem( tr("Basic Latin"));
00333               usedCharClasses.insert(counter, 1);
00334               counter++;
00335        }
00336        if (charactersLatin1Supplement.count() != 0)
00337        {
00338               rangeSelector->insertItem( tr("Latin-1 Supplement"));
00339               usedCharClasses.insert(counter, 2);
00340               counter++;
00341        }
00342        if (charactersLatinExtendedA.count() != 0)
00343        {
00344               rangeSelector->insertItem( tr("Latin Extended-A"));
00345               usedCharClasses.insert(counter, 3);
00346               counter++;
00347        }
00348        if (charactersLatinExtendedB.count() != 0)
00349        {
00350               rangeSelector->insertItem( tr("Latin Extended-B"));
00351               usedCharClasses.insert(counter, 4);
00352               counter++;
00353        }
00354        if (charactersGeneralPunctuation.count() != 0)
00355        {
00356               rangeSelector->insertItem( tr("General Punctuation"));
00357               usedCharClasses.insert(counter, 5);
00358               counter++;
00359        }
00360        if (charactersSuperSubscripts.count() != 0)
00361        {
00362               rangeSelector->insertItem( tr("Super- and Subscripts"));
00363               usedCharClasses.insert(counter, 6);
00364               counter++;
00365        }
00366        if (charactersCurrencySymbols.count() != 0)
00367        {
00368               rangeSelector->insertItem( tr("Currency Symbols"));
00369               usedCharClasses.insert(counter, 7);
00370               counter++;
00371        }
00372        if (charactersLetterlikeSymbols.count() != 0)
00373        {
00374               rangeSelector->insertItem( tr("Letterlike Symbols"));
00375               usedCharClasses.insert(counter, 8);
00376               counter++;
00377        }
00378        if (charactersNumberForms.count() != 0)
00379        {
00380               rangeSelector->insertItem( tr("Number Forms"));
00381               usedCharClasses.insert(counter, 9);
00382               counter++;
00383        }
00384        if (charactersArrows.count() != 0)
00385        {
00386               rangeSelector->insertItem( tr("Arrows"));
00387               usedCharClasses.insert(counter, 10);
00388               counter++;
00389        }
00390        if (charactersMathematicalOperators.count() != 0)
00391        {
00392               rangeSelector->insertItem( tr("Mathematical Operators"));
00393               usedCharClasses.insert(counter, 11);
00394               counter++;
00395        }
00396        if (charactersBoxDrawing.count() != 0)
00397        {
00398               rangeSelector->insertItem( tr("Box Drawing"));
00399               usedCharClasses.insert(counter, 12);
00400               counter++;
00401        }
00402        if (charactersBlockElements.count() != 0)
00403        {
00404               rangeSelector->insertItem( tr("Block Elements"));
00405               usedCharClasses.insert(counter, 13);
00406               counter++;
00407        }
00408        if (charactersGeometricShapes.count() != 0)
00409        {
00410               rangeSelector->insertItem( tr("Geometric Shapes"));
00411               usedCharClasses.insert(counter, 14);
00412               counter++;
00413        }
00414        if (charactersMiscellaneousSymbols.count() != 0)
00415        {
00416               rangeSelector->insertItem( tr("Miscellaneous Symbols"));
00417               usedCharClasses.insert(counter, 15);
00418               counter++;
00419        }
00420        if (charactersDingbats.count() != 0)
00421        {
00422               rangeSelector->insertItem( tr("Dingbats"));
00423               usedCharClasses.insert(counter, 16);
00424               counter++;
00425        }
00426        if (charactersSmallFormVariants.count() != 0)
00427        {
00428               rangeSelector->insertItem( tr("Small Form Variants"));
00429               usedCharClasses.insert(counter, 17);
00430               counter++;
00431        }
00432        if (charactersAlphabeticPresentationForms.count() != 0)
00433        {
00434               rangeSelector->insertItem( tr("Ligatures"));
00435               usedCharClasses.insert(counter, 18);
00436               counter++;
00437        }
00438        if (charactersSpecial.count() != 0)
00439        {
00440               rangeSelector->insertItem( tr("Specials"));
00441               usedCharClasses.insert(counter, 19);
00442               counter++;
00443        }
00444        if (charactersGreek.count() != 0)
00445        {
00446               rangeSelector->insertItem( tr("Greek"));
00447               usedCharClasses.insert(counter, 20);
00448               counter++;
00449        }
00450        if (charactersGreekExtended.count() != 0)
00451        {
00452               rangeSelector->insertItem( tr("Greek Extended"));
00453               usedCharClasses.insert(counter, 21);
00454               counter++;
00455        }
00456        if (charactersCyrillic.count() != 0)
00457        {
00458               rangeSelector->insertItem( tr("Cyrillic"));
00459               usedCharClasses.insert(counter, 22);
00460               counter++;
00461        }
00462        if (charactersCyrillicSupplement.count() != 0)
00463        {
00464               rangeSelector->insertItem( tr("Cyrillic Supplement"));
00465               usedCharClasses.insert(counter, 23);
00466               counter++;
00467        }
00468        if (charactersArabic.count() != 0)
00469        {
00470               rangeSelector->insertItem( tr("Arabic"));
00471               usedCharClasses.insert(counter, 24);
00472               counter++;
00473        }
00474        if (charactersArabicPresentationFormsA.count() != 0)
00475        {
00476               rangeSelector->insertItem( tr("Arabic Extended A"));
00477               usedCharClasses.insert(counter, 25);
00478               counter++;
00479        }
00480        if (charactersArabicPresentationFormsB.count() != 0)
00481        {
00482               rangeSelector->insertItem( tr("Arabic Extended B"));
00483               usedCharClasses.insert(counter, 26);
00484               counter++;
00485        }
00486        if (charactersHebrew.count() != 0)
00487        {
00488               rangeSelector->insertItem( tr("Hebrew"));
00489               usedCharClasses.insert(counter, 27);
00490               counter++;
00491        }
00492        rangeSelector->setCurrentItem(0);
00493        connect(rangeSelector, SIGNAL(activated(int)), this, SLOT(newCharClass(int)));
00494 }
00495 
00496 void CharSelect::generatePreview(int charClass)
00497 {
00498        characters.clear();
00499        characters = allClasses[charClass];
00500        m_charTable->setCharacters(characters);
00501 }
00502 
00503 void CharSelect::newCharClass(int c)
00504 {
00505        m_characterClass = usedCharClasses[c];
00506        generatePreview(m_characterClass);
00507 }
00508 
00509 void CharSelect::newFont(int font)
00510 {
00511        QString oldFont(m_fontInUse);
00512        m_fontInUse = fontSelector->text(font);
00513        if (!m_fontInUse.isEmpty())
00514        {
00515               m_charTable->setFontInUse(m_fontInUse);
00516               m_userTable->setFontInUse(m_fontInUse);
00517               unicodeButton->setFont((*m_doc->AllFonts)[m_fontInUse]);
00518               (*m_doc->AllFonts)[m_fontInUse].increaseUsage();
00519               if (!oldFont.isEmpty())
00520                      (*m_doc->AllFonts)[oldFont].decreaseUsage();
00521               delEdit();
00522               scanFont();
00523               generatePreview(0);
00524               m_characterClass = 0;
00525               setupRangeCombo();
00526        }
00527 }
00528 
00529 void CharSelect::userNewChar(uint i)
00530 {
00531        emit insertUserSpecialChar(QChar(i));
00532 }
00533 
00534 void CharSelect::newChar(uint i)
00535 {
00536        chToIns += QChar(i);
00537        sample->setPixmap(FontSample((*m_doc->AllFonts)[m_fontInUse], 28, chToIns, paletteBackgroundColor(), true));
00538        insertButton->setEnabled(true);
00539        QString tmp;
00540        tmp.sprintf("%04X", i);
00541 }
00542 
00543 void CharSelect::delChar()
00544 {
00545        if (chToIns.length() == 0)
00546               return;
00547        if (chToIns.length() == 1)
00548        {
00549               delEdit();
00550               return;
00551        }
00552        chToIns.truncate(chToIns.length() - 1);
00553        sample->setPixmap(FontSample((*m_doc->AllFonts)[m_fontInUse], 28, chToIns, paletteBackgroundColor(), true));
00554        insertButton->setEnabled(true);
00555 }
00556 
00557 void CharSelect::delEdit()
00558 {
00559        chToIns = "";
00560        QPixmap pm(1,28);
00561        pm.fill(paletteBackgroundColor());
00562        sample->setPixmap(pm);
00563        insertButton->setEnabled(false);
00564 }
00565 
00566 void CharSelect::insChar()
00567 {
00568        emit insertSpecialChar();
00569 }
00570 
00571 void CharSelect::slot_insertSpecialChar()
00572 {
00573        if (!m_Item)
00574               return;
00575 
00576        if (m_Item->HasSel)
00577               m_Item->asTextFrame()->deleteSelectedTextFromFrame();
00578        //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
00579        for (uint a=0; a<chToIns.length(); ++a)
00580        {
00581               QChar ch = chToIns.at(a);
00582               if (ch == QChar(10))
00583                      ch = QChar(13);
00584               if (ch == QChar(9))
00585                      ch = QChar(32);
00586               m_Item->itemText.insertChars(m_Item->CPos, ch, true);
00587               m_Item->CPos += 1;
00588        }
00589        m_doc->view()->DrawNew();
00590        m_doc->changed();
00591        delEdit();
00592 }
00593 
00594 void CharSelect::slot_insertUserSpecialChar(QChar ch)
00595 {
00596        if (!m_Item)
00597               return;
00598        if (m_Item->HasSel)
00599               m_Item->asTextFrame()->deleteSelectedTextFromFrame();
00600        //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
00601        if (ch == QChar(10))
00602               ch = QChar(13);
00603        if (ch == QChar(9))
00604               ch = QChar(32);
00605        m_Item->itemText.insertChars(m_Item->CPos, ch, true);
00606        m_Item->CPos += 1;
00607        m_doc->view()->DrawNew();
00608        m_doc->changed();
00609 }
00610 
00611 bool CharSelect::eventFilter(QObject* /*obj*/, QEvent *ev)
00612 {
00613        if (ev->type() == QEvent::Show)
00614        {
00615               m_charTable->recalcCellSizes();
00616               m_userTable->recalcCellSizes();
00617 //            return true;
00618        }
00619        return false;
00620 }
00621 
00622 void CharSelect::hideCheck_clicked()
00623 {
00624        m_bigPalette->setShown(!hideCheck->isChecked());
00625        adjustSize();
00626 }
00627 
00628 void CharSelect::show()
00629 {
00630        ScrPaletteBase::show();
00631        if (m_userTable->characters().count() > 0)
00632        {
00633               hideCheck->setChecked(true);
00634               hideCheck_clicked();
00635        }
00636 }
00637 
00638 void CharSelect::setEnabled(bool state, PageItem* item)
00639 {
00640        ScrPaletteBase::setEnabled(state);
00641        m_Item = item;
00642        if (state)
00643               setDoc(m_doc);
00644 }
00645 
00646 void CharSelect::uniLoadButton_clicked()
00647 {
00648        QString f = QFileDialog::getOpenFileName(
00649                     QDir::currentDirPath(),
00650                     paletteFileMask,
00651                     this,
00652                     "loadDialog",
00653                     tr("Choose a filename to open"));
00654        if (!f.isNull())
00655               loadUserContent(f);
00656 }
00657 
00658 void CharSelect::loadUserContent(QString f)
00659 {
00660        CharClassDef newChars;
00661        QFile file(f);
00662        if (!file.exists())
00663               return;
00664        if (file.open(IO_ReadOnly))
00665        {
00666               QTextStream stream(&file);
00667               QString line;
00668               while (!stream.atEnd())
00669               {
00670                      bool ok = false;
00671                      line = stream.readLine();
00672                      if (line.left(1) == "#")
00673                             continue; // don't mess with a comment
00674                      int val = line.toInt(&ok, 10);
00675                      if (ok)
00676                             newChars.append(val);
00677                      else
00678                      {
00679                             QMessageBox::warning(this, tr("Error"),
00680                                                                 "<qt>" + tr("Error reading file %1 - file is corrupted propably.").arg(f) + "</qt>",
00681                                                                 QMessageBox::Ok, QMessageBox::NoButton);
00682                             break;
00683                      }
00684               }
00685               file.close();
00686               m_userTable->setCharacters(newChars);
00687        }
00688 }
00689 
00690 void CharSelect::uniSaveButton_clicked()
00691 {
00692        if (m_userTable->characters().count() == 0)
00693               return;
00694        QString f = QFileDialog::getSaveFileName(
00695                     QDir::currentDirPath(),
00696                     paletteFileMask,
00697                     this,
00698                     "saveDialog",
00699                     tr("Choose a filename to save under"));
00700        if (f.isNull() || !overwrite(this, f))
00701               return;
00702        saveUserContent(f);
00703 }
00704 
00705 void CharSelect::saveUserContent(QString f)
00706 {
00707        QFile file(f);
00708        if (file.open(IO_WriteOnly))
00709        {
00710               QTextStream stream(&file);
00711               CharClassDef chars = m_userTable->characters();
00712               stream << "# This is a character palette file for Scribus\n";
00713               for (CharClassDef::Iterator it = chars.begin(); it != chars.end(); ++it)
00714                      stream << (*it) << "\n";
00715               file.close();
00716        }
00717        else
00718               QMessageBox::warning(this, tr("Error"),
00719                                     "<qt>" + tr("Cannot write file %1").arg(f) + "</qt>",
00720                                     QMessageBox::Ok, QMessageBox::NoButton);
00721 }
00722 
00723 void CharSelect::uniClearButton_clicked()
00724 {
00725        if (m_userTable->characters().count() > 0
00726               &&
00727               !QMessageBox::question(this, tr("Clean the Palette?"),
00728                                     "<qt>" + tr("You will clean all characters from this palette. Are you sure?") + "</qt>",
00729                                     CommonStrings::trYesKey, CommonStrings::trNoKey,
00730                                     QString::null, 0, 1 )
00731           )
00732        {
00733               m_userTable->setCharacters(CharClassDef());
00734        }
00735 }