Skip to content

Commit f9d1e6e

Browse files
committed
Use QBrush instead of QColor for background painting
1 parent 6f2d6aa commit f9d1e6e

4 files changed

Lines changed: 37 additions & 28 deletions

File tree

src/color_manager.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ ColoredArea::ColoredArea()
1010
_posStart = 0;
1111
_posEnd = 0;
1212
_fontColor = QPen(QColor::fromRgba(qRgba(0, 0, 0, 0)));
13-
_areaColor = QColor::fromRgba(qRgba(0, 0, 0, 0));
13+
_areaStyle = QColor::fromRgba(qRgba(0, 0, 0, 0));
1414
}
1515

16-
ColoredArea::ColoredArea(QPen pen, QColor background)
16+
ColoredArea::ColoredArea(QPen pen, QBrush background)
1717
{
1818
_posStart = 0;
1919
_posEnd = 0;
2020
_fontColor = pen;
21-
_areaColor = background;
21+
_areaStyle = background;
2222
}
2323

24-
ColoredArea::ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QColor background)
24+
ColoredArea::ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background)
2525
{
2626
_posStart = posStart;
2727
_posEnd = posEnd;
2828
_fontColor = pen;
29-
_areaColor = background;
29+
_areaStyle = background;
3030
}
3131

3232
QPen ColoredArea::fontPen()
@@ -46,12 +46,22 @@ void ColoredArea::setFontColor(QColor color)
4646

4747
QColor ColoredArea::areaColor()
4848
{
49-
return _areaColor;
49+
return _areaStyle.color();
50+
}
51+
52+
QBrush ColoredArea::areaStyle()
53+
{
54+
return _areaStyle;
5055
}
5156

5257
void ColoredArea::setAreaColor(QColor color)
5358
{
54-
_areaColor = color;
59+
_areaStyle.setColor(color);
60+
}
61+
62+
void ColoredArea::setAreaStyle(QBrush backround)
63+
{
64+
_areaStyle = backround;
5565
}
5666

5767
qint64 ColoredArea::posStart()
@@ -87,11 +97,11 @@ ColorManager::ColorManager()
8797

8898
void ColorManager::setPalette(const QPalette &palette)
8999
{
90-
_selection = ColoredArea(palette.highlightedText().color(), palette.highlight().color());
100+
_selection = ColoredArea(palette.highlightedText().color(), palette.highlight());
91101
_highlighting = ColoredArea(QColor::fromRgb(0, 0, 0), QColor(0xff, 0xff, 0x99));
92-
_address = ColoredArea(palette.windowText().color(), palette.alternateBase().color());
93-
_hex = ColoredArea(palette.windowText().color(), palette.base().color());
94-
_ascii = ColoredArea(palette.windowText().color(), palette.alternateBase().color());
102+
_address = ColoredArea(palette.windowText().color(), palette.alternateBase());
103+
_hex = ColoredArea(palette.windowText().color(), palette.base());
104+
_ascii = ColoredArea(palette.windowText().color(), palette.alternateBase());
95105
}
96106

97107
// read only, copy of relevant ColoredArea is returned: you can't change anything
@@ -145,9 +155,9 @@ ColoredArea& ColorManager::highlighting()
145155
return _highlighting;
146156
};
147157

148-
void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QColor areaColor)
158+
void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle)
149159
{
150-
ColoredArea userArea = ColoredArea(posStart, posEnd, fontColor, areaColor);
160+
ColoredArea userArea = ColoredArea(posStart, posEnd, fontColor, areaStyle);
151161
_userAreas.append(userArea);
152162
}
153163

src/color_manager.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ class ColoredArea
3131
public:
3232
// Cunstructors
3333
ColoredArea();
34-
ColoredArea(QPen pen, QColor background);
35-
ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QColor background);
34+
ColoredArea(QPen pen, QBrush background);
35+
ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background);
3636

3737
// Property to set/get font color
3838
QColor fontColor();
3939
void setFontColor(QColor color);
4040

41-
// Property to set/get area color
41+
// Property to set/get area style
4242
QColor areaColor();
43+
QBrush areaStyle();
4344
void setAreaColor(QColor color);
45+
void setAreaStyle(QBrush background);
4446

4547
// other Methods to acces and set internal data
4648
QPen fontPen();
@@ -53,7 +55,7 @@ class ColoredArea
5355
qint64 _posStart;
5456
qint64 _posEnd;
5557
QPen _fontColor;
56-
QColor _areaColor;
58+
QBrush _areaStyle;
5759
};
5860

5961

@@ -79,15 +81,12 @@ class ColorManager
7981
ColoredArea& highlighting();
8082

8183
// Add a user defined area
82-
void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QColor areaColor);
84+
void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle);
8385

8486
// Clear all user defined areas
8587
void clearUserAreas();
8688

8789
private:
88-
QPalette _darkPalette;
89-
QPalette _brightPalette;
90-
9190
ColoredArea _highlighting;
9291
ColoredArea _selection;
9392
ColoredArea _address;

src/qhexedit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ void QHexEdit::replace(qint64 pos, qint64 len, const QByteArray &ba)
350350
}
351351

352352
// ********************************************************************** User marking areas
353-
void QHexEdit::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QColor areaColor)
353+
void QHexEdit::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle)
354354
{
355-
_colorManager->addUserArea(posStart, posEnd, fontColor, areaColor);
355+
_colorManager->addUserArea(posStart, posEnd, fontColor, areaStyle);
356356
}
357357

358358
void QHexEdit::clearUserAreas()
@@ -855,7 +855,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
855855
_pxCharWidth * (_addrDigits + 1),
856856
height()
857857
),
858-
_colorManager->notMarked(Area::Address).areaColor()
858+
_colorManager->notMarked(Area::Address).areaStyle()
859859
);
860860
if (_asciiArea)
861861
{
@@ -866,7 +866,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
866866
_pxCharWidth * _bytesPerLine,
867867
height()
868868
),
869-
_colorManager->notMarked(Area::Ascii).areaColor()
869+
_colorManager->notMarked(Area::Ascii).areaStyle()
870870
);
871871
}
872872

@@ -910,7 +910,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
910910
3*_pxCharWidth,
911911
_pxCharHeight
912912
);
913-
painter.fillRect(rect, hexArea.areaColor());
913+
painter.fillRect(rect, hexArea.areaStyle());
914914
hex = _hexDataShown.mid((bPosLine + colIdx) * 2, 2);
915915
painter.drawText(pxPosX, pxPosY, hexCaps()?hex.toUpper():hex);
916916
pxPosX += 3*_pxCharWidth;
@@ -925,7 +925,7 @@ void QHexEdit::paintEvent(QPaintEvent *event)
925925
if ( ch < ' ' || ch > '~' )
926926
ch = '.';
927927
rect.setRect(pxPosAsciiX2, pxPosY - _pxCharHeight + _pxSelectionSub, _pxCharWidth, _pxCharHeight);
928-
painter.fillRect(rect, asciiArea.areaColor());
928+
painter.fillRect(rect, asciiArea.areaStyle());
929929
painter.drawText(pxPosAsciiX2, pxPosY, QChar(ch));
930930
pxPosAsciiX2 += _pxCharWidth;
931931
}

src/qhexedit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class QHEXEDIT_API QHexEdit : public QAbstractScrollArea
210210
prioritized in the event of overlaps. The areas defined first
211211
have priority over areas that follow later.
212212
*/
213-
void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QColor areaColor);
213+
void addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle);
214214

215215
/*! Delets all user defined areas
216216
*/

0 commit comments

Comments
 (0)