From 16d12c56e453a7164e2a7bedb06e77aaf6deea76 Mon Sep 17 00:00:00 2001 From: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com> Date: Jul 15 2020 16:07:26 +0000 Subject: 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 * 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 --- diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index 8e09662..c1f5f78 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); @@ -1334,6 +1376,9 @@ bool PageViewer::event(QEvent *e) { (wchar_t)shortcutKey + L")"); } } + if (indexInPage == m_page->getStyleCount()) { + toolTip = tr("New Style"); + } if (toolTip != "") QToolTip::showText(helpEvent->globalPos(), toolTip); else @@ -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(); }