Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 45 additions & 27 deletions lib/ColorScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,12 @@ const char* const ColorScheme::translatedColorNames[TABLE_COLORS] =
tr_NOOP("Color 8 (Intense)")
};

ColorScheme::ColorScheme()
ColorScheme::ColorScheme(QObject *parent) : QObject(parent)
{
_table = nullptr;
_randomTable = nullptr;
_opacity = 1.0;
}
ColorScheme::ColorScheme(const ColorScheme& other)
: _opacity(other._opacity)
,_table(nullptr)
,_randomTable(nullptr)
{
setName(other.name());
setDescription(other.description());

if ( other._table != nullptr )
{
for ( int i = 0 ; i < TABLE_COLORS ; i++ )
setColorTableEntry(i,other._table[i]);
}

if ( other._randomTable != nullptr )
{
for ( int i = 0 ; i < TABLE_COLORS ; i++ )
{
const RandomizationRange& range = other._randomTable[i];
setRandomizationRange(i,range.hue,range.saturation,range.value);
}
}
}
ColorScheme::~ColorScheme()
{
delete[] _table;
Expand Down Expand Up @@ -206,6 +183,19 @@ ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const

return entry;
}
QColor ColorScheme::getColor(int index) const
{
return colorEntry(index).color;
}
void ColorScheme::setColor(int index, QColor color)
{
ColorEntry colorEntry = ColorScheme::colorEntry(index);
if (colorEntry.color != color) {
colorEntry.color = color;
setColorTableEntry(index, colorEntry);
Q_EMIT colorChanged(index);
}
}
void ColorScheme::getColorTable(ColorEntry* table , uint randomSeed) const
{
for ( int i = 0 ; i < TABLE_COLORS ; i++ )
Expand Down Expand Up @@ -267,7 +257,7 @@ bool ColorScheme::hasDarkBackground() const
// so 127 is in the middle, anything less is deemed 'dark'
return backgroundColor().value() < 127;
}
void ColorScheme::setOpacity(qreal opacity) { _opacity = opacity; }
void ColorScheme::setOpacity(qreal opacity) { _opacity = opacity; opacityChanged(); }
qreal ColorScheme::opacity() const { return _opacity; }

void ColorScheme::read(const QString & fileName)
Expand All @@ -284,6 +274,21 @@ void ColorScheme::read(const QString & fileName)
readColorEntry(&s, i);
}
}

void ColorScheme::write(const QString & fileName) const
{
QSettings s(fileName, QSettings::IniFormat);
s.beginGroup("General");

s.setValue("Description", _description);
s.setValue("Opacity", _opacity);
s.endGroup();

for (int i=0 ; i < TABLE_COLORS ; i++)
{
writeColorEntry(&s, i, colorTable()[i]);
}
}
#if 0
// implemented upstream - user apps
void ColorScheme::read(KConfig& config)
Expand Down Expand Up @@ -403,6 +408,19 @@ void ColorScheme::readColorEntry(QSettings * s , int index)

s->endGroup();
}
void ColorScheme::writeColorEntry(QSettings * s, int index, const ColorEntry& entry) const
{
s->beginGroup(colorNameForIndex(index));
QStringList colorList;
colorList << QString::number(entry.color.red()) << QString::number(entry.color.green()) << QString::number(entry.color.blue());
s->setValue("Color", colorList);
s->setValue("Transparency", (bool)entry.transparent);
if (entry.fontWeight != ColorEntry::UseCurrentFormat)
{
s->setValue("Bold", entry.fontWeight == ColorEntry::Bold);
}
s->endGroup();
}
#if 0
// implemented upstream - user apps
void ColorScheme::writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry , const RandomizationRange& random) const
Expand Down Expand Up @@ -566,7 +584,7 @@ bool ColorSchemeManager::loadColorScheme(const QString& filePath)

const QString& schemeName = info.baseName();

ColorScheme* scheme = new ColorScheme();
ColorScheme* scheme = new ColorScheme(this);
scheme->setName(schemeName);
scheme->read(filePath);

Expand Down Expand Up @@ -649,7 +667,7 @@ QString ColorSchemeManager::findColorSchemePath(const QString& name) const

return path;
}
const ColorScheme* ColorSchemeManager::findColorScheme(const QString& name)
const Konsole::ColorScheme* ColorSchemeManager::findColorScheme(const QString& name)
{
if ( name.isEmpty() )
return defaultColorScheme();
Expand Down
26 changes: 18 additions & 8 deletions lib/ColorScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ namespace Konsole
* The color scheme includes the palette of colors used to draw the text and character backgrounds
* in the display and the opacity level of the display background.
*/
class ColorScheme
class ColorScheme : public QObject
{
Q_OBJECT

public:
/**
* Constructs a new color scheme which is initialised to the default color set
* for Konsole.
*/
ColorScheme();
ColorScheme(const ColorScheme& other);
ColorScheme(QObject *parent = nullptr);
~ColorScheme();

/** Sets the descriptive name of the color scheme. */
Expand All @@ -74,6 +75,7 @@ class ColorScheme
void write(KConfig& config) const;
#endif
void read(const QString & filename);
Q_INVOKABLE void write(const QString & filename) const;

/** Sets a single entry within the color palette. */
void setColorTableEntry(int index , const ColorEntry& entry);
Expand All @@ -96,6 +98,10 @@ class ColorScheme
*/
ColorEntry colorEntry(int index , uint randomSeed = 0) const;

Q_INVOKABLE QColor getColor(int index) const;
Q_INVOKABLE void setColor(int index, QColor color);
Q_SIGNAL void colorChanged(int index);

/**
* Convenience method. Returns the
* foreground color for this scheme,
Expand Down Expand Up @@ -126,12 +132,13 @@ class ColorScheme
*
* TODO: More documentation
*/
void setOpacity(qreal opacity);
Q_INVOKABLE void setOpacity(qreal opacity);
/**
* Returns the opacity level for this color scheme, see setOpacity()
* TODO: More documentation
*/
qreal opacity() const;
Q_INVOKABLE qreal opacity() const;
Q_SIGNAL void opacityChanged();

/**
* Enables randomization of the background color. This will cause
Expand Down Expand Up @@ -177,6 +184,7 @@ class ColorScheme
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
#endif
void readColorEntry(QSettings *s, int index);
void writeColorEntry(QSettings *s, int index, const ColorEntry& entry) const;

// sets the amount of randomization allowed for a particular color
// in the palette. creates the randomization table if
Expand Down Expand Up @@ -221,8 +229,10 @@ class AccessibleColorScheme : public ColorScheme
* Manages the color schemes available for use by terminal displays.
* See ColorScheme
*/
class ColorSchemeManager
class ColorSchemeManager : public QObject
{
Q_OBJECT

public:

/**
Expand Down Expand Up @@ -251,7 +261,7 @@ class ColorSchemeManager
* The first time that a color scheme with a particular name is
* requested, the configuration information is loaded from disk.
*/
const ColorScheme* findColorScheme(const QString& name);
Q_INVOKABLE const Konsole::ColorScheme* findColorScheme(const QString& name);

#if 0
/**
Expand Down Expand Up @@ -291,7 +301,7 @@ class ColorSchemeManager
* @param[in] path The path to KDE 4 .colorscheme or KDE 3 .schema.
* @return Whether the color scheme is loaded successfully.
*/
bool loadCustomColorScheme(const QString& path);
Q_INVOKABLE bool loadCustomColorScheme(const QString& path);

/**
* @brief Allows to add a custom location of color schemes.
Expand Down
58 changes: 48 additions & 10 deletions lib/TerminalDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,30 @@ void TerminalDisplay::setBackgroundColor(const QColor& color)
// Avoid propagating the palette change to the scroll bar
_scrollBar->setPalette( QApplication::palette() );

emit backgroundColorChanged();
update();
}
void TerminalDisplay::setForegroundColor(const QColor& color)
{
_colorTable[DEFAULT_FORE_COLOR].color = color;

emit foregroundColorChanged();
update();
}
QColor TerminalDisplay::backgroundColor() const
{
return _colorTable[DEFAULT_BACK_COLOR].color;
}
QColor TerminalDisplay::foregroundColor() const
{
return _colorTable[DEFAULT_FORE_COLOR].color;
}
void TerminalDisplay::setColorTable(const ColorEntry table[])
{
for (int i = 0; i < TABLE_COLORS; i++)
_colorTable[i] = table[i];

setBackgroundColor(_colorTable[DEFAULT_BACK_COLOR].color);
setForegroundColor(_colorTable[DEFAULT_FORE_COLOR].color);
}

/* ------------------------------------------------------------------------- */
Expand Down Expand Up @@ -362,6 +372,7 @@ TerminalDisplay::TerminalDisplay(QQuickItem *parent)
,_flowControlWarningEnabled(false)
,_outputSuspendedLabel(nullptr)
,_lineSpacing(0)
,_colorSchemeRef(0)
,_colorsInverted(false)
,_opacity(static_cast<qreal>(1))
,_backgroundMode(None)
Expand Down Expand Up @@ -2867,6 +2878,15 @@ void TerminalDisplay::pasteSelection()
emitSelection(true,false);
}

bool TerminalDisplay::isClipboardEmpty()
{
return QApplication::clipboard()->text().isEmpty();
}

bool TerminalDisplay::isSelectionEmpty()
{
return _screenWindow->selectedText(_preserveLineBreaks).isEmpty();
}

void TerminalDisplay::setConfirmMultilinePaste(bool confirmMultilinePaste) {
_confirmMultilinePaste = confirmMultilinePaste;
Expand Down Expand Up @@ -3486,24 +3506,24 @@ QStringList TerminalDisplay::availableColorSchemes()
void TerminalDisplay::setColorScheme(const QString &name)
{
if ( name != _colorScheme ) {
const ColorScheme *cs;
if (_colorSchemeRef) {
disconnect(_colorSchemeRef, 0, this, 0);
}
// avoid legacy (int) solution
if (!availableColorSchemes().contains(name))
cs = ColorSchemeManager::instance()->defaultColorScheme();
_colorSchemeRef = ColorSchemeManager::instance()->defaultColorScheme();
else
cs = ColorSchemeManager::instance()->findColorScheme(name);
_colorSchemeRef = ColorSchemeManager::instance()->findColorScheme(name);

if (! cs)
if (! _colorSchemeRef)
{
qDebug() << "Cannot load color scheme: " << name;
return;
}

ColorEntry table[TABLE_COLORS];
cs->getColorTable(table);
setColorTable(table);

setFillColor(cs->backgroundColor());
connect(_colorSchemeRef, SIGNAL(colorChanged(int)), this, SLOT(applyColorScheme()));
connect(_colorSchemeRef, SIGNAL(opacityChanged()), this, SLOT(applyColorScheme()));
applyColorScheme();
_colorScheme = name;
emit colorSchemeChanged();
}
Expand All @@ -3514,6 +3534,17 @@ QString TerminalDisplay::colorScheme() const
return _colorScheme;
}

void TerminalDisplay::applyColorScheme()
{
ColorEntry table[TABLE_COLORS];
_colorSchemeRef->getColorTable(table);
setColorTable(table);
QColor backgroundColor = _colorTable[DEFAULT_BACK_COLOR].color;
backgroundColor.setAlphaF(_colorSchemeRef->opacity());
setBackgroundColor(backgroundColor);
setFillColor(backgroundColor);
}

void TerminalDisplay::simulateKeyPress(int key, int modifiers, bool pressed, quint32 nativeScanCode, const QString &text)
{
Q_UNUSED(nativeScanCode);
Expand Down Expand Up @@ -3572,6 +3603,13 @@ int TerminalDisplay::getScrollbarValue()
return _scrollBar->value();
}

void TerminalDisplay::setScrollbarValue(int value)
{
if (value != _scrollBar->value()) {
_scrollBar->setValue(value);
}
}

int TerminalDisplay::getScrollbarMaximum()
{
return _scrollBar->maximum();
Expand Down
Loading