1 /* This file is part of the KDE project
2 * Copyright (C) 2007, 2008, 2010 Thomas Zander <zander@kde.org>
3 * Copyright (C) 2009-2010 C. Boemann <cbo@boemann.dk>
4 * Copyright (C) 2011 Mojtaba Shahi Senobari <mojtaba.shahi3000@gmail.com>
5 * Copyright (C) 2011-2012 Pierre Stirnweiss <pstirnweiss@googlemail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22 #include "SimpleParagraphWidget.h"
23 #include "TextTool.h"
24 #include <ListItemsHelper.h>
25 #include "FormattingButton.h"
26 #include <KoStyleThumbnailer.h>
27
28 #include "StylesCombo.h"
29 #include "StylesModel.h"
30 #include "DockerStylesComboModel.h"
31 #include "StylesDelegate.h"
32 #include "ListLevelWidget.h"
33 #include "commands/ChangeListLevelCommand.h"
34
35 #include <KoTextEditor.h>
36 #include <KoTextBlockData.h>
37 #include <KoParagraphStyle.h>
38 #include <KoInlineTextObjectManager.h>
39 #include <KoTextRangeManager.h>
40 #include <KoTextDocumentLayout.h>
41 #include <KoZoomHandler.h>
42 #include <KoStyleManager.h>
43 #include <KoListLevelProperties.h>
44 #include <KoShapePaintingContext.h>
45 #include <KoDialog.h>
46 #include <KoOdfLoadingContext.h>
47 #include <KoShapeLoadingContext.h>
48 #include <KoShapeSavingContext.h>
49 #include <KoXmlWriter.h>
50 #include <KoGenStyles.h>
51 #include <KoEmbeddedDocumentSaver.h>
52 #include <KoStore.h>
53 #include <KoOdfReadStore.h>
54 #include <KoXmlReader.h>
55
56 #include <ksharedconfig.h>
57 #include <kconfiggroup.h>
58
59 #include <QAction>
60 #include <QBuffer>
61 #include <QTextLayout>
62 #include <QFlags>
63 #include <QMenu>
64 #include <QWidgetAction>
65
66 #include <QDebug>
67
SimpleParagraphWidget(TextTool * tool,QWidget * parent)68 SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, QWidget *parent)
69 : QWidget(parent)
70 , m_styleManager(0)
71 , m_blockSignals(false)
72 , m_tool(tool)
73 , m_directionButtonState(Auto)
74 , m_thumbnailer(new KoStyleThumbnailer())
75 , m_stylesModel(new StylesModel(0, StylesModel::ParagraphStyle))
76 , m_sortedStylesModel(new DockerStylesComboModel())
77 , m_stylesDelegate(0)
78 {
79 widget.setupUi(this);
80 widget.alignCenter->setDefaultAction(tool->action("format_aligncenter"));
81 widget.alignBlock->setDefaultAction(tool->action("format_alignblock"));
82 // RTL layout will reverse the button order, but the align left/right then get mixed up.
83 // this makes sure that whatever happens the 'align left' is to the left of the 'align right'
84 if (QApplication::isRightToLeft()) {
85 widget.alignLeft->setDefaultAction(tool->action("format_alignright"));
86 widget.alignRight->setDefaultAction(tool->action("format_alignleft"));
87 } else {
88 widget.alignLeft->setDefaultAction(tool->action("format_alignleft"));
89 widget.alignRight->setDefaultAction(tool->action("format_alignright"));
90 }
91
92 widget.decreaseIndent->setDefaultAction(tool->action("format_decreaseindent"));
93 widget.increaseIndent->setDefaultAction(tool->action("format_increaseindent"));
94 widget.changeTextDirection->setDefaultAction(tool->action("change_text_direction"));
95
96 widget.moreOptions->setText("...");
97 widget.moreOptions->setToolTip(i18n("Change paragraph format"));
98 connect(widget.moreOptions, SIGNAL(clicked(bool)), tool->action("format_paragraph"), SLOT(trigger()));
99
100 connect(widget.changeTextDirection, SIGNAL(clicked()), this, SIGNAL(doneWithFocus()));
101 connect(widget.alignCenter, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
102 connect(widget.alignBlock, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
103 connect(widget.alignLeft, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
104 connect(widget.alignRight, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
105 connect(widget.decreaseIndent, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
106 connect(widget.increaseIndent, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
107
108 widget.bulletListButton->setDefaultAction(tool->action("format_list"));
109
110 fillListButtons();
111 widget.bulletListButton->addSeparator();
112
113 connect(widget.bulletListButton, SIGNAL(itemTriggered(int)), this, SLOT(listStyleChanged(int)));
114
115 m_stylesModel->setStyleThumbnailer(m_thumbnailer);
116 widget.paragraphStyleCombo->setStylesModel(m_sortedStylesModel);
117 connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex)), this, SLOT(styleSelected(QModelIndex)));
118 connect(widget.paragraphStyleCombo, SIGNAL(newStyleRequested(QString)), this, SIGNAL(newStyleRequested(QString)));
119 connect(widget.paragraphStyleCombo, SIGNAL(newStyleRequested(QString)), this, SIGNAL(doneWithFocus()));
120 connect(widget.paragraphStyleCombo, SIGNAL(showStyleManager(int)), this, SLOT(slotShowStyleManager(int)));
121
122
123 m_sortedStylesModel->setStylesModel(m_stylesModel);
124
125 }
126
~SimpleParagraphWidget()127 SimpleParagraphWidget::~SimpleParagraphWidget()
128 {
129 QBuffer dev;
130 KoXmlWriter writer(&dev);
131 KoGenStyles genStyles;
132 KoEmbeddedDocumentSaver mainStyles;
133 KoShapeSavingContext savingContext(writer, genStyles, mainStyles);
134
135 writer.startElement("templates:templates");
136 foreach (const KoListLevelProperties &llp, m_levelLibrary) {
137 llp.saveOdf(&writer, savingContext);
138 }
139 writer.endElement(); // list-level-properties
140
141 KSharedConfig::openConfig()->reparseConfiguration();
142 KConfigGroup appAuthorGroup( KSharedConfig::openConfig("calligrarc"), "");
143 appAuthorGroup.writeEntry("listLevelFormats", QString(dev.data()));
144
145 //the style model is set on the comboBox who takes over ownership
146 delete m_thumbnailer;
147 }
148
generateListLevelPixmap(const KoListLevelProperties & llp)149 QPixmap SimpleParagraphWidget::generateListLevelPixmap(const KoListLevelProperties &llp)
150 {
151 KoZoomHandler zoomHandler;
152 zoomHandler.setZoom(1.2);
153 zoomHandler.setDpi(72, 72);
154
155 KoInlineTextObjectManager itom;
156 KoTextRangeManager tlm;
157 TextShape textShape(&itom, &tlm);
158 textShape.setSize(QSizeF(300, 100));
159 QTextCursor cursor (textShape.textShapeData()->document());
160 textShape.textShapeData()->document()->setUndoRedoEnabled(false); // let's noth bother
161
162 QPixmap pm(48,48);
163
164 pm.fill(Qt::transparent);
165 QPainter p(&pm);
166 p.translate(0, -1.5);
167 p.setRenderHint(QPainter::Antialiasing);
168 if(llp.labelType() == KoListStyle::None) {
169 } else if (KoListStyle::isNumberingStyle(llp.labelType())) {
170 KoListStyle listStyle;
171
172 listStyle.setLevelProperties(llp);
173 cursor.select(QTextCursor::Document);
174 QTextCharFormat textCharFormat=cursor.blockCharFormat();
175 textCharFormat.setFontPointSize(11);
176 textCharFormat.setFontWeight(QFont::Normal);
177 cursor.setCharFormat(textCharFormat);
178
179 QTextBlock cursorBlock = cursor.block();
180 KoTextBlockData data(cursorBlock);
181 cursor.insertText("----");
182 listStyle.applyStyle(cursor.block(),1);
183 cursorBlock = cursor.block();
184 KoTextBlockData data1(cursorBlock);
185 cursor.insertText("\n----");
186 cursorBlock = cursor.block();
187 KoTextBlockData data2(cursorBlock);
188 cursor.insertText("\n----");
189 cursorBlock = cursor.block();
190 KoTextBlockData data3(cursorBlock);
191 } else {
192 KoListStyle listStyle;
193 listStyle.setLevelProperties(llp);
194 cursor.select(QTextCursor::Document);
195 QTextCharFormat textCharFormat=cursor.blockCharFormat();
196 textCharFormat.setFontPointSize(27);
197 textCharFormat.setFontWeight(QFont::Normal);
198 cursor.setBlockCharFormat(textCharFormat);
199
200 QTextBlock cursorBlock = cursor.block();
201 KoTextBlockData data(cursorBlock);
202 listStyle.applyStyle(cursor.block(),1);
203 }
204
205 KoTextDocumentLayout *lay = dynamic_cast<KoTextDocumentLayout*>(textShape.textShapeData()->document()->documentLayout());
206 if(lay)
207 lay->layout();
208
209 KoShapePaintingContext paintContext; //FIXME
210 textShape.paintComponent(p, zoomHandler, paintContext);
211
212 return pm;
213 }
214
fillListButtons()215 void SimpleParagraphWidget::fillListButtons()
216 {
217 KSharedConfig::openConfig()->reparseConfiguration();
218 KConfigGroup appAuthorGroup( KSharedConfig::openConfig("calligrarc"), "");
219 QString formats = appAuthorGroup.readEntry("listLevelFormats", QString());
220 formats.replace("\n", "");
221
222 if (false/*!formats.isEmpty()*/) {
223
224 KoXmlDocument document;
225 document.setContent(formats);
226 KoXmlElement styleElem;
227 forEachElement(styleElem, document.documentElement()) {
228 KoListLevelProperties llp;
229 // properties.loadOdf(scontext, styleElem);
230 m_levelLibrary.append(llp);
231 }
232 // KoOdfLoadingContext odfContext;
233 // KoShapeLoadingContext loadingContext(odfContext);
234 } else {
235 KoListStyle listStyle;
236 KoListLevelProperties llp = listStyle.levelProperties(1);
237 llp.setMargin(36.0);
238 llp.setMarginIncrease(18.0);
239 llp.setTextIndent(-18.0);
240 llp.setTabStopPosition(36.0);
241 llp.setLabelFollowedBy(KoListStyle::ListTab);
242 llp.setDisplayLevel(4);
243
244 llp.setLabelType(KoListStyle::BulletCharLabelType);
245 llp.setBulletCharacter(QChar(0x2022)); // Bullet
246 m_levelLibrary.append(llp);
247
248 llp.setLabelType(KoListStyle::BulletCharLabelType);
249 llp.setBulletCharacter(QChar(0x25A0)); // Square
250 m_levelLibrary.append(llp);
251
252 llp.setLabelType(KoListStyle::BulletCharLabelType);
253 llp.setBulletCharacter(QChar(0x25C6)); // Rhombus
254 m_levelLibrary.append(llp);
255
256 llp.setLabelType(KoListStyle::BulletCharLabelType);
257 llp.setBulletCharacter(QChar(0x25CB)); // Circle
258 m_levelLibrary.append(llp);
259
260 llp.setLabelType(KoListStyle::BulletCharLabelType);
261 llp.setBulletCharacter(QChar(0x2714)); // HeavyCheckMark
262 m_levelLibrary.append(llp);
263
264 llp.setLabelType(KoListStyle::BulletCharLabelType);
265 llp.setBulletCharacter(QChar(0x2794)); // Right Arrow
266 m_levelLibrary.append(llp);
267
268 llp.setLabelType(KoListStyle::NumberLabelType);
269 llp.setNumberFormat(KoOdfNumberDefinition::Numeric);
270 llp.setListItemSuffix(".");
271 m_levelLibrary.append(llp);
272
273 llp.setLabelType(KoListStyle::NumberLabelType);
274 llp.setNumberFormat(KoOdfNumberDefinition::Numeric);
275 llp.setListItemSuffix(")");
276 m_levelLibrary.append(llp);
277
278 llp.setLabelType(KoListStyle::NumberLabelType);
279 llp.setNumberFormat(KoOdfNumberDefinition::AlphabeticLowerCase);
280 llp.setListItemSuffix(".");
281 m_levelLibrary.append(llp);
282
283 llp.setLabelType(KoListStyle::NumberLabelType);
284 llp.setNumberFormat(KoOdfNumberDefinition::AlphabeticLowerCase);
285 llp.setListItemSuffix(")");
286 m_levelLibrary.append(llp);
287
288 llp.setLabelType(KoListStyle::NumberLabelType);
289 llp.setNumberFormat(KoOdfNumberDefinition::AlphabeticUpperCase);
290 llp.setListItemSuffix("");
291 m_levelLibrary.append(llp);
292
293 llp.setLabelType(KoListStyle::NumberLabelType);
294 llp.setNumberFormat(KoOdfNumberDefinition::RomanLowerCase);
295 llp.setListItemSuffix("");
296 m_levelLibrary.append(llp);
297
298 llp.setLabelType(KoListStyle::NumberLabelType);
299 llp.setNumberFormat(KoOdfNumberDefinition::RomanUpperCase);
300 llp.setListItemSuffix("");
301 m_levelLibrary.append(llp);
302 }
303
304 m_recentChooserAction = widget.bulletListButton->addItemChooser(5, i18n("Recently Used Level Formats"));
305 int id=1;
306 m_recentListFormats.append(m_levelLibrary.at(0));
307 widget.bulletListButton->addItem(m_recentChooserAction, generateListLevelPixmap( m_recentListFormats.at(0)), id);
308
309 m_libraryChooserAction = widget.bulletListButton->addItemChooser(5, i18n("Library of Level Formats"));
310 id=1000;
311 foreach(const KoListLevelProperties &llp, m_levelLibrary) {
312 widget.bulletListButton->addItem(m_libraryChooserAction, generateListLevelPixmap(llp), id);
313 QAction *a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Delete"));
314 a->setData(id);
315 connect(a, SIGNAL(triggered(bool)), this, SLOT(deleteLevelFormat()));
316 a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Edit..."));
317 a->setData(id);
318 connect(a, SIGNAL(triggered(bool)), this, SLOT(editLevelFormat()));
319 id++;
320 }
321
322 widget.bulletListButton->addSeparator();
323
324 QAction *action = new QAction(i18n("Define New Level Format..."),this);
325 action->setToolTip(i18n("Define new bullet or numbering format"));
326 widget.bulletListButton->addAction(action);
327 connect(action, SIGNAL(triggered(bool)), this, SLOT(defineLevelFormat()));
328 /* action = new QAction(i18n("Continue Previous List"),this);
329 action->setToolTip(i18n("Continue the list from a previous list"));
330 widget.bulletListButton->addAction(action);
331 action = new QAction(i18n("Set Numbering Value..."),this);
332 action->setToolTip(i18n("Set the numbering value"));
333 widget.bulletListButton->addAction(action);
334 */
335 }
336
defineLevelFormat()337 void SimpleParagraphWidget::defineLevelFormat()
338 {
339 ListLevelWidget *llw = new ListLevelWidget();
340 KoDialog dia(this);
341
342 dia.setModal(true);
343 dia.setButtons(KoDialog::Ok | KoDialog::Cancel);
344 dia.setMainWidget(llw);
345 dia.setWindowTitle(i18n("Define New List Level Format"));
346
347 KoListLevelProperties llp;
348 llp.setMargin(36.0);
349 llp.setMarginIncrease(18.0);
350 llp.setTextIndent(-18.0);
351 llp.setTabStopPosition(36.0);
352 llp.setLabelFollowedBy(KoListStyle::ListTab);
353 llw->setDisplay(llp);
354
355 if (dia.exec()) {
356 for(int i = 0; i < m_levelLibrary.size(); ++i) {
357 KoListLevelProperties llp = m_levelLibrary.at(i);
358 llp.setLevel(1);
359 widget.bulletListButton->addItem(m_libraryChooserAction, generateListLevelPixmap(m_levelLibrary.at(i)), i+1000);
360 }
361
362 int id = m_levelLibrary.size() + 1000;
363 llw->save(llp);
364
365 m_levelLibrary.append(llp);
366 llp.setLevel(1);
367 widget.bulletListButton->addItem(m_libraryChooserAction, generateListLevelPixmap(m_levelLibrary.at(id-1000)), id);
368 QAction *a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Delete"));
369 a->setData(id);
370 connect(a, SIGNAL(triggered(bool)), this, SLOT(deleteLevelFormat()));
371 a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Edit..."));
372 a->setData(id);
373 connect(a, SIGNAL(triggered(bool)), this, SLOT(editLevelFormat()));
374 }
375 }
376
setCurrentBlock(const QTextBlock & block)377 void SimpleParagraphWidget::setCurrentBlock(const QTextBlock &block)
378 {
379 if (block == m_currentBlock) {
380 return;
381 }
382
383 m_currentBlock = block;
384 m_blockSignals = true;
385 struct Finally {
386 Finally(SimpleParagraphWidget *p) {
387 parent = p;
388 }
389 ~Finally() {
390 parent->m_blockSignals = false;
391 }
392 SimpleParagraphWidget *parent;
393 };
394 Finally finally(this);
395
396 setCurrentFormat(m_currentBlock.blockFormat());
397 }
398
setCurrentFormat(const QTextBlockFormat & format)399 void SimpleParagraphWidget::setCurrentFormat(const QTextBlockFormat &format)
400 {
401 if (!m_styleManager || format == m_currentBlockFormat)
402 return;
403 m_currentBlockFormat = format;
404
405 int id = m_currentBlockFormat.intProperty(KoParagraphStyle::StyleId);
406 KoParagraphStyle *style(m_styleManager->paragraphStyle(id));
407 if (style) {
408 bool unchanged = true;
409
410 foreach(int property, m_currentBlockFormat.properties().keys()) {
411 switch (property) {
412 case QTextFormat::ObjectIndex:
413 case KoParagraphStyle::ListStyleId:
414 case KoParagraphStyle::OutlineLevel:
415 case KoParagraphStyle::ListStartValue:
416 case KoParagraphStyle::IsListHeader:
417 case KoParagraphStyle::UnnumberedListItem:
418 continue;
419 // These can be both content and style properties so let's ignore
420 case KoParagraphStyle::BreakBefore:
421 case KoParagraphStyle::MasterPageName:
422 continue;
423
424 default:
425 break;
426 }
427 if (property == QTextBlockFormat::BlockAlignment) { //the default alignment can be retrieved in the defaultTextOption. However, calligra sets the Qt::AlignAbsolute flag, so we need to or this flag with the default alignment before comparing.
428 if ((m_currentBlockFormat.property(property) != style->value(property))
429 && !(style->value(property).isNull()
430 && ((m_currentBlockFormat.intProperty(property)) == int(m_currentBlock.document()->defaultTextOption().alignment()| Qt::AlignAbsolute)))) {
431 unchanged = false;
432 break;
433 }
434 else {
435 continue;
436 }
437 }
438 if (property == KoParagraphStyle::TextProgressionDirection) {
439 if (style->value(property).isNull() && m_currentBlockFormat.intProperty(property) == KoText::LeftRightTopBottom) {
440 //LTR seems to be Qt default when unset
441 continue;
442 }
443 }
444 if ((m_currentBlockFormat.property(property) != style->value(property)) && !(style->value(property).isNull() && !m_currentBlockFormat.property(property).toBool())) {
445 //the last check seems to work. might be cause of a bug. The problem is when comparing an unset property in the style with a set to {0, false, ...) property in the format (eg. set then unset bold)
446 unchanged = false;
447 break;
448 }
449 }
450 //we are updating the combo's selected item to what is the current format. we do not want this to apply the style as it would mess up the undo stack, the change tracking,...
451 disconnect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex)), this, SLOT(styleSelected(QModelIndex)));
452 m_sortedStylesModel->styleApplied(style);
453 widget.paragraphStyleCombo->setCurrentIndex(m_sortedStylesModel->indexOf(style).row());
454 widget.paragraphStyleCombo->setStyleIsOriginal(unchanged);
455 m_stylesModel->setCurrentParagraphStyle(id);
456 widget.paragraphStyleCombo->slotUpdatePreview();
457 connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex)), this, SLOT(styleSelected(QModelIndex)));
458 }
459 }
460
setStyleManager(KoStyleManager * sm)461 void SimpleParagraphWidget::setStyleManager(KoStyleManager *sm)
462 {
463 Q_ASSERT(sm);
464 if (!sm || m_styleManager == sm) {
465 return;
466 }
467 if (m_styleManager) {
468 disconnect(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)), this, SLOT(slotParagraphStyleApplied(const KoParagraphStyle*)));
469 }
470 m_styleManager = sm;
471 //we want to disconnect this before setting the stylemanager. Populating the model apparently selects the first inserted item. We don't want this to actually set a new style.
472 disconnect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex)), this, SLOT(styleSelected(QModelIndex)));
473 m_stylesModel->setStyleManager(sm);
474 m_sortedStylesModel->setStyleManager(sm);
475 connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex)), this, SLOT(styleSelected(QModelIndex)));
476 connect(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)), this, SLOT(slotParagraphStyleApplied(const KoParagraphStyle*)));
477 }
478
setInitialUsedStyles(QVector<int> list)479 void SimpleParagraphWidget::setInitialUsedStyles(QVector<int> list)
480 {
481 m_sortedStylesModel->setInitialUsedStyles(list);
482 }
483
listStyleChanged(int id)484 void SimpleParagraphWidget::listStyleChanged(int id)
485 {
486 emit doneWithFocus();
487 if (m_blockSignals) return;
488 KoListLevelProperties llp;
489
490 if (id >= 1000) {
491 llp = m_levelLibrary.at(id-1000);
492 } else {
493 llp = m_recentListFormats.at(id-1);
494 m_recentListFormats.removeAt(id-1);
495 }
496
497 llp.setLevel(1);
498 m_recentListFormats.prepend(llp);
499 if (m_recentListFormats.size() > 5) {
500 m_recentListFormats.removeLast();
501 }
502 for(int i = 0; i < m_recentListFormats.size(); ++i) {
503 widget.bulletListButton->addItem(m_recentChooserAction, generateListLevelPixmap(m_recentListFormats.at(i)), i+1); // +1 as items are 1 based
504 }
505 KoTextEditor::ChangeListFlags flags(KoTextEditor::AutoListStyle | KoTextEditor::DontUnsetIfSame);
506 m_tool->textEditor()->setListProperties(llp, flags);
507 }
508
deleteLevelFormat()509 void SimpleParagraphWidget::deleteLevelFormat()
510 {
511 int id = qobject_cast<QAction *>(sender())->data().toInt();
512 m_levelLibrary.takeAt(id-1000);
513 widget.bulletListButton->removeLastItem(m_libraryChooserAction);
514
515 for(int i = 0; i < m_levelLibrary.size(); ++i) {
516 KoListLevelProperties llp = m_levelLibrary.at(i);
517 llp.setLevel(1);
518 if(llp.labelType() != KoListStyle::None) {
519 widget.bulletListButton->addItem(m_libraryChooserAction, generateListLevelPixmap(m_levelLibrary.at(i)), i+1000);
520 /* QAction *a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Delete"));
521 a->setData(id);
522 connect(a, SIGNAL(triggered(bool)), this, SLOT(deleteLevelFormat()));
523 a = widget.bulletListButton->addItemMenuItem(m_libraryChooserAction, id, i18n("Edit..."));
524 a->setData(id);
525 connect(a, SIGNAL(triggered(bool)), this, SLOT(editLevelFormat()));
526 */ }
527 }
528 }
529
editLevelFormat()530 void SimpleParagraphWidget::editLevelFormat()
531 {
532 int id = qobject_cast<QAction *>(sender())->data().toInt();
533
534 ListLevelWidget *llw = new ListLevelWidget();
535 KoDialog dia(this);
536
537 dia.setModal(true);
538 dia.setButtons(KoDialog::Ok | KoDialog::Cancel);
539 dia.setMainWidget(llw);
540 dia.setWindowTitle(i18n("Edit List Level Format"));
541
542 llw->setDisplay(m_levelLibrary.at(id-1000));
543
544 if (dia.exec()) {
545 llw->save(m_levelLibrary[id-1000]);
546 widget.bulletListButton->addItem(m_libraryChooserAction, generateListLevelPixmap(m_levelLibrary.at(id-1000)), id);
547 }
548 }
549
550
styleSelected(int index)551 void SimpleParagraphWidget::styleSelected(int index)
552 {
553 KoParagraphStyle *paragStyle = m_styleManager->paragraphStyle(m_sortedStylesModel->index(index, 0, QModelIndex()).internalId());
554 if (paragStyle) {
555 emit paragraphStyleSelected(paragStyle);
556 }
557 emit doneWithFocus();
558 }
559
styleSelected(const QModelIndex & index)560 void SimpleParagraphWidget::styleSelected(const QModelIndex &index)
561 {
562 if (!index.isValid()) {
563 return;
564 }
565 KoParagraphStyle *paragStyle = m_styleManager->paragraphStyle(index.internalId());
566 if (paragStyle) {
567 emit paragraphStyleSelected(paragStyle);
568 }
569 emit doneWithFocus();
570 }
571
slotShowStyleManager(int index)572 void SimpleParagraphWidget::slotShowStyleManager(int index)
573 {
574 int styleId = m_sortedStylesModel->index(index, 0, QModelIndex()).internalId();
575 emit showStyleManager(styleId);
576 emit doneWithFocus();
577 }
578
slotParagraphStyleApplied(const KoParagraphStyle * style)579 void SimpleParagraphWidget::slotParagraphStyleApplied(const KoParagraphStyle *style)
580 {
581 m_sortedStylesModel->styleApplied(style);
582 }
583