Salome HOME
updated copyright message
[modules/yacs.git] / src / ydfx_gui / YDFXGUIPortsSelector.hxx
1 // Copyright (C) 2016-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __YDFXGUIPORTSSELECTOR_HXX__
22 #define __YDFXGUIPORTSSELECTOR_HXX__
23
24 #include "ydfxwidgetsExport.hxx"
25
26 #include "YDFXGUIWrap.hxx"
27
28 #include <QLabel>
29 #include <QLineEdit>
30 #include <QGroupBox>
31 #include <QScrollArea>
32 #include <QHBoxLayout>
33 #include <QTableWidget>
34 #include <QItemDelegate>
35
36 #include <vector>
37
38 class QValidator;
39
40 class YDFXGUIInputPortValueEditor;
41
42 class ColoredString
43 {
44 public:
45   ColoredString(const QString& str):_str(str) { }
46   void setColor(const QColor& col) { _col=col; }
47   const QString& str() const { return _str; }
48   const QColor& color() const { return _col; }
49 private:
50   QString _str;
51   QColor _col;
52 };
53
54 class MyWidgetPainter
55 {
56 public:
57   virtual ~MyWidgetPainter() { }
58   virtual void paintEvent(QPaintEvent *event) = 0;
59   virtual QSize sizeHint() const = 0;
60   virtual void appendLetter(const QString& letter) = 0;
61   virtual void supprLetter() = 0;
62   virtual bool isNotSelected() const = 0;
63 public:
64   void changeAngle();
65 protected:
66   MyWidgetPainter(YDFXGUIInputPortValueEditor *wid):_wid(wid),_angle(120) { }
67   YDFXGUIInputPortValueEditor *getWidget() const { return _wid; }
68 protected:
69   void paintDataCommonPart(QPaintEvent *event, const QString& text);
70   void drawPadlock(QWidget *wid) const;
71   void drawDice(QWidget *wid) const;
72 private:
73   YDFXGUIInputPortValueEditor *_wid;
74   int _angle;
75 public:
76   static const int SZ_OF_PEN_RECT;
77   static const int PADLOCK_X;
78   static const int PADLOCK_Y;
79   static const int DICE_X;
80   static const int DICE_Y;
81 };
82
83 class MyWidgetPainterNoFocus : public MyWidgetPainter
84 {
85 public:
86   MyWidgetPainterNoFocus(YDFXGUIInputPortValueEditor *wid):MyWidgetPainter(wid) { }
87 private:
88   template<class FontBrushSetGet>
89   static void prepareFontAndBrush(FontBrushSetGet *fbsg);
90 private:
91   virtual ~MyWidgetPainterNoFocus() { }
92   void paintEvent(QPaintEvent *event);
93   QSize sizeHint() const;
94   void appendLetter(const QString& letter);
95   void supprLetter();
96   bool isNotSelected() const { return true; }
97 };
98
99 class MyWidgetPainterFocus : public MyWidgetPainter
100 {
101 public:
102   MyWidgetPainterFocus(YDFXGUIInputPortValueEditor *wid):MyWidgetPainter(wid) { }
103   QString getText() const { return _textEntered; }
104 private:
105   template<class FontBrushSetGet>
106   static void prepareFontAndBrush(FontBrushSetGet *fbsg);
107 private:
108   virtual ~MyWidgetPainterFocus() { }
109   void paintEvent(QPaintEvent *event);
110   QSize sizeHint() const;
111   void appendLetter(const QString& letter);
112   void supprLetter();
113   bool isNotSelected() const { return false; }
114 private:
115   QString _textEntered;
116 };
117
118 class YDFXGUIInputPortValueEditor : public QWidget
119 {
120   Q_OBJECT
121   Q_PROPERTY(QString text READ text WRITE setText)
122 public:
123   YDFXWIDGETS_EXPORT YDFXGUIInputPortValueEditor(YACSEvalInputPort *inp);
124   YDFXWIDGETS_EXPORT ~YDFXGUIInputPortValueEditor();
125   YDFXWIDGETS_EXPORT QString text() const;
126   YDFXWIDGETS_EXPORT void setText(const QString& text);
127   YDFXWIDGETS_EXPORT void paintEvent(QPaintEvent *event);
128   YDFXWIDGETS_EXPORT void mousePressEvent(QMouseEvent *event);
129   YDFXWIDGETS_EXPORT void mouseReleaseEvent(QMouseEvent *event);
130   YDFXWIDGETS_EXPORT void keyPressEvent(QKeyEvent *event);
131   YDFXWIDGETS_EXPORT void focusOutEvent(QFocusEvent * event);
132   YDFXWIDGETS_EXPORT QSize sizeHint() const;
133   YDFXWIDGETS_EXPORT QSize minimumSizeHint() const;
134 public:
135   YDFXWIDGETS_EXPORT bool isOK() const;
136   YDFXWIDGETS_EXPORT bool isRandom() const;
137   YDFXWIDGETS_EXPORT YACSEvalInputPort *getPort() const { return _inp; }
138   YDFXWIDGETS_EXPORT static bool IsOK(YACSEvalInputPort *inp);
139 public slots:
140   YDFXWIDGETS_EXPORT void applyModificationOfLook();
141   YDFXWIDGETS_EXPORT bool toggleRandom();
142 signals:
143   void changeLook();
144   void statusChanged();
145 private:
146   YACSEvalInputPort *_inp;
147   MyWidgetPainter *_zePainter;
148   QValidator *_valid;
149 };
150
151 class HoverLabel : public QLabel
152 {
153 public:
154   YDFXWIDGETS_EXPORT HoverLabel(QWidget *parent);
155   YDFXWIDGETS_EXPORT void mousePressEvent(QMouseEvent *event);
156   YDFXWIDGETS_EXPORT void mouseReleaseEvent(QMouseEvent *event);
157   YDFXWIDGETS_EXPORT void enterEvent(QEvent *event);
158   YDFXWIDGETS_EXPORT void leaveEvent(QEvent *event);
159   YDFXWIDGETS_EXPORT void paintEvent(QPaintEvent *event);
160   YDFXWIDGETS_EXPORT QSize sizeHint() const;
161 private:
162   virtual QSize sizeHintNotHovered() const = 0;
163   virtual void paintIfNotOn(QPaintEvent *event) = 0;
164   virtual void pressOccured() = 0;
165   virtual std::vector<ColoredString> textForEmulatedPushButton() const = 0;
166   static void AssignFontOnHover(QFont& ft);
167 private:
168   bool _isin;
169   bool _isPressed;
170   static const int PT_SZ_ON_HOVER;
171 };
172
173 class InputLabel : public HoverLabel
174 {
175   Q_OBJECT
176 public:
177   YDFXWIDGETS_EXPORT InputLabel(YACSEvalInputPort *inp, QWidget *parent);
178 private:
179   QSize sizeHintNotHovered() const;
180   void paintIfNotOn(QPaintEvent *event);
181   void pressOccured();
182   std::vector<ColoredString> textForEmulatedPushButton() const;
183 public:
184   YDFXWIDGETS_EXPORT static void AssignTextAndTooltip(QLabel *wid, YACSEvalInputPort *port);
185 signals:
186   YDFXWIDGETS_EXPORT void randomnessStatusChanged();
187 private:
188   YACSEvalInputPort *_inp;
189 };
190
191 class InputLabelNonToggle : public QLabel
192 {
193 public:
194   YDFXWIDGETS_EXPORT InputLabelNonToggle(YDFXGUIInputPortValueEditor *wid, QWidget *parent);
195 private:
196   YDFXGUIInputPortValueEditor *_wid;
197 };
198
199 class OutputLabel : public HoverLabel
200 {
201   Q_OBJECT
202 public:
203   YDFXWIDGETS_EXPORT OutputLabel(YACSEvalOutputPort *outp, QWidget *parent);
204   YDFXWIDGETS_EXPORT bool isQOfInt() const;
205 private:
206   QSize sizeHintNotHovered() const;
207   void paintIfNotOn(QPaintEvent *event);
208   void pressOccured();
209   std::vector<ColoredString> textForEmulatedPushButton() const;
210   QSize minimumSizeHint() const;
211   static void ComputePointsToCircle(const QString& txt, const QRect& refRect, const QFont& font, QPointF pts[7]);
212 signals:
213   void clicked();
214 private:
215   static const int PEN_SZ_CIRCLED;
216 private:
217   YACSEvalOutputPort *_outp;
218 };
219
220 class YDFXGUIOKCls
221 {
222 public:
223   YDFXWIDGETS_EXPORT YDFXGUIOKCls():_isOK(false) { }
224   YDFXWIDGETS_EXPORT bool wasOK() const { return _isOK; }
225   YDFXWIDGETS_EXPORT void setWasOKStatus(bool newStatus) { _isOK=newStatus; }
226   YDFXWIDGETS_EXPORT virtual bool isOK() const = 0;
227 protected:
228   void initOK();
229 private:
230   bool _isOK;
231 };
232
233 class YDFXGUIGatherPorts : public QWidget, public YDFXGUIOKCls
234 {
235   Q_OBJECT
236 public:
237   YDFXWIDGETS_EXPORT YDFXGUIGatherPorts(QWidget *parent):QWidget(parent) { }
238 public slots:
239   YDFXWIDGETS_EXPORT void somebodyChangedStatus();
240 signals:
241   void theGlobalStatusChanged(bool newStatus);
242 };
243
244 class YDFXGUIInputPortsSelector : public YDFXGUIGatherPorts
245 {
246   Q_OBJECT
247 public:
248   YDFXWIDGETS_EXPORT YDFXGUIInputPortsSelector(YACSEvalYFXWrap *efx, QWidget *parent=0);
249   YDFXWIDGETS_EXPORT ~YDFXGUIInputPortsSelector();
250   YDFXWIDGETS_EXPORT const std::vector< YACSEvalInputPort * >& getInputs() const { return _inps; }
251   YDFXWIDGETS_EXPORT bool isOK() const;
252   YDFXWIDGETS_EXPORT bool areSeqWellDefined() const;
253   YDFXWIDGETS_EXPORT static void DrawWarningSign(QPainter& painter, int width0, int height0);
254 private:
255   void fillWidget();
256   void showEvent(QShowEvent *e);
257   void timerEvent(QTimerEvent *e);
258   void paintEvent(QPaintEvent *e);
259 private:
260   std::vector< YACSEvalInputPort * > _inps;
261   int _timerId;
262 };
263
264 class YDFXGUIOutputPortsSelector : public YDFXGUIGatherPorts
265 {
266   Q_OBJECT
267 public:
268   YDFXWIDGETS_EXPORT YDFXGUIOutputPortsSelector(YACSEvalYFXWrap *efx, QWidget *parent=0);
269   YDFXWIDGETS_EXPORT const std::vector< YACSEvalOutputPort * >& getOutputs() const { return _outps; }
270   YDFXWIDGETS_EXPORT bool isOK() const;
271 private:
272   void fillWidget();
273   void paintEvent(QPaintEvent *e);
274 private:
275   std::vector< YACSEvalOutputPort * > _outps;
276 };
277
278 class YDFXGUIAbstractPorts : public QWidget
279 {
280 protected:
281   YDFXGUIAbstractPorts(YACSEvalYFXWrap *efx, QWidget *parent):QWidget(parent) {  }
282   QScrollArea *setupWidgets(const QString& title, QWidget *zeWidget);
283   virtual YDFXGUIGatherPorts *getPortsManager() = 0;
284   virtual const YDFXGUIGatherPorts *getPortsManager() const = 0;
285 };
286
287 class YDFXGUIInputPorts : public YDFXGUIAbstractPorts
288 {
289 public:
290   YDFXWIDGETS_EXPORT YDFXGUIInputPorts(YACSEvalYFXWrap *efx, QWidget *parent);
291   YDFXWIDGETS_EXPORT bool isOK() const { return _inputsSelector->isOK(); }
292   YDFXWIDGETS_EXPORT bool areSeqWellDefined() const { return _inputsSelector->areSeqWellDefined(); }
293   YDFXWIDGETS_EXPORT YDFXGUIInputPortsSelector *getInputsSelector() const { return _inputsSelector; }
294   YDFXWIDGETS_EXPORT YDFXGUIGatherPorts *getPortsManager() { return _inputsSelector; }
295   YDFXWIDGETS_EXPORT const YDFXGUIGatherPorts *getPortsManager() const { return _inputsSelector; }
296 private:
297   YDFXGUIInputPortsSelector *_inputsSelector;
298 };
299
300 class YDFXGUIOutputPorts : public YDFXGUIAbstractPorts
301 {
302 public:
303   YDFXWIDGETS_EXPORT YDFXGUIOutputPorts(YACSEvalYFXWrap *efx, QWidget *parent);
304   YDFXWIDGETS_EXPORT bool isOK() const { return _outputsSelector->isOK(); }
305   YDFXWIDGETS_EXPORT YDFXGUIGatherPorts *getPortsManager() { return _outputsSelector; }
306   YDFXWIDGETS_EXPORT const YDFXGUIGatherPorts *getPortsManager() const { return _outputsSelector; }
307 private:
308   YDFXGUIOutputPortsSelector *_outputsSelector;
309 };
310
311 class YDFXGUIAllPorts : public QWidget
312 {
313   Q_OBJECT
314 public:
315   YDFXWIDGETS_EXPORT YDFXGUIAllPorts(YACSEvalYFXWrap *efx, QWidget *parent);
316   YDFXWIDGETS_EXPORT bool isOK() const;
317 private:
318   YDFXGUIInputPorts *_in;
319   YDFXGUIOutputPorts *_out;
320 public slots:
321   YDFXWIDGETS_EXPORT void somethingChangedInPorts(bool status);
322 signals:
323   void sequencesCanBeDefinedSignal(bool status);
324   void canBeExecutedSignal(bool status);
325 };
326
327 #endif