2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_qpropertiesdialog.h"
|
|
|
|
#include "ui_lc_qpropertiesdialog.h"
|
2016-06-14 01:57:31 +02:00
|
|
|
#include "lc_qutils.h"
|
2013-08-16 03:25:51 +02:00
|
|
|
#include "lc_basewindow.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_colors.h"
|
|
|
|
#include "lc_application.h"
|
|
|
|
#include "pieceinf.h"
|
|
|
|
|
|
|
|
lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::lcQPropertiesDialog)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
connect(ui->solidColorButton, SIGNAL(clicked()), this, SLOT(colorClicked()));
|
|
|
|
connect(ui->gradient1ColorButton, SIGNAL(clicked()), this, SLOT(colorClicked()));
|
|
|
|
connect(ui->gradient2ColorButton, SIGNAL(clicked()), this, SLOT(colorClicked()));
|
|
|
|
|
|
|
|
options = (lcPropertiesDialogOptions*)data;
|
|
|
|
|
2014-12-31 18:05:23 +01:00
|
|
|
setWindowTitle(tr("%1 Properties").arg(options->Properties.mName));
|
|
|
|
|
2014-09-06 03:34:03 +02:00
|
|
|
ui->descriptionEdit->setText(options->Properties.mDescription);
|
|
|
|
ui->authorEdit->setText(options->Properties.mAuthor);
|
|
|
|
ui->commentsEdit->setText(options->Properties.mComments);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-02-10 01:13:41 +01:00
|
|
|
if (options->Properties.mBackgroundType == LC_BACKGROUND_IMAGE)
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->imageRadio->setChecked(true);
|
2014-02-10 01:13:41 +01:00
|
|
|
else if (options->Properties.mBackgroundType == LC_BACKGROUND_GRADIENT)
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->gradientRadio->setChecked(true);
|
|
|
|
else
|
|
|
|
ui->solidRadio->setChecked(true);
|
|
|
|
|
2014-09-08 21:42:20 +02:00
|
|
|
ui->imageNameEdit->setText(options->Properties.mBackgroundImage);
|
2014-02-10 01:13:41 +01:00
|
|
|
ui->imageTileCheckBox->setChecked(options->Properties.mBackgroundImageTile);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
QPixmap pix(12, 12);
|
|
|
|
|
2014-02-10 01:13:41 +01:00
|
|
|
pix.fill(QColor(options->Properties.mBackgroundSolidColor[0] * 255, options->Properties.mBackgroundSolidColor[1] * 255, options->Properties.mBackgroundSolidColor[2] * 255));
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->solidColorButton->setIcon(pix);
|
2014-02-10 01:13:41 +01:00
|
|
|
pix.fill(QColor(options->Properties.mBackgroundGradientColor1[0] * 255, options->Properties.mBackgroundGradientColor1[1] * 255, options->Properties.mBackgroundGradientColor1[2] * 255));
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->gradient1ColorButton->setIcon(pix);
|
2014-02-10 01:13:41 +01:00
|
|
|
pix.fill(QColor(options->Properties.mBackgroundGradientColor2[0] * 255, options->Properties.mBackgroundGradientColor2[1] * 255, options->Properties.mBackgroundGradientColor2[2] * 255));
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->gradient2ColorButton->setIcon(pix);
|
|
|
|
|
2016-11-16 23:53:41 +01:00
|
|
|
const lcPartsList& PartsList = options->PartsList;
|
|
|
|
QStringList horizontalLabels;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2016-11-15 21:12:47 +01:00
|
|
|
QVector<bool> ColorsUsed(gNumUserColors);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& PartIt : PartsList)
|
|
|
|
for (const auto& ColorIt : PartIt.second)
|
|
|
|
ColorsUsed[ColorIt.first] = true;
|
2013-08-19 03:01:06 +02:00
|
|
|
|
2016-11-15 21:12:47 +01:00
|
|
|
QVector<int> ColorColumns(gNumUserColors);
|
|
|
|
int NumColors = 0;
|
2013-08-19 03:01:06 +02:00
|
|
|
|
|
|
|
horizontalLabels.append(tr("Part"));
|
|
|
|
|
|
|
|
for (int colorIdx = 0; colorIdx < gNumUserColors; colorIdx++)
|
|
|
|
{
|
2016-11-15 21:12:47 +01:00
|
|
|
if (ColorsUsed[colorIdx])
|
2013-08-19 03:01:06 +02:00
|
|
|
{
|
2016-11-15 21:12:47 +01:00
|
|
|
ColorColumns[colorIdx] = NumColors++;
|
2013-08-19 03:01:06 +02:00
|
|
|
horizontalLabels.append(gColorList[colorIdx].Name);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-25 01:11:31 +02:00
|
|
|
horizontalLabels.append(tr("Total"));
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
QTableWidget *table = ui->partsTable;
|
2016-11-15 21:12:47 +01:00
|
|
|
table->setColumnCount(NumColors + 2);
|
2019-05-18 20:33:27 +02:00
|
|
|
table->setRowCount((int)PartsList.size() + 1);
|
2013-08-09 06:57:18 +02:00
|
|
|
table->setHorizontalHeaderLabels(horizontalLabels);
|
2014-01-26 07:56:36 +01:00
|
|
|
|
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
|
2019-03-11 00:23:32 +01:00
|
|
|
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
2014-01-26 07:56:36 +01:00
|
|
|
#else
|
2019-03-11 00:23:32 +01:00
|
|
|
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
2014-01-26 07:56:36 +01:00
|
|
|
#endif
|
2013-08-19 03:01:06 +02:00
|
|
|
|
2019-05-18 20:33:27 +02:00
|
|
|
std::vector<int> InfoTotals(PartsList.size());
|
|
|
|
std::vector<int> ColorTotals(NumColors);
|
2019-05-28 01:22:49 +02:00
|
|
|
int Row = 0, Total = 0;
|
2015-05-25 01:11:31 +02:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& PartIt : PartsList)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2017-04-16 00:54:17 +02:00
|
|
|
table->setItem(Row, 0, new QTableWidgetItem(PartIt.first->m_strDescription));
|
2015-05-25 01:11:31 +02:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& ColorIt : PartIt.second)
|
2016-11-16 23:53:41 +01:00
|
|
|
{
|
2017-04-16 00:54:17 +02:00
|
|
|
int ColorIndex = ColorIt.first;
|
|
|
|
int Count = ColorIt.second;
|
2015-05-25 01:11:31 +02:00
|
|
|
|
2016-11-16 23:53:41 +01:00
|
|
|
QTableWidgetItem* Item = new QTableWidgetItem(QString::number(Count));
|
|
|
|
Item->setTextAlignment(Qt::AlignCenter);
|
|
|
|
table->setItem(Row, ColorColumns[ColorIndex] + 1, Item);
|
|
|
|
|
|
|
|
InfoTotals[Row] += Count;
|
|
|
|
ColorTotals[ColorColumns[ColorIndex]] += Count;
|
|
|
|
Total += Count;
|
|
|
|
}
|
2017-04-16 00:54:17 +02:00
|
|
|
|
|
|
|
Row++;
|
2015-05-25 01:11:31 +02:00
|
|
|
}
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2019-05-18 20:33:27 +02:00
|
|
|
table->setItem((int)InfoTotals.size(), 0, new QTableWidgetItem(tr("Total")));
|
2016-11-16 23:53:41 +01:00
|
|
|
|
|
|
|
for (Row = 0; Row < InfoTotals.size(); Row++)
|
2015-05-25 01:11:31 +02:00
|
|
|
{
|
2016-11-16 23:53:41 +01:00
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(QString::number(InfoTotals[Row]));
|
2013-08-19 03:01:06 +02:00
|
|
|
item->setTextAlignment(Qt::AlignCenter);
|
2016-11-16 23:53:41 +01:00
|
|
|
table->setItem(Row, NumColors + 1, item);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
2016-11-15 21:12:47 +01:00
|
|
|
for (int colorIdx = 0; colorIdx < NumColors; colorIdx++)
|
2015-05-25 01:11:31 +02:00
|
|
|
{
|
2016-11-15 21:12:47 +01:00
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(QString::number(ColorTotals[colorIdx]));
|
2015-05-25 01:11:31 +02:00
|
|
|
item->setTextAlignment(Qt::AlignCenter);
|
2019-05-18 20:33:27 +02:00
|
|
|
table->setItem((int)InfoTotals.size(), colorIdx + 1, item);
|
2015-05-25 01:11:31 +02:00
|
|
|
}
|
|
|
|
|
2016-11-16 23:53:41 +01:00
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(QString::number(Total));
|
2015-05-25 01:11:31 +02:00
|
|
|
item->setTextAlignment(Qt::AlignCenter);
|
2019-05-18 20:33:27 +02:00
|
|
|
table->setItem((int)InfoTotals.size(), NumColors + 1, item);
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lcQPropertiesDialog::~lcQPropertiesDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQPropertiesDialog::accept()
|
|
|
|
{
|
2014-09-06 03:34:03 +02:00
|
|
|
options->Properties.mDescription = ui->descriptionEdit->text();
|
|
|
|
options->Properties.mAuthor = ui->authorEdit->text();
|
|
|
|
options->Properties.mComments = ui->commentsEdit->toPlainText();
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
if (ui->imageRadio->isChecked())
|
2014-02-10 01:13:41 +01:00
|
|
|
options->Properties.mBackgroundType = LC_BACKGROUND_IMAGE;
|
2013-08-09 06:57:18 +02:00
|
|
|
else if (ui->gradientRadio->isChecked())
|
2014-02-10 01:13:41 +01:00
|
|
|
options->Properties.mBackgroundType = LC_BACKGROUND_GRADIENT;
|
2013-08-09 06:57:18 +02:00
|
|
|
else
|
2014-02-10 01:13:41 +01:00
|
|
|
options->Properties.mBackgroundType = LC_BACKGROUND_SOLID;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2014-09-08 21:42:20 +02:00
|
|
|
options->Properties.mBackgroundImage = ui->imageNameEdit->text();
|
2014-02-10 01:13:41 +01:00
|
|
|
options->Properties.mBackgroundImageTile = ui->imageTileCheckBox->isChecked();
|
2013-08-09 06:57:18 +02:00
|
|
|
options->SetDefault = ui->setDefaultCheckBox->isChecked();
|
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQPropertiesDialog::colorClicked()
|
|
|
|
{
|
|
|
|
QObject *button = sender();
|
|
|
|
QString title;
|
2017-04-14 02:26:40 +02:00
|
|
|
float *color = nullptr;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
if (button == ui->solidColorButton)
|
|
|
|
{
|
2014-02-10 01:13:41 +01:00
|
|
|
color = options->Properties.mBackgroundSolidColor;
|
2013-08-09 06:57:18 +02:00
|
|
|
title = tr("Select Background Color");
|
|
|
|
}
|
|
|
|
else if (button == ui->gradient1ColorButton)
|
|
|
|
{
|
2014-02-10 01:13:41 +01:00
|
|
|
color = options->Properties.mBackgroundGradientColor1;
|
2013-08-09 06:57:18 +02:00
|
|
|
title = tr("Select Background Top Color");
|
|
|
|
}
|
|
|
|
else if (button == ui->gradient2ColorButton)
|
|
|
|
{
|
2014-02-10 01:13:41 +01:00
|
|
|
color = options->Properties.mBackgroundGradientColor2;
|
2013-08-09 06:57:18 +02:00
|
|
|
title = tr("Select Background Bottom Color");
|
|
|
|
}
|
|
|
|
|
2017-02-13 03:05:20 +01:00
|
|
|
if (!color)
|
|
|
|
return;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
QColor oldColor = QColor(color[0] * 255, color[1] * 255, color[2] * 255);
|
|
|
|
QColor newColor = QColorDialog::getColor(oldColor, this, title);
|
|
|
|
|
|
|
|
if (newColor == oldColor || !newColor.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
color[0] = (float)newColor.red() / 255.0f;
|
|
|
|
color[1] = (float)newColor.green() / 255.0f;
|
|
|
|
color[2] = (float)newColor.blue() / 255.0f;
|
|
|
|
|
|
|
|
QPixmap pix(12, 12);
|
|
|
|
|
|
|
|
pix.fill(newColor);
|
|
|
|
((QToolButton*)button)->setIcon(pix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQPropertiesDialog::on_imageNameButton_clicked()
|
|
|
|
{
|
|
|
|
QString result = QFileDialog::getOpenFileName(this, tr("Select Background Image"), ui->imageNameEdit->text(), tr("All Image Files (*.png *.jpg *.gif *.bmp);;PNG Files (*.png);;JPEG Files (*.jpg);;GIF Files (*.gif);;BMP Files (*.bmp);;All Files (*.*)"));
|
|
|
|
|
|
|
|
if (!result.isEmpty())
|
|
|
|
ui->imageNameEdit->setText(QDir::toNativeSeparators(result));
|
|
|
|
}
|