Commit 91d7001e authored by Gustavo Carneiro's avatar Gustavo Carneiro Committed by Tomaz Canabrava
Browse files

Rename ColorEntry to QColor.

parent 3480514e
......@@ -14,40 +14,40 @@
using namespace Konsole;
const ColorEntry CharacterColorTest::DefaultColorTable[TABLE_COLORS] = {
ColorEntry(0x00, 0x00, 0x00), // Dfore
ColorEntry(0xFF, 0xFF, 0xFF), // Dback
ColorEntry(0x00, 0x00, 0x00), // Black
ColorEntry(0xB2, 0x18, 0x18), // Red
ColorEntry(0x18, 0xB2, 0x18), // Green
ColorEntry(0xB2, 0x68, 0x18), // Yellow
ColorEntry(0x18, 0x18, 0xB2), // Blue
ColorEntry(0xB2, 0x18, 0xB2), // Magenta
ColorEntry(0x18, 0xB2, 0xB2), // Cyan
ColorEntry(0xB2, 0xB2, 0xB2), // White
const QColor CharacterColorTest::DefaultColorTable[TABLE_COLORS] = {
QColor(0x00, 0x00, 0x00), // Dfore
QColor(0xFF, 0xFF, 0xFF), // Dback
QColor(0x00, 0x00, 0x00), // Black
QColor(0xB2, 0x18, 0x18), // Red
QColor(0x18, 0xB2, 0x18), // Green
QColor(0xB2, 0x68, 0x18), // Yellow
QColor(0x18, 0x18, 0xB2), // Blue
QColor(0xB2, 0x18, 0xB2), // Magenta
QColor(0x18, 0xB2, 0xB2), // Cyan
QColor(0xB2, 0xB2, 0xB2), // White
// intensive versions
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x68, 0x68, 0x68),
ColorEntry(0xFF, 0x54, 0x54),
ColorEntry(0x54, 0xFF, 0x54),
ColorEntry(0xFF, 0xFF, 0x54),
ColorEntry(0x54, 0x54, 0xFF),
ColorEntry(0xFF, 0x54, 0xFF),
ColorEntry(0x54, 0xFF, 0xFF),
ColorEntry(0xFF, 0xFF, 0xFF),
QColor(0x00, 0x00, 0x00),
QColor(0xFF, 0xFF, 0xFF),
QColor(0x68, 0x68, 0x68),
QColor(0xFF, 0x54, 0x54),
QColor(0x54, 0xFF, 0x54),
QColor(0xFF, 0xFF, 0x54),
QColor(0x54, 0x54, 0xFF),
QColor(0xFF, 0x54, 0xFF),
QColor(0x54, 0xFF, 0xFF),
QColor(0xFF, 0xFF, 0xFF),
// Here are faint intensities, which may not be good.
// faint versions
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0x65, 0x00, 0x00),
ColorEntry(0x00, 0x65, 0x00),
ColorEntry(0x65, 0x5E, 0x00),
ColorEntry(0x00, 0x00, 0x65),
ColorEntry(0x65, 0x00, 0x65),
ColorEntry(0x00, 0x65, 0x65),
ColorEntry(0x65, 0x65, 0x65)
QColor(0x00, 0x00, 0x00),
QColor(0xFF, 0xFF, 0xFF),
QColor(0x00, 0x00, 0x00),
QColor(0x65, 0x00, 0x00),
QColor(0x00, 0x65, 0x00),
QColor(0x65, 0x5E, 0x00),
QColor(0x00, 0x00, 0x65),
QColor(0x65, 0x00, 0x65),
QColor(0x00, 0x65, 0x65),
QColor(0x65, 0x65, 0x65)
};
void CharacterColorTest::init()
......@@ -60,10 +60,10 @@ void CharacterColorTest::cleanup()
void CharacterColorTest::testColorEntry()
{
ColorEntry black = ColorEntry(0x00, 0x00, 0x00);
ColorEntry white = ColorEntry(0xFF, 0xFF, 0xFF);
ColorEntry red = ColorEntry(0xB2, 0x18, 0x18);
ColorEntry green = ColorEntry(0x18, 0xB2, 0x18);
QColor black = QColor(0x00, 0x00, 0x00);
QColor white = QColor(0xFF, 0xFF, 0xFF);
QColor red = QColor(0xB2, 0x18, 0x18);
QColor green = QColor(0x18, 0xB2, 0x18);
// Test operator== operator!=
QCOMPARE(black == white, false);
......@@ -75,13 +75,13 @@ void CharacterColorTest::testColorEntry()
QCOMPARE(red != green, true);
// Test operator=
ColorEntry tmpColorEntry;
QColor tmpColorEntry;
tmpColorEntry = red;
QCOMPARE(tmpColorEntry == red, true);
QCOMPARE(red == tmpColorEntry, true);
// Test ColorEntry()
ColorEntry defaultColorEntry = ColorEntry();
// Test QColor()
QColor defaultColorEntry = QColor();
QCOMPARE(defaultColorEntry != green, true);
QCOMPARE(defaultColorEntry != black, true);
QCOMPARE(defaultColorEntry.isValid(), false);
......
......@@ -35,7 +35,7 @@ private Q_SLOTS:
void testColor256();
private:
static const ColorEntry DefaultColorTable[];
static const QColor DefaultColorTable[];
};
}
......
......@@ -37,30 +37,30 @@ void TerminalTest::testScrollBarPositions()
void TerminalTest::testColorTable()
{
// These are from ColorScheme.cpp but they can be anything to test
const ColorEntry defaultTable[TABLE_COLORS] = {
ColorEntry(0x00, 0x00, 0x00), ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x00, 0x00, 0x00), ColorEntry(0xB2, 0x18, 0x18),
ColorEntry(0x18, 0xB2, 0x18), ColorEntry(0xB2, 0x68, 0x18),
ColorEntry(0x18, 0x18, 0xB2), ColorEntry(0xB2, 0x18, 0xB2),
ColorEntry(0x18, 0xB2, 0xB2), ColorEntry(0xB2, 0xB2, 0xB2),
ColorEntry(0x00, 0x00, 0x00), ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x68, 0x68, 0x68), ColorEntry(0xFF, 0x54, 0x54),
ColorEntry(0x54, 0xFF, 0x54), ColorEntry(0xFF, 0xFF, 0x54),
ColorEntry(0x54, 0x54, 0xFF), ColorEntry(0xFF, 0x54, 0xFF),
ColorEntry(0x54, 0xFF, 0xFF), ColorEntry(0x00, 0xFF, 0xFF)
const QColor defaultTable[TABLE_COLORS] = {
QColor(0x00, 0x00, 0x00), QColor(0xFF, 0xFF, 0xFF),
QColor(0x00, 0x00, 0x00), QColor(0xB2, 0x18, 0x18),
QColor(0x18, 0xB2, 0x18), QColor(0xB2, 0x68, 0x18),
QColor(0x18, 0x18, 0xB2), QColor(0xB2, 0x18, 0xB2),
QColor(0x18, 0xB2, 0xB2), QColor(0xB2, 0xB2, 0xB2),
QColor(0x00, 0x00, 0x00), QColor(0xFF, 0xFF, 0xFF),
QColor(0x68, 0x68, 0x68), QColor(0xFF, 0x54, 0x54),
QColor(0x54, 0xFF, 0x54), QColor(0xFF, 0xFF, 0x54),
QColor(0x54, 0x54, 0xFF), QColor(0xFF, 0x54, 0xFF),
QColor(0x54, 0xFF, 0xFF), QColor(0x00, 0xFF, 0xFF)
};
auto display = new TerminalDisplay(nullptr);
display->terminalColor()->setColorTable(defaultTable);
const ColorEntry *colorTable = display->terminalColor()->colorTable();
const QColor *colorTable = display->terminalColor()->colorTable();
for (int i = 0; i < TABLE_COLORS; i++) {
QCOMPARE(colorTable[i], defaultTable[i]);
}
ColorEntry colorEntry = ColorEntry(0x00, 0x00, 0x00);
QColor colorEntry = QColor(0x00, 0x00, 0x00);
QVERIFY(colorTable[1] != colorEntry);
delete display;
......
......@@ -12,13 +12,6 @@
#include <QColor>
namespace Konsole {
/**
* An entry in a terminal display's color palette.
*
* A color palette is an array of 16 ColorEntry instances which map
* system color indexes (from 0 to 15) into actual colors.
*/
typedef QColor ColorEntry;
// Attributed Character Representations ///////////////////////////////
......@@ -177,7 +170,7 @@ public:
* The @p base is only used if this color is one of the 16 system colors, otherwise
* it is ignored.
*/
QColor color(const ColorEntry *base) const;
QColor color(const QColor *base) const;
/**
* Compares two colors and returns true if they represent the same color value and
......@@ -212,7 +205,7 @@ inline bool operator !=(const CharacterColor &a, const CharacterColor &b)
return !operator==(a, b);
}
inline const QColor color256(quint8 u, const ColorEntry *base)
inline const QColor color256(quint8 u, const QColor *base)
{
// 0.. 16: system colors
if (u < 8) {
......@@ -238,7 +231,7 @@ inline const QColor color256(quint8 u, const ColorEntry *base)
return QColor(gray, gray, gray);
}
inline QColor CharacterColor::color(const ColorEntry *base) const
inline QColor CharacterColor::color(const QColor *base) const
{
switch (_colorSpace) {
case COLOR_SPACE_DEFAULT:
......
......@@ -43,40 +43,40 @@ using namespace Konsole;
// The following are almost IBM standard color codes, with some slight
// gamma correction for the dim colors to compensate for bright X screens.
// It contains the 8 ansiterm/xterm colors in 2 intensities.
const ColorEntry ColorScheme::defaultTable[TABLE_COLORS] = {
ColorEntry(0x00, 0x00, 0x00), // Dfore
ColorEntry(0xFF, 0xFF, 0xFF), // Dback
ColorEntry(0x00, 0x00, 0x00), // Black
ColorEntry(0xB2, 0x18, 0x18), // Red
ColorEntry(0x18, 0xB2, 0x18), // Green
ColorEntry(0xB2, 0x68, 0x18), // Yellow
ColorEntry(0x18, 0x18, 0xB2), // Blue
ColorEntry(0xB2, 0x18, 0xB2), // Magenta
ColorEntry(0x18, 0xB2, 0xB2), // Cyan
ColorEntry(0xB2, 0xB2, 0xB2), // White
const QColor ColorScheme::defaultTable[TABLE_COLORS] = {
QColor(0x00, 0x00, 0x00), // Dfore
QColor(0xFF, 0xFF, 0xFF), // Dback
QColor(0x00, 0x00, 0x00), // Black
QColor(0xB2, 0x18, 0x18), // Red
QColor(0x18, 0xB2, 0x18), // Green
QColor(0xB2, 0x68, 0x18), // Yellow
QColor(0x18, 0x18, 0xB2), // Blue
QColor(0xB2, 0x18, 0xB2), // Magenta
QColor(0x18, 0xB2, 0xB2), // Cyan
QColor(0xB2, 0xB2, 0xB2), // White
// intensive versions
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x68, 0x68, 0x68),
ColorEntry(0xFF, 0x54, 0x54),
ColorEntry(0x54, 0xFF, 0x54),
ColorEntry(0xFF, 0xFF, 0x54),
ColorEntry(0x54, 0x54, 0xFF),
ColorEntry(0xFF, 0x54, 0xFF),
ColorEntry(0x54, 0xFF, 0xFF),
ColorEntry(0xFF, 0xFF, 0xFF),
QColor(0x00, 0x00, 0x00),
QColor(0xFF, 0xFF, 0xFF),
QColor(0x68, 0x68, 0x68),
QColor(0xFF, 0x54, 0x54),
QColor(0x54, 0xFF, 0x54),
QColor(0xFF, 0xFF, 0x54),
QColor(0x54, 0x54, 0xFF),
QColor(0xFF, 0x54, 0xFF),
QColor(0x54, 0xFF, 0xFF),
QColor(0xFF, 0xFF, 0xFF),
// Here are faint intensities, which may not be good.
// faint versions
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0xFF, 0xFF, 0xFF),
ColorEntry(0x00, 0x00, 0x00),
ColorEntry(0x65, 0x00, 0x00),
ColorEntry(0x00, 0x65, 0x00),
ColorEntry(0x65, 0x5E, 0x00),
ColorEntry(0x00, 0x00, 0x65),
ColorEntry(0x65, 0x00, 0x65),
ColorEntry(0x00, 0x65, 0x65),
ColorEntry(0x65, 0x65, 0x65)
QColor(0x00, 0x00, 0x00),
QColor(0xFF, 0xFF, 0xFF),
QColor(0x00, 0x00, 0x00),
QColor(0x65, 0x00, 0x00),
QColor(0x00, 0x65, 0x00),
QColor(0x65, 0x5E, 0x00),
QColor(0x00, 0x00, 0x65),
QColor(0x65, 0x00, 0x65),
QColor(0x00, 0x65, 0x65),
QColor(0x65, 0x65, 0x65)
};
const char * const ColorScheme::colorNames[TABLE_COLORS] = {
......@@ -224,12 +224,12 @@ QString ColorScheme::name() const
return _name;
}
void ColorScheme::setColorTableEntry(int index, const ColorEntry &entry)
void ColorScheme::setColorTableEntry(int index, const QColor &entry)
{
Q_ASSERT(index >= 0 && index < TABLE_COLORS);
if (_table == nullptr) {
_table = new ColorEntry[TABLE_COLORS];
_table = new QColor[TABLE_COLORS];
for (int i = 0; i < TABLE_COLORS; i++) {
_table[i] = defaultTable[i];
......@@ -244,11 +244,11 @@ void ColorScheme::setColorTableEntry(int index, const ColorEntry &entry)
}
}
ColorEntry ColorScheme::colorEntry(int index, uint randomSeed) const
QColor ColorScheme::colorEntry(int index, uint randomSeed) const
{
Q_ASSERT(index >= 0 && index < TABLE_COLORS);
ColorEntry entry = colorTable()[index];
QColor entry = colorTable()[index];
if (!_colorRandomization || randomSeed == 0 || _randomTable == nullptr
|| _randomTable[index].isNull()) {
......@@ -320,7 +320,7 @@ ColorEntry ColorScheme::colorEntry(int index, uint randomSeed) const
return {qRound(red * 255), qRound(green * 255), qRound(blue * 255)};
}
void ColorScheme::getColorTable(ColorEntry *table, uint randomSeed) const
void ColorScheme::getColorTable(QColor *table, uint randomSeed) const
{
for (int i = 0; i < TABLE_COLORS; i++) {
table[i] = colorEntry(i, randomSeed);
......@@ -370,7 +370,7 @@ void ColorScheme::setRandomizationRange(int index, double hue, double saturation
_randomTable[index].lightness = lightness;
}
const ColorEntry *ColorScheme::colorTable() const
const QColor *ColorScheme::colorTable() const
{
if (_table != nullptr) {
return _table;
......@@ -450,7 +450,7 @@ void ColorScheme::readColorEntry(const KConfig &config, int index)
return;
}
ColorEntry entry;
QColor entry;
entry = configGroup.readEntry("Color", QColor());
setColorTableEntry(index, entry);
......@@ -496,7 +496,7 @@ void ColorScheme::writeColorEntry(KConfig &config, int index) const
{
KConfigGroup configGroup = config.group(colorNameForIndex(index));
const ColorEntry &entry = colorTable()[index];
const QColor &entry = colorTable()[index];
configGroup.writeEntry("Color", entry);
......
......@@ -57,7 +57,7 @@ public:
void write(KConfig &config) const;
/** Sets a single entry within the color palette. */
void setColorTableEntry(int index, const ColorEntry &entry);
void setColorTableEntry(int index, const QColor &entry);
/**
* Copies the color entries which form the palette for this color scheme
......@@ -68,14 +68,14 @@ public:
* @param randomSeed Color schemes may allow certain colors in their
* palette to be randomized. The seed is used to pick the random color.
*/
void getColorTable(ColorEntry *table, uint randomSeed = 0) const;
void getColorTable(QColor *table, uint randomSeed = 0) const;
/**
* Retrieves a single color entry from the table.
*
* See getColorTable()
*/
ColorEntry colorEntry(int index, uint randomSeed = 0) const;
QColor colorEntry(int index, uint randomSeed = 0) const;
/**
* Convenience method. Returns the
......@@ -140,7 +140,7 @@ public:
/** Returns true if color randomization is enabled. */
bool isColorRandomizationEnabled() const;
static const ColorEntry defaultTable[]; // table of default color entries
static const QColor defaultTable[]; // table of default color entries
static QString colorNameForIndex(int index);
static QString translatedColorNameForIndex(int index);
......@@ -168,7 +168,7 @@ private:
// returns the active color table. if none has been set specifically,
// this is the default color table.
const ColorEntry *colorTable() const;
const QColor *colorTable() const;
// reads a single color entry from a KConfig source
// and sets the palette entry at 'index' to the entry read.
......@@ -186,7 +186,7 @@ private:
// pointer to custom color table, or 0 if the default color table is
// being used
ColorEntry *_table;
QColor *_table;
// pointer to randomization table, or 0 if no colors in the color
// scheme support randomization
......
......@@ -174,7 +174,7 @@ void ColorSchemeEditor::editColorItem(QTableWidgetItem *item)
colorSchemeRow += 2*COLOR_TABLE_ROW_LENGTH;
}
ColorEntry entry(_colors->colorEntry(colorSchemeRow));
QColor entry(_colors->colorEntry(colorSchemeRow));
entry = color;
_colors->setColorTableEntry(colorSchemeRow, entry);
......@@ -284,7 +284,7 @@ void ColorSchemeEditor::setup(const ColorScheme *scheme, bool isNewScheme)
void ColorSchemeEditor::setupColorTable(const ColorScheme *colors)
{
ColorEntry table[TABLE_COLORS];
QColor table[TABLE_COLORS];
colors->getColorTable(table);
for (int row = 0; row < COLOR_TABLE_ROW_LENGTH; row++) {
......
......@@ -39,7 +39,7 @@ namespace Konsole
QTextStream *_output;
QString _colorSchemeName;
QFont _profileFont;
ColorEntry _colorTable[TABLE_COLORS];
QColor _colorTable[TABLE_COLORS];
bool _innerSpanOpen;
RenditionFlags _lastRendition;
CharacterColor _lastForeColor;
......
......@@ -32,7 +32,7 @@ namespace Konsole
void TerminalColor::applyProfile(const Profile::Ptr &profile, ColorScheme const *colorScheme, int randomSeed)
{
ColorEntry table[TABLE_COLORS];
QColor table[TABLE_COLORS];
colorScheme->getColorTable(table, randomSeed);
setColorTable(table);
setOpacity(colorScheme->opacity());
......@@ -51,7 +51,7 @@ namespace Konsole
return m_colorTable[DEFAULT_FORE_COLOR];
}
void TerminalColor::setColorTable(const ColorEntry *table)
void TerminalColor::setColorTable(const QColor *table)
{
for (int index = 0; index < TABLE_COLORS; index++) {
m_colorTable[index] = table[index];
......@@ -60,7 +60,7 @@ namespace Konsole
onColorsChanged();
}
const ColorEntry* TerminalColor::colorTable() const
const QColor* TerminalColor::colorTable() const
{
return m_colorTable;
}
......@@ -148,7 +148,7 @@ namespace Konsole
void TerminalColor::swapFGBGColors()
{
ColorEntry color = m_colorTable[DEFAULT_BACK_COLOR];
QColor color = m_colorTable[DEFAULT_BACK_COLOR];
m_colorTable[DEFAULT_BACK_COLOR] = m_colorTable[DEFAULT_FORE_COLOR];
m_colorTable[DEFAULT_FORE_COLOR] = color;
......
......@@ -34,8 +34,8 @@ namespace Konsole
QColor backgroundColor() const;
QColor foregroundColor() const;
void setColorTable(const ColorEntry *table);
const ColorEntry *colorTable() const;
void setColorTable(const QColor *table);
const QColor *colorTable() const;
void setOpacity(qreal opacity);
......@@ -75,7 +75,7 @@ namespace Konsole
QColor m_cursorColor;
QColor m_cursorTextColor;
ColorEntry m_colorTable[TABLE_COLORS];
QColor m_colorTable[TABLE_COLORS];
};
}
......
......@@ -699,7 +699,7 @@ private:
int _imageSize;
QVector<LineProperty> _lineProperties;
ColorEntry _colorTable[TABLE_COLORS];
QColor _colorTable[TABLE_COLORS];
uint _randomSeed;
......
......@@ -332,7 +332,7 @@ namespace Konsole
}
void TerminalPainter::drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style, const ColorEntry *colorTable)
const Character *style, const QColor *colorTable)
{
// setup painter
const QColor foregroundColor = style->foregroundColor.color(colorTable);
......
......@@ -81,7 +81,7 @@ namespace Konsole
// draws a section of text, all the text in this section
// has a common color and style
void drawTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style, const ColorEntry *colorTable);
const Character *style, const QColor *colorTable);
void drawPrinterFriendlyTextFragment(QPainter &painter, const QRect &rect, const QString &text,
const Character *style);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment