mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Refactored no color drawing.
This commit is contained in:
parent
680511879a
commit
6c5e05570c
3 changed files with 55 additions and 35 deletions
|
@ -4,6 +4,47 @@
|
||||||
#include "lc_library.h"
|
#include "lc_library.h"
|
||||||
#include "lc_colors.h"
|
#include "lc_colors.h"
|
||||||
|
|
||||||
|
void lcDrawNoColorRect(QPainter& Painter, const QRect& Rect)
|
||||||
|
{
|
||||||
|
Painter.setBrush(Qt::black);
|
||||||
|
Painter.drawRect(Rect);
|
||||||
|
|
||||||
|
const int SquareSize = 3;
|
||||||
|
int Column = 0;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int x = Rect.left() + 1 + Column * SquareSize;
|
||||||
|
|
||||||
|
if (x >= Rect.right())
|
||||||
|
break;
|
||||||
|
|
||||||
|
int Row = Column & 1;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int y = Rect.top() + 1 + Row * SquareSize;
|
||||||
|
|
||||||
|
if (y >= Rect.bottom())
|
||||||
|
break;
|
||||||
|
|
||||||
|
QRect GridRect(x, y, SquareSize, SquareSize);
|
||||||
|
|
||||||
|
if (GridRect.right() > Rect.right())
|
||||||
|
GridRect.setRight(Rect.right());
|
||||||
|
|
||||||
|
if (GridRect.bottom() > Rect.bottom())
|
||||||
|
GridRect.setBottom(Rect.bottom());
|
||||||
|
|
||||||
|
Painter.fillRect(GridRect, Qt::white);
|
||||||
|
|
||||||
|
Row += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Column++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lcQColorList::lcQColorList(QWidget* Parent, bool AllowNoColor)
|
lcQColorList::lcQColorList(QWidget* Parent, bool AllowNoColor)
|
||||||
: QWidget(Parent), mAllowNoColor(AllowNoColor)
|
: QWidget(Parent), mAllowNoColor(AllowNoColor)
|
||||||
{
|
{
|
||||||
|
@ -125,7 +166,7 @@ void lcQColorList::UpdateRects()
|
||||||
const int Left = CellWidth * CurColumn - 1;
|
const int Left = CellWidth * CurColumn - 1;
|
||||||
const int Right = (CurColumn + 1) * CellWidth - 1;
|
const int Right = (CurColumn + 1) * CellWidth - 1;
|
||||||
const int Top = GroupY + CellHeight * NumRows;
|
const int Top = GroupY + CellHeight * NumRows;
|
||||||
const int Bottom = (TotalRows != mRows) ? GroupY + CellHeight * (NumRows + 1) : height();
|
const int Bottom = (TotalRows != mRows) ? GroupY + CellHeight * (NumRows + 1) : height() - 1;
|
||||||
|
|
||||||
mCells[CurCell].Rect = QRect(Left, Top, Right - Left, Bottom - Top);
|
mCells[CurCell].Rect = QRect(Left, Top, Right - Left, Bottom - Top);
|
||||||
|
|
||||||
|
@ -198,14 +239,7 @@ bool lcQColorList::event(QEvent *event)
|
||||||
if (color->Code != LC_COLOR_NOCOLOR)
|
if (color->Code != LC_COLOR_NOCOLOR)
|
||||||
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
painter.drawRect(0, 0, image.width() - 1, image.height() - 1);
|
||||||
else
|
else
|
||||||
{
|
lcDrawNoColorRect(painter, QRect(0, 0, image.width() - 1, image.height() - 1));
|
||||||
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();
|
painter.end();
|
||||||
|
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
|
@ -403,37 +437,28 @@ void lcQColorList::paintEvent(QPaintEvent* Event)
|
||||||
|
|
||||||
for (size_t CellIndex = 0; CellIndex < mCells.size(); CellIndex++)
|
for (size_t CellIndex = 0; CellIndex < mCells.size(); CellIndex++)
|
||||||
{
|
{
|
||||||
lcColor* Color = &gColorList[mCells[CellIndex].ColorIndex];
|
const lcColor* Color = &gColorList[mCells[CellIndex].ColorIndex];
|
||||||
QColor CellColor(Color->Value[0] * 255, Color->Value[1] * 255, Color->Value[2] * 255);
|
|
||||||
|
|
||||||
Painter.setBrush(CellColor);
|
|
||||||
const QRect& Rect = mCells[CellIndex].Rect;
|
const QRect& Rect = mCells[CellIndex].Rect;
|
||||||
|
|
||||||
if (Color->Code != LC_COLOR_NOCOLOR)
|
if (Color->Code != LC_COLOR_NOCOLOR)
|
||||||
Painter.drawRect(Rect);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Painter.setBrush(Qt::black);
|
QColor CellColor(Color->Value[0] * 255, Color->Value[1] * 255, Color->Value[2] * 255);
|
||||||
Painter.drawRect(Rect);
|
|
||||||
|
|
||||||
const int SquareWidth = Rect.width() / 2 - 1;
|
Painter.setBrush(CellColor);
|
||||||
const int SquareHeight = Rect.height() / 2 - 1;
|
Painter.drawRect(Rect);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
lcDrawNoColorRect(Painter, Rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mCurrentCell < mCells.size())
|
if (mCurrentCell < mCells.size())
|
||||||
{
|
{
|
||||||
lcColor* Color = &gColorList[mCells[mCurrentCell].ColorIndex];
|
const lcColor* Color = &gColorList[mCells[mCurrentCell].ColorIndex];
|
||||||
QColor EdgeColor(255 - Color->Value[0] * 255, 255 - Color->Value[1] * 255, 255 - Color->Value[2] * 255);
|
QColor EdgeColor(255 - Color->Value[0] * 255, 255 - Color->Value[1] * 255, 255 - Color->Value[2] * 255);
|
||||||
QColor CellColor(Color->Value[0] * 255, Color->Value[1] * 255, Color->Value[2] * 255);
|
|
||||||
|
|
||||||
Painter.setPen(EdgeColor);
|
Painter.setPen(EdgeColor);
|
||||||
if (Color->Code != LC_COLOR_NOCOLOR)
|
Painter.setBrush(Qt::NoBrush);
|
||||||
Painter.setBrush(CellColor);
|
|
||||||
else
|
|
||||||
Painter.setBrush(Qt::NoBrush);
|
|
||||||
|
|
||||||
QRect CellRect = mCells[mCurrentCell].Rect;
|
QRect CellRect = mCells[mCurrentCell].Rect;
|
||||||
CellRect.adjust(1, 1, -1, -1);
|
CellRect.adjust(1, 1, -1, -1);
|
||||||
|
|
|
@ -13,6 +13,8 @@ struct lcColorListGroup
|
||||||
std::vector<size_t> Cells;
|
std::vector<size_t> Cells;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void lcDrawNoColorRect(QPainter& Painter, const QRect& Rect);
|
||||||
|
|
||||||
class lcQColorList : public QWidget
|
class lcQColorList : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
@ -146,7 +146,7 @@ void lcQColorPicker::buttonPressed(bool toggled)
|
||||||
|
|
||||||
void lcQColorPicker::UpdateIcon()
|
void lcQColorPicker::UpdateIcon()
|
||||||
{
|
{
|
||||||
const int IconSize = style()->pixelMetric(QStyle::PM_SmallIconSize);
|
const int IconSize = 14;//style()->pixelMetric(QStyle::PM_SmallIconSize);
|
||||||
QPixmap Pixmap(IconSize, IconSize);
|
QPixmap Pixmap(IconSize, IconSize);
|
||||||
|
|
||||||
QPainter Painter(&Pixmap);
|
QPainter Painter(&Pixmap);
|
||||||
|
@ -161,14 +161,7 @@ void lcQColorPicker::UpdateIcon()
|
||||||
Painter.drawRect(0, 0, Pixmap.width() - 1, Pixmap.height() - 1);
|
Painter.drawRect(0, 0, Pixmap.width() - 1, Pixmap.height() - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
lcDrawNoColorRect(Painter, QRect(0, 0, Pixmap.width() - 1, Pixmap.height() - 1));
|
||||||
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();
|
Painter.end();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue