Warning, file /graphics/glaxnimate/src/gui/tools/draw_tool_base.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "draw_tool_base.hpp" 0008 0009 0010 void glaxnimate::gui::tools::DrawToolBase::draw_shape(const PaintEvent& event, const QPainterPath& path) 0011 { 0012 ShapeToolWidget* options = widget(); 0013 0014 if ( !options->create_stroke() && !options->create_fill() ) 0015 { 0016 event.painter->setBrush(Qt::transparent); 0017 0018 //event.painter->setCompositionMode(QPainter::CompositionMode_Difference); 0019 QPen p(Qt::white, 1); 0020 p.setCosmetic(true); 0021 p.setDashPattern({4., 4.}); 0022 event.painter->setPen(p); 0023 event.painter->drawPath(path); 0024 0025 //event.painter->setCompositionMode(QPainter::CompositionMode_SourceOver); 0026 p.setDashOffset(4); 0027 p.setColor(Qt::black); 0028 event.painter->setPen(p); 0029 event.painter->drawPath(path); 0030 } 0031 else 0032 { 0033 if ( options->create_fill() ) 0034 event.painter->setBrush(event.window->current_color()); 0035 else 0036 event.painter->setBrush(Qt::transparent); 0037 0038 if ( options->create_stroke() ) 0039 { 0040 QPen p = event.window->current_pen_style(); 0041 p.setWidthF(p.widthF() * event.window->current_zoom()); 0042 event.painter->setPen(p); 0043 } 0044 else 0045 { 0046 event.painter->setPen(Qt::NoPen); 0047 } 0048 0049 event.painter->drawPath(path); 0050 } 0051 0052 } 0053 0054 void glaxnimate::gui::tools::DrawToolBase::create_shape( 0055 const QString& command_name, 0056 const Event& event, 0057 std::unique_ptr<model::ShapeElement> shape 0058 ) 0059 { 0060 auto document = event.window->document(); 0061 command::UndoMacroGuard macro(command_name, document); 0062 0063 model::VisualNode* select = shape.get(); 0064 0065 QString name = document->get_best_name(shape.get(), shape->name.get()); 0066 0067 model::ShapeListProperty* prop = get_container(event.window); 0068 0069 ShapeToolWidget* options = widget(); 0070 int index = prop->size(); 0071 0072 // Layer 0073 if ( options->create_layer() ) 0074 { 0075 std::unique_ptr<model::Layer> layer = std::make_unique<model::Layer>(document); 0076 auto comp = event.window->current_composition(); 0077 layer->animation->last_frame.set(comp->animation->last_frame.get()); 0078 layer->animation->first_frame.set(comp->animation->first_frame.get()); 0079 layer->name.set(name); 0080 model::ShapeListProperty* group_container = &event.window->current_composition()->shapes; 0081 select = layer.get(); 0082 prop = &layer->shapes; 0083 document->undo_stack().push( 0084 new command::AddShape(group_container, std::move(layer), group_container->size()) 0085 ); 0086 index = 0; 0087 } 0088 0089 if ( options->create_layer() || options->create_group() ) 0090 { 0091 // Group 0092 std::unique_ptr<model::Group> group = std::make_unique<model::Group>(document); 0093 group->name.set(name); 0094 model::ShapeListProperty* group_container = prop; 0095 prop = &group->shapes; 0096 if ( !options->create_layer() ) 0097 select = group.get(); 0098 model::VisualNode* owner_node = static_cast<model::VisualNode*>(group_container->object()); 0099 QTransform parent_t = owner_node->transform_matrix(owner_node->time()); 0100 QTransform parent_t_inv = parent_t.inverted(); 0101 group->transform.get()->set_transform_matrix(parent_t_inv); 0102 0103 QPointF center = shape->local_bounding_rect(0).center(); 0104 group->transform.get()->anchor_point.set(center); 0105 group->transform.get()->position.set(parent_t_inv.map(center)); 0106 0107 document->undo_stack().push( 0108 new command::AddShape(group_container, std::move(group), index) 0109 ); 0110 index = 0; 0111 0112 // Fill 0113 auto fill = std::make_unique<model::Fill>(document); 0114 fill->name.set(i18n("Fill")); 0115 fill->color.set(event.window->current_color()); 0116 fill->use.set(event.window->linked_brush_style(false)); 0117 fill->visible.set(options->create_fill()); 0118 0119 document->undo_stack().push( 0120 new command::AddShape(prop, std::move(fill), index) 0121 ); 0122 index++; 0123 0124 // Stroke 0125 auto stroke = std::make_unique<model::Stroke>(document); 0126 stroke->name.set(i18n("Stroke")); 0127 stroke->set_pen_style(event.window->current_pen_style()); 0128 stroke->use.set(event.window->linked_brush_style(true)); 0129 stroke->visible.set(options->create_stroke()); 0130 0131 document->undo_stack().push( 0132 new command::AddShape(prop, std::move(stroke), index) 0133 ); 0134 index++; 0135 } 0136 0137 shape->name.set(name); 0138 document->undo_stack().push( 0139 new command::AddShape(prop, std::move(shape), index) 0140 ); 0141 0142 event.window->set_current_document_node(select); 0143 } 0144 0145 void glaxnimate::gui::tools::DrawToolBase::shape_style_change_event(const Event& event) 0146 { 0147 event.repaint(); 0148 } 0149 0150 0151