2021-01-31 00:37:17 +01:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_findreplacewidget.h"
|
|
|
|
#include "lc_qcolorpicker.h"
|
|
|
|
#include "lc_library.h"
|
|
|
|
#include "lc_mainwindow.h"
|
|
|
|
#include "pieceinf.h"
|
|
|
|
#include "piece.h"
|
|
|
|
#include "lc_model.h"
|
|
|
|
|
|
|
|
lcFindReplaceWidget::lcFindReplaceWidget(QWidget* Parent, lcModel* Model, bool Replace)
|
|
|
|
: QWidget(Parent)
|
|
|
|
{
|
|
|
|
setAutoFillBackground(true);
|
2021-01-31 20:02:50 +01:00
|
|
|
QPalette Palette = palette();
|
|
|
|
Palette.setColor(QPalette::Window, QApplication::palette().color(QPalette::Button));
|
|
|
|
setPalette(Palette);
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
QGridLayout* Layout = new QGridLayout(this);
|
|
|
|
Layout->setContentsMargins(5, 5, 5, 5);
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
Layout->addWidget(new QLabel(tr("Find:")), 0, 0);
|
|
|
|
|
|
|
|
QCheckBox* FindColorCheckBox = new QCheckBox(this);
|
2021-01-31 00:37:17 +01:00
|
|
|
Layout->addWidget(FindColorCheckBox, 0, 1);
|
|
|
|
|
|
|
|
lcQColorPicker* FindColorPicker = new lcQColorPicker(this);
|
|
|
|
Layout->addWidget(FindColorPicker, 0, 2);
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindPartComboBox = new QComboBox(this);
|
|
|
|
mFindPartComboBox->setEditable(true);
|
|
|
|
mFindPartComboBox->setInsertPolicy(QComboBox::NoInsert);
|
|
|
|
Layout->addWidget(mFindPartComboBox, 0, 4);
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
QToolButton* FindNextButton = new QToolButton(this);
|
2021-01-31 20:02:50 +01:00
|
|
|
FindNextButton->setAutoRaise(true);
|
2021-01-31 00:37:17 +01:00
|
|
|
FindNextButton->setDefaultAction(gMainWindow->mActions[LC_EDIT_FIND_NEXT]);
|
|
|
|
Layout->addWidget(FindNextButton, 0, 5);
|
|
|
|
|
2021-01-31 20:02:50 +01:00
|
|
|
QToolButton* FindAllButton = new QToolButton(this);
|
|
|
|
FindAllButton ->setAutoRaise(true);
|
|
|
|
FindAllButton ->setDefaultAction(gMainWindow->mActions[LC_EDIT_FIND_ALL]);
|
|
|
|
Layout->addWidget(FindAllButton, 0, 6);
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(FindColorCheckBox, &QCheckBox::toggled, [this](bool Checked)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.MatchColor = Checked;
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(FindColorPicker, &lcQColorPicker::colorChanged, [this](int ColorIndex)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ColorIndex = ColorIndex;
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(mFindPartComboBox->lineEdit(), &QLineEdit::returnPressed, gMainWindow->mActions[LC_EDIT_FIND_NEXT], &QAction::trigger);
|
|
|
|
connect(mFindPartComboBox->lineEdit(), &QLineEdit::textEdited, this, &lcFindReplaceWidget::FindTextEdited);
|
|
|
|
connect(mFindPartComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &lcFindReplaceWidget::FindIndexChanged);
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
QCheckBox* ReplaceColorCheckBox = nullptr;
|
|
|
|
lcQColorPicker* ReplaceColorPicker = nullptr;
|
|
|
|
QCheckBox* ReplacePartCheckBox = nullptr;
|
|
|
|
QComboBox* ReplacePartComboBox = nullptr;
|
|
|
|
|
|
|
|
if (Replace)
|
|
|
|
{
|
2021-01-31 21:23:28 +01:00
|
|
|
Layout->addWidget(new QLabel(tr("Replace:")), 1, 0);
|
|
|
|
|
|
|
|
ReplaceColorCheckBox = new QCheckBox(this);
|
2021-01-31 00:37:17 +01:00
|
|
|
Layout->addWidget(ReplaceColorCheckBox, 1, 1);
|
|
|
|
|
|
|
|
ReplaceColorPicker = new lcQColorPicker(this);
|
|
|
|
Layout->addWidget(ReplaceColorPicker, 1, 2);
|
|
|
|
|
2021-01-31 21:23:28 +01:00
|
|
|
ReplacePartCheckBox = new QCheckBox(this);
|
2021-01-31 00:37:17 +01:00
|
|
|
Layout->addWidget(ReplacePartCheckBox, 1, 3);
|
|
|
|
|
|
|
|
ReplacePartComboBox = new QComboBox(this);
|
|
|
|
Layout->addWidget(ReplacePartComboBox, 1, 4);
|
|
|
|
|
|
|
|
QToolButton* ReplaceNextButton = new QToolButton(this);
|
2021-01-31 20:02:50 +01:00
|
|
|
ReplaceNextButton->setAutoRaise(true);
|
2021-01-31 00:37:17 +01:00
|
|
|
ReplaceNextButton->setDefaultAction(gMainWindow->mActions[LC_EDIT_REPLACE_NEXT]);
|
|
|
|
Layout->addWidget(ReplaceNextButton, 1, 5);
|
|
|
|
|
2021-01-31 20:02:50 +01:00
|
|
|
QToolButton* ReplaceAllButton = new QToolButton(this);
|
|
|
|
ReplaceAllButton->setAutoRaise(true);
|
|
|
|
ReplaceAllButton->setDefaultAction(gMainWindow->mActions[LC_EDIT_REPLACE_ALL]);
|
|
|
|
Layout->addWidget(ReplaceAllButton, 1, 6);
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(ReplaceColorCheckBox, &QCheckBox::toggled, [this](bool Checked)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ReplaceColor = Checked;
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(ReplaceColorPicker, &lcQColorPicker::colorChanged, [this](int ColorIndex)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ReplaceColorIndex = ColorIndex;
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(ReplacePartCheckBox, &QCheckBox::toggled, [this](bool Checked)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ReplaceInfo = Checked;
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
connect(ReplacePartComboBox, qOverload<int>(&QComboBox::currentIndexChanged), [this, ReplacePartComboBox](int Index)
|
2021-01-31 00:37:17 +01:00
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ReplacePieceInfo = (PieceInfo*)ReplacePartComboBox->itemData(Index).value<void*>();
|
2021-01-31 00:37:17 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
ReplacePartComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
|
ReplacePartComboBox->setMinimumContentsLength(1);
|
|
|
|
|
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
|
|
|
std::vector<PieceInfo*> SortedPieces;
|
|
|
|
SortedPieces.reserve(Library->mPieces.size());
|
|
|
|
|
|
|
|
for (const auto& PartIt : Library->mPieces)
|
|
|
|
SortedPieces.push_back(PartIt.second);
|
|
|
|
|
|
|
|
auto PieceCompare = [](PieceInfo* Info1, PieceInfo* Info2)
|
|
|
|
{
|
|
|
|
return strcmp(Info1->m_strDescription, Info2->m_strDescription) < 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::sort(SortedPieces.begin(), SortedPieces.end(), PieceCompare);
|
|
|
|
|
|
|
|
for (PieceInfo* Info : SortedPieces)
|
|
|
|
ReplacePartComboBox->addItem(Info->m_strDescription, QVariant::fromValue((void*)Info));
|
|
|
|
}
|
|
|
|
|
|
|
|
lcPartsList PartsList;
|
|
|
|
Model->GetPartsList(gDefaultColor, false, true, PartsList);
|
|
|
|
|
|
|
|
for (const auto& PartIt : PartsList)
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindPartComboBox->addItem(QString::fromLatin1(PartIt.first->m_strDescription), QVariant::fromValue((void*)PartIt.first));
|
|
|
|
mFindPartComboBox->model()->sort(0);
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
lcPiece* Focus = dynamic_cast<lcPiece*>(Model->GetFocusObject());
|
|
|
|
|
|
|
|
if (Focus)
|
|
|
|
{
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.FindInfo = Focus->mPieceInfo;
|
2021-01-31 00:37:17 +01:00
|
|
|
|
2021-01-31 21:05:15 +01:00
|
|
|
mFindReplaceParams.ColorIndex = Focus->GetColorIndex();
|
2021-01-31 00:37:17 +01:00
|
|
|
FindColorCheckBox->setChecked(true);
|
2021-01-31 21:05:15 +01:00
|
|
|
FindColorPicker->setCurrentColor(mFindReplaceParams.ColorIndex);
|
|
|
|
mFindPartComboBox->setCurrentIndex(mFindPartComboBox->findData(QVariant::fromValue((void*)mFindReplaceParams.FindInfo)));
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
if (Replace)
|
|
|
|
{
|
|
|
|
ReplaceColorCheckBox->setChecked(true);
|
2021-01-31 21:05:15 +01:00
|
|
|
ReplaceColorPicker->setCurrentColor(mFindReplaceParams.ColorIndex);
|
2021-01-31 00:37:17 +01:00
|
|
|
ReplacePartCheckBox->setChecked(true);
|
2021-01-31 21:05:15 +01:00
|
|
|
ReplacePartComboBox->setCurrentIndex(ReplacePartComboBox->findData(QVariant::fromValue((void*)mFindReplaceParams.FindInfo)));
|
2021-01-31 00:37:17 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-31 21:05:15 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mFindPartComboBox->setEditText(QString());
|
|
|
|
}
|
2021-01-31 00:37:17 +01:00
|
|
|
|
|
|
|
adjustSize();
|
|
|
|
move(1, 1);
|
|
|
|
show();
|
|
|
|
}
|
2021-01-31 21:05:15 +01:00
|
|
|
|
|
|
|
void lcFindReplaceWidget::FindTextEdited(const QString& Text)
|
|
|
|
{
|
|
|
|
mFindReplaceParams.FindString = Text;
|
|
|
|
mFindReplaceParams.FindInfo = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcFindReplaceWidget::FindIndexChanged(int Index)
|
|
|
|
{
|
|
|
|
mFindReplaceParams.FindString.clear();
|
|
|
|
mFindReplaceParams.FindInfo = (PieceInfo*)mFindPartComboBox->itemData(Index).value<void*>();
|
|
|
|
}
|