Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Create New Style Command Button (#3394)

DoctorRyan16d12c56e453
diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp
index 8e096629d..c1f5f78a0 100644
--- a/toonz/sources/toonzqt/paletteviewergui.cpp
+++ b/toonz/sources/toonzqt/paletteviewergui.cpp
@@ -596,6 +596,9 @@ void PageViewer::paintEvent(QPaintEvent *e) {
int i1 = posToIndex(visibleRect.bottomRight());
if (i1 >= getChipCount()) i1 = getChipCount() - 1;
+ QFont preFont = p.font();
+ QFont tmpFont = p.font();
+
if (m_viewMode == List) {
// disegno le celle
int i;
@@ -653,6 +656,23 @@ void PageViewer::paintEvent(QPaintEvent *e) {
// toggle link
drawToggleLink(p, chipRect, m_page->getStyle(i));
}
+ if (!m_page->getPalette()->isLocked()) {
+ int j = getChipCount();
+ QRect rect = getItemRect(j);
+ p.setPen(QColor(200, 200, 200));
+ // p.fillRect(rect, QBrush(QColor(0, 0, 0, 64)));
+ // p.drawRect(rect);
+ tmpFont.setPointSize(16);
+ tmpFont.setBold(true);
+ p.setFont(tmpFont);
+ QString newLabel = tr(" + ");
+ p.drawText(rect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
+
+ // revert font set
+ p.setFont(preFont);
+ p.setPen(Qt::black);
+ }
+
} else {
int currentStyleIndex = getCurrentStyleIndex();
int i;
@@ -880,6 +900,24 @@ void PageViewer::paintEvent(QPaintEvent *e) {
// draw link indicator
drawToggleLink(p, chipRect, style);
}
+ // draw new style chip
+ if (!m_page->getPalette()->isLocked()) {
+ i = getChipCount();
+ QRect chipRect = getItemRect(i).adjusted(0, -1, 0, -1);
+ p.setPen(QColor(200, 200, 200));
+ p.fillRect(chipRect, QBrush(QColor(0, 0, 0, 64)));
+ p.drawRect(chipRect);
+ tmpFont.setPointSize(16);
+ tmpFont.setBold(true);
+ p.setFont(tmpFont);
+ QString newLabel = tr(" + ");
+ p.drawText(chipRect.adjusted(0, -6, 0, 0), Qt::AlignCenter, newLabel);
+
+ // revert font set
+ p.setFont(preFont);
+ // revert brush
+ p.setBrush(Qt::NoBrush);
+ }
}
// indicatore di drop
@@ -955,10 +993,14 @@ void PageViewer::mousePressEvent(QMouseEvent *event) {
}
m_dragStartPosition = pos;
if (indexInPage < 0 || indexInPage >= getChipCount()) {
- // l'utente ha fatto click fuori dai color chip. vuole deselezionare tutto
- // (lasciando la selezione attiva, per un eventuale paste)
+ if (indexInPage == getChipCount() && !m_page->getPalette()->isLocked()) {
+ PaletteCmd::createStyle(getPaletteHandle(), getPage());
+ } else {
+ // the user clicked out of the color chips.wants to deselect everything
+ // (leaving the selection active, for a possible paste)
m_styleSelection->select(pageIndex);
m_styleSelection->makeCurrent();
+ }
update();
// update locks when the styleSelection becomes current
@@ -1324,8 +1366,8 @@ bool PageViewer::event(QEvent *e) {
if (0 <= indexInPage && indexInPage < m_page->getStyleCount()) {
TColorStyle *style = m_page->getStyle(indexInPage);
if (style) {
- int styleIndex = m_page->getStyleId(indexInPage);
- toolTip = "#" + QString::number(styleIndex) + " " +
+ int styleIndex = m_page->getStyleId(indexInPage);
+ toolTip = "#" + QString::number(styleIndex) + " " +
QString::fromStdWString(style->getName());
int shortcutKey = m_page->getPalette()->getStyleShortcut(styleIndex);
@@ -1333,6 +1375,9 @@ bool PageViewer::event(QEvent *e) {
toolTip += QString::fromStdWString(std::wstring(L" (") +
(wchar_t)shortcutKey + L")");
}
+ }
+ if (indexInPage == m_page->getStyleCount()) {
+ toolTip = tr("New Style");
}
if (toolTip != "")
QToolTip::showText(helpEvent->globalPos(), toolTip);
@@ -1426,7 +1471,7 @@ void PageViewer::computeSize() {
QSize chipSize = getChipSize();
m_chipPerRow = m_viewMode == List ? 1 : (w - 8) / chipSize.width();
if (m_chipPerRow == 0) m_chipPerRow = 1;
- int rowCount = (chipCount + m_chipPerRow - 1) / m_chipPerRow;
+ int rowCount = (chipCount + m_chipPerRow) / m_chipPerRow;
setMinimumSize(w, rowCount * chipSize.height() + 10);
}
@@ -1727,4 +1772,5 @@ void PageViewer::updateCommandLocks() {
cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked);
cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked);
cmd->getAction("MI_EraseUnusedStyles")->setEnabled(!isLocked);
+ update();
}