Commit 554d6bb8 authored by Robert Knight's avatar Robert Knight

Add a simple one-check box option to the color scheme editor to vary the...

Add a simple one-check box option to the color scheme editor to vary the background color randomly for each tab.  The results are not great yet because the algorithm which randomizes the colors needs work.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=698080
parent d3681ca7
......@@ -181,16 +181,18 @@ ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const
!_randomTable[index].isNull() )
{
const RandomizationRange& range = _randomTable[index];
int hueDifference = range.hue ? (qrand() % range.hue) - range.hue/2 : 0;
int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation/2 : 0;
int valueDifference = range.value ? (qrand() % range.value) - range.value/2 : 0;
QColor& color = entry.color;
// qDebug() << "Standard hue" << color.hue() << "saturation" << color.saturation() << "value" << color.value();
int newHue = qAbs( (color.hue() + hueDifference) % MAX_HUE );
int newValue = qAbs( color.value() + valueDifference );
int newSaturation = qAbs( color.saturation() + saturationDifference );
int newValue = qMin( qAbs(color.value() + valueDifference) , 255 );
int newSaturation = qMin( qAbs(color.saturation() + saturationDifference) , 255 );
// qDebug() << "New hue: " << newHue << "New sat:" << newSaturation <<
// "New value:" << newValue;
......@@ -206,6 +208,27 @@ void ColorScheme::getColorTable(ColorEntry* table , uint randomSeed) const
for ( int i = 0 ; i < TABLE_COLORS ; i++ )
table[i] = colorEntry(i,randomSeed);
}
bool ColorScheme::randomizedBackgroundColor() const
{
return _randomTable == 0 ? false : !_randomTable[1].isNull();
}
void ColorScheme::setRandomizedBackgroundColor(bool randomize)
{
// the hue of the background colour is allowed to be randomly
// adjusted as much as possible.
//
// the value and saturation are left alone to maintain read-ability
if ( randomize )
{
setRandomizationRange( 1 /* background color index */ , MAX_HUE , 255 , 0 );
}
else
{
if ( _randomTable )
setRandomizationRange( 1 /* background color index */ , 0 , 0 , 0 );
}
}
void ColorScheme::setRandomizationRange( int index , quint16 hue , quint8 saturation ,
quint8 value )
{
......@@ -267,7 +290,8 @@ void ColorScheme::write(KConfig& config) const
for (int i=0 ; i < TABLE_COLORS ; i++)
{
writeColorEntry(config,colorNameForIndex(i),colorTable()[i]);
RandomizationRange random = _randomTable != 0 ? _randomTable[i] : RandomizationRange();
writeColorEntry(config,colorNameForIndex(i),colorTable()[i],random);
}
}
......@@ -302,13 +326,22 @@ void ColorScheme::readColorEntry(KConfig& config , int index)
if ( hue != 0 || value != 0 || saturation != 0 )
setRandomizationRange( index , hue , saturation , value );
}
void ColorScheme::writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry) const
void ColorScheme::writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry , const RandomizationRange& random) const
{
KConfigGroup configGroup(&config,colorName);
configGroup.writeEntry("Color",entry.color);
configGroup.writeEntry("Transparency",(bool)entry.transparent);
configGroup.writeEntry("Bold",(bool)entry.bold);
// record randomization if this color has randomization or
// if one of the keys already exists
if ( !random.isNull() || configGroup.hasKey("MaxRandomHue") )
{
configGroup.writeEntry("MaxRandomHue",(int)random.hue);
configGroup.writeEntry("MaxRandomValue",(int)random.value);
configGroup.writeEntry("MaxRandomSaturation",(int)random.saturation);
}
}
......
......@@ -128,16 +128,37 @@ public:
*/
qreal opacity() const;
//void setCursorColor(const QColor& color);
//QColor cursorColor() const;
/**
* Enables randomization of the background color. This will cause
* the palette returned by getColorTable() and colorEntry() to
* be adjusted depending on the value of the random seed argument
* to them.
*/
void setRandomizedBackgroundColor(bool randomize);
//void setCursorShape(int shape);
//int cursorShape() const;
/** Returns true if the background color is randomized. */
bool randomizedBackgroundColor() const;
static QString colorNameForIndex(int index);
static QString translatedColorNameForIndex(int index);
private:
// specifies how much a particular color can be randomized by
class RandomizationRange
{
public:
RandomizationRange() : hue(0) , saturation(0) , value(0) {}
bool isNull() const
{
return ( hue == 0 && saturation == 0 && value == 0 );
}
quint16 hue;
quint8 saturation;
quint8 value;
};
// returns the active color table. if none has been set specifically,
// this is the default color table.
const ColorEntry* colorTable() const;
......@@ -146,7 +167,7 @@ private:
// and sets the the palette entry at 'index' to the entry read.
void readColorEntry(KConfig& config , int index);
// writes a single colour entry to a KConfig source
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry) const;
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
// sets the amount of randomization allowed for a particular color
// in the palette. creates the randomization table if
......@@ -159,21 +180,6 @@ private:
ColorEntry* _table; // pointer to custom color table or 0 if the default
// color scheme is being used
// specifies how much a particular color can be randomized by
class RandomizationRange
{
public:
RandomizationRange() : hue(0) , saturation(0) , value(0) {}
bool isNull() const
{
return ( hue == 0 && saturation == 0 && value == 0 );
}
quint16 hue;
quint8 saturation;
quint8 value;
};
static const quint16 MAX_HUE = 340;
......@@ -192,6 +198,9 @@ private:
*
* This is designed primarily for the benefit of users who are using specially
* designed colors.
*
* TODO Implement and make it the default on systems with specialized KDE
* color schemes.
*/
class AccessibleColorScheme : public ColorScheme
{
......
......@@ -69,6 +69,10 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget* parent)
connect( _ui->transparencySlider , SIGNAL(valueChanged(int)) , this , SLOT(setTransparencyPercentLabel(int)) );
// randomized background
connect( _ui->randomizedBackgroundCheck , SIGNAL(toggled(bool)) , this ,
SLOT(setRandomizedBackgroundColor(bool)) );
// color table
_ui->colorTable->setColumnCount(2);
_ui->colorTable->setRowCount(TABLE_COLORS);
......@@ -98,21 +102,10 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget* parent)
{
_ui->transparencyWarningIcon->setPixmap( KIcon("dialog-warning").pixmap(QSize(48,48)) );
}
#if 0
//QItemDelegate* delegate = qobject_cast<QItemDelegate*>(_ui->colorTable->itemDelegateForColumn(1));
QItemDelegate* delegate = new QItemDelegate(this);
_ui->colorTable->setItemDelegateForColumn(1,delegate);
delegate->setItemEditorFactory( new QItemEditorFactory );
Q_ASSERT(delegate);
Q_ASSERT(delegate->itemEditorFactory());
delegate->itemEditorFactory()->registerEditor( QVariant::Color , new ColorEditorCreator );
#endif
}
void ColorSchemeEditor::setRandomizedBackgroundColor( bool randomize )
{
_colors->setRandomizedBackgroundColor(randomize);
}
ColorSchemeEditor::~ColorSchemeEditor()
{
......@@ -174,6 +167,9 @@ void ColorSchemeEditor::setup(const ColorScheme* scheme)
_ui->transparencySlider->setValue(transparencyPercent);
setTransparencyPercentLabel(transparencyPercent);
// randomized background color checkbox
_ui->randomizedBackgroundCheck->setChecked( scheme->randomizedBackgroundColor() );
}
void ColorSchemeEditor::setupColorTable(const ColorScheme* colors)
{
......
......@@ -74,6 +74,7 @@ public slots:
private slots:
void setTransparencyPercentLabel(int percent);
void setRandomizedBackgroundColor(bool randomized);
void editColorItem(QTableWidgetItem* item);
private:
......
......@@ -76,6 +76,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="randomizedBackgroundCheck" >
<property name="text" >
<string>Vary the background color for each tab</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
......
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