File indexing completed on 2025-02-02 04:11:24
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "glaxnimate_window_p.hpp" 0008 #include "widgets/shape_style/shape_style_preview_widget.hpp" 0009 0010 0011 void GlaxnimateWindow::Private::scene_selection_changed(const std::vector<model::VisualNode*>& selected, const std::vector<model::VisualNode*>& deselected) 0012 { 0013 if ( update_selection ) 0014 return; 0015 0016 selection_changed(selected, deselected); 0017 0018 0019 if ( !selected.empty() ) 0020 { 0021 set_current_object(selected.back()); 0022 } 0023 else 0024 { 0025 auto current = ui.view_document_node->currentIndex(); 0026 if ( current.isValid() && ! ui.view_document_node->selectionModel()->isSelected(current) ) 0027 set_current_object(nullptr); 0028 } 0029 } 0030 0031 void GlaxnimateWindow::Private::timeline_current_node_changed(model::VisualNode* node) 0032 { 0033 set_current_object(node); 0034 } 0035 0036 void GlaxnimateWindow::Private::set_current_document_node(model::VisualNode* node) 0037 { 0038 ui.view_document_node->replace_selection(node); 0039 ui.view_document_node->set_current_node(node); 0040 } 0041 0042 void GlaxnimateWindow::Private::set_current_object(model::DocumentNode* node) 0043 { 0044 if ( update_selection ) 0045 return; 0046 0047 auto lock = update_selection.get_lock(); 0048 0049 current_node = node; 0050 0051 model::Stroke* stroke = nullptr; 0052 model::Fill* fill = nullptr; 0053 0054 if ( node ) 0055 { 0056 stroke = qobject_cast<model::Stroke*>(node); 0057 fill = qobject_cast<model::Fill*>(node); 0058 if ( !stroke && !fill ) 0059 { 0060 auto group = qobject_cast<model::Group*>(node); 0061 0062 if ( !group ) 0063 { 0064 if ( auto parent = node->docnode_parent() ) 0065 group = qobject_cast<model::Group*>(parent); 0066 } 0067 0068 if ( group ) 0069 { 0070 int stroke_count = 0; 0071 int fill_count = 0; 0072 for ( const auto& shape : group->shapes ) 0073 { 0074 if ( auto s = qobject_cast<model::Stroke*>(shape.get()) ) 0075 { 0076 stroke = s; 0077 stroke_count++; 0078 } 0079 else if ( auto f = qobject_cast<model::Fill*>(shape.get()) ) 0080 { 0081 fill = f; 0082 fill_count++; 0083 } 0084 } 0085 0086 if ( stroke_count > 1 ) 0087 stroke = nullptr; 0088 0089 if ( fill_count > 1 ) 0090 fill = nullptr; 0091 } 0092 } 0093 } 0094 0095 // Property view 0096 property_model.set_object(node); 0097 ui.view_properties->expandAll(); 0098 0099 // Timeline Widget 0100 if ( parent->sender() != ui.timeline_widget ) 0101 ui.timeline_widget->set_current_node(node); 0102 0103 // Document tree view 0104 if ( parent->sender() != ui.view_document_node ) 0105 { 0106 ui.view_document_node->set_current_node(node); 0107 ui.view_document_node->repaint(); 0108 } 0109 0110 // Styles 0111 ui.stroke_style_widget->set_current(stroke);; 0112 ui.fill_style_widget->set_current(fill); 0113 ui.widget_gradients->set_current(fill, stroke); 0114 widget_current_style->clear_gradients(); 0115 0116 if ( fill ) 0117 { 0118 set_brush_reference(fill->use.get(), false); 0119 if ( !fill->visible.get() ) 0120 widget_current_style->set_fill_color(Qt::transparent); 0121 } 0122 0123 if ( stroke ) 0124 { 0125 set_brush_reference(stroke->use.get(), true); 0126 if ( !stroke->visible.get() ) 0127 widget_current_style->set_stroke_color(Qt::transparent); 0128 } 0129 } 0130 0131 0132 void GlaxnimateWindow::Private::selection_changed(const std::vector<model::VisualNode*>& selected, const std::vector<model::VisualNode*>& deselected) 0133 { 0134 if ( update_selection ) 0135 return; 0136 0137 auto lock = update_selection.get_lock(); 0138 0139 if ( parent->sender() != ui.view_document_node && parent->sender() != ui.view_document_node->selectionModel() ) 0140 ui.view_document_node->update_selection(selected, deselected); 0141 0142 if ( parent->sender() != &scene ) 0143 { 0144 scene.user_select(deselected, graphics::DocumentScene::Remove); 0145 scene.user_select(selected, graphics::DocumentScene::Append); 0146 } 0147 0148 if ( parent->sender() != ui.timeline_widget ) 0149 ui.timeline_widget->select(selected, deselected); 0150 0151 const auto& selection = scene.selection(); 0152 0153 if ( std::find(deselected.begin(), deselected.end(), current_node) != deselected.end() ) 0154 { 0155 lock.unlock(); 0156 set_current_object(selection.empty() ? nullptr : selection[0]); 0157 } 0158 0159 std::vector<model::Fill*> fills; 0160 std::vector<model::Stroke*> strokes; 0161 for ( auto node : selection ) 0162 { 0163 for ( const auto styler : node->docnode_find_by_type<model::Styler>() ) 0164 { 0165 if ( auto fill = styler->cast<model::Fill>() ) 0166 fills.push_back(fill); 0167 else if ( auto stroke = styler->cast<model::Stroke>() ) 0168 strokes.push_back(stroke); 0169 } 0170 } 0171 0172 ui.fill_style_widget->set_targets(fills); 0173 ui.stroke_style_widget->set_targets(strokes); 0174 ui.widget_gradients->set_targets(fills, strokes); 0175 } 0176