1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_MORPH_OPERATOR_VIEW_HH
4 #define SPECTMORPH_MORPH_OPERATOR_VIEW_HH
5 
6 #include "smwindow.hh"
7 #include "smlabel.hh"
8 #include "smfixedgrid.hh"
9 #include "smframe.hh"
10 #include "smslider.hh"
11 #include "smmorphplan.hh"
12 #include "smmorphplanwindow.hh"
13 #include "smtoolbutton.hh"
14 #include <functional>
15 
16 namespace SpectMorph
17 {
18 
19 class MorphOperatorTitle : public Label
20 {
21   bool in_move = false;
22 
23 public:
MorphOperatorTitle(Widget * parent,const std::string & text)24   MorphOperatorTitle (Widget *parent, const std::string& text) :
25     Label (parent, text)
26   {
27   }
28   void
mouse_press(const MouseEvent & event)29   mouse_press (const MouseEvent& event) override
30   {
31     if (event.button == LEFT_BUTTON)
32       {
33         if (event.double_click)
34           {
35             signal_rename();
36           }
37         else
38           {
39             in_move = true;
40 
41             signal_move (abs_y() + event.y);
42           }
43       }
44   }
45   void
mouse_move(const MouseEvent & event)46   mouse_move (const MouseEvent& event) override
47   {
48     if (in_move)
49       signal_move (abs_y() + event.y);
50   }
51   void
mouse_release(const MouseEvent & event)52   mouse_release (const MouseEvent& event) override
53   {
54     if (event.button == LEFT_BUTTON && in_move)
55       {
56         in_move = false;
57 
58         // DELETION can occur here
59         signal_end_move (abs_y() + event.y);
60       }
61   }
62   Signal<double> signal_move;
63   Signal<double> signal_end_move;
64   Signal<>       signal_rename;
65 };
66 class MorphPlanWindow;
67 
68 class MorphOperatorView : public Frame
69 {
70 protected:
71   ToolButton         *fold_button;
72   ToolButton         *close_button;
73   MorphOperatorTitle *title_label;
74   int                 m_role = -1;
75 
76   MorphPlanWindow *morph_plan_window;
77   MorphOperator *m_op;
78   MorphOperator *move_start_next;
79 
80 public:
81   Widget        *body_widget;
82 
83   Signal<>                      signal_size_changed;
84   Signal<MorphOperator *, bool> signal_move_indication;
85 
86   MorphOperatorView (Widget *parent, MorphOperator *op, MorphPlanWindow *window);
87 
88   void
hide_tool_buttons()89   hide_tool_buttons()
90   {
91     fold_button->set_visible (false);
92     close_button->set_visible (false);
93   }
94   void
on_fold_clicked()95   on_fold_clicked()
96   {
97     m_op->set_folded (!m_op->folded());
98 
99     update_body_visible();
100 
101     signal_size_changed();
102   }
103   void
update_body_visible()104   update_body_visible()
105   {
106     fold_button->set_symbol (m_op->folded() ? '>' : 'v');
107     body_widget->set_visible (!m_op->folded());
108   }
109   virtual double
view_height()110   view_height()
111   {
112     return 4;
113   }
114   virtual bool
is_output()115   is_output()
116   {
117     return false;
118   }
119   MorphOperator *
op()120   op()
121   {
122     return m_op;
123   }
124   void set_role (int role);
125   void set_role_colors();
126 
127   void on_move (double y);
128   void on_end_move (double y);
129   void on_rename();
130   void on_operators_changed();
131 };
132 
133 }
134 
135 #endif
136