Changeset View
Changeset View
Standalone View
Standalone View
plugins/textshape/dialogs/SimpleTableOfContentsWidget.cpp
Show All 26 Lines | |||||
27 | #include <KoTableOfContentsGeneratorInfo.h> | 27 | #include <KoTableOfContentsGeneratorInfo.h> | ||
28 | #include <KoIcon.h> | 28 | #include <KoIcon.h> | ||
29 | 29 | | |||
30 | #include <QAction> | 30 | #include <QAction> | ||
31 | #include <QDebug> | 31 | #include <QDebug> | ||
32 | 32 | | |||
33 | #include <QWidget> | 33 | #include <QWidget> | ||
34 | #include <QMenu> | 34 | #include <QMenu> | ||
35 | #include <QSignalMapper> | | |||
36 | 35 | | |||
37 | SimpleTableOfContentsWidget::SimpleTableOfContentsWidget(ReferencesTool *tool, QWidget *parent) | 36 | SimpleTableOfContentsWidget::SimpleTableOfContentsWidget(ReferencesTool *tool, QWidget *parent) | ||
38 | : QWidget(parent), | 37 | : QWidget(parent), | ||
39 | m_blockSignals(false), | 38 | m_blockSignals(false), | ||
40 | m_referenceTool(tool), | 39 | m_referenceTool(tool) | ||
41 | m_signalMapper(0) | | |||
42 | { | 40 | { | ||
43 | widget.setupUi(this); | 41 | widget.setupUi(this); | ||
44 | Q_ASSERT(tool); | 42 | Q_ASSERT(tool); | ||
45 | 43 | | |||
46 | m_templateGenerator = new TableOfContentsTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | 44 | m_templateGenerator = new TableOfContentsTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | ||
47 | 45 | | |||
48 | widget.addToC->setIcon(koIcon("insert-table-of-contents")); | 46 | widget.addToC->setIcon(koIcon("insert-table-of-contents")); | ||
49 | connect(widget.addToC, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus())); | 47 | connect(widget.addToC, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus())); | ||
Show All 9 Lines | |||||
59 | void SimpleTableOfContentsWidget::setStyleManager(KoStyleManager *sm) | 57 | void SimpleTableOfContentsWidget::setStyleManager(KoStyleManager *sm) | ||
60 | { | 58 | { | ||
61 | m_styleManager = sm; | 59 | m_styleManager = sm; | ||
62 | } | 60 | } | ||
63 | 61 | | |||
64 | void SimpleTableOfContentsWidget::prepareTemplateMenu() | 62 | void SimpleTableOfContentsWidget::prepareTemplateMenu() | ||
65 | { | 63 | { | ||
66 | m_previewGenerator.clear(); | 64 | m_previewGenerator.clear(); | ||
67 | if (m_signalMapper) { | | |||
68 | delete m_signalMapper; | | |||
69 | m_signalMapper = 0; | | |||
70 | } | | |||
71 | qDeleteAll(m_templateList.begin(), m_templateList.end()); | 65 | qDeleteAll(m_templateList.begin(), m_templateList.end()); | ||
72 | m_templateList.clear(); | 66 | m_templateList.clear(); | ||
73 | 67 | | |||
74 | m_signalMapper = new QSignalMapper(); | | |||
75 | | ||||
76 | m_templateList = m_templateGenerator->templates(); | 68 | m_templateList = m_templateGenerator->templates(); | ||
77 | 69 | | |||
78 | connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int))); | | |||
79 | | ||||
80 | m_chooser = widget.addToC->addItemChooser(1); | 70 | m_chooser = widget.addToC->addItemChooser(1); | ||
81 | 71 | | |||
82 | int index = 0; | 72 | int index = 0; | ||
83 | foreach (KoTableOfContentsGeneratorInfo *info, m_templateList) { | 73 | foreach (KoTableOfContentsGeneratorInfo *info, m_templateList) { | ||
84 | TableOfContentsPreview *preview = new TableOfContentsPreview(); | 74 | TableOfContentsPreview *preview = new TableOfContentsPreview(); | ||
85 | preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | 75 | preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | ||
86 | preview->setPreviewSize(QSize(200,120)); | 76 | preview->setPreviewSize(QSize(200,120)); | ||
87 | preview->updatePreview(info); | 77 | preview->updatePreview(info); | ||
88 | connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); | 78 | connect(preview, &TableOfContentsPreview::pixmapGenerated, this, [this, index] { pixmapReady(index); }); | ||
dfaure: same
Also, add `this` as third argument. | |||||
89 | m_signalMapper->setMapping(preview, index); | | |||
90 | m_previewGenerator.append(preview); | 79 | m_previewGenerator.append(preview); | ||
91 | ++index; | 80 | ++index; | ||
92 | 81 | | |||
93 | //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady() | 82 | //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady() | ||
94 | if (! widget.addToC->hasItemId(index)) { | 83 | if (! widget.addToC->hasItemId(index)) { | ||
95 | QPixmap pmm(QSize(200,120)); | 84 | QPixmap pmm(QSize(200,120)); | ||
96 | pmm.fill(Qt::white); | 85 | pmm.fill(Qt::white); | ||
97 | widget.addToC->addItem(m_chooser, pmm, index); | 86 | widget.addToC->addItem(m_chooser, pmm, index); | ||
98 | } | 87 | } | ||
99 | } | 88 | } | ||
100 | if (widget.addToC->isFirstTimeMenuShown()) { | 89 | if (widget.addToC->isFirstTimeMenuShown()) { | ||
101 | widget.addToC->addSeparator(); | 90 | widget.addToC->addSeparator(); | ||
102 | widget.addToC->addAction(m_referenceTool->action("insert_configure_tableofcontents")); | 91 | widget.addToC->addAction(m_referenceTool->action("insert_configure_tableofcontents")); | ||
103 | connect(m_referenceTool->action("insert_configure_tableofcontents"), SIGNAL(triggered()), this, SLOT(insertCustomToC()), Qt::UniqueConnection); | 92 | connect(m_referenceTool->action("insert_configure_tableofcontents"), SIGNAL(triggered()), this, SLOT(insertCustomToC()), Qt::UniqueConnection); | ||
104 | widget.addToC->addAction(m_referenceTool->action("format_tableofcontents")); | 93 | widget.addToC->addAction(m_referenceTool->action("format_tableofcontents")); | ||
105 | } | 94 | } | ||
106 | } | 95 | } | ||
107 | 96 | | |||
108 | void SimpleTableOfContentsWidget::pixmapReady(int templateId) | 97 | void SimpleTableOfContentsWidget::pixmapReady(int templateId) | ||
109 | { | 98 | { | ||
110 | // +1 to the templateId is because formattingButton does not allow id = 0 | 99 | // +1 to the templateId is because formattingButton does not allow id = 0 | ||
111 | widget.addToC->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); | 100 | widget.addToC->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); | ||
112 | disconnect(m_previewGenerator.at(templateId), SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); | 101 | disconnect(m_previewGenerator.at(templateId), &TableOfContentsPreview::pixmapGenerated, this, nullptr); | ||
113 | m_previewGenerator.at(templateId)->deleteLater(); | 102 | m_previewGenerator.at(templateId)->deleteLater(); | ||
114 | } | 103 | } | ||
115 | 104 | | |||
116 | void SimpleTableOfContentsWidget::applyTemplate(int templateId) | 105 | void SimpleTableOfContentsWidget::applyTemplate(int templateId) | ||
117 | { | 106 | { | ||
118 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(templateId - 1)); | 107 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(templateId - 1)); | ||
119 | m_referenceTool->editor()->insertTableOfContents(m_templateList.at(templateId - 1)); | 108 | m_referenceTool->editor()->insertTableOfContents(m_templateList.at(templateId - 1)); | ||
120 | } | 109 | } | ||
121 | 110 | | |||
122 | void SimpleTableOfContentsWidget::insertCustomToC() | 111 | void SimpleTableOfContentsWidget::insertCustomToC() | ||
123 | { | 112 | { | ||
124 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(0)); | 113 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(0)); | ||
125 | m_referenceTool->insertCustomToC(m_templateList.at(0)); | 114 | m_referenceTool->insertCustomToC(m_templateList.at(0)); | ||
126 | } | 115 | } |
same
Also, add this as third argument.