1 // Copyright (C) 2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #ifndef __YDFXGUIPORTSSELECTOR_HXX__
22 #define __YDFXGUIPORTSSELECTOR_HXX__
24 #include "ydfxwidgetsExport.hxx"
26 #include "YDFXGUIWrap.hxx"
31 #include <QScrollArea>
32 #include <QHBoxLayout>
33 #include <QTableWidget>
34 #include <QItemDelegate>
40 class YDFXGUIInputPortValueEditor;
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; }
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;
66 MyWidgetPainter(YDFXGUIInputPortValueEditor *wid):_wid(wid),_angle(120) { }
67 YDFXGUIInputPortValueEditor *getWidget() const { return _wid; }
69 void paintDataCommonPart(QPaintEvent *event, const QString& text);
70 void drawPadlock(QWidget *wid) const;
71 void drawDice(QWidget *wid) const;
73 YDFXGUIInputPortValueEditor *_wid;
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;
83 class MyWidgetPainterNoFocus : public MyWidgetPainter
86 MyWidgetPainterNoFocus(YDFXGUIInputPortValueEditor *wid):MyWidgetPainter(wid) { }
88 template<class FontBrushSetGet>
89 static void prepareFontAndBrush(FontBrushSetGet *fbsg);
91 virtual ~MyWidgetPainterNoFocus() { }
92 void paintEvent(QPaintEvent *event);
93 QSize sizeHint() const;
94 void appendLetter(const QString& letter);
96 bool isNotSelected() const { return true; }
99 class MyWidgetPainterFocus : public MyWidgetPainter
102 MyWidgetPainterFocus(YDFXGUIInputPortValueEditor *wid):MyWidgetPainter(wid) { }
103 QString getText() const { return _textEntered; }
105 template<class FontBrushSetGet>
106 static void prepareFontAndBrush(FontBrushSetGet *fbsg);
108 virtual ~MyWidgetPainterFocus() { }
109 void paintEvent(QPaintEvent *event);
110 QSize sizeHint() const;
111 void appendLetter(const QString& letter);
113 bool isNotSelected() const { return false; }
115 QString _textEntered;
118 class YDFXGUIInputPortValueEditor : public QWidget
121 Q_PROPERTY(QString text READ text WRITE setText)
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;
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);
140 YDFXWIDGETS_EXPORT void applyModificationOfLook();
141 YDFXWIDGETS_EXPORT bool toggleRandom();
144 void statusChanged();
146 YACSEvalInputPort *_inp;
147 MyWidgetPainter *_zePainter;
151 class HoverLabel : public QLabel
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;
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);
170 static const int PT_SZ_ON_HOVER;
173 class InputLabel : public HoverLabel
177 YDFXWIDGETS_EXPORT InputLabel(YACSEvalInputPort *inp, QWidget *parent);
179 QSize sizeHintNotHovered() const;
180 void paintIfNotOn(QPaintEvent *event);
182 std::vector<ColoredString> textForEmulatedPushButton() const;
184 YDFXWIDGETS_EXPORT static void AssignTextAndTooltip(QLabel *wid, YACSEvalInputPort *port);
186 YDFXWIDGETS_EXPORT void randomnessStatusChanged();
188 YACSEvalInputPort *_inp;
191 class InputLabelNonToggle : public QLabel
194 YDFXWIDGETS_EXPORT InputLabelNonToggle(YDFXGUIInputPortValueEditor *wid, QWidget *parent);
196 YDFXGUIInputPortValueEditor *_wid;
199 class OutputLabel : public HoverLabel
203 YDFXWIDGETS_EXPORT OutputLabel(YACSEvalOutputPort *outp, QWidget *parent);
204 YDFXWIDGETS_EXPORT bool isQOfInt() const;
206 QSize sizeHintNotHovered() const;
207 void paintIfNotOn(QPaintEvent *event);
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]);
215 static const int PEN_SZ_CIRCLED;
217 YACSEvalOutputPort *_outp;
223 YDFXWIDGETS_EXPORT YDFXGUIOKCls():_isOK(false) { }
224 YDFXWIDGETS_EXPORT bool wasOK() const { return _isOK; }
225 YDFXWIDGETS_EXPORT bool setWasOKStatus(bool newStatus) { _isOK=newStatus; }
226 YDFXWIDGETS_EXPORT virtual bool isOK() const = 0;
233 class YDFXGUIGatherPorts : public QWidget, public YDFXGUIOKCls
237 YDFXWIDGETS_EXPORT YDFXGUIGatherPorts(QWidget *parent):QWidget(parent) { }
239 YDFXWIDGETS_EXPORT void somebodyChangedStatus();
241 void theGlobalStatusChanged(bool newStatus);
244 class YDFXGUIInputPortsSelector : public YDFXGUIGatherPorts
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);
256 void showEvent(QShowEvent *e);
257 void timerEvent(QTimerEvent *e);
258 void paintEvent(QPaintEvent *e);
260 std::vector< YACSEvalInputPort * > _inps;
264 class YDFXGUIOutputPortsSelector : public YDFXGUIGatherPorts
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;
273 void paintEvent(QPaintEvent *e);
275 std::vector< YACSEvalOutputPort * > _outps;
278 class YDFXGUIAbstractPorts : public QWidget
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;
287 class YDFXGUIInputPorts : public YDFXGUIAbstractPorts
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; }
297 YDFXGUIInputPortsSelector *_inputsSelector;
300 class YDFXGUIOutputPorts : public YDFXGUIAbstractPorts
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; }
308 YDFXGUIOutputPortsSelector *_outputsSelector;
311 class YDFXGUIAllPorts : public QWidget
315 YDFXWIDGETS_EXPORT YDFXGUIAllPorts(YACSEvalYFXWrap *efx, QWidget *parent);
316 YDFXWIDGETS_EXPORT bool isOK() const;
318 YDFXGUIInputPorts *_in;
319 YDFXGUIOutputPorts *_out;
321 YDFXWIDGETS_EXPORT void somethingChangedInPorts(bool status);
323 void sequencesCanBeDefinedSignal(bool status);
324 void canBeExecutedSignal(bool status);