|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/styleselection.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/gutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/selectioncommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "styledata.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tpalettehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tscenehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txsheethandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/studiopalette.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/palettecmd.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshsimplelevel.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/cleanupcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/txshlevelhandle.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/levelproperties.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "tcolorstyles.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tundo.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tconvert.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "../toonz/menubarcommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "historytypes.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qapplication></qapplication>
|
|
Toshihiro Shimizu |
890ddd |
#include <qclipboard></qclipboard>
|
|
Toshihiro Shimizu |
890ddd |
#include <qbytearray></qbytearray>
|
|
Toshihiro Shimizu |
890ddd |
#include <qbuffer></qbuffer>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
enum StyleType { NORMALSTYLE, STUDIOSTYLE, LINKEDSTYLE };
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void copyStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex, std::set<int> *styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
if (!palette || pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
int n = styleIndicesInPage->size();
|
|
Shinya Kitaoka |
120a6e |
if (n == 0) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
StyleData *data = new StyleData();
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage->begin(); it != styleIndicesInPage->end();
|
|
Shinya Kitaoka |
120a6e |
++it) {
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = *it;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = page->getStyle(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
if (!style) continue;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *newStyle = style->clone();
|
|
Shinya Kitaoka |
120a6e |
data->addStyle(styleId, newStyle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
QApplication::clipboard()->setMimeData(data);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! Paste styles contained in \b data in the end of current palette page.
|
|
Shinya Kitaoka |
120a6e |
Add to styleIndicesInPage pasted styles index.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
bool pasteStylesDataWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
const StyleData *data, int indexInPage,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex,
|
|
Shinya Kitaoka |
120a6e |
std::set<int> *styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
if (!palette) palette = pltHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return false;
|
|
Shinya Kitaoka |
120a6e |
// page = pagina corrente
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!data) return false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// comincio a fare paste
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
int styleId = 0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < data->getStyleCount(); i++) {
|
|
Shinya Kitaoka |
120a6e |
styleId = data->getStyleIndex(i);
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = data->getStyle(i)->clone();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Se la palette e' di cleanup gli stili devono essere 8.
|
|
Shinya Kitaoka |
120a6e |
if (palette->isCleanupPalette() && palette->getStyleInPagesCount() >= 8) {
|
|
Shinya Kitaoka |
120a6e |
delete style;
|
|
Shinya Kitaoka |
120a6e |
break;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
171458 |
// For now styles will be inserted regardless the styleId of copied styles
|
|
shun-iwasawa |
171458 |
// are already used in the target palette or not.
|
|
shun-iwasawa |
171458 |
styleId = palette->getFirstUnpagedStyle();
|
|
shun-iwasawa |
171458 |
if (styleId >= 0)
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleId, style);
|
|
shun-iwasawa |
171458 |
else
|
|
shun-iwasawa |
171458 |
styleId = palette->addStyle(style);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// check the type of the original(copied) style
|
|
Shinya Kitaoka |
120a6e |
// If the original is NormalStyle
|
|
Shinya Kitaoka |
120a6e |
if (style->getGlobalName() == L"") {
|
|
Shinya Kitaoka |
120a6e |
// 1. If pasting normal style to level palette, do nothing
|
|
Shinya Kitaoka |
120a6e |
if (palette->getGlobalName() == L"") {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// 2. If pasting normal style to studio palette, add a new link and make
|
|
Shinya Kitaoka |
120a6e |
// it linkable
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
std::wstring gname =
|
|
Shinya Kitaoka |
120a6e |
L"-" + palette->getGlobalName() + L"-" + std::to_wstring(styleId);
|
|
Shinya Kitaoka |
120a6e |
style->setGlobalName(gname);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// If the original is StudioPaletteStyle
|
|
Shinya Kitaoka |
120a6e |
else if (style->getOriginalName() == L"") {
|
|
Shinya Kitaoka |
120a6e |
// 3. If pasting StudioPaletteStyle to level palette, set the style name
|
|
Shinya Kitaoka |
120a6e |
// into the original name.
|
|
Shinya Kitaoka |
120a6e |
// 4. If pasting StudioPaletteStyle to studio palette, set the style name
|
|
Shinya Kitaoka |
120a6e |
// into the original name and keep the link.
|
|
Shinya Kitaoka |
120a6e |
style->setOriginalName(style->getName());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// If the original is linked style, do nothing
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// move in the page
|
|
Shinya Kitaoka |
120a6e |
// inserisco lo stile nella pagina
|
|
Shinya Kitaoka |
120a6e |
int index = indexInPage + i;
|
|
Shinya Kitaoka |
120a6e |
page->insertStyle(index, styleId);
|
|
Shinya Kitaoka |
120a6e |
// e lo seleziono
|
|
Shinya Kitaoka |
120a6e |
if (styleIndicesInPage) styleIndicesInPage->insert(index);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (palette == pltHandle->getPalette()) pltHandle->setStyleIndex(styleId);
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyPaletteChanged();
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
/*! Paste styles contained in application data after current style. Clear
|
|
Shinya Kitaoka |
120a6e |
styleIndicesInPage
|
|
Shinya Kitaoka |
120a6e |
and add to it pasted styles. If currentStyleIndex == -1 take
|
|
Shinya Kitaoka |
120a6e |
paletteHandle current style.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Shinya Kitaoka |
120a6e |
bool pasteStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex, std::set<int> *styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
if (!palette) palette = pltHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
// page = pagina corrente
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
// cerco il punto di inserimento (dopo lo stile corrente)
|
|
Shinya Kitaoka |
120a6e |
int currentStyleIndex = pltHandle->getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = page->search(currentStyleIndex) + 1;
|
|
Shinya Kitaoka |
120a6e |
const StyleData *data =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
|
|
Shinya Kitaoka |
120a6e |
if (!data) return false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// cancello la selezione
|
|
Shinya Kitaoka |
120a6e |
if (styleIndicesInPage) styleIndicesInPage->clear();
|
|
Shinya Kitaoka |
120a6e |
return pasteStylesDataWithoutUndo(palette, pltHandle, data, indexInPage,
|
|
Shinya Kitaoka |
120a6e |
pageIndex, styleIndicesInPage);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void deleteStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex, std::set<int> *styleIndicesInPage,</int>
|
|
Shinya Kitaoka |
120a6e |
int fir = 0) {
|
|
Shinya Kitaoka |
120a6e |
if (!palette) palette = pltHandle->getPalette();
|
|
shun-iwasawa |
b37337 |
int n = styleIndicesInPage->size();
|
|
Shinya Kitaoka |
120a6e |
if (n == 0) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int currentStyleIndexInPage = page->search(pltHandle->getStyleIndex());
|
|
Shinya Kitaoka |
120a6e |
bool mustChangeCurrentStyle =
|
|
Shinya Kitaoka |
120a6e |
currentStyleIndexInPage >= 0 &&
|
|
Shinya Kitaoka |
120a6e |
styleIndicesInPage->count(currentStyleIndexInPage) > 0;
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::reverse_iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage->rbegin(); it != styleIndicesInPage->rend();
|
|
Shinya Kitaoka |
120a6e |
++it) {
|
|
Shinya Kitaoka |
120a6e |
int j = *it;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(j);
|
|
Shinya Kitaoka |
120a6e |
if (styleId < 2) {
|
|
Shinya Kitaoka |
120a6e |
error(QObject::tr("It is not possible to delete the style #") +
|
|
Shinya Kitaoka |
120a6e |
QString::number(styleId));
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (styleId == pltHandle->getStyleIndex()) pltHandle->setStyleIndex(1);
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleId, TPixel32::Red);
|
|
Shinya Kitaoka |
120a6e |
page->removeStyle(j);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
styleIndicesInPage->clear();
|
|
Shinya Kitaoka |
120a6e |
if (mustChangeCurrentStyle) {
|
|
Shinya Kitaoka |
120a6e |
// ho cancellato lo stile corrente
|
|
Shinya Kitaoka |
120a6e |
if (currentStyleIndexInPage < page->getStyleCount()) {
|
|
Shinya Kitaoka |
120a6e |
// posso fare in modo che lo stile selezionato sia nella stessa posizione
|
|
Shinya Kitaoka |
120a6e |
pltHandle->setStyleIndex(page->getStyleId(currentStyleIndexInPage));
|
|
Shinya Kitaoka |
120a6e |
} else if (page->getStyleCount() > 0) {
|
|
Shinya Kitaoka |
120a6e |
// almeno faccio in modo che sia nella stessa pagina
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(page->getStyleCount() - 1);
|
|
Shinya Kitaoka |
120a6e |
pltHandle->setStyleIndex(styleId);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
// seleziono lo stile #1 (che c'e' sempre). n.b. questo puo' comportare un
|
|
Shinya Kitaoka |
120a6e |
// cambio pagina
|
|
Shinya Kitaoka |
120a6e |
pltHandle->setStyleIndex(1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// This function is used in undo and redo. So do not activate dirtyflag.
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyPaletteChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void cutStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex, std::set<int> *styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
copyStylesWithoutUndo(palette, pltHandle, pageIndex, styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
deleteStylesWithoutUndo(palette, pltHandle, pageIndex, styleIndicesInPage);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void insertStylesWithoutUndo(TPalette *palette, TPaletteHandle *pltHandle,
|
|
Shinya Kitaoka |
120a6e |
int pageIndex, std::set<int> *styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
if (!palette) palette = pltHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const StyleData *data =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
|
|
Shinya Kitaoka |
120a6e |
if (!data) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int styleId = 0;
|
|
Shinya Kitaoka |
120a6e |
// comincio a fare paste
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it = styleIndicesInPage->begin();</int>
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < data->getStyleCount(); i++, it++) {
|
|
Shinya Kitaoka |
120a6e |
styleId = data->getStyleIndex(i);
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = data->getStyle(i)->clone();
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleId, style);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// inserisco lo stile nella pagina
|
|
Shinya Kitaoka |
120a6e |
int index = *it;
|
|
Shinya Kitaoka |
120a6e |
page->insertStyle(index, styleId);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (palette == pltHandle->getPalette()) pltHandle->setStyleIndex(styleId);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
pltHandle->notifyPaletteChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// PasteStylesUndo
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class PasteStylesUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection *m_selection;
|
|
Shinya Kitaoka |
120a6e |
int m_oldStyleIndex;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
std::set<int> m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Shinya Kitaoka |
120a6e |
QMimeData *m_data;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
PasteStylesUndo(TStyleSelection *selection, int oldStyleIndex,
|
|
Shinya Kitaoka |
120a6e |
QMimeData *data)
|
|
Shinya Kitaoka |
120a6e |
: m_selection(selection), m_oldStyleIndex(oldStyleIndex), m_data(data) {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = m_selection->getPageIndex();
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage = m_selection->getIndicesInPage();
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_selection->getPaletteHandle()->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~PasteStylesUndo() { delete m_data; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
cutStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Setto l'indice corrente.
|
|
Shinya Kitaoka |
120a6e |
if (m_palette.getPointer() == paletteHandle->getPalette())
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->setStyleIndex(m_oldStyleIndex);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
// Se e' la paletta corrente setto l'indice corrente.
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
|
|
Shinya Kitaoka |
120a6e |
if (m_palette.getPointer() == paletteHandle->getPalette())
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->setStyleIndex(m_oldStyleIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = page->search(m_oldStyleIndex) + 1;
|
|
Shinya Kitaoka |
120a6e |
const StyleData *data = dynamic_cast<const *="" styledata="">(m_data);</const>
|
|
Shinya Kitaoka |
120a6e |
assert(data);
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
pasteStylesDataWithoutUndo(m_palette.getPointer(), paletteHandle, data,
|
|
Shinya Kitaoka |
120a6e |
indexInPage, m_pageIndex, &styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Se e' la paletta corrente aggiorno la selezione
|
|
Shinya Kitaoka |
120a6e |
if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end();
|
|
Shinya Kitaoka |
120a6e |
++it)
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, *it, true);
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Paste Style in Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DeleteStylesUndo
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class DeleteStylesUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection *m_selection;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
std::set<int> m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
QMimeData *m_data;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
DeleteStylesUndo(TStyleSelection *selection, QMimeData *data)
|
|
Shinya Kitaoka |
120a6e |
: m_selection(selection), m_data(data) {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = m_selection->getPageIndex();
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage = m_selection->getIndicesInPage();
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_selection->getPaletteHandle()->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setStyleIndicesInPage(const std::set<int> &styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage = styleIndicesInPage;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setPageIndex(int pageIndex) { m_pageIndex = pageIndex; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~DeleteStylesUndo() { delete m_data; }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
|
|
Shinya Kitaoka |
120a6e |
// Prendo il data corrente
|
|
Shinya Kitaoka |
120a6e |
QClipboard *clipboard = QApplication::clipboard();
|
|
Shinya Kitaoka |
120a6e |
QMimeData *currentData = cloneData(clipboard->mimeData());
|
|
Shinya Kitaoka |
120a6e |
// Setto il vecchio data
|
|
Shinya Kitaoka |
120a6e |
clipboard->setMimeData(cloneData(m_data), QClipboard::Clipboard);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
insertStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end();
|
|
Shinya Kitaoka |
120a6e |
++it)
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, *it, true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// Rimetto il data corrente.
|
|
Shinya Kitaoka |
120a6e |
clipboard->setMimeData(currentData, QClipboard::Clipboard);
|
|
Shinya Kitaoka |
120a6e |
// do not activate dirty flag here in case that the m_palette is not current
|
|
Shinya Kitaoka |
120a6e |
// when undo
|
|
Shinya Kitaoka |
120a6e |
paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
deleteStylesWithoutUndo(m_palette.getPointer(),
|
|
Shinya Kitaoka |
120a6e |
m_selection->getPaletteHandle(), m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
if (m_selection) {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Delete Style from Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// CutStylesUndo
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class CutStylesUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection *m_selection;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
std::set<int> m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
QMimeData *m_oldData; //!< data before cut
|
|
Shinya Kitaoka |
120a6e |
QMimeData *m_data; //!< data containing cut styles
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
CutStylesUndo(TStyleSelection *selection, QMimeData *data, QMimeData *oldData)
|
|
Shinya Kitaoka |
120a6e |
: m_selection(selection), m_oldData(oldData), m_data(data) {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = m_selection->getPageIndex();
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage = m_selection->getIndicesInPage();
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_selection->getPaletteHandle()->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~CutStylesUndo() {
|
|
Shinya Kitaoka |
120a6e |
delete m_oldData;
|
|
Shinya Kitaoka |
120a6e |
delete m_data;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *paletteHandle = m_selection->getPaletteHandle();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Setto il data del cut
|
|
Shinya Kitaoka |
120a6e |
QClipboard *clipboard = QApplication::clipboard();
|
|
Shinya Kitaoka |
120a6e |
clipboard->setMimeData(cloneData(m_data), QClipboard::Clipboard);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
insertStylesWithoutUndo(m_palette.getPointer(), paletteHandle, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_selection && m_palette.getPointer() == paletteHandle->getPalette()) {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end();
|
|
Shinya Kitaoka |
120a6e |
++it)
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, *it, true);
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Setto il che c'era prima del cut
|
|
Shinya Kitaoka |
120a6e |
clipboard->setMimeData(cloneData(m_oldData), QClipboard::Clipboard);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage = m_styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
cutStylesWithoutUndo(m_palette.getPointer(),
|
|
Shinya Kitaoka |
120a6e |
m_selection->getPaletteHandle(), m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Cut Style from Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// TStyleSelection
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TStyleSelection::TStyleSelection()
|
|
Shinya Kitaoka |
120a6e |
: m_paletteHandle(0)
|
|
Shinya Kitaoka |
120a6e |
, m_xsheetHandle(0)
|
|
Shinya Kitaoka |
120a6e |
, m_pageIndex(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_levelHandle(0) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection::~TStyleSelection() {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::enableCommands() {
|
|
Shinya Kitaoka |
120a6e |
if (m_paletteHandle && m_paletteHandle->getPalette() &&
|
|
Shinya Kitaoka |
120a6e |
!m_paletteHandle->getPalette()->isCleanupPalette()) {
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_Cut, &TStyleSelection::cutStyles);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_Copy, &TStyleSelection::copyStyles);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_Paste, &TStyleSelection::pasteStyles);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_PasteValues, &TStyleSelection::pasteStylesValue);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_PasteColors, &TStyleSelection::pasteStylesColor);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_PasteNames, &TStyleSelection::pasteStylesName);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// available only for level palette
|
|
shun_iwasawa |
640862 |
if (m_paletteHandle->getPalette()->getGlobalName() == L"") {
|
|
shun_iwasawa |
640862 |
enableCommand(this, MI_GetColorFromStudioPalette,
|
|
shun_iwasawa |
640862 |
&TStyleSelection::getBackOriginalStyle);
|
|
shun_iwasawa |
640862 |
enableCommand(this, MI_ToggleLinkToStudioPalette,
|
|
shun_iwasawa |
640862 |
&TStyleSelection::toggleLink);
|
|
shun_iwasawa |
640862 |
enableCommand(this, MI_RemoveReferenceToStudioPalette,
|
|
shun_iwasawa |
640862 |
&TStyleSelection::removeLink);
|
|
shun_iwasawa |
640862 |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_Clear, &TStyleSelection::deleteStyles);
|
|
shun-iwasawa |
b37337 |
enableCommand(this, MI_EraseUnusedStyles, &TStyleSelection::eraseUnusedStyle);
|
|
Shinya Kitaoka |
120a6e |
enableCommand(this, MI_BlendColors, &TStyleSelection::blendStyles);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::select(int pageIndex) {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = pageIndex;
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::select(int pageIndex, int styleIndexInPage, bool on) {
|
|
Shinya Kitaoka |
120a6e |
if (on) {
|
|
Shinya Kitaoka |
120a6e |
if (pageIndex != m_pageIndex) m_styleIndicesInPage.clear();
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = pageIndex;
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.insert(styleIndexInPage);
|
|
Shinya Kitaoka |
120a6e |
} else if (pageIndex == m_pageIndex)
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.erase(styleIndexInPage);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TStyleSelection::isSelected(int pageIndex, int id) const {
|
|
Shinya Kitaoka |
120a6e |
return m_pageIndex == pageIndex &&
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.find(id) != m_styleIndicesInPage.end();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TStyleSelection::isPageSelected(int pageIndex) const {
|
|
Shinya Kitaoka |
120a6e |
return m_pageIndex == pageIndex;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TStyleSelection::canHandleStyles() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return false;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return false;
|
|
Shinya Kitaoka |
120a6e |
if ((isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) ||
|
|
Shinya Kitaoka |
120a6e |
(isSelected(m_pageIndex, 1) && page->getStyleId(1) == 1))
|
|
Shinya Kitaoka |
120a6e |
return false;
|
|
Shinya Kitaoka |
120a6e |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::selectNone() {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = -1;
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.clear();
|
|
Shinya Kitaoka |
120a6e |
notifyView();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool TStyleSelection::isEmpty() const {
|
|
Shinya Kitaoka |
120a6e |
return m_pageIndex < 0 && m_styleIndicesInPage.empty();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int TStyleSelection::getStyleCount() const {
|
|
Shinya Kitaoka |
120a6e |
return m_styleIndicesInPage.size();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::cutStyles() {
|
|
Shinya Kitaoka |
120a6e |
if (isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
QClipboard *clipboard = QApplication::clipboard();
|
|
Shinya Kitaoka |
120a6e |
QMimeData *oldData = cloneData(clipboard->mimeData());
|
|
Shinya Kitaoka |
120a6e |
if (!canHandleStyles()) {
|
|
Shinya Kitaoka |
120a6e |
error(QObject::tr("It is not possible to delete styles #0 and #1."));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette) return;
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
StyleData *data = new StyleData();
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::vector<int> styleIds;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end();
|
|
Shinya Kitaoka |
120a6e |
++it) {
|
|
Shinya Kitaoka |
120a6e |
int j = *it;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(j);
|
|
Shinya Kitaoka |
120a6e |
if (styleId < 0) continue;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = page->getStyle(j)->clone();
|
|
Shinya Kitaoka |
120a6e |
data->addStyle(styleId, style);
|
|
Shinya Kitaoka |
120a6e |
styleIds.push_back(page->getStyleId(*it));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
2a7129 |
std::unique_ptr<tundo> undo(new CutStylesUndo(this, data, oldData));</tundo>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_xsheetHandle) {
|
|
Shinya Kitaoka |
120a6e |
if (eraseStylesInDemand(palette, styleIds, m_xsheetHandle) == 0) return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
cutStylesWithoutUndo(palette, m_paletteHandle, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&m_styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo.release());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::copyStyles() {
|
|
Shinya Kitaoka |
120a6e |
if (isEmpty()) return;
|
|
Shinya Kitaoka |
120a6e |
copyStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex, &m_styleIndicesInPage);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::pasteStyles() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
// se non c'e' palette o pagina corrente esco
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
if (isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) {
|
|
Shinya Kitaoka |
120a6e |
error(QObject::tr("Can't paste styles there"));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int oldStyleIndex = m_paletteHandle->getStyleIndex();
|
|
Shinya Kitaoka |
120a6e |
QClipboard *clipboard = QApplication::clipboard();
|
|
Shinya Kitaoka |
120a6e |
QMimeData *oldData = cloneData(clipboard->mimeData());
|
|
Shinya Kitaoka |
120a6e |
pasteStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex, &m_styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(
|
|
Shinya Kitaoka |
120a6e |
new PasteStylesUndo(this, oldStyleIndex, oldData));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::deleteStyles() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
if (!canHandleStyles()) {
|
|
Shinya Kitaoka |
120a6e |
error(QObject::tr("It is not possible to delete styles #0 and #1."));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (getStyleCount() == 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
StyleData *data = new StyleData();
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::vector<int> styleIds;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = m_styleIndicesInPage.begin(); it != m_styleIndicesInPage.end();
|
|
Shinya Kitaoka |
120a6e |
++it) {
|
|
Shinya Kitaoka |
120a6e |
int j = *it;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(j);
|
|
Shinya Kitaoka |
120a6e |
if (styleId < 0) continue;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = page->getStyle(j)->clone();
|
|
Shinya Kitaoka |
120a6e |
data->addStyle(styleId, style);
|
|
Shinya Kitaoka |
120a6e |
styleIds.push_back(page->getStyleId(*it));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TUndoScopedBlock undoBlock;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_xsheetHandle) {
|
|
Shinya Kitaoka |
120a6e |
if (eraseStylesInDemand(palette, styleIds, m_xsheetHandle) ==
|
|
Shinya Kitaoka |
120a6e |
0) // Could add an undo
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
2a7129 |
std::unique_ptr<tundo> undo(new DeleteStylesUndo(this, data));</tundo>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
deleteStylesWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex, &m_styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo.release());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
b37337 |
void TStyleSelection::eraseUnusedStyle() {
|
|
Shinya Kitaoka |
120a6e |
std::set<txshsimplelevel *=""> levels;</txshsimplelevel>
|
|
Shinya Kitaoka |
120a6e |
int row, column, i, j;
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
findPaletteLevels(levels, row, column, palette, m_xsheetHandle->getXsheet());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Verifico quali stili sono usati e quali no
|
|
Shinya Kitaoka |
120a6e |
std::map<int, bool=""> usedStyleIds;</int,>
|
|
Shinya Kitaoka |
120a6e |
int pageCount = palette->getPageCount();
|
|
Shinya Kitaoka |
120a6e |
for (auto const level : levels) {
|
|
Shinya Kitaoka |
120a6e |
std::vector<tframeid> fids;</tframeid>
|
|
Shinya Kitaoka |
120a6e |
level->getFids(fids);
|
|
Shinya Kitaoka |
120a6e |
int m, i, j;
|
|
Shinya Kitaoka |
120a6e |
for (m = 0; m < (int)fids.size(); m++) {
|
|
Shinya Kitaoka |
120a6e |
TImageP image = level->getFrame(fids[m], false);
|
|
Shinya Kitaoka |
120a6e |
if (!image) continue;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < pageCount; i++) {
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(i);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < page->getStyleCount(); j++) {
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(j);
|
|
Shinya Kitaoka |
120a6e |
if (m != 0 && usedStyleIds[styleId]) continue;
|
|
shun-iwasawa |
1a6552 |
if (i == 0 &&
|
|
shun-iwasawa |
1a6552 |
(j == 0 || j == 1)) // Il primo stile della prima pagina non deve
|
|
shun-iwasawa |
1a6552 |
// essere mai cancellato
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
usedStyleIds[styleId] = true;
|
|
Shinya Kitaoka |
120a6e |
continue;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
usedStyleIds[styleId] = isStyleUsed(image, styleId);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
b37337 |
// check if there are styles to be erased
|
|
shun-iwasawa |
b37337 |
QMap<int, std::set<int="">> styleIndicesInPageMap;</int,>
|
|
shun-iwasawa |
b37337 |
QString indicesStr;
|
|
shun-iwasawa |
b37337 |
int count = 0;
|
|
Shinya Kitaoka |
120a6e |
// Butto gli stili non usati
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < pageCount; i++) {
|
|
Shinya Kitaoka |
120a6e |
// Variabili usate per l'undo
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(i);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < page->getStyleCount(); j++) {
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(j);
|
|
Shinya Kitaoka |
120a6e |
if (usedStyleIds[styleId]) continue;
|
|
Shinya Kitaoka |
120a6e |
styleIndicesInPage.insert(j);
|
|
shun-iwasawa |
b37337 |
if (count < 10) indicesStr.append(QString::number(styleId) + ", ");
|
|
shun-iwasawa |
b37337 |
count++;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
b37337 |
if (!styleIndicesInPage.empty())
|
|
shun-iwasawa |
b37337 |
styleIndicesInPageMap.insert(i, styleIndicesInPage);
|
|
shun-iwasawa |
b37337 |
}
|
|
shun-iwasawa |
b37337 |
|
|
shun-iwasawa |
b37337 |
if (styleIndicesInPageMap.isEmpty()) {
|
|
shun-iwasawa |
b37337 |
DVGui::error(QObject::tr("There are no unused styles."));
|
|
shun-iwasawa |
b37337 |
return;
|
|
shun-iwasawa |
b37337 |
}
|
|
shun-iwasawa |
b37337 |
if (count <= 10)
|
|
shun-iwasawa |
b37337 |
indicesStr.chop(2);
|
|
shun-iwasawa |
b37337 |
else
|
|
shun-iwasawa |
b37337 |
indicesStr.append(
|
|
shun-iwasawa |
b37337 |
QObject::tr("and %1 more styles.").arg(QString::number(count - 10)));
|
|
shun-iwasawa |
b37337 |
// open confirmation popup
|
|
shun-iwasawa |
b37337 |
QString question =
|
|
shun-iwasawa |
b37337 |
QObject::tr(
|
|
shun-iwasawa |
b37337 |
"Erasing unused styles with following indices. Are you sure?\n\n%1")
|
|
shun-iwasawa |
b37337 |
.arg(indicesStr);
|
|
shun-iwasawa |
b37337 |
int ret =
|
|
shun-iwasawa |
b37337 |
DVGui::MsgBox(question, QObject::tr("Erase"), QObject::tr("Cancel"), 0);
|
|
shun-iwasawa |
b37337 |
if (ret == 2 || ret == 0) return;
|
|
shun-iwasawa |
b37337 |
|
|
shun-iwasawa |
b37337 |
TUndoManager::manager()->beginBlock();
|
|
shun-iwasawa |
b37337 |
|
|
shun-iwasawa |
b37337 |
QMap<int, std::set<int="">>::const_iterator styleMapItr =</int,>
|
|
shun-iwasawa |
b37337 |
styleIndicesInPageMap.constBegin();
|
|
shun-iwasawa |
b37337 |
while (styleMapItr != styleIndicesInPageMap.constEnd()) {
|
|
shun-iwasawa |
b37337 |
int pageIndex = styleMapItr.key();
|
|
shun-iwasawa |
b37337 |
std::set<int> styleIndicesInPage = styleMapItr.value();</int>
|
|
shun-iwasawa |
b37337 |
StyleData *data = new StyleData();
|
|
shun-iwasawa |
b37337 |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
shun-iwasawa |
b37337 |
for (auto indexInPage : styleIndicesInPage) {
|
|
shun-iwasawa |
b37337 |
int styleId = page->getStyleId(indexInPage);
|
|
shun-iwasawa |
b37337 |
data->addStyle(styleId, page->getStyle(indexInPage)->clone());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
b37337 |
|
|
Shinya Kitaoka |
120a6e |
// Cancello gli stili
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::reverse_iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage.rbegin(); it != styleIndicesInPage.rend();
|
|
Shinya Kitaoka |
120a6e |
++it)
|
|
Shinya Kitaoka |
120a6e |
page->removeStyle(*it);
|
|
Shinya Kitaoka |
120a6e |
// Undo
|
|
Shinya Kitaoka |
120a6e |
DeleteStylesUndo *undo = new DeleteStylesUndo(this, data);
|
|
shun-iwasawa |
b37337 |
undo->setPageIndex(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
undo->setStyleIndicesInPage(styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
shun-iwasawa |
b37337 |
|
|
shun-iwasawa |
b37337 |
++styleMapItr;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->endBlock();
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->setStyleIndex(1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// UndoPasteValues
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoPasteValues final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection *m_selection;
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool m_pasteName;
|
|
Shinya Kitaoka |
120a6e |
bool m_pasteColor;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
class Item {
|
|
Shinya Kitaoka |
120a6e |
public:
|
|
Shinya Kitaoka |
120a6e |
int m_index;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *m_oldStyle;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *m_newStyle;
|
|
Shinya Kitaoka |
120a6e |
Item(int index, const TColorStyle *oldStyle, const TColorStyle *newStyle)
|
|
Shinya Kitaoka |
120a6e |
: m_index(index)
|
|
Shinya Kitaoka |
120a6e |
, m_oldStyle(oldStyle->clone())
|
|
Shinya Kitaoka |
120a6e |
, m_newStyle(newStyle->clone()) {}
|
|
Shinya Kitaoka |
120a6e |
Item(int index, const TColorStyle *newStyle)
|
|
Shinya Kitaoka |
120a6e |
: m_index(index), m_oldStyle(0), m_newStyle(newStyle->clone()) {}
|
|
Shinya Kitaoka |
120a6e |
~Item() {
|
|
Shinya Kitaoka |
120a6e |
delete m_oldStyle;
|
|
Shinya Kitaoka |
120a6e |
delete m_newStyle;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<item *=""> m_items;</item>
|
|
Shinya Kitaoka |
120a6e |
std::vector<item *=""> m_itemsInserted;</item>
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette *getPalette() const { return m_palette.getPointer(); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoPasteValues(TStyleSelection *selection, bool pasteName,
|
|
Shinya Kitaoka |
120a6e |
bool pasteColor = true)
|
|
Shinya Kitaoka |
120a6e |
: m_selection(selection)
|
|
Shinya Kitaoka |
120a6e |
, m_pasteName(pasteName)
|
|
Shinya Kitaoka |
120a6e |
, m_pasteColor(pasteColor) {
|
|
Shinya Kitaoka |
120a6e |
m_pageIndex = m_selection->getPageIndex();
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle = m_selection->getPaletteHandle();
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~UndoPasteValues() {
|
|
Shinya Kitaoka |
120a6e |
clearPointerContainer(m_items);
|
|
Shinya Kitaoka |
120a6e |
clearPointerContainer(m_itemsInserted);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void addItem(int index, const TColorStyle *oldStyle,
|
|
Shinya Kitaoka |
120a6e |
const TColorStyle *newStyle) {
|
|
Shinya Kitaoka |
120a6e |
m_items.push_back(new Item(index, oldStyle, newStyle));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void addItemToInsert(const std::set<int> styleIndicesInPage) {</int>
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = getPalette()->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::const_iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
for (it = styleIndicesInPage.begin(); it != styleIndicesInPage.end(); it++)
|
|
Shinya Kitaoka |
120a6e |
m_itemsInserted.push_back(new Item(*it, page->getStyle(*it)));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void pasteValue(int styleId, const TColorStyle *newStyle) const {
|
|
Shinya Kitaoka |
120a6e |
// preserva il vecchio nome se m_pasteOnlyColor e' falso
|
|
Shinya Kitaoka |
120a6e |
std::wstring str = newStyle->getName();
|
|
Shinya Kitaoka |
120a6e |
if (m_pasteColor) {
|
|
Shinya Kitaoka |
120a6e |
getPalette()->setStyle(styleId, newStyle->clone());
|
|
Shinya Kitaoka |
120a6e |
if (!m_pasteName) getPalette()->getStyle(styleId)->setName(str);
|
|
Shinya Kitaoka |
120a6e |
} else if (m_pasteName)
|
|
Shinya Kitaoka |
120a6e |
getPalette()->getStyle(styleId)->setName(newStyle->getName());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = getPalette()->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_items.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = m_items[i]->m_index;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
pasteValue(styleId, m_items[i]->m_oldStyle);
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, indexInPage, true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Se avevo aggiunto degli stili devo rimuoverli.
|
|
Shinya Kitaoka |
120a6e |
int j;
|
|
Shinya Kitaoka |
120a6e |
for (j = (int)m_itemsInserted.size() - 1; j >= 0; j--) {
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = m_itemsInserted[j]->m_index;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
if (getPalette() == m_paletteHandle->getPalette() &&
|
|
Shinya Kitaoka |
120a6e |
styleId == m_paletteHandle->getStyleIndex())
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->setStyleIndex(page->getStyleId(indexInPage - 1));
|
|
Shinya Kitaoka |
120a6e |
getPalette()->setStyle(styleId, TPixel32::Red);
|
|
Shinya Kitaoka |
120a6e |
page->removeStyle(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
// do not activate a dirty flag here in case that m_palette is not
|
|
Shinya Kitaoka |
120a6e |
// currentpalette
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
m_selection->selectNone();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = getPalette()->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = 0;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_items.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
std::wstring oldName = m_items[i]->m_oldStyle->getName();
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *style = m_items[i]->m_newStyle;
|
|
Shinya Kitaoka |
120a6e |
indexInPage = m_items[i]->m_index;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// first, check out the types of copied and pasted styles
|
|
Shinya Kitaoka |
120a6e |
StyleType srcType, dstType;
|
|
Shinya Kitaoka |
120a6e |
// copied (source)
|
|
Shinya Kitaoka |
120a6e |
if (style->getGlobalName() == L"")
|
|
Shinya Kitaoka |
120a6e |
srcType = NORMALSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else if (style->getOriginalName() == L"")
|
|
Shinya Kitaoka |
120a6e |
srcType = STUDIOSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
srcType = LINKEDSTYLE;
|
|
Shinya Kitaoka |
120a6e |
// pasted (destination)
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *dstStyle = m_items[i]->m_oldStyle;
|
|
Shinya Kitaoka |
120a6e |
std::wstring dstGlobalName = dstStyle->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
std::wstring dstOriginalName = dstStyle->getOriginalName();
|
|
Shinya Kitaoka |
120a6e |
if (dstGlobalName == L"")
|
|
Shinya Kitaoka |
120a6e |
dstType = NORMALSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else if (dstOriginalName == L"")
|
|
Shinya Kitaoka |
120a6e |
dstType = STUDIOSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
dstType = LINKEDSTYLE;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
pasteValue(styleId, style);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Process the global and original names according to the pasted style
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *pastedStyle = getPalette()->getStyle(styleId);
|
|
Shinya Kitaoka |
120a6e |
if (srcType == NORMALSTYLE) {
|
|
Shinya Kitaoka |
120a6e |
if (dstType == NORMALSTYLE) {
|
|
Shinya Kitaoka |
120a6e |
} // 1. From normal to normal. Do nothing.
|
|
Shinya Kitaoka |
120a6e |
else if (dstType == STUDIOSTYLE) // 2. From normal to studio. Restore
|
|
Shinya Kitaoka |
120a6e |
// the global name
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setGlobalName(dstGlobalName);
|
|
Shinya Kitaoka |
120a6e |
else // dstType == LINKEDSTYLE //3. From normal to linked.
|
|
Shinya Kitaoka |
120a6e |
// Restore both the global and the original name. Activate the
|
|
Shinya Kitaoka |
120a6e |
// edited flag.
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setGlobalName(dstGlobalName);
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setOriginalName(dstOriginalName);
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setIsEditedFlag(true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else if (srcType == STUDIOSTYLE) {
|
|
Shinya Kitaoka |
120a6e |
if (dstType == NORMALSTYLE) // 4. From studio to normal. Set the studio
|
|
Shinya Kitaoka |
120a6e |
// style's name to the original name.
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setOriginalName(style->getName());
|
|
Shinya Kitaoka |
120a6e |
else if (dstType == STUDIOSTYLE) // 5. From studio to studio. Restore
|
|
Shinya Kitaoka |
120a6e |
// the global name.
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setGlobalName(dstGlobalName);
|
|
Shinya Kitaoka |
120a6e |
else // dstStyle == LINKEDSTYLE //6. From studio to
|
|
Shinya Kitaoka |
120a6e |
// linked. Set the studio style's name to the original name, and
|
|
Shinya Kitaoka |
120a6e |
// set the edited flag to off.
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setOriginalName(style->getName());
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setIsEditedFlag(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else // srcType == LINKEDSTYLE
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
if (dstType == NORMALSTYLE) {
|
|
Shinya Kitaoka |
120a6e |
} // 7. From linked to normal. Do nothing.
|
|
Shinya Kitaoka |
120a6e |
else if (dstType == STUDIOSTYLE) // 8. From linked to studio. Restore
|
|
Shinya Kitaoka |
120a6e |
// the global name. Delete the
|
|
Shinya Kitaoka |
120a6e |
// original name. Set the edited flag
|
|
Shinya Kitaoka |
120a6e |
// to off.
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setGlobalName(dstGlobalName);
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setOriginalName(L"");
|
|
Shinya Kitaoka |
120a6e |
pastedStyle->setIsEditedFlag(false);
|
|
Shinya Kitaoka |
38fd86 |
} else // dstStyle == LINKEDSTYLE //9. From linked to
|
|
Shinya Kitaoka |
38fd86 |
// linked.
|
|
Shinya Kitaoka |
120a6e |
// Do nothing (bring all information from the original).
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!m_pasteName) // devo settare al nuovo stile il vecchio nome
|
|
Shinya Kitaoka |
120a6e |
getPalette()->getStyle(styleId)->setName(oldName);
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, indexInPage, true);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (m_itemsInserted.size() != 0) {
|
|
Shinya Kitaoka |
120a6e |
StyleData *newData = new StyleData();
|
|
Shinya Kitaoka |
120a6e |
int j;
|
|
Shinya Kitaoka |
120a6e |
for (j = 0; j < (int)m_itemsInserted.size(); j++)
|
|
Shinya Kitaoka |
120a6e |
newData->addStyle(m_itemsInserted[j]->m_index,
|
|
Shinya Kitaoka |
120a6e |
m_itemsInserted[j]->m_newStyle->clone());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
pasteStylesDataWithoutUndo(getPalette(), m_paletteHandle, newData,
|
|
Shinya Kitaoka |
120a6e |
indexInPage + 1, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator styleIt;</int>
|
|
Shinya Kitaoka |
120a6e |
for (styleIt = styleIndicesInPage.begin();
|
|
Shinya Kitaoka |
120a6e |
styleIt != styleIndicesInPage.end(); ++styleIt)
|
|
Shinya Kitaoka |
120a6e |
m_selection->select(m_pageIndex, *styleIt, true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
delete newData;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection->makeCurrent();
|
|
Shinya Kitaoka |
120a6e |
// do not activate a dirty flag here in case that m_palette is not
|
|
Shinya Kitaoka |
120a6e |
// currentpalette
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(*this) + (int)m_items.size() * 100; // forfait
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
QString palNameStr =
|
|
Shinya Kitaoka |
120a6e |
QObject::tr(" to Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
if (m_pasteName && m_pasteColor)
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Paste Color && Name%1").arg(palNameStr);
|
|
Shinya Kitaoka |
120a6e |
else if (m_pasteName && !m_pasteColor)
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Paste Name%1").arg(palNameStr);
|
|
Shinya Kitaoka |
120a6e |
else if (!m_pasteName && m_pasteColor)
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Paste Color%1").arg(palNameStr);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Paste%1").arg(palNameStr);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::pasteStylesValues(bool pasteName, bool pasteColor) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
if (isSelected(m_pageIndex, 0) && page->getStyleId(0) == 0) {
|
|
Shinya Kitaoka |
120a6e |
error(QObject::tr("Can't modify color #0"));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const StyleData *data =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<const *="" styledata="">(QApplication::clipboard()->mimeData());</const>
|
|
Shinya Kitaoka |
120a6e |
if (!data) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int dataStyleCount = data->getStyleCount();
|
|
Shinya Kitaoka |
120a6e |
if (dataStyleCount > (int)m_styleIndicesInPage.size()) {
|
|
Shinya Kitaoka |
120a6e |
QString question = QObject::tr(
|
|
Shinya Kitaoka |
120a6e |
"There are more cut/copied styles than selected. Paste anyway (adding "
|
|
Shinya Kitaoka |
120a6e |
"styles)?");
|
|
Shinya Kitaoka |
120a6e |
int ret =
|
|
Shinya Kitaoka |
120a6e |
DVGui::MsgBox(question, QObject::tr("Paste"), QObject::tr("Cancel"), 0);
|
|
Shinya Kitaoka |
120a6e |
if (ret == 2 || ret == 0) return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
int i = 0;
|
|
Shinya Kitaoka |
120a6e |
UndoPasteValues *undo = new UndoPasteValues(this, pasteName, pasteColor);
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator it;</int>
|
|
Shinya Kitaoka |
120a6e |
int indexInPage = 0;
|
|
Shinya Kitaoka |
120a6e |
for (it = m_styleIndicesInPage.begin();
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end() && i < data->getStyleCount();
|
|
Shinya Kitaoka |
120a6e |
++it, i++) {
|
|
Shinya Kitaoka |
120a6e |
if (page->getStyleCount() < i) break;
|
|
Shinya Kitaoka |
120a6e |
indexInPage = *it;
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
undo->addItem(indexInPage, palette->getStyle(styleId), data->getStyle(i));
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *colorStyle = page->getStyle(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
std::wstring styleName = colorStyle->getName();
|
|
Shinya Kitaoka |
120a6e |
unsigned int flags = colorStyle->getFlags();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (pasteColor) {
|
|
Shinya Kitaoka |
120a6e |
// first, check out the types of copied and pasted styles
|
|
Shinya Kitaoka |
120a6e |
StyleType srcType, dstType;
|
|
Shinya Kitaoka |
120a6e |
// copied (source)
|
|
Shinya Kitaoka |
120a6e |
if (data->getStyle(i)->getGlobalName() == L"")
|
|
Shinya Kitaoka |
120a6e |
srcType = NORMALSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else if (data->getStyle(i)->getOriginalName() == L"")
|
|
Shinya Kitaoka |
120a6e |
srcType = STUDIOSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
srcType = LINKEDSTYLE;
|
|
Shinya Kitaoka |
120a6e |
// pasted (destination)
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *dstStyle = page->getStyle(indexInPage);
|
|
Shinya Kitaoka |
120a6e |
std::wstring dstGlobalName = dstStyle->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
std::wstring dstOriginalName = dstStyle->getOriginalName();
|
|
Shinya Kitaoka |
120a6e |
if (dstGlobalName == L"")
|
|
Shinya Kitaoka |
120a6e |
dstType = NORMALSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else if (dstOriginalName == L"")
|
|
Shinya Kitaoka |
120a6e |
dstType = STUDIOSTYLE;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
dstType = LINKEDSTYLE;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// For cleanup styles, do not duplicate the cleanup information. Just
|
|
Shinya Kitaoka |
120a6e |
// paste color information.
|
|
Shinya Kitaoka |
120a6e |
TCleanupStyle *cleanupStyle =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<tcleanupstyle *="">(data->getStyle(i));</tcleanupstyle>
|
|
Shinya Kitaoka |
120a6e |
if (cleanupStyle && !palette->isCleanupPalette())
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleId, cleanupStyle->getMainColor());
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(styleId, data->getStyle(i)->clone());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Process the global and original names according to the pasted style
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *pastedStyle = getPalette()->getStyle(styleId);
|
|
shun-iwasawa |
d84981 |
|
|
shun-iwasawa |
d84981 |
// If paste color and name are both ON, then paste the link information.
|
|
shun-iwasawa |
d84981 |
if (pasteName) {
|
|
shun-iwasawa |
d84981 |
if (srcType == NORMALSTYLE) {
|
|
shun-iwasawa |
d84981 |
if (dstType == NORMALSTYLE) {
|
|
shun-iwasawa |
d84981 |
} // 1. From normal to normal. Do nothing.
|
|
shun-iwasawa |
d84981 |
else if (dstType == STUDIOSTYLE) // 2. From normal to studio. Restore
|
|
shun-iwasawa |
d84981 |
// the global name
|
|
shun-iwasawa |
d84981 |
pastedStyle->setGlobalName(dstGlobalName);
|
|
shun-iwasawa |
d84981 |
else // dstType == LINKEDSTYLE //3. From normal to
|
|
shun-iwasawa |
d84981 |
// linked. Restore both the global and the original name.
|
|
shun-iwasawa |
d84981 |
// Activate the edited flag.
|
|
shun-iwasawa |
d84981 |
{
|
|
shun-iwasawa |
d84981 |
pastedStyle->setGlobalName(dstGlobalName);
|
|
shun-iwasawa |
d84981 |
pastedStyle->setOriginalName(dstOriginalName);
|
|
shun-iwasawa |
d84981 |
pastedStyle->setIsEditedFlag(true);
|
|
shun-iwasawa |
d84981 |
}
|
|
shun-iwasawa |
d84981 |
} else if (srcType == STUDIOSTYLE) {
|
|
shun-iwasawa |
d84981 |
if (dstType ==
|
|
shun-iwasawa |
d84981 |
NORMALSTYLE) // 4. From studio to normal. Set the studio
|
|
shun-iwasawa |
d84981 |
// style's name to the original name.
|
|
shun-iwasawa |
d84981 |
pastedStyle->setOriginalName(data->getStyle(i)->getName());
|
|
shun-iwasawa |
d84981 |
else if (dstType == STUDIOSTYLE) // 5. From studio to studio. Restore
|
|
shun-iwasawa |
d84981 |
// the global name.
|
|
shun-iwasawa |
d84981 |
pastedStyle->setGlobalName(dstGlobalName);
|
|
shun-iwasawa |
d84981 |
else // dstType == LINKEDSTYLE //6. From studio to
|
|
shun-iwasawa |
d84981 |
// linked. Set the studio style's name to the original name, and
|
|
shun-iwasawa |
d84981 |
// set the edited flag to off.
|
|
shun-iwasawa |
d84981 |
{
|
|
shun-iwasawa |
d84981 |
pastedStyle->setOriginalName(data->getStyle(i)->getName());
|
|
shun-iwasawa |
d84981 |
pastedStyle->setIsEditedFlag(false);
|
|
shun-iwasawa |
d84981 |
}
|
|
shun-iwasawa |
d84981 |
} else // srcType == LINKEDSTYLE
|
|
Shinya Kitaoka |
120a6e |
{
|
|
shun-iwasawa |
d84981 |
if (dstType == NORMALSTYLE) {
|
|
shun-iwasawa |
d84981 |
} // 7. From linked to normal. Do nothing.
|
|
shun-iwasawa |
d84981 |
else if (dstType == STUDIOSTYLE) // 8. From linked to studio. Restore
|
|
shun-iwasawa |
d84981 |
// the global name. Delete the
|
|
shun-iwasawa |
d84981 |
// original name. Set the edited
|
|
shun-iwasawa |
d84981 |
// flag to off.
|
|
shun-iwasawa |
d84981 |
{
|
|
shun-iwasawa |
d84981 |
pastedStyle->setGlobalName(dstGlobalName);
|
|
shun-iwasawa |
d84981 |
pastedStyle->setOriginalName(L"");
|
|
shun-iwasawa |
d84981 |
pastedStyle->setIsEditedFlag(false);
|
|
shun-iwasawa |
d84981 |
} else // dstType == LINKEDSTYLE //9. From linked to
|
|
shun-iwasawa |
d84981 |
// linked.
|
|
shun-iwasawa |
d84981 |
// Do nothing (bring all information from the original).
|
|
shun-iwasawa |
d84981 |
{
|
|
shun-iwasawa |
d84981 |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun-iwasawa |
d84981 |
// If paste color is ON and paste name is OFF, then revert the link
|
|
shun-iwasawa |
d84981 |
// information (i.e. "paste color" will paste color info only).
|
|
shun-iwasawa |
d84981 |
else { // !pasteName
|
|
shun-iwasawa |
d84981 |
pastedStyle->setGlobalName(dstGlobalName);
|
|
shun-iwasawa |
d84981 |
pastedStyle->setOriginalName(dstOriginalName);
|
|
shun-iwasawa |
dfb4bd |
pastedStyle->setIsEditedFlag(dstType == LINKEDSTYLE);
|
|
shun-iwasawa |
d84981 |
|
|
shun-iwasawa |
d84981 |
// put back the name
|
|
Shinya Kitaoka |
120a6e |
page->getStyle(indexInPage)->setName(styleName);
|
|
Shinya Kitaoka |
120a6e |
page->getStyle(indexInPage)->setFlags(flags);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// when "paste name"
|
|
Shinya Kitaoka |
120a6e |
if (pasteName)
|
|
Shinya Kitaoka |
120a6e |
page->getStyle(indexInPage)->setName(data->getStyle(i)->getName());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
d84981 |
// If the styles of the data are more than those selected, make a paste of the
|
|
shun-iwasawa |
d84981 |
// styles that remain, inserting the new styles after indexInPage
|
|
Shinya Kitaoka |
120a6e |
if (i < dataStyleCount) {
|
|
Shinya Kitaoka |
120a6e |
StyleData *newData = new StyleData();
|
|
Shinya Kitaoka |
120a6e |
int j;
|
|
Shinya Kitaoka |
120a6e |
for (j = i; j < dataStyleCount; j++)
|
|
Shinya Kitaoka |
120a6e |
newData->addStyle(data->getStyleIndex(j), data->getStyle(j)->clone());
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int> styleIndicesInPage;</int>
|
|
Shinya Kitaoka |
120a6e |
pasteStylesDataWithoutUndo(m_paletteHandle->getPalette(), m_paletteHandle,
|
|
Shinya Kitaoka |
120a6e |
newData, indexInPage + 1, m_pageIndex,
|
|
Shinya Kitaoka |
120a6e |
&styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
undo->addItemToInsert(styleIndicesInPage);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::set<int>::iterator styleIt;</int>
|
|
Shinya Kitaoka |
120a6e |
for (styleIt = styleIndicesInPage.begin();
|
|
Shinya Kitaoka |
120a6e |
styleIt != styleIndicesInPage.end(); ++styleIt)
|
|
Shinya Kitaoka |
120a6e |
m_styleIndicesInPage.insert(*styleIt);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
delete newData;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// clear cache(invalidate) of the level
|
|
Shinya Kitaoka |
120a6e |
if (m_levelHandle && m_levelHandle->getSimpleLevel() &&
|
|
Shinya Kitaoka |
120a6e |
!m_levelHandle->getSimpleLevel()->getProperties()->getDirtyFlag())
|
|
Shinya Kitaoka |
120a6e |
m_levelHandle->getSimpleLevel()->invalidateFrames();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// this is to redraw the style editor with colorStyleSwitched() signal
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->setStyleIndex(m_paletteHandle->getStyleIndex());
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::pasteStylesValue() { pasteStylesValues(true, true); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::pasteStylesColor() { pasteStylesValues(false, true); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::pasteStylesName() { pasteStylesValues(true, false); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// UndoBlendColor
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoBlendColor final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, *="" tcolorstyle="">> m_colorStyles;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
TPixel32 m_c0, m_c1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoBlendColor(TPaletteHandle *paletteHandle, int pageIndex,
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, *="" tcolorstyle="">> colorStyles,</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
const TPixel32 &c0, const TPixel32 &c1)
|
|
Shinya Kitaoka |
120a6e |
: m_paletteHandle(paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
, m_pageIndex(pageIndex)
|
|
Shinya Kitaoka |
120a6e |
, m_colorStyles(colorStyles)
|
|
Shinya Kitaoka |
120a6e |
, m_c0(c0)
|
|
Shinya Kitaoka |
120a6e |
, m_c1(c1) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~UndoBlendColor() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
if (!m_palette) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
int count = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (UINT i = 0; i < m_colorStyles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *st = page->getStyle(m_colorStyles[i].first);
|
|
Shinya Kitaoka |
120a6e |
QString gname = QString::fromStdWString(st->getGlobalName());
|
|
Shinya Kitaoka |
120a6e |
if (!gname.isEmpty() && gname[0] != L'-') continue;
|
|
Shinya Kitaoka |
120a6e |
m_palette->setStyle(page->getStyleId(m_colorStyles[i].first),
|
|
Shinya Kitaoka |
120a6e |
m_colorStyles[i].second->clone());
|
|
Shinya Kitaoka |
120a6e |
m_colorStyles[i].second->invalidateIcon();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// do not activate a dirty flag here in case that m_palette is not
|
|
Shinya Kitaoka |
120a6e |
// currentpalette
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
if (!m_palette) return;
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
for (UINT i = 0; i < m_colorStyles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(m_colorStyles[i].first);
|
|
Shinya Kitaoka |
120a6e |
QString gname = QString::fromStdWString(cs->getGlobalName());
|
|
Shinya Kitaoka |
120a6e |
if (!gname.isEmpty() && gname[0] != L'-') continue;
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
if (!cs) continue;
|
|
Shinya Kitaoka |
120a6e |
cs->setMainColor(
|
|
Shinya Kitaoka |
120a6e |
blend(m_c0, m_c1, (double)i / (double)(m_colorStyles.size() - 1)));
|
|
Shinya Kitaoka |
120a6e |
cs->invalidateIcon();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// do not activate a dirty flag here in case that m_palette is not
|
|
Shinya Kitaoka |
120a6e |
// currentpalette
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof(
|
|
Shinya Kitaoka |
120a6e |
*this); //+500*m_oldStyles.size(); //dipende da che stile ha salvato
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Blend Colors in Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::blendStyles() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
Shinya Kitaoka |
120a6e |
if (n < 2) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<tcolorstyle *=""> styles;</tcolorstyle>
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, *="" tcolorstyle="">> oldStyles;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(*it);
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
styles.push_back(cs);
|
|
Shinya Kitaoka |
120a6e |
oldStyles.push_back(std::pair<int, *="" tcolorstyle="">(*it, cs->clone()));</int,>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
assert(styles.size() >= 2);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPixel32 c0 = styles.front()->getMainColor();
|
|
Shinya Kitaoka |
120a6e |
TPixel32 c1 = styles.back()->getMainColor();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool areAllStyleLincked = true;
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 1; i < n - 1; i++) {
|
|
Shinya Kitaoka |
120a6e |
QString gname = QString::fromStdWString(styles[i]->getGlobalName());
|
|
Shinya Kitaoka |
120a6e |
if (!gname.isEmpty() && gname[0] != L'-') continue;
|
|
Shinya Kitaoka |
120a6e |
areAllStyleLincked = false;
|
|
Shinya Kitaoka |
120a6e |
styles[i]->setMainColor(blend(c0, c1, (double)i / (double)(n - 1)));
|
|
Shinya Kitaoka |
120a6e |
styles[i]->invalidateIcon();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (areAllStyleLincked) return;
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
UndoBlendColor *undo =
|
|
Shinya Kitaoka |
120a6e |
new UndoBlendColor(m_paletteHandle, m_pageIndex, oldStyles, c0, c1);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// UndoLinkToStudioPalette
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoLinkToStudioPalette final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
struct ColorStyleData {
|
|
Shinya Kitaoka |
120a6e |
int m_indexInPage;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *m_oldStyle;
|
|
Shinya Kitaoka |
120a6e |
std::wstring m_newName;
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
std::vector<colorstyledata> m_styles;</colorstyledata>
|
|
Shinya Kitaoka |
120a6e |
bool m_updateLinkedColors;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoLinkToStudioPalette(TPaletteHandle *paletteHandle, int pageIndex)
|
|
Shinya Kitaoka |
120a6e |
: m_paletteHandle(paletteHandle)
|
|
Shinya Kitaoka |
120a6e |
, m_pageIndex(pageIndex)
|
|
Shinya Kitaoka |
120a6e |
, m_updateLinkedColors(false) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~UndoLinkToStudioPalette() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setUpdateLinkedColors(bool updateLinkedColors) {
|
|
Shinya Kitaoka |
120a6e |
m_updateLinkedColors = updateLinkedColors;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setColorStyle(int indexInPage, TColorStyle *oldStyle,
|
|
Shinya Kitaoka |
120a6e |
std::wstring newName) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data;
|
|
Shinya Kitaoka |
120a6e |
data.m_indexInPage = indexInPage;
|
|
Shinya Kitaoka |
120a6e |
data.m_newName = newName;
|
|
Shinya Kitaoka |
120a6e |
data.m_oldStyle = oldStyle;
|
|
Shinya Kitaoka |
120a6e |
m_styles.push_back(data);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_styles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data = m_styles[i];
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(m_styles[i].m_indexInPage);
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *oldStyle = m_styles[i].m_oldStyle;
|
|
Shinya Kitaoka |
120a6e |
m_palette->setStyle(styleId, oldStyle->clone());
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(styleId)->assignNames(oldStyle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_styles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data = m_styles[i];
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(data.m_indexInPage);
|
|
Shinya Kitaoka |
120a6e |
cs->setGlobalName(data.m_newName);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
if (m_updateLinkedColors)
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->updateLinkedColors(m_palette.getPointer());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Toggle Link in Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::toggleLink() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Jeremy Bullock |
0b1ad7 |
if (isEmpty() || palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
Shinya Kitaoka |
120a6e |
if (n <= 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, std::wstring="">> oldColorStylesLinked;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, std::wstring="">> newColorStylesLinked;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
|
|
shun_iwasawa |
640862 |
bool somethingHasBeenLinked = false;
|
|
shun_iwasawa |
640862 |
bool somethingChanged = false;
|
|
Shinya Kitaoka |
120a6e |
bool currentStyleIsInSelection = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
UndoLinkToStudioPalette *undo =
|
|
Shinya Kitaoka |
120a6e |
new UndoLinkToStudioPalette(m_paletteHandle, m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
int index = *it;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(index);
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
std::wstring name = cs->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *oldCs = cs->clone();
|
|
Shinya Kitaoka |
120a6e |
if (name != L"" && (name[0] == L'-' || name[0] == L'+')) {
|
|
Shinya Kitaoka |
120a6e |
name[0] = name[0] == L'-' ? L'+' : L'-';
|
|
Shinya Kitaoka |
120a6e |
cs->setGlobalName(name);
|
|
Shinya Kitaoka |
120a6e |
if (name[0] == L'+') somethingHasBeenLinked = true;
|
|
shun-iwasawa |
b37337 |
somethingChanged = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
undo->setColorStyle(index, oldCs, name);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (*it ==
|
|
Shinya Kitaoka |
120a6e |
palette->getPage(m_pageIndex)->search(m_paletteHandle->getStyleIndex()))
|
|
Shinya Kitaoka |
120a6e |
currentStyleIsInSelection = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
shun_iwasawa |
640862 |
|
|
shun_iwasawa |
640862 |
// if nothing changed, do not set dirty flag, nor register undo
|
|
shun_iwasawa |
640862 |
if (!somethingChanged) {
|
|
shun_iwasawa |
640862 |
delete undo;
|
|
shun_iwasawa |
640862 |
return;
|
|
shun_iwasawa |
640862 |
}
|
|
shun_iwasawa |
640862 |
|
|
Shinya Kitaoka |
120a6e |
if (somethingHasBeenLinked)
|
|
Shinya Kitaoka |
120a6e |
StudioPalette::instance()->updateLinkedColors(palette);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (currentStyleIsInSelection) m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
undo->setUpdateLinkedColors(somethingHasBeenLinked);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::eraseToggleLink() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Jeremy Bullock |
0b1ad7 |
if (isEmpty() || palette->isLocked()) return;
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
Shinya Kitaoka |
120a6e |
if (n <= 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool currentStyleIsInSelection = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, std::wstring="">> oldColorStylesLinked;</std::pair<int,>
|
|
Shinya Kitaoka |
120a6e |
std::vector<std::pair<int, std::wstring="">> newColorStylesLinked;</std::pair<int,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
UndoLinkToStudioPalette *undo =
|
|
Shinya Kitaoka |
120a6e |
new UndoLinkToStudioPalette(m_paletteHandle, m_pageIndex);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
int index = *it;
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(index);
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *oldCs = cs->clone();
|
|
Shinya Kitaoka |
120a6e |
std::wstring name = cs->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
if (name != L"" && (name[0] == L'-' || name[0] == L'+'))
|
|
Shinya Kitaoka |
120a6e |
cs->setGlobalName(L"");
|
|
Shinya Kitaoka |
120a6e |
undo->setColorStyle(index, oldCs, L"");
|
|
Shinya Kitaoka |
120a6e |
if (*it ==
|
|
Shinya Kitaoka |
120a6e |
palette->getPage(m_pageIndex)->search(m_paletteHandle->getStyleIndex()))
|
|
Shinya Kitaoka |
120a6e |
currentStyleIsInSelection = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (currentStyleIsInSelection) m_paletteHandle->notifyColorStyleSwitched();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::toggleKeyframe(int frame) {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(*it);
|
|
Shinya Kitaoka |
120a6e |
palette->setKeyframe(styleId, frame);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
d1f6c4 |
class UndoRemoveLink final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TPaletteHandle *m_paletteHandle;
|
|
Shinya Kitaoka |
120a6e |
TPaletteP m_palette;
|
|
Shinya Kitaoka |
120a6e |
int m_pageIndex;
|
|
Shinya Kitaoka |
120a6e |
struct ColorStyleData {
|
|
Shinya Kitaoka |
120a6e |
int m_indexInPage;
|
|
Shinya Kitaoka |
120a6e |
std::wstring m_oldGlobalName;
|
|
Shinya Kitaoka |
120a6e |
std::wstring m_oldOriginalName;
|
|
Shinya Kitaoka |
120a6e |
bool m_oldEdittedFlag;
|
|
Shinya Kitaoka |
120a6e |
};
|
|
Shinya Kitaoka |
120a6e |
std::vector<colorstyledata> m_styles;</colorstyledata>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
UndoRemoveLink(TPaletteHandle *paletteHandle, int pageIndex)
|
|
Shinya Kitaoka |
120a6e |
: m_paletteHandle(paletteHandle), m_pageIndex(pageIndex) {
|
|
Shinya Kitaoka |
120a6e |
m_palette = m_paletteHandle->getPalette();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~UndoRemoveLink() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setColorStyle(int indexInPage, TColorStyle *oldStyle) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data;
|
|
Shinya Kitaoka |
120a6e |
data.m_indexInPage = indexInPage;
|
|
Shinya Kitaoka |
120a6e |
data.m_oldGlobalName = oldStyle->getGlobalName();
|
|
Shinya Kitaoka |
120a6e |
data.m_oldOriginalName = oldStyle->getOriginalName();
|
|
Shinya Kitaoka |
120a6e |
data.m_oldEdittedFlag = oldStyle->getIsEditedFlag();
|
|
Shinya Kitaoka |
120a6e |
m_styles.push_back(data);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_styles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data = m_styles[i];
|
|
Shinya Kitaoka |
120a6e |
int styleId = page->getStyleId(m_styles[i].m_indexInPage);
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(styleId)->setGlobalName(data.m_oldGlobalName);
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(styleId)->setOriginalName(data.m_oldOriginalName);
|
|
Shinya Kitaoka |
120a6e |
m_palette->getStyle(styleId)->setIsEditedFlag(data.m_oldEdittedFlag);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override {
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = m_palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
int i;
|
|
Shinya Kitaoka |
120a6e |
for (i = 0; i < (int)m_styles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
ColorStyleData data = m_styles[i];
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(data.m_indexInPage);
|
|
Shinya Kitaoka |
120a6e |
cs->setGlobalName(L"");
|
|
Shinya Kitaoka |
120a6e |
cs->setOriginalName(L"");
|
|
Shinya Kitaoka |
120a6e |
cs->setIsEditedFlag(false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override { return sizeof(*this); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
shun_iwasawa |
640862 |
return QObject::tr("Remove Reference in Palette : %1")
|
|
Shinya Kitaoka |
120a6e |
.arg(QString::fromStdWString(m_palette->getPaletteName()));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
luz paz |
6454c4 |
/*! remove link from studio palette. Delete the global and the original names.
|
|
Shinya Kitaoka |
120a6e |
* return true if something changed
|
|
shun-iwasawa |
b37337 |
*/
|
|
shun_iwasawa |
640862 |
void TStyleSelection::removeLink() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
shun_iwasawa |
640862 |
if (!palette || m_pageIndex < 0) return;
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
shun_iwasawa |
640862 |
if (n <= 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool somethingChanged = false;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
UndoRemoveLink *undo = new UndoRemoveLink(m_paletteHandle, m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(*it);
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (cs->getGlobalName() != L"" || cs->getOriginalName() != L"") {
|
|
Shinya Kitaoka |
120a6e |
undo->setColorStyle(*it, cs);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
cs->setGlobalName(L"");
|
|
Shinya Kitaoka |
120a6e |
cs->setOriginalName(L"");
|
|
Shinya Kitaoka |
120a6e |
cs->setIsEditedFlag(false);
|
|
Shinya Kitaoka |
120a6e |
somethingChanged = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (somethingChanged) {
|
|
shun_iwasawa |
640862 |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
delete undo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Shinya Kitaoka |
d1f6c4 |
class getBackOriginalStyleUndo final : public TUndo {
|
|
Shinya Kitaoka |
120a6e |
TStyleSelection m_selection;
|
|
Shinya Kitaoka |
120a6e |
std::vector<tpixel32> m_oldColors, m_newColors;</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// remember the edited flags
|
|
Shinya Kitaoka |
120a6e |
std::vector<bool> m_oldEditedFlags, m_newEditedFlags;</bool>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
getBackOriginalStyleUndo(const TStyleSelection &selection)
|
|
Shinya Kitaoka |
120a6e |
: m_selection(selection) {
|
|
Shinya Kitaoka |
120a6e |
getColors(m_oldColors, m_oldEditedFlags);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
~getBackOriginalStyleUndo() {}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void getStyles(std::vector<tcolorstyle *=""> &styles,</tcolorstyle>
|
|
Shinya Kitaoka |
120a6e |
const TStyleSelection &selection) const {
|
|
Shinya Kitaoka |
120a6e |
styles.clear();
|
|
Shinya Kitaoka |
120a6e |
int pageIndex = selection.getPageIndex();
|
|
Shinya Kitaoka |
120a6e |
TPaletteP palette = selection.getPalette();
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(pageIndex);
|
|
Shinya Kitaoka |
120a6e |
if (!page) return;
|
|
Shinya Kitaoka |
120a6e |
std::set<int> indices = selection.getIndicesInPage();</int>
|
|
Shinya Kitaoka |
120a6e |
// non si puo' modificare il BG
|
|
Shinya Kitaoka |
120a6e |
if (pageIndex == 0) indices.erase(0);
|
|
Shinya Kitaoka |
120a6e |
styles.reserve(indices.size());
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = indices.begin(); it != indices.end();</int>
|
|
Shinya Kitaoka |
120a6e |
++it)
|
|
Shinya Kitaoka |
120a6e |
styles.push_back(page->getStyle(*it));
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
int getSize() const override {
|
|
Shinya Kitaoka |
120a6e |
return sizeof *this +
|
|
Shinya Kitaoka |
120a6e |
(m_oldColors.size() + m_newColors.size()) * sizeof(TPixel32);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void onAdd() override { getColors(m_newColors, m_newEditedFlags); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void getColors(std::vector<tpixel32> &colors,</tpixel32>
|
|
Shinya Kitaoka |
120a6e |
std::vector<bool> &flags) const {</bool>
|
|
Shinya Kitaoka |
120a6e |
std::vector<tcolorstyle *=""> styles;</tcolorstyle>
|
|
Shinya Kitaoka |
120a6e |
getStyles(styles, m_selection);
|
|
Shinya Kitaoka |
120a6e |
colors.resize(styles.size());
|
|
Shinya Kitaoka |
120a6e |
flags.resize(styles.size());
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < (int)styles.size(); i++) {
|
|
Shinya Kitaoka |
120a6e |
colors[i] = styles[i]->getMainColor();
|
|
Shinya Kitaoka |
120a6e |
flags[i] = styles[i]->getIsEditedFlag();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
void setColors(const std::vector<tpixel32> &colors,</tpixel32>
|
|
Shinya Kitaoka |
120a6e |
const std::vector<bool> &flags) const {</bool>
|
|
Shinya Kitaoka |
120a6e |
std::vector<tcolorstyle *=""> styles;</tcolorstyle>
|
|
Shinya Kitaoka |
120a6e |
getStyles(styles, m_selection);
|
|
Shinya Kitaoka |
120a6e |
int n = std::min(styles.size(), colors.size());
|
|
Shinya Kitaoka |
120a6e |
for (int i = 0; i < n; i++) {
|
|
Shinya Kitaoka |
120a6e |
QString gname = QString::fromStdWString(styles[i]->getGlobalName());
|
|
Shinya Kitaoka |
120a6e |
if (!gname.isEmpty() && gname[0] != L'-') continue;
|
|
Shinya Kitaoka |
120a6e |
styles[i]->setMainColor(colors[i]);
|
|
Shinya Kitaoka |
120a6e |
styles[i]->setIsEditedFlag(flags[i]);
|
|
Shinya Kitaoka |
120a6e |
styles[i]->invalidateIcon();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_selection.getPaletteHandle()->notifyColorStyleChanged(false, false);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void undo() const override { setColors(m_oldColors, m_oldEditedFlags); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
void redo() const override { setColors(m_newColors, m_newEditedFlags); }
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
473e70 |
QString getHistoryString() override {
|
|
Shinya Kitaoka |
120a6e |
return QObject::tr("Get Color from Studio Palette");
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
473e70 |
int getHistoryType() override { return HistoryType::Palette; }
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! get the color from the linked style of the studio palette
|
|
shun-iwasawa |
b37337 |
*/
|
|
Shinya Kitaoka |
120a6e |
void TStyleSelection::getBackOriginalStyle() {
|
|
Shinya Kitaoka |
120a6e |
TPalette *palette = getPalette();
|
|
Shinya Kitaoka |
120a6e |
if (!palette || m_pageIndex < 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (isEmpty() || palette->isLocked()) return; // 110804 iwasawa
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int n = m_styleIndicesInPage.size();
|
|
Shinya Kitaoka |
120a6e |
if (n <= 0) return;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
Shinya Kitaoka |
120a6e |
assert(page);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
bool somethingChanged = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::map<std::wstring, tpalettep=""> table;</std::wstring,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TUndo *undo = new getBackOriginalStyleUndo(this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// for each selected style
|
|
Shinya Kitaoka |
120a6e |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
Shinya Kitaoka |
120a6e |
it != m_styleIndicesInPage.end(); ++it) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *cs = page->getStyle(*it);
|
|
Shinya Kitaoka |
120a6e |
assert(cs);
|
|
Shinya Kitaoka |
120a6e |
std::wstring gname = cs->getGlobalName();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// if the style has no link
|
|
Shinya Kitaoka |
120a6e |
if (gname == L"") continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// Find the palette from the table
|
|
Shinya Kitaoka |
120a6e |
int k = gname.find_first_of(L'-', 1);
|
|
Shinya Kitaoka |
120a6e |
if (k == (int)std::wstring::npos) continue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::wstring paletteId = gname.substr(1, k - 1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
std::map<std::wstring, tpalettep="">::iterator palIt;</std::wstring,>
|
|
Shinya Kitaoka |
120a6e |
palIt = table.find(paletteId);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPalette *spPalette = 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// If not found in the table, then search for a new studio palette.
|
|
Shinya Kitaoka |
120a6e |
if (palIt == table.end()) {
|
|
Shinya Kitaoka |
120a6e |
spPalette = StudioPalette::instance()->getPalette(paletteId);
|
|
Shinya Kitaoka |
120a6e |
if (!spPalette) continue;
|
|
Shinya Kitaoka |
120a6e |
table[paletteId] = spPalette;
|
|
Shinya Kitaoka |
120a6e |
assert(spPalette->getRefCount() == 1);
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
spPalette = palIt->second.getPointer();
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
3bb469 |
// j is StyleID
|
|
Shinya Kitaoka |
120a6e |
int j = std::stoi(gname.substr(k + 1));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (spPalette && 0 <= j && j < spPalette->getStyleCount()) {
|
|
Shinya Kitaoka |
120a6e |
TColorStyle *spStyle = spPalette->getStyle(j);
|
|
Shinya Kitaoka |
120a6e |
assert(spStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// edit flag is also copied here
|
|
Shinya Kitaoka |
120a6e |
spStyle = spStyle->clone();
|
|
Shinya Kitaoka |
120a6e |
spStyle->setGlobalName(gname);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// get the original name from the studio palette
|
|
Shinya Kitaoka |
120a6e |
spStyle->setOriginalName(spStyle->getName());
|
|
Shinya Kitaoka |
120a6e |
// do not change the style name
|
|
Shinya Kitaoka |
120a6e |
spStyle->setName(cs->getName());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
palette->setStyle(page->getStyleId(*it), spStyle);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
somethingChanged = true;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (somethingChanged) {
|
|
Shinya Kitaoka |
120a6e |
palette->setDirtyFlag(true);
|
|
Shinya Kitaoka |
120a6e |
TUndoManager::manager()->add(undo);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleChanged(false);
|
|
Shinya Kitaoka |
120a6e |
m_paletteHandle->notifyColorStyleSwitched();
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
delete undo;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
shun_iwasawa |
9f19cf |
|
|
shun_iwasawa |
9f19cf |
//-----------------------------------------------------------------------------
|
|
shun_iwasawa |
9f19cf |
/*! return true if there is at least one linked style in the selection
|
|
shun-iwasawa |
b37337 |
*/
|
|
shun_iwasawa |
9f19cf |
|
|
shun_iwasawa |
9f19cf |
bool TStyleSelection::hasLinkedStyle() {
|
|
shun_iwasawa |
9f19cf |
TPalette *palette = getPalette();
|
|
shun_iwasawa |
9f19cf |
if (!palette || m_pageIndex < 0 || isEmpty()) return false;
|
|
shun_iwasawa |
9f19cf |
if (m_styleIndicesInPage.size() <= 0) return false;
|
|
shun_iwasawa |
9f19cf |
|
|
shun_iwasawa |
9f19cf |
TPalette::Page *page = palette->getPage(m_pageIndex);
|
|
shun_iwasawa |
9f19cf |
assert(page);
|
|
shun_iwasawa |
9f19cf |
|
|
shun_iwasawa |
9f19cf |
// for each selected style
|
|
shun_iwasawa |
9f19cf |
for (std::set<int>::iterator it = m_styleIndicesInPage.begin();</int>
|
|
shun_iwasawa |
9f19cf |
it != m_styleIndicesInPage.end(); ++it) {
|
|
shun_iwasawa |
9f19cf |
TColorStyle *cs = page->getStyle(*it);
|
|
shun_iwasawa |
9f19cf |
std::wstring gname = cs->getGlobalName();
|
|
shun_iwasawa |
9f19cf |
// if the style has link, return true
|
|
shun_iwasawa |
9f19cf |
if (gname != L"" && (gname[0] == L'-' || gname[0] == L'+')) return true;
|
|
shun_iwasawa |
9f19cf |
}
|
|
shun_iwasawa |
9f19cf |
return false;
|
|
shun_iwasawa |
9f19cf |
}
|