Skip to content

Commit 16d12c5

Browse files
Create New Style Command Button (#3394)
* Create New Style Command Button This PR creates a new button in the pallette editor that creates a new style. Button is large and easy access for a faster and easier workflow. Original code developed by Turtletooth for Tahoma. Given permission to develop within Openoonz. Co-Authored-By: Jeremy Bullock <[email protected]> * Update paletteviewergui.cpp Made changes to the PR per request by Shun. * Fixed a space within the code that wasn't suppose to be there. Co-authored-by: Jeremy Bullock <[email protected]>
1 parent 20df5ad commit 16d12c5

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

toonz/sources/toonzqt/paletteviewergui.cpp

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ void PageViewer::paintEvent(QPaintEvent *e) {
596596
int i1 = posToIndex(visibleRect.bottomRight());
597597
if (i1 >= getChipCount()) i1 = getChipCount() - 1;
598598

599+
QFont preFont = p.font();
600+
QFont tmpFont = p.font();
601+
599602
if (m_viewMode == List) {
600603
// disegno le celle
601604
int i;
@@ -653,6 +656,23 @@ void PageViewer::paintEvent(QPaintEvent *e) {
653656
// toggle link
654657
drawToggleLink(p, chipRect, m_page->getStyle(i));
655658
}
659+
if (!m_page->getPalette()->isLocked()) {
660+
int j = getChipCount();
661+
QRect rect = getItemRect(j);
662+
p.setPen(QColor(200, 200, 200));
663+
// p.fillRect(rect, QBrush(QColor(0, 0, 0, 64)));
664+
// p.drawRect(rect);
665+
tmpFont.setPointSize(16);
666+
tmpFont.setBold(true);
667+
p.setFont(tmpFont);
668+
QString newLabel = tr(" + ");
669+
p.drawText(rect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
670+
671+
// revert font set
672+
p.setFont(preFont);
673+
p.setPen(Qt::black);
674+
}
675+
656676
} else {
657677
int currentStyleIndex = getCurrentStyleIndex();
658678
int i;
@@ -880,6 +900,24 @@ void PageViewer::paintEvent(QPaintEvent *e) {
880900
// draw link indicator
881901
drawToggleLink(p, chipRect, style);
882902
}
903+
// draw new style chip
904+
if (!m_page->getPalette()->isLocked()) {
905+
i = getChipCount();
906+
QRect chipRect = getItemRect(i).adjusted(0, -1, 0, -1);
907+
p.setPen(QColor(200, 200, 200));
908+
p.fillRect(chipRect, QBrush(QColor(0, 0, 0, 64)));
909+
p.drawRect(chipRect);
910+
tmpFont.setPointSize(16);
911+
tmpFont.setBold(true);
912+
p.setFont(tmpFont);
913+
QString newLabel = tr(" + ");
914+
p.drawText(chipRect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
915+
916+
// revert font set
917+
p.setFont(preFont);
918+
// revert brush
919+
p.setBrush(Qt::NoBrush);
920+
}
883921
}
884922

885923
// indicatore di drop
@@ -955,10 +993,14 @@ void PageViewer::mousePressEvent(QMouseEvent *event) {
955993
}
956994
m_dragStartPosition = pos;
957995
if (indexInPage < 0 || indexInPage >= getChipCount()) {
958-
// l'utente ha fatto click fuori dai color chip. vuole deselezionare tutto
959-
// (lasciando la selezione attiva, per un eventuale paste)
996+
if (indexInPage == getChipCount() && !m_page->getPalette()->isLocked()) {
997+
PaletteCmd::createStyle(getPaletteHandle(), getPage());
998+
} else {
999+
// the user clicked out of the color chips.wants to deselect everything
1000+
// (leaving the selection active, for a possible paste)
9601001
m_styleSelection->select(pageIndex);
9611002
m_styleSelection->makeCurrent();
1003+
}
9621004

9631005
update();
9641006
// update locks when the styleSelection becomes current
@@ -1324,15 +1366,18 @@ bool PageViewer::event(QEvent *e) {
13241366
if (0 <= indexInPage && indexInPage < m_page->getStyleCount()) {
13251367
TColorStyle *style = m_page->getStyle(indexInPage);
13261368
if (style) {
1327-
int styleIndex = m_page->getStyleId(indexInPage);
1328-
toolTip = "#" + QString::number(styleIndex) + " " +
1369+
int styleIndex = m_page->getStyleId(indexInPage);
1370+
toolTip = "#" + QString::number(styleIndex) + " " +
13291371
QString::fromStdWString(style->getName());
13301372

13311373
int shortcutKey = m_page->getPalette()->getStyleShortcut(styleIndex);
13321374
if (shortcutKey > 0)
13331375
toolTip += QString::fromStdWString(std::wstring(L" (") +
13341376
(wchar_t)shortcutKey + L")");
13351377
}
1378+
}
1379+
if (indexInPage == m_page->getStyleCount()) {
1380+
toolTip = tr("New Style");
13361381
}
13371382
if (toolTip != "")
13381383
QToolTip::showText(helpEvent->globalPos(), toolTip);
@@ -1426,7 +1471,7 @@ void PageViewer::computeSize() {
14261471
QSize chipSize = getChipSize();
14271472
m_chipPerRow = m_viewMode == List ? 1 : (w - 8) / chipSize.width();
14281473
if (m_chipPerRow == 0) m_chipPerRow = 1;
1429-
int rowCount = (chipCount + m_chipPerRow - 1) / m_chipPerRow;
1474+
int rowCount = (chipCount + m_chipPerRow) / m_chipPerRow;
14301475
setMinimumSize(w, rowCount * chipSize.height() + 10);
14311476
}
14321477

@@ -1727,4 +1772,5 @@ void PageViewer::updateCommandLocks() {
17271772
cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked);
17281773
cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked);
17291774
cmd->getAction("MI_EraseUnusedStyles")->setEnabled(!isLocked);
1775+
update();
17301776
}

0 commit comments

Comments
 (0)