Merge pull request #2762 from melieconiek/merge-levels-without-groups-command
Add Ability to Execute 'Merge Levels' Command Without Grouping Strokes
This commit is contained in:
commit
794392416e
3 changed files with 53 additions and 15 deletions
|
@ -97,8 +97,8 @@ public:
|
|||
|
||||
void deleteMatchlines(TXshSimpleLevel *sl, const std::set<TFrameId> &fids);
|
||||
void deleteInk(TXshSimpleLevel *sl, const std::set<TFrameId> &fids);
|
||||
void mergeColumns(int dstColumn, int srcColumn, bool isRedo);
|
||||
void mergeColumns(const std::set<int> &columns);
|
||||
void mergeColumns(int dstColumn, int srcColumn, bool isRedo, bool groupLevels);
|
||||
void mergeColumns(const std::set<int> &columns, bool groupLevels);
|
||||
void doMatchlines(int column, int mColumn, int index, int inkPrevalence,
|
||||
int MatchlineSessionId = 0);
|
||||
void mergeCmapped(int dstColumn, int srcColumn, const QString &fullpath,
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "tpalette.h"
|
||||
|
||||
// TnzLib includes
|
||||
#include "toonz/txsheet.h"
|
||||
#include "toonz/toonzscene.h"
|
||||
#include "toonz/txshcell.h"
|
||||
#include "toonz/txshsimplelevel.h"
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include "toonz/txshlevelhandle.h"
|
||||
#include "toonz/txsheethandle.h"
|
||||
#include "toonz/tscenehandle.h"
|
||||
#include "toonz/txshleveltypes.h"
|
||||
|
||||
// TnzQt includes
|
||||
#include "toonzqt/menubarcommand.h"
|
||||
|
@ -99,6 +101,31 @@ MergeCmappedDialog::MergeCmappedDialog(TFilePath &levelPath)
|
|||
// MergeColumns command
|
||||
//*****************************************************************************
|
||||
|
||||
bool isVectorColumn(const std::set<int> &columns) {
|
||||
TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
|
||||
std::set<int>::const_iterator column = columns.begin();
|
||||
int start, end;
|
||||
xsh->getCellRange(*column, start, end);
|
||||
|
||||
if (start > end) return false;
|
||||
|
||||
std::vector<TXshCell> cell(end - start + 1);
|
||||
xsh->getCells(start, *column, cell.size(), &(cell[0]));
|
||||
|
||||
TXshSimpleLevel *level = 0;
|
||||
for (int i = 0; i < (int)cell.size(); i++) {
|
||||
if (cell[i].isEmpty()) continue;
|
||||
|
||||
level = cell[i].getSimpleLevel();
|
||||
if (level->getType() == PLI_XSHLEVEL) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MergeColumnsCommand final : public MenuItemHandler {
|
||||
public:
|
||||
MergeColumnsCommand() : MenuItemHandler(MI_MergeColumns) {}
|
||||
|
@ -123,8 +150,17 @@ public:
|
|||
"only one columns is selected."));
|
||||
return;
|
||||
}
|
||||
|
||||
mergeColumns(indices);
|
||||
|
||||
bool groupLevels = true;
|
||||
if (isVectorColumn(indices)) {
|
||||
int opt = DVGui::MsgBox("Group strokes by vector levels?", QObject::tr("Yes"), QObject::tr("No"), QObject::tr("Cancel"));
|
||||
if (opt == 3) return;
|
||||
else {
|
||||
groupLevels = (opt == 1);
|
||||
};
|
||||
}
|
||||
|
||||
mergeColumns(indices, groupLevels);
|
||||
TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
|
||||
}
|
||||
|
||||
|
|
|
@ -144,7 +144,7 @@ bool needTobeGrouped(const TVectorImageP &vimg) {
|
|||
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
void mergeVectorColumns(const std::vector<MatchlinePair> &matchingLevels) {
|
||||
void mergeVectorColumns(const std::vector<MatchlinePair> &matchingLevels, bool groupLevels) {
|
||||
if (matchingLevels.empty()) return;
|
||||
|
||||
int i = 0;
|
||||
|
@ -157,9 +157,9 @@ void mergeVectorColumns(const std::vector<MatchlinePair> &matchingLevels) {
|
|||
throw TRopException("Cannot merge columns of different image types!");
|
||||
// img->lock();
|
||||
|
||||
if (needTobeGrouped(vimg)) vimg->group(0, vimg->getStrokeCount());
|
||||
if (needTobeGrouped(vimg) && groupLevels) vimg->group(0, vimg->getStrokeCount());
|
||||
bool ungroup = false;
|
||||
if (needTobeGrouped(vmatch)) {
|
||||
if (needTobeGrouped(vmatch) && groupLevels) {
|
||||
ungroup = true;
|
||||
vmatch->group(0, vmatch->getStrokeCount());
|
||||
}
|
||||
|
@ -184,12 +184,13 @@ class MergeColumnsUndo final : public TUndo {
|
|||
|
||||
int m_column, m_mColumn;
|
||||
TPalette *m_palette;
|
||||
bool m_groupLevels;
|
||||
|
||||
public:
|
||||
MergeColumnsUndo(TXshLevelP xl, int matchlineSessionId, int column,
|
||||
TXshSimpleLevel *level,
|
||||
const std::map<TFrameId, QString> &images, int mColumn,
|
||||
TPalette *palette)
|
||||
TPalette *palette, bool groupLevels)
|
||||
: TUndo()
|
||||
, m_xl(xl)
|
||||
, m_matchlineSessionId(matchlineSessionId)
|
||||
|
@ -197,7 +198,8 @@ public:
|
|||
, m_column(column)
|
||||
, m_mColumn(mColumn)
|
||||
, m_images(images)
|
||||
, m_palette(palette->clone()) {}
|
||||
, m_palette(palette->clone())
|
||||
, m_groupLevels(groupLevels) {}
|
||||
|
||||
void undo() const override {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
@ -225,7 +227,7 @@ public:
|
|||
void redo() const override {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
mergeColumns(m_column, m_mColumn, true);
|
||||
mergeColumns(m_column, m_mColumn, true, m_groupLevels);
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
@ -250,7 +252,7 @@ public:
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void mergeColumns(const std::set<int> &columns) {
|
||||
void mergeColumns(const std::set<int> &columns, bool groupLevels) {
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
|
||||
std::set<int>::const_iterator it = columns.begin();
|
||||
|
@ -260,7 +262,7 @@ void mergeColumns(const std::set<int> &columns) {
|
|||
|
||||
TUndoManager::manager()->beginBlock();
|
||||
|
||||
for (; it != columns.end(); ++it) mergeColumns(dstColumn, *it, false);
|
||||
for (; it != columns.end(); ++it) mergeColumns(dstColumn, *it, false, groupLevels);
|
||||
|
||||
TUndoManager::manager()->endBlock();
|
||||
|
||||
|
@ -271,7 +273,7 @@ void mergeColumns(const std::set<int> &columns) {
|
|||
|
||||
static int MergeColumnsSessionId = 0;
|
||||
|
||||
void mergeColumns(int column, int mColumn, bool isRedo) {
|
||||
void mergeColumns(int column, int mColumn, bool isRedo, bool groupLevels) {
|
||||
if (!isRedo) MergeColumnsSessionId++;
|
||||
TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
|
||||
int start, end;
|
||||
|
@ -386,7 +388,7 @@ void mergeColumns(int column, int mColumn, bool isRedo) {
|
|||
if (!isRedo)
|
||||
TUndoManager::manager()->add(
|
||||
new MergeColumnsUndo(xl, MergeColumnsSessionId, column, level, images,
|
||||
mColumn, level->getPalette()));
|
||||
mColumn, level->getPalette(), groupLevels));
|
||||
|
||||
if (areRasters) {
|
||||
mergeRasterColumns(matchingLevels);
|
||||
|
@ -399,7 +401,7 @@ void mergeColumns(int column, int mColumn, bool isRedo) {
|
|||
ToolUtils::updateSaveBox(cell[i].getSimpleLevel(), cell[i].m_frameId);
|
||||
}
|
||||
} else
|
||||
mergeVectorColumns(matchingLevels);
|
||||
mergeVectorColumns(matchingLevels, groupLevels);
|
||||
|
||||
TXshLevel *sl =
|
||||
TApp::instance()->getCurrentScene()->getScene()->getLevelSet()->getLevel(
|
||||
|
|
Loading…
Reference in a new issue