mirror of
https://github.com/leozide/leocad.git
synced 2026-10-26 22:10:32 +00:00
Explain piece selection, template persistence, palette management, and online inventory imports with tooltips and contextual Help/F1 support. Link minifigure labels to their selectors and give unlabeled controls accessible names. Rename the inventory dialog to Import Set Inventory to describe its action. Show None for initially omitted minifigure pieces so selectors agree with the preview. Refresh catalogs while preserving existing translations and leaving new help untranslated. Validation: debug build, all 17 initial minifigure selections, 47 generated controls, 17 label buddies, eight F1 routes, Help/Escape behavior, and catalog preservation checks passed.
193 lines
5.6 KiB
C++
193 lines
5.6 KiB
C++
#include "lc_global.h"
|
|
#include "lc_qutils.h"
|
|
#include "lc_partpalettedialog.h"
|
|
#include "ui_lc_partpalettedialog.h"
|
|
#include "lc_partselectionwidget.h"
|
|
#include "lc_setsdatabasedialog.h"
|
|
#include "project.h"
|
|
|
|
lcPartPaletteDialog::lcPartPaletteDialog(QWidget* Parent, std::vector<lcPartPalette>& PartPalettes)
|
|
: QDialog(Parent), ui(new Ui::lcPartPaletteDialog), mPartPalettes(PartPalettes)
|
|
{
|
|
ui->setupUi(this);
|
|
lcSetupDialogHelp(this, ui->buttonBox);
|
|
|
|
connect(ui->NewButton, &QPushButton::clicked, this, &lcPartPaletteDialog::NewButtonClicked);
|
|
connect(ui->DeleteButton, &QPushButton::clicked, this, &lcPartPaletteDialog::DeleteButtonClicked);
|
|
connect(ui->RenameButton, &QPushButton::clicked, this, &lcPartPaletteDialog::RenameButtonClicked);
|
|
connect(ui->ImportButton, &QPushButton::clicked, this, &lcPartPaletteDialog::ImportButtonClicked);
|
|
connect(ui->MoveUpButton, &QPushButton::clicked, this, &lcPartPaletteDialog::MoveUpButtonClicked);
|
|
connect(ui->MoveDownButton, &QPushButton::clicked, this, &lcPartPaletteDialog::MoveDownButtonClicked);
|
|
connect(ui->PaletteList, QOverload<int>::of(&QListWidget::currentRowChanged), this, &lcPartPaletteDialog::PaletteListCurrentRowChanged);
|
|
|
|
for (const lcPartPalette& Palette : PartPalettes)
|
|
{
|
|
QListWidgetItem* Item = new QListWidgetItem(Palette.Name);
|
|
Item->setData(Qt::UserRole, QVariant::fromValue<uintptr_t>(reinterpret_cast<uintptr_t>(&Palette)));
|
|
ui->PaletteList->addItem(Item);
|
|
}
|
|
|
|
ui->PaletteList->setCurrentRow(0);
|
|
UpdateButtons();
|
|
}
|
|
|
|
lcPartPaletteDialog::~lcPartPaletteDialog()
|
|
{
|
|
for (lcPartPalette* Palette : mImportedPalettes)
|
|
delete Palette;
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void lcPartPaletteDialog::UpdateButtons()
|
|
{
|
|
int CurrentPalette = ui->PaletteList->currentRow();
|
|
int PaletteCount = ui->PaletteList->count();
|
|
|
|
ui->DeleteButton->setEnabled(PaletteCount > 1);
|
|
ui->MoveUpButton->setEnabled(PaletteCount > 1 && CurrentPalette > 0);
|
|
ui->MoveDownButton->setEnabled(PaletteCount > 1 && CurrentPalette < PaletteCount - 1);
|
|
}
|
|
|
|
void lcPartPaletteDialog::accept()
|
|
{
|
|
std::vector<lcPartPalette> PartPalettes;
|
|
PartPalettes.reserve(ui->PaletteList->count());
|
|
|
|
for (int ItemIdx = 0; ItemIdx < ui->PaletteList->count(); ItemIdx++)
|
|
{
|
|
QListWidgetItem* Item = ui->PaletteList->item(ItemIdx);
|
|
lcPartPalette* OldPalette = reinterpret_cast<lcPartPalette*>(Item->data(Qt::UserRole).value<uintptr_t>());
|
|
|
|
lcPartPalette Palette;
|
|
Palette.Name = Item->text();
|
|
if (OldPalette)
|
|
Palette.Parts = std::move(OldPalette->Parts);
|
|
|
|
PartPalettes.emplace_back(std::move(Palette));
|
|
}
|
|
|
|
mPartPalettes = std::move(PartPalettes);
|
|
|
|
QDialog::accept();
|
|
}
|
|
|
|
void lcPartPaletteDialog::NewButtonClicked()
|
|
{
|
|
bool Ok = false;
|
|
|
|
QString Name = QInputDialog::getText(this, tr("New Piece Palette"), tr("Palette Name:"), QLineEdit::Normal, QString(), &Ok);
|
|
|
|
if (!Ok || Name.isEmpty())
|
|
return;
|
|
|
|
QListWidgetItem* Item = new QListWidgetItem(Name);
|
|
Item->setData(Qt::UserRole, QVariant::fromValue<uintptr_t>(0));
|
|
ui->PaletteList->addItem(Item);
|
|
ui->PaletteList->setCurrentRow(ui->PaletteList->count() - 1);
|
|
UpdateButtons();
|
|
}
|
|
|
|
void lcPartPaletteDialog::DeleteButtonClicked()
|
|
{
|
|
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
|
|
|
if (SelectedItems.isEmpty())
|
|
return;
|
|
|
|
QString Prompt = tr("Are you sure you want to delete the palette '%1'?").arg(SelectedItems[0]->text());
|
|
if (QMessageBox::question(this, tr("Delete Piece Palette"), Prompt, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
|
|
return;
|
|
|
|
QListWidgetItem* SelectedItem = SelectedItems.first();
|
|
|
|
delete SelectedItem;
|
|
UpdateButtons();
|
|
}
|
|
|
|
void lcPartPaletteDialog::RenameButtonClicked()
|
|
{
|
|
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
|
|
|
if (SelectedItems.isEmpty())
|
|
return;
|
|
|
|
bool Ok = false;
|
|
|
|
QString Name = SelectedItems[0]->text();
|
|
Name = QInputDialog::getText(this, tr("Rename Piece Palette"), tr("Palette Name:"), QLineEdit::Normal, Name, &Ok);
|
|
|
|
if (!Ok || Name.isEmpty())
|
|
return;
|
|
|
|
if (!Name.isEmpty())
|
|
SelectedItems[0]->setText(Name);
|
|
}
|
|
|
|
void lcPartPaletteDialog::ImportButtonClicked()
|
|
{
|
|
lcSetsDatabaseDialog Dialog(this);
|
|
|
|
if (Dialog.exec() != QDialog::Accepted)
|
|
return;
|
|
|
|
lcPartPalette* Palette = new lcPartPalette;
|
|
Palette->Name = Dialog.GetSetDescription();
|
|
mImportedPalettes.push_back(Palette);
|
|
|
|
std::vector<lcSetInventoryItem> Inventory = Dialog.GetSetInventory();
|
|
|
|
for (const lcSetInventoryItem& Item : Inventory)
|
|
{
|
|
Palette->Parts.push_back(Item.PartID.toUpper().toStdString() + ".DAT");
|
|
}
|
|
|
|
QListWidgetItem* Item = new QListWidgetItem(Palette->Name);
|
|
Item->setData(Qt::UserRole, QVariant::fromValue<uintptr_t>(reinterpret_cast<uintptr_t>(Palette)));
|
|
ui->PaletteList->addItem(Item);
|
|
ui->PaletteList->setCurrentRow(ui->PaletteList->count() - 1);
|
|
UpdateButtons();
|
|
}
|
|
|
|
void lcPartPaletteDialog::MoveUpButtonClicked()
|
|
{
|
|
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
|
|
|
if (SelectedItems.isEmpty())
|
|
return;
|
|
|
|
QListWidgetItem* Item = SelectedItems[0];
|
|
int Row = ui->PaletteList->row(Item);
|
|
|
|
if (Row == 0)
|
|
return;
|
|
|
|
ui->PaletteList->takeItem(Row);
|
|
ui->PaletteList->insertItem(Row - 1, Item);
|
|
ui->PaletteList->setCurrentItem(Item);
|
|
UpdateButtons();
|
|
}
|
|
|
|
void lcPartPaletteDialog::MoveDownButtonClicked()
|
|
{
|
|
QList<QListWidgetItem*> SelectedItems = ui->PaletteList->selectedItems();
|
|
|
|
if (SelectedItems.isEmpty())
|
|
return;
|
|
|
|
QListWidgetItem* Item = SelectedItems[0];
|
|
int Row = ui->PaletteList->row(Item);
|
|
|
|
ui->PaletteList->takeItem(Row);
|
|
ui->PaletteList->insertItem(Row + 1, Item);
|
|
ui->PaletteList->setCurrentItem(Item);
|
|
UpdateButtons();
|
|
}
|
|
|
|
void lcPartPaletteDialog::PaletteListCurrentRowChanged(int CurrentRow)
|
|
{
|
|
Q_UNUSED(CurrentRow);
|
|
|
|
UpdateButtons();
|
|
}
|