src/mainwindow.cpp

changeset 1432
4cc687851fbb
parent 1428
ece049033adc
child 1433
bd3a9e237ef5
equal deleted inserted replaced
1431:2e0e2c696605 1432:4cc687851fbb
87 connect (m_tabs, SIGNAL (currentChanged(int)), this, SLOT (tabSelected())); 87 connect (m_tabs, SIGNAL (currentChanged(int)), this, SLOT (tabSelected()));
88 connect (m_tabs, SIGNAL (tabCloseRequested (int)), this, SLOT (closeTab (int))); 88 connect (m_tabs, SIGNAL (tabCloseRequested (int)), this, SLOT (closeTab (int)));
89 connect(m_documents, &DocumentManager::documentCreated, this, &MainWindow::newDocument); 89 connect(m_documents, &DocumentManager::documentCreated, this, &MainWindow::newDocument);
90 connect(m_documents, SIGNAL(documentClosed(LDDocument*)), this, SLOT(documentClosed(LDDocument*))); 90 connect(m_documents, SIGNAL(documentClosed(LDDocument*)), this, SLOT(documentClosed(LDDocument*)));
91 91
92 m_quickColors = m_guiUtilities->loadQuickColorList();
93 updateActions(); 92 updateActions();
94 93
95 // Connect all actions and save default sequences 94 // Connect all actions and save default sequences
96 applyToActions([&](QAction* action) 95 applyToActions([&](QAction* action)
97 { 96 {
252 m_colorButtons.clear(); 251 m_colorButtons.clear();
253 ui.toolBarColors->clear(); 252 ui.toolBarColors->clear();
254 ui.toolBarColors->addAction (ui.actionUncolor); 253 ui.toolBarColors->addAction (ui.actionUncolor);
255 ui.toolBarColors->addSeparator(); 254 ui.toolBarColors->addSeparator();
256 255
257 for (ColorToolbarItem& entry : m_quickColors) 256 for (LDColor entry : config::quickColorToolbar())
258 { 257 {
259 if (entry.isSeparator()) 258 if (entry == LDColor::nullColor)
260 { 259 {
260 // Null color is used as a separator
261 ui.toolBarColors->addSeparator(); 261 ui.toolBarColors->addSeparator();
262 } 262 }
263 else 263 else
264 { 264 {
265 QToolButton* colorButton = new QToolButton {this}; 265 QToolButton* colorButton = new QToolButton {this};
266 colorButton->setIcon(makeColorIcon(entry.color(), 16)); 266 colorButton->setIcon(makeColorIcon(entry, 16));
267 colorButton->setIconSize({16, 16}); 267 colorButton->setIconSize({16, 16});
268 colorButton->setToolTip(entry.color().name()); 268 colorButton->setToolTip(entry.name());
269 colorButton->setStatusTip(format( 269 colorButton->setStatusTip(format(
270 tr("Changes the color of selected objects to %1"), 270 tr("Changes the color of selected objects to %1"),
271 entry.color().name() 271 entry.name()
272 )); 272 ));
273 ui.toolBarColors->addWidget (colorButton); 273 ui.toolBarColors->addWidget (colorButton);
274 m_colorButtons << colorButton; 274 m_colorButtons << colorButton;
275 connect(colorButton, 275 connect(colorButton,
276 &QToolButton::clicked, 276 &QToolButton::clicked,
277 [&]() 277 [&]()
278 { 278 {
279 for (LDObject* object : selectedObjects()) 279 for (LDObject* object : selectedObjects())
280 { 280 {
281 if (object->isColored()) 281 if (object->isColored())
282 object->setColor(entry.color()); 282 object->setColor(entry);
283 } 283 }
284 284
285 endAction(); 285 endAction();
286 } 286 }
287 ); 287 );
726 return static_cast<Canvas*>(ui.rendererStack->currentWidget()); 726 return static_cast<Canvas*>(ui.rendererStack->currentWidget());
727 } 727 }
728 728
729 // --------------------------------------------------------------------------------------------------------------------- 729 // ---------------------------------------------------------------------------------------------------------------------
730 // 730 //
731 void MainWindow::setQuickColors (const QVector<ColorToolbarItem>& colors)
732 {
733 m_quickColors = colors;
734 updateColorToolbar();
735 }
736
737 // ---------------------------------------------------------------------------------------------------------------------
738 //
739 void MainWindow::closeTab (int tabindex) 731 void MainWindow::closeTab (int tabindex)
740 { 732 {
741 auto iterator = m_documents->findDocumentByName(m_tabs->tabData (tabindex).toString()); 733 auto iterator = m_documents->findDocumentByName(m_tabs->tabData (tabindex).toString());
742 734
743 if (iterator != m_documents->end()) 735 if (iterator != m_documents->end())
821 connect (document->history(), SIGNAL (redone()), this, SLOT (historyTraversed())); 813 connect (document->history(), SIGNAL (redone()), this, SLOT (historyTraversed()));
822 connect (document->history(), SIGNAL (stepAdded()), this, SLOT (updateActions())); 814 connect (document->history(), SIGNAL (stepAdded()), this, SLOT (updateActions()));
823 815
824 if (not cache) 816 if (not cache)
825 openDocumentForEditing(document); 817 openDocumentForEditing(document);
818 }
819
820 void MainWindow::settingsChanged()
821 {
822 m_documents->loadLogoedStuds();
823 updateColorToolbar();
824 renderer()->setBackground();
825 doFullRefresh();
826 updateDocumentList();
826 } 827 }
827 828
828 void MainWindow::openDocumentForEditing(LDDocument* document) 829 void MainWindow::openDocumentForEditing(LDDocument* document)
829 { 830 {
830 if (document->isFrozen()) 831 if (document->isFrozen())
993 994
994 void MainWindow::replaceSelection(const QItemSelection& selection) 995 void MainWindow::replaceSelection(const QItemSelection& selection)
995 { 996 {
996 m_selections[m_currentDocument]->select(selection, QItemSelectionModel::ClearAndSelect); 997 m_selections[m_currentDocument]->select(selection, QItemSelectionModel::ClearAndSelect);
997 } 998 }
998
999 // ---------------------------------------------------------------------------------------------------------------------
1000 //
1001 ColorToolbarItem::ColorToolbarItem(LDColor color) :
1002 m_color (color) {}
1003
1004 ColorToolbarItem ColorToolbarItem::makeSeparator()
1005 {
1006 return {LDColor::nullColor};
1007 }
1008
1009 bool ColorToolbarItem::isSeparator() const
1010 {
1011 return color() == LDColor::nullColor;
1012 }
1013
1014 LDColor ColorToolbarItem::color() const
1015 {
1016 return m_color;
1017 }
1018
1019 void ColorToolbarItem::setColor (LDColor color)
1020 {
1021 m_color = color;
1022 }

mercurial