MetadataWidget.hpp
1 #pragma once
2 
3 #include <Scenario/Commands/Metadata/ChangeElementColor.hpp>
4 #include <Scenario/Commands/Metadata/ChangeElementComments.hpp>
5 #include <Scenario/Commands/Metadata/ChangeElementLabel.hpp>
6 #include <Scenario/Commands/Metadata/ChangeElementName.hpp>
7 #include <Scenario/Inspector/CommentEdit.hpp>
8 
9 #include <Inspector/InspectorLayout.hpp>
10 
11 #include <score/command/Dispatchers/CommandDispatcher.hpp>
12 #include <score/model/IdentifiedObject.hpp>
13 #include <score/widgets/MarginLess.hpp>
14 #include <score/widgets/TextLabel.hpp>
15 
16 #include <QLineEdit>
17 #include <QPixmap>
18 #include <QString>
19 #include <QToolButton>
20 #include <QWidget>
21 
22 #include <verdigris>
23 
24 namespace score
25 {
26 class ModelMetadata;
27 }
28 
29 class QLabel;
30 class QLineEdit;
31 class QObject;
32 class QPushButton;
33 class QToolButton;
34 
35 namespace color_widgets
36 {
37 class ColorPaletteModel;
38 class Swatch;
39 }
40 
41 namespace Scenario
42 {
43 class CommentEdit;
44 
45 // TODO move me in Process
46 class MetadataWidget final : public QWidget
47 {
48  W_OBJECT(MetadataWidget)
49 
50 public:
51  explicit MetadataWidget(
52  const score::ModelMetadata& metadata, const score::CommandStackFacade& m,
53  const QObject* docObject, QWidget* parent = nullptr);
54 
55  ~MetadataWidget();
56 
57  template <typename T>
58  void setupConnections(const T& model)
59  {
60  using namespace Scenario::Command;
61  using namespace score::IDocument;
62  connect(this, &MetadataWidget::labelChanged, [&](const QString& newLabel) {
63  if(newLabel != model.metadata().getLabel())
64  m_commandDispatcher.submit(new ChangeElementLabel<T>{model, newLabel});
65  });
66 
67  connect(this, &MetadataWidget::commentsChanged, [&](const QString& newComments) {
68  if(newComments != model.metadata().getComment())
69  m_commandDispatcher.submit(new ChangeElementComments<T>{model, newComments});
70  });
71 
72  connect(this, &MetadataWidget::colorChanged, [&](score::ColorRef newColor) {
73  if(newColor != model.metadata().getColor())
74  m_commandDispatcher.submit(new ChangeElementColor<T>{model, newColor});
75  });
76 
77  /*
78  connect(
79  this, &MetadataWidget::extendedMetadataChanged,
80  [&](const QVariantMap& newM) {
81  if (newM != model.metadata().getExtendedMetadata())
82  m_commandDispatcher.submit(
83  new SetExtendedMetadata<T>{model, newM});
84  });
85  */
86  }
87 
88  void updateAsked();
89 
90 public:
91  void labelChanged(QString arg) W_SIGNAL(labelChanged, arg);
92  void commentsChanged(QString arg) W_SIGNAL(commentsChanged, arg);
93  void colorChanged(score::ColorRef arg) W_SIGNAL(colorChanged, arg);
94  void extendedMetadataChanged(const QVariantMap& arg)
95  W_SIGNAL(extendedMetadataChanged, arg);
96 
97 private:
98  static const constexpr int m_colorIconSize{21};
99 
100  const score::ModelMetadata& m_metadata;
101  CommandDispatcher<> m_commandDispatcher;
102 
103  Inspector::VBoxLayout m_metadataLayout;
104  QLineEdit m_labelLine;
105  CommentEdit m_comments;
106  color_widgets::Swatch* m_palette_widget;
107  QPixmap m_colorButtonPixmap{4 * m_colorIconSize / 3, 4 * m_colorIconSize / 3};
108 };
109 }
The CommandDispatcher class.
Definition: CommandDispatcher.hpp:13
Definition: lib/score/widgets/Layout.hpp:41
Definition: ChangeElementColor.hpp:15
Definition: ChangeElementComments.hpp:14
Definition: ChangeElementLabel.hpp:14
Definition: CommentEdit.hpp:9
Definition: MetadataWidget.hpp:47
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
The ModelMetadata class.
Definition: ModelMetadata.hpp:22
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Base toolkit upon which the software is built.
Definition: Application.cpp:90
A reference to a color. Used for skinning.
Definition: ColorReference.hpp:21