1 
2 
3 #include "xshnoteviewer.h"
4 
5 // Tnz6 includes
6 #include "xsheetviewer.h"
7 #include "tapp.h"
8 
9 // TnzQt includes
10 #include "toonzqt/gutil.h"
11 
12 // TnzLib includes
13 #include "toonz/toonzscene.h"
14 #include "toonz/txshnoteset.h"
15 #include "toonz/sceneproperties.h"
16 #include "toonz/txsheethandle.h"
17 #include "orientation.h"
18 
19 // Qt includes
20 #include <QVariant>
21 #include <QPainter>
22 #include <QPushButton>
23 #include <QToolButton>
24 #include <QMainWindow>
25 #include <QButtonGroup>
26 #include <QComboBox>
27 
28 namespace {
29 
computeBackgroundStyleSheetString(QColor color)30 QString computeBackgroundStyleSheetString(QColor color) {
31   QVariant vR(color.red());
32   QVariant vG(color.green());
33   QVariant vB(color.blue());
34   QVariant vA(color.alpha());
35   return QString("#noteTextEdit { border-image: 0; background: rgbm(") +
36          vR.toString() + QString(",") + vG.toString() + QString(",") +
37          vB.toString() + QString(",") + vA.toString() + QString("); }");
38 }
39 }
40 
41 //=============================================================================
42 
43 namespace XsheetGUI {
44 
45 //=============================================================================
46 // NotePopup
47 //-----------------------------------------------------------------------------
48 
NotePopup(XsheetViewer * viewer,int noteIndex)49 NotePopup::NotePopup(XsheetViewer *viewer, int noteIndex)
50     : DVGui::Dialog(TApp::instance()->getMainWindow(), false, false,
51                     "NotePopup")
52     , m_viewer(viewer)
53     , m_noteIndex(noteIndex)
54     , m_currentColorIndex(0)
55     , m_isOneButtonPressed(false) {
56   setWindowTitle(tr("Memo"));
57   bool ret = true;
58 
59   setMinimumSize(330, 180);
60 
61   setTopMargin(0);
62 
63   beginVLayout();
64 
65   QGridLayout *layout = new QGridLayout(this);
66   layout->setMargin(1);
67   layout->setColumnStretch(7, 10);
68   layout->setColumnStretch(8, 10);
69   int row = 0;
70   int col = 0;
71 
72   QString text;
73   TPixel32 color;
74   int colorIndex = 0;
75   if (m_noteIndex < 0) {
76     text  = QString();
77     color = getColors().at(0);
78   } else {
79     text                = getNotes()->getNoteHtmlText(m_noteIndex);
80     m_currentColorIndex = getNotes()->getNoteColorIndex(m_noteIndex);
81     color               = getColors().at(m_currentColorIndex);
82   }
83 
84   m_textEditor = new DVGui::DvTextEdit(this);
85   m_textEditor->setObjectName("noteTextEdit");
86   m_textEditor->setHtml(text);
87   m_textEditor->setStyleSheet(computeBackgroundStyleSheetString(
88       QColor(color.r, color.g, color.b, color.m)));
89   layout->addWidget(m_textEditor, row, col, 1, 9);
90   layout->setRowStretch(row, 10);
91   ret = ret && connect(m_textEditor, SIGNAL(focusIn()), this,
92                        SLOT(onTextEditFocusIn()));
93   row++;
94 
95   int index                 = 0;
96   DVGui::ColorField *color1 = createColorField(index);
97   ret = ret && connect(color1, SIGNAL(editingChanged(const TPixel32 &, bool)),
98                        SLOT(onColor1Switched(const TPixel32 &, bool)));
99   layout->addWidget(color1, row, index, 1, 1);
100   m_colorFields.push_back(color1);
101   index++;
102   DVGui::ColorField *color2 = createColorField(index);
103   ret = ret && connect(color2, SIGNAL(editingChanged(const TPixel32 &, bool)),
104                        SLOT(onColor2Switched(const TPixel32 &, bool)));
105   layout->addWidget(color2, row, index, 1, 1);
106   m_colorFields.push_back(color2);
107   index++;
108   DVGui::ColorField *color3 = createColorField(index);
109   ret = ret && connect(color3, SIGNAL(editingChanged(const TPixel32 &, bool)),
110                        SLOT(onColor3Switched(const TPixel32 &, bool)));
111   layout->addWidget(color3, row, index, 1, 1);
112   m_colorFields.push_back(color3);
113   index++;
114   DVGui::ColorField *color4 = createColorField(index);
115   ret = ret && connect(color4, SIGNAL(editingChanged(const TPixel32 &, bool)),
116                        SLOT(onColor4Switched(const TPixel32 &, bool)));
117   layout->addWidget(color4, row, index, 1, 1);
118   m_colorFields.push_back(color4);
119   index++;
120   DVGui::ColorField *color5 = createColorField(index);
121   ret = ret && connect(color5, SIGNAL(editingChanged(const TPixel32 &, bool)),
122                        SLOT(onColor5Switched(const TPixel32 &, bool)));
123   layout->addWidget(color5, row, index, 1, 1);
124   m_colorFields.push_back(color5);
125   index++;
126   DVGui::ColorField *color6 = createColorField(index);
127   ret = ret && connect(color6, SIGNAL(editingChanged(const TPixel32 &, bool)),
128                        SLOT(onColor6Switched(const TPixel32 &, bool)));
129   layout->addWidget(color6, row, index, 1, 1);
130   m_colorFields.push_back(color6);
131   index++;
132   DVGui::ColorField *color7 = createColorField(index);
133   ret = ret && connect(color7, SIGNAL(editingChanged(const TPixel32 &, bool)),
134                        SLOT(onColor7Switched(const TPixel32 &, bool)));
135   layout->addWidget(color7, row, index, 1, 1);
136   m_colorFields.push_back(color7);
137 
138   col = index;
139   col++;
140 
141   QPushButton *addNoteButton = new QPushButton(tr("Post"));
142   addNoteButton->setMinimumSize(50, 20);
143   addNoteButton->setObjectName("PushButton_NoPadding");
144   ret = ret &&
145         connect(addNoteButton, SIGNAL(pressed()), this, SLOT(onNoteAdded()));
146   layout->addWidget(addNoteButton, row, col, 1, 1);
147   col++;
148   QPushButton *discardNoteButton = new QPushButton(tr("Discard"));
149   discardNoteButton->setMinimumSize(50, 20);
150   discardNoteButton->setObjectName("PushButton_NoPadding");
151   ret = ret && connect(discardNoteButton, SIGNAL(pressed()), this,
152                        SLOT(onNoteDiscarded()));
153   layout->addWidget(discardNoteButton, row, col, 1, 1);
154   addLayout(layout, false);
155 
156   endVLayout();
157 
158   // bad patch to bug:
159   // when you write  some text to an existing note, appending it, the resulting
160   // html is corrupted and nothing is shown. setting a font (for example) fix
161   // it!
162   m_textEditor->changeFont(QFont("Arial", 10));
163 
164   assert(ret);
165 }
166 
167 //-----------------------------------------------------------------------------
168 
setCurrentNoteIndex(int index)169 void NotePopup::setCurrentNoteIndex(int index) { m_noteIndex = index; }
170 
171 //-----------------------------------------------------------------------------
172 
update()173 void NotePopup::update() {
174   TPixel32 color = getColors().at(m_currentColorIndex);
175   m_textEditor->setStyleSheet(computeBackgroundStyleSheetString(
176       QColor(color.r, color.g, color.b, color.m)));
177   DVGui::Dialog::update();
178 }
179 
180 //-----------------------------------------------------------------------------
181 
createColorField(int index)182 DVGui::ColorField *NotePopup::createColorField(int index) {
183   TPixel32 color                = getColors().at(index);
184   DVGui::ColorField *colorField = new DVGui::ColorField(this, true, color, 20);
185   colorField->hideChannelsFields(true);
186   bool ret = connect(colorField, SIGNAL(colorChanged(const TPixel32 &, bool)),
187                      SLOT(onColorChanged(const TPixel32 &, bool)));
188   assert(ret);
189   return colorField;
190 }
191 
192 //-----------------------------------------------------------------------------
193 
updateColorField()194 void NotePopup::updateColorField() {
195   int i;
196   for (i = 0; i < m_colorFields.size(); i++) {
197     DVGui::ColorField *colorField = m_colorFields.at(i);
198     colorField->setEditingChangeNotified(false);
199     if (m_currentColorIndex == i)
200       colorField->setIsEditing(true);
201     else
202       colorField->setIsEditing(false);
203     colorField->setEditingChangeNotified(true);
204   }
205 }
206 
207 //-----------------------------------------------------------------------------
208 
showEvent(QShowEvent *)209 void NotePopup::showEvent(QShowEvent *) {
210   if (m_noteIndex == -1) m_textEditor->clear();
211   m_isOneButtonPressed = false;
212   updateColorField();
213   onXsheetSwitched();
214   TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
215   bool ret = connect(xsheetHandle, SIGNAL(xsheetSwitched()), this,
216                      SLOT(onXsheetSwitched()));
217   assert(ret);
218 }
219 
220 //-----------------------------------------------------------------------------
221 
hideEvent(QHideEvent *)222 void NotePopup::hideEvent(QHideEvent *) {
223   TXsheetHandle *xsheetHandle = TApp::instance()->getCurrentXsheet();
224   disconnect(xsheetHandle, SIGNAL(xsheetSwitched()), this,
225              SLOT(onXsheetSwitched()));
226 }
227 
228 //-----------------------------------------------------------------------------
229 
onColorChanged(const TPixel32 & color,bool isDragging)230 void NotePopup::onColorChanged(const TPixel32 &color, bool isDragging) {
231   if (!isDragging)
232     m_textEditor->setStyleSheet(computeBackgroundStyleSheetString(
233         QColor(color.r, color.g, color.b, color.m)));
234 
235   TSceneProperties *sp = m_viewer->getXsheet()->getScene()->getProperties();
236   sp->setNoteColor(color, m_currentColorIndex);
237   m_viewer->updateNoteWidgets();
238 }
239 
240 //-----------------------------------------------------------------------------
241 
getNotes()242 TXshNoteSet *NotePopup::getNotes() { return m_viewer->getXsheet()->getNotes(); }
243 
244 //-----------------------------------------------------------------------------
245 
getColors()246 QList<TPixel32> NotePopup::getColors() {
247   return m_viewer->getXsheet()->getScene()->getProperties()->getNoteColors();
248 }
249 
250 //-----------------------------------------------------------------------------
251 
onColorFieldEditingChanged(const TPixel32 & color,bool isEditing,int index)252 void NotePopup::onColorFieldEditingChanged(const TPixel32 &color,
253                                            bool isEditing, int index) {
254   if (!isEditing) return;
255   m_textEditor->setStyleSheet(computeBackgroundStyleSheetString(
256       QColor(color.r, color.g, color.b, color.m)));
257   DVGui::ColorField *colorField = m_colorFields.at(m_currentColorIndex);
258   colorField->setEditingChangeNotified(false);
259   colorField->setIsEditing(false);
260   colorField->setEditingChangeNotified(true);
261   m_currentColorIndex = index;
262 }
263 
264 //-----------------------------------------------------------------------------
265 
onColor1Switched(const TPixel32 & color,bool isEditing)266 void NotePopup::onColor1Switched(const TPixel32 &color, bool isEditing) {
267   onColorFieldEditingChanged(color, isEditing, 0);
268 }
269 
270 //-----------------------------------------------------------------------------
271 
onColor2Switched(const TPixel32 & color,bool isEditing)272 void NotePopup::onColor2Switched(const TPixel32 &color, bool isEditing) {
273   onColorFieldEditingChanged(color, isEditing, 1);
274 }
275 
276 //-----------------------------------------------------------------------------
277 
onColor3Switched(const TPixel32 & color,bool isEditing)278 void NotePopup::onColor3Switched(const TPixel32 &color, bool isEditing) {
279   onColorFieldEditingChanged(color, isEditing, 2);
280 }
281 
282 //-----------------------------------------------------------------------------
283 
onColor4Switched(const TPixel32 & color,bool isEditing)284 void NotePopup::onColor4Switched(const TPixel32 &color, bool isEditing) {
285   onColorFieldEditingChanged(color, isEditing, 3);
286 }
287 
288 //-----------------------------------------------------------------------------
289 
onColor5Switched(const TPixel32 & color,bool isEditing)290 void NotePopup::onColor5Switched(const TPixel32 &color, bool isEditing) {
291   onColorFieldEditingChanged(color, isEditing, 4);
292 }
293 
294 //-----------------------------------------------------------------------------
295 
onColor6Switched(const TPixel32 & color,bool isEditing)296 void NotePopup::onColor6Switched(const TPixel32 &color, bool isEditing) {
297   onColorFieldEditingChanged(color, isEditing, 5);
298 }
299 
300 //-----------------------------------------------------------------------------
301 
onColor7Switched(const TPixel32 & color,bool isEditing)302 void NotePopup::onColor7Switched(const TPixel32 &color, bool isEditing) {
303   onColorFieldEditingChanged(color, isEditing, 6);
304 }
305 
306 //-----------------------------------------------------------------------------
307 
onNoteAdded()308 void NotePopup::onNoteAdded() {
309   if (m_isOneButtonPressed) return;
310   m_isOneButtonPressed = true;
311   int newNoteIndex     = m_noteIndex;
312   if (m_noteIndex < 0) {
313     TXshNoteSet::Note note;
314     note.m_col   = m_viewer->getCurrentColumn();
315     note.m_row   = m_viewer->getCurrentRow();
316     newNoteIndex = getNotes()->addNote(note);
317   }
318 
319   getNotes()->setNoteHtmlText(newNoteIndex, m_textEditor->toHtml());
320   getNotes()->setNoteColorIndex(newNoteIndex, m_currentColorIndex);
321 
322   m_viewer->setCurrentNoteIndex(newNoteIndex);
323   m_viewer->updateCells();
324 
325   close();
326 }
327 
328 //-----------------------------------------------------------------------------
329 
onNoteDiscarded()330 void NotePopup::onNoteDiscarded() {
331   if (m_isOneButtonPressed) return;
332   m_isOneButtonPressed = true;
333   if (m_noteIndex < 0) {
334     hide();
335     return;
336   }
337   getNotes()->removeNote(m_noteIndex);
338   hide();
339 
340   m_viewer->discardNoteWidget();
341 }
342 
343 //-----------------------------------------------------------------------------
344 
onTextEditFocusIn()345 void NotePopup::onTextEditFocusIn() {
346   m_viewer->setCurrentNoteIndex(m_noteIndex);
347 }
348 
349 //-----------------------------------------------------------------------------
350 
onXsheetSwitched()351 void NotePopup::onXsheetSwitched() {
352   TXshNoteSet *notes = getNotes();
353   if (notes->getCount() == 0 || m_noteIndex == -1) return;
354   m_currentColorIndex = getNotes()->getNoteColorIndex(m_noteIndex);
355   TPixel32 color      = getColors().at(m_currentColorIndex);
356   m_textEditor->setStyleSheet(computeBackgroundStyleSheetString(
357       QColor(color.r, color.g, color.b, color.m)));
358   m_textEditor->setHtml(notes->getNoteHtmlText(m_noteIndex));
359 }
360 
361 //=============================================================================
362 // NoteWidget
363 //-----------------------------------------------------------------------------
364 
NoteWidget(XsheetViewer * parent,int noteIndex)365 NoteWidget::NoteWidget(XsheetViewer *parent, int noteIndex)
366     : QWidget(parent)
367     , m_viewer(parent)
368     , m_noteIndex(noteIndex)
369     , m_isHovered(false) {
370   int width = (m_noteIndex < 0) ? 40 : NoteWidth;
371   setFixedSize(width, NoteHeight);
372 }
373 
374 //-----------------------------------------------------------------------------
375 
paint(QPainter * painter,QPoint pos,bool isCurrent)376 void NoteWidget::paint(QPainter *painter, QPoint pos, bool isCurrent) {
377   painter->translate(pos);
378   QRect rect = m_viewer->orientation()->rect(PredefinedRect::NOTE_ICON);
379 
380   TXshNoteSet *notes   = m_viewer->getXsheet()->getNotes();
381   TSceneProperties *sp = m_viewer->getXsheet()->getScene()->getProperties();
382   TPixel32 c;
383   if (m_noteIndex < 0)
384     c.m = 0;
385   else
386     c = sp->getNoteColor(notes->getNoteColorIndex(m_noteIndex));
387   QColor color(c.r, c.g, c.b, c.m);
388   QPoint topLeft = rect.topLeft();
389   int d          = 8;
390   if (isCurrent)
391     painter->setPen(Qt::white);
392   else
393     painter->setPen(Qt::black);
394   QPainterPath rectPath(topLeft + QPoint(d, 0));
395   rectPath.lineTo(rect.topRight());
396   rectPath.lineTo(rect.bottomRight());
397   rectPath.lineTo(rect.bottomLeft());
398   rectPath.lineTo(topLeft + QPoint(0, d));
399   rectPath.lineTo(topLeft + QPoint(d, 0));
400   painter->fillPath(rectPath, QBrush(color));
401   painter->drawPath(rectPath);
402 
403   color = QColor(tcrop(c.r - 20, 0, 255), tcrop(c.g - 20, 0, 255),
404                  tcrop(c.b - 20, 0, 255), tcrop(c.m - 20, 0, 255));
405   QPainterPath path(topLeft + QPoint(d, 0));
406   path.lineTo(topLeft + QPoint(d, d));
407   path.lineTo(topLeft + QPoint(0, d));
408   path.lineTo(topLeft + QPoint(d, 0));
409   painter->fillPath(path, QBrush(color));
410   painter->drawPath(path);
411 
412   painter->setPen(Qt::black);
413   if (m_noteIndex >= 0) {
414     QTextDocument document;
415     document.setHtml(notes->getNoteHtmlText(m_noteIndex));
416     painter->translate(d, -1);
417     document.drawContents(painter, rect.adjusted(0, 0, -2 * d, 0));
418     painter->translate(-d, 1);
419   } else
420     painter->drawText(rect.adjusted(d + 1, 1, -d, 0),
421                       Qt::AlignCenter | Qt::AlignTop, QString("+"));
422 
423   painter->translate(-pos);
424 }
425 
426 //-----------------------------------------------------------------------------
427 
openNotePopup()428 void NoteWidget::openNotePopup() {
429   if (!m_noteEditor) {
430     m_noteEditor.reset(new XsheetGUI::NotePopup(m_viewer, m_noteIndex));
431   }
432 
433   if (m_noteEditor->isVisible()) {
434     m_noteEditor->activateWindow();
435   } else {
436     m_noteEditor->show();
437   }
438 }
439 
440 //-----------------------------------------------------------------------------
441 
paintEvent(QPaintEvent * event)442 void NoteWidget::paintEvent(QPaintEvent *event) {
443   QPainter p(this);
444   paint(&p);
445 }
446 
447 //=============================================================================
448 // NoteArea
449 //-----------------------------------------------------------------------------
450 
451 #if QT_VERSION >= 0x050500
NoteArea(XsheetViewer * parent,Qt::WindowFlags flags)452 NoteArea::NoteArea(XsheetViewer *parent, Qt::WindowFlags flags)
453 #else
454 NoteArea::NoteArea(XsheetViewer *parent, Qt::WFlags flags)
455 #endif
456     : QFrame(parent)
457     , m_viewer(parent)
458     , m_flipOrientationButton(nullptr)
459     , m_noteButton(nullptr)
460     , m_precNoteButton(nullptr)
461     , m_nextNoteButton(nullptr)
462     , m_frameDisplayStyleCombo(nullptr)
463     , m_layerHeaderPanel(nullptr) {
464 
465   setFrameStyle(QFrame::StyledPanel);
466   setObjectName("cornerWidget");
467 
468   m_flipOrientationButton  = new QPushButton(this);
469   m_noteButton             = new QToolButton(this);
470   m_precNoteButton         = new QToolButton(this);
471   m_nextNoteButton         = new QToolButton(this);
472   m_frameDisplayStyleCombo = new QComboBox(this);
473   m_layerHeaderPanel       = new LayerHeaderPanel(m_viewer, this);
474 
475   //-----
476 
477   m_flipOrientationButton->setObjectName("flipOrientationButton");
478   m_flipOrientationButton->setFocusPolicy(Qt::FocusPolicy::NoFocus);
479   m_flipOrientationButton->setFixedSize(QSize(70, 23));
480   m_flipOrientationButton->setIconSize(QSize(20, 20));
481   m_flipOrientationButton->setIcon(createQIcon("toggle_xsheet_orientation"));
482   m_flipOrientationButton->setToolTip(tr("Toggle Xsheet/Timeline"));
483 
484   m_noteButton->setObjectName("ToolbarToolButton");
485   m_noteButton->setFixedSize(34, 25);
486   m_noteButton->setIconSize(QSize(30, 20));
487   m_noteButton->setIcon(createQIcon("newmemo"));
488   m_noteButton->setToolTip(tr("Add New Memo"));
489 
490   m_precNoteButton->setObjectName("ToolbarToolButton");
491   m_precNoteButton->setFixedSize(17, 25);
492   m_precNoteButton->setIconSize(QSize(17, 17));
493   m_precNoteButton->setIcon(createQIcon("prevkey"));
494   m_precNoteButton->setToolTip(tr("Previous Memo"));
495 
496   m_nextNoteButton->setObjectName("ToolbarToolButton");
497   m_nextNoteButton->setFixedSize(17, 25);
498   m_nextNoteButton->setIconSize(QSize(17, 17));
499   m_nextNoteButton->setIcon(createQIcon("nextkey"));
500   m_nextNoteButton->setToolTip(tr("Next Memo"));
501 
502   QStringList frameDisplayStyles;
503   frameDisplayStyles << tr("Frame") << tr("Sec Frame") << tr("6sec Sheet")
504                      << tr("3sec Sheet");
505   m_frameDisplayStyleCombo->addItems(frameDisplayStyles);
506   m_frameDisplayStyleCombo->setCurrentIndex(
507       (int)m_viewer->getFrameDisplayStyle());
508 
509   // layout
510   createLayout();
511 
512   // signal-slot connections
513   bool ret = true;
514   ret      = ret && connect(m_flipOrientationButton, SIGNAL(clicked()),
515                        SLOT(flipOrientation()));
516 
517   ret = ret && connect(m_noteButton, SIGNAL(clicked()), SLOT(toggleNewNote()));
518   ret = ret &&
519         connect(m_precNoteButton, SIGNAL(clicked()), this, SLOT(precNote()));
520   ret = ret &&
521         connect(m_nextNoteButton, SIGNAL(clicked()), this, SLOT(nextNote()));
522 
523   ret =
524       ret && connect(m_frameDisplayStyleCombo, SIGNAL(currentIndexChanged(int)),
525                      this, SLOT(onFrameDisplayStyleChanged(int)));
526 
527   ret = ret && connect(m_viewer, &XsheetViewer::orientationChanged, this,
528                        &NoteArea::onXsheetOrientationChanged);
529 
530   updateButtons();
531 
532   assert(ret);
533 }
534 
535 //-----------------------------------------------------------------------------
536 
removeLayout()537 void NoteArea::removeLayout() {
538   QLayout *currentLayout = layout();
539   if (!currentLayout) return;
540 
541   currentLayout->removeWidget(m_flipOrientationButton);
542   currentLayout->removeWidget(m_noteButton);
543   currentLayout->removeWidget(m_precNoteButton);
544   currentLayout->removeWidget(m_nextNoteButton);
545   currentLayout->removeWidget(m_frameDisplayStyleCombo);
546   currentLayout->removeWidget(m_layerHeaderPanel);
547   delete currentLayout;
548 }
549 
createLayout()550 void NoteArea::createLayout() {
551   const Orientation *o = m_viewer->orientation();
552   QRect rect           = o->rect(PredefinedRect::NOTE_AREA);
553 
554   setFixedSize(rect.size());
555 
556   // has two elements: main layout and header panel
557   QVBoxLayout *panelLayout = new QVBoxLayout();
558   panelLayout->setMargin(1);
559   panelLayout->setSpacing(0);
560   {
561     QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::Direction(
562         o->dimension(PredefinedDimension::QBOXLAYOUT_DIRECTION)));
563     Qt::AlignmentFlag centerAlign =
564         Qt::AlignmentFlag(o->dimension(PredefinedDimension::CENTER_ALIGN));
565     mainLayout->setMargin(1);
566     mainLayout->setSpacing(0);
567     {
568       mainLayout->addWidget(m_flipOrientationButton, 0, centerAlign);
569 
570       mainLayout->addStretch(1);
571 
572       QHBoxLayout *buttonsLayout = new QHBoxLayout();
573       buttonsLayout->setMargin(0);
574       buttonsLayout->setSpacing(0);
575       {
576         buttonsLayout->addWidget(m_precNoteButton, 0);
577         buttonsLayout->addWidget(m_noteButton, 0, centerAlign);
578         buttonsLayout->addWidget(m_nextNoteButton, 0);
579       }
580       mainLayout->addLayout(buttonsLayout, 0);
581 
582       mainLayout->addStretch(1);
583 
584       mainLayout->addWidget(m_frameDisplayStyleCombo, 0);
585     }
586     panelLayout->addLayout(mainLayout);
587 
588     panelLayout->addWidget(m_layerHeaderPanel);
589   }
590   setLayout(panelLayout);
591 
592   m_layerHeaderPanel->showOrHide(o);
593 }
594 
595 //-----------------------------------------------------------------------------
596 
updateButtons()597 void NoteArea::updateButtons() {
598   TXshNoteSet *notes = m_viewer->getXsheet()->getNotes();
599 
600   int count = notes->getCount();
601   m_nextNoteButton->setEnabled(false);
602   m_precNoteButton->setEnabled(false);
603   if (count == 0) return;
604   int currentNoteIndex = m_viewer->getCurrentNoteIndex();
605   if (currentNoteIndex == -1 || count == 1)
606     m_nextNoteButton->setEnabled(true);
607   else {
608     if (count > currentNoteIndex + 1) m_nextNoteButton->setEnabled(true);
609     if (currentNoteIndex > 0) m_precNoteButton->setEnabled(true);
610   }
611 }
612 
613 //-----------------------------------------------------------------------------
614 
flipOrientation()615 void NoteArea::flipOrientation() { m_viewer->flipOrientation(); }
616 
onXsheetOrientationChanged(const Orientation * newOrientation)617 void NoteArea::onXsheetOrientationChanged(const Orientation *newOrientation) {
618   //  m_flipOrientationButton->setText(newOrientation->caption());
619 
620   m_flipOrientationButton->setIcon(createQIcon("toggle_xsheet_orientation"));
621   m_flipOrientationButton->setIconSize(QSize(20, 20));
622 
623   removeLayout();
624   createLayout();
625 }
626 
627 //-----------------------------------------------------------------------------
628 
toggleNewNote()629 void NoteArea::toggleNewNote() {
630   if (!m_newNotePopup)
631     m_newNotePopup.reset(new XsheetGUI::NotePopup(m_viewer, -1));
632 
633   if (m_newNotePopup->isVisible()) {
634     m_newNotePopup->activateWindow();
635   } else {
636     m_newNotePopup->show();
637   }
638 }
639 
640 //-----------------------------------------------------------------------------
641 
nextNote()642 void NoteArea::nextNote() {
643   int currentNoteIndex = m_viewer->getCurrentNoteIndex();
644   TXshNoteSet *notes   = m_viewer->getXsheet()->getNotes();
645   // Se ho una sola nota la rendo corrente e la visualizzo
646   if (notes->getCount() == 1) {
647     m_viewer->setCurrentNoteIndex(0);
648     return;
649   }
650 
651   m_viewer->setCurrentNoteIndex(++currentNoteIndex);
652 }
653 
654 //-----------------------------------------------------------------------------
655 
precNote()656 void NoteArea::precNote() {
657   int currentNoteIndex = m_viewer->getCurrentNoteIndex();
658   m_viewer->setCurrentNoteIndex(--currentNoteIndex);
659 }
660 
661 //-----------------------------------------------------------------------------
662 
onFrameDisplayStyleChanged(int id)663 void NoteArea::onFrameDisplayStyleChanged(int id) {
664   m_viewer->setFrameDisplayStyle((XsheetViewer::FrameDisplayStyle)id);
665   m_viewer->updateRows();
666 }
667 
668 //-----------------------------------------------------------------------------
669 
670 }  // namespace XsheetGUI;
671