mirror of
https://github.com/leozide/leocad.git
synced 2026-10-27 06:20:55 +00:00
UI labels mixed part and piece terminology, several messages left asset and file names unquoted, and Blender preferences contained British spellings and typos. Use piece terminology throughout displayed text, quote names and paths in messages and tooltips, and standardize US English spelling. Keep status-bar names and the properties-dialog title unquoted. Update translation source keys while preserving existing translations, settings keys, and external format names. Validation: macOS Qt 6.10 Debug build passed without warnings; XML, translation-key, placeholder, and whitespace checks passed.
191 lines
5.5 KiB
C++
191 lines
5.5 KiB
C++
#include "lc_global.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);
|
|
|
|
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();
|
|
}
|