Restoring the FonButton in Preferences (#3540)

This commit is contained in:
Hombre
2016-12-18 22:50:59 +01:00
parent 7de1ec2d66
commit c993906d07
10 changed files with 126 additions and 14 deletions

View File

@@ -48,8 +48,8 @@ void LockableColorPicker::updateBackBuffer ()
Glib::RefPtr<Pango::Context> pangoContext = iArea->get_pango_context ();
Pango::FontDescription fontd = pangoContext->get_font_description();
// set font family and size
fontd.set_family("sans");
fontd.set_size(8 * Pango::SCALE); // 8pt, will be scaled by Gtk depending on the screen's DPI
fontd.set_family(options.CPFontFamily == "default" ? "sans" : options.CPFontFamily);
fontd.set_size((options.CPFontFamily == "default" ? 8 : options.CPFontSize) * Pango::SCALE);
fontd.set_weight(Pango::WEIGHT_NORMAL);
pangoContext->set_font_description (fontd);

View File

@@ -56,6 +56,7 @@ Glib::ustring creditsPath;
Glib::ustring licensePath;
Glib::ustring argv1;
bool simpleEditor;
Glib::RefPtr<Gtk::CssProvider> cssForced;
Glib::RefPtr<Gtk::CssProvider> cssRT;
//Glib::Threads::Thread* mainThread;
@@ -332,6 +333,19 @@ int main(int argc, char **argv)
} catch (...) {
printf("Error: Can't load css file \"%s\"\n", filename.c_str());
}
// Set the font face and size
if (options.fontFamily != "default") {
try {
cssForced = Gtk::CssProvider::create();
cssForced->load_from_data (Glib::ustring::compose("* { font-family: %1; font-size: %2pt }", options.fontFamily, options.fontSize));
Gtk::StyleContext::add_provider_for_screen(screen, cssForced, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Glib::Error &err) {
printf("Error: \"%s\"\n", err.what().c_str());
} catch (...) {
printf("Error: Can't find the font named \"%s\"\n", options.fontFamily.c_str());
}
}
}
#ifndef NDEBUG

View File

@@ -338,6 +338,10 @@ void Options::setDefaults ()
browserDirPanelOpened = true;
editorFilmStripOpened = true;
historyPanelWidth = 330;
fontFamily = "default";
fontSize = 10;
CPFontFamily = "default";
CPFontSize = 8;
lastScale = 5;
panAccelFactor = 5;
rememberZoomAndPan = true;
@@ -1309,6 +1313,22 @@ int Options::readFromFile (Glib::ustring fname)
historyPanelWidth = keyFile.get_integer ("GUI", "HistoryPanelWidth");
}
if (keyFile.has_key ("GUI", "FontFamily")) {
fontFamily = keyFile.get_string ("GUI", "FontFamily");
}
if (keyFile.has_key ("GUI", "FontSize")) {
fontSize = keyFile.get_integer ("GUI", "FontSize");
}
if (keyFile.has_key ("GUI", "CPFontFamily")) {
CPFontFamily = keyFile.get_string ("GUI", "CPFontFamily");
}
if (keyFile.has_key ("GUI", "CPFontSize")) {
CPFontSize = keyFile.get_integer ("GUI", "CPFontSize");
}
if (keyFile.has_key ("GUI", "LastPreviewScale")) {
lastScale = keyFile.get_integer ("GUI", "LastPreviewScale");
}
@@ -1977,6 +1997,10 @@ int Options::saveToFile (Glib::ustring fname)
keyFile.set_boolean ("GUI", "EditorFilmStripOpened", editorFilmStripOpened);
keyFile.set_boolean ("GUI", "BrowserDirPanelOpened", browserDirPanelOpened);
keyFile.set_integer ("GUI", "HistoryPanelWidth", historyPanelWidth);
keyFile.set_string ("GUI", "FontFamily", fontFamily);
keyFile.set_integer ("GUI", "FontSize", fontSize);
keyFile.set_string ("GUI", "CPFontFamily", CPFontFamily);
keyFile.set_integer ("GUI", "CPFontSize", CPFontSize);
keyFile.set_integer ("GUI", "LastPreviewScale", lastScale);
keyFile.set_integer ("GUI", "PanAccelFactor", panAccelFactor);
keyFile.set_boolean ("GUI", "RememberZoomAndPan", rememberZoomAndPan);

View File

@@ -135,6 +135,10 @@ public:
int lastScale;
int panAccelFactor;
int lastCropSize;
Glib::ustring fontFamily; // RT's main font family
int fontSize; // RT's main font size (units: pt)
Glib::ustring CPFontFamily; // ColorPicker font family
int CPFontSize; // ColorPicker font size (units: pt)
bool fbOnlyRaw;
bool fbShowDateTime;
bool fbShowBasicExif;

View File

@@ -32,14 +32,15 @@
extern Options options;
extern Glib::ustring argv0;
Glib::RefPtr<Gtk::CssProvider> css;
Glib::RefPtr<Gtk::CssProvider> themecss;
Glib::RefPtr<Gtk::CssProvider> fontcss;
Preferences::Preferences (RTWindow *rtwindow)
: Gtk::Dialog (M("MAIN_BUTTON_PREFERENCES"), *rtwindow, true)
, splash (nullptr)
, rprofiles (nullptr)
, iprofiles (nullptr)
, parent (rtwindow)
, splash (nullptr)
{
regex = Glib::Regex::create(THEMEREGEXSTR, Glib::RegexCompileFlags::REGEX_CASELESS);
@@ -924,6 +925,26 @@ Gtk::Widget* Preferences::getGeneralPanel ()
themeGrid->attach_next_to(*themelab, Gtk::POS_LEFT, 1, 1);
themeGrid->attach_next_to(*theme, *themelab, Gtk::POS_RIGHT, 1, 1);
Gtk::Label* fontlab = Gtk::manage( new Gtk::Label (M("PREFERENCES_SELECTFONT")) );
setExpandAlignProperties(fontlab, false, false, Gtk::ALIGN_FILL, Gtk::ALIGN_BASELINE);
fontButton = Gtk::manage( new Gtk::FontButton ());
setExpandAlignProperties(fontButton, false, false, Gtk::ALIGN_FILL, Gtk::ALIGN_BASELINE);
fontButton->set_use_size(true);
fontButton->set_font_name(Glib::ustring::compose("%1 %2", options.fontFamily == "default" ? "sans" : options.fontFamily, options.fontSize));
themeGrid->attach_next_to(*fontlab, *theme, Gtk::POS_RIGHT, 1, 1);
themeGrid->attach_next_to(*fontButton, *fontlab, Gtk::POS_RIGHT, 1, 1);
Gtk::Label* cpfontlab = Gtk::manage( new Gtk::Label (M("PREFERENCES_SELECTFONT_COLPICKER") + ":") );
setExpandAlignProperties(cpfontlab, false, false, Gtk::ALIGN_FILL, Gtk::ALIGN_BASELINE);
colorPickerFontButton = Gtk::manage( new Gtk::FontButton ());
setExpandAlignProperties(fontButton, false, false, Gtk::ALIGN_FILL, Gtk::ALIGN_BASELINE);
colorPickerFontButton->set_use_size(true);
colorPickerFontButton->set_font_name(Glib::ustring::compose("%1 %2", options.CPFontFamily == "default" ? "sans" : options.CPFontFamily, options.CPFontSize));
themeGrid->attach_next_to(*cpfontlab, *fontButton, Gtk::POS_RIGHT, 1, 1);
themeGrid->attach_next_to(*colorPickerFontButton, *cpfontlab, Gtk::POS_RIGHT, 1, 1);
Gtk::Label* cutOverlayLabel = Gtk::manage( new Gtk::Label (M("PREFERENCES_CUTOVERLAYBRUSH") + ":") );
setExpandAlignProperties(cutOverlayLabel, false, false, Gtk::ALIGN_START, Gtk::ALIGN_BASELINE);
butCropCol = Gtk::manage( new Gtk::ColorButton() );
@@ -937,7 +958,7 @@ Gtk::Widget* Preferences::getGeneralPanel ()
butNavGuideCol = Gtk::manage( new Gtk::ColorButton() );
setExpandAlignProperties(butNavGuideCol, false, false, Gtk::ALIGN_START, Gtk::ALIGN_CENTER);
butNavGuideCol->set_use_alpha(true);
themeGrid->attach_next_to(*navGuideLabel, *butCropCol, Gtk::POS_RIGHT, 1, 1);
themeGrid->attach_next_to(*navGuideLabel, *butCropCol, Gtk::POS_RIGHT, 2, 1);
themeGrid->attach_next_to(*butNavGuideCol, *navGuideLabel, Gtk::POS_RIGHT, 1, 1);
ftheme->add (*themeGrid);
@@ -1069,6 +1090,7 @@ Gtk::Widget* Preferences::getGeneralPanel ()
langAutoDetectConn = ckbLangAutoDetect->signal_toggled().connect (sigc::mem_fun(*this, &Preferences::langAutoDetectToggled));
tconn = theme->signal_changed().connect( sigc::mem_fun(*this, &Preferences::themeChanged) );
fconn = fontButton->signal_font_set().connect( sigc::mem_fun(*this, &Preferences::fontChanged) );
return mvbsd;
}
@@ -1457,6 +1479,14 @@ void Preferences::storePreferences ()
moptions.navGuideBrush[2] = NavGuideCol.get_blue();
moptions.navGuideBrush[3] = butNavGuideCol->get_alpha() / 65535.0;
Pango::FontDescription fd(fontButton->get_font_name());
moptions.fontFamily = fd.get_family();
moptions.fontSize = fd.get_size() / Pango::SCALE;
Pango::FontDescription cpfd(colorPickerFontButton->get_font_name());
moptions.CPFontFamily = cpfd.get_family();
moptions.CPFontSize = cpfd.get_size() / Pango::SCALE;
#ifdef WIN32
moptions.gimpDir = gimpDir->get_filename ();
moptions.psDir = psDir->get_filename ();
@@ -1602,6 +1632,7 @@ void Preferences::fillPreferences ()
{
tconn.block (true);
fconn.block (true);
sconn.block (true);
dfconn.block (true);
ffconn.block (true);
@@ -1672,6 +1703,9 @@ void Preferences::fillPreferences ()
butNavGuideCol->set_rgba(NavGuideCol);
butNavGuideCol->set_alpha ( (unsigned short)(moptions.navGuideBrush[3] * 65535.0));
fontButton->set_font_name(Glib::ustring::compose("%1 %2", options.fontFamily == "default" ? "sans" : options.fontFamily, options.fontSize));
colorPickerFontButton->set_font_name(Glib::ustring::compose("%1 %2", options.CPFontFamily == "default" ? "sans" : options.CPFontFamily, options.CPFontSize));
showDateTime->set_active (moptions.fbShowDateTime);
showBasicExif->set_active (moptions.fbShowBasicExif);
showExpComp->set_active (moptions.fbShowExpComp);
@@ -1787,6 +1821,7 @@ void Preferences::fillPreferences ()
addc.block (false);
setc.block (false);
fconn.block (false);
tconn.block (false);
sconn.block (false);
dfconn.block (false);
@@ -1864,6 +1899,12 @@ void Preferences::cancelPressed ()
switchThemeTo(options.theme);
}
// set the initial font back
Pango::FontDescription fd(fontButton->get_font_name());
if (fd.get_family() != options.fontFamily && (fd.get_size() / Pango::SCALE) != options.fontSize) {
switchFontTo(options.fontFamily == "default" ? "sans" : options.fontFamily, options.fontSize);
}
// update the profileStore
if (useBundledProfiles->get_active () != options.useBundledProfiles) {
// we have to rescan with the old value;
@@ -2038,14 +2079,14 @@ void Preferences::switchThemeTo(Glib::ustring newTheme)
Glib::ustring filename(Glib::build_filename(argv0, "themes", newTheme + ".css"));
if (!css) {
css = Gtk::CssProvider::create();
if (!themecss) {
themecss = Gtk::CssProvider::create();
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
Gtk::StyleContext::add_provider_for_screen(screen, css, GTK_STYLE_PROVIDER_PRIORITY_USER);
Gtk::StyleContext::add_provider_for_screen(screen, themecss, GTK_STYLE_PROVIDER_PRIORITY_USER);
}
try {
css->load_from_path (filename);
themecss->load_from_path (filename);
} catch (Glib::Error &err) {
printf("Error: Can't load css file \"%s\"\nMessage: %s\n", filename.c_str(), err.what().c_str());
} catch (...) {
@@ -2053,6 +2094,33 @@ void Preferences::switchThemeTo(Glib::ustring newTheme)
}
}
void Preferences::fontChanged ()
{
Pango::FontDescription fd(fontButton->get_font_name());
switchFontTo(fd.get_family(), fd.get_size() / Pango::SCALE);
}
void Preferences::switchFontTo(const Glib::ustring &newFontFamily, const int newFontSize)
{
if (newFontFamily != "default") {
if (!fontcss) {
fontcss = Gtk::CssProvider::create();
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
Gtk::StyleContext::add_provider_for_screen(screen, fontcss, GTK_STYLE_PROVIDER_PRIORITY_USER);
}
try {
fontcss->load_from_data (Glib::ustring::compose("* { font-family: %1; font-size: %2pt }", newFontFamily, newFontSize));
} catch (Glib::Error &err) {
printf("Error: \"%s\"\n", err.what().c_str());
} catch (...) {
printf("Error: Can't find the font named \"%s\"\n", newFontFamily.c_str());
}
}
}
void Preferences::workflowUpdate ()
{

View File

@@ -138,6 +138,8 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener
Gtk::ComboBoxText* curveBBoxPosC;
Gtk::ComboBoxText* theme;
Gtk::FontButton* fontButton;
Gtk::FontButton* colorPickerFontButton;
Gtk::ColorButton* butCropCol;
Gtk::ColorButton* butNavGuideCol;
@@ -200,7 +202,7 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener
Glib::ustring storedValueImg;
Options moptions;
sigc::connection tconn, sconn, addc, setc, dfconn, ffconn, bpconn, rpconn, ipconn;
sigc::connection tconn, sconn, fconn, addc, setc, dfconn, ffconn, bpconn, rpconn, ipconn;
sigc::connection autoMonProfileConn, sndEnableConn, langAutoDetectConn, autocielabConn;
Glib::ustring initialTheme;
Glib::ustring initialFont;
@@ -213,12 +215,14 @@ class Preferences : public Gtk::Dialog, public ProfileStoreListener
void updateFFinfos ();
void workflowUpdate();
void themeChanged ();
void fontChanged ();
void forRAWComboChanged ();
void forImageComboChanged ();
void layoutComboChanged ();
void bundledProfilesChanged ();
void iccDirChanged ();
void switchThemeTo (Glib::ustring newTheme);
void switchFontTo (const Glib::ustring &newFontFamily, const int newFontSize);
bool splashClosed(GdkEventAny* event);
int getThemeRowNumber(Glib::ustring& longThemeFName);