Rev 113 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
102 | Franz | 1 | /*************************************************************************** |
2 | story.cpp - description |
||
3 | ------------------- |
||
4 | begin : Tue Nov 11 2003 |
||
5 | copyright : (C) 2003 by Franz Schmid |
||
6 | email : Franz.Schmid@altmuehlnet.de |
||
7 | ***************************************************************************/ |
||
8 | |||
9 | /*************************************************************************** |
||
10 | * * |
||
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | ***************************************************************************/ |
||
17 | #include "story.h" |
||
18 | #include "story.moc" |
||
19 | #include <qlayout.h> |
||
20 | #include <qtooltip.h> |
||
21 | #include <qpixmap.h> |
||
22 | #include <qcombobox.h> |
||
103 | Franz | 23 | #include <qmessagebox.h> |
102 | Franz | 24 | #include "serializer.h" |
25 | extern QPixmap loadIcon(QString nam); |
||
26 | |||
27 | |||
28 | SEditor::SEditor(QWidget* parent) : QTextEdit(parent) |
||
29 | { |
||
30 | clines = 0; |
||
31 | setFrameStyle( QFrame::NoFrame | QFrame::Plain ); |
||
113 | Franz | 32 | setUndoRedoEnabled(true); |
33 | setUndoDepth(50); |
||
102 | Franz | 34 | // setTextFormat(Qt::RichText); |
35 | } |
||
36 | |||
113 | Franz | 37 | void SEditor::focusInEvent(QFocusEvent *f) |
38 | { |
||
39 | bool u = isUndoAvailable(); |
||
40 | bool r = isRedoAvailable(); |
||
41 | emit UnRe(u, r); |
||
42 | QTextEdit::focusInEvent(f); |
||
43 | } |
||
44 | |||
102 | Franz | 45 | void SEditor::keyPressEvent(QKeyEvent *k) |
46 | { |
||
47 | int p, i; |
||
48 | getCursorPosition(&p, &i); |
||
49 | if ((k->key() == Key_Backspace) && (i == 0)) |
||
50 | { |
||
51 | emit bsPressed(); |
||
52 | return; |
||
53 | } |
||
54 | if ((k->key() == Key_Delete) && (i == static_cast<int>(text().length()))) |
||
55 | { |
||
56 | emit delPressed(); |
||
57 | return; |
||
58 | } |
||
59 | QTextEdit::keyPressEvent(k); |
||
60 | if (clines != lines()) |
||
61 | emit wrapped(); |
||
62 | clines = lines(); |
||
113 | Franz | 63 | bool u = isUndoAvailable(); |
64 | bool r = isRedoAvailable(); |
||
65 | emit UnRe(u, r); |
||
102 | Franz | 66 | ensureCursorVisible(); |
67 | } |
||
68 | |||
69 | |||
70 | STable::STable(QWidget* parent) : QTable(parent) |
||
71 | { |
||
72 | setShowGrid(false); |
||
112 | Franz | 73 | HomeK = 0; |
74 | EndK = 0; |
||
102 | Franz | 75 | } |
76 | |||
77 | void STable::keyPressEvent(QKeyEvent *k) |
||
78 | { |
||
79 | QString tmp; |
||
80 | int p, i, l, r, c, n; |
||
103 | Franz | 81 | SEditor *tt; |
102 | Franz | 82 | n = numRows(); |
83 | r = currentRow(); |
||
84 | c = currentColumn(); |
||
85 | if (c == 1) |
||
86 | { |
||
103 | Franz | 87 | tt = (SEditor*)cellWidget(r, 1); |
111 | Franz | 88 | if ((k->key() == Key_Prior) || (k->key() == Key_Next)) |
112 | Franz | 89 | { |
90 | HomeK = 0; |
||
91 | EndK = 0; |
||
111 | Franz | 92 | return; |
112 | Franz | 93 | } |
111 | Franz | 94 | if ((k->key() == Key_Left) |
95 | || (k->key() == Key_Right) |
||
96 | || (k->key() == Key_Down) |
||
97 | || (k->key() == Key_Up) |
||
98 | || (k->key() == Key_Home) |
||
99 | || (k->key() == Key_End)) |
||
102 | Franz | 100 | { |
101 | QTextEdit::CursorAction move; |
||
102 | tt->getCursorPosition(&p, &i); |
||
103 | switch (k->key()) |
||
104 | { |
||
111 | Franz | 105 | case Key_Home: |
112 | Franz | 106 | EndK = 0; |
107 | HomeK++; |
||
108 | switch (HomeK) |
||
109 | { |
||
110 | case 1: |
||
111 | move = QTextEdit::MoveLineStart; |
||
112 | break; |
||
113 | case 2: |
||
114 | move = QTextEdit::MoveHome; |
||
115 | break; |
||
116 | case 3: |
||
117 | tt = (SEditor*)cellWidget(0, 1); |
||
118 | setCurrentCell(0, 1); |
||
119 | move = QTextEdit::MoveHome; |
||
120 | HomeK = 0; |
||
121 | break; |
||
122 | } |
||
111 | Franz | 123 | break; |
124 | case Key_End: |
||
112 | Franz | 125 | HomeK = 0; |
126 | EndK++; |
||
127 | switch (EndK) |
||
128 | { |
||
129 | case 1: |
||
130 | move = QTextEdit::MoveLineEnd; |
||
131 | break; |
||
132 | case 2: |
||
133 | move = QTextEdit::MoveEnd; |
||
134 | break; |
||
135 | case 3: |
||
136 | tt = (SEditor*)cellWidget(n-1, 1); |
||
137 | setCurrentCell(n-1, 1); |
||
138 | move = QTextEdit::MoveEnd; |
||
139 | EndK = 0; |
||
140 | break; |
||
141 | } |
||
111 | Franz | 142 | break; |
102 | Franz | 143 | case Key_Left: |
144 | if ((i == 0) && (r > 0)) |
||
145 | { |
||
103 | Franz | 146 | tt = (SEditor*)cellWidget(r-1, 1); |
102 | Franz | 147 | setCurrentCell(r-1, 1); |
148 | move = QTextEdit::MoveEnd; |
||
149 | } |
||
150 | else |
||
151 | move = QTextEdit::MoveBackward; |
||
152 | break; |
||
153 | case Key_Right: |
||
154 | if ((i == static_cast<int>(tt->text().length())) && (r < n-1)) |
||
155 | { |
||
103 | Franz | 156 | tt = (SEditor*)cellWidget(r+1, 1); |
102 | Franz | 157 | setCurrentCell(r+1, 1); |
158 | move = QTextEdit::MoveLineStart; |
||
159 | } |
||
160 | else |
||
161 | move = QTextEdit::MoveForward; |
||
162 | break; |
||
163 | case Key_Up: |
||
164 | l = tt->lineOfChar(0, i); |
||
165 | if ((l == 0) && (r > 0)) |
||
166 | { |
||
103 | Franz | 167 | tt = (SEditor*)cellWidget(r-1, 1); |
102 | Franz | 168 | setCurrentCell(r-1, 1); |
169 | move = QTextEdit::MoveEnd; |
||
170 | } |
||
171 | else |
||
172 | move = QTextEdit::MoveUp; |
||
173 | break; |
||
174 | case Key_Down: |
||
175 | l = tt->lineOfChar(0, i); |
||
176 | if ((l == tt->lines()-1) && (r < n-1)) |
||
177 | { |
||
103 | Franz | 178 | tt = (SEditor*)cellWidget(r+1, 1); |
102 | Franz | 179 | setCurrentCell(r+1, 1); |
180 | move = QTextEdit::MoveLineStart; |
||
181 | } |
||
182 | else |
||
183 | move = QTextEdit::MoveDown; |
||
184 | break; |
||
185 | } |
||
112 | Franz | 186 | if (k->key() != Key_Home) |
187 | HomeK = 0; |
||
188 | if (k->key() != Key_End) |
||
189 | EndK = 0; |
||
102 | Franz | 190 | tt->moveCursor(move, false); |
191 | tt->setFocus(); |
||
192 | updateHeaderStates(); |
||
193 | return; |
||
194 | } |
||
195 | } |
||
112 | Franz | 196 | HomeK = 0; |
197 | EndK = 0; |
||
102 | Franz | 198 | QTable::keyPressEvent(k); |
199 | } |
||
200 | |||
201 | void STable::adjHeight(int r) |
||
202 | { |
||
103 | Franz | 203 | SEditor *cp = (SEditor*)cellWidget(r, 1); |
102 | Franz | 204 | cp->sync(); |
205 | QFontMetrics fm2(cp->currentFont()); |
||
206 | setRowHeight(r, QMAX((fm2.lineSpacing() * (cp->lines()+1)), 24)); |
||
207 | updateHeaderStates();; |
||
208 | } |
||
209 | |||
107 | Franz | 210 | StoryEditor::StoryEditor(QWidget* parent, ScribusDoc *docc, PageItem *ite) : QDialog(parent, "StoryEditor", true, 0) |
102 | Franz | 211 | { |
212 | uint a; |
||
213 | int para = 0; |
||
214 | int pstyle; |
||
215 | doc = docc; |
||
216 | QString Dat = ""; |
||
217 | setCaption( tr( "Story Editor" ) ); |
||
218 | setIcon(loadIcon("AppIcon.png")); |
||
103 | Franz | 219 | Form1Layout = new QHBoxLayout( this, 5, 5, "Form1Layout"); |
102 | Franz | 220 | edList.clear(); |
221 | stList.clear(); |
||
112 | Franz | 222 | style.append( tr("Left")); |
223 | style.append( tr("Center")); |
||
224 | style.append( tr("Right")); |
||
225 | style.append( tr("Block")); |
||
226 | style.append( tr("Forced")); |
||
102 | Franz | 227 | if (doc->Vorlagen.count() > 5) |
228 | { |
||
229 | for (uint a = 5; a < doc->Vorlagen.count(); ++a) |
||
230 | { |
||
231 | style.append(doc->Vorlagen[a].Vname); |
||
232 | } |
||
233 | } |
||
234 | CurrItem = ite; |
||
103 | Franz | 235 | |
236 | fmenu = new QPopupMenu(); |
||
237 | fmenu->insertItem(loadIcon("DateiNeu16.png"), tr("New"), this, SLOT(Do_new()), CTRL+Key_N); |
||
112 | Franz | 238 | /* fmenu->insertItem( tr("Save as..."), this, SLOT(SaveAs())); |
103 | Franz | 239 | fmenu->insertItem(loadIcon("DateiOpen16.png"), tr("Load..."), this, SLOT(LoadScript())); |
240 | fmenu->insertSeparator(); */ |
||
112 | Franz | 241 | fmenu->insertItem( tr("Save and Exit"), this, SLOT(accept())); |
242 | fmenu->insertItem( tr("Exit without Saving"), this, SLOT(Do_leave())); |
||
103 | Franz | 243 | emenu = new QPopupMenu(); |
113 | Franz | 244 | Mundo = emenu->insertItem( tr("Undo"), this, SLOT(Do_undo()), CTRL+Key_Z); |
245 | Mredo = emenu->insertItem( tr("Redo"), this, SLOT(Do_redo())); |
||
103 | Franz | 246 | emenu->insertSeparator(); |
113 | Franz | 247 | Mcopy = emenu->insertItem(loadIcon("editcut.png"), tr("Cut"), this, SLOT(Do_cut()), CTRL+Key_X); |
248 | Mcut = emenu->insertItem(loadIcon("editcopy.png"), tr("Copy"), this, SLOT(Do_copy()), CTRL+Key_C); |
||
249 | Mpaste = emenu->insertItem(loadIcon("editpaste.png"), tr("Paste"), this, SLOT(Do_paste()), CTRL+Key_V); |
||
250 | Mdel = emenu->insertItem(loadIcon("editdelete.png"), tr("Clear"), this, SLOT(Do_del()), CTRL+Key_V); |
||
103 | Franz | 251 | emenu->insertSeparator(); |
112 | Franz | 252 | emenu->insertItem( tr("Edit Styles..."), this , SLOT(slotEditStyles())); |
113 | Franz | 253 | Mupdt = emenu->insertItem( tr("Update Textframe"), this, SLOT(updateTextFrame())); |
103 | Franz | 254 | menuBar = new QMenuBar(this); |
112 | Franz | 255 | menuBar->insertItem( tr("File"), fmenu); |
256 | menuBar->insertItem( tr("Edit"), emenu); |
||
103 | Franz | 257 | Form1Layout->setMenuBar( menuBar ); |
102 | Franz | 258 | table1 = new STable( this ); |
259 | table1->setNumCols( 2 ); |
||
260 | table1->horizontalHeader()->setLabel( 0, tr( "Style" ) ); |
||
261 | table1->horizontalHeader()->setLabel( 1, tr( "Text" ) ); |
||
262 | table1->setSelectionMode( QTable::Single ); |
||
263 | table1->setColumnStretchable(0, false); |
||
264 | table1->setColumnStretchable(1, true); |
||
265 | Form1Layout->addWidget( table1 ); |
||
266 | resize( QSize(509, 326).expandedTo(minimumSizeHint()) ); |
||
267 | show(); |
||
105 | Franz | 268 | QPtrList<Pti> y; |
269 | PageItem *nb = ite; |
||
270 | while (nb != 0) |
||
271 | { |
||
272 | if (nb->BackBox != 0) |
||
273 | nb = nb->BackBox; |
||
274 | else |
||
275 | break; |
||
276 | } |
||
277 | while (nb != 0) |
||
278 | { |
||
279 | y = nb->Ptext; |
||
280 | for (a = 0; a < y.count(); ++a) |
||
281 | { |
||
282 | QString b = y.at(a)->ch; |
||
283 | pstyle = y.at(a)->cab; |
||
284 | if (b == QChar(13)) |
||
285 | { |
||
286 | addPar(para, Dat, pstyle); |
||
287 | Dat = ""; |
||
288 | para++; |
||
289 | } |
||
290 | else |
||
291 | Dat += b; |
||
292 | } |
||
293 | nb = nb->NextBox; |
||
294 | } |
||
106 | Franz | 295 | if (Dat != "") |
296 | addPar(para, Dat, pstyle); |
||
103 | Franz | 297 | if (table1->numRows() == 0) |
298 | addPar(0, "", doc->CurrentABStil); |
||
102 | Franz | 299 | TextChanged = false; |
106 | Franz | 300 | table1->setCurrentCell(0, 1); |
301 | table1->ensureVisible(0, 1); |
||
103 | Franz | 302 | SEditor *cp = (SEditor*)table1->cellWidget(0, 1); |
303 | cp->setFocus(); |
||
304 | cp->setCursorPosition(0, 0); |
||
113 | Franz | 305 | for (uint a = 0; a < edList.count(); ++a) |
306 | { |
||
307 | SEditor *tt = edList.at(a); |
||
308 | tt->setUndoRedoEnabled(false); |
||
309 | tt->setUndoRedoEnabled(true); |
||
310 | } |
||
311 | emenu->setItemEnabled(Mundo, 0); |
||
312 | emenu->setItemEnabled(Mredo, 0); |
||
313 | emenu->setItemEnabled(Mcopy, 0); |
||
314 | emenu->setItemEnabled(Mcut, 0); |
||
315 | emenu->setItemEnabled(Mdel, 0); |
||
316 | emenu->setItemEnabled(Mupdt, 0); |
||
102 | Franz | 317 | } |
318 | |||
103 | Franz | 319 | void StoryEditor::closeEvent(QCloseEvent *) |
320 | { |
||
321 | Do_leave(); |
||
322 | } |
||
323 | |||
324 | void StoryEditor::Do_leave() |
||
325 | { |
||
326 | if (TextChanged) |
||
327 | { |
||
328 | int t = QMessageBox::warning(this, tr("Warning"), |
||
118 | Franz | 329 | tr("Do you really want to lose all your Changes?"), |
103 | Franz | 330 | QMessageBox::No, QMessageBox::Yes, QMessageBox::NoButton); |
331 | if (t == QMessageBox::No) |
||
332 | return; |
||
333 | } |
||
334 | reject(); |
||
335 | } |
||
336 | |||
337 | void StoryEditor::Do_new() |
||
338 | { |
||
339 | int t = QMessageBox::warning(this, tr("Warning"), |
||
340 | tr("Do you really want to clear all your Text?"), |
||
341 | QMessageBox::No, QMessageBox::Yes, QMessageBox::NoButton); |
||
342 | if (t == QMessageBox::No) |
||
343 | return; |
||
344 | table1->setNumCols( 2 ); |
||
345 | table1->setNumRows( 0 ); |
||
346 | stList.clear(); |
||
347 | edList.clear(); |
||
348 | addPar(0, "", doc->CurrentABStil); |
||
349 | SEditor *cp = (SEditor*)table1->cellWidget(0, 1); |
||
113 | Franz | 350 | cp->setUndoRedoEnabled(false); |
351 | cp->setUndoRedoEnabled(true); |
||
103 | Franz | 352 | cp->setFocus(); |
353 | cp->setCursorPosition(0, 0); |
||
113 | Franz | 354 | emenu->setItemEnabled(Mundo, 0); |
355 | emenu->setItemEnabled(Mredo, 0); |
||
356 | emenu->setItemEnabled(Mcopy, 0); |
||
357 | emenu->setItemEnabled(Mcut, 0); |
||
358 | emenu->setItemEnabled(Mdel, 0); |
||
103 | Franz | 359 | } |
360 | |||
361 | void StoryEditor::Do_undo() |
||
362 | { |
||
363 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
364 | cp->undo(); |
||
365 | table1->adjHeight(table1->currentRow()); |
||
366 | } |
||
367 | |||
368 | void StoryEditor::Do_redo() |
||
369 | { |
||
370 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
371 | cp->redo(); |
||
372 | table1->adjHeight(table1->currentRow()); |
||
373 | } |
||
374 | |||
375 | void StoryEditor::Do_copy() |
||
376 | { |
||
377 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
378 | cp->copy(); |
||
379 | table1->adjHeight(table1->currentRow()); |
||
380 | } |
||
381 | |||
382 | void StoryEditor::Do_paste() |
||
383 | { |
||
384 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
385 | cp->paste(); |
||
386 | table1->adjHeight(table1->currentRow()); |
||
387 | } |
||
388 | |||
389 | void StoryEditor::Do_cut() |
||
390 | { |
||
391 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
392 | cp->cut(); |
||
393 | table1->adjHeight(table1->currentRow()); |
||
394 | } |
||
395 | |||
396 | void StoryEditor::Do_del() |
||
397 | { |
||
398 | SEditor *cp = (SEditor*)table1->cellWidget(table1->currentRow(), 1); |
||
399 | cp->del(); |
||
400 | table1->adjHeight(table1->currentRow()); |
||
401 | } |
||
402 | |||
113 | Franz | 403 | void StoryEditor::UnReMenu(bool u, bool r) |
404 | { |
||
405 | emenu->setItemEnabled(Mundo, u); |
||
406 | emenu->setItemEnabled(Mredo, r); |
||
407 | } |
||
408 | |||
409 | void StoryEditor::CopyAvail(bool u) |
||
410 | { |
||
411 | emenu->setItemEnabled(Mcopy, u); |
||
412 | emenu->setItemEnabled(Mcut, u); |
||
413 | emenu->setItemEnabled(Mdel, u); |
||
414 | } |
||
415 | |||
102 | Franz | 416 | void StoryEditor::updateTextFrame() |
417 | { |
||
418 | bool first = false; |
||
107 | Franz | 419 | PageItem *nb = CurrItem; |
420 | while (nb != 0) |
||
421 | { |
||
422 | if (nb->BackBox != 0) |
||
423 | nb = nb->BackBox; |
||
424 | else |
||
425 | break; |
||
426 | } |
||
102 | Franz | 427 | for (uint a = 0; a < edList.count(); ++a) |
428 | { |
||
429 | Serializer *ss = new Serializer(""); |
||
103 | Franz | 430 | SEditor *tt = edList.at(a); |
102 | Franz | 431 | QComboBox *cp = stList.at(a); |
432 | ss->Objekt = tt->text(); |
||
433 | if (a < edList.count()-1) |
||
434 | ss->Objekt += QChar(10); |
||
435 | int st = cp->currentItem(); |
||
107 | Franz | 436 | ss->GetText(nb, st, doc->Vorlagen[st].Font, doc->Vorlagen[st].FontSize, first); |
102 | Franz | 437 | delete ss; |
438 | first = true; |
||
439 | } |
||
105 | Franz | 440 | while (nb != 0) |
441 | { |
||
442 | if (doc->Trenner->AutoCheck) |
||
443 | { |
||
444 | if (doc->Trenner->Language != nb->Language) |
||
445 | doc->Trenner->slotNewDict(nb->Language); |
||
446 | doc->Trenner->slotHyphenate(nb); |
||
447 | } |
||
448 | else |
||
107 | Franz | 449 | nb->OwnPage->RefreshItem(nb); |
105 | Franz | 450 | nb = nb->NextBox; |
451 | } |
||
102 | Franz | 452 | TextChanged = false; |
113 | Franz | 453 | emenu->setItemEnabled(Mupdt, 0); |
107 | Franz | 454 | emit DocChanged(); |
102 | Franz | 455 | } |
456 | |||
112 | Franz | 457 | void StoryEditor::slotEditStyles() |
458 | { |
||
459 | int sty; |
||
460 | QComboBox *ct; |
||
461 | emit EditSt(); |
||
462 | style.clear(); |
||
463 | style.append( tr("Left")); |
||
464 | style.append( tr("Center")); |
||
465 | style.append( tr("Right")); |
||
466 | style.append( tr("Block")); |
||
467 | style.append( tr("Forced")); |
||
468 | if (doc->Vorlagen.count() > 5) |
||
469 | { |
||
470 | for (uint a = 5; a < doc->Vorlagen.count(); ++a) |
||
471 | { |
||
472 | style.append(doc->Vorlagen[a].Vname); |
||
473 | } |
||
474 | } |
||
475 | for (uint b = 0; b < stList.count(); ++b) |
||
476 | { |
||
477 | ct = stList.at(b); |
||
478 | sty = ct->currentItem(); |
||
479 | if (sty > static_cast<int>(doc->Vorlagen.count()-1)) |
||
480 | sty = 0; |
||
481 | disconnect(ct, SIGNAL(activated(int)), this, SLOT(styleChange(int))); |
||
482 | ct->clear(); |
||
483 | ct->insertStringList(style); |
||
484 | connect(ct, SIGNAL(highlighted(int)), this, SLOT(styleChange(int))); |
||
485 | ct->setCurrentItem(sty); |
||
486 | disconnect(ct, SIGNAL(highlighted(int)), this, SLOT(styleChange(int))); |
||
487 | connect(ct, SIGNAL(activated(int)), this, SLOT(styleChange(int))); |
||
488 | } |
||
489 | } |
||
490 | |||
102 | Franz | 491 | void StoryEditor::styleChange(int st) |
492 | { |
||
493 | int r = stList.findRef((QComboBox*)sender()); |
||
494 | int align; |
||
495 | if (st > 4) |
||
496 | align = doc->Vorlagen[st].Ausri; |
||
497 | else |
||
498 | align = st; |
||
499 | if (r != -1) |
||
500 | { |
||
103 | Franz | 501 | SEditor *tt = (SEditor*)table1->cellWidget(r, 1); |
102 | Franz | 502 | switch (align) |
503 | { |
||
504 | case 0: |
||
505 | tt->setAlignment(Qt::AlignLeft); |
||
506 | break; |
||
507 | case 1: |
||
508 | tt->setAlignment(Qt::AlignCenter); |
||
509 | break; |
||
510 | case 2: |
||
511 | tt->setAlignment(Qt::AlignRight); |
||
512 | break; |
||
513 | case 3: |
||
514 | case 4: |
||
515 | tt->setAlignment(Qt::AlignJustify); |
||
516 | break; |
||
517 | default: |
||
518 | break; |
||
519 | } |
||
113 | Franz | 520 | modifiedText(); |
102 | Franz | 521 | } |
522 | } |
||
523 | |||
524 | int StoryEditor::getStyle(int where) |
||
525 | { |
||
526 | QComboBox *cp = stList.at(where); |
||
527 | return cp->currentItem(); |
||
528 | } |
||
529 | |||
530 | void StoryEditor::addPar(int where, QString text, int sty) |
||
531 | { |
||
532 | table1->insertRows(where); |
||
533 | QComboBox *ct = new QComboBox( this ); |
||
534 | ct->insertStringList(style); |
||
535 | ct->setMaximumSize(200, 24); |
||
536 | ct->setEditable(false); |
||
537 | table1->setCellWidget(where, 0, ct); |
||
538 | SEditor *cp = new SEditor(this); |
||
539 | stList.insert(where, ct); |
||
540 | edList.insert(where, cp); |
||
541 | table1->setCellWidget(where, 1, cp); |
||
542 | table1->setCurrentCell(where, 1); |
||
543 | cp->setText(text); |
||
544 | table1->adjHeight(where); |
||
545 | connect(ct, SIGNAL(highlighted(int)), this, SLOT(styleChange(int))); |
||
546 | ct->setCurrentItem(sty); |
||
547 | disconnect(ct, SIGNAL(highlighted(int)), this, SLOT(styleChange(int))); |
||
548 | cp->setFocus(); |
||
549 | cp->setCursorPosition(0, 0); |
||
113 | Franz | 550 | connect(cp, SIGNAL(copyAvailable(bool)), this, SLOT(CopyAvail(bool))); |
551 | connect(cp, SIGNAL(UnRe(bool, bool)), this, SLOT(UnReMenu(bool, bool))); |
||
102 | Franz | 552 | connect(cp, SIGNAL(wrapped()), this, SLOT(WrapHandler())); |
553 | connect(cp, SIGNAL(delPressed()), this, SLOT(KeyDel())); |
||
554 | connect(cp, SIGNAL(bsPressed()), this, SLOT(KeyBS())); |
||
555 | connect(cp, SIGNAL(returnPressed()), this, SLOT(KeyRet())); |
||
556 | connect(cp, SIGNAL(clicked(int, int)), this, SLOT(clickAt(int, int))); |
||
557 | connect(cp, SIGNAL(textChanged()), this, SLOT(modifiedText())); |
||
558 | connect(ct, SIGNAL(activated(int)), this, SLOT(styleChange(int))); |
||
559 | } |
||
560 | |||
561 | void StoryEditor::modifiedText() |
||
562 | { |
||
563 | TextChanged = true; |
||
112 | Franz | 564 | table1->HomeK = 0; |
565 | table1->EndK = 0; |
||
113 | Franz | 566 | emenu->setItemEnabled(Mupdt, 1); |
102 | Franz | 567 | } |
568 | |||
569 | void StoryEditor::WrapHandler() |
||
570 | { |
||
103 | Franz | 571 | int r = edList.findRef((SEditor*)sender()); |
102 | Franz | 572 | if (r != -1) |
573 | table1->adjHeight(r); |
||
574 | } |
||
575 | |||
576 | void StoryEditor::clickAt( int row, int col) |
||
577 | { |
||
103 | Franz | 578 | int r = edList.findRef((SEditor*)sender()); |
102 | Franz | 579 | if (r != -1) |
580 | { |
||
581 | table1->setCurrentCell(r, 1); |
||
582 | table1->cellWidget(r, 1)->setFocus(); |
||
583 | table1->updateHeaderStates(); |
||
584 | } |
||
585 | } |
||
586 | |||
587 | void StoryEditor::KeyDel() |
||
588 | { |
||
589 | QString tmp, tmp2; |
||
590 | int r = table1->currentRow(); |
||
103 | Franz | 591 | SEditor *tt = (SEditor*)sender(); |
102 | Franz | 592 | tmp = tt->text(); |
593 | if (r < table1->numRows()-1) |
||
594 | { |
||
595 | int al = tt->alignment(); |
||
103 | Franz | 596 | SEditor *bt = edList.at(r+1); |
102 | Franz | 597 | tmp2 = bt->text(); |
598 | tt->setText(tmp + tmp2); |
||
599 | tt->setAlignment(al); |
||
600 | edList.remove(r+1); |
||
601 | stList.remove(r+1); |
||
602 | table1->removeRow(r+1); |
||
603 | table1->setCurrentCell(r, 1); |
||
604 | table1->adjHeight(r); |
||
605 | tt->setFocus(); |
||
606 | tt->setCursorPosition(0, tmp.length()); |
||
607 | } |
||
608 | } |
||
609 | |||
610 | void StoryEditor::KeyBS() |
||
611 | { |
||
612 | QString tmp, tmp2; |
||
613 | int r = table1->currentRow(); |
||
103 | Franz | 614 | SEditor *tt = (SEditor*)sender(); |
102 | Franz | 615 | tmp = tt->text(); |
616 | if (r > 0) |
||
617 | { |
||
103 | Franz | 618 | SEditor *bt = edList.at(r-1); |
102 | Franz | 619 | int al = bt->alignment(); |
620 | tmp2 = bt->text(); |
||
621 | bt->setText(tmp2 + tmp); |
||
622 | bt->setAlignment(al); |
||
623 | edList.remove(r); |
||
624 | stList.remove(r); |
||
625 | table1->removeRow(r); |
||
626 | table1->setCurrentCell(r-1, 1); |
||
627 | table1->adjHeight(r-1); |
||
628 | bt->setFocus(); |
||
629 | bt->setCursorPosition(0, tmp2.length()); |
||
630 | } |
||
631 | } |
||
632 | |||
633 | void StoryEditor::KeyRet() |
||
634 | { |
||
635 | QString tmp, tmp2; |
||
636 | QString tmp3 = ""; |
||
103 | Franz | 637 | SEditor *tt = (SEditor*)sender(); |
102 | Franz | 638 | tmp = tt->text(); |
639 | int al = tt->alignment(); |
||
640 | int st = getStyle(table1->currentRow()); |
||
641 | int rPos = tmp.find("\n"); |
||
107 | Franz | 642 | if (CurrItem->PType == 8) |
643 | { |
||
644 | tmp.remove("\n"); |
||
645 | tt->setText(tmp); |
||
646 | tt->setAlignment(al); |
||
647 | return; |
||
648 | } |
||
102 | Franz | 649 | if (rPos < static_cast<int>(tmp.length())) |
650 | { |
||
651 | tmp2 = tmp.left(rPos); |
||
652 | tmp3 = tmp.mid(rPos+1); |
||
653 | tt->setText(tmp2); |
||
654 | } |
||
655 | else |
||
656 | { |
||
657 | tmp.remove("\n"); |
||
658 | tt->setText(tmp); |
||
659 | } |
||
660 | tt->setAlignment(al); |
||
661 | table1->adjHeight(table1->currentRow()); |
||
662 | addPar(table1->currentRow()+1, tmp3, st); |
||
663 | } |
||
664 |