File indexing completed on 2025-03-09 04:00:36
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 "shape_parent_dialog.hpp" 0008 #include "ui_shape_parent_dialog.h" 0009 #include <QtColorWidgets/ColorDelegate> 0010 #include "model/shapes/group.hpp" 0011 #include "item_models/node_type_proxy_model.hpp" 0012 0013 using namespace glaxnimate::gui; 0014 using namespace glaxnimate; 0015 0016 class ShapeParentDialog::Private 0017 { 0018 public: 0019 model::ShapeListProperty* current = nullptr; 0020 Ui::ShapeParentDialog ui; 0021 color_widgets::ReadOnlyColorDelegate color_delegate; 0022 item_models::NodeTypeProxyModel proxy; 0023 0024 Private(item_models::DocumentNodeModel* model) 0025 : proxy(model) 0026 { 0027 proxy.allow<model::Group>(); 0028 proxy.allow<model::Composition>(); 0029 } 0030 0031 model::ShapeListProperty* get_popr(const QModelIndex& index) 0032 { 0033 auto node = proxy.node(index); 0034 if ( !node ) 0035 return nullptr; 0036 if ( auto grp = qobject_cast<model::Group*>(node) ) 0037 return &grp->shapes; 0038 if ( auto lay = qobject_cast<model::Composition*>(node) ) 0039 return &lay->shapes; 0040 return nullptr; 0041 } 0042 }; 0043 0044 ShapeParentDialog::ShapeParentDialog(item_models::DocumentNodeModel* model, QWidget* parent) 0045 : QDialog(parent), d(std::make_unique<Private>(model)) 0046 { 0047 d->ui.setupUi(this); 0048 d->ui.view_document_node->setModel(&d->proxy); 0049 d->ui.view_document_node->expandAll(); 0050 d->ui.view_document_node->header()->setSectionResizeMode(item_models::DocumentNodeModel::ColumnName, QHeaderView::Stretch); 0051 d->ui.view_document_node->header()->hideSection(item_models::DocumentNodeModel::ColumnVisible); 0052 d->ui.view_document_node->header()->hideSection(item_models::DocumentNodeModel::ColumnLocked); 0053 d->ui.view_document_node->header()->hideSection(item_models::DocumentNodeModel::ColumnUsers); 0054 d->ui.view_document_node->header()->setSectionResizeMode(item_models::DocumentNodeModel::ColumnColor, QHeaderView::ResizeToContents); 0055 d->ui.view_document_node->setItemDelegateForColumn(item_models::DocumentNodeModel::ColumnColor, &d->color_delegate); 0056 } 0057 0058 ShapeParentDialog::~ShapeParentDialog() = default; 0059 0060 void ShapeParentDialog::changeEvent(QEvent* e) 0061 { 0062 QDialog::changeEvent(e); 0063 0064 if ( e->type() == QEvent::LanguageChange) 0065 { 0066 d->ui.retranslateUi(this); 0067 } 0068 } 0069 0070 model::ShapeListProperty * ShapeParentDialog::shape_parent() const 0071 { 0072 return d->current; 0073 } 0074 0075 0076 void ShapeParentDialog::select(const QModelIndex& index) 0077 { 0078 d->current = d->get_popr(index); 0079 } 0080 0081 void ShapeParentDialog::select_and_accept(const QModelIndex& index) 0082 { 0083 select(index); 0084 accept(); 0085 } 0086 0087 model::ShapeListProperty * ShapeParentDialog::get_shape_parent() 0088 { 0089 if ( exec() == QDialog::Accepted ) 0090 return d->current; 0091 return nullptr; 0092 } 0093 0094