Layout list WYSIWYM

Daniel xracoonx at gmx.de
Sun Jul 26 17:54:15 UTC 2020


On 2020-07-24 18:13, Daniel wrote:
> On 2020-04-14 09:47, Daniel wrote:
>> On 2020-04-14 09:29, Daniel wrote:
>>> On 2020-04-14 09:23, Daniel wrote:
>>>> If I read correctly, then drop-down list items can be styled in Qt. 
>>>> I think it would look awesome and, more importantly, enhance finding 
>>>> items if the layout list would provide some of the WYSIWYM styles 
>>>> from the work area. I'd suggest font attributes and labeling.
>>>>
>>>> Attached is a mock-up of what this might look like.
>>>>
>>>> Daniel
>>>>
>>>
>>> There was some grayish background color. A nicer version is attached.
>>>
>>> Daniel
>>
>> Some more thoughts on the content of the items in the list:
>>
>> I guess the easiest way would be to always show
>>
>>      label + layout-name
>>
>> However, in some cases this leads to non-ideal results. For example, 
>> this would result in
>>
>>      Theorem 1. Theorem
>>
>> That's long and confusing. So, instead there needs to be an attribute, 
>> call it "LayoutListLabel", that allows the formatting if the layout 
>> list item should have a different content. I guess it would be enough 
>> to have a reference to the whole label (such as Riki's ## for 
>> PrettyFormat but more customization, which might also come to 
>> PrettyFormat soon, might be better). So, for the theorem environments 
>> it would be:
>>
>>      LayoutListLabel        "##"
> 
> Due to popular demand ;), and for the fun of it, I have made some steps 
> towards implementation. Attached is the visual result of these first 
> steps. I think looks nice and helps to more quickly find what one is 
> looking for. I'd be curious what you think?
> 
> Next step would be to try to figure out how to get the string with 
> counter and bullets. This would also make the stars (*) on the layout 
> names redundant.
> 
> Daniel
> 
> 

A first attempt is the attached patch. However, there are a couple of 
(possible) issues:

1. I get an ASSERTION:

support/lassert.cpp (51): ASSERTION false VIOLATED IN 
/Users/Shared/LyX/lyx/src/frontends/qt/GuiFontLoader.cpp:132
frontends/qt/GuiFontLoader.cpp (133): Unrealized font!

I guess I am not getting the QFont from the lyx::FontInfo correctly. But 
I am not sure what the correct function is. It seems otherwise to work 
as expected.

2. I am not sure the way I get the size of an unchanged row from the 
dropdownlist in an efficient way.

Maybe someone has a comment on any of the above or other?

Daniel
-------------- next part --------------
diff --git a/src/frontends/qt/LayoutBox.cpp b/src/frontends/qt/LayoutBox.cpp
index 01cb60e652..ca9a60797f 100644
--- a/src/frontends/qt/LayoutBox.cpp
+++ b/src/frontends/qt/LayoutBox.cpp
@@ -31,6 +31,7 @@
 #include "LyXRC.h"
 #include "Paragraph.h"
 #include "TextClass.h"
+#include "GuiFontLoader.h"
 
 #include "insets/InsetText.h"
 
@@ -400,6 +401,8 @@ void LayoutBox::showPopup()
 	d->resetFilter();
 	QComboBox::showPopup();
 	view()->setUpdatesEnabled(enabled);
+	// update popup size to fit content which can be wider due to formatted text
+	view()->setMinimumWidth(view()->sizeHintForColumn(0));
 }
 
 
@@ -502,7 +505,7 @@ void LayoutBox::set(docstring const & layout)
 
 
 void LayoutBox::addItemSort(docstring const & item, docstring const & category,
-	bool sorted, bool sortedByCat, bool unknown)
+	FontInfo const & f, bool sorted, bool sortedByCat, bool unknown)
 {
 	QString qitem = toqstr(item);
 	docstring const loc_item = translateIfPossible(item);
@@ -511,7 +514,16 @@ void LayoutBox::addItemSort(docstring const & item, docstring const & category,
 	QString qcat = toqstr(translateIfPossible(category));
 
 	QList<QStandardItem *> row;
-	row.append(new QStandardItem(titem));
+	QStandardItem *guititem = new QStandardItem(titem);
+	// get default font pointsize and metric
+	int dfps = guititem->font().pointSize();
+	QFontMetrics fm(guititem->font());
+	// set item font according to layout
+	guititem->setFont(getFont(f));
+	// set minimum height in case the font is smaller than 1.5 default
+	if (guititem->font().pointSize() < dfps*1.5)
+	  guititem->setSizeHint(QSize(sizeHint().width(), fm.height()*1.5));
+	row.append(guititem);
 	row.append(new QStandardItem(qitem));
 	row.append(new QStandardItem(qcat));
 
@@ -599,7 +611,7 @@ void LayoutBox::updateContents(bool reset)
 		// obsoleted layouts are skipped as well
 		if (!lit->obsoleted_by().empty())
 			continue;
-		addItemSort(name, lit->category(), lyxrc.sort_layouts,
+		addItemSort(name, lit->category(), lit->font, lyxrc.sort_layouts,
 				lyxrc.group_layouts, lit->isUnknown());
 	}
 
diff --git a/src/frontends/qt/LayoutBox.h b/src/frontends/qt/LayoutBox.h
index ac8c86e0f1..955f5adb8b 100644
--- a/src/frontends/qt/LayoutBox.h
+++ b/src/frontends/qt/LayoutBox.h
@@ -16,6 +16,8 @@
 #ifndef LYX_LAYOUT_BOX_H
 #define LYX_LAYOUT_BOX_H
 
+#include "FontInfo.h"
+
 #include "support/strfwd.h"
 
 #include <QComboBox>
@@ -43,7 +45,7 @@ public:
 	void updateContents(bool reset);
 	/// Add Item to Layout box according to sorting settings from preferences
 	void addItemSort(docstring const & item, docstring const & category,
-		bool sorted, bool sortedByCat, bool unknown);
+		FontInfo const & f, bool sorted, bool sortedByCat, bool unknown);
 
 	///
 	void showPopup();


More information about the lyx-devel mailing list