124
124
QPoint viewPos = editor->viewport()->mapFromGlobal(globalPos);
125
125
int p = editor->cursorForPosition(QPoint(2, viewPos.y())).position();
126
126
CurrentPar = editor->StyledText.nrOfParagraph(p);
127
int pos = editor->StyledText.startOfParagraph(p);
127
int pos = editor->StyledText.startOfParagraph( editor->StyledText.nrOfParagraph(p) );
129
QString styleName = "";
129
130
ParaStyleComboBox* paraStyleCombo = new ParaStyleComboBox(this);
130
131
paraStyleCombo->setDoc(editor->doc);
131
132
if ((CurrentPar < static_cast<int>(editor->StyledText.nrOfParagraphs())) && (editor->StyledText.length() != 0))
133
134
int len = editor->StyledText.endOfParagraph(CurrentPar) - editor->StyledText.startOfParagraph(CurrentPar);
135
paraStyleCombo->setFormat(editor->StyledText.paragraphStyle(pos).displayName());
137
paraStyleCombo->setFormat("");
136
styleName = editor->StyledText.paragraphStyle(pos).parent(); //FIXME ParaStyleComboBox and use localized style name
140
paraStyleCombo->setFormat("");
138
paraStyleCombo->setFormat(styleName);
141
139
connect(paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setPStyle(const QString&)));
143
141
paraStyleAct = new QWidgetAction(this);
269
267
setAutoFillBackground(true);
270
268
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
271
269
connect(this->document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(handleContentsChange(int, int, int)));
270
SuspendContentsChange = 0;
274
273
void SEditor::setCurrentDocument(ScribusDoc *docc)
280
279
void SEditor::inputMethodEvent(QInputMethodEvent *event)
282
281
QString uc = event->commitString();
283
if ((!uc.isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
282
SuspendContentsChange = 1; // prevent our handler from doing anything
283
bool changed = false;
285
if(textCursor().hasSelection())
287
pos = textCursor().selectionStart();
288
StyledText.removeChars(pos, textCursor().selectionEnd() - pos);
294
if ((*doc->AllFonts)[CurrFont].canRender(uc[0]))
296
pos = textCursor().hasSelection() ? textCursor().selectionStart() : textCursor().position();
297
pos = qMin(pos, StyledText.length());
301
event->setCommitString("");
304
QTextEdit::inputMethodEvent(event);
305
SuspendContentsChange = 0;
308
handleContentsChange(pos, 0, uc.length());
313
emit SideBarUp(true);
314
emit SideBarUpdate();
316
/* if ((!uc.isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
285
318
// Should be processed by the handleContentsChange slot
286
319
// insertCharsInternal(event->commitString());
287
320
QTextEdit::inputMethodEvent(event);
288
321
emit SideBarUp(true);
289
322
emit SideBarUpdate();
293
326
void SEditor::keyPressEvent(QKeyEvent *k)
448
481
void SEditor::handleContentsChange(int position, int charsRemoved, int charsAdded)
483
// As of Qt 4.7.4, Cococa-QTextEdit output of input method is broken.
484
// We need a workaround to avoit the bug.
485
if(SuspendContentsChange != 0)
450
487
if (blockContentsChangeHook <= 0)
452
489
if (charsRemoved > 0 && StyledText.length() > 0)
598
634
void SEditor::setAlign(int align)
636
QTextCursor tCursor = this->textCursor();
637
setAlign(tCursor, align);
640
void SEditor::setAlign(QTextCursor& tCursor, int align)
600
642
++blockContentsChangeHook;
643
QTextBlockFormat blockFormat;
604
setAlignment(Qt::AlignLeft);
647
blockFormat.setAlignment(Qt::AlignLeft);
607
setAlignment(Qt::AlignCenter);
650
blockFormat.setAlignment(Qt::AlignCenter);
610
setAlignment(Qt::AlignRight);
653
blockFormat.setAlignment(Qt::AlignRight);
614
setAlignment(Qt::AlignJustify);
657
blockFormat.setAlignment(Qt::AlignJustify);
662
tCursor.setBlockFormat(blockFormat);
619
663
--blockContentsChangeHook;
630
674
int npars = currItem->itemText.nrOfParagraphs();
631
675
SelParaStart = 0;
632
while (currItem->CPos >= (SelCharStart = currItem->itemText.endOfParagraph(SelParaStart))
676
while (currItem->itemText.cursorPosition() >= (SelCharStart = currItem->itemText.endOfParagraph(SelParaStart))
633
677
&& SelParaStart < npars)
635
if (currItem->CPos < SelCharStart)
636
SelCharStart = currItem->CPos;
679
if (currItem->itemText.cursorPosition() < SelCharStart)
680
SelCharStart = currItem->itemText.cursorPosition();
637
681
SelCharStart -= currItem->itemText.startOfParagraph(SelParaStart);
638
682
StoredSel = false;
639
683
//qDebug() << "SE::loadItemText: cursor";
680
724
int cSty = StyledText.charStyle(position).effects();
681
725
int pAli = StyledText.paragraphStyle(position).alignment();
684
728
for (int pos = position; pos < end; ++pos)
686
730
const CharStyle& cstyle(StyledText.charStyle(pos));
787
831
void SEditor::updateFromChars(int pa)
789
833
int start = StyledText.startOfParagraph(pa);
790
int end = StyledText.endOfParagraph(pa);
834
int end = StyledText.endOfParagraph(pa);
791
835
if (start >= end)
793
837
setUpdatesEnabled(false);
794
838
int SelStart = start;
796
840
int pos = textCursor().position();
797
841
textCursor().clearSelection();
798
int Csty = StyledText.charStyle(start).effects();
842
int effects = StyledText.charStyle(start).effects();
799
843
for (int a = start; a < end; ++a)
801
if (Csty == StyledText.charStyle(a).effects())
845
if (effects == StyledText.charStyle(a).effects())
805
849
textCursor().setPosition(SelStart);
806
850
textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor);
808
852
textCursor().clearSelection();
809
Csty = StyledText.charStyle(a).effects();
853
effects = StyledText.charStyle(a).effects();
810
854
SelStart = SelEnd;
814
textCursor().setPosition(SelStart);
815
textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor);
817
textCursor().clearSelection();
818
setAlign(StyledText.paragraphStyle(start).alignment());
858
QTextCursor tCursor = textCursor();
859
tCursor.setPosition(SelStart);
860
tCursor.setPosition(SelEnd, QTextCursor::KeepAnchor);
861
setEffects(tCursor, effects);
862
setAlign(tCursor, StyledText.paragraphStyle(start).alignment());
863
tCursor.clearSelection();
819
864
setUpdatesEnabled(true);
820
QTextCursor tCursor = textCursor();
865
tCursor = textCursor();
821
866
tCursor.setPosition(pos);
822
867
setTextCursor(tCursor);
868
913
StoredSel = false;
871
void SEditor::setStyle(int Csty)
916
void SEditor::setEffects(int effects)
918
QTextCursor tCursor = textCursor();
919
setEffects(tCursor, effects);
920
//setTextCursor(tCursor);
923
void SEditor::setEffects(QTextCursor& tCursor, int effects)
873
925
++blockContentsChangeHook;
874
926
QTextCharFormat charF;
876
928
charF.setFontUnderline(true);
878
930
charF.setFontUnderline(false);
880
932
charF.setFontStrikeOut(true);
882
934
charF.setFontStrikeOut(false);
884
936
charF.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
937
else if (effects & 2)
886
938
charF.setVerticalAlignment(QTextCharFormat::AlignSubScript);
888
940
charF.setVerticalAlignment(QTextCharFormat::AlignNormal);
889
QTextCursor tCursor = textCursor();
890
941
tCursor.setCharFormat(charF);
891
setTextCursor(tCursor);
892
942
--blockContentsChangeHook;
1520
1570
void StoryEditor::showEvent(QShowEvent *)
1522
1572
charSelect = new CharSelect(this);
1523
charSelect->userTableModel()->setCharacters(
1524
ScCore->primaryMainWindow()->charPalette->userTableModel()->characters());
1573
charSelect->userTableModel()->setCharactersAndFonts(ScCore->primaryMainWindow()->charPalette->userTableModel()->characters(), ScCore->primaryMainWindow()->charPalette->userTableModel()->fonts());
1525
1574
connect(charSelect, SIGNAL(insertSpecialChar()),
1526
1575
this, SLOT(slot_insertSpecialChar()));
1527
connect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
1528
this, SLOT(slot_insertUserSpecialChar(QChar)));
1576
connect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)),
1577
this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
1531
1580
void StoryEditor::hideEvent(QHideEvent *)
1535
1584
if (charSelectUsed)
1537
ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharacters(
1538
charSelect->userTableModel()->characters());
1586
ScCore->primaryMainWindow()->charPalette->userTableModel()->setCharactersAndFonts(charSelect->userTableModel()->characters(), charSelect->userTableModel()->fonts());
1540
1588
if (charSelect->isVisible())
1541
1589
charSelect->close();
1542
1590
disconnect(charSelect, SIGNAL(insertSpecialChar()),
1543
1591
this, SLOT(slot_insertSpecialChar()));
1544
disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar)),
1545
this, SLOT(slot_insertUserSpecialChar(QChar)));
1592
disconnect(charSelect, SIGNAL(insertUserSpecialChar(QChar, QString)),
1593
this, SLOT(slot_insertUserSpecialChar(QChar, QString)));
1546
1594
delete charSelect;
1547
1595
charSelect = NULL;
1996
2046
connect(Editor, SIGNAL(SideBarUp(bool )), EditorBar, SLOT(setRepaint(bool )));
1997
2047
connect(Editor, SIGNAL(SideBarUpdate( )), EditorBar, SLOT(doRepaint()));
1998
2048
connect(Editor->document(), SIGNAL(contentsChange(int, int, int)), Editor, SLOT(handleContentsChange(int, int, int)));
2049
Editor->SuspendContentsChange = 0;
1999
2050
// 10/12/2004 - pv - #1203: wrong selection on double click
2000
2051
// connect(Editor, SIGNAL(doubleClicked(int, int)), this, SLOT(doubleClick(int, int)));
2001
2052
connect(EditorBar, SIGNAL(ChangeStyle(int, const QString& )), this, SLOT(changeStyleSB(int, const QString&)));
2260
2311
void StoryEditor::newTxStyle(int s)
2262
Editor->CurrentStyle = static_cast<StyleFlag>(s);
2313
Editor->CurrentEffects = static_cast<StyleFlag>(s);
2263
2314
CharStyle charStyle;
2264
charStyle.setFeatures(Editor->CurrentStyle.featureList());
2315
charStyle.setFeatures(Editor->CurrentEffects.featureList());
2265
2316
Editor->updateSel(charStyle);
2266
Editor->setStyle(s);
2317
Editor->setEffects(s);
2267
2318
if ((s & ScStyle_Outline) || (s & ScStyle_Shadowed))
2269
2320
StrokeTools->TxStroke->setEnabled(true);
2384
2435
const CharStyle& curstyle(pos < Editor->StyledText.length()? currItem->itemText.charStyle(pos) : currItem->itemText.defaultStyle().charStyle());
2385
2436
const ParagraphStyle parStyle(pos < Editor->StyledText.length()? currItem->itemText.paragraphStyle(pos) : currItem->itemText.defaultStyle());
2437
Editor->currentParaStyle = parStyle.parent();
2386
2438
Editor->CurrAlign = parStyle.alignment();
2387
2439
Editor->CurrTextFill = curstyle.fillColor();
2388
2440
Editor->CurrTextFillSh = curstyle.fillShade();
2390
2442
Editor->CurrTextStrokeSh = curstyle.strokeShade();
2391
2443
Editor->prevFont = Editor->CurrFont;
2392
2444
Editor->CurrFont = curstyle.font().scName();
2393
Editor->CurrFontSize = curstyle.fontSize();
2394
Editor->CurrentStyle = curstyle.effects();
2395
Editor->currentParaStyle = curstyle.parent();
2396
Editor->CurrTextKern = curstyle.tracking();
2397
Editor->CurrTextScale = curstyle.scaleH();
2445
Editor->CurrFontSize = curstyle.fontSize();
2446
Editor->CurrentEffects = curstyle.effects();
2447
Editor->CurrTextKern = curstyle.tracking();
2448
Editor->CurrTextScale = curstyle.scaleH();
2398
2449
Editor->CurrTextScaleV = curstyle.scaleV();
2399
2450
Editor->CurrTextBase = curstyle.baselineOffset();
2400
2451
Editor->CurrTextShadowX = curstyle.shadowXOffset();
2435
2486
AlignTools->SetAlign(Editor->CurrAlign);
2436
2487
AlignTools->SetParaStyle(Editor->currentParaStyle);
2437
2488
StyleTools->SetKern(Editor->CurrTextKern);
2438
StyleTools->SetStyle(Editor->CurrentStyle);
2489
StyleTools->SetStyle(Editor->CurrentEffects);
2439
2490
StyleTools->SetShadow(Editor->CurrTextShadowX, Editor->CurrTextShadowY);
2440
2491
StyleTools->setOutline(Editor->CurrTextOutline);
2441
2492
StyleTools->setUnderline(Editor->CurrTextUnderPos, Editor->CurrTextUnderWidth);
2445
2496
FontTools->SetScale(Editor->CurrTextScale);
2446
2497
FontTools->SetScaleV(Editor->CurrTextScaleV);
2448
if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
2499
if ((Editor->CurrentEffects & ScStyle_Outline) || (Editor->CurrentEffects & ScStyle_Shadowed))
2450
2501
StrokeTools->TxStroke->setEnabled(true);
2451
2502
StrokeTools->PM1->setEnabled(true);
2455
2506
StrokeTools->TxStroke->setEnabled(false);
2456
2507
StrokeTools->PM1->setEnabled(false);
2458
Editor->setStyle(Editor->CurrentStyle);
2509
Editor->setEffects(Editor->CurrentEffects);
2459
2510
firstSet = true;
2460
2511
updateUnicodeActions();
2463
2514
int parStart = Editor->StyledText.startOfParagraph(p);
2464
2515
const ParagraphStyle& parStyle(Editor->StyledText.paragraphStyle(parStart));
2465
Editor->currentParaStyle = parStyle.displayName();
2516
Editor->currentParaStyle = parStyle.parent(); //FIXME ParaStyleComboBox and use localized style name
2466
2517
if (Editor->StyledText.endOfParagraph(p) <= parStart)
2468
2519
Editor->prevFont = Editor->CurrFont;
2469
2520
Editor->CurrFont = parStyle.charStyle().font().scName();
2470
Editor->CurrFontSize = parStyle.charStyle().fontSize();
2471
Editor->CurrentStyle = parStyle.charStyle().effects();
2472
Editor->CurrTextFill = parStyle.charStyle().fillColor();
2521
Editor->CurrFontSize = parStyle.charStyle().fontSize();
2522
Editor->CurrentEffects = parStyle.charStyle().effects();
2523
Editor->CurrTextFill = parStyle.charStyle().fillColor();
2473
2524
Editor->CurrTextFillSh = parStyle.charStyle().fillShade();
2474
2525
Editor->CurrTextStroke = parStyle.charStyle().strokeColor();
2475
2526
Editor->CurrTextStrokeSh = parStyle.charStyle().strokeShade();
2481
2532
Editor->CurrTextStrikePos = parStyle.charStyle().strikethruOffset();
2482
2533
Editor->CurrTextStrikeWidth = parStyle.charStyle().strikethruWidth();
2483
2534
Editor->setAlign(Editor->CurrAlign);
2484
Editor->setStyle(Editor->CurrentStyle);
2535
Editor->setEffects(Editor->CurrentEffects);
2513
2564
Editor->prevFont = Editor->CurrFont;
2514
2565
Editor->CurrFont = charStyle.font().scName();
2515
2566
Editor->CurrFontSize = charStyle.fontSize();
2516
Editor->CurrentStyle = charStyle.effects() & static_cast<StyleFlag>(1919);
2517
Editor->CurrTextKern = charStyle.tracking();
2518
Editor->CurrTextScale = charStyle.scaleH();
2567
Editor->CurrentEffects = charStyle.effects() & static_cast<StyleFlag>(1919);
2568
Editor->CurrTextKern = charStyle.tracking();
2569
Editor->CurrTextScale = charStyle.scaleH();
2519
2570
Editor->CurrTextScaleV = charStyle.scaleV();
2520
2571
Editor->CurrTextBase = charStyle.baselineOffset();
2521
2572
Editor->CurrTextShadowX = charStyle.shadowXOffset();
2555
2606
StrokeTools->SetColor(c);
2556
if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
2607
if ((Editor->CurrentEffects & ScStyle_Outline) || (Editor->CurrentEffects & ScStyle_Shadowed))
2558
2609
StrokeTools->TxStroke->setEnabled(true);
2559
2610
StrokeTools->PM1->setEnabled(true);
2564
2615
StrokeTools->PM1->setEnabled(false);
2566
2617
StyleTools->SetKern(Editor->CurrTextKern);
2567
StyleTools->SetStyle(Editor->CurrentStyle);
2618
StyleTools->SetStyle(Editor->CurrentEffects);
2568
2619
StyleTools->SetShadow(Editor->CurrTextShadowX, Editor->CurrTextShadowY);
2569
2620
StyleTools->setOutline(Editor->CurrTextOutline);
2570
2621
StyleTools->setUnderline(Editor->CurrTextUnderPos, Editor->CurrTextUnderWidth);
2984
3034
Editor->prevFont = Editor->CurrFont;
2985
3035
Editor->CurrFont = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().font().scName();
2986
3036
Editor->CurrFontSize = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fontSize();
2987
Editor->CurrentStyle = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().effects();
2988
Editor->CurrTextFill = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillColor();
3037
Editor->CurrentEffects = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().effects();
3038
Editor->CurrTextFill = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillColor();
2989
3039
Editor->CurrTextFillSh = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillShade();
2990
3040
Editor->CurrTextStroke = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strokeColor();
2991
3041
Editor->CurrTextStrokeSh = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strokeShade();
2997
3047
Editor->CurrTextStrikePos = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strikethruOffset();
2998
3048
Editor->CurrTextStrikeWidth = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strikethruWidth();
3000
Editor->setStyle(Editor->CurrentStyle);
3001
if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
3050
Editor->setEffects(Editor->CurrentEffects);
3051
if ((Editor->CurrentEffects & ScStyle_Outline) || (Editor->CurrentEffects & ScStyle_Shadowed))
3003
3053
StrokeTools->TxStroke->setEnabled(true);
3004
3054
StrokeTools->PM1->setEnabled(true);
3072
3122
Editor->prevFont = Editor->CurrFont;
3073
3123
Editor->CurrFont = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().font().scName();
3074
3124
Editor->CurrFontSize = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fontSize();
3075
Editor->CurrentStyle = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().effects();
3076
Editor->CurrTextFill = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillColor();
3125
Editor->CurrentEffects = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().effects();
3126
Editor->CurrTextFill = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillColor();
3077
3127
Editor->CurrTextFillSh = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().fillShade();
3078
3128
Editor->CurrTextStroke = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strokeColor();
3079
3129
Editor->CurrTextStrokeSh = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strokeShade();
3085
3135
Editor->CurrTextStrikePos = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strikethruOffset();
3086
3136
Editor->CurrTextStrikeWidth = currDoc->paragraphStyles().get(Editor->currentParaStyle).charStyle().strikethruWidth();
3088
Editor->setStyle(Editor->CurrentStyle);
3089
if ((Editor->CurrentStyle & ScStyle_Outline) || (Editor->CurrentStyle & ScStyle_Shadowed))
3138
Editor->setEffects(Editor->CurrentEffects);
3139
if ((Editor->CurrentEffects & ScStyle_Outline) || (Editor->CurrentEffects & ScStyle_Shadowed))
3091
3141
StrokeTools->TxStroke->setEnabled(true);
3092
3142
StrokeTools->PM1->setEnabled(true);