Back to index

scribus-ng  1.3.4.dfsg+svn20071115
story.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 /***************************************************************************
00008                           story.cpp  -  description
00009                              -------------------
00010     begin                : Tue Nov 11 2003
00011     copyright            : (C) 2003 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 #include "colorcombo.h"
00024 #include "scfonts.h"
00025 #include "story.h"
00026 #include "story.moc"
00027 #include <qtooltip.h>
00028 #include <qpixmap.h>
00029 #include <qcombobox.h>
00030 #include <qregexp.h>
00031 #include <qhbox.h>
00032 #include <qcolordialog.h>
00033 #include <qfontdialog.h>
00034 #include <qcursor.h>
00035 #include <qtextcodec.h>
00036 
00037 #include "actionmanager.h"
00038 #include "alignselect.h"
00039 #include "charselect.h"
00040 #include "colorlistbox.h"
00041 #include "commonstrings.h"
00042 #include "customfdialog.h"
00043 // #include "editformats.h"
00044 #include "fontcombo.h"
00045 #include "menumanager.h"
00046 #include "mspinbox.h"
00047 #include "pageitem.h"
00048 #include "pluginmanager.h"
00049 #include "prefscontext.h"
00050 #include "prefsmanager.h"
00051 #include "prefsfile.h"
00052 #include "scmessagebox.h"
00053 #include "scraction.h"
00054 #include "scribuscore.h"
00055 #include "search.h"
00056 #include "serializer.h"
00057 #include "shadebutton.h"
00058 #include "spalette.h"
00059 #include "styleitem.h"
00060 #include "styleselect.h"
00061 #include "stylemanager.h"
00062 #include "util.h"
00063 #include "scplugin.h"
00064 #include "text/nlsconfig.h"
00065 
00066 extern QPixmap loadIcon(QString nam);
00067 
00068 
00069 SideBar::SideBar(QWidget *pa) : QLabel(pa)
00070 {
00071        setEraseColor(QColor(255,255,255));
00072        offs = 0;
00073        editor = 0;
00074        noUpdt = true;
00075        inRep = false;
00076        pmen = new QPopupMenu(this);
00077        setMinimumWidth(fontMetrics().width( tr("No Style") )+30);
00078 }
00079 
00080 void SideBar::mouseReleaseEvent(QMouseEvent *m)
00081 {
00082        CurrentPar = editor->paragraphAt(QPoint(2, m->y()+offs));
00083        int p=0, i=0;
00084        editor->getCursorPosition(&p, &i);
00085        int pos = editor->StyledText.startOfParagraph(p) + i;
00086        ParaStyleComboBox* paraStyleCombo = new ParaStyleComboBox(this);
00087        paraStyleCombo->setDoc(editor->doc);
00088        if ((CurrentPar < static_cast<int>(editor->StyledText.nrOfParagraphs())) && (editor->StyledText.length() != 0))
00089        {
00090               int len = editor->StyledText.endOfParagraph(CurrentPar) - editor->StyledText.startOfParagraph(CurrentPar);
00091               if (len > 0)
00092                      paraStyleCombo->setFormat(editor->StyledText.paragraphStyle(pos).displayName());
00093               else
00094                      paraStyleCombo->setFormat("");
00095        }
00096        else
00097               paraStyleCombo->setFormat("");
00098        connect(paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setPStyle(const QString&)));
00099        pmen->clear();
00100        pmen->insertItem(paraStyleCombo);
00101        pmen->insertItem( tr("Edit Styles..."), this, SLOT(editStyles()));
00102        pmen->exec(QCursor::pos());
00103 }
00104 
00105 void SideBar::editStyles()
00106 {
00107        emit sigEditStyles();
00108 }
00109 
00110 void SideBar::setPStyle(const QString& name)
00111 {
00112        emit ChangeStyle(CurrentPar, name);
00113        pmen->activateItemAt(0);
00114 }
00115 
00116 void SideBar::paintEvent(QPaintEvent *e)
00117 {
00118        inRep = true;
00119        QLabel::paintEvent(e);
00120        QPainter p;
00121        p.begin(this);
00122        if ((editor != 0) && (noUpdt))
00123        {
00124               for (uint pa = 0; pa < editor->StyledText.nrOfParagraphs(); ++pa)
00125               {
00126                      QRect re = editor->paragraphRect(pa);
00127                      if (!re.isValid())
00128                             break;
00129                      re.setWidth(width()-5);
00130                      re.moveBy(5, 0);
00131                      if (((re.y()+re.height())-offs < height()) && ((re.y()+re.height())-offs > 0))
00132                             p.drawLine(0, (re.y()+re.height())-offs, width()-1, (re.y()+re.height())-offs);
00133                      if ((re.y()-offs < height()) && (re.y()-offs > 0))
00134                      {
00135                             re.setY(re.y()-offs);
00136                             QString parname = editor->StyledText.paragraphStyle(editor->StyledText.startOfParagraph(pa)).parent();
00137                             if (parname.isEmpty())
00138                                    parname = tr("No Style");
00139                             p.drawText(re, Qt::AlignLeft | Qt::AlignTop, parname);
00140                      }
00141               }
00142        }
00143        p.end();
00144        inRep = false;
00145 }
00146 
00147 void SideBar::doMove(int, int y)
00148 {
00149        offs = y;
00150        if (!inRep)
00151               update();
00152 }
00153 
00154 void SideBar::doRepaint()
00155 {
00156        if (!inRep)
00157               update();
00158 }
00159 
00160 void SideBar::setRepaint(bool r)
00161 {
00162        noUpdt = r;
00163 }
00164 
00165 SEditor::SEditor(QWidget* parent, ScribusDoc *docc, StoryEditor* parentSE) : QTextEdit(parent)
00166 {
00167        setCurrentDocument(docc);
00168        parentStoryEditor=parentSE;
00169        wasMod = false;
00170        StoredSel = false;
00171        SelCharStart = 0;
00172        SelParaStart = 0;
00173        StyledText.clear();
00174        cBuffer.clear();
00175        setUndoRedoEnabled(true);
00176        setUndoDepth(0);
00177        setTextFormat(Qt::PlainText);
00178        viewport()->setAcceptDrops(false);
00179        ClipData = 0;
00180        unicodeTextEditMode = false;
00181        connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
00182 //     connect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(SelClipChange()));
00183 }
00184 
00185 void SEditor::setCurrentDocument(ScribusDoc *docc)
00186 {
00187        doc = docc;
00188        StyledText = StoryText(docc);
00189 }
00190 
00191 void SEditor::imEndEvent(QIMEvent *e)
00192 {
00193        QString uc = e->text();
00194        if ((!uc.isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
00195        {
00196               insChars(e->text());
00197               QTextEdit::imEndEvent(e);
00198               emit SideBarUp(true);
00199               emit SideBarUpdate();
00200        }
00201 }
00202 
00203 void SEditor::keyPressEvent(QKeyEvent *k)
00204 {
00205        emit SideBarUp(false);
00206        int p=0, i=0;
00207        getCursorPosition(&p, &i);
00208        int pos = StyledText.startOfParagraph(p) + i;
00209        int keyMod=0;
00210        if (k->state() & ShiftButton)
00211               keyMod |= SHIFT;
00212        if (k->state() & ControlButton)
00213               keyMod |= CTRL;
00214        if (k->state() & AltButton)
00215               keyMod |= ALT;
00216 
00217        QString uc = k->text();
00218        switch (k->state())
00219        {
00220               case ControlButton:
00221               case ControlButton|ShiftButton:
00222               case ControlButton|Keypad:
00223               case ControlButton|ShiftButton|Keypad:
00224                      switch (k->key())
00225                      {
00226                             case Key_Delete:
00227                                    moveCursor(QTextEdit::MoveWordForward, true);
00228                                    deleteSel();
00229                                    break;
00230                             case Key_Backspace:
00231                                    moveCursor(QTextEdit::MoveWordBackward, true);
00232                                    deleteSel();
00233                                    break;
00234                             case Key_K:
00235                                    moveCursor(QTextEdit::MoveLineEnd, true);
00236                                    deleteSel();
00237                                    break;
00238                             case Key_D:
00239                                    moveCursor(QTextEdit::MoveForward, true);
00240                                    deleteSel();
00241                                    break;
00242                             case Key_H:
00243                                    moveCursor(QTextEdit::MoveBackward, true);
00244                                    deleteSel();
00245                                    break;
00246                             case Key_X:
00247                                    cut();
00248                                    return;
00249                                    break;
00250                             case Key_V:
00251                                    paste();
00252                                    return;
00253                                    break;
00254                             case Key_Y:
00255                             case Key_Z:
00256                                    emit SideBarUp(true);
00257                                    return;
00258                                    break;
00259                             case Key_C:
00260                                    copyStyledText();
00261                                    break;
00262                      }
00263                      break;
00264               case NoButton:
00265               case Keypad:
00266               case ShiftButton:
00267               case ControlButton|AltButton:
00268               case ControlButton|AltButton|ShiftButton: // Shift + AltGr on Windows for polish characters
00269                      if (unicodeTextEditMode)
00270                      {
00271                             int conv = 0;
00272                             bool ok = false;
00273                             unicodeInputString += k->text();
00274                             conv = unicodeInputString.toInt(&ok, 16);
00275                             if (!ok)
00276                             {
00277                                    unicodeTextEditMode = false;
00278                                    unicodeInputCount = 0;
00279                                    unicodeInputString = "";
00280                                    return;
00281                             }
00282                             unicodeInputCount++;
00283                             if (unicodeInputCount == 4)
00284                             {
00285                                    unicodeTextEditMode = false;
00286                                    unicodeInputCount = 0;
00287                                    unicodeInputString = "";
00288                                    if (ok)
00289                                    {
00290                                           if (conv < 31)
00291                                                  conv = 32;
00292                                           insChars(QString(QChar(conv)));
00293                                           insert(QString(QChar(conv)));
00294                                           emit SideBarUp(true);
00295                                           emit SideBarUpdate();
00296                                           return;
00297                                    }
00298                             }
00299                             else
00300                             {
00301                                    emit SideBarUp(true);
00302                                    emit SideBarUpdate();
00303                                    return;
00304                             }
00305                      }
00306                      wasMod = false;
00307                      switch (k->key())
00308                      {
00309                             case Key_Escape:
00310                                    k->ignore();
00311                                    break;
00312                             case Key_Shift:
00313                             case Key_Control:
00314                             case Key_Alt:
00315                                    wasMod = true;
00316                                    break;
00317                             case Key_F12:
00318                                    unicodeTextEditMode = true;
00319                                    unicodeInputCount = 0;
00320                                    unicodeInputString = "";
00321                                    return;
00322                                    break;
00323                             case Key_Delete:
00324                                    if (!hasSelectedText())
00325                                    {
00326                                           if (pos < StyledText.length())
00327                                                  StyledText.removeChars(pos, 1);
00328                                    }
00329                                    else
00330                                           deleteSel();
00331                                    break;
00332                             case Key_Backspace:
00333                                    if (!hasSelectedText())
00334                                    {
00335                                           if (pos > 0)
00336                                                  StyledText.removeChars(pos-1, 1);
00337                                    }
00338                                    else
00339                                           deleteSel();
00340                                    break;
00341                             case Key_Return:
00342                             case Key_Enter:
00343                                    {
00344                                           if (hasSelectedText()) {
00345                                                  pos = StyledText.startOfSelection();
00346                                                  deleteSel();
00347                                           }
00348                                           StyledText.insertChars(pos, SpecialChars::PARSEP);
00349                                    }
00350                                    break;
00351                             case Key_Left:
00352                             case Key_Right:
00353                             case Key_Prior:
00354                             case Key_Next:
00355                             case Key_Up:
00356                             case Key_Down:
00357                             case Key_Home:
00358                             case Key_End:
00359                                    break;
00360                             default:
00361                                    if ((!k->text().isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
00362                                    {
00363                                           insChars(k->text());
00364                                           QTextEdit::keyPressEvent(k);
00365                                           emit SideBarUp(true);
00366                                           emit SideBarUpdate();
00367                                    }
00368                                    return;
00369                                    break;
00370                      }
00371                      break;
00372               default:
00373                      break;
00374        }
00375        QTextEdit::keyPressEvent(k);
00376        emit SideBarUp(true);
00377        emit SideBarUpdate();
00378 }
00379 
00380 void SEditor::focusOutEvent(QFocusEvent *e)
00381 {
00382        int p,c;
00383        getCursorPosition(&p, &c);
00384        //qDebug(QString("SE focusOut: %1/%2 (%3 %4/%5)").arg(p).arg(c).arg(StoredSel).arg(SelParaStart).arg(SelCharStart));
00385        if (hasSelectedText())
00386        {
00387               getSelection(&SelParaStart, &SelCharStart, &SelParaEnd, &SelCharEnd);
00388               StoredSel = true;
00389        }
00390        else {
00391               getCursorPosition(&SelParaStart, &SelCharStart);
00392               StoredSel = false;
00393        }
00394        QTextEdit::focusOutEvent(e);
00395 }
00396 
00397 void SEditor::focusInEvent(QFocusEvent *e)
00398 {
00399        int p,c;
00400        getCursorPosition(&p, &c);
00401        //qDebug(QString("SE focusIn: %1/%2 (%3 %4/%5)").arg(p).arg(c).arg(StoredSel).arg(SelParaStart).arg(SelCharStart));
00402        if (StoredSel)
00403        {
00404               setSelection(SelParaStart, SelCharStart, SelParaEnd, SelCharEnd);
00405               StoredSel = false;
00406        }
00407        else {
00408               setCursorPosition(SelParaStart, SelCharStart);
00409               StoredSel = false;
00410        }
00411               
00412        QTextEdit::focusInEvent(e);
00413 }
00414 
00415 void SEditor::insChars(QString t)
00416 {
00417        int p=0, i=0;
00418        if (hasSelectedText())
00419               deleteSel();
00420        getCursorPosition(&p, &i);
00421        int pos = QMIN(StyledText.startOfParagraph(p) + i, StyledText.length());
00422        StyledText.insertChars(pos, t, true);
00423 }
00424 
00425 void SEditor::insStyledText()
00426 {
00427        if (cBuffer.length() == 0)
00428               return;
00429        int p=0, i=0;
00430        if (hasSelectedText())
00431               deleteSel();
00432        getCursorPosition(&p, &i);
00433        int pos = QMIN(StyledText.startOfParagraph(p) + i, StyledText.length());
00434        StyledText.insert(pos, cBuffer);
00435 }
00436 
00437 void SEditor::copyStyledText()
00438 {
00439        int PStart, PEnd, SelStart, SelEnd, start, end;
00440        getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
00441        start = StyledText.startOfParagraph(PStart) + SelStart;
00442        end = StyledText.startOfParagraph(PEnd) + SelEnd;
00443        if (start < 0 || end <= start)
00444               return;
00445        StyledText.select(start, end-start);
00446        cBuffer.clear();
00447        cBuffer.insert(0, StyledText, true);
00448 }
00449 
00450 void SEditor::saveItemText(PageItem *currItem)
00451 {
00452        currItem->CPos = 0;
00453        currItem->itemText.clear();
00454        currItem->itemText.setDefaultStyle(StyledText.defaultStyle());
00455        currItem->itemText.append(StyledText);
00456        
00457 /* uh... FIXME
00458               if (ch == SpecialChars::OBJECT)
00459                      {
00460                             PageItem* embedded = chars->at(c)->cembedded;
00461                             currItem->doc()->FrameItems.append(embedded);
00462                             if (embedded->Groups.count() != 0)
00463                             {
00464                                    for (uint ga=0; ga<FrameItems.count(); ++ga)
00465                                    {
00466                                           if (FrameItems.at(ga)->Groups.count() != 0)
00467                                           {
00468                                                  if (FrameItems.at(ga)->Groups.top() == embedded->Groups.top())
00469                                                  {
00470                                                         if (FrameItems.at(ga)->ItemNr != embedded->ItemNr)
00471                                                         {
00472                                                                if (currItem->doc()->FrameItems.find(FrameItems.at(ga)) == -1)
00473                                                                       currItem->doc()->FrameItems.append(FrameItems.at(ga));
00474                                                         }
00475                                                  }
00476                                           }
00477                                    }
00478                             }
00479                             currItem->itemText.insertObject(pos, embedded);
00480                      }
00481 */
00482 }
00483 
00484 void SEditor::setAlign(int align)
00485 {
00486        switch (align)
00487        {
00488        case 0:
00489               setAlignment(Qt::AlignLeft);
00490               break;
00491        case 1:
00492               setAlignment(Qt::AlignCenter);
00493               break;
00494        case 2:
00495               setAlignment(Qt::AlignRight);
00496               break;
00497        case 3:
00498        case 4:
00499               setAlignment(Qt::AlignJustify);
00500               break;
00501        default:
00502               break;
00503        }
00504 }
00505 
00506 
00507 void SEditor::loadItemText(PageItem *currItem)
00508 {
00509        StyledText.clear();
00510        FrameItems.clear();
00511        StyledText.append(currItem->itemText);
00512        updateAll();
00513        int npars = currItem->itemText.nrOfParagraphs();
00514        SelParaStart = 0;
00515        while (currItem->CPos >= (SelCharStart = currItem->itemText.endOfParagraph(SelParaStart))
00516                  && SelParaStart < npars)
00517               ++SelParaStart;
00518        if (currItem->CPos < SelCharStart)
00519               SelCharStart = currItem->CPos;
00520        SelCharStart -= currItem->itemText.startOfParagraph(SelParaStart);
00521        StoredSel = false;
00522        //qDebug("SE::loadItemText: cursor");
00523        setCursorPosition(SelParaStart, SelCharStart);
00524        emit setProps(SelParaStart, SelCharStart);
00525 }
00526 
00527 void SEditor::loadText(QString tx, PageItem *currItem)
00528 {
00529        setUpdatesEnabled(false);
00530        QString Text = "";
00531        StyledText.clear();
00532        StyledText.setDefaultStyle(currItem->itemText.defaultStyle());
00533        StyledText.insertChars(0, tx);
00534        updateAll();
00535        if (StyledText.length() != 0)
00536               emit setProps(0, 0);
00537        //qDebug("SE::loadText: cursor");
00538        setCursorPosition(0, 0);
00539 }
00540 
00541 void SEditor::updateAll()
00542 {
00543        clear();
00544        if (StyledText.length() == 0)
00545               return;
00546        setUpdatesEnabled(false);
00547        int p=0, i=0;
00548        getCursorPosition(&p, &i);
00549        QString Text = "";
00550        QString chars;
00551        int Csty = StyledText.charStyle(0).effects();
00552        int Ali = StyledText.paragraphStyle(0).alignment();
00553        setAlign(Ali);
00554        setStyle(Csty);
00555        for (uint pa = 0; pa < StyledText.nrOfParagraphs(); ++pa)
00556        {
00557               int start = StyledText.startOfParagraph(pa);
00558               int end = StyledText.endOfParagraph(pa);
00559               const ParagraphStyle& pstyle(StyledText.paragraphStyle(start));
00560               Ali = pstyle.alignment();
00561               setAlign(Ali);
00562               if (start >= end && pa < StyledText.nrOfParagraphs()-1)
00563               {
00564                      Text += "\n";
00565                      continue;
00566               }
00567               for (int a = start; a < end; ++a)
00568               {
00569                      const CharStyle& cstyle(StyledText.charStyle(a));
00570                      const QChar ch = StyledText.text(a);
00571                      if (Csty != cstyle.effects() ||
00572                             ch == SpecialChars::OBJECT ||
00573                             ch == SpecialChars::PAGENUMBER ||
00574                             ch == SpecialChars::NBSPACE ||
00575                             ch == SpecialChars::FRAMEBREAK ||
00576                             ch == SpecialChars::COLBREAK ||
00577                             ch == SpecialChars::NBHYPHEN ||
00578                             ch == SpecialChars::LINEBREAK)
00579                      {
00580                             setAlign(Ali);
00581                             setStyle(Csty);
00582                             insert(Text);
00583                             Text = "";
00584                             Csty = cstyle.effects();
00585                      }
00586 
00587                      if (ch == SpecialChars::OBJECT)
00588                      {
00589                             setFarbe(true);
00590                             insert("@");
00591                             setFarbe(false);
00592                      }
00593                      else if (ch == SpecialChars::PAGENUMBER)
00594                      {
00595                             setFarbe(true);
00596                             insert("#");
00597                             setFarbe(false);
00598                      }
00599                      else if (ch == SpecialChars::NBSPACE)
00600                      {
00601                             setFarbe(true);
00602                             insert("_");
00603                             setFarbe(false);
00604                      }
00605                      else if (ch == SpecialChars::FRAMEBREAK)
00606                      {
00607                             setFarbe(true);
00608                             insert("|");
00609                             setFarbe(false);
00610                      }
00611                      else if (ch == SpecialChars::COLBREAK)
00612                      {
00613                             setFarbe(true);
00614                             insert("^");
00615                             setFarbe(false);
00616                      }
00617                      else if (ch == SpecialChars::NBHYPHEN)
00618                      {
00619                             setFarbe(true);
00620                             insert("=");
00621                             setFarbe(false);
00622                      }
00623                      else if (ch == SpecialChars::LINEBREAK)
00624                      {
00625                             setFarbe(true);
00626                             insert("*");
00627                             setFarbe(false);
00628                      }
00629                      else
00630                             Text += ch;
00631               }
00632               if (pa < StyledText.nrOfParagraphs()-1)
00633                      Text += "\n";
00634        }
00635        setAlign(Ali);
00636        setStyle(Csty);
00637        insert(Text);
00638        setCursorPosition(p, i);
00639        setUpdatesEnabled(true);
00640        //CB Removed to fix 2083 setCursorPosition(p, i);
00641 }
00642 
00643 
00644 void SEditor::updateFromChars(int pa)
00645 {
00646        int start = StyledText.startOfParagraph(pa);
00647        int end = StyledText.endOfParagraph(pa);
00648        if (start >= end)
00649               return;
00650        setUpdatesEnabled(false);
00651        int SelStart = 0;
00652        int SelEnd = 0;
00653        int p=0, i=0;
00654        getCursorPosition(&p, &i);
00655        removeSelection();
00656        int Csty = StyledText.charStyle(start).effects();
00657        for (int a = start; a < end; ++a)
00658        {
00659               if (Csty == StyledText.charStyle(a).effects())
00660                      SelEnd++;
00661               else
00662               {
00663                      setSelection(pa, SelStart, pa, SelEnd);
00664                      setStyle(Csty);
00665                      removeSelection();
00666                      Csty = StyledText.charStyle(a).effects();
00667                      SelStart = SelEnd;
00668                      SelEnd++;
00669               }
00670        }
00671        setSelection(pa, SelStart, pa, SelEnd);
00672        setStyle(Csty);
00673        removeSelection();
00674        setAlign(StyledText.paragraphStyle(start).alignment());
00675        setUpdatesEnabled(true);
00676        //qDebug(QString("SE::updateFromChars: cursor %1/%2").arg(p).arg(i));
00677        setCursorPosition(p, i);
00678 }
00679 
00680 /* updates the internal StyledText structure, applies 'newStyle' to the selection */
00681 void SEditor::updateSel(const ParagraphStyle& newStyle)
00682 {
00683        int PStart, PEnd, SelStart, SelEnd, start;
00684        if (StoredSel)
00685        {
00686               //qDebug("SE::updateSel: setsel");
00687               setSelection(SelParaStart, SelCharStart, SelParaEnd, SelCharEnd);
00688               StoredSel = false;
00689        }
00690        getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
00691        for (int pa=PStart; pa <= PEnd; ++pa)
00692        {
00693               start = StyledText.startOfParagraph(PStart) + SelStart;
00694               StyledText.applyStyle(start, newStyle);
00695        }
00696 }
00697 
00698 void SEditor::updateSel(const CharStyle& newStyle)
00699 {
00700        int PStart, PEnd, SelStart, SelEnd, start, end;
00701        if (StoredSel)
00702        {
00703               setSelection(SelParaStart, SelCharStart, SelParaEnd, SelCharEnd);
00704               StoredSel = false;
00705        }
00706        getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
00707        start = StyledText.startOfParagraph(PStart) + SelStart;
00708        end = StyledText.startOfParagraph(PEnd) + SelEnd;
00709        if (start >= 0 && start < end)
00710               StyledText.applyCharStyle(start, end-start, newStyle);
00711 }
00712 
00713 
00714 void SEditor::deleteSel()
00715 {
00716        int PStart, PEnd, SelStart, SelEnd, start, end;
00717        getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
00718        start = StyledText.startOfParagraph(PStart) + SelStart;
00719        end = StyledText.startOfParagraph(PEnd) + SelEnd;
00720        if (end > start)
00721               StyledText.removeChars(start, end-start);
00722        //qDebug("SE::deleteSel: cursor");
00723        setCursorPosition(PStart, SelStart);
00724 }
00725 
00726 void SEditor::setStyle(int Csty)
00727 {
00728        if (Csty & 8)
00729               setUnderline(true);
00730        else
00731               setUnderline(false);
00732        QFont f = currentFont();
00733        if (Csty & 16)
00734               f.setStrikeOut(true);
00735        else
00736               f.setStrikeOut(false);
00737        setCurrentFont(f);
00738        if (Csty & 1)
00739               setVerticalAlignment(AlignSuperScript);
00740        else if (Csty & 2)
00741               setVerticalAlignment(AlignSubScript);
00742        else
00743               setVerticalAlignment(AlignNormal);
00744 }
00745 
00746 void SEditor::setFarbe(bool marker)
00747 {
00748        QColor tmp;
00749        if (marker)
00750               tmp = QColor(red);
00751        else
00752               tmp = QColor(black);
00753        setColor(tmp);
00754 }
00755 
00756 void SEditor::copy()
00757 {
00758        emit SideBarUp(false);
00759        if ((hasSelectedText()) && (!selectedText().isEmpty()))
00760        {
00761               disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
00762 //            disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(SelClipChange()));
00763               copyStyledText();
00764               QApplication::clipboard()->setText(tBuffer, QClipboard::Clipboard);
00765               ClipData = 1;
00766               connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
00767 //            connect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(SelClipChange()));
00768               emit PasteAvail();
00769        }
00770        emit SideBarUp(true);
00771 }
00772 
00773 void SEditor::cut()
00774 {
00775        copy();
00776        emit SideBarUp(false);
00777        if (hasSelectedText())
00778        {
00779               deleteSel();
00780               removeSelectedText();
00781        }
00782        emit SideBarUp(true);
00783        emit SideBarUpdate();
00784 }
00785 
00786 void SEditor::paste()
00787 {
00788        emit SideBarUp(false);
00789        int currentPara, currentCharPos;
00790        QString data = "";
00791        int newParaCount, lengthLastPara;
00792        int advanceLen = 0;
00793 //     bool inserted=false;
00794        getCursorPosition(&currentPara, &currentCharPos);
00795        if (ClipData == 1)
00796        {
00797               advanceLen = cBuffer.length();
00798               insStyledText();
00799        }
00800        else
00801        {
00802 //            QString data = QApplication::clipboard()->text(QClipboard::Selection);
00803 //            if (data.isNull())
00804               data = QApplication::clipboard()->text(QClipboard::Clipboard);
00805               if (!data.isNull())
00806               {
00807                      data.replace(QRegExp("\r"), "");
00808                      newParaCount=data.contains("\n");
00809                      lengthLastPara=data.length()-data.findRev("\n");
00810                      data.replace(QRegExp("\n"), SpecialChars::PARSEP);
00811 //                   inserted=true;
00812                      advanceLen = data.length() - newParaCount;
00813                      insChars(data);
00814                      ClipData = 2;
00815                      emit PasteAvail();
00816               }
00817               else
00818               {
00819                      emit SideBarUp(true);
00820                      return;
00821               }
00822        }
00823        updateAll();
00824        setUpdatesEnabled(false);
00825        //qDebug("SE::paste: cursor");
00826        setCursorPosition(currentPara, currentCharPos);
00827        for (int a = 0; a < advanceLen; ++a)
00828        {
00829               moveCursor(QTextEdit::MoveForward, false);
00830        }
00831        setUpdatesEnabled(true);
00832 //     if (inserted)
00833 //            setCursorPosition(currentPara+newParaCount,(newParaCount==0?currentCharPos:0)+lengthLastPara-1);
00834        sync();
00835        repaintContents();
00836        emit SideBarUp(true);
00837        emit SideBarUpdate();
00838 }
00839 
00840 QPopupMenu* SEditor::createPopupMenu(const QPoint & pos)
00841 {
00842        QPopupMenu *p = QTextEdit::createPopupMenu(pos);
00843        p->removeItemAt(0);
00844        p->removeItemAt(0);
00845        p->removeItemAt(0);
00846        p->removeItemAt(3);
00847        return p;
00848 }
00849 
00850 void SEditor::SelClipChange()
00851 {
00852        ClipData = 3;
00853        emit PasteAvail();
00854 }
00855 
00856 void SEditor::ClipChange()
00857 {
00858        ClipData = 2;
00859        emit PasteAvail();
00860 }
00861 
00862 /* Toolbar for Fill Colour */
00863 SToolBColorF::SToolBColorF(QMainWindow* parent, ScribusDoc *doc) : QToolBar( tr("Fill Color Settings"), parent)
00864 {
00865        FillIcon = new QLabel( "", this, "FillIcon" );
00866        FillIcon->setPixmap(loadIcon("16/color-fill.png"));
00867        FillIcon->setScaledContents( false );
00868        TxFill = new ColorCombo( false, this, "TxFill" );
00869        PM2 = new ShadeButton(this);
00870        setCurrentDocument(doc);
00871        //TxFill->listBox()->setMinimumWidth(TxFill->listBox()->maxItemWidth()+24);
00872        connect(TxFill, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00873        connect(PM2, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00874 
00875        languageChange();
00876 }
00877 
00878 void SToolBColorF::languageChange()
00879 {
00880        QToolTip::remove(TxFill);
00881        QToolTip::remove(PM2);
00882        QToolTip::add(TxFill, tr( "Color of text fill" ));
00883        QToolTip::add(PM2, tr( "Saturation of color of text fill" ));
00884 
00885 
00886 
00887 }
00888 
00889 void SToolBColorF::setCurrentDocument(ScribusDoc *doc)
00890 {
00891        TxFill->clear();
00892        TxFill->insertItem(CommonStrings::tr_NoneColor);
00893        if (doc!=NULL)
00894               TxFill->insertItems(doc->PageColors, ColorCombo::smallPixmaps);
00895        resize(minimumSizeHint());
00896 }
00897 
00898 void SToolBColorF::SetColor(int c)
00899 {
00900        disconnect(TxFill, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00901        TxFill->setCurrentItem(c);
00902        connect(TxFill, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00903 }
00904 
00905 void SToolBColorF::SetShade(int s)
00906 {
00907        disconnect(PM2, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00908        PM2->setValue(s);
00909        connect(PM2, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00910 }
00911 
00912 void SToolBColorF::newShadeHandler()
00913 {
00914        emit NewColor(TxFill->currentItem(), PM2->getValue());
00915 }
00916 
00917 /* Toolbar for Stroke Colour */
00918 SToolBColorS::SToolBColorS(QMainWindow* parent, ScribusDoc *doc) : QToolBar( tr("Stroke Color Settings"), parent)
00919 {
00920        StrokeIcon = new QLabel( "", this, "StrokeIcon" );
00921        StrokeIcon->setPixmap(loadIcon("16/color-stroke.png"));
00922        StrokeIcon->setScaledContents( false );
00923        TxStroke = new ColorCombo( false, this, "TxStroke" );
00924        PM1 = new ShadeButton(this);
00925        setCurrentDocument(doc);
00926        //TxStroke->listBox()->setMinimumWidth(TxStroke->listBox()->maxItemWidth()+24);
00927        connect(TxStroke, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00928        connect(PM1, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00929 
00930        languageChange();
00931 }
00932 
00933 void SToolBColorS::languageChange()
00934 {
00935        QToolTip::remove(TxStroke);
00936        QToolTip::remove(PM1);
00937        QToolTip::add(TxStroke, tr("Color of text stroke"));
00938        QToolTip::add(PM1, tr("Saturation of color of text stroke"));
00939 }
00940 
00941 void SToolBColorS::setCurrentDocument(ScribusDoc *doc)
00942 {
00943        TxStroke->clear();
00944        TxStroke->insertItem(CommonStrings::tr_NoneColor);
00945        if (doc!=NULL)
00946               TxStroke->insertItems(doc->PageColors, ColorCombo::smallPixmaps);
00947        resize(minimumSizeHint());
00948 }
00949 
00950 void SToolBColorS::SetColor(int c)
00951 {
00952        disconnect(TxStroke, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00953        TxStroke->setCurrentItem(c);
00954        connect(TxStroke, SIGNAL(activated(int)), this, SLOT(newShadeHandler()));
00955 }
00956 
00957 void SToolBColorS::SetShade(int s)
00958 {
00959        disconnect(PM1, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00960        PM1->setValue(s);
00961        connect(PM1, SIGNAL(clicked()), this, SLOT(newShadeHandler()));
00962 }
00963 
00964 void SToolBColorS::newShadeHandler()
00965 {
00966        emit NewColor(TxStroke->currentItem(), PM1->getValue());
00967 }
00968 
00969 /* Toolbar for Character Style Settings */
00970 SToolBStyle::SToolBStyle(QMainWindow* parent) : QToolBar( tr("Character Settings"), parent)
00971 {
00972        SeStyle = new StyleSelect(this);
00973        trackingLabel = new QLabel( this, "trackingLabel" );
00974        trackingLabel->setText("");
00975        trackingLabel->setPixmap(loadIcon("textkern.png"));
00976        Extra = new MSpinBox( this, 1 );
00977        Extra->setValues( -300, 300, 10, 0);
00978        Extra->setSuffix( tr( " %" ) );
00979 
00980        connect(SeStyle, SIGNAL(State(int)), this, SIGNAL(newStyle(int)));
00981        connect(Extra, SIGNAL(valueChanged(int)), this, SLOT(newKernHandler()));
00982        connect(SeStyle->ShadowVal->Xoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
00983        connect(SeStyle->ShadowVal->Yoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
00984        connect(SeStyle->OutlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newOutlineHandler()));
00985        connect(SeStyle->UnderlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
00986        connect(SeStyle->UnderlineVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
00987        connect(SeStyle->StrikeVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
00988        connect(SeStyle->StrikeVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
00989 
00990        languageChange();
00991 }
00992 
00993 void SToolBStyle::languageChange()
00994 {
00995        QToolTip::remove(Extra);
00996        QToolTip::add(Extra, tr( "Manual Tracking" ));
00997 }
00998 
00999 void SToolBStyle::newStrikeHandler()
01000 {
01001        int x = qRound(SeStyle->StrikeVal->LPos->value() * 10.0);
01002        int y = qRound(SeStyle->StrikeVal->LWidth->value() * 10.0);
01003 //     emit newUnderline(x, y);
01004        emit newStrike(x, y);
01005 }
01006 
01007 void SToolBStyle::newUnderlineHandler()
01008 {
01009        int x = qRound(SeStyle->UnderlineVal->LPos->value() * 10.0);
01010        int y = qRound(SeStyle->UnderlineVal->LWidth->value() * 10.0);
01011        emit newUnderline(x, y);
01012 }
01013 
01014 void SToolBStyle::newOutlineHandler()
01015 {
01016        int x = qRound(SeStyle->OutlineVal->LWidth->value() * 10.0);
01017        emit newOutline(x);
01018 }
01019 
01020 void SToolBStyle::newShadowHandler()
01021 {
01022        int x = qRound(SeStyle->ShadowVal->Xoffset->value() * 10.0);
01023        int y = qRound(SeStyle->ShadowVal->Yoffset->value() * 10.0);
01024        emit NewShadow(x, y);
01025 }
01026 
01027 void SToolBStyle::newKernHandler()
01028 {
01029        emit NewKern(qRound(Extra->value() * 10.0));
01030 }
01031 
01032 void SToolBStyle::setOutline(int x)
01033 {
01034        disconnect(SeStyle->OutlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newOutlineHandler()));
01035        SeStyle->OutlineVal->LWidth->setValue(x / 10.0);
01036        connect(SeStyle->OutlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newOutlineHandler()));
01037 }
01038 
01039 void SToolBStyle::setStrike(int p, int w)
01040 {
01041        disconnect(SeStyle->StrikeVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
01042        disconnect(SeStyle->StrikeVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
01043        SeStyle->StrikeVal->LWidth->setValue(w / 10.0);
01044        SeStyle->StrikeVal->LPos->setValue(p / 10.0);
01045        connect(SeStyle->StrikeVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
01046        connect(SeStyle->StrikeVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newStrikeHandler()));
01047 }
01048 
01049 void SToolBStyle::setUnderline(int p, int w)
01050 {
01051        disconnect(SeStyle->UnderlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
01052        disconnect(SeStyle->UnderlineVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
01053        SeStyle->UnderlineVal->LWidth->setValue(w / 10.0);
01054        SeStyle->UnderlineVal->LPos->setValue(p / 10.0);
01055        connect(SeStyle->UnderlineVal->LWidth, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
01056        connect(SeStyle->UnderlineVal->LPos, SIGNAL(valueChanged(int)), this, SLOT(newUnderlineHandler()));
01057 }
01058 
01059 void SToolBStyle::SetShadow(int x, int y)
01060 {
01061        disconnect(SeStyle->ShadowVal->Xoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
01062        disconnect(SeStyle->ShadowVal->Yoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
01063        SeStyle->ShadowVal->Xoffset->setValue(x / 10.0);
01064        SeStyle->ShadowVal->Yoffset->setValue(y / 10.0);
01065        connect(SeStyle->ShadowVal->Xoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
01066        connect(SeStyle->ShadowVal->Yoffset, SIGNAL(valueChanged(int)), this, SLOT(newShadowHandler()));
01067 }
01068 
01069 void SToolBStyle::SetStyle(int s)
01070 {
01071        disconnect(SeStyle, SIGNAL(State(int)), this, SIGNAL(newStyle(int)));
01072        SeStyle->setStyle(s);
01073        connect(SeStyle, SIGNAL(State(int)), this, SIGNAL(newStyle(int)));
01074 }
01075 
01076 void SToolBStyle::SetKern(int k)
01077 {
01078        disconnect(Extra, SIGNAL(valueChanged(int)), this, SLOT(newKernHandler()));
01079        Extra->setValue(k / 10.0);
01080        connect(Extra, SIGNAL(valueChanged(int)), this, SLOT(newKernHandler()));
01081 }
01082 
01083 /* Toolbar for alignment of Paragraphs */
01084 SToolBAlign::SToolBAlign(QMainWindow* parent) : QToolBar( tr("Style Settings"), parent)
01085 {
01086        GroupAlign = new AlignSelect(this);
01087        paraStyleCombo = new ParaStyleComboBox(this);
01088        connect(paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SIGNAL(newParaStyle(const QString& )));
01089        connect(GroupAlign, SIGNAL(State(int)), this, SIGNAL(newAlign(int )));
01090 
01091        languageChange();
01092 }
01093 
01094 void SToolBAlign::languageChange()
01095 {
01096        QToolTip::remove(paraStyleCombo);
01097        QToolTip::add(paraStyleCombo, tr("Style of current paragraph"));
01098 }
01099 
01100 
01101 void SToolBAlign::SetAlign(int s)
01102 {
01103        disconnect(GroupAlign, SIGNAL(State(int)), this, SIGNAL(newAlign(int )));
01104        GroupAlign->setStyle(s);
01105        connect(GroupAlign, SIGNAL(State(int)), this, SIGNAL(newAlign(int )));
01106 }
01107 
01108 void SToolBAlign::SetParaStyle(int s)
01109 {
01110        disconnect(paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SIGNAL(newParaStyle(const QString& )));
01111        paraStyleCombo->selFormat(s);
01112        connect(paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SIGNAL(newParaStyle(const QString& )));
01113 }
01114 
01115 
01116 /* Toolbar for Font related Settings */
01117 SToolBFont::SToolBFont(QMainWindow* parent) : QToolBar( tr("Font Settings"), parent)
01118 {
01119        Fonts = new FontCombo(this);
01120        Fonts->setMaximumSize(190, 30);
01121        Size = new MSpinBox( 0.5, 2048, this, 1 );
01122        PrefsManager* prefsManager = PrefsManager::instance();
01123        Size->setPrefix( "" );
01124        Size->setSuffix( tr( " pt" ) );
01125        Size->setValue(prefsManager->appPrefs.toolSettings.defSize / 10.0);
01126        ScaleTxt = new QLabel("", this, "ScaleTxt" );
01127        ScaleTxt->setPixmap(loadIcon("textscaleh.png"));
01128        ChScale = new MSpinBox( 10, 400,  this, 1 );
01129        ChScale->setValue( 100 );
01130        ChScale->setSuffix( tr( " %" ) );
01131        ScaleTxtV = new QLabel("", this, "ScaleTxtV" );
01132        ScaleTxtV->setPixmap(loadIcon("textscalev.png"));
01133        ChScaleV = new MSpinBox( 10, 400, this, 1 );
01134        ChScaleV->setValue( 100 );
01135        ChScaleV->setSuffix( tr( " %" ) );
01136 
01137        connect(ChScale, SIGNAL(valueChanged(int)), this, SIGNAL(NewScale(int)));
01138        connect(ChScaleV, SIGNAL(valueChanged(int)), this, SIGNAL(NewScaleV(int)));
01139        connect(Fonts, SIGNAL(activated(const QString &)), this, SIGNAL(NewFont(const QString &)));
01140        connect(Size, SIGNAL(valueChanged(int)), this, SLOT(newSizeHandler()));
01141 }
01142 
01143 void SToolBFont::languageChange()
01144 {
01145        QToolTip::remove(Fonts);
01146        QToolTip::remove(Size);
01147        QToolTip::remove(ChScale);
01148        QToolTip::remove(ChScaleV);
01149        QToolTip::add(Fonts, tr("Font of selected text"));
01150        QToolTip::add(Size, tr("Font Size"));
01151        QToolTip::add(ChScale, tr("Scaling width of characters"));
01152        QToolTip::add(ChScaleV, tr("Scaling height of characters"));
01153 }
01154 
01155 void SToolBFont::SetFont(QString f)
01156 {
01157        disconnect(Fonts, SIGNAL(activated(const QString &)), this, SIGNAL(NewFont(const QString &)));
01158        Fonts->setCurrentText(f);
01159        connect(Fonts, SIGNAL(activated(const QString &)), this, SIGNAL(NewFont(const QString &)));
01160 }
01161 
01162 void SToolBFont::SetSize(double s)
01163 {
01164        disconnect(Size, SIGNAL(valueChanged(int)), this, SLOT(newSizeHandler()));
01165        Size->setValue(s / 10.0);
01166        connect(Size, SIGNAL(valueChanged(int)), this, SLOT(newSizeHandler()));
01167 }
01168 
01169 void SToolBFont::SetScale(int s)
01170 {
01171        disconnect(ChScale, SIGNAL(valueChanged(int)), this, SIGNAL(NewScale(int)));
01172        ChScale->setValue(s / 10.0);
01173        connect(ChScale, SIGNAL(valueChanged(int)), this, SIGNAL(NewScale(int)));
01174 }
01175 
01176 void SToolBFont::SetScaleV(int s)
01177 {
01178        disconnect(ChScaleV, SIGNAL(valueChanged(int)), this, SIGNAL(NewScaleV(int)));
01179        ChScaleV->setValue(s / 10.0);
01180        connect(ChScaleV, SIGNAL(valueChanged(int)), this, SIGNAL(NewScaleV(int)));
01181 }
01182 
01183 void SToolBFont::newSizeHandler()
01184 {
01185        emit NewSize(Size->value());
01186 }
01187 
01188 /* Main Story Editor Class */
01189 // StoryEditor::StoryEditor(QWidget* parent, ScribusDoc *docc, PageItem *ite)
01190 //     : QMainWindow(parent, "StoryEditor", WType_TopLevel) //  WType_Dialog) //WShowModal |
01191 // {
01192 //     prefsManager=PrefsManager::instance();
01193 //     currDoc = docc;
01194 //     seMenuMgr=NULL;
01195 //     buildGUI();
01196 //     currItem = ite;
01197 // //  charSelect = NULL;
01198 //     firstSet = false;
01199 //     activFromApp = true;
01200 //     Editor->loadItemText(ite);
01201 //     Editor->getCursorPosition(&CurrPara, &CurrChar);
01202 //     EditorBar->setRepaint(true);
01203 //     EditorBar->doRepaint();
01204 //     updateProps(CurrPara, CurrChar);
01205 //     updateStatus();
01206 //     textChanged = false;
01207 //     disconnectSignals();
01208 //     connectSignals();
01209 //     Editor->setFocus();
01210 //     Editor->setFarbe(false);
01211 //     blockUpdate = false;
01212 //     loadPrefs();
01213 //     // hack to keep charPalette visible. See destructor too - PV
01214 //     ScCore->primaryMainWindow()->charPalette->reparent(this, QPoint(0, 0));
01215 // }
01216 
01217 /* Main Story Editor Class, no current document */
01218 StoryEditor::StoryEditor(QWidget* parent) : QMainWindow(parent, "StoryEditor", WType_TopLevel), // WType_Dialog) //WShowModal |
01219        activFromApp(true),
01220        currDoc(NULL),
01221        currItem(NULL),
01222        textChanged(false),
01223        firstSet(false),
01224        blockUpdate(false),
01225        CurrPara(0),
01226        CurrChar(0),
01227        charSelect(NULL),
01228        charSelectUsed(false)
01229 {
01230        prefsManager=PrefsManager::instance();
01231 #ifdef Q_WS_MAC
01232        noIcon = loadIcon("noicon.xpm");
01233 #endif
01234        buildGUI();
01235        /*
01236        //Editor->loadItemText(ite);
01237        updateProps(0,0);
01238        updateStatus();
01239        */
01240        Editor->setFocus();
01241        Editor->setFarbe(false);
01242        loadPrefs();
01243 }
01244 
01245 StoryEditor::~StoryEditor()
01246 {
01247        savePrefs();
01248 }
01249 
01250 void StoryEditor::showEvent(QShowEvent *)
01251 {
01252        charSelect = new CharSelect(this);
01253        charSelect->userTable()->setCharacters(
01254                                             ScCore->primaryMainWindow()->charPalette->userTable()->characters());
01255        connect(charSelect, SIGNAL(insertSpecialChar()),
01256                      this, SLOT(slot_insertSpecialChar()));
01257        connect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
01258                      this, SLOT(slot_insertUserSpecialChar(QChar)));
01259 }
01260 
01261 void StoryEditor::hideEvent(QHideEvent *)
01262 {
01263        if (charSelectUsed)
01264               ScCore->primaryMainWindow()->charPalette->userTable()->setCharacters(
01265                                                         charSelect->userTable()->characters());
01266        if (charSelect->isShown())
01267               charSelect->close();
01268        disconnect(charSelect, SIGNAL(insertSpecialChar()),
01269                         this, SLOT(slot_insertSpecialChar()));
01270        disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
01271                         this, SLOT(slot_insertUserSpecialChar(QChar)));
01272        delete charSelect;
01273        charSelect = NULL;
01274 }
01275 
01276 void StoryEditor::savePrefs()
01277 {
01278        // save prefs
01279        QRect geo = geometry();
01280        prefs->set("left", geo.left());
01281        prefs->set("top", geo.top());
01282        prefs->set("width", width());
01283        prefs->set("height", height());
01284        QValueList<int> splitted = EdSplit->sizes();
01285        prefs->set("side", splitted[0]);
01286        prefs->set("main", splitted[1]);
01287 }
01288 
01289 void StoryEditor::loadPrefs()
01290 {
01291        prefs = PrefsManager::instance()->prefsFile->getPluginContext("StoryEditor");
01292        int vleft   = QMAX(-80, prefs->getInt("left", 10));
01293 #if defined(QT_MAC) || defined(_WIN32)
01294        int vtop    = QMAX(64, prefs->getInt("top", 10));
01295 #else
01296        int vtop    = QMAX(-80, prefs->getInt("top", 10));
01297 #endif
01298        int vwidth  = QMAX(600, prefs->getInt("width", 600));
01299        int vheight = QMAX(400, prefs->getInt("height", 400));
01300        // Check values against current screen size
01301        QRect scr = QApplication::desktop()->screen()->geometry();
01302        QSize gStrut = QApplication::globalStrut();
01303        if ( vleft >= scr.width() )
01304               vleft = 0;
01305        if ( vtop >= scr.height() )
01306               vtop = 64;
01307        if ( vwidth >= scr.width() )
01308               vwidth = QMAX( gStrut.width(), scr.width() - vleft );
01309        if ( vheight >= scr.height() )
01310               vheight = QMAX( gStrut.height(), scr.height() - vtop );
01311        setGeometry(vleft, vtop, vwidth, vheight);
01312        int side = prefs->getInt("side", -1);
01313        int txtarea = prefs->getInt("main", -1);
01314        if ((side != -1) && (txtarea != -1))
01315        {
01316               QValueList<int> splitted;
01317               splitted.append(side);
01318               splitted.append(txtarea);
01319               EdSplit->setSizes(splitted);
01320        }
01321 }
01322 
01323 void StoryEditor::initActions()
01324 {
01325        //File Menu
01326        seActions.insert("fileNew", new ScrAction(QIconSet(loadIcon("16/document-new.png"), loadIcon("22/document-new.png")), "", CTRL+Key_N, this, "fileNew"));
01327        seActions.insert("fileRevert", new ScrAction(QIconSet(loadIcon("reload16.png"), loadIcon("reload.png")), "", QKeySequence(), this, "fileRevert"));
01328        seActions.insert("fileSaveToFile", new ScrAction(QIconSet(loadIcon("16/document-save.png"), loadIcon("22/document-save.png")), "", QKeySequence(), this, "fileSaveToFile"));
01329        seActions.insert("fileLoadFromFile", new ScrAction(QIconSet(loadIcon("16/document-open.png"),  loadIcon("22/document-open.png")), "", QKeySequence(), this, "fileLoadFromFile"));
01330        seActions.insert("fileSaveDocument", new ScrAction("", CTRL+Key_S, this, "fileSaveDocument"));
01331        seActions.insert("fileUpdateAndExit", new ScrAction(QIconSet(loadIcon("ok.png"), loadIcon("ok22.png")), "", CTRL+Key_W,  this, "fileUpdateAndExit"));
01332        seActions.insert("fileExit", new ScrAction(QIconSet(loadIcon("exit.png"), loadIcon("exit22.png")), "", QKeySequence(),  this, "fileExit"));
01333 
01334        connect( seActions["fileNew"], SIGNAL(activated()), this, SLOT(Do_new()) );
01335        connect( seActions["fileRevert"], SIGNAL(activated()), this, SLOT(slotFileRevert()) );
01336        connect( seActions["fileSaveToFile"], SIGNAL(activated()), this, SLOT(SaveTextFile()) );
01337        connect( seActions["fileLoadFromFile"], SIGNAL(activated()), this, SLOT(LoadTextFile()) );
01338        connect( seActions["fileSaveDocument"], SIGNAL(activated()), this, SLOT(Do_saveDocument()) );
01339        connect( seActions["fileUpdateAndExit"], SIGNAL(activated()), this, SLOT(Do_leave2()) );
01340        connect( seActions["fileExit"], SIGNAL(activated()), this, SLOT(Do_leave()) );
01341 
01342        //Edit Menu
01343        seActions.insert("editSelectAll", new ScrAction(QIconSet(loadIcon("16/edit-select-all.png")), "", CTRL+Key_A, this, "editSelectAll"));
01344        seActions.insert("editCut", new ScrAction(QIconSet(loadIcon("16/edit-cut.png")), "", CTRL+Key_X, this, "editCut"));
01345        seActions.insert("editCopy", new ScrAction(QIconSet(loadIcon("16/edit-copy.png")), "", CTRL+Key_C, this, "editCopy"));
01346        seActions.insert("editPaste", new ScrAction(QIconSet(loadIcon("16/edit-paste.png")), "", CTRL+Key_V, this, "editPaste"));
01347        seActions.insert("editClear", new ScrAction(QIconSet(loadIcon("16/edit-delete.png")), "", Key_Delete, this, "editClear"));
01348        seActions.insert("editSearchReplace", new ScrAction(QIconSet(loadIcon("16/edit-find-replace.png")), "", QKeySequence(), this, "editSearchReplace"));
01349        seActions.insert("editEditStyle", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "editEditStyle"));
01350        seActions.insert("editFontPreview", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "editFontPreview"));
01351        seActions.insert("editUpdateFrame", new ScrAction(QIconSet(loadIcon("compfile16.png"),loadIcon("compfile.png")), "", CTRL+Key_U, this, "editUpdateFrame"));
01352 
01353        connect( seActions["editSelectAll"], SIGNAL(activated()), this, SLOT(Do_selectAll()) );
01354        connect( seActions["editCut"], SIGNAL(activated()), this, SLOT(Do_cut()) );
01355        connect( seActions["editCopy"], SIGNAL(activated()), this, SLOT(Do_copy()) );
01356        connect( seActions["editPaste"], SIGNAL(activated()), this, SLOT(Do_paste()) );
01357        connect( seActions["editClear"], SIGNAL(activated()), this, SLOT(Do_del()) );
01358        connect( seActions["editSearchReplace"], SIGNAL(activated()), this, SLOT(SearchText()) );
01359        connect( seActions["editEditStyle"], SIGNAL(activated()), this, SLOT(slotEditStyles()) );
01360        connect( seActions["editFontPreview"], SIGNAL(activated()), this, SLOT(Do_fontPrev()) );
01361        connect( seActions["editUpdateFrame"], SIGNAL(activated()), this, SLOT(updateTextFrame()) );
01362 
01363        //Insert Menu
01364        seActions.insert("insertGlyph", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "insertGlyph"));
01365        connect( seActions["insertGlyph"], SIGNAL(activated()), this, SLOT(Do_insSp()) );
01366 
01367        //Settings Menu
01368        seActions.insert("settingsBackground", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "settingsBackground"));
01369        seActions.insert("settingsDisplayFont", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "settingsDisplayFont"));
01370        seActions.insert("settingsSmartTextSelection", new ScrAction(QIconSet(noIcon), "", QKeySequence(), this, "settingsSmartTextSelection"));
01371        smartSelection = false;
01372        seActions["settingsSmartTextSelection"]->setOn(false);
01373        seActions["settingsSmartTextSelection"]->setToggleAction(true);
01374 
01375        connect( seActions["settingsBackground"], SIGNAL(activated()), this, SLOT(setBackPref()) );
01376        connect( seActions["settingsDisplayFont"], SIGNAL(activated()), this, SLOT(setFontPref()) );
01377        connect( seActions["settingsSmartTextSelection"], SIGNAL(toggled(bool)), this, SLOT(setSmart(bool)) );
01378 
01379 
01380        seActions["fileRevert"]->setEnabled(false);
01381        seActions["editCopy"]->setEnabled(false);
01382        seActions["editCut"]->setEnabled(false);
01383        seActions["editPaste"]->setEnabled(false);
01384        seActions["editClear"]->setEnabled(false);
01385        seActions["editUpdateFrame"]->setEnabled(false);
01386 }
01387 
01388 void StoryEditor::buildMenus()
01389 {
01390        seMenuMgr = new MenuManager(this->menuBar(), this->menuBar());
01391        seMenuMgr->createMenu("File", tr("&File"));
01392        seMenuMgr->addMenuItem(seActions["fileNew"], "File");
01393        seMenuMgr->addMenuItem(seActions["fileRevert"], "File");
01394        seMenuMgr->addMenuSeparator("File");
01395        seMenuMgr->addMenuItem(seActions["fileSaveToFile"], "File");
01396        seMenuMgr->addMenuItem(seActions["fileLoadFromFile"], "File");
01397        seMenuMgr->addMenuItem(seActions["fileSaveDocument"], "File");
01398        seMenuMgr->addMenuSeparator("File");
01399        seMenuMgr->addMenuItem(seActions["fileUpdateAndExit"], "File");
01400        seMenuMgr->addMenuItem(seActions["fileExit"], "File");
01401        seMenuMgr->createMenu("Edit", tr("&Edit"));
01402        seMenuMgr->addMenuItem(seActions["editSelectAll"], "Edit");
01403        seMenuMgr->addMenuItem(seActions["editCut"], "Edit");
01404        seMenuMgr->addMenuItem(seActions["editCopy"], "Edit");
01405        seMenuMgr->addMenuItem(seActions["editPaste"], "Edit");
01406        seMenuMgr->addMenuItem(seActions["editClear"], "Edit");
01407        seMenuMgr->addMenuSeparator("Edit");
01408        seMenuMgr->addMenuItem(seActions["editSearchReplace"], "Edit");
01409        seMenuMgr->addMenuSeparator("Edit");
01410        seMenuMgr->addMenuItem(seActions["editEditStyle"], "Edit");
01411        seMenuMgr->addMenuItem(seActions["editFontPreview"], "Edit");
01412        seMenuMgr->addMenuItem(seActions["editUpdateFrame"], "Edit");
01413        seMenuMgr->createMenu("Insert", tr("&Insert"));
01414        seMenuMgr->addMenuItem(seActions["insertGlyph"], "Insert");
01415        seMenuMgr->createMenu("InsertChar", QPixmap(noIcon), tr("Character"), "Insert");
01416        seMenuMgr->addMenuItem(seActions["unicodePageNumber"], "InsertChar");
01417        //seMenuMgr->addMenuItem(seActions["unicodeSmartHyphen"], "InsertChar");
01418        seMenuMgr->addMenuItem(seActions["unicodeNonBreakingHyphen"], "InsertChar");
01419        seMenuMgr->addMenuSeparator("InsertChar");
01420        seMenuMgr->addMenuItem(seActions["unicodeCopyRight"], "InsertChar");
01421        seMenuMgr->addMenuItem(seActions["unicodeRegdTM"], "InsertChar");
01422        seMenuMgr->addMenuItem(seActions["unicodeTM"], "InsertChar");
01423        seMenuMgr->addMenuItem(seActions["unicodeSolidus"], "InsertChar");
01424        seMenuMgr->addMenuItem(seActions["unicodeBullet"], "InsertChar");
01425        seMenuMgr->addMenuItem(seActions["unicodeMidpoint"], "InsertChar");
01426        seMenuMgr->addMenuSeparator("InsertChar");
01427        seMenuMgr->addMenuItem(seActions["unicodeDashEm"], "InsertChar");
01428        seMenuMgr->addMenuItem(seActions["unicodeDashEn"], "InsertChar");
01429        seMenuMgr->addMenuItem(seActions["unicodeDashFigure"], "InsertChar");
01430        seMenuMgr->addMenuItem(seActions["unicodeDashQuotation"], "InsertChar");
01431        seMenuMgr->createMenu("InsertQuote", QPixmap(noIcon), tr("Quote"), "Insert");
01432        seMenuMgr->addMenuItem(seActions["unicodeQuoteApostrophe"], "InsertQuote");
01433        seMenuMgr->addMenuItem(seActions["unicodeQuoteStraight"], "InsertQuote");
01434        seMenuMgr->addMenuSeparator("InsertQuote");
01435        seMenuMgr->addMenuItem(seActions["unicodeQuoteSingleLeft"], "InsertQuote");
01436        seMenuMgr->addMenuItem(seActions["unicodeQuoteSingleRight"], "InsertQuote");
01437        seMenuMgr->addMenuItem(seActions["unicodeQuoteDoubleLeft"], "InsertQuote");
01438        seMenuMgr->addMenuItem(seActions["unicodeQuoteDoubleRight"], "InsertQuote");
01439        seMenuMgr->addMenuSeparator("InsertQuote");
01440        seMenuMgr->addMenuItem(seActions["unicodeQuoteSingleReversed"], "InsertQuote");
01441        seMenuMgr->addMenuItem(seActions["unicodeQuoteDoubleReversed"], "InsertQuote");
01442        seMenuMgr->addMenuSeparator("InsertQuote");
01443        seMenuMgr->addMenuItem(seActions["unicodeQuoteLowSingleComma"], "InsertQuote");
01444        seMenuMgr->addMenuItem(seActions["unicodeQuoteLowDoubleComma"], "InsertQuote");
01445        seMenuMgr->addMenuSeparator("InsertQuote");
01446        seMenuMgr->addMenuItem(seActions["unicodeQuoteSingleLeftGuillemet"], "InsertQuote");
01447        seMenuMgr->addMenuItem(seActions["unicodeQuoteSingleRightGuillemet"], "InsertQuote");
01448        seMenuMgr->addMenuItem(seActions["unicodeQuoteDoubleLeftGuillemet"], "InsertQuote");
01449        seMenuMgr->addMenuItem(seActions["unicodeQuoteDoubleRightGuillemet"], "InsertQuote");
01450        seMenuMgr->addMenuSeparator("InsertQuote");
01451        seMenuMgr->addMenuItem(seActions["unicodeQuoteCJKSingleLeft"], "InsertQuote");
01452        seMenuMgr->addMenuItem(seActions["unicodeQuoteCJKSingleRight"], "InsertQuote");
01453        seMenuMgr->addMenuItem(seActions["unicodeQuoteCJKDoubleLeft"], "InsertQuote");
01454        seMenuMgr->addMenuItem(seActions["unicodeQuoteCJKDoubleRight"], "InsertQuote");
01455        seMenuMgr->createMenu("InsertSpace", QPixmap(noIcon), tr("Spaces && Breaks"), "Insert");
01456        seMenuMgr->addMenuItem(seActions["unicodeNonBreakingSpace"], "InsertSpace");
01457        seMenuMgr->addMenuItem(seActions["unicodeSpaceEN"], "InsertSpace");
01458        seMenuMgr->addMenuItem(seActions["unicodeSpaceEM"], "InsertSpace");
01459        seMenuMgr->addMenuItem(seActions["unicodeSpaceThin"], "InsertSpace");
01460        seMenuMgr->addMenuItem(seActions["unicodeSpaceThick"], "InsertSpace");
01461        seMenuMgr->addMenuItem(seActions["unicodeSpaceMid"], "InsertSpace");
01462        seMenuMgr->addMenuItem(seActions["unicodeSpaceHair"], "InsertSpace");
01463        seMenuMgr->addMenuSeparator("InsertSpace");
01464        seMenuMgr->addMenuItem(seActions["unicodeNewLine"], "InsertSpace");
01465        seMenuMgr->addMenuItem(seActions["unicodeFrameBreak"], "InsertSpace");
01466        seMenuMgr->addMenuItem(seActions["unicodeColumnBreak"], "InsertSpace");
01467        seMenuMgr->createMenu("InsertLigature", QPixmap(noIcon), tr("Ligature"), "Insert");
01468        seMenuMgr->addMenuItem(seActions["unicodeLigature_ff"], "InsertLigature");
01469        seMenuMgr->addMenuItem(seActions["unicodeLigature_fi"], "InsertLigature");
01470        seMenuMgr->addMenuItem(seActions["unicodeLigature_fl"], "InsertLigature");
01471        seMenuMgr->addMenuItem(seActions["unicodeLigature_ffi"], "InsertLigature");
01472        seMenuMgr->addMenuItem(seActions["unicodeLigature_ffl"], "InsertLigature");
01473        seMenuMgr->addMenuItem(seActions["unicodeLigature_ft"], "InsertLigature");
01474        seMenuMgr->addMenuItem(seActions["unicodeLigature_st"], "InsertLigature");
01475 
01476        seMenuMgr->createMenu("Settings", tr("&Settings"));
01477        seMenuMgr->addMenuItem(seActions["settingsBackground"], "Settings");
01478        seMenuMgr->addMenuItem(seActions["settingsDisplayFont"], "Settings");
01479        seMenuMgr->addMenuItem(seActions["settingsSmartTextSelection"], "Settings");
01480 
01481        seMenuMgr->addMenuToMenuBar("File");
01482        seMenuMgr->addMenuToMenuBar("Edit");
01483        seMenuMgr->addMenuToMenuBar("Insert");
01484        seMenuMgr->addMenuToMenuBar("Settings");
01485 }
01486 
01487 void StoryEditor::buildGUI()
01488 {
01489        unicodeCharActionNames.clear();
01490        seActions.clear();
01491        initActions();
01492        ActionManager::initUnicodeActions(&seActions, this, &unicodeCharActionNames);
01493        seActions["unicodeSmartHyphen"]->setEnabled(false);//CB TODO doesnt work in SE yet.
01494        buildMenus();
01495 
01496        setIcon(loadIcon("AppIcon.png"));
01497        QHBox* vb = new QHBox( this );
01498        StoryEd2Layout = new QHBoxLayout( 0, 5, 5, "StoryEd2Layout");
01499 
01500 /* Setting up Toolbars */
01501        FileTools = new QToolBar(this);
01502        seActions["fileNew"]->addTo(FileTools);
01503        seActions["fileLoadFromFile"]->addTo(FileTools);
01504        seActions["fileSaveToFile"]->addTo(FileTools);
01505        seActions["fileUpdateAndExit"]->addTo(FileTools);
01506        seActions["fileExit"]->addTo(FileTools);
01507        seActions["fileRevert"]->addTo(FileTools);
01508        seActions["editUpdateFrame"]->addTo(FileTools);
01509        seActions["editSearchReplace"]->addTo(FileTools);
01510 
01511        setDockEnabled(FileTools, DockLeft, false);
01512        setDockEnabled(FileTools, DockRight, false);
01513        setDockEnabled(FileTools, DockBottom, false);
01514        FontTools = new SToolBFont(this);
01515        setDockEnabled(FontTools, DockLeft, false);
01516        setDockEnabled(FontTools, DockRight, false);
01517        setDockEnabled(FontTools, DockBottom, false);
01518        AlignTools = new SToolBAlign(this);
01519        setDockEnabled(AlignTools, DockLeft, false);
01520        setDockEnabled(AlignTools, DockRight, false);
01521        setDockEnabled(AlignTools, DockBottom, false);
01522        AlignTools->paraStyleCombo->setDoc(currDoc);
01523        StyleTools = new SToolBStyle(this);
01524        setDockEnabled(StyleTools, DockLeft, false);
01525        setDockEnabled(StyleTools, DockRight, false);
01526        setDockEnabled(StyleTools, DockBottom, false);
01527        StrokeTools = new SToolBColorS(this, currDoc);
01528        setDockEnabled(StrokeTools, DockLeft, false);
01529        setDockEnabled(StrokeTools, DockRight, false);
01530        setDockEnabled(StrokeTools, DockBottom, false);
01531        StrokeTools->TxStroke->setEnabled(false);
01532        StrokeTools->PM1->setEnabled(false);
01533        FillTools = new SToolBColorF(this, currDoc);
01534        setDockEnabled(FillTools, DockLeft, false);
01535        setDockEnabled(FillTools, DockRight, false);
01536        setDockEnabled(FillTools, DockBottom, false);
01537 
01538        EdSplit = new QSplitter(vb);
01539 /* SideBar Widget */
01540        EditorBar = new SideBar(EdSplit);
01541 /* Editor Widget, subclass of QTextEdit */
01542        Editor = new SEditor(EdSplit, currDoc, this);
01543        StoryEd2Layout->addWidget( EdSplit );
01544 
01545 /* Setting up Status Bar */
01546        ButtonGroup1 = new QButtonGroup( statusBar(), "ButtonGroup1" );
01547        ButtonGroup1->setFrameShape( QButtonGroup::NoFrame );
01548        ButtonGroup1->setFrameShadow( QButtonGroup::Plain );
01549        ButtonGroup1->setTitle("");
01550        ButtonGroup1->setExclusive( true );
01551        ButtonGroup1->setColumnLayout(0, Qt::Vertical );
01552        ButtonGroup1->layout()->setSpacing( 0 );
01553        ButtonGroup1->layout()->setMargin( 0 );
01554        ButtonGroup1Layout = new QGridLayout( ButtonGroup1->layout() );
01555        ButtonGroup1Layout->setAlignment( Qt::AlignTop );
01556        ButtonGroup1Layout->setSpacing( 2 );
01557        ButtonGroup1Layout->setMargin( 0 );
01558        WordCT1 = new QLabel(ButtonGroup1, "wt");
01559        ButtonGroup1Layout->addMultiCellWidget( WordCT1, 0, 0, 0, 3 );
01560        WordCT = new QLabel(ButtonGroup1, "wt");
01561        ButtonGroup1Layout->addWidget( WordCT, 1, 0 );
01562        WordC = new QLabel(ButtonGroup1, "wc");
01563        ButtonGroup1Layout->addWidget( WordC, 1, 1 );
01564        CharCT = new QLabel(ButtonGroup1, "ct");
01565        ButtonGroup1Layout->addWidget( CharCT, 1, 2 );
01566        CharC = new QLabel(ButtonGroup1, "cc");
01567        ButtonGroup1Layout->addWidget( CharC, 1, 3 );
01568        statusBar()->addWidget(ButtonGroup1, 1, true);
01569        ButtonGroup2 = new QButtonGroup( statusBar(), "ButtonGroup2" );
01570        ButtonGroup2->setFrameShape( QButtonGroup::NoFrame );
01571        ButtonGroup2->setFrameShadow( QButtonGroup::Plain );
01572        ButtonGroup2->setTitle("");
01573        ButtonGroup2->setExclusive( true );
01574        ButtonGroup2->setColumnLayout(0, Qt::Vertical );
01575        ButtonGroup2->layout()->setSpacing( 0 );
01576        ButtonGroup2->layout()->setMargin( 0 );
01577        ButtonGroup2Layout = new QGridLayout( ButtonGroup2->layout() );
01578        ButtonGroup2Layout->setAlignment( Qt::AlignTop );
01579        ButtonGroup2Layout->setSpacing( 2 );
01580        ButtonGroup2Layout->setMargin( 0 );
01581        WordCT3 = new QLabel(ButtonGroup2, "wt");
01582        ButtonGroup2Layout->addMultiCellWidget( WordCT3, 0, 0, 0, 5 );
01583        ParCT = new QLabel(ButtonGroup2, "pt");
01584        ButtonGroup2Layout->addWidget( ParCT, 1, 0 );
01585        ParC = new QLabel(ButtonGroup2, "pc");
01586        ButtonGroup2Layout->addWidget( ParC, 1, 1 );
01587        WordCT2 = new QLabel(ButtonGroup2, "wt");
01588        ButtonGroup2Layout->addWidget( WordCT2, 1, 2 );
01589        WordC2 = new QLabel(ButtonGroup2, "wc");
01590        ButtonGroup2Layout->addWidget( WordC2, 1, 3 );
01591        CharCT2 = new QLabel(ButtonGroup2, "ct");
01592        ButtonGroup2Layout->addWidget( CharCT2, 1, 4 );
01593        CharC2 = new QLabel(ButtonGroup2, "cc");
01594        ButtonGroup2Layout->addWidget( CharC2, 1, 5 );
01595        statusBar()->addWidget(ButtonGroup2, 1, true);
01596        setCentralWidget( vb );
01597        //Final setup
01598        resize( QSize(660, 500).expandedTo(minimumSizeHint()) );
01599        if (prefsManager==NULL)
01600               sDebug(QString("%1").arg("prefsmgr null"));
01601 
01602        Editor->setPaper(prefsManager->appPrefs.STEcolor);
01603        QFont fo;
01604        fo.fromString(prefsManager->appPrefs.STEfont);
01605        Editor->setFont(fo);
01606        EditorBar->setFrameStyle(Editor->frameStyle());
01607        EditorBar->setLineWidth(Editor->lineWidth());
01608        EditorBar->editor = Editor;
01609        Editor->installEventFilter(this);
01610        languageChange();
01611 }
01612 
01613 void StoryEditor::languageChange()
01614 {
01615        setCaption( tr( "Story Editor" ) );
01616        //File Menu
01617        seMenuMgr->setMenuText("File", tr("&File"));
01618        seActions["fileNew"]->setMenuText( tr("&New"));
01619        seActions["fileNew"]->setText( tr("Clear All Text"));
01620        seActions["fileRevert"]->setTexts( tr("&Reload Text from Frame"));
01621        seActions["fileSaveToFile"]->setTexts( tr("&Save to File..."));
01622        seActions["fileLoadFromFile"]->setTexts( tr("&Load from File..."));
01623        seActions["fileSaveDocument"]->setTexts( tr("Save &Document"));
01624        seActions["fileUpdateAndExit"]->setTexts( tr("&Update Text Frame and Exit"));
01625        seActions["fileExit"]->setTexts( tr("&Exit Without Updating Text Frame"));
01626        //Edit Menu
01627        seMenuMgr->setMenuText("Edit", tr("&Edit"));
01628        seActions["editSelectAll"]->setTexts( tr("Select &All"));
01629        seActions["editCut"]->setTexts( tr("Cu&t"));
01630        seActions["editCopy"]->setTexts( tr("&Copy"));
01631        seActions["editPaste"]->setTexts( tr("&Paste"));
01632        seActions["editClear"]->setTexts( tr("C&lear"));
01633        seActions["editSearchReplace"]->setTexts( tr("&Search/Replace..."));
01634        seActions["editEditStyle"]->setTexts( tr("&Edit Styles..."));
01635        seActions["editFontPreview"]->setTexts( tr("&Fonts Preview..."));
01636        seActions["editUpdateFrame"]->setTexts( tr("&Update Text Frame"));
01637 
01638        //Insert menu
01639        seMenuMgr->setMenuText("Insert", tr("&Insert"));
01640        seMenuMgr->setMenuText("InsertChar", tr("Character"));
01641        seMenuMgr->setMenuText("InsertQuote", tr("Quote"));
01642        seMenuMgr->setMenuText("InsertSpace", tr("Space"));
01643        seActions["insertGlyph"]->setTexts( tr("&Insert Glyph..."));
01644 
01645        //Settings Menu
01646        seMenuMgr->setMenuText("Settings", tr("&Settings"));
01647        seActions["settingsBackground"]->setTexts( tr("&Background..."));
01648        seActions["settingsDisplayFont"]->setTexts( tr("&Display Font..."));
01649        seActions["settingsSmartTextSelection"]->setTexts( tr("&Smart text selection"));
01650 
01651        //Unicode Actions
01652        ActionManager::languageChangeUnicodeActions(&seActions);
01653 
01654        FileTools->setLabel( tr("File"));
01655 
01656        WordCT1->setText( tr("Current Paragraph:"));
01657        WordCT->setText( tr("Words: "));
01658        CharCT->setText( tr("Chars: "));
01659        WordCT3->setText( tr("Totals:"));
01660        ParCT->setText( tr("Paragraphs: "));
01661        WordCT2->setText( tr("Words: "));
01662        CharCT2->setText( tr("Chars: "));
01663 
01664 }
01665 
01666 void StoryEditor::disconnectSignals()
01667 {
01668        disconnect(Editor,0,0,0);
01669        disconnect(EditorBar,0,0,0);
01670        disconnect(AlignTools,0,0,0);
01671        disconnect(FillTools,0,0,0);
01672        disconnect(FontTools,0,0,0);
01673        disconnect(StrokeTools,0,0,0);
01674        disconnect(StyleTools,0,0,0);
01675 }
01676 
01677 void StoryEditor::connectSignals()
01678 {
01679        connect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
01680        connect(Editor, SIGNAL(clicked(int, int)), this, SLOT(updateProps(int, int)));
01681        connect(Editor, SIGNAL(setProps(int, int)), this, SLOT(updateProps(int, int)));
01682        connect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
01683        connect(Editor, SIGNAL(copyAvailable(bool)), this, SLOT(CopyAvail(bool )));
01684        connect(Editor, SIGNAL(PasteAvail()), this, SLOT(PasteAvail()));
01685        connect(Editor, SIGNAL(contentsMoving(int, int)), EditorBar, SLOT(doMove(int, int )));
01686        connect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
01687        connect(Editor, SIGNAL(SideBarUp(bool )), EditorBar, SLOT(setRepaint(bool )));
01688        connect(Editor, SIGNAL(SideBarUpdate( )), EditorBar, SLOT(doRepaint()));
01689        // 10/12/2004 - pv - #1203: wrong selection on double click
01690        connect(Editor, SIGNAL(doubleClicked(int, int)), this, SLOT(doubleClick(int, int)));
01691        connect(EditorBar, SIGNAL(ChangeStyle(int, const QString& )), this, SLOT(changeStyleSB(int, const QString&)));
01692        connect(EditorBar, SIGNAL(sigEditStyles()), this, SLOT(slotEditStyles()));
01693        connect(AlignTools, SIGNAL(newParaStyle(const QString&)), this, SLOT(newStyle(const QString&)));
01694        connect(AlignTools, SIGNAL(newAlign(int)), this, SLOT(newAlign(int)));
01695        connect(FillTools, SIGNAL(NewColor(int, int)), this, SLOT(newTxFill(int, int)));
01696        connect(StrokeTools, SIGNAL(NewColor(int, int)), this, SLOT(newTxStroke(int, int)));
01697        connect(FontTools, SIGNAL(NewSize(double )), this, SLOT(newTxSize(double)));
01698        connect(FontTools, SIGNAL(NewFont(const QString& )), this, SLOT(newTxFont(const QString& )));
01699        connect(FontTools, SIGNAL(NewScale(int )), this, SLOT(newTxScale(int )));
01700        connect(FontTools, SIGNAL(NewScaleV(int )), this, SLOT(newTxScaleV(int )));
01701        connect(StyleTools, SIGNAL(NewKern(int )), this, SLOT(newTxKern(int )));
01702        connect(StyleTools, SIGNAL(newStyle(int )), this, SLOT(newTxStyle(int )));
01703        connect(StyleTools, SIGNAL(NewShadow(int, int)), this, SLOT(newShadowOffs(int, int)));
01704        connect(StyleTools, SIGNAL(newOutline(int )), this, SLOT(newTxtOutline(int )));
01705        connect(StyleTools, SIGNAL(newUnderline(int, int)), this, SLOT(newTxtUnderline(int, int)));
01706        connect(StyleTools, SIGNAL(newStrike(int, int )), this, SLOT(newTxtStrike(int, int)));
01707 }
01708 
01709 void StoryEditor::setCurrentDocumentAndItem(ScribusDoc *doc, PageItem *item)
01710 {
01711        disconnectSignals();
01712        currDoc=doc;
01713        textChanged=false;
01714        AlignTools->paraStyleCombo->setDoc(currDoc);
01715        StrokeTools->setCurrentDocument(currDoc);
01716        FillTools->setCurrentDocument(currDoc);
01717        Editor->setCurrentDocument(currDoc);
01718        currItem = item;
01719        if (currItem!=NULL)
01720        {
01721               setCaption( tr("Story Editor - %1").arg(currItem->itemName()));
01722               firstSet = false;
01723               FontTools->Fonts->RebuildList(currDoc, currItem->isAnnotation());
01724               Editor->loadItemText(currItem);
01725               Editor->getCursorPosition(&CurrPara, &CurrChar);
01726               Editor->sync();
01727               Editor->repaintContents();
01728               EditorBar->setRepaint(true);
01729               EditorBar->doRepaint();
01730               updateProps(0,0);
01731               updateStatus();
01732               connectSignals();
01733        }
01734        else
01735        {
01736               Editor->StyledText.clear();
01737               Editor->clear();
01738               setCaption( tr( "Story Editor" ));
01739        }
01740        QString data = QApplication::clipboard()->text(QClipboard::Clipboard);
01741        if (!data.isNull())
01742               seActions["editPaste"]->setEnabled(true);
01743 }
01744 
01749 void StoryEditor::doubleClick(int para, int position)
01750 {
01751        int paraFrom=0, indexFrom=0, paraTo=0, indexTo=0;
01752        QString selText = Editor->selectedText();
01753        if (selText.length() == 0 || !smartSelection)
01754        {
01755               updateProps(para, position);
01756               return;
01757        }
01758        Editor->getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
01759        selText =  selText.stripWhiteSpace();
01760        Editor->setSelection(paraFrom, indexFrom, paraFrom, indexFrom + selText.length());
01761        updateProps(para, position);
01762 }
01763 
01764 void StoryEditor::setSmart(bool newSmartSelection)
01765 {
01766        smartSelection = newSmartSelection;
01767 }
01768 
01769 void StoryEditor::closeEvent(QCloseEvent *)
01770 {
01771        if (textChanged)
01772        {
01773               blockUpdate = true;
01774               int t = ScMessageBox::warning(this, CommonStrings::trWarning,
01775                                                                tr("Do you want to save your changes?"),
01776                                                                QMessageBox::Yes|QMessageBox::Default,
01777                                                                QMessageBox::No,
01778                                                                QMessageBox::Cancel|QMessageBox::Escape);
01779               qApp->processEvents();
01780               if (t == QMessageBox::Yes)
01781               {
01782                      updateTextFrame();
01783                      result = QDialog::Accepted;
01784               }
01785               else if (t == QMessageBox::Cancel)
01786               {
01787                      blockUpdate = false;
01788                      return;
01789               }
01790               else if (t == QMessageBox::No)
01791                      result = QDialog::Rejected;
01792        }
01793        else
01794               result = QDialog::Rejected;
01795        setCurrentDocumentAndItem(NULL, NULL);
01796        savePrefs();
01797 //     if (charSelect != NULL)
01798 //            charSelect->close();
01799        hide();
01800        blockUpdate = false;
01801 }
01802 
01803 void StoryEditor::keyPressEvent (QKeyEvent * e)
01804 {
01805        if (e->key() == Qt::Key_Escape)
01806               close();
01807        else
01808        {
01809               activFromApp = false;
01810               return QMainWindow::keyReleaseEvent(e);
01811        }
01812 }
01813 
01814 bool StoryEditor::eventFilter( QObject* ob, QEvent* ev )
01815 {
01816        if ( ev->type() == QEvent::WindowDeactivate )
01817        {
01818               if ((currItem!=NULL) && (!blockUpdate))
01819                      updateTextFrame();
01820               activFromApp = false;
01821               Editor->getCursorPosition(&CurrPara, &CurrChar);
01822        }
01823        if ( ev->type() == QEvent::WindowActivate )
01824        {
01825               if ((!activFromApp) && (!textChanged) && (!blockUpdate))
01826               {
01827                      activFromApp = true;
01828                      if (currItem!=NULL)
01829                      {
01830                             disconnectSignals();
01831                             Editor->setUndoRedoEnabled(false);
01832                             Editor->setUndoRedoEnabled(true);
01833 //                          Editor->setCursorPosition(0, 0);
01834                             seActions["fileRevert"]->setEnabled(false);
01835                             seActions["editCopy"]->setEnabled(false);
01836                             seActions["editCut"]->setEnabled(false);
01837                             seActions["editClear"]->setEnabled(false);
01838                             textChanged = false;
01839                             FontTools->Fonts->RebuildList(currDoc, currItem->isAnnotation());
01840                             Editor->loadItemText(currItem);
01841                             Editor->getCursorPosition(&CurrPara, &CurrChar);
01842                             updateStatus();
01843                             textChanged = false;
01844                             Editor->sync();
01845                             Editor->repaintContents();
01846                             EditorBar->doMove(0, Editor->contentsY());
01847                             EditorBar->setRepaint(true);
01848                             EditorBar->doRepaint();
01849                             connectSignals();
01850                      }
01851               }
01852        }
01853        return QMainWindow::eventFilter(ob, ev);
01854 }
01855 
01856 void StoryEditor::setBackPref()
01857 {
01858        blockUpdate = true;
01859        QColor neu = QColor();
01860        neu = QColorDialog::getColor(Editor->paper().color(), this);
01861        if (neu.isValid())
01862        {
01863               Editor->setPaper(neu);
01864               prefsManager->appPrefs.STEcolor = neu;
01865        }
01866        blockUpdate = false;
01867 }
01868 
01869 void StoryEditor::setFontPref()
01870 {
01871        blockUpdate = true;
01872        Editor->setFont( QFontDialog::getFont( 0, Editor->font(), this ) );
01873        prefsManager->appPrefs.STEfont = Editor->font().toString();
01874        EditorBar->doRepaint();
01875        blockUpdate = false;
01876 }
01877 
01878 void StoryEditor::newTxFill(int c, int s)
01879 {
01880        if (c != -1)
01881               Editor->CurrTextFill = FillTools->TxFill->text(c);
01882        if (s != -1)
01883               Editor->CurrTextFillSh = s;
01884        CharStyle charStyle;
01885        charStyle.setFillColor(Editor->CurrTextFill);
01886        charStyle.setFillShade(Editor->CurrTextFillSh);
01887        Editor->updateSel(charStyle);
01888        modifiedText();
01889        Editor->setFocus();
01890 }
01891 
01892 void StoryEditor::newTxStroke(int c, int s)
01893 {
01894        if (c != -1)
01895               Editor->CurrTextStroke = StrokeTools->TxStroke->text(c);
01896        if (s != -1)
01897               Editor->CurrTextStrokeSh = s;
01898        CharStyle charStyle;
01899        charStyle.setStrokeColor(Editor->CurrTextStroke);
01900        charStyle.setStrokeShade(Editor->CurrTextStrokeSh);
01901        Editor->updateSel(charStyle);
01902        modifiedText();
01903        Editor->setFocus();
01904 }
01905 
01906 void StoryEditor::newTxFont(const QString &f)
01907 {
01908        if(!currDoc->UsedFonts.contains(f)) {
01909               if (!currDoc->AddFont(f)) {
01910 //, prefsManager->appPrefs.AvailFonts[f]->Font)) {
01911                      FontTools->Fonts->RebuildList(currDoc);
01912                      return;
01913               };
01914        }
01915        Editor->prevFont = Editor->CurrFont;
01916        Editor->CurrFont = f;
01917        updateUnicodeActions();
01918        CharStyle charStyle;
01919        charStyle.setFont((*currDoc->AllFonts)[Editor->CurrFont]);
01920        Editor->updateSel(charStyle);
01921        modifiedText();
01922        Editor->setFocus();
01923 }
01924 
01925 void StoryEditor::newTxSize(double s)
01926 {
01927        Editor->CurrFontSize = qRound(s * 10.0);
01928        CharStyle charStyle;
01929        charStyle.setFontSize(Editor->CurrFontSize);
01930        Editor->updateSel(charStyle);
01931        modifiedText();
01932        Editor->setFocus();
01933 }
01934 
01935 void StoryEditor::newTxStyle(int s)
01936 {
01937        Editor->CurrentStyle = static_cast<StyleFlag>(s);
01938        CharStyle charStyle;
01939        charStyle.setFeatures(Editor->CurrentStyle.featureList());
01940        Editor->updateSel(charStyle);
01941        Editor->setStyle(s);
01942        if ((s & ScStyle_Outline) || (s & ScStyle_Shadowed))
01943        {
01944               StrokeTools->TxStroke->setEnabled(true);
01945               StrokeTools->PM1->setEnabled(true);
01946        }
01947        else
01948        {
01949               StrokeTools->TxStroke->setEnabled(false);
01950               StrokeTools->PM1->setEnabled(false);
01951        }
01952        modifiedText();
01953        Editor->setFocus();
01954 }
01955 
01956 void StoryEditor::newTxScale(int )
01957 {
01958        int ss = qRound(FontTools->ChScale->value() * 10);
01959        Editor->CurrTextScale = ss;
01960        CharStyle charStyle;
01961        charStyle.setScaleH(Editor->CurrTextScale);
01962        Editor->updateSel(charStyle);
01963        modifiedText();
01964        Editor->setFocus();
01965 }
01966 
01967 void StoryEditor::newTxScaleV(int )
01968 {
01969        int ss = qRound(FontTools->ChScaleV->value() * 10);
01970        Editor->CurrTextScaleV = ss;
01971        CharStyle charStyle;
01972        charStyle.setScaleV(Editor->CurrTextScaleV);
01973        Editor->updateSel(charStyle);
01974        modifiedText();
01975        Editor->setFocus();
01976 }
01977 
01978 void StoryEditor::newTxKern(int s)
01979 {
01980        Editor->CurrTextKern = s;
01981        CharStyle charStyle;
01982        charStyle.setTracking(Editor->CurrTextKern);
01983        Editor->updateSel(charStyle);
01984        modifiedText();
01985        Editor->setFocus();
01986 }
01987 
01988 void StoryEditor::newShadowOffs(int x, int y)
01989 {
01990        CharStyle charStyle;
01991        charStyle.setShadowXOffset(x);
01992        charStyle.setShadowYOffset(y);
01993        Editor->CurrTextShadowX = x;
01994        Editor->CurrTextShadowY = y;
01995        Editor->updateSel(charStyle);
01996        modifiedText();
01997        Editor->setFocus();
01998 }
01999 
02000 void StoryEditor::newTxtOutline(int o)
02001 {
02002        Editor->CurrTextOutline = o;
02003        CharStyle charStyle;
02004        charStyle.setOutlineWidth(Editor->CurrTextOutline);
02005        Editor->updateSel(charStyle);
02006        modifiedText();
02007        Editor->setFocus();
02008 }
02009 
02010 void StoryEditor::newTxtUnderline(int p, int w)
02011 {
02012        CharStyle charStyle;
02013        charStyle.setUnderlineOffset(p);
02014        charStyle.setUnderlineWidth(w);
02015        Editor->CurrTextUnderPos = p;
02016        Editor->CurrTextUnderWidth = w;
02017        Editor->updateSel(charStyle);
02018        modifiedText();
02019        Editor->setFocus();
02020 }
02021 
02022 void StoryEditor::newTxtStrike(int p, int w)
02023 {
02024        CharStyle charStyle;
02025        charStyle.setStrikethruOffset(p);
02026        charStyle.setStrikethruWidth(w);
02027        Editor->CurrTextStrikePos = p;
02028        Editor->CurrTextStrikeWidth = w;
02029        Editor->updateSel(charStyle);
02030        modifiedText();
02031        Editor->setFocus();
02032 }
02033 
02034 void StoryEditor::updateProps(int p, int ch)
02035 {
02036        ColorList::Iterator it;
02037        int c = 0;
02038        if (Editor->wasMod)
02039               return;
02040        if ((p >= static_cast<int>(Editor->StyledText.nrOfParagraphs())) || (Editor->StyledText.length() == 0) || (!firstSet))
02041        {
02042               int pos = Editor->StyledText.startOfParagraph(p) + ch;
02043               if (!firstSet)
02044               {
02045                      const CharStyle& curstyle(pos < Editor->StyledText.length()? currItem->itemText.charStyle(pos) : currItem->itemText.defaultStyle().charStyle());
02046                      Editor->CurrTextFill = curstyle.fillColor();
02047                      Editor->CurrTextFillSh = curstyle.fillShade();
02048                      Editor->CurrTextStroke = curstyle.strokeColor();
02049                      Editor->CurrTextStrokeSh = curstyle.strokeShade();
02050                      Editor->prevFont = Editor->CurrFont;
02051                      Editor->CurrFont = curstyle.font().scName();
02052                      Editor->CurrFontSize = curstyle.fontSize();
02053                      Editor->CurrentStyle = curstyle.effects();
02054                      Editor->currentParaStyle = curstyle.parent();
02055                      Editor->CurrTextKern = curstyle.tracking();
02056                      Editor->CurrTextScale = curstyle.scaleH();
02057                      Editor->CurrTextScaleV = curstyle.scaleV();
02058                      Editor->CurrTextBase = curstyle.baselineOffset();
02059                      Editor->CurrTextShadowX = curstyle.shadowXOffset();
02060                      Editor->CurrTextShadowY = curstyle.shadowYOffset();
02061                      Editor->CurrTextOutline = curstyle.outlineWidth();
02062                      Editor->CurrTextUnderPos = curstyle.underlineOffset();
02063                      Editor->CurrTextUnderWidth = curstyle.underlineWidth();
02064                      Editor->CurrTextStrikePos = curstyle.strikethruOffset();
02065                      Editor->CurrTextStrikeWidth = curstyle.strikethruWidth();
02066                      c = 0;
02067                      StrokeTools->SetShade(Editor->CurrTextStrokeSh);
02068                      FillTools->SetShade(Editor->CurrTextFillSh);
02069                      QString b = Editor->CurrTextFill;
02070                      if ((b != CommonStrings::None) && (!b.isEmpty()))
02071                      {
02072                             c++;
02073                             for (it = currDoc->PageColors.begin(); it != currDoc->PageColors.end(); ++it)
02074                             {
02075                                    if (it.key() == b)
02076                                           break;
02077                                    c++;
02078                             }
02079                      }
02080                      FillTools->SetColor(c);
02081                      c = 0;
02082                      b = Editor->CurrTextStroke;
02083                      if ((b != CommonStrings::None) && (!b.isEmpty()))
02084                      {
02085                             c++;
02086                             for (it = currDoc->PageColors.begin(); it != currDoc->PageColors.end(); ++it)
02087                             {
02088                                    if (it.key() == b)
02089                                           break;
02090                                    c++;
02091                             }
02092                      }
02093                      StrokeTools->SetColor(c);
02094                      AlignTools->SetAlign(Editor->CurrAlign);
02095                      StyleTools->SetKern(Editor->CurrTextKern);
02096                      StyleTools->SetStyle(Editor->CurrentStyle);
02097                      StyleTools->SetShadow(Editor->CurrTextShadowX, Editor->CurrTextShadowY);
02098                      StyleTools->setOutline(Editor->CurrTextOutline);
02099                      StyleTools->setUnderline(Editor->CurrTextUnderPos, Editor->CurrTextUnderWidth);
02100                      StyleTools->setStrike(Editor->CurrTextStrikePos, Editor->CurrTextStrikeWidth);
02101                      FontTools->SetSize(Editor->CurrFontSize);
02102                      FontTools->SetFont(Editor->CurrFont);
02103                      FontTools->SetScale(Editor->CurrTextScale);
02104                      FontTools->SetScaleV(Editor->CurrTextScaleV);
02105               }
02106               if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
02107               {
02108                      StrokeTools->TxStroke->setEnabled(true);
02109                      StrokeTools->PM1->setEnabled(true);
02110               }
02111               else
02112               {
02113                      StrokeTools->TxStroke->setEnabled(false);
02114                      StrokeTools->PM1->setEnabled(false);
02115               }
02116               Editor->setStyle(Editor->CurrentStyle);
02117               firstSet = true;
02118               updateUnicodeActions();
02119               return;
02120        }
02121        int parStart = Editor->StyledText.startOfParagraph(p);
02122        const ParagraphStyle& parStyle(Editor->StyledText.paragraphStyle(parStart));
02123        Editor->currentParaStyle = parStyle.displayName();
02124        if (Editor->StyledText.endOfParagraph(p) <= parStart)
02125        {
02126               Editor->prevFont = Editor->CurrFont;
02127               Editor->CurrFont = parStyle.charStyle().font().scName();
02128               Editor->CurrFontSize = parStyle.charStyle().fontSize();
02129               Editor->CurrentStyle = parStyle.charStyle().effects();
02130               Editor->CurrTextFill = parStyle.charStyle().fillColor();
02131               Editor->CurrTextFillSh = parStyle.charStyle().fillShade();
02132               Editor->CurrTextStroke = parStyle.charStyle().strokeColor();
02133               Editor->CurrTextStrokeSh = parStyle.charStyle().strokeShade();
02134               Editor->CurrTextShadowX = parStyle.charStyle().shadowXOffset();
02135               Editor->CurrTextShadowY = parStyle.charStyle().shadowYOffset();
02136               Editor->CurrTextOutline = parStyle.charStyle().outlineWidth();
02137               Editor->CurrTextUnderPos = parStyle.charStyle().underlineOffset();
02138               Editor->CurrTextUnderWidth = parStyle.charStyle().underlineWidth();
02139               Editor->CurrTextStrikePos = parStyle.charStyle().strikethruOffset();
02140               Editor->CurrTextStrikeWidth = parStyle.charStyle().strikethruWidth();
02141               Editor->setAlign(Editor->CurrAlign);
02142               Editor->setStyle(Editor->CurrentStyle);
02143        }
02144        else
02145        {
02146               int start;
02147               if (Editor->hasSelectedText())
02148               {
02149                      int PStart=0, PEnd=0, SelStart=0, SelEnd=0;
02150                      Editor->getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
02151                      start = Editor->StyledText.startOfParagraph(PStart);
02152                      if (SelStart >= 0 && start + SelStart < Editor->StyledText.endOfParagraph(PStart))
02153                             start = QMIN(start + SelStart, Editor->StyledText.endOfParagraph(PStart)-1);
02154                      else
02155                             start = QMIN(start + QMAX(ch-1, 0), Editor->StyledText.endOfParagraph(p)-1);
02156               }
02157               else
02158                      start = QMIN(Editor->StyledText.startOfParagraph(p) + QMAX(ch-1, 0), Editor->StyledText.endOfParagraph(p)-1);
02159               if (start >= Editor->StyledText.length())
02160                      start = Editor->StyledText.length() - 1;
02161               if (start < 0)
02162                      start = 0;
02163               const CharStyle& charStyle(Editor->StyledText.charStyle(start));
02164               Editor->CurrTextFill = charStyle.fillColor();
02165               Editor->CurrTextFillSh = charStyle.fillShade();
02166               Editor->CurrTextStroke = charStyle.strokeColor();
02167               Editor->CurrTextStrokeSh = charStyle.strokeShade();
02168               Editor->prevFont = Editor->CurrFont;
02169               Editor->CurrFont = charStyle.font().scName();
02170               Editor->CurrFontSize = charStyle.fontSize();
02171               Editor->CurrentStyle = charStyle.effects() & static_cast<StyleFlag>(1919);
02172               Editor->CurrTextKern = charStyle.tracking();
02173               Editor->CurrTextScale = charStyle.scaleH();
02174               Editor->CurrTextScaleV = charStyle.scaleV();
02175               Editor->CurrTextBase = charStyle.baselineOffset();
02176               Editor->CurrTextShadowX = charStyle.shadowXOffset();
02177               Editor->CurrTextShadowY = charStyle.shadowYOffset();
02178               Editor->CurrTextOutline = charStyle.outlineWidth();
02179               Editor->CurrTextUnderPos = charStyle.underlineOffset();
02180               Editor->CurrTextUnderWidth = charStyle.underlineWidth();
02181               Editor->CurrTextStrikePos = charStyle.strikethruOffset();
02182               Editor->CurrTextStrikeWidth = charStyle.strikethruWidth();
02183        }
02184        StrokeTools->SetShade(Editor->CurrTextStrokeSh);
02185        FillTools->SetShade(Editor->CurrTextFillSh);
02186        QString b = Editor->CurrTextFill;
02187        if ((b != CommonStrings::None) && (!b.isEmpty()))
02188        {
02189               c++;
02190               for (it = currDoc->PageColors.begin(); it != currDoc->PageColors.end(); ++it)
02191               {
02192                      if (it.key() == b)
02193                             break;
02194                      c++;
02195               }
02196        }
02197        FillTools->SetColor(c);
02198        c = 0;
02199        b = Editor->CurrTextStroke;
02200        if ((b != CommonStrings::None) && (!b.isEmpty()))
02201        {
02202               c++;
02203               for (it = currDoc->PageColors.begin(); it != currDoc->PageColors.end(); ++it)
02204               {
02205                      if (it.key() == b)
02206                             break;
02207                      c++;
02208               }
02209        }
02210        StrokeTools->SetColor(c);
02211        if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
02212        {
02213               StrokeTools->TxStroke->setEnabled(true);
02214               StrokeTools->PM1->setEnabled(true);
02215        }
02216        else
02217        {
02218               StrokeTools->TxStroke->setEnabled(false);
02219               StrokeTools->PM1->setEnabled(false);
02220        }
02221        StyleTools->SetKern(Editor->CurrTextKern);
02222        StyleTools->SetStyle(Editor->CurrentStyle);
02223        StyleTools->SetShadow(Editor->CurrTextShadowX, Editor->CurrTextShadowY);
02224        StyleTools->setOutline(Editor->CurrTextOutline);
02225        StyleTools->setUnderline(Editor->CurrTextUnderPos, Editor->CurrTextUnderWidth);
02226        StyleTools->setStrike(Editor->CurrTextStrikePos, Editor->CurrTextStrikeWidth);
02227        FontTools->SetSize(Editor->CurrFontSize);
02228        FontTools->SetFont(Editor->CurrFont);
02229        FontTools->SetScale(Editor->CurrTextScale);
02230        FontTools->SetScaleV(Editor->CurrTextScaleV);
02231        AlignTools->SetAlign(Editor->CurrAlign);
02232        updateUnicodeActions();
02233        updateStatus();
02234 }
02235 
02236 void StoryEditor::updateStatus()
02237 {
02238        QString tmp;
02239        int p=0, i=0;
02240        Editor->getCursorPosition(&p, &i);
02241        int start = Editor->StyledText.startOfParagraph(p);
02242        int end = Editor->StyledText.endOfParagraph(p);
02243 
02244        ParC->setText(tmp.setNum(Editor->StyledText.nrOfParagraphs()));
02245        CharC->setText(tmp.setNum(end - start));
02246        CharC2->setText(tmp.setNum(Editor->StyledText.length()));
02247 
02248        QRegExp rx( "(\\w+)\\b" );
02249        const QString& txt(Editor->StyledText.text(0, Editor->StyledText.length()));
02250        int pos = 1;
02251        int counter = end > start? 1 : 0;
02252        int counter2 = Editor->StyledText.length() > 0? 1 : 0;
02253        while ( pos >= 0 )
02254        {
02255               pos = rx.search( txt, pos );
02256               if ( pos > -1 )
02257               {
02258                      if (pos > start && pos < end)
02259                             counter++;
02260 
02261                      counter2++;
02262                      pos += rx.matchedLength();
02263               }
02264        }
02265 
02266        WordC->setText(tmp.setNum(counter));
02267        WordC2->setText(tmp.setNum(counter2));
02268 }
02269 
02270 void StoryEditor::Do_insSp()
02271 {
02272        //ScCore->primaryMainWindow()->charPalette->show();
02273        charSelectUsed = true;
02274        if (charSelect->isShown())
02275               return;
02276        charSelect->setEnabled(true, 0);
02277        charSelect->setDoc(currDoc);
02278        charSelect->show();
02279 }
02280 
02281 void StoryEditor::slot_insertSpecialChar()
02282 {
02283        blockUpdate = true;
02284        if (!charSelect->getCharacters().isEmpty())
02285        {
02286               Editor->insChars(charSelect->getCharacters());
02287               Editor->insert(charSelect->getCharacters());
02288        }
02289        blockUpdate = false;
02290 }
02291 
02292 void StoryEditor::slot_insertUserSpecialChar(QChar c)
02293 {
02294        blockUpdate = true;
02295        Editor->insChars(c);
02296        Editor->insert(c);
02297        blockUpdate = false;
02298 }
02299 
02300 void StoryEditor::Do_fontPrev()
02301 {
02302        blockUpdate = true;
02303        QString retval;
02304        ScActionPlugin* plugin;
02305        bool result = false;
02306 
02307        if (PluginManager::instance().DLLexists("fontpreview"))
02308        {
02309               plugin = dynamic_cast<ScActionPlugin*>(PluginManager::instance().getPlugin("fontpreview", false));
02310               if (plugin)
02311                      result = plugin->run(this, currDoc, Editor->CurrFont);
02312               if (result)
02313               {
02314                      retval = plugin->runResult();
02315                      if (!retval.isEmpty())
02316                      {
02317                             newTxFont(retval);
02318                             FontTools->SetFont(retval);
02319                      }
02320               }
02321        }
02322        blockUpdate = false;
02323 }
02324 
02325 void StoryEditor::Do_leave2()
02326 {
02327        updateTextFrame();
02328        result = QDialog::Accepted;
02329        setCurrentDocumentAndItem(currDoc, NULL);
02330        hide();
02331        blockUpdate = false;
02332 }
02333 
02334 void StoryEditor::Do_leave()
02335 {
02336        if (textChanged)
02337        {
02338               blockUpdate = true;
02339               int t = ScMessageBox::warning(this, CommonStrings::trWarning,
02340                                            tr("Do you really want to lose all your changes?"),
02341                                            QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
02342               qApp->processEvents();
02343               if (t == QMessageBox::No)
02344               {
02345                      blockUpdate = false;
02346                      return;
02347               }
02348        }
02349        result = QDialog::Rejected;
02350        setCurrentDocumentAndItem(currDoc, NULL);
02351        hide();
02352        blockUpdate = false;
02353 }
02354 
02355 void StoryEditor::Do_saveDocument()
02356 {
02357        blockUpdate = true;
02358        if (ScCore->primaryMainWindow()->slotFileSave())
02359               updateTextFrame();
02360        blockUpdate = false;
02361 }
02362 
02363 bool StoryEditor::Do_new()
02364 {
02365        if (Editor->length() != 0)
02366        {
02367               blockUpdate = true;
02368               int t = ScMessageBox::warning(this, CommonStrings::trWarning,
02369                                     tr("Do you really want to clear all your text?"),
02370                                     QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
02371               qApp->processEvents();
02372               if (t == QMessageBox::No)
02373               {
02374                      blockUpdate = false;
02375                      return false;
02376               }
02377        }
02378        Editor->StyledText.clear();
02379        Editor->clear();
02380        Editor->setUndoRedoEnabled(false);
02381        Editor->setUndoRedoEnabled(true);
02382        //qDebug("SE::Do_new: cursor");
02383        Editor->setCursorPosition(0, 0);
02384        seActions["fileRevert"]->setEnabled(false);
02385        seActions["editCopy"]->setEnabled(false);
02386        seActions["editCut"]->setEnabled(false);
02387        seActions["editClear"]->setEnabled(false);
02388 //     textChanged = false;
02389        EditorBar->setRepaint(true);
02390        EditorBar->doRepaint();
02391        updateProps(0, 0);
02392        updateStatus();
02393        blockUpdate = false;
02394        return true;
02395 }
02396 
02397 void StoryEditor::slotFileRevert()
02398 {
02399        if (Do_new())
02400        {
02401               Editor->loadItemText(currItem);
02402               Editor->getCursorPosition(&CurrPara, &CurrChar);
02403               updateStatus();
02404               EditorBar->setRepaint(true);
02405               EditorBar->doRepaint();
02406               Editor->sync();
02407               Editor->repaintContents();
02408        }
02409 }
02410 
02411 void StoryEditor::Do_selectAll()
02412 {
02413        if (Editor->StyledText.length() == 0)
02414               return;
02415 
02416        int lastPar = Editor->StyledText.nrOfParagraphs()-1;
02417        if (lastPar > 0)
02418        {
02419               int lastParStart = Editor->StyledText.startOfParagraph(lastPar);
02420               int lastParEnd = Editor->StyledText.endOfParagraph(lastPar);
02421               Editor->setSelection(0, 0, lastPar, lastParEnd - lastParStart);
02422        }
02423        else
02424        {
02425               Editor->setSelection(0, 0, 0, Editor->StyledText.length());
02426        }
02427 }
02428 
02429 void StoryEditor::Do_copy()
02430 {
02431        Editor->copy();
02432 }
02433 
02434 void StoryEditor::Do_paste()
02435 {
02436        Editor->paste();
02437 }
02438 
02439 void StoryEditor::Do_cut()
02440 {
02441        Editor->cut();
02442 }
02443 
02444 void StoryEditor::Do_del()
02445 {
02446        if (Editor->StyledText.length() == 0)
02447               return;
02448        EditorBar->setRepaint(false);
02449        if (Editor->hasSelectedText())
02450        {
02451               Editor->deleteSel();
02452               Editor->removeSelectedText();
02453        }
02454        EditorBar->setRepaint(true);
02455        EditorBar->doRepaint();
02456 }
02457 
02458 void StoryEditor::CopyAvail(bool u)
02459 {
02460        seActions["editCopy"]->setEnabled(u);
02461        seActions["editCut"]->setEnabled(u);
02462        seActions["editClear"]->setEnabled(u);
02463 //     seActions["editCopy"]->setEnabled(Editor->tBuffer.length() != 0);
02464 }
02465 
02466 void StoryEditor::PasteAvail()
02467 {
02468        seActions["editPaste"]->setEnabled(true);
02469 }
02470 
02471 void StoryEditor::updateTextFrame()
02472 {
02473        //Return immediately if we dont have to update the frame
02474        if (!textChanged)
02475               return;
02476        PageItem *nextItem = currItem;
02477 #if 0
02478        if (currItem->asTextFrame())
02479        {
02480               while (nextItem != 0)
02481               {
02482                      if (nextItem->prevInChain() != 0)
02483                             nextItem = nextItem->prevInChain();
02484                      else
02485                             break;
02486               }
02487        }
02488 #endif
02489        PageItem* nb2 = nextItem;
02490        nb2->itemText.clear();
02491 #if 0
02492        if (currItem->asTextFrame())
02493        {
02494               while (nb2 != 0)
02495               {
02496               for (int j = nb2->firstInFrame(); j <= nb2->lastInFrame(); ++j)
02497               {
02498                      if ((nb2->itemText.text(j) == SpecialChars::OBJECT) && (nb2->itemText.item(j)->cembedded != 0))
02499                      {
02500                             QPtrList<PageItem> emG;
02501                             emG.clear();
02502                             emG.append(nb2->itemText.item(j)->cembedded);
02503                             if (nb2->itemText.item(j)->cembedded->Groups.count() != 0)
02504                             {
02505                                    for (uint ga=0; ga<Editor->FrameItems.count(); ++ga)
02506                                    {
02507                                           if (Editor->FrameItems.at(ga)->Groups.count() != 0)
02508                                           {
02509                                                  if (Editor->FrameItems.at(ga)->Groups.top() == nb2->itemText.item(j)->cembedded->Groups.top())
02510                                                  {
02511                                                         if (Editor->FrameItems.at(ga)->ItemNr != nb2->itemText.item(j)->cembedded->ItemNr)
02512                                                         {
02513                                                                if (emG.find(Editor->FrameItems.at(ga)) == -1)
02514                                                                       emG.append(Editor->FrameItems.at(ga));
02515                                                         }
02516                                                  }
02517                                           }
02518                                    }
02519                             }
02520                             for (uint em = 0; em < emG.count(); ++em)
02521                             {
02522                                    currDoc->FrameItems.remove(emG.at(em));
02523                             }
02524                      }
02525               }
02526               nb2->itemText.clear();
02527                      nb2->CPos = 0;
02528                      nb2->Dirty = false;
02529                      nb2 = nb2->nextInChain();
02530               }
02531        }
02532 #endif
02533        Editor->saveItemText(nextItem);
02534 #if 0
02535        QPtrList<PageItem> FrameItemsDel;
02536        FrameItemsDel.setAutoDelete(true);
02537        for (uint a = 0; a < Editor->FrameItems.count(); ++a)
02538        {
02539               if (currDoc->FrameItems.findRef(Editor->FrameItems.at(a)) == -1)
02540                      FrameItemsDel.append(Editor->FrameItems.at(a));
02541        }
02542        for (uint a = 0; a < FrameItemsDel.count(); ++a)
02543        {
02544               Editor->FrameItems.remove(FrameItemsDel.at(a));
02545        }
02546        FrameItemsDel.clear();
02547 #endif
02548        currDoc->updateFrameItems();
02549 #if 0
02550        if (currItem->asTextFrame())
02551        {
02552               nextItem->layout();
02553               nb2 = nextItem;
02554               while (nb2 != 0)
02555               {
02556                      nb2->Dirty = false;
02557                      nb2 = nb2->nextInChain();
02558               }
02559        }
02560 #endif
02561        ScCore->primaryMainWindow()->view->DrawNew();
02562        textChanged = false;
02563        seActions["fileRevert"]->setEnabled(false);
02564        seActions["editUpdateFrame"]->setEnabled(false);
02565        emit DocChanged();
02566 }
02567 
02568 void StoryEditor::SearchText()
02569 {
02570        blockUpdate = true;
02571        EditorBar->setRepaint(false);
02572        SearchReplace* dia = new SearchReplace(this, currDoc, currItem, false);
02573        dia->exec();
02574        delete dia;
02575        qApp->processEvents();
02576        blockUpdate = false;
02577        EditorBar->setRepaint(true);
02578        EditorBar->doRepaint();
02579 }
02580 
02581 void StoryEditor::slotEditStyles()
02582 {
02583        ScCore->primaryMainWindow()->styleMgr()->exec(this);
02584 }
02585 
02586 void StoryEditor::newAlign(int st)
02587 {
02588        Editor->CurrAlign = st;
02589        changeAlign(st);
02590 }
02591 
02592 
02593 void StoryEditor::newStyle(const QString& name)
02594 {
02595        Editor->currentParaStyle = name;
02596        changeStyle();
02597 }
02598 
02599 
02600 void StoryEditor::changeStyleSB(int pa, const QString& name)
02601 {
02602        Editor->currentParaStyle = name;
02603        ParagraphStyle newStyle;
02604        newStyle.setParent(Editor->currentParaStyle);
02605 
02606        if (Editor->StyledText.length() != 0)
02607        {
02608               disconnect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02609               disconnect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02610               disconnect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02611 
02612 /*            qDebug(QString("changeStyleSB: pa=%2, start=%2, new=%3 %4")
02613                         .arg(pa)
02614                         .arg(Editor->StyledText.startOfParagraph(pa))
02615                         .arg(newStyle.parent())
02616                         .arg(newStyle.hasParent()));
02617 */
02618               Editor->StyledText.applyStyle(Editor->StyledText.startOfParagraph(pa), newStyle);
02619 
02620               Editor->updateFromChars(pa);
02621 //            Editor->setCursorPosition(pa, 0);
02622 //            updateProps(pa, 0);
02623               Editor->ensureCursorVisible();
02624               EditorBar->doRepaint();
02625               connect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02626               connect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02627               connect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02628        }
02629        else
02630        {
02631               Editor->prevFont = Editor->CurrFont;
02632               Editor->CurrFont = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().font().scName();
02633               Editor->CurrFontSize = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fontSize();
02634               Editor->CurrentStyle = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().effects();
02635               Editor->CurrTextFill = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fillColor();
02636               Editor->CurrTextFillSh = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fillShade();
02637               Editor->CurrTextStroke = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strokeColor();
02638               Editor->CurrTextStrokeSh = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strokeShade();
02639               Editor->CurrTextShadowX = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().shadowXOffset();
02640               Editor->CurrTextShadowY = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().shadowYOffset();
02641               Editor->CurrTextOutline = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().outlineWidth();
02642               Editor->CurrTextUnderPos = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().underlineOffset();
02643               Editor->CurrTextUnderWidth = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().underlineWidth();
02644               Editor->CurrTextStrikePos = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strikethruOffset();
02645               Editor->CurrTextStrikeWidth = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strikethruWidth();
02646 
02647               Editor->setStyle(Editor->CurrentStyle);
02648               if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
02649               {
02650                      StrokeTools->TxStroke->setEnabled(true);
02651                      StrokeTools->PM1->setEnabled(true);
02652               }
02653               else
02654               {
02655                      StrokeTools->TxStroke->setEnabled(false);
02656                      StrokeTools->PM1->setEnabled(false);
02657               }
02658               //qDebug("SE::changeStyleSB: cursor");
02659               Editor->setCursorPosition(0, 0);
02660               updateProps(0, 0);
02661        }
02662 
02663        Editor->sync();
02664        Editor-> repaintContents();
02665        modifiedText();
02666        Editor->setFocus();
02667 }
02668 
02669 void StoryEditor::changeStyle()
02670 {
02671        int p=0, i=0;
02672        bool sel = false;
02673        ParagraphStyle newStyle;
02674        newStyle.setParent(Editor->currentParaStyle);
02675 
02676        Editor->getCursorPosition(&p, &i);
02677        if (Editor->StyledText.length() != 0)
02678        {
02679               disconnect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02680               disconnect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02681               disconnect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02682               int PStart = 0;
02683               int PEnd = 0;
02684               int SelStart = 0;
02685               int SelEnd = 0;
02686               int PStart2 = 0;
02687               int PEnd2 = 0;
02688               int SelStart2 = 0;
02689               int SelEnd2 = 0;
02690               if (Editor->hasSelectedText())
02691               {
02692                      Editor->getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
02693                      PStart2 = PStart;
02694                      PEnd2 = PEnd;
02695                      SelStart2 = SelStart;
02696                      SelEnd2 = SelEnd;
02697                      sel = true;
02698               }
02699               else
02700               {
02701                      PStart = p;
02702                      PEnd = p;
02703               }
02704               for (int pa = PStart; pa <= PEnd; ++pa)
02705               {
02706                      Editor->StyledText.applyStyle(Editor->StyledText.startOfParagraph(pa), newStyle);
02707                      Editor->updateFromChars(pa);
02708               }
02709               if (sel)
02710                      Editor->setSelection(PStart2, SelStart2, PEnd2, SelEnd2);
02711               //qDebug("SE::changeStyle: cursor");
02712               Editor->setCursorPosition(p, i);
02713               Editor->ensureCursorVisible();
02714               updateProps(p, i);
02715               EditorBar->doRepaint();
02716               connect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02717               connect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02718               connect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02719        }
02720        else
02721        {
02722               Editor->prevFont = Editor->CurrFont;
02723               Editor->CurrFont = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().font().scName();
02724               Editor->CurrFontSize = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fontSize();
02725               Editor->CurrentStyle = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().effects();
02726               Editor->CurrTextFill = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fillColor();
02727               Editor->CurrTextFillSh = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().fillShade();
02728               Editor->CurrTextStroke = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strokeColor();
02729               Editor->CurrTextStrokeSh = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strokeShade();
02730               Editor->CurrTextShadowX = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().shadowXOffset();
02731               Editor->CurrTextShadowY = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().shadowYOffset();
02732               Editor->CurrTextOutline = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().outlineWidth();
02733               Editor->CurrTextUnderPos = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().underlineOffset();
02734               Editor->CurrTextUnderWidth = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().underlineWidth();
02735               Editor->CurrTextStrikePos = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strikethruOffset();
02736               Editor->CurrTextStrikeWidth = currDoc->paragraphStyles()[Editor->currentParaStyle].charStyle().strikethruWidth();
02737 
02738               Editor->setStyle(Editor->CurrentStyle);
02739               if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
02740               {
02741                      StrokeTools->TxStroke->setEnabled(true);
02742                      StrokeTools->PM1->setEnabled(true);
02743               }
02744               else
02745               {
02746                      StrokeTools->TxStroke->setEnabled(false);
02747                      StrokeTools->PM1->setEnabled(false);
02748               }
02749               //qDebug("SE::changeStyle00: cursor");
02750               Editor->setCursorPosition(0, 0);
02751               updateProps(0, 0);
02752        }
02753        modifiedText();
02754        Editor->sync();
02755        Editor-> repaintContents();
02756        Editor->setFocus();
02757 }
02758 
02759 
02760 void StoryEditor::changeAlign(int )
02761 {
02762        int p=0, i=0;
02763        bool sel = false;
02764        ParagraphStyle newStyle;
02765        newStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(Editor->CurrAlign));
02766 
02767        Editor->getCursorPosition(&p, &i);
02768        if (Editor->StyledText.length() != 0)
02769        {
02770               disconnect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02771               disconnect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02772               disconnect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02773               int PStart = 0;
02774               int PEnd = 0;
02775               int SelStart = 0;
02776               int SelEnd = 0;
02777               int PStart2 = 0;
02778               int PEnd2 = 0;
02779               int SelStart2 = 0;
02780               int SelEnd2 = 0;
02781               if (Editor->hasSelectedText())
02782               {
02783                      Editor->getSelection(&PStart, &SelStart, &PEnd, &SelEnd);
02784                      PStart2 = PStart;
02785                      PEnd2 = PEnd;
02786                      SelStart2 = SelStart;
02787                      SelEnd2 = SelEnd;
02788                      sel = true;
02789               }
02790               else
02791               {
02792                      PStart = p;
02793                      PEnd = p;
02794               }
02795               for (int pa = PStart; pa <= PEnd; ++pa)
02796               {
02797                      Editor->StyledText.applyStyle(Editor->StyledText.startOfParagraph(pa), newStyle);
02798                      Editor->updateFromChars(pa);
02799               }
02800               if (sel)
02801                      Editor->setSelection(PStart2, SelStart2, PEnd2, SelEnd2);
02802               //qDebug("SE::changeAlign: cursor");
02803               Editor->setCursorPosition(p, i);
02804               Editor->ensureCursorVisible();
02805               updateProps(p, i);
02806               EditorBar->doRepaint();
02807               connect(Editor, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(updateProps(int, int)));
02808               connect(Editor, SIGNAL(textChanged()), this, SLOT(modifiedText()));
02809               connect(Editor, SIGNAL(textChanged()), EditorBar, SLOT(doRepaint()));
02810        }
02811        modifiedText();
02812        Editor->sync();
02813        Editor->repaintContents();
02814        Editor->setFocus();
02815 }
02816 
02817 
02818 void StoryEditor::modifiedText()
02819 {
02820        textChanged = true;
02821        firstSet = true;
02822        seActions["fileRevert"]->setEnabled(true);
02823        seActions["editUpdateFrame"]->setEnabled(true);
02824 //     seActions["editPaste"]->setEnabled(Editor->tBuffer.length() != 0);
02825        updateStatus();
02826 }
02827 
02828 void StoryEditor::LoadTextFile()
02829 {
02830        if (Do_new())
02831        {
02832               EditorBar->setRepaint(false);
02833               QString LoadEnc = "";
02834               QString fileName = "";
02835               PrefsContext* dirs = prefsManager->prefsFile->getContext("dirs");
02836               QString wdir = dirs->get("story_load", prefsManager->documentDir());
02837               CustomFDialog dia(this, wdir, tr("Open"), tr("Text Files (*.txt);;All Files(*)"), fdExistingFiles | fdShowCodecs);
02838               if (dia.exec() != QDialog::Accepted)
02839                      return;
02840               LoadEnc = dia.TxCodeM->currentText();
02841               if (LoadEnc == "UTF-16")
02842                      LoadEnc = "ISO-10646-UCS-2";
02843               fileName =  dia.selectedFile();
02844               if (!fileName.isEmpty())
02845               {
02846                      dirs->set("story_load", fileName.left(fileName.findRev("/")));
02847                      QString txt;
02848                      if (Serializer::readWithEncoding(fileName, LoadEnc, txt))
02849                      {
02850                             txt.replace(QRegExp("\r"), "");
02851                             txt.replace(QRegExp("\n"), QChar(13));
02852                             Editor->loadText(txt, currItem);
02853                             seActions["editPaste"]->setEnabled(false);
02854                             seActions["editCopy"]->setEnabled(false);
02855                             seActions["editCut"]->setEnabled(false);
02856                             seActions["editClear"]->setEnabled(false);
02857                      }
02858               }
02859               EditorBar->setRepaint(true);
02860               EditorBar->doRepaint();
02861        }
02862        Editor->sync();
02863        Editor-> repaintContents();
02864 }
02865 
02866 void StoryEditor::SaveTextFile()
02867 {
02868        blockUpdate = true;
02869        QString LoadEnc = "";
02870        QString fileName = "";
02871        PrefsContext* dirs = prefsManager->prefsFile->getContext("dirs");
02872        QString wdir = dirs->get("story_save", prefsManager->appPrefs.DocDir);
02873        CustomFDialog dia(this, wdir, tr("Save as"), tr("Text Files (*.txt);;All Files(*)"), fdShowCodecs);
02874        qApp->processEvents();
02875        if (dia.exec() != QDialog::Accepted)
02876        {
02877               blockUpdate = false;
02878               return;
02879        }
02880        LoadEnc = dia.TxCodeM->currentText();
02881        if (LoadEnc == "UTF-16")
02882               LoadEnc = "ISO-10646-UCS-2";
02883        fileName =  dia.selectedFile();
02884        if (!fileName.isEmpty())
02885        {
02886               dirs->set("story_save", fileName.left(fileName.findRev("/")));
02887               Serializer::writeWithEncoding(fileName, LoadEnc, Editor->text());
02888        }
02889        blockUpdate = false;
02890 }
02891 
02892 bool StoryEditor::textDataChanged() const
02893 {
02894        return textChanged;
02895 }
02896 
02897 PageItem* StoryEditor::currentItem() const
02898 {
02899        return currItem;
02900 }
02901 
02902 ScribusDoc* StoryEditor::currentDocument() const
02903 {
02904        return currDoc;
02905 }
02906 
02907 void StoryEditor::specialActionKeyEvent(const QString& /*actionName*/, int unicodevalue)
02908 {
02909        Editor->insChars(QString(QChar(unicodevalue)));
02910        QString guiInsertString=QChar(unicodevalue);
02911        bool setColor=false;
02912        if (unicodevalue == seActions["unicodePageNumber"]->actionInt())
02913        {
02914               setColor=true;
02915               guiInsertString="#";
02916        }
02917        if (unicodevalue == seActions["unicodeNonBreakingSpace"]->actionInt())
02918        {
02919               setColor=true;
02920               guiInsertString="_";
02921        }
02922        if (unicodevalue == seActions["unicodeFrameBreak"]->actionInt())
02923        {
02924               setColor=true;
02925               guiInsertString="|";
02926        }
02927        if (unicodevalue == seActions["unicodeNewLine"]->actionInt())
02928        {
02929               setColor=true;
02930               guiInsertString="*";
02931        }
02932        if (unicodevalue == seActions["unicodeColumnBreak"]->actionInt())
02933        {
02934               setColor=true;
02935               guiInsertString="^";
02936        }
02937        if (unicodevalue == seActions["unicodeNonBreakingHyphen"]->actionInt())
02938        {
02939               setColor=true;
02940               guiInsertString="=";
02941        }
02942        if (setColor)
02943               Editor->setFarbe(true);
02944        Editor->insert(guiInsertString);
02945        if (setColor)
02946               Editor->setFarbe(false);
02947        modifiedText();
02948        EditorBar->setRepaint(true);
02949        EditorBar->doRepaint();
02950 }
02951 
02952 void StoryEditor::updateUnicodeActions()
02953 {
02954        if (Editor->prevFont!=Editor->CurrFont)
02955               ScCore->primaryMainWindow()->actionManager->enableUnicodeActions(&seActions, true, Editor->CurrFont);
02956 }