Skip to content

Commit 726b1d9

Browse files
committed
new style button optional
1 parent 487b061 commit 726b1d9

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

toonz/sources/include/toonzqt/paletteviewer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ protected slots:
166166
void setIsLocked(bool lock);
167167

168168
void onSwitchToPage(int pageIndex);
169+
void onShowNewStyleButtonToggled();
169170
};
170171

171172
#endif // PALETTEVIEWER_H

toonz/sources/toonzqt/paletteviewer.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// TnzCore includes
2626
#include "tconvert.h"
2727
#include "tsystem.h"
28+
#include "tenv.h"
2829

2930
// Qt includes
3031
#include <QVBoxLayout>
@@ -38,6 +39,7 @@
3839
#include <QLabel>
3940
#include <QDrag>
4041

42+
TEnv::IntVar ShowNewStyleButton("ShowNewStyleButton", 1);
4143
using namespace PaletteViewerGUI;
4244

4345
//=============================================================================
@@ -401,6 +403,13 @@ void PaletteViewer::createPaletteToolBar() {
401403
addNameDisplayAction(tr("StudioPalette Name"), PageViewer::Original);
402404
addNameDisplayAction(tr("Both Names"), PageViewer::StyleAndOriginal);
403405

406+
viewMode->addSeparator();
407+
QString str = (ShowNewStyleButton) ? tr("Hide New Style Button")
408+
: tr("Show New Style Button");
409+
QAction *showNewStyleBtn = viewMode->addAction(str);
410+
connect(showNewStyleBtn, SIGNAL(triggered()), this,
411+
SLOT(onShowNewStyleButtonToggled()));
412+
404413
viewModeButton->setMenu(viewMode);
405414

406415
// Attenzione: avendo invertito la direzione devo aggiungere gli oggetti al
@@ -1156,3 +1165,17 @@ void PaletteViewer::setIsLocked(bool lock) {
11561165
void PaletteViewer::onSwitchToPage(int pageIndex) {
11571166
m_pagesBar->setCurrentIndex(pageIndex);
11581167
}
1168+
1169+
//-----------------------------------------------------------------------------
1170+
1171+
void PaletteViewer::onShowNewStyleButtonToggled() {
1172+
ShowNewStyleButton = (ShowNewStyleButton == 1) ? 0 : 1;
1173+
QAction *act = dynamic_cast<QAction *>(sender());
1174+
if (act) {
1175+
QString str = (ShowNewStyleButton) ? tr("Hide New Style Button")
1176+
: tr("Show New Style Button");
1177+
act->setText(str);
1178+
}
1179+
m_pageViewer->computeSize();
1180+
m_pageViewer->update();
1181+
}

toonz/sources/toonzqt/paletteviewergui.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
// enable to set font size for style name separately from other texts
4141
TEnv::IntVar EnvSoftwareCurrentFontSize_StyleName(
4242
"SoftwareCurrentFontSize_StyleName", 11);
43+
extern TEnv::IntVar ShowNewStyleButton;
4344

4445
using namespace PaletteViewerGUI;
4546
using namespace DVGui;
@@ -230,6 +231,7 @@ int PageViewer::getCurrentStyleIndex() const {
230231
/*! Set current page to \b page and update view.
231232
*/
232233
void PageViewer::setPage(TPalette::Page *page) {
234+
if (m_page == page) return;
233235
m_page = page;
234236
computeSize();
235237
update();
@@ -556,20 +558,19 @@ void PageViewer::drawToggleLink(QPainter &p, QRect &chipRect,
556558

557559
//-----------------------------------------------------------------------------
558560
/*! Draw the chip name \b name inside rectangle \b chipRect using painter \b p.
559-
* If the name is too wide to fit on the chip, use left align - to show the
560-
* start of the name. Otherwise, use center align.
561-
*/
561+
* If the name is too wide to fit on the chip, use left align - to show the
562+
* start of the name. Otherwise, use center align.
563+
*/
562564
static void drawChipName(QPainter &p, const QRect &chipRect,
563-
const std::wstring &name) {
565+
const std::wstring &name) {
564566
const QString nameQString = QString::fromStdWString(name);
565567
QRect textRect = p.boundingRect(chipRect, Qt::AlignCenter, nameQString);
566568

567569
if (chipRect.width() < textRect.width()) {
568570
// align left if the name is too wide to fit on the chip
569-
p.drawText(chipRect.adjusted(4, 0, -4, 0),
570-
Qt::AlignLeft | Qt::AlignVCenter, nameQString);
571-
}
572-
else {
571+
p.drawText(chipRect.adjusted(4, 0, -4, 0), Qt::AlignLeft | Qt::AlignVCenter,
572+
nameQString);
573+
} else {
573574
// otherwise align by center
574575
p.drawText(chipRect, Qt::AlignCenter, nameQString);
575576
}
@@ -580,6 +581,7 @@ static void drawChipName(QPainter &p, const QRect &chipRect,
580581
*/
581582
void PageViewer::paintEvent(QPaintEvent *e) {
582583
QPainter p(this);
584+
QColor textColor = p.pen().color();
583585
if (m_chipPerRow == 0) {
584586
p.drawText(QPoint(5, 25), tr("- No Styles -"));
585587
return;
@@ -656,10 +658,11 @@ void PageViewer::paintEvent(QPaintEvent *e) {
656658
// toggle link
657659
drawToggleLink(p, chipRect, m_page->getStyle(i));
658660
}
659-
if (!m_page->getPalette()->isLocked()) {
661+
if (ShowNewStyleButton && !m_page->getPalette()->isLocked()) {
660662
int j = getChipCount();
661663
QRect rect = getItemRect(j);
662-
p.setPen(QColor(200, 200, 200));
664+
p.setPen(
665+
QColor(textColor.red(), textColor.green(), textColor.blue(), 128));
663666
// p.fillRect(rect, QBrush(QColor(0, 0, 0, 64)));
664667
// p.drawRect(rect);
665668
tmpFont.setPointSize(16);
@@ -671,7 +674,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {
671674
// revert font set
672675
p.setFont(preFont);
673676
p.setPen(Qt::black);
674-
}
677+
}
675678

676679
} else {
677680
int currentStyleIndex = getCurrentStyleIndex();
@@ -805,8 +808,7 @@ void PageViewer::paintEvent(QPaintEvent *e) {
805808
// display mode
806809
if (m_nameDisplayMode == Style) {
807810
drawChipName(p, chipRect, name);
808-
}
809-
else if (m_nameDisplayMode == Original) {
811+
} else if (m_nameDisplayMode == Original) {
810812
if (origName != L"") {
811813
tmpFont.setItalic(true);
812814
p.setFont(tmpFont);
@@ -900,11 +902,12 @@ void PageViewer::paintEvent(QPaintEvent *e) {
900902
// draw link indicator
901903
drawToggleLink(p, chipRect, style);
902904
}
903-
// draw new style chip
904-
if (!m_page->getPalette()->isLocked()) {
905+
// draw new style chip
906+
if (ShowNewStyleButton && !m_page->getPalette()->isLocked()) {
905907
i = getChipCount();
906-
QRect chipRect = getItemRect(i).adjusted(0, -1, 0, -1);
907-
p.setPen(QColor(200, 200, 200));
908+
QRect chipRect = getItemRect(i).adjusted(4, 4, -5, -5);
909+
p.setPen(
910+
QColor(textColor.red(), textColor.green(), textColor.blue(), 128));
908911
p.fillRect(chipRect, QBrush(QColor(0, 0, 0, 64)));
909912
p.drawRect(chipRect);
910913
tmpFont.setPointSize(16);
@@ -993,13 +996,14 @@ void PageViewer::mousePressEvent(QMouseEvent *event) {
993996
}
994997
m_dragStartPosition = pos;
995998
if (indexInPage < 0 || indexInPage >= getChipCount()) {
996-
if (indexInPage == getChipCount() && !m_page->getPalette()->isLocked()) {
999+
if (ShowNewStyleButton && indexInPage == getChipCount() &&
1000+
!m_page->getPalette()->isLocked()) {
9971001
PaletteCmd::createStyle(getPaletteHandle(), getPage());
9981002
} else {
9991003
// the user clicked out of the color chips.wants to deselect everything
10001004
// (leaving the selection active, for a possible paste)
1001-
m_styleSelection->select(pageIndex);
1002-
m_styleSelection->makeCurrent();
1005+
m_styleSelection->select(pageIndex);
1006+
m_styleSelection->makeCurrent();
10031007
}
10041008

10051009
update();
@@ -1366,8 +1370,8 @@ bool PageViewer::event(QEvent *e) {
13661370
if (0 <= indexInPage && indexInPage < m_page->getStyleCount()) {
13671371
TColorStyle *style = m_page->getStyle(indexInPage);
13681372
if (style) {
1369-
int styleIndex = m_page->getStyleId(indexInPage);
1370-
toolTip = "#" + QString::number(styleIndex) + " " +
1373+
int styleIndex = m_page->getStyleId(indexInPage);
1374+
toolTip = "#" + QString::number(styleIndex) + " " +
13711375
QString::fromStdWString(style->getName());
13721376

13731377
int shortcutKey = m_page->getPalette()->getStyleShortcut(styleIndex);
@@ -1376,8 +1380,8 @@ bool PageViewer::event(QEvent *e) {
13761380
(wchar_t)shortcutKey + L")");
13771381
}
13781382
}
1379-
if (indexInPage == m_page->getStyleCount()) {
1380-
toolTip = tr("New Style");
1383+
if (ShowNewStyleButton && indexInPage == m_page->getStyleCount()) {
1384+
toolTip = tr("New Style");
13811385
}
13821386
if (toolTip != "")
13831387
QToolTip::showText(helpEvent->globalPos(), toolTip);
@@ -1471,7 +1475,8 @@ void PageViewer::computeSize() {
14711475
QSize chipSize = getChipSize();
14721476
m_chipPerRow = m_viewMode == List ? 1 : (w - 8) / chipSize.width();
14731477
if (m_chipPerRow == 0) m_chipPerRow = 1;
1474-
int rowCount = (chipCount + m_chipPerRow) / m_chipPerRow;
1478+
if (ShowNewStyleButton) chipCount++;
1479+
int rowCount = (chipCount + m_chipPerRow - 1) / m_chipPerRow;
14751480
setMinimumSize(w, rowCount * chipSize.height() + 10);
14761481
}
14771482

0 commit comments

Comments
 (0)