1 #pragma once
2 
3 #ifndef PANE_H
4 #define PANE_H
5 
6 // TODO: cambiare il nome del file in tpanel.h
7 
8 //#include <QDockWidget>
9 #include "../toonzqt/tdockwindows.h"
10 
11 class TPanelTitleBarButtonSet;
12 class Room;
13 
14 //! icon buttons placed on the panel titlebar (cfr. viewerpane.h)
15 class TPanelTitleBarButton : public QWidget {
16   Q_OBJECT
17   QString m_standardPixmapName;
18   QPixmap m_standardPixmap;
19   QColor m_overColor;
20   QColor m_pressedColor;
21   QColor m_freezeColor;
22   QColor m_previewColor;
23 
24   Q_PROPERTY(QColor OverColor READ getOverColor WRITE setOverColor);
25   Q_PROPERTY(QColor PressedColor READ getPressedColor WRITE setPressedColor);
26   Q_PROPERTY(QColor FreezeColor READ getFreezeColor WRITE setFreezeColor);
27   Q_PROPERTY(QColor PreviewColor READ getPreviewColor WRITE setPreviewColor);
28 
29   bool m_rollover;
30   TPanelTitleBarButtonSet *m_buttonSet;
31   int m_id;
32 
33 protected:
34   bool m_pressed;
35 
36 public:
37   TPanelTitleBarButton(QWidget *parent, const QString &standardPixmapName);
38   TPanelTitleBarButton(QWidget *parent, const QPixmap &standardPixmap);
39 
40   //! call this method to make a radio button. id is the button identifier
41   void setButtonSet(TPanelTitleBarButtonSet *buttonSet, int id);
getId()42   int getId() const { return m_id; }
43 
setOverColor(const QColor & color)44   void setOverColor(const QColor &color) { m_overColor = color; }
getOverColor()45   QColor getOverColor() const { return m_overColor; }
setPressedColor(const QColor & color)46   void setPressedColor(const QColor &color) { m_pressedColor = color; }
getPressedColor()47   QColor getPressedColor() const { return m_pressedColor; }
setFreezeColor(const QColor & color)48   void setFreezeColor(const QColor &color) { m_freezeColor = color; }
getFreezeColor()49   QColor getFreezeColor() const { return m_freezeColor; }
setPreviewColor(const QColor & color)50   void setPreviewColor(const QColor &color) { m_previewColor = color; }
getPreviewColor()51   QColor getPreviewColor() const { return m_previewColor; }
52 
53 public slots:
54   void setPressed(bool pressed);  // n.b. doesn't emit signals. calls update()
55 
56 protected:
57   void paintEvent(QPaintEvent *event) override;
58 
59   void mouseMoveEvent(QMouseEvent *event) override;
60   void enterEvent(QEvent *) override;
61   void leaveEvent(QEvent *) override;
62   void mousePressEvent(QMouseEvent *event) override;
63 
64 signals:
65   //! emitted when the user press the button
66   //! n.b. the signal is not emitted if the button is part of a buttonset
67   void toggled(bool pressed);
68 };
69 
70 //-----------------------------------------------------------------------------
71 /*! specialized button for sage area which enables to choose safe area size by
72  * context menu
73  */
74 
75 class TPanelTitleBarButtonForSafeArea final : public TPanelTitleBarButton {
76   Q_OBJECT
77 public:
TPanelTitleBarButtonForSafeArea(QWidget * parent,const QString & standardPixmapName)78   TPanelTitleBarButtonForSafeArea(QWidget *parent,
79                                   const QString &standardPixmapName)
80       : TPanelTitleBarButton(parent, standardPixmapName) {}
81   void getSafeAreaNameList(QList<QString> &nameList);
82 
83 protected:
84   void contextMenuEvent(QContextMenuEvent *event) override;
85   void mousePressEvent(QMouseEvent *event) override;
86 protected slots:
87   void onSetSafeArea();
88 };
89 
90 //-----------------------------------------------------------------------------
91 
92 //! a buttonset can group different TPanelTitleBarButton
93 class TPanelTitleBarButtonSet final : public QObject {
94   Q_OBJECT
95   std::vector<TPanelTitleBarButton *> m_buttons;
96 
97 public:
98   TPanelTitleBarButtonSet();
99   ~TPanelTitleBarButtonSet();
100 
101   void add(TPanelTitleBarButton *button);
102   void select(TPanelTitleBarButton *button);
103 
104 signals:
105   //! emitted when the current button changes. id is the button identifier
106   void selected(int id);
107 };
108 
109 //-----------------------------------------------------------------------------
110 
111 class TPanelTitleBar final : public QFrame {
112   Q_OBJECT
113 
114   bool m_closeButtonHighlighted;
115   std::vector<std::pair<QPoint, QWidget *>> m_buttons;
116 
117   QPixmap m_borderPm, m_activeBorderPm, m_floatBorderPm, m_floatActiveBorderPm;
118   QColor m_titleColor, m_activeTitleColor;
119 
120 public:
121   TPanelTitleBar(QWidget *parent                      = 0,
122                  TDockWidget::Orientation orientation = TDockWidget::vertical);
123 
sizeHint()124   QSize sizeHint() const override { return minimumSizeHint(); }
125   QSize minimumSizeHint() const override;
126 
127   // pos = widget position. n.b. if pos.x()<0 then origin is topright corner
128   void add(const QPoint &pos, QWidget *widget);
129 
getBorderPixmap()130   QPixmap getBorderPixmap() const { return m_borderPm; }
setBorderPixmap(const QPixmap & pixmap)131   void setBorderPixmap(const QPixmap &pixmap) { m_borderPm = pixmap; }
getActiveBorderPixmap()132   QPixmap getActiveBorderPixmap() const { return m_activeBorderPm; }
setActiveBorderPixmap(const QPixmap & pixmap)133   void setActiveBorderPixmap(const QPixmap &pixmap) {
134     m_activeBorderPm = pixmap;
135   }
getFloatBorderPixmap()136   QPixmap getFloatBorderPixmap() const { return m_floatBorderPm; }
setFloatBorderPixmap(const QPixmap & pixmap)137   void setFloatBorderPixmap(const QPixmap &pixmap) { m_floatBorderPm = pixmap; }
getFloatActiveBorderPixmap()138   QPixmap getFloatActiveBorderPixmap() const { return m_floatActiveBorderPm; }
setFloatActiveBorderPixmap(const QPixmap & pixmap)139   void setFloatActiveBorderPixmap(const QPixmap &pixmap) {
140     m_floatActiveBorderPm = pixmap;
141   }
getTitleColor()142   QColor getTitleColor() const { return m_titleColor; }
setTitleColor(const QColor & color)143   void setTitleColor(const QColor &color) { m_titleColor = color; }
getActiveTitleColor()144   QColor getActiveTitleColor() const { return m_activeTitleColor; }
setActiveTitleColor(const QColor & color)145   void setActiveTitleColor(const QColor &color) { m_activeTitleColor = color; }
146 
147 protected:
148   void resizeEvent(QResizeEvent *e) override;
149 
150   // To Disable the default context Menu
contextMenuEvent(QContextMenuEvent *)151   void contextMenuEvent(QContextMenuEvent *) override {}
152 
153   void paintEvent(QPaintEvent *event) override;
154   void mouseMoveEvent(QMouseEvent *event) override;
155   void mousePressEvent(QMouseEvent *event) override;
156   void mouseDoubleClickEvent(QMouseEvent *) override;
157 
158   Q_PROPERTY(QPixmap BorderPixmap READ getBorderPixmap WRITE setBorderPixmap);
159   Q_PROPERTY(QPixmap ActiveBorderPixmap READ getActiveBorderPixmap WRITE
160                  setActiveBorderPixmap);
161   Q_PROPERTY(QPixmap FloatBorderPixmap READ getFloatBorderPixmap WRITE
162                  setFloatBorderPixmap);
163   Q_PROPERTY(QPixmap FloatActiveBorderPixmap READ getFloatActiveBorderPixmap
164                  WRITE setFloatActiveBorderPixmap);
165   Q_PROPERTY(QColor TitleColor READ getTitleColor WRITE setTitleColor);
166   Q_PROPERTY(QColor ActiveTitleColor READ getActiveTitleColor WRITE
167                  setActiveTitleColor);
168 
169 signals:
170 
171   void closeButtonPressed();
172   void doubleClick(QMouseEvent *me);
173 };
174 
175 //-----------------------------------------------------------------------------
176 
177 class TPanel : public TDockWidget {
178   Q_OBJECT
179 
180   QColor
181       m_bgcolor;  // overrides palette background color in paint event - Mac fix
182 
Q_PROPERTY(QColor BGColor READ getBGColor WRITE setBGColor)183   Q_PROPERTY(QColor BGColor READ getBGColor WRITE setBGColor)
184 
185   QColor getBGColor() const { return m_bgcolor; }
setBGColor(const QColor & color)186   void setBGColor(const QColor &color) { m_bgcolor = color; }
187 
188   std::string m_panelType;
189   bool m_isMaximizable;
190   bool m_isMaximized;
191   bool m_multipleInstancesAllowed;
192 
193   TPanelTitleBar *m_panelTitleBar;
194 
195   QList<TPanel *> m_hiddenDockWidgets;
196   QByteArray m_currentRoomOldState;
197 
198 public:
199   TPanel(QWidget *parent = 0, Qt::WindowFlags flags = 0,
200          TDockWidget::Orientation orientation = TDockWidget::vertical);
201   ~TPanel();
202 
setPanelType(const std::string & panelType)203   void setPanelType(const std::string &panelType) { m_panelType = panelType; }
getPanelType()204   std::string getPanelType() { return m_panelType; }
205 
setIsMaximizable(bool value)206   void setIsMaximizable(bool value) { m_isMaximizable = value; }
isMaximizable()207   bool isMaximizable() { return m_isMaximizable; }
208   // bool isMaximized() { return m_isMaximized; }
209   // void setMaximized(bool isMaximized, Room *room = 0);
210 
getHiddenDockWidget()211   QList<TPanel *> getHiddenDockWidget() const { return m_hiddenDockWidgets; }
getSavedOldState()212   QByteArray getSavedOldState() const { return m_currentRoomOldState; }
213 
214   // void setTitleBarWidget(TPanelTitleBar *newTitleBar);
215 
216   // si riferisce a istanze multiple dei pannelli floating; default = true
allowMultipleInstances(bool allowed)217   void allowMultipleInstances(bool allowed) {
218     m_multipleInstancesAllowed = allowed;
219   }
areMultipleInstancesAllowed()220   bool areMultipleInstancesAllowed() const {
221     return m_multipleInstancesAllowed;
222   }
223 
getTitleBar()224   TPanelTitleBar *getTitleBar() const { return m_panelTitleBar; }
225 
reset()226   virtual void reset(){};
227 
getViewType()228   virtual int getViewType() { return -1; };
setViewType(int viewType)229   virtual void setViewType(int viewType){};
230 
widgetInThisPanelIsFocused()231   virtual bool widgetInThisPanelIsFocused() {
232     // by default, chech if the panel content itself has focus
233     if (widget())
234       return widget()->hasFocus();
235     else
236       return false;
237   };
238 
239   virtual void restoreFloatingPanelState();
240 
241 protected:
242   void paintEvent(QPaintEvent *) override;
243   void enterEvent(QEvent *) override;
244   void leaveEvent(QEvent *) override;
245 
isActivatableOnEnter()246   virtual bool isActivatableOnEnter() { return false; }
247 
248 protected slots:
249 
250   void onCloseButtonPressed();
widgetFocusOnEnter()251   virtual void widgetFocusOnEnter() {
252     // by default, focus the panel content
253     if (widget()) widget()->setFocus();
254   };
widgetClearFocusOnLeave()255   virtual void widgetClearFocusOnLeave() {
256     if (widget()) widget()->clearFocus();
257   };
258 
259 signals:
260 
261   void doubleClick(QMouseEvent *me);
262   void closeButtonPressed();
263 };
264 
265 //-----------------------------------------------------------------------------
266 
267 class TPanelFactory {
268   QString m_panelType;
269   static QMap<QString, TPanelFactory *> &tableInstance();
270 
271 public:
272   TPanelFactory(QString panelType);
273   ~TPanelFactory();
274 
getPanelType()275   QString getPanelType() const { return m_panelType; }
276 
277   virtual void initialize(TPanel *panel) = 0;
278   virtual TPanel *createPanel(QWidget *parent);
279   static TPanel *createPanel(QWidget *parent, QString panelType);
280 };
281 
282 //-----------------------------------------------------------------------------
283 
284 #endif  // PANE_H
285