mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
Add new pref use_system_colors (defaults to true).
What is missing is some feedback on what colors are set from the system (they should be disabled in the color list). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35096 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
088059724d
commit
17729b9346
@ -199,6 +199,7 @@ LexerKeyword lyxrcTags[] = {
|
||||
{ "\\use_pixmap_cache", LyXRC::RC_USE_PIXMAP_CACHE },
|
||||
// compatibility with versions older than 1.4.0 only
|
||||
{ "\\use_pspell", LyXRC::RC_USE_SPELL_LIB },
|
||||
{ "\\use_system_colors", LyXRC::RC_USE_SYSTEM_COLORS },
|
||||
// compatibility with versions older than 1.4.0 only
|
||||
{ "\\use_tempdir", LyXRC::RC_USETEMPDIR },
|
||||
{ "\\use_tooltip", LyXRC::RC_USE_TOOLTIP },
|
||||
@ -330,6 +331,7 @@ void LyXRC::setDefaults()
|
||||
preview_hashed_labels = false;
|
||||
preview_scale_factor = 1.0;
|
||||
use_converter_cache = true;
|
||||
use_system_colors = true;
|
||||
use_tooltip = true;
|
||||
use_pixmap_cache = false;
|
||||
converter_cache_maxage = 6 * 30 * 24 * 3600; // 6 months
|
||||
@ -914,6 +916,9 @@ int LyXRC::read(Lexer & lexrc)
|
||||
case RC_ACCEPT_COMPOUND:
|
||||
lexrc >> spellchecker_accept_compound;
|
||||
break;
|
||||
case RC_USE_SYSTEM_COLORS:
|
||||
lexrc >> use_system_colors;
|
||||
break;
|
||||
case RC_USE_TOOLTIP:
|
||||
lexrc >> use_tooltip;
|
||||
break;
|
||||
@ -2382,6 +2387,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
|
||||
// obsoleted in 2.0
|
||||
if (tag != RC_LAST)
|
||||
break;
|
||||
case RC_USE_SYSTEM_COLORS:
|
||||
if (ignore_system_lyxrc ||
|
||||
use_system_colors != system_lyxrc.use_system_colors) {
|
||||
os << "\\use_system_colors "
|
||||
<< convert<string>(use_system_colors)
|
||||
<< '\n';
|
||||
}
|
||||
if (tag != RC_LAST)
|
||||
break;
|
||||
case RC_USE_TOOLTIP:
|
||||
if (ignore_system_lyxrc ||
|
||||
use_tooltip != system_lyxrc.use_tooltip) {
|
||||
@ -2932,6 +2946,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
|
||||
case LyXRC::RC_USE_ESC_CHARS:
|
||||
case LyXRC::RC_USE_INP_ENC:
|
||||
case LyXRC::RC_USE_PERS_DICT:
|
||||
case LyXRC::RC_USE_SYSTEM_COLORS:
|
||||
case LyXRC::RC_USE_TOOLTIP:
|
||||
case LyXRC::RC_USE_PIXMAP_CACHE:
|
||||
case LyXRC::RC_USE_SPELL_LIB:
|
||||
@ -3382,6 +3397,10 @@ string const LyXRC::getDescription(LyXRCTags tag)
|
||||
case RC_USETEMPDIR:
|
||||
break;
|
||||
|
||||
case RC_USE_TOOLTIP:
|
||||
str = _("Enable use the system colors for some things like main window background and selection.");
|
||||
break;
|
||||
|
||||
case RC_USE_TOOLTIP:
|
||||
str = _("Enable the automatic appearance of tool tips in the work area.");
|
||||
break;
|
||||
|
@ -182,6 +182,7 @@ public:
|
||||
RC_USE_ESC_CHARS,
|
||||
RC_USE_INP_ENC,
|
||||
RC_USE_PERS_DICT,
|
||||
RC_USE_SYSTEM_COLORS,
|
||||
RC_USE_TOOLTIP,
|
||||
RC_USE_PIXMAP_CACHE,
|
||||
RC_USE_SPELL_LIB,
|
||||
@ -351,6 +352,8 @@ public:
|
||||
bool paragraph_markers;
|
||||
/// Use tooltips?
|
||||
bool use_tooltip;
|
||||
/// Use the colors from current system theme?
|
||||
bool use_system_colors;
|
||||
/// Use pixmap cache?
|
||||
bool use_pixmap_cache;
|
||||
/// Spellchecker engine: aspell, hunspell, etc
|
||||
|
@ -10,15 +10,56 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "ColorCache.h"
|
||||
#include "ColorSet.h"
|
||||
|
||||
namespace lyx {
|
||||
|
||||
void ColorCache::setColor(int col, QPalette::ColorRole cr)
|
||||
{
|
||||
lcolors_[col] = pal_.brush(QPalette::Active, cr).color();
|
||||
}
|
||||
|
||||
|
||||
void ColorCache::init()
|
||||
{
|
||||
if (lyxrc.use_system_colors) {
|
||||
for (int col = 0; col <= Color_ignore; ++col) {
|
||||
switch (ColorCode(col)) {
|
||||
case Color_background:
|
||||
case Color_commentbg:
|
||||
case Color_greyedoutbg:
|
||||
case Color_mathbg:
|
||||
case Color_graphicsbg:
|
||||
case Color_mathmacrobg:
|
||||
case Color_mathcorners:
|
||||
setColor(col, QPalette::Base);
|
||||
break;
|
||||
|
||||
case Color_foreground:
|
||||
case Color_cursor:
|
||||
case Color_preview:
|
||||
case Color_tabularline:
|
||||
case Color_previewframe:
|
||||
setColor(col, QPalette::Text);
|
||||
break;
|
||||
|
||||
case Color_selection:
|
||||
setColor(col, QPalette::Highlight);
|
||||
break;
|
||||
case Color_selectiontext:
|
||||
setColor(col, QPalette::HighlightedText);
|
||||
break;
|
||||
default:
|
||||
lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int col = 0; col <= Color_ignore; ++col)
|
||||
lcolors_[col] = QColor(lcolor.getX11Name(ColorCode(col)).c_str());
|
||||
}
|
||||
initialized_ = true;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Color.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QPalette>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
@ -26,11 +27,15 @@ struct RGBColor;
|
||||
class ColorCache
|
||||
{
|
||||
public:
|
||||
///
|
||||
ColorCache() : initialized_(false) {}
|
||||
|
||||
/// get the given color
|
||||
QColor get(Color color) const;
|
||||
|
||||
/// change the undelying palette
|
||||
void setPalette(QPalette const pal) { pal_ = pal; initialized_ = false; }
|
||||
|
||||
/// clear all colors
|
||||
void clear() { initialized_ = false; }
|
||||
|
||||
@ -38,9 +43,13 @@ private:
|
||||
///
|
||||
void init();
|
||||
///
|
||||
void setColor(int col, QPalette::ColorRole cr);
|
||||
///
|
||||
QColor lcolors_[Color_ignore + 1];
|
||||
///
|
||||
bool initialized_;
|
||||
///
|
||||
QPalette pal_;
|
||||
};
|
||||
|
||||
///
|
||||
|
@ -162,7 +162,11 @@ frontend::Application * createApplication(int & argc, char * argv[])
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return new frontend::GuiApplication(argc, argv);
|
||||
frontend::GuiApplication * guiApp = new frontend::GuiApplication(argc, argv);
|
||||
// I'd rather do that in the constructor, but I do not think that
|
||||
// the palette is accessible there.
|
||||
guiApp->colorCache().setPalette(guiApp->palette());
|
||||
return guiApp;
|
||||
}
|
||||
|
||||
namespace frontend {
|
||||
@ -759,13 +763,6 @@ GuiApplication::~GuiApplication()
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
void setColor(ColorCode code, QPalette const & pal, QPalette::ColorRole cr)
|
||||
{
|
||||
lcolor.setColor(code, fromqstr(pal.brush(QPalette::Active, cr).color().name()));
|
||||
}
|
||||
}
|
||||
|
||||
GuiApplication::GuiApplication(int & argc, char ** argv)
|
||||
: QApplication(argc, argv), current_view_(0),
|
||||
d(new GuiApplication::Private)
|
||||
@ -827,24 +824,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
|
||||
if (lyxrc.typewriter_font_name.empty())
|
||||
lyxrc.typewriter_font_name = fromqstr(typewriterFontName());
|
||||
|
||||
// initialize colors
|
||||
setColor(Color_background, palette(), QPalette::Base);
|
||||
setColor(Color_commentbg, palette(), QPalette::Base);
|
||||
setColor(Color_greyedoutbg, palette(), QPalette::Base);
|
||||
setColor(Color_mathbg, palette(), QPalette::Base);
|
||||
setColor(Color_graphicsbg, palette(), QPalette::Base);
|
||||
setColor(Color_mathmacrobg, palette(), QPalette::Base);
|
||||
setColor(Color_mathcorners, palette(), QPalette::Base);
|
||||
|
||||
setColor(Color_foreground, palette(), QPalette::Text);
|
||||
setColor(Color_cursor, palette(), QPalette::Text);
|
||||
setColor(Color_preview, palette(), QPalette::Text);
|
||||
setColor(Color_tabularline, palette(), QPalette::Text);
|
||||
setColor(Color_previewframe, palette(), QPalette::Text);
|
||||
|
||||
setColor(Color_selection, palette(), QPalette::Highlight);
|
||||
setColor(Color_selectiontext, palette(), QPalette::HighlightedText);
|
||||
|
||||
d->general_timer_.setInterval(500);
|
||||
connect(&d->general_timer_, SIGNAL(timeout()),
|
||||
this, SLOT(handleRegularEvents()));
|
||||
|
@ -1088,18 +1088,26 @@ PrefColors::PrefColors(GuiPreferences * form)
|
||||
this, SLOT(changeLyxObjectsSelection()));
|
||||
connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)),
|
||||
this, SLOT(changeColor()));
|
||||
connect(syscolorsCB, SIGNAL(toggled(bool)),
|
||||
this, SIGNAL(changed()));
|
||||
}
|
||||
|
||||
|
||||
void PrefColors::apply(LyXRC & /*rc*/) const
|
||||
void PrefColors::apply(LyXRC & rc) const
|
||||
{
|
||||
LyXRC oldrc = rc;
|
||||
|
||||
for (unsigned int i = 0; i < lcolors_.size(); ++i)
|
||||
if (curcolors_[i] != newcolors_[i])
|
||||
form_->setColor(lcolors_[i], newcolors_[i]);
|
||||
rc.use_system_colors = syscolorsCB->isChecked();
|
||||
|
||||
if (oldrc.use_system_colors != rc.use_system_colors)
|
||||
guiApp->colorCache().clear();
|
||||
}
|
||||
|
||||
|
||||
void PrefColors::update(LyXRC const & /*rc*/)
|
||||
void PrefColors::update(LyXRC const & rc)
|
||||
{
|
||||
for (unsigned int i = 0; i < lcolors_.size(); ++i) {
|
||||
QColor color = QColor(guiApp->colorCache().get(lcolors_[i]));
|
||||
@ -1108,6 +1116,7 @@ void PrefColors::update(LyXRC const & /*rc*/)
|
||||
lyxObjectsLW->item(i)->setIcon(QIcon(coloritem));
|
||||
newcolors_[i] = curcolors_[i] = color.name();
|
||||
}
|
||||
syscolorsCB->setChecked(rc.use_system_colors);
|
||||
changeLyxObjectsSelection();
|
||||
}
|
||||
|
||||
@ -3081,6 +3090,7 @@ void GuiPreferences::applyView()
|
||||
apply(rc());
|
||||
}
|
||||
|
||||
|
||||
bool GuiPreferences::initialiseParams(string const &)
|
||||
{
|
||||
rc_ = lyxrc;
|
||||
|
@ -5,26 +5,18 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>199</width>
|
||||
<height>226</height>
|
||||
<width>231</width>
|
||||
<height>254</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item rowspan="2" row="0" column="0" >
|
||||
<widget class="QListWidget" name="lyxObjectsLW" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy>
|
||||
<hsizetype>5</hsizetype>
|
||||
<vsizetype>7</vsizetype>
|
||||
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@ -64,6 +56,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2" >
|
||||
<widget class="QCheckBox" name="syscolorsCB" >
|
||||
<property name="text" >
|
||||
<string>Use system colors</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<includes>
|
||||
|
Loading…
Reference in New Issue
Block a user