Skip to content

Commit

Permalink
Merge pull request #1262 from davidlamhauge/issue1174_palette_import_…
Browse files Browse the repository at this point in the history
…open

#1174 More consistent palette import behavior
  • Loading branch information
candyface authored Jan 6, 2020
2 parents 11cc918 + 662c9f0 commit 9ad6c32
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 37 deletions.
69 changes: 42 additions & 27 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ void MainWindow2::createMenus()
connect(ui->actionImport_Movie, &QAction::triggered, this, &MainWindow2::importMovie);

connect(ui->actionImport_Sound, &QAction::triggered, mCommands, &ActionCommands::importSound);
connect(ui->actionImport_Palette, &QAction::triggered, this, &MainWindow2::importPalette);
connect(ui->actionImport_Append_Palette, &QAction::triggered, this, &MainWindow2::importPalette);
connect(ui->actionImport_Replace_Palette, &QAction::triggered, this, &MainWindow2::openPalette);

//--- Edit Menu ---
connect(ui->actionUndo, &QAction::triggered, mEditor, &Editor::undo);
Expand Down Expand Up @@ -1062,7 +1063,7 @@ void MainWindow2::setupKeyboardShortcuts()
ui->actionImport_Image->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE));
ui->actionImport_ImageSeq->setShortcut(cmdKeySeq(CMD_IMPORT_IMAGE_SEQ));
ui->actionImport_Movie->setShortcut(cmdKeySeq(CMD_IMPORT_MOVIE));
ui->actionImport_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE));
ui->actionImport_Append_Palette->setShortcut(cmdKeySeq(CMD_IMPORT_PALETTE));
ui->actionImport_Sound->setShortcut(cmdKeySeq(CMD_IMPORT_SOUND));

ui->actionExport_Image->setShortcut(cmdKeySeq(CMD_EXPORT_IMAGE));
Expand Down Expand Up @@ -1226,6 +1227,44 @@ void MainWindow2::importPalette()
}
}

void MainWindow2::openPalette()
{
int count = 0;
int maxNumber = mEditor->object()->getColourCount();
bool openPalette = true;
while (count < maxNumber)
{
if (mEditor->object()->isColourInUse(count))
{
QMessageBox msgBox;
msgBox.setText(tr("Opening palette, will replace the old palette.\n"
"Color(s) in strokes will be altered by this action!\n"));
msgBox.addButton(tr("Open Palette"), QMessageBox::AcceptRole);
msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);

int ret = msgBox.exec();
if (ret == QMessageBox::RejectRole)
{
openPalette = false;
}
count = maxNumber;
}
count++;
}

if (openPalette)
{
FileDialog fileDialog(this);
QString filePath = fileDialog.openFile(FileType::PALETTE);
if (!filePath.isEmpty())
{
mEditor->object()->openPalette(filePath);
mColorPalette->refreshColorList();
mEditor->color()->setColorNumber(0);
}
}
}

void MainWindow2::makeConnections(Editor* editor)
{
connect(editor, &Editor::updateBackup, this, &MainWindow2::updateSaveState);
Expand Down Expand Up @@ -1355,31 +1394,7 @@ void MainWindow2::changePlayState(bool isPlaying)
}
update();
}
/*
void MainWindow2::alignPegs()
{
QStringList bitmaplayers;
bitmaplayers = mPegreg->getLayerList();
if (bitmaplayers.isEmpty())
{
QMessageBox::information(this, nullptr,
tr("No layers selected!"),
QMessageBox::Ok);
}
else
{
Status::StatusInt statusint = mEditor->pegBarAlignment(bitmaplayers);
if (statusint.errorcode == Status::FAIL)
{
QMessageBox::information(this, nullptr,
tr("Peg bar alignment failed!"),
QMessageBox::Ok);
return;
}
closePegReg();
}
}
*/

void MainWindow2::displayMessageBox(const QString& title, const QString& body)
{
QMessageBox::information(this, tr(qPrintable(title)), tr(qPrintable(body)), QMessageBox::Ok);
Expand Down
1 change: 1 addition & 0 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private slots:
void clearKeyboardShortcuts();
void updateZoomLabel();

void openPalette();
void importPalette();
void exportPalette();

Expand Down
27 changes: 19 additions & 8 deletions app/ui/mainwindow2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>26</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -69,7 +69,8 @@
<addaction name="actionImportLayers_from_pclx"/>
<addaction name="actionImport_Sound"/>
<addaction name="separator"/>
<addaction name="actionImport_Palette"/>
<addaction name="actionImport_Replace_Palette"/>
<addaction name="actionImport_Append_Palette"/>
</widget>
<widget class="QMenu" name="menuExport">
<property name="title">
Expand Down Expand Up @@ -321,7 +322,7 @@
</action>
<action name="actionExport_Palette">
<property name="text">
<string>Palette...</string>
<string>Palette</string>
</property>
</action>
<action name="actionImport_Image">
Expand All @@ -347,11 +348,6 @@
<string>Sound...</string>
</property>
</action>
<action name="actionImport_Palette">
<property name="text">
<string>Palette...</string>
</property>
</action>
<action name="actionImport_ImageSeqNum">
<property name="text">
<string>Image Predefined set...</string>
Expand Down Expand Up @@ -991,6 +987,21 @@
<string>Peg bar Alignment</string>
</property>
</action>
<action name="actionImport_Append_Palette">
<property name="text">
<string>Append to Palette...</string>
</property>
</action>
<action name="actionImport_Replace_Palette">
<property name="text">
<string>Replace Palette...</string>
</property>
</action>
<action name="actionExport_Other_Palette_formats">
<property name="text">
<string>Other Palette format...</string>
</property>
</action>
<action name="actionChangeLineColorCurrent_keyframe">
<property name="text">
<string>Current keyframe</string>
Expand Down
15 changes: 14 additions & 1 deletion core_lib/src/structure/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ void Object::importPalettePencil(QFile& file)
QDomDocument doc;
doc.setContent(&file);

mPalette.clear();
QDomElement docElem = doc.documentElement();
QDomNode tag = docElem.firstChild();
while (!tag.isNull())
Expand All @@ -560,6 +559,20 @@ void Object::importPalettePencil(QFile& file)
}
}

void Object::openPalette(QString filePath)
{
if (!QFile::exists(filePath))
{
return;
}

mPalette.clear();
importPalette(filePath);
}

/*
* Imports palette, e.g. appends to palette
*/
bool Object::importPalette(QString filePath)
{
QFile file(filePath);
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/structure/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Object : public QObject
bool importPalette(QString filePath);
void importPaletteGPL(QFile& file);
void importPalettePencil(QFile& file);
void openPalette(QString filePath);

bool exportPalette(QString filePath);
void exportPaletteGPL(QFile& file);
Expand Down
1 change: 0 additions & 1 deletion core_lib/src/util/fileformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ GNU General Public License for more details.
#define PFF_DEFAULT_PALETTE_EXT \
QString(".xml")


#define PFF_OLD_DATA_DIR "data"
#define PFF_DATA_DIR "data"
#define PFF_XML_FILE_NAME "main.xml"
Expand Down

0 comments on commit 9ad6c32

Please sign in to comment.