leocad/common/lc_findreplacewidget.cpp

161 lines
5.5 KiB
C++
Raw Normal View History

2021-01-31 00:37:17 +01:00
#include "lc_global.h"
#include "lc_findreplacewidget.h"
2023-05-16 06:12:08 +02:00
#include "lc_colorpicker.h"
2021-01-31 00:37:17 +01:00
#include "lc_mainwindow.h"
#include "pieceinf.h"
#include "piece.h"
#include "lc_model.h"
#include "lc_view.h"
#include "lc_qutils.h"
2021-01-31 00:37:17 +01:00
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);
2023-05-16 06:02:17 +02:00
lcColorPicker* FindColorPicker = new lcColorPicker(this, true);
2024-01-15 19:18:50 +01:00
FindColorPicker->setToolTip(tr("Search Color"));
2021-02-01 02:49:22 +01:00
Layout->addWidget(FindColorPicker, 0, 1);
2021-01-31 00:37:17 +01:00
2021-01-31 21:05:15 +01:00
mFindPartComboBox = new QComboBox(this);
2024-01-15 19:18:50 +01:00
mFindPartComboBox->setToolTip(tr("Search Part"));
2021-01-31 21:05:15 +01:00
mFindPartComboBox->setEditable(true);
mFindPartComboBox->setInsertPolicy(QComboBox::NoInsert);
2021-02-01 02:49:22 +01:00
Layout->addWidget(mFindPartComboBox, 0, 2);
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]);
2021-02-01 02:49:22 +01:00
Layout->addWidget(FindNextButton, 0, 3);
2021-01-31 00:37:17 +01:00
2021-01-31 20:02:50 +01:00
QToolButton* FindAllButton = new QToolButton(this);
FindAllButton ->setAutoRaise(true);
FindAllButton ->setDefaultAction(gMainWindow->mActions[LC_EDIT_FIND_ALL]);
2021-02-01 02:49:22 +01:00
Layout->addWidget(FindAllButton, 0, 4);
2021-01-31 20:02:50 +01:00
2023-05-16 06:02:17 +02:00
connect(FindColorPicker, &lcColorPicker::ColorChanged, this, &lcFindReplaceWidget::FindColorIndexChanged);
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);
2021-02-01 02:32:38 +01:00
connect(mFindPartComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &lcFindReplaceWidget::FindActivated);
2021-01-31 00:37:17 +01:00
2023-05-16 06:02:17 +02:00
lcColorPicker* ReplaceColorPicker = nullptr;
2021-01-31 00:37:17 +01:00
if (Replace)
{
2021-01-31 21:23:28 +01:00
Layout->addWidget(new QLabel(tr("Replace:")), 1, 0);
2023-05-16 06:02:17 +02:00
ReplaceColorPicker = new lcColorPicker(this, true);
2024-01-15 19:18:50 +01:00
ReplaceColorPicker->setToolTip(tr("Replacement Color"));
2021-02-01 02:49:22 +01:00
Layout->addWidget(ReplaceColorPicker, 1, 1);
2021-01-31 00:37:17 +01:00
2021-02-01 02:49:22 +01:00
mReplacePartComboBox = new QComboBox(this);
2024-01-15 19:18:50 +01:00
mReplacePartComboBox->setToolTip(tr("Replacement Part"));
2021-02-01 02:49:22 +01:00
Layout->addWidget(mReplacePartComboBox, 1, 2);
2021-01-31 00:37:17 +01:00
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]);
2021-02-01 02:49:22 +01:00
Layout->addWidget(ReplaceNextButton, 1, 3);
2021-01-31 00:37:17 +01:00
2021-01-31 20:02:50 +01:00
QToolButton* ReplaceAllButton = new QToolButton(this);
ReplaceAllButton->setAutoRaise(true);
ReplaceAllButton->setDefaultAction(gMainWindow->mActions[LC_EDIT_REPLACE_ALL]);
2021-02-01 02:49:22 +01:00
Layout->addWidget(ReplaceAllButton, 1, 4);
2021-01-31 20:02:50 +01:00
2023-05-16 06:02:17 +02:00
connect(ReplaceColorPicker, &lcColorPicker::ColorChanged, this, &lcFindReplaceWidget::ReplaceColorIndexChanged);
2021-02-01 02:49:22 +01:00
connect(mReplacePartComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &lcFindReplaceWidget::ReplaceActivated);
2021-01-31 00:37:17 +01:00
2021-02-01 02:49:22 +01:00
mReplacePartComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
mReplacePartComboBox->setMinimumContentsLength(1);
2021-01-31 00:37:17 +01:00
mReplacePartComboBox->setModel(new lcPieceIdStringModel(gMainWindow->GetActiveModel(), mReplacePartComboBox));
2021-02-01 02:49:22 +01:00
2023-05-16 06:02:17 +02:00
ReplaceColorPicker->SetCurrentColor(lcGetColorIndex(LC_COLOR_NOCOLOR));
2021-02-01 02:49:22 +01:00
mReplacePartComboBox->setCurrentIndex(0);
2021-01-31 00:37:17 +01:00
}
2024-01-15 04:34:01 +01:00
QToolButton* CloseButton = new QToolButton(this);
CloseButton->setAutoRaise(true);
CloseButton->setIcon(QIcon(":/stylesheet/close.png"));
2024-01-15 19:18:50 +01:00
CloseButton->setToolTip(tr("Close"));
2024-01-15 04:34:01 +01:00
Layout->addWidget(CloseButton, 0, 5);
2024-01-15 19:18:50 +01:00
connect(CloseButton, &QToolButton::clicked, this, &QObject::deleteLater);
2021-01-31 00:37:17 +01:00
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)
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
2021-01-31 00:37:17 +01:00
Params.FindInfo = Focus->mPieceInfo;
Params.FindColorIndex = Focus->GetColorIndex();
2023-05-16 06:02:17 +02:00
FindColorPicker->SetCurrentColor(Params.FindColorIndex);
mFindPartComboBox->setCurrentIndex(mFindPartComboBox->findData(QVariant::fromValue((void*)Params.FindInfo)));
2021-01-31 00:37:17 +01:00
}
2021-01-31 21:05:15 +01:00
else
{
2023-05-16 06:02:17 +02:00
FindColorPicker->SetCurrentColor(lcGetColorIndex(LC_COLOR_NOCOLOR));
2021-01-31 21:05:15 +01:00
mFindPartComboBox->setEditText(QString());
}
2021-01-31 00:37:17 +01:00
2021-02-01 02:32:38 +01:00
mFindPartComboBox->setFocus();
2021-01-31 00:37:17 +01:00
adjustSize();
move(1, 1);
show();
}
2021-01-31 21:05:15 +01:00
2021-02-01 02:32:38 +01:00
void lcFindReplaceWidget::FindColorIndexChanged(int ColorIndex)
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
Params.FindColorIndex = ColorIndex;
2021-02-01 02:32:38 +01:00
}
2021-01-31 21:05:15 +01:00
void lcFindReplaceWidget::FindTextEdited(const QString& Text)
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
Params.FindString = Text;
Params.FindInfo = nullptr;
2021-01-31 21:05:15 +01:00
}
2021-02-01 02:32:38 +01:00
void lcFindReplaceWidget::FindActivated(int Index)
2021-01-31 21:05:15 +01:00
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
Params.FindString.clear();
Params.FindInfo = (PieceInfo*)mFindPartComboBox->itemData(Index).value<void*>();
2021-01-31 21:05:15 +01:00
}
2021-02-01 02:49:22 +01:00
void lcFindReplaceWidget::ReplaceColorIndexChanged(int ColorIndex)
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
Params.ReplaceColorIndex = ColorIndex;
2021-02-01 02:49:22 +01:00
}
void lcFindReplaceWidget::ReplaceActivated(int Index)
{
lcFindReplaceParams& Params = lcView::GetFindReplaceParams();
Params.ReplacePieceInfo = (PieceInfo*)mReplacePartComboBox->itemData(Index).value<void*>();
2021-02-01 02:49:22 +01:00
}