Rev 24880 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16856 | craig | 1 | /* |
2 | Copyright (C) 2011 Elvis Stansvik <elvstone@gmail.com> |
||
3 | |||
4 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
5 | to the COPYING file provided with the program. Following this notice may exist |
||
6 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
7 | for which a new license (GPL+exception) is in place. |
||
8 | */ |
||
9 | #include <QColor> |
||
10 | #include <QListWidget> |
||
11 | #include <QListWidgetItem> |
||
24779 | jghali | 12 | #include <QScopedValueRollback> |
16856 | craig | 13 | #include <QWidget> |
14 | |||
19495 | craig | 15 | #include "appmodehelper.h" |
19067 | craig | 16 | #include "appmodes.h" |
16856 | craig | 17 | #include "colorcombo.h" |
18 | #include "commonstrings.h" |
||
20185 | craig | 19 | #include "iconmanager.h" |
16856 | craig | 20 | #include "pageitem_table.h" |
19067 | craig | 21 | #include "propertiespalette_table.h" |
16856 | craig | 22 | #include "sccolorengine.h" |
23 | #include "scribus.h" |
||
23474 | jghali | 24 | #include "scribusapp.h" |
16856 | craig | 25 | #include "selection.h" |
26 | #include "tableborder.h" |
||
27 | #include "tablesideselector.h" |
||
24782 | jghali | 28 | #include "undomanager.h" |
29 | #include "undotransaction.h" |
||
16856 | craig | 30 | #include "util.h" |
31 | #include "util_color.h" |
||
32 | |||
33 | |||
20185 | craig | 34 | |
23609 | craig | 35 | PropertiesPalette_Table::PropertiesPalette_Table(QWidget* parent) : QWidget(parent) |
16856 | craig | 36 | { |
37 | setupUi(this); |
||
17383 | fschmid | 38 | setSizePolicy( QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); |
16856 | craig | 39 | |
23474 | jghali | 40 | iconSetChange(); |
17333 | fschmid | 41 | labelTable->setBuddy(tableStyleCombo); |
42 | labelCells->setBuddy(cellStyleCombo); |
||
23474 | jghali | 43 | |
44 | connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange())); |
||
45 | |||
24928 | jghali | 46 | connect(tableStyleCombo, SIGNAL(newStyle(QString)), this, SLOT(setTableStyle(QString))); |
47 | connect(cellStyleCombo, SIGNAL(newStyle(QString)), this, SLOT(setCellStyle(QString))); |
||
16856 | craig | 48 | } |
49 | |||
23474 | jghali | 50 | void PropertiesPalette_Table::iconSetChange() |
51 | { |
||
52 | IconManager& iconManager = IconManager::instance(); |
||
53 | |||
54 | addBorderLineButton->setIcon(iconManager.loadIcon("penciladd.png")); |
||
55 | removeBorderLineButton->setIcon(iconManager.loadIcon("pencilsub.png")); |
||
56 | buttonClearTableStyle->setIcon(iconManager.loadIcon("16/edit-clear.png")); |
||
57 | buttonClearCellStyle->setIcon(iconManager.loadIcon("16/edit-clear.png")); |
||
58 | } |
||
59 | |||
16856 | craig | 60 | void PropertiesPalette_Table::handleUpdateRequest(int updateFlags) |
61 | { |
||
62 | if (updateFlags & reqColorsUpdate) |
||
63 | updateColorList(); |
||
23620 | jghali | 64 | tableStyleCombo->updateStyleList(); |
65 | cellStyleCombo->updateStyleList(); |
||
16856 | craig | 66 | } |
67 | |||
68 | void PropertiesPalette_Table::updateColorList() |
||
69 | { |
||
70 | if (!m_doc) |
||
71 | return; |
||
72 | |||
21855 | jghali | 73 | borderLineColor->setColors(m_doc->PageColors, true); |
74 | fillColor->setColors(m_doc->PageColors, true); |
||
16856 | craig | 75 | } |
76 | |||
77 | void PropertiesPalette_Table::setMainWindow(ScribusMainWindow* mainWindow) |
||
78 | { |
||
79 | m_mainWindow = mainWindow; |
||
80 | |||
81 | connect(m_mainWindow, SIGNAL(UpdateRequest(int)), SLOT(handleUpdateRequest(int))); |
||
19495 | craig | 82 | connect(m_mainWindow->appModeHelper, SIGNAL(AppModeChanged(int,int)), this, SLOT(updateFillControls())); |
83 | connect(m_mainWindow->appModeHelper, SIGNAL(AppModeChanged(int,int)), this, SLOT(updateStyleControls())); |
||
16856 | craig | 84 | } |
85 | |||
86 | void PropertiesPalette_Table::setDocument(ScribusDoc *doc) |
||
87 | { |
||
18754 | jghali | 88 | if (m_doc) |
89 | { |
||
90 | disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged())); |
||
91 | disconnect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged())); |
||
92 | } |
||
93 | |||
16856 | craig | 94 | m_doc = doc; |
18754 | jghali | 95 | |
17333 | fschmid | 96 | tableStyleCombo->setDoc(m_doc); |
97 | cellStyleCombo->setDoc(m_doc); |
||
18754 | jghali | 98 | |
99 | connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged())); |
||
100 | connect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged())); |
||
16856 | craig | 101 | } |
102 | |||
103 | void PropertiesPalette_Table::unsetDocument() |
||
104 | { |
||
18754 | jghali | 105 | if (m_doc) |
106 | { |
||
107 | disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged())); |
||
108 | disconnect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged())); |
||
109 | } |
||
110 | |||
22601 | craig | 111 | m_doc = nullptr; |
18754 | jghali | 112 | |
17333 | fschmid | 113 | tableStyleCombo->setDoc(m_doc); |
114 | cellStyleCombo->setDoc(m_doc); |
||
16856 | craig | 115 | } |
116 | |||
117 | void PropertiesPalette_Table::setItem(PageItem* item) |
||
118 | { |
||
119 | m_item = item; |
||
17332 | fschmid | 120 | if (item->isTable()) |
21397 | jghali | 121 | connect(m_item->asTable(), SIGNAL(selectionChanged()), this, SLOT(handleCellSelectionChanged()), Qt::UniqueConnection); |
16856 | craig | 122 | } |
123 | |||
124 | void PropertiesPalette_Table::unsetItem() |
||
125 | { |
||
18753 | fschmid | 126 | disconnect(this, SLOT(handleCellSelectionChanged())); |
127 | |||
128 | // if ((m_item) && (m_item->isTable())) |
||
129 | // disconnect(m_item->asTable(), SIGNAL(selectionChanged()), this, SLOT(handleCellSelectionChanged())); |
||
22601 | craig | 130 | m_item = nullptr; |
16856 | craig | 131 | } |
132 | |||
133 | void PropertiesPalette_Table::handleSelectionChanged() |
||
134 | { |
||
135 | if (!m_doc) |
||
136 | return; |
||
137 | |||
138 | // We only handle a single item for now. |
||
139 | if (m_doc->m_Selection->count() >= 1 && m_doc->m_Selection->itemAt(0)->isTable()) |
||
140 | m_item = m_doc->m_Selection->itemAt(0); |
||
141 | else |
||
22601 | craig | 142 | m_item = nullptr; |
16856 | craig | 143 | |
24782 | jghali | 144 | sideSelector->setSelection(TableSide::All); |
16856 | craig | 145 | |
146 | updateFillControls(); |
||
17333 | fschmid | 147 | updateStyleControls(); |
16856 | craig | 148 | } |
149 | |||
17327 | fschmid | 150 | void PropertiesPalette_Table::handleCellSelectionChanged() |
151 | { |
||
152 | if (!m_doc) |
||
153 | return; |
||
154 | if (!m_item) |
||
155 | return; |
||
156 | updateFillControls(); |
||
17333 | fschmid | 157 | updateStyleControls(); |
21397 | jghali | 158 | on_sideSelector_selectionChanged(); |
17327 | fschmid | 159 | } |
160 | |||
18795 | jghali | 161 | void PropertiesPalette_Table::showTableStyle(const QString& name) |
17333 | fschmid | 162 | { |
163 | bool blocked = tableStyleCombo->blockSignals(true); |
||
23620 | jghali | 164 | tableStyleCombo->setStyle(name); |
17333 | fschmid | 165 | tableStyleCombo->blockSignals(blocked); |
166 | } |
||
167 | |||
18795 | jghali | 168 | void PropertiesPalette_Table::showCellStyle(const QString& name) |
17333 | fschmid | 169 | { |
170 | bool blocked = cellStyleCombo->blockSignals(true); |
||
23620 | jghali | 171 | cellStyleCombo->setStyle(name); |
17333 | fschmid | 172 | cellStyleCombo->blockSignals(blocked); |
173 | } |
||
174 | |||
175 | void PropertiesPalette_Table::updateStyleControls() |
||
176 | { |
||
177 | if (m_item && m_item->isTable()) |
||
178 | { |
||
179 | PageItem_Table* table = m_item->asTable(); |
||
180 | tableStyleCombo->setEnabled(true); |
||
181 | cellStyleCombo->setEnabled(true); |
||
182 | buttonClearTableStyle->setEnabled(true); |
||
183 | buttonClearCellStyle->setEnabled(true); |
||
184 | // Fill in values. |
||
185 | if (m_doc->appMode != modeEditTable) |
||
186 | { |
||
20635 | jghali | 187 | showTableStyle(table->styleName()); |
17333 | fschmid | 188 | cellStyleCombo->setEnabled(false); |
189 | buttonClearCellStyle->setEnabled(false); |
||
190 | } |
||
191 | else |
||
192 | { |
||
18795 | jghali | 193 | // showTableStyle(table->style()); |
20635 | jghali | 194 | showCellStyle(table->activeCell().styleName()); |
17333 | fschmid | 195 | } |
196 | } |
||
197 | else |
||
198 | { |
||
199 | tableStyleCombo->setEnabled(false); |
||
200 | cellStyleCombo->setEnabled(false); |
||
201 | buttonClearTableStyle->setEnabled(false); |
||
202 | buttonClearCellStyle->setEnabled(false); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | void PropertiesPalette_Table::setTableStyle(const QString &name) |
||
207 | { |
||
208 | if (!m_item || !m_item->isTable()) |
||
209 | return; |
||
210 | m_item->asTable()->setStyle(name); |
||
211 | m_item->asTable()->update(); |
||
18795 | jghali | 212 | showTableStyle(name); |
17333 | fschmid | 213 | } |
214 | |||
215 | void PropertiesPalette_Table::setCellStyle(const QString &name) |
||
216 | { |
||
217 | if (!m_item || !m_item->isTable()) |
||
218 | return; |
||
24779 | jghali | 219 | QScopedValueRollback<bool> dontResizeRb(m_doc->dontResize, true); |
220 | |||
24782 | jghali | 221 | m_doc->itemSelection_SetNamedCellStyle(name); |
24779 | jghali | 222 | |
17333 | fschmid | 223 | m_item->asTable()->update(); |
18795 | jghali | 224 | showCellStyle(name); |
17333 | fschmid | 225 | } |
226 | |||
16856 | craig | 227 | void PropertiesPalette_Table::on_sideSelector_selectionChanged() |
228 | { |
||
229 | if (!m_item || !m_item->isTable()) |
||
230 | return; |
||
231 | |||
232 | /* |
||
233 | * Figure out the selection state. Either |
||
234 | * |
||
235 | * 1) Some sides are selected and they all have the same border, or |
||
236 | * 2) Some sides are selected but they have different borders, or |
||
237 | * 3) No sides are selected. |
||
238 | */ |
||
239 | State borderState = Unset; |
||
240 | m_currentBorder = TableBorder(); |
||
24782 | jghali | 241 | TableSides selectedSides = sideSelector->selection(); |
16856 | craig | 242 | PageItem_Table* table = m_item->asTable(); |
21397 | jghali | 243 | bool tableEditMode = (m_doc->appMode == modeEditTable); |
16856 | craig | 244 | |
24782 | jghali | 245 | if (selectedSides & TableSide::Left) |
16856 | craig | 246 | { |
21397 | jghali | 247 | TableBorder leftBorder = tableEditMode ? table->activeCell().leftBorder() : table->leftBorder(); |
248 | if (borderState == Unset && !leftBorder.isNull()) |
||
16856 | craig | 249 | { |
21397 | jghali | 250 | m_currentBorder = leftBorder; |
16856 | craig | 251 | borderState = Set; |
252 | } |
||
21397 | jghali | 253 | else if (m_currentBorder != leftBorder) |
16856 | craig | 254 | borderState = TriState; |
255 | } |
||
256 | |||
24782 | jghali | 257 | if (selectedSides & TableSide::Right) |
16856 | craig | 258 | { |
21397 | jghali | 259 | TableBorder rightBorder = tableEditMode ? table->activeCell().rightBorder() : table->rightBorder(); |
260 | if (borderState == Unset && !rightBorder.isNull()) |
||
16856 | craig | 261 | { |
21397 | jghali | 262 | m_currentBorder = rightBorder; |
16856 | craig | 263 | borderState = Set; |
264 | } |
||
21397 | jghali | 265 | else if (m_currentBorder != rightBorder) |
16856 | craig | 266 | borderState = TriState; |
267 | } |
||
268 | |||
24782 | jghali | 269 | if (selectedSides & TableSide::Top) |
16856 | craig | 270 | { |
21397 | jghali | 271 | TableBorder topBorder = tableEditMode ? table->activeCell().topBorder() : table->topBorder(); |
16856 | craig | 272 | if (borderState == Unset && !table->topBorder().isNull()) |
273 | { |
||
21397 | jghali | 274 | m_currentBorder = topBorder; |
16856 | craig | 275 | borderState = Set; |
276 | } |
||
21397 | jghali | 277 | else if (m_currentBorder != topBorder) |
16856 | craig | 278 | borderState = TriState; |
279 | } |
||
280 | |||
24782 | jghali | 281 | if (selectedSides & TableSide::Bottom) |
16856 | craig | 282 | { |
21397 | jghali | 283 | TableBorder bottomBorder = tableEditMode ? table->activeCell().bottomBorder() : table->bottomBorder(); |
284 | if (borderState == Unset && !bottomBorder.isNull()) |
||
16856 | craig | 285 | { |
21397 | jghali | 286 | m_currentBorder = bottomBorder; |
16856 | craig | 287 | borderState = Set; |
288 | } |
||
21397 | jghali | 289 | else if (m_currentBorder != bottomBorder) |
16856 | craig | 290 | borderState = TriState; |
291 | } |
||
292 | |||
293 | if (borderState == Set) |
||
294 | { |
||
295 | /// Some sides selected and they have same border. |
||
296 | addBorderLineButton->setEnabled(true); |
||
297 | removeBorderLineButton->setEnabled(true); |
||
298 | borderLineList->setEnabled(true); |
||
299 | } |
||
300 | else if (borderState == TriState) |
||
301 | { |
||
302 | /// Some sides selected but they have different border. |
||
303 | m_currentBorder = TableBorder(); |
||
304 | addBorderLineButton->setEnabled(true); |
||
305 | removeBorderLineButton->setEnabled(true); |
||
306 | borderLineList->setEnabled(true); |
||
307 | } |
||
308 | else |
||
309 | { |
||
310 | /// No sides selected. |
||
311 | m_currentBorder = TableBorder(); |
||
312 | addBorderLineButton->setEnabled(false); |
||
313 | removeBorderLineButton->setEnabled(false); |
||
314 | borderLineList->setEnabled(false); |
||
315 | } |
||
316 | |||
317 | updateBorderLineList(); |
||
318 | } |
||
319 | |||
320 | void PropertiesPalette_Table::updateBorderLineList() |
||
321 | { |
||
322 | borderLineList->clear(); |
||
22508 | jghali | 323 | for (const TableBorderLine& borderLine : m_currentBorder.borderLines()) |
16856 | craig | 324 | { |
23210 | craig | 325 | QString text = QString(" %1%2 %3").arg(borderLine.width()).arg(borderLineWidth->suffix(), CommonStrings::translatePenStyleName(borderLine.style())); |
17417 | fschmid | 326 | if (borderLine.color() != CommonStrings::None) |
327 | { |
||
328 | QPixmap *icon = getWidePixmap(getColor(borderLine.color(), borderLine.shade())); |
||
329 | borderLineList->addItem(new QListWidgetItem(*icon, text, borderLineList)); |
||
330 | } |
||
331 | else |
||
332 | borderLineList->addItem(new QListWidgetItem(text, borderLineList)); |
||
16856 | craig | 333 | } |
17336 | fschmid | 334 | removeBorderLineButton->setEnabled(borderLineList->count() > 1); |
16856 | craig | 335 | } |
336 | |||
22195 | jghali | 337 | void PropertiesPalette_Table::updateBorderLineList(const TableBorderLine& current) |
338 | { |
||
339 | updateBorderLineList(); |
||
340 | |||
341 | const QList<TableBorderLine>& borderLines = m_currentBorder.borderLines(); |
||
342 | for (int i = 0; i < borderLines.count(); ++i) |
||
343 | { |
||
344 | const TableBorderLine& borderLine = borderLines.at(i); |
||
345 | if (borderLine == current) |
||
346 | { |
||
347 | borderLineList->setCurrentRow(i); |
||
348 | break; |
||
349 | } |
||
350 | } |
||
351 | } |
||
352 | |||
16856 | craig | 353 | void PropertiesPalette_Table::updateBorderLineListItem() |
354 | { |
||
355 | QListWidgetItem* item = borderLineList->currentItem(); |
||
24782 | jghali | 356 | if (!item) |
357 | return; |
||
358 | |||
23210 | craig | 359 | QString text = QString(" %1%2 %3").arg(borderLineWidth->getValue()).arg(borderLineWidth->suffix(), CommonStrings::translatePenStyleName(static_cast<Qt::PenStyle>(borderLineStyle->currentIndex() + 1))); |
17417 | fschmid | 360 | if (borderLineColor->currentColor() != CommonStrings::None) |
361 | { |
||
362 | QPixmap *icon = getWidePixmap(getColor(borderLineColor->currentColor(), borderLineShade->value())); |
||
363 | item->setIcon(*icon); |
||
364 | } |
||
16856 | craig | 365 | item->setText(text); |
366 | } |
||
367 | |||
368 | void PropertiesPalette_Table::updateFillControls() |
||
369 | { |
||
370 | if (m_item && m_item->isTable()) |
||
371 | { |
||
372 | PageItem_Table* table = m_item->asTable(); |
||
373 | // Enable fill editing controls. |
||
374 | fillColor->setEnabled(true); |
||
375 | fillColorLabel->setEnabled(true); |
||
376 | fillShade->setEnabled(true); |
||
377 | fillShadeLabel->setEnabled(true); |
||
378 | // Fill in values. |
||
17327 | fschmid | 379 | if (m_doc->appMode != modeEditTable) |
17318 | fschmid | 380 | { |
17327 | fschmid | 381 | QString color = table->fillColor(); |
382 | if (color == CommonStrings::None) |
||
383 | color = CommonStrings::tr_NoneColor; |
||
384 | setCurrentComboItem(fillColor, color); |
||
18480 | jghali | 385 | bool sigBlocked = fillShade->blockSignals(true); |
17318 | fschmid | 386 | fillShade->setValue(table->fillShade()); |
18480 | jghali | 387 | fillShade->blockSignals(sigBlocked); |
17318 | fschmid | 388 | } |
17327 | fschmid | 389 | else |
17318 | fschmid | 390 | { |
17327 | fschmid | 391 | TableCell cell = table->activeCell(); |
392 | QString color = cell.fillColor(); |
||
393 | if (color == CommonStrings::None) |
||
394 | color = CommonStrings::tr_NoneColor; |
||
395 | setCurrentComboItem(fillColor, color); |
||
18480 | jghali | 396 | bool sigBlocked = fillShade->blockSignals(true); |
17318 | fschmid | 397 | fillShade->setValue(cell.fillShade()); |
18480 | jghali | 398 | fillShade->blockSignals(sigBlocked); |
17318 | fschmid | 399 | } |
16856 | craig | 400 | } |
401 | else |
||
402 | { |
||
403 | // Disable fill editing controls. |
||
404 | fillColor->setEnabled(false); |
||
405 | fillColorLabel->setEnabled(false); |
||
406 | fillShade->setEnabled(false); |
||
407 | fillShadeLabel->setEnabled(false); |
||
408 | } |
||
409 | } |
||
410 | |||
411 | QColor PropertiesPalette_Table::getColor(const QString& colorName, int shade) const |
||
412 | { |
||
413 | if (!m_doc) |
||
414 | return QColor(); |
||
415 | |||
416 | return ScColorEngine::getDisplayColor(m_doc->PageColors[colorName], m_doc, shade); |
||
417 | } |
||
418 | |||
419 | void PropertiesPalette_Table::on_borderLineList_currentRowChanged(int row) |
||
420 | { |
||
421 | if (row == -1) |
||
422 | { |
||
423 | // No list item selected, so disable editing widgets. |
||
424 | borderLineWidth->setEnabled(false); |
||
425 | borderLineWidthLabel->setEnabled(false); |
||
426 | borderLineColor->setEnabled(false); |
||
427 | borderLineColorLabel->setEnabled(false); |
||
428 | borderLineStyle->setEnabled(false); |
||
429 | borderLineStyleLabel->setEnabled(false); |
||
430 | borderLineShade->setEnabled(false); |
||
431 | borderLineShadeLabel->setEnabled(false); |
||
432 | } |
||
433 | else |
||
434 | { |
||
435 | QList<TableBorderLine> borderLines = m_currentBorder.borderLines(); |
||
436 | Q_ASSERT(borderLineList->count() == borderLines.size()); |
||
22601 | craig | 437 | const TableBorderLine& line = borderLines.at(row); |
16856 | craig | 438 | |
439 | // Enable editing widgets. |
||
440 | borderLineWidth->setEnabled(true); |
||
441 | borderLineWidthLabel->setEnabled(true); |
||
442 | borderLineColor->setEnabled(true); |
||
443 | borderLineColorLabel->setEnabled(true); |
||
444 | borderLineStyle->setEnabled(true); |
||
445 | borderLineStyleLabel->setEnabled(true); |
||
446 | borderLineShade->setEnabled(true); |
||
447 | borderLineShadeLabel->setEnabled(true); |
||
448 | |||
449 | // Fill in values. |
||
450 | borderLineWidth->showValue(line.width()); |
||
451 | setCurrentComboItem(borderLineColor, line.color()); |
||
452 | borderLineStyle->setCurrentIndex(static_cast<int>(line.style()) - 1); |
||
17311 | fschmid | 453 | borderLineShade->setValue(line.shade()); |
16856 | craig | 454 | } |
455 | } |
||
456 | |||
457 | /// Handles adding of a new border line. |
||
458 | void PropertiesPalette_Table::on_addBorderLineButton_clicked() |
||
459 | { |
||
460 | if (!m_item || !m_item->isTable()) |
||
461 | return; |
||
462 | |||
463 | m_currentBorder.addBorderLine(TableBorderLine()); |
||
464 | updateBorderLineList(); |
||
465 | } |
||
466 | |||
467 | /// Handles removing of a border line. |
||
468 | void PropertiesPalette_Table::on_removeBorderLineButton_clicked() |
||
469 | { |
||
470 | int index = borderLineList->currentRow(); |
||
471 | borderLineList->removeItemWidget(borderLineList->currentItem()); |
||
472 | m_currentBorder.removeBorderLine(index); |
||
22195 | jghali | 473 | |
474 | updateBorders(); |
||
16856 | craig | 475 | updateBorderLineList(); |
476 | } |
||
477 | |||
478 | void PropertiesPalette_Table::on_borderLineWidth_valueChanged(double width) |
||
479 | { |
||
480 | int index = borderLineList->currentRow(); |
||
481 | TableBorderLine borderLine = m_currentBorder.borderLines().at(index); |
||
482 | borderLine.setWidth(width); |
||
483 | m_currentBorder.replaceBorderLine(index, borderLine); |
||
484 | |||
485 | updateBorders(); |
||
22195 | jghali | 486 | updateBorderLineList(borderLine); |
16856 | craig | 487 | } |
488 | |||
20635 | jghali | 489 | void PropertiesPalette_Table::on_borderLineShade_valueChanged(double shade) |
17311 | fschmid | 490 | { |
491 | int index = borderLineList->currentRow(); |
||
492 | TableBorderLine borderLine = m_currentBorder.borderLines().at(index); |
||
493 | borderLine.setShade(shade); |
||
494 | m_currentBorder.replaceBorderLine(index, borderLine); |
||
495 | |||
496 | updateBorders(); |
||
497 | updateBorderLineListItem(); |
||
498 | } |
||
499 | |||
24880 | jghali | 500 | void PropertiesPalette_Table::on_borderLineColor_textActivated(const QString& colorName) |
16856 | craig | 501 | { |
502 | int index = borderLineList->currentRow(); |
||
503 | TableBorderLine borderLine = m_currentBorder.borderLines().at(index); |
||
21397 | jghali | 504 | QString color = colorName; |
505 | if (colorName == CommonStrings::tr_NoneColor) |
||
506 | color = CommonStrings::None; |
||
507 | borderLine.setColor(color); |
||
16856 | craig | 508 | m_currentBorder.replaceBorderLine(index, borderLine); |
509 | |||
510 | updateBorders(); |
||
511 | updateBorderLineListItem(); |
||
512 | } |
||
513 | |||
514 | void PropertiesPalette_Table::on_borderLineStyle_activated(int style) |
||
515 | { |
||
516 | int index = borderLineList->currentRow(); |
||
517 | TableBorderLine borderLine = m_currentBorder.borderLines().at(index); |
||
518 | borderLine.setStyle(static_cast<Qt::PenStyle>(style + 1)); |
||
519 | m_currentBorder.replaceBorderLine(index, borderLine); |
||
520 | |||
521 | updateBorders(); |
||
522 | updateBorderLineListItem(); |
||
523 | } |
||
524 | |||
24880 | jghali | 525 | void PropertiesPalette_Table::on_fillColor_textActivated(const QString& colorName) |
16856 | craig | 526 | { |
527 | if (!m_item || !m_item->isTable()) |
||
528 | return; |
||
24782 | jghali | 529 | |
530 | UndoTransaction activeTransaction; |
||
531 | if (UndoManager::undoEnabled()) |
||
532 | activeTransaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap(), Um::CellFillColor, QString(), Um::ITable); |
||
533 | |||
17327 | fschmid | 534 | QString color = colorName; |
535 | if (colorName == CommonStrings::tr_NoneColor) |
||
536 | color = CommonStrings::None; |
||
24782 | jghali | 537 | |
16856 | craig | 538 | PageItem_Table* table = m_item->asTable(); |
17327 | fschmid | 539 | if (m_doc->appMode != modeEditTable) |
540 | table->setFillColor(color); |
||
541 | else |
||
24782 | jghali | 542 | table->setCellFillColor(color); |
17318 | fschmid | 543 | |
24782 | jghali | 544 | if (activeTransaction) |
545 | activeTransaction.commit(); |
||
546 | |||
17311 | fschmid | 547 | table->update(); |
548 | } |
||
16856 | craig | 549 | |
20635 | jghali | 550 | void PropertiesPalette_Table::on_fillShade_valueChanged(double shade) |
17311 | fschmid | 551 | { |
552 | if (!m_item || !m_item->isTable()) |
||
553 | return; |
||
554 | |||
24782 | jghali | 555 | UndoTransaction activeTransaction; |
556 | if (UndoManager::undoEnabled()) |
||
557 | activeTransaction = UndoManager::instance()->beginTransaction(m_item->getUName(), m_item->getUPixmap(), Um::CellFillShade, QString(), Um::ITable); |
||
558 | |||
17327 | fschmid | 559 | QString color = fillColor->currentColor(); |
560 | if (color == CommonStrings::tr_NoneColor) |
||
561 | color = CommonStrings::None; |
||
24782 | jghali | 562 | |
17311 | fschmid | 563 | PageItem_Table* table = m_item->asTable(); |
17327 | fschmid | 564 | if (m_doc->appMode != modeEditTable) |
17318 | fschmid | 565 | table->setFillShade(shade); |
17327 | fschmid | 566 | else |
24782 | jghali | 567 | table->setCellFillShade(fillShade->value()); |
568 | |||
569 | if (activeTransaction) |
||
570 | activeTransaction.commit(); |
||
571 | |||
16856 | craig | 572 | table->update(); |
573 | } |
||
574 | |||
17336 | fschmid | 575 | void PropertiesPalette_Table::on_buttonClearTableStyle_clicked() |
576 | { |
||
577 | if (!m_item || !m_item->isTable()) |
||
578 | return; |
||
579 | PageItem_Table* table = m_item->asTable(); |
||
580 | table->unsetDirectFormatting(); |
||
581 | table->update(); |
||
582 | } |
||
583 | |||
584 | void PropertiesPalette_Table::on_buttonClearCellStyle_clicked() |
||
585 | { |
||
586 | if (!m_item || !m_item->isTable()) |
||
587 | return; |
||
24779 | jghali | 588 | QScopedValueRollback<bool> dontResizeRb(m_doc->dontResize, true); |
589 | |||
17336 | fschmid | 590 | PageItem_Table* table = m_item->asTable(); |
24779 | jghali | 591 | if (m_doc->appMode != modeEditTable) |
592 | { |
||
593 | for (int row = 0; row < table->rows(); ++row) |
||
594 | { |
||
595 | int colSpan = 0; |
||
596 | for (int col = 0; col < table->columns(); col += colSpan) |
||
597 | { |
||
598 | TableCell currentCell = table->cellAt(row, col); |
||
599 | if (row == currentCell.row()) |
||
600 | currentCell.unsetDirectFormatting(); |
||
601 | colSpan = currentCell.columnSpan(); |
||
602 | } |
||
603 | } |
||
604 | } |
||
605 | else |
||
606 | { |
||
607 | QSet<TableCell> cells = table->selectedCells(); |
||
608 | if (cells.isEmpty()) |
||
609 | cells.insert(table->activeCell()); |
||
610 | for (auto cellIter = cells.begin(); cellIter != cells.end(); cellIter++) |
||
611 | { |
||
612 | TableCell currentCell(*cellIter); |
||
613 | currentCell.unsetDirectFormatting(); |
||
614 | } |
||
615 | } |
||
616 | |||
17336 | fschmid | 617 | table->adjustTable(); |
618 | table->update(); |
||
619 | } |
||
620 | |||
16856 | craig | 621 | void PropertiesPalette_Table::updateBorders() |
622 | { |
||
623 | if (!m_doc || !m_item || !m_item->isTable()) |
||
624 | return; |
||
24779 | jghali | 625 | QScopedValueRollback<bool> dontResizeRb(m_doc->dontResize, true); |
16856 | craig | 626 | |
627 | PageItem_Table* table = m_item->asTable(); |
||
24782 | jghali | 628 | TableSides selectedSides = sideSelector->selection(); |
17336 | fschmid | 629 | if (m_doc->appMode != modeEditTable) |
630 | { |
||
24782 | jghali | 631 | table->setBorders(m_currentBorder, selectedSides); |
17336 | fschmid | 632 | } |
633 | else |
||
634 | { |
||
23344 | jghali | 635 | QSet<TableCell> cells = table->selectedCells(); |
636 | if (cells.isEmpty()) |
||
637 | cells.insert(table->activeCell()); |
||
24782 | jghali | 638 | table->setCellBorders(cells, m_currentBorder, selectedSides); |
17336 | fschmid | 639 | } |
16856 | craig | 640 | table->update(); |
641 | } |
||
642 | |||
643 | void PropertiesPalette_Table::languageChange() |
||
644 | { |
||
21354 | jghali | 645 | retranslateUi(this); |
16856 | craig | 646 | } |
647 | |||
648 | void PropertiesPalette_Table::unitChange() |
||
649 | { |
||
650 | // Not implemented. |
||
651 | } |