1 #pragma once
2 
3 #ifndef XSHNOTEVIEWER_H
4 #define XSHNOTEVIEWER_H
5 
6 #include <memory>
7 
8 #include "toonz/txsheet.h"
9 #include "toonzqt/dvdialog.h"
10 #include "toonzqt/dvtextedit.h"
11 #include "toonzqt/colorfield.h"
12 
13 #include <QFrame>
14 #include <QScrollArea>
15 
16 #include "layerheaderpanel.h"
17 
18 //-----------------------------------------------------------------------------
19 
20 // forward declaration
21 class XsheetViewer;
22 class QTextEdit;
23 class TColorStyle;
24 class QToolButton;
25 class QPushButton;
26 class QComboBox;
27 class Orientation;
28 
29 //-----------------------------------------------------------------------------
30 
31 namespace XsheetGUI {
32 
33 //=============================================================================
34 // NotePopup
35 //-----------------------------------------------------------------------------
36 
37 class NotePopup final : public DVGui::Dialog {
38   Q_OBJECT
39   XsheetViewer *m_viewer;
40   int m_noteIndex;
41   DVGui::DvTextEdit *m_textEditor;
42   int m_currentColorIndex;
43   QList<DVGui::ColorField *> m_colorFields;
44   //! Used to avoid double click in discard or post button.
45   bool m_isOneButtonPressed;
46 
47 public:
48   NotePopup(XsheetViewer *viewer, int noteIndex);
~NotePopup()49   ~NotePopup() {}
50 
51   void setCurrentNoteIndex(int index);
52 
53   void update();
54 
55 protected:
56   TXshNoteSet *getNotes();
57   QList<TPixel32> getColors();
58 
59   void onColorFieldEditingChanged(const TPixel32 &color, bool isEditing,
60                                   int index);
61 
62   DVGui::ColorField *createColorField(int index);
63   void updateColorField();
64 
65   void showEvent(QShowEvent *) override;
66   void hideEvent(QHideEvent *) override;
67 
68 protected slots:
69   void onColor1Switched(const TPixel32 &, bool isDragging);
70   void onColor2Switched(const TPixel32 &, bool isDragging);
71   void onColor3Switched(const TPixel32 &, bool isDragging);
72   void onColor4Switched(const TPixel32 &, bool isDragging);
73   void onColor5Switched(const TPixel32 &, bool isDragging);
74   void onColor6Switched(const TPixel32 &, bool isDragging);
75   void onColor7Switched(const TPixel32 &, bool isDragging);
76 
77   void onColorChanged(const TPixel32 &, bool isDragging);
78   void onNoteAdded();
79   void onNoteDiscarded();
80   void onTextEditFocusIn();
81 
82   void onXsheetSwitched();
83 };
84 
85 //=============================================================================
86 // NoteWidget
87 //-----------------------------------------------------------------------------
88 
89 class NoteWidget final : public QWidget {
90   Q_OBJECT
91   XsheetViewer *m_viewer;
92   int m_noteIndex;
93   std::unique_ptr<NotePopup> m_noteEditor;
94   bool m_isHovered;
95 
96 public:
97   NoteWidget(XsheetViewer *parent = 0, int noteIndex = -1);
98 
getNoteIndex()99   int getNoteIndex() const { return m_noteIndex; }
setNoteIndex(int index)100   void setNoteIndex(int index) {
101     m_noteIndex = index;
102     if (m_noteEditor) m_noteEditor->setCurrentNoteIndex(index);
103   }
104 
105   void paint(QPainter *painter, QPoint pos = QPoint(), bool isCurrent = false);
106 
107   void openNotePopup();
108 
109 protected:
110   void paintEvent(QPaintEvent *event) override;
111 };
112 
113 //=============================================================================
114 // NoteArea
115 //-----------------------------------------------------------------------------
116 
117 class NoteArea final : public QFrame {
118   Q_OBJECT
119 
120   std::unique_ptr<NotePopup> m_newNotePopup;  // Popup used to create new note
121   XsheetViewer *m_viewer;
122 
123   QPushButton *m_flipOrientationButton;
124 
125   QToolButton *m_noteButton;
126   QToolButton *m_nextNoteButton;
127   QToolButton *m_precNoteButton;
128 
129   QComboBox *m_frameDisplayStyleCombo;
130 
131   LayerHeaderPanel *m_layerHeaderPanel;
132 
133 public:
134 #if QT_VERSION >= 0x050500
135   NoteArea(XsheetViewer *parent = 0, Qt::WindowFlags flags = 0);
136 #else
137   NoteArea(XsheetViewer *parent = 0, Qt::WFlags flags = 0);
138 #endif
139 
updatePopup()140   void updatePopup() { m_newNotePopup->update(); }
141   void updateButtons();
142 
143 protected slots:
144   void flipOrientation();
145   void toggleNewNote();
146   void nextNote();
147   void precNote();
148 
149   void onFrameDisplayStyleChanged(int id);
150   void onXsheetOrientationChanged(const Orientation *orientation);
151 
152 protected:
153   void removeLayout();
154   void createLayout();
155 };
156 
157 }  // namespace XsheetGUI;
158 
159 #endif  // XSHNOTEVIEWER_H
160