mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Removed find color checkbox.
This commit is contained in:
parent
dc0ffbc8bb
commit
c182daa10d
10 changed files with 197 additions and 121 deletions
|
@ -395,7 +395,7 @@ bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle)
|
|||
if (Valid)
|
||||
lcAdjustStudStyleColors(Colors, StudStyle);
|
||||
|
||||
bool FoundMain = false, FoundEdge = false, FoundStud = false;
|
||||
bool FoundMain = false, FoundEdge = false, FoundStud = false, FoundNoColor = false;
|
||||
|
||||
for (const lcColor& Color : Colors)
|
||||
{
|
||||
|
@ -412,6 +412,10 @@ bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle)
|
|||
case 4242:
|
||||
FoundStud = true;
|
||||
break;
|
||||
|
||||
case LC_COLOR_NOCOLOR:
|
||||
FoundNoColor = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -473,6 +477,27 @@ bool lcLoadColorFile(lcFile& File, lcStudStyle StudStyle)
|
|||
Colors.push_back(StudCylinderColor);
|
||||
}
|
||||
|
||||
if (!FoundNoColor)
|
||||
{
|
||||
lcColor NoColor;
|
||||
|
||||
NoColor.Code = LC_COLOR_NOCOLOR;
|
||||
NoColor.Translucent = false;
|
||||
NoColor.Group = LC_NUM_COLORGROUPS;
|
||||
NoColor.Value[0] = 0.5f;
|
||||
NoColor.Value[1] = 0.5f;
|
||||
NoColor.Value[2] = 0.5f;
|
||||
NoColor.Value[3] = 1.0f;
|
||||
NoColor.Edge[0] = 0.2f;
|
||||
NoColor.Edge[1] = 0.2f;
|
||||
NoColor.Edge[2] = 0.2f;
|
||||
NoColor.Edge[3] = 1.0f;
|
||||
strcpy(NoColor.Name, "No Color");
|
||||
strcpy(NoColor.SafeName, "No_Color");
|
||||
|
||||
Colors.push_back(NoColor);
|
||||
}
|
||||
|
||||
for (lcColor& Color : gColorList)
|
||||
Color.Group = LC_NUM_COLORGROUPS;
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#define LC_MAX_COLOR_NAME 64
|
||||
#define LC_COLOR_DIRECT 0x80000000
|
||||
#define LC_COLOR_NOCOLOR 0xffffffff
|
||||
|
||||
struct lcColor
|
||||
{
|
||||
|
|
|
@ -20,10 +20,7 @@ lcFindReplaceWidget::lcFindReplaceWidget(QWidget* Parent, lcModel* Model, bool R
|
|||
|
||||
Layout->addWidget(new QLabel(tr("Find:")), 0, 0);
|
||||
|
||||
QCheckBox* FindColorCheckBox = new QCheckBox(this);
|
||||
Layout->addWidget(FindColorCheckBox, 0, 1);
|
||||
|
||||
lcQColorPicker* FindColorPicker = new lcQColorPicker(this);
|
||||
lcQColorPicker* FindColorPicker = new lcQColorPicker(this, true);
|
||||
Layout->addWidget(FindColorPicker, 0, 2);
|
||||
|
||||
mFindPartComboBox = new QComboBox(this);
|
||||
|
@ -41,19 +38,10 @@ lcFindReplaceWidget::lcFindReplaceWidget(QWidget* Parent, lcModel* Model, bool R
|
|||
FindAllButton ->setDefaultAction(gMainWindow->mActions[LC_EDIT_FIND_ALL]);
|
||||
Layout->addWidget(FindAllButton, 0, 6);
|
||||
|
||||
connect(FindColorCheckBox, &QCheckBox::toggled, [this](bool Checked)
|
||||
{
|
||||
mFindReplaceParams.MatchColor = Checked;
|
||||
});
|
||||
|
||||
connect(FindColorPicker, &lcQColorPicker::colorChanged, [this](int ColorIndex)
|
||||
{
|
||||
mFindReplaceParams.ColorIndex = ColorIndex;
|
||||
});
|
||||
|
||||
connect(FindColorPicker, &lcQColorPicker::colorChanged, this, &lcFindReplaceWidget::FindColorIndexChanged);
|
||||
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);
|
||||
connect(mFindPartComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &lcFindReplaceWidget::FindActivated);
|
||||
|
||||
QCheckBox* ReplaceColorCheckBox = nullptr;
|
||||
lcQColorPicker* ReplaceColorPicker = nullptr;
|
||||
|
@ -139,37 +127,43 @@ lcFindReplaceWidget::lcFindReplaceWidget(QWidget* Parent, lcModel* Model, bool R
|
|||
if (Focus)
|
||||
{
|
||||
mFindReplaceParams.FindInfo = Focus->mPieceInfo;
|
||||
mFindReplaceParams.FindColorIndex = Focus->GetColorIndex();
|
||||
|
||||
mFindReplaceParams.ColorIndex = Focus->GetColorIndex();
|
||||
FindColorCheckBox->setChecked(true);
|
||||
FindColorPicker->setCurrentColor(mFindReplaceParams.ColorIndex);
|
||||
FindColorPicker->setCurrentColor(mFindReplaceParams.FindColorIndex);
|
||||
mFindPartComboBox->setCurrentIndex(mFindPartComboBox->findData(QVariant::fromValue((void*)mFindReplaceParams.FindInfo)));
|
||||
|
||||
if (Replace)
|
||||
{
|
||||
ReplaceColorCheckBox->setChecked(true);
|
||||
ReplaceColorPicker->setCurrentColor(mFindReplaceParams.ColorIndex);
|
||||
ReplaceColorPicker->setCurrentColor(mFindReplaceParams.FindColorIndex);
|
||||
ReplacePartCheckBox->setChecked(true);
|
||||
ReplacePartComboBox->setCurrentIndex(ReplacePartComboBox->findData(QVariant::fromValue((void*)mFindReplaceParams.FindInfo)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FindColorPicker->setCurrentColor(lcGetColorIndex(LC_COLOR_NOCOLOR));
|
||||
mFindPartComboBox->setEditText(QString());
|
||||
}
|
||||
|
||||
mFindPartComboBox->setFocus();
|
||||
adjustSize();
|
||||
move(1, 1);
|
||||
show();
|
||||
}
|
||||
|
||||
void lcFindReplaceWidget::FindColorIndexChanged(int ColorIndex)
|
||||
{
|
||||
mFindReplaceParams.FindColorIndex = ColorIndex;
|
||||
}
|
||||
|
||||
void lcFindReplaceWidget::FindTextEdited(const QString& Text)
|
||||
{
|
||||
mFindReplaceParams.FindString = Text;
|
||||
mFindReplaceParams.FindInfo = nullptr;
|
||||
}
|
||||
|
||||
void lcFindReplaceWidget::FindIndexChanged(int Index)
|
||||
void lcFindReplaceWidget::FindActivated(int Index)
|
||||
{
|
||||
mFindReplaceParams.FindString.clear();
|
||||
mFindReplaceParams.FindInfo = (PieceInfo*)mFindPartComboBox->itemData(Index).value<void*>();
|
||||
|
|
|
@ -4,11 +4,10 @@ struct lcFindReplaceParams
|
|||
{
|
||||
PieceInfo* FindInfo = nullptr;
|
||||
QString FindString;
|
||||
int FindColorIndex = 0;
|
||||
|
||||
bool MatchColor = false;
|
||||
bool ReplaceInfo = false;
|
||||
bool ReplaceColor = false;
|
||||
int ColorIndex = 0;
|
||||
PieceInfo* ReplacePieceInfo = nullptr;
|
||||
int ReplaceColorIndex = 0;
|
||||
};
|
||||
|
@ -26,8 +25,9 @@ public:
|
|||
}
|
||||
|
||||
protected slots:
|
||||
void FindColorIndexChanged(int ColorIndex);
|
||||
void FindTextEdited(const QString& Text);
|
||||
void FindIndexChanged(int Index);
|
||||
void FindActivated(int Index);
|
||||
|
||||
protected:
|
||||
QComboBox* mFindPartComboBox = nullptr;
|
||||
|
|
|
@ -3789,15 +3789,17 @@ void lcModel::FindReplacePiece(bool SearchForward, bool FindAll)
|
|||
if (!Params)
|
||||
return;
|
||||
|
||||
auto PieceMatches = [Params](const lcPiece* Piece)
|
||||
auto PieceMatches = [](const lcPiece* Piece)
|
||||
{
|
||||
const lcFindReplaceParams* Params = lcView::GetFindReplaceParams();
|
||||
|
||||
if (Params->FindInfo && Params->FindInfo != Piece->mPieceInfo)
|
||||
return false;
|
||||
|
||||
if (!Params->FindString.isEmpty() && !strcasestr(Piece->mPieceInfo->m_strDescription, Params->FindString.toLatin1()))
|
||||
return false;
|
||||
|
||||
return !Params->MatchColor || Piece->GetColorIndex() == Params->ColorIndex;
|
||||
return (lcGetColorCode(Params->FindColorIndex) == LC_COLOR_NOCOLOR) || (Piece->GetColorIndex() == Params->FindColorIndex);
|
||||
};
|
||||
|
||||
int StartIdx = mPieces.GetSize() - 1;
|
||||
|
|
|
@ -16,7 +16,7 @@ qtHaveModule(gamepad) {
|
|||
}
|
||||
|
||||
INCLUDEPATH += qt common
|
||||
CONFIG += precompile_header incremental c++14 force_debug_info
|
||||
CONFIG += precompile_header incremental c++11 force_debug_info
|
||||
|
||||
win32 {
|
||||
RC_ICONS = resources/leocad.ico
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
#include "lc_library.h"
|
||||
#include "lc_colors.h"
|
||||
|
||||
lcQColorList::lcQColorList(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
lcQColorList::lcQColorList(QWidget* Parent, bool AllowNoColor)
|
||||
: QWidget(Parent), mAllowNoColor(AllowNoColor)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
|
@ -17,31 +17,43 @@ lcQColorList::lcQColorList(QWidget *parent)
|
|||
void lcQColorList::UpdateCells()
|
||||
{
|
||||
mCells.clear();
|
||||
mGroupRects.clear();
|
||||
mGroups.clear();
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
lcColorListGroup ListGroup;
|
||||
|
||||
for (int ColorIndex : Group->Colors)
|
||||
{
|
||||
mCells.emplace_back(lcColorListCell{ QRect(), ColorIndex });
|
||||
ListGroup.Name = Group->Name;
|
||||
ListGroup.Cells.emplace_back(mCells.size());
|
||||
}
|
||||
|
||||
mGroups.emplace_back(std::move(ListGroup));
|
||||
}
|
||||
|
||||
if (mAllowNoColor)
|
||||
{
|
||||
mCells.emplace_back(lcColorListCell{ QRect(), lcGetColorIndex(LC_COLOR_NOCOLOR) });
|
||||
mGroups[LC_COLORGROUP_SPECIAL].Cells.emplace_back(mCells.size());
|
||||
}
|
||||
|
||||
mColumns = 14;
|
||||
mRows = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
|
||||
for (int ColorIndex : Group->Colors)
|
||||
mCells.emplace_back(lcColorListCell{ QRect(), ColorIndex });
|
||||
|
||||
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
|
||||
}
|
||||
for (const lcColorListGroup& Group : mGroups)
|
||||
mRows += ((int)Group.Cells.size() + mColumns - 1) / mColumns;
|
||||
|
||||
QFontMetrics Metrics(font());
|
||||
int TextHeight = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
for (lcColorListGroup& Group : mGroups)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
Group.Rect = Metrics.boundingRect(rect(), Qt::TextSingleLine | Qt::AlignCenter, Group.Name);
|
||||
|
||||
mGroupRects.emplace_back(Metrics.boundingRect(rect(), Qt::TextSingleLine | Qt::AlignCenter, Group->Name));
|
||||
|
||||
TextHeight += mGroupRects[GroupIdx].height();
|
||||
TextHeight += Group.Rect.height();
|
||||
}
|
||||
|
||||
mPreferredHeight = TextHeight + 10 * mRows;
|
||||
|
@ -54,13 +66,11 @@ void lcQColorList::UpdateRects()
|
|||
QFontMetrics Metrics(font());
|
||||
int TextHeight = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
for (lcColorListGroup& Group : mGroups)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
Group.Rect = Metrics.boundingRect(rect(), Qt::TextSingleLine | Qt::AlignCenter, Group.Name);
|
||||
|
||||
mGroupRects[GroupIdx] = Metrics.boundingRect(rect(), Qt::TextSingleLine | Qt::AlignCenter, Group->Name);
|
||||
|
||||
TextHeight += mGroupRects[GroupIdx].height();
|
||||
TextHeight += Group.Rect.height();
|
||||
}
|
||||
|
||||
mPreferredHeight = TextHeight + 10 * mRows;
|
||||
|
@ -73,11 +83,8 @@ void lcQColorList::UpdateRects()
|
|||
mColumns++;
|
||||
mRows = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
|
||||
}
|
||||
for (const lcColorListGroup& Group : mGroups)
|
||||
mRows += ((int)Group.Cells.size() + mColumns - 1) / mColumns;
|
||||
|
||||
CellWidth = (float)(width() + 1) / (float)mColumns;
|
||||
CellHeight = (float)(height() - TextHeight) / (float)mRows;
|
||||
|
@ -91,11 +98,8 @@ void lcQColorList::UpdateRects()
|
|||
mColumns--;
|
||||
mRows = 0;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
mRows += ((int)Group->Colors.size() + mColumns - 1) / mColumns;
|
||||
}
|
||||
for (const lcColorListGroup& Group : mGroups)
|
||||
mRows += ((int)Group.Cells.size() + mColumns - 1) / mColumns;
|
||||
|
||||
CellWidth = (float)(width() + 1) / (float)mColumns;
|
||||
CellHeight = (float)(height() - TextHeight) / (float)mRows;
|
||||
|
@ -108,16 +112,15 @@ void lcQColorList::UpdateRects()
|
|||
float GroupY = 0.0f;
|
||||
int TotalRows = 1;
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
for (lcColorListGroup& Group : mGroups)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
int CurColumn = 0;
|
||||
int NumRows = 0;
|
||||
|
||||
mGroupRects[GroupIdx] = QRect(0, (int)GroupY, width(), mGroupRects[GroupIdx].height());
|
||||
GroupY += mGroupRects[GroupIdx].height();
|
||||
Group.Rect = QRect(0, (int)GroupY, width(), Group.Rect.height());
|
||||
GroupY += Group.Rect.height();
|
||||
|
||||
for (size_t ColorIdx = 0; ColorIdx < Group->Colors.size(); ColorIdx++)
|
||||
for (size_t ColorIdx = 0; ColorIdx < Group.Cells.size(); ColorIdx++)
|
||||
{
|
||||
const int Left = CellWidth * CurColumn - 1;
|
||||
const int Right = (CurColumn + 1) * CellWidth - 1;
|
||||
|
@ -192,7 +195,17 @@ bool lcQColorList::event(QEvent *event)
|
|||
image.fill(rgb);
|
||||
QPainter painter(&image);
|
||||
painter.setPen(Qt::darkGray);
|
||||
if (color->Code != LC_COLOR_NOCOLOR)
|
||||
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
||||
else
|
||||
{
|
||||
painter.setBrush(Qt::black);
|
||||
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
||||
|
||||
const int SquareSize = image.width() / 2 - 1;
|
||||
painter.fillRect(1, 1, SquareSize, SquareSize, Qt::white);
|
||||
painter.fillRect(1 + SquareSize, 1 + SquareSize, SquareSize, SquareSize, Qt::white);
|
||||
}
|
||||
painter.end();
|
||||
|
||||
QByteArray ba;
|
||||
|
@ -202,8 +215,17 @@ bool lcQColorList::event(QEvent *event)
|
|||
buffer.close();
|
||||
|
||||
int colorIndex = mCells[CellIndex].ColorIndex;
|
||||
QString text;
|
||||
if (color->Code != LC_COLOR_NOCOLOR)
|
||||
{
|
||||
const char* format = "<table><tr><td style=\"vertical-align:middle\"><img src=\"data:image/png;base64,%1\"/></td><td>%2 (%3)</td></tr></table>";
|
||||
QString text = QString(format).arg(QString(buffer.data().toBase64()), gColorList[colorIndex].Name, QString::number(gColorList[colorIndex].Code));
|
||||
text = QString(format).arg(QString(buffer.data().toBase64()), gColorList[colorIndex].Name, QString::number(gColorList[colorIndex].Code));
|
||||
}
|
||||
else
|
||||
{
|
||||
const char* format = "<table><tr><td style=\"vertical-align:middle\"><img src=\"data:image/png;base64,%1\"/></td><td>%2</td></tr></table>";
|
||||
text = QString(format).arg(QString(buffer.data().toBase64()), gColorList[colorIndex].Name);
|
||||
}
|
||||
|
||||
QToolTip::showText(helpEvent->globalPos(), text);
|
||||
return true;
|
||||
|
@ -291,9 +313,9 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
|
|||
size_t CurGroup = 0;
|
||||
size_t NumCells = 0;
|
||||
|
||||
for (CurGroup = 0; CurGroup < LC_NUM_COLORGROUPS; CurGroup++)
|
||||
for (CurGroup = 0; CurGroup < mGroups.size(); CurGroup++)
|
||||
{
|
||||
int NumColors = (int)gColorGroups[CurGroup].Colors.size();
|
||||
int NumColors = (int)mGroups[CurGroup].Cells.size();
|
||||
|
||||
if (mCurrentCell < NumCells + NumColors)
|
||||
break;
|
||||
|
@ -310,7 +332,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
|
|||
NewCell = mCurrentCell - mColumns;
|
||||
else if (CurGroup > 0)
|
||||
{
|
||||
size_t NumColors = gColorGroups[CurGroup - 1].Colors.size();
|
||||
size_t NumColors = mGroups[CurGroup - 1].Cells.size();
|
||||
size_t NumColumns = NumColors % mColumns;
|
||||
|
||||
if (NumColumns < Column + 1)
|
||||
|
@ -321,7 +343,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event)
|
|||
}
|
||||
else if (event->key() == Qt::Key_Down)
|
||||
{
|
||||
int NumColors = (int)gColorGroups[CurGroup].Colors.size();
|
||||
int NumColors = (int)mGroups[CurGroup].Cells.size();
|
||||
|
||||
if (mCurrentCell + mColumns < NumCells + NumColors)
|
||||
NewCell = mCurrentCell + mColumns;
|
||||
|
@ -374,12 +396,8 @@ void lcQColorList::paintEvent(QPaintEvent* Event)
|
|||
Painter.setFont(font());
|
||||
Painter.setPen(palette().color(QPalette::Text));
|
||||
|
||||
for (int GroupIdx = 0; GroupIdx < LC_NUM_COLORGROUPS; GroupIdx++)
|
||||
{
|
||||
lcColorGroup* Group = &gColorGroups[GroupIdx];
|
||||
|
||||
Painter.drawText(mGroupRects[GroupIdx], Qt::TextSingleLine | Qt::AlignLeft, Group->Name);
|
||||
}
|
||||
for (const lcColorListGroup& Group : mGroups)
|
||||
Painter.drawText(Group.Rect, Qt::TextSingleLine | Qt::AlignLeft, Group.Name);
|
||||
|
||||
Painter.setPen(palette().color(QPalette::Shadow));
|
||||
|
||||
|
@ -389,7 +407,20 @@ void lcQColorList::paintEvent(QPaintEvent* Event)
|
|||
QColor CellColor(Color->Value[0] * 255, Color->Value[1] * 255, Color->Value[2] * 255);
|
||||
|
||||
Painter.setBrush(CellColor);
|
||||
Painter.drawRect(mCells[CellIndex].Rect);
|
||||
const QRect& Rect = mCells[CellIndex].Rect;
|
||||
|
||||
if (Color->Code != LC_COLOR_NOCOLOR)
|
||||
Painter.drawRect(Rect);
|
||||
else
|
||||
{
|
||||
Painter.setBrush(Qt::black);
|
||||
Painter.drawRect(Rect);
|
||||
|
||||
const int SquareWidth = Rect.width() / 2 - 1;
|
||||
const int SquareHeight = Rect.height() / 2 - 1;
|
||||
Painter.fillRect(Rect.x() + 1, Rect.y() + 1, SquareWidth, SquareHeight, Qt::white);
|
||||
Painter.fillRect(Rect.x() + 1 + SquareWidth, Rect.y() + 1 + SquareHeight, Rect.width() - SquareWidth - 1, SquareHeight, Qt::white);
|
||||
}
|
||||
}
|
||||
|
||||
if (mCurrentCell < mCells.size())
|
||||
|
@ -399,7 +430,10 @@ void lcQColorList::paintEvent(QPaintEvent* Event)
|
|||
QColor CellColor(Color->Value[0] * 255, Color->Value[1] * 255, Color->Value[2] * 255);
|
||||
|
||||
Painter.setPen(EdgeColor);
|
||||
if (Color->Code != LC_COLOR_NOCOLOR)
|
||||
Painter.setBrush(CellColor);
|
||||
else
|
||||
Painter.setBrush(Qt::NoBrush);
|
||||
|
||||
QRect CellRect = mCells[mCurrentCell].Rect;
|
||||
CellRect.adjust(1, 1, -1, -1);
|
||||
|
|
|
@ -6,12 +6,19 @@ struct lcColorListCell
|
|||
int ColorIndex;
|
||||
};
|
||||
|
||||
struct lcColorListGroup
|
||||
{
|
||||
QRect Rect;
|
||||
QString Name;
|
||||
std::vector<size_t> Cells;
|
||||
};
|
||||
|
||||
class lcQColorList : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcQColorList(QWidget* Parent = nullptr);
|
||||
lcQColorList(QWidget* Parent = nullptr, bool AllowNoColor = false);
|
||||
~lcQColorList() = default;
|
||||
|
||||
QSize sizeHint() const override;
|
||||
|
@ -38,7 +45,7 @@ protected:
|
|||
void keyPressEvent(QKeyEvent* KeyEvent) override;
|
||||
|
||||
std::vector<lcColorListCell> mCells;
|
||||
std::vector<QRect> mGroupRects;
|
||||
std::vector<lcColorListGroup> mGroups;
|
||||
|
||||
size_t mCurrentCell = 0;
|
||||
quint32 mColorCode = 0;
|
||||
|
@ -48,6 +55,7 @@ protected:
|
|||
int mWidth = 0;
|
||||
int mHeight = 0;
|
||||
int mPreferredHeight = 0;
|
||||
bool mAllowNoColor;
|
||||
|
||||
QPoint mDragStartPosition;
|
||||
};
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "lc_qcolorlist.h"
|
||||
#include "lc_colors.h"
|
||||
|
||||
lcQColorPickerPopup::lcQColorPickerPopup(QWidget *parent, int colorIndex)
|
||||
: QFrame(parent, Qt::Popup)
|
||||
lcQColorPickerPopup::lcQColorPickerPopup(QWidget* Parent, int ColorIndex, bool AllowNoColor)
|
||||
: QFrame(Parent, Qt::Popup)
|
||||
{
|
||||
setFrameStyle(QFrame::StyledPanel);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
|
@ -16,13 +16,13 @@ lcQColorPickerPopup::lcQColorPickerPopup(QWidget *parent, int colorIndex)
|
|||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(layout);
|
||||
|
||||
colorList = new lcQColorList(this);
|
||||
colorList = new lcQColorList(this, AllowNoColor);
|
||||
connect(colorList, SIGNAL(colorChanged(int)), this, SLOT(colorChanged(int)));
|
||||
connect(colorList, SIGNAL(colorSelected(int)), this, SLOT(colorSelected(int)));
|
||||
layout->addWidget(colorList);
|
||||
|
||||
colorList->blockSignals(true);
|
||||
colorList->setCurrentColor(colorIndex);
|
||||
colorList->setCurrentColor(ColorIndex);
|
||||
colorList->blockSignals(false);
|
||||
|
||||
eventLoop = nullptr;
|
||||
|
@ -75,17 +75,15 @@ void lcQColorPickerPopup::showEvent(QShowEvent *)
|
|||
colorList->setFocus();
|
||||
}
|
||||
|
||||
lcQColorPicker::lcQColorPicker(QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
lcQColorPicker::lcQColorPicker(QWidget* Parent, bool AllowNoColor)
|
||||
: QPushButton(Parent), mAllowNoColor(AllowNoColor)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
setAutoDefault(false);
|
||||
setCheckable(true);
|
||||
|
||||
initialColorIndex = 0;
|
||||
currentColorIndex = 0;
|
||||
updateIcon();
|
||||
UpdateIcon();
|
||||
|
||||
connect(this, SIGNAL(toggled(bool)), SLOT(buttonPressed(bool)));
|
||||
}
|
||||
|
@ -106,12 +104,12 @@ void lcQColorPicker::setCurrentColorCode(int colorCode)
|
|||
|
||||
int lcQColorPicker::currentColor() const
|
||||
{
|
||||
return currentColorIndex;
|
||||
return mCurrentColorIndex;
|
||||
}
|
||||
|
||||
int lcQColorPicker::currentColorCode() const
|
||||
{
|
||||
return gColorList[currentColorIndex].Code;
|
||||
return gColorList[mCurrentColorIndex].Code;
|
||||
}
|
||||
|
||||
void lcQColorPicker::buttonPressed(bool toggled)
|
||||
|
@ -119,7 +117,7 @@ void lcQColorPicker::buttonPressed(bool toggled)
|
|||
if (!toggled)
|
||||
return;
|
||||
|
||||
lcQColorPickerPopup *popup = new lcQColorPickerPopup(this, currentColorIndex);
|
||||
lcQColorPickerPopup *popup = new lcQColorPickerPopup(this, mCurrentColorIndex, mAllowNoColor);
|
||||
connect(popup, SIGNAL(changed(int)), SLOT(changed(int)));
|
||||
connect(popup, SIGNAL(selected(int)), SLOT(selected(int)));
|
||||
connect(popup, SIGNAL(hid()), SLOT(popupClosed()));
|
||||
|
@ -146,26 +144,41 @@ void lcQColorPicker::buttonPressed(bool toggled)
|
|||
popup->show();
|
||||
}
|
||||
|
||||
void lcQColorPicker::updateIcon()
|
||||
void lcQColorPicker::UpdateIcon()
|
||||
{
|
||||
int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||
QPixmap pix(iconSize, iconSize);
|
||||
const int IconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||
QPixmap Pixmap(IconSize, IconSize);
|
||||
|
||||
QPainter p(&pix);
|
||||
QPainter Painter(&Pixmap);
|
||||
|
||||
lcColor* color = &gColorList[currentColorIndex];
|
||||
p.setPen(Qt::darkGray);
|
||||
p.setBrush(QColor::fromRgbF(color->Value[0], color->Value[1], color->Value[2]));
|
||||
p.drawRect(0, 0, pix.width() - 1, pix.height() - 1);
|
||||
p.end();
|
||||
Painter.setPen(Qt::darkGray);
|
||||
|
||||
setIcon(QIcon(pix));
|
||||
const lcColor* Color = &gColorList[mCurrentColorIndex];
|
||||
|
||||
if (Color->Code != LC_COLOR_NOCOLOR)
|
||||
{
|
||||
Painter.setBrush(QColor::fromRgbF(Color->Value[0], Color->Value[1], Color->Value[2]));
|
||||
Painter.drawRect(0, 0, Pixmap.width() - 1, Pixmap.height() - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Painter.setBrush(Qt::black);
|
||||
Painter.drawRect(0, 0, Pixmap.width() - 1, Pixmap.height() - 1);
|
||||
|
||||
const int SquareSize = IconSize / 2 - 1;
|
||||
Painter.fillRect(1, 1, SquareSize, SquareSize, Qt::white);
|
||||
Painter.fillRect(1 + SquareSize, 1 + SquareSize, SquareSize, SquareSize, Qt::white);
|
||||
}
|
||||
|
||||
Painter.end();
|
||||
|
||||
setIcon(QIcon(Pixmap));
|
||||
}
|
||||
|
||||
void lcQColorPicker::popupClosed()
|
||||
{
|
||||
if (initialColorIndex != currentColorIndex)
|
||||
changed(initialColorIndex);
|
||||
if (mInitialColorIndex != mCurrentColorIndex)
|
||||
changed(mInitialColorIndex);
|
||||
|
||||
setChecked(false);
|
||||
setFocus();
|
||||
|
@ -173,19 +186,19 @@ void lcQColorPicker::popupClosed()
|
|||
|
||||
void lcQColorPicker::changed(int colorIndex)
|
||||
{
|
||||
if (colorIndex == currentColorIndex)
|
||||
if (colorIndex == mCurrentColorIndex)
|
||||
return;
|
||||
|
||||
currentColorIndex = colorIndex;
|
||||
updateIcon();
|
||||
mCurrentColorIndex = colorIndex;
|
||||
UpdateIcon();
|
||||
|
||||
repaint();
|
||||
|
||||
emit colorChanged(currentColorIndex);
|
||||
emit colorChanged(mCurrentColorIndex);
|
||||
}
|
||||
|
||||
void lcQColorPicker::selected(int colorIndex)
|
||||
{
|
||||
initialColorIndex = colorIndex;
|
||||
mInitialColorIndex = colorIndex;
|
||||
changed(colorIndex);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class lcQColorPickerPopup : public QFrame
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcQColorPickerPopup(QWidget *parent = nullptr, int colorIndex = 0);
|
||||
lcQColorPickerPopup(QWidget* Parent = nullptr, int ColorIndex = 0, bool AllowNoColor = false);
|
||||
~lcQColorPickerPopup();
|
||||
|
||||
void exec();
|
||||
|
@ -28,8 +28,8 @@ protected:
|
|||
void mouseReleaseEvent(QMouseEvent* MouseEvent) override;
|
||||
|
||||
private:
|
||||
QEventLoop *eventLoop;
|
||||
lcQColorList *colorList;
|
||||
QEventLoop* eventLoop;
|
||||
lcQColorList* colorList;
|
||||
};
|
||||
|
||||
class lcQColorPicker : public QPushButton
|
||||
|
@ -37,7 +37,7 @@ class lcQColorPicker : public QPushButton
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcQColorPicker(QWidget *parent = 0);
|
||||
lcQColorPicker(QWidget* Parent = nullptr, bool AllowNoColor = false);
|
||||
~lcQColorPicker();
|
||||
|
||||
int currentColor() const;
|
||||
|
@ -52,15 +52,14 @@ public slots:
|
|||
signals:
|
||||
void colorChanged(int colorIndex);
|
||||
|
||||
protected:
|
||||
void updateIcon();
|
||||
|
||||
private slots:
|
||||
void buttonPressed(bool toggled);
|
||||
void popupClosed();
|
||||
|
||||
private:
|
||||
int currentColorIndex;
|
||||
int initialColorIndex;
|
||||
};
|
||||
protected:
|
||||
void UpdateIcon();
|
||||
|
||||
int mCurrentColorIndex = 0;
|
||||
int mInitialColorIndex = 0;
|
||||
bool mAllowNoColor = false;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue