Le 16/09/2016 à 18:12, Jürgen Spitzmüller a écrit :
Am Freitag, den 16.09.2016, 10:20 -0600 schrieb Joel Kulesza:
Perhaps not something to be done immediately, but do you agree that
it is a reasonable request to be considered for implementation in the
future?


Yes. Note, though, that it seems to be non-trivial. I have tried to
implement it, but did not succeed to change the color in a sensible
way. Disabling the widget does not, as in the case of other widgets,
grey it out. The way to go seems to be playing with the color palette,
but I didn't manage to get it to work either (but did not try too
hard).

Yes, it seems that all that cannot be used to control the html
formatting, which the citation preview uses. I finally found that the
trick was to change the html. See attached.


In any case, if it is done, it should be done for all widgets that do
only display information.


Where else should that be done?

Guillaume

>From d803e0b6c566dc1d4ba74b7a901df1c6e1cceade Mon Sep 17 00:00:00 2001
From: Guillaume Munch <g...@lyx.org>
Date: Fri, 16 Sep 2016 22:06:38 +0100
Subject: [PATCH] GuiCitation: Set infoML to read-only colors

---
 src/frontends/qt4/GuiCitation.cpp | 26 +++++++++++++++++++-------
 src/frontends/qt4/GuiCitation.h   |  2 ++
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp
index b294fd8..078a3e3 100644
--- a/src/frontends/qt4/GuiCitation.cpp
+++ b/src/frontends/qt4/GuiCitation.cpp
@@ -124,6 +124,9 @@ GuiCitation::GuiCitation(GuiView & lv)
 	searchOpts->addAction(instant_);
 	searchOptionsPB->setMenu(searchOpts);
 
+	//initialize info box
+	setInfoHtml(docstring());
+
 	connect(citationStyleCO, SIGNAL(activated(int)),
 		this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
 	connect(fulllistCB, SIGNAL(clicked()),
@@ -366,14 +369,23 @@ void GuiCitation::setButtons()
 
 void GuiCitation::updateInfo(BiblioInfo const & bi, QModelIndex const & idx)
 {
-	if (!idx.isValid() || bi.empty()) {
-		infoML->document()->clear();
-		return;
-	}
+	docstring const html = (!idx.isValid() || bi.empty()) ? docstring()
+		: bi.getInfo(qstring_to_ucs4(idx.data().toString()),
+		             documentBuffer(),
+		             true);
+	setInfoHtml(html);
+}
 
-	QString const keytxt = toqstr(
-		bi.getInfo(qstring_to_ucs4(idx.data().toString()), documentBuffer(), true));
-	infoML->document()->setHtml(keytxt);
+
+void GuiCitation::setInfoHtml(docstring const & html)
+{
+	//set preview in window colors to denote read-only
+	QString body("<body style=\"color:%1; background-color:%2\">"
+	                 "<p>%3</p>"
+	             "</body>");
+	body = body.arg(QPalette().windowText().color().name());
+	body = body.arg(QPalette().window().color().name());
+	infoML->document()->setHtml(body.arg(toqstr(html)));
 }
 
 
diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h
index 035b2d2..fee8c60 100644
--- a/src/frontends/qt4/GuiCitation.h
+++ b/src/frontends/qt4/GuiCitation.h
@@ -95,6 +95,8 @@ private:
 	bool isSelected(const QModelIndex &);
 	/// update the display of BibTeX information
 	void updateInfo(BiblioInfo const & bi, QModelIndex const &);
+	/// format and insert text into the info QTextEdit
+	void setInfoHtml(docstring const & html);
 	/// enable/disable buttons
 	void setButtons();
 	/// fill the fields combo
-- 
2.7.4

Reply via email to