1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/*
* QHexEdit is a Hex Editor Widget for the Qt Framework
* Copyright (C) 2010-2025 Winfried Simon
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* https://www.gnu.org/licenses/
*/
#include "color_manager.h"
#include <QApplication>
#include <QStyleFactory>
#include <QtGui>
#include <QtCore>
ColoredArea::ColoredArea()
{
_posStart = 0;
_posEnd = 0;
_fontColor = QPen(QColor::fromRgba(qRgba(0, 0, 0, 0)));
_areaStyle = QColor::fromRgba(qRgba(0, 0, 0, 0));
}
ColoredArea::ColoredArea(QPen pen, QBrush background)
{
_posStart = 0;
_posEnd = 0;
_fontColor = pen;
_areaStyle = background;
}
ColoredArea::ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background)
{
_posStart = posStart;
_posEnd = posEnd;
_fontColor = pen;
_areaStyle = background;
}
QPen ColoredArea::fontPen()
{
return _fontColor;
}
QColor ColoredArea::fontColor()
{
return _fontColor.color();
}
void ColoredArea::setFontColor(QColor color)
{
_fontColor = QPen(color);
}
QColor ColoredArea::areaColor()
{
return _areaStyle.color();
}
QBrush ColoredArea::areaStyle()
{
return _areaStyle;
}
void ColoredArea::setAreaColor(QColor color)
{
_areaStyle.setColor(color);
}
void ColoredArea::setAreaStyle(QBrush backround)
{
_areaStyle = backround;
}
qint64 ColoredArea::posStart()
{
return _posStart;
};
qint64 ColoredArea::posEnd()
{
return _posEnd;
};
void ColoredArea::setRange(qint64 posStart, qint64 posEnd)
{
_posStart = posStart;
_posEnd = posEnd;
};
void ColoredArea::clear()
{
_posStart = 0;
_posEnd = 0;
}
/********************************************* */
ColorManager::ColorManager()
{
QPalette palette = qApp->palette();
setPalette(palette);
};
void ColorManager::setPalette(const QPalette &palette)
{
_selection = ColoredArea(palette.highlightedText().color(), palette.highlight());
_highlighting = ColoredArea(QColor::fromRgb(0, 0, 0), QColor(0xff, 0xff, 0x99));
_address = ColoredArea(palette.windowText().color(), palette.alternateBase());
_hex = ColoredArea(palette.windowText().color(), palette.base());
_ascii = ColoredArea(palette.windowText().color(), palette.alternateBase());
}
// read only, copy of relevant ColoredArea is returned: you can't change anything
ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks)
{
// prio 1 selection
if (pos >= _selection.posStart() && pos < _selection.posEnd())
{
return _selection;
}
// prio 2 highlighting (changed data)
if (chunks->dataChanged(pos))
{
return _highlighting;
}
// prio 3 user defined areas
foreach (ColoredArea area, _userAreas)
{
if (pos >= area.posStart() && pos < area.posEnd())
{
return area;
}
}
// nothing found -> standard colors
return this->notMarked(area);
};
ColoredArea& ColorManager::notMarked(Area area)
{
switch (area) {
case Area::Address:
return _address;
break;
case Area::Ascii:
return _ascii;
break;
case Area::Hex:
return _hex;
break;
}
return _hex; // should never happen
}
ColoredArea& ColorManager::selection()
{
return _selection;
};
ColoredArea& ColorManager::highlighting()
{
return _highlighting;
};
void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle)
{
ColoredArea userArea = ColoredArea(posStart, posEnd, fontColor, areaStyle);
_userAreas.append(userArea);
}
void ColorManager::clearUserAreas()
{
_userAreas.clear();
}
|