Dear Jürgen and Jean-Marc:

Thanks for cleaning up my patch and committing it!

> Concerning the 7in default: I see in LaTeX sources that the default text
> width is 360pt, that is, 5in. What does the 7in come from? [I am not
> asking for change, I ask :)]

The 7 in default is from the discussion on Trac and several of the old
patches. I left it because the Trac discussion seemed to have settled
on 7 in.

I am attaching a patch that implements Jean-Marc's checkbox-free UI
suggestion and restricts the available units to inches, cm, and
%textwidth. Unfortunately, the Length class does not support pixels as
a unit. (possible workaround could be to create an ad-hoc subclass of
LengthCombo). Hopefully this patch has more polish than the last one!

> In order to ship it with LyX, we need a license statement from you, sent to 
> this list, like this:

I grant permission to license, under the GNU General Public License
(version 2 or later), all past contributions I have made to LyX
including the patch attached below.
I grant permission to license, under the GNU General Public License
(version 2 or later), all contributions I make to LyX in the future
via lyx-devel@lists.lyx.org or on official LyX project websites.

Best regards,
Chris


On Sat, Oct 29, 2022 at 5:30 AM Jürgen Spitzmüller <jspi...@gmail.com> wrote:
>
> Am Sonntag, dem 23.10.2022 um 18:15 -0400 schrieb Christopher
> Hillenbrand:
> > Dear LyX developers,
> >
> > Here's a patch for adjusting editor text width in windowed mode (see
> > ticket https://www.lyx.org/trac/ticket/9376). It's an adaptation of
> > the previous patch uploaded by stwitt (two years ago). Please try it
> > out when you get a chance!
>
> Your patch has been committed to master (and slightly polished
> afterwards). In order to ship it with LyX, we need a license statement
> from you, sent to this list, like this:
> https://marc.info/?l=lyx-devel&m=110907530127164
>
> Thanks,
> --
> Jürgen
> --
> lyx-devel mailing list
> lyx-devel@lists.lyx.org
> http://lists.lyx.org/mailman/listinfo/lyx-devel
From bab1d4c22530a54347f30e16421bb7dbc73732b6 Mon Sep 17 00:00:00 2001
From: chillenb <chillenb.li...@gmail.com>
Date: Sun, 30 Oct 2022 11:38:28 -0400
Subject: [PATCH] More improvements to the screen width UI:

* The screen width unit selector is restricted to inches, cm, and %textwidth
* Screen width limitation is disabled by leaving it empty
* Invalid screen widths are rejected, just like invalid page margins
---
 src/frontends/qt/GuiPrefs.cpp     | 49 ++++++++++++++++++++++++-------
 src/frontends/qt/GuiPrefs.h       |  2 +-
 src/frontends/qt/ui/PrefEditUi.ui |  5 +++-
 3 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index 03d630d397..c2c31a87d5 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -2827,13 +2827,35 @@ PrefEdit::PrefEdit(GuiPreferences * form)
 		this, SIGNAL(changed()));
 	connect(toggleToolbarsCB, SIGNAL(toggled(bool)),
 		this, SIGNAL(changed()));
-}
-
 
-void PrefEdit::on_screenLimitCB_toggled(bool const state)
-{
-	screenWidthLE->setEnabled(state);
-	screenWidthUnitCO->setEnabled(state);
+	screenWidthLE->setPlaceholderText(qt_("100% Text Width"));
+	screenWidthLE->setValidator(new LengthValidator(screenWidthLE));
+	form->bc().addCheckedLineEdit(screenWidthLE, screenWidthLA);
+	screenWidthUnitCO->removeUnit(lyx::Length::BP);
+	screenWidthUnitCO->removeUnit(lyx::Length::CC);
+	screenWidthUnitCO->removeUnit(lyx::Length::DD);
+	screenWidthUnitCO->removeUnit(lyx::Length::EM);
+	screenWidthUnitCO->removeUnit(lyx::Length::EX);
+	screenWidthUnitCO->removeUnit(lyx::Length::MM);
+	screenWidthUnitCO->removeUnit(lyx::Length::MU);
+	screenWidthUnitCO->removeUnit(lyx::Length::PC);
+	screenWidthUnitCO->removeUnit(lyx::Length::PT);
+	screenWidthUnitCO->removeUnit(lyx::Length::SP);
+	screenWidthUnitCO->removeUnit(lyx::Length::PCW);
+	screenWidthUnitCO->removeUnit(lyx::Length::PPW);
+	screenWidthUnitCO->removeUnit(lyx::Length::PLW);
+	screenWidthUnitCO->removeUnit(lyx::Length::PTH);
+	screenWidthUnitCO->removeUnit(lyx::Length::PPH);
+	screenWidthUnitCO->removeUnit(lyx::Length::BLS);
+	// This leaves inches, cm, and % text width
+}
+
+
+void PrefEdit::on_screenWidthLE_textChanged(QString const & text)
+{
+	const bool isempty = !text.isEmpty();
+	screenWidthLA->setEnabled(isempty);
+	screenWidthUnitCO->setEnabled(isempty);
 	changed();
 }
 
@@ -2867,8 +2889,14 @@ void PrefEdit::applyRC(LyXRC & rc) const
 	rc.full_screen_statusbar = toggleStatusbarCB->isChecked();
 	rc.full_screen_tabbar = toggleTabbarCB->isChecked();
 	rc.full_screen_menubar = toggleMenubarCB->isChecked();
-	rc.screen_width = Length(widgetsToLength(screenWidthLE, screenWidthUnitCO)); 
-	rc.screen_limit = screenLimitCB->isChecked(); 
+	rc.screen_width = Length(widgetsToLength(screenWidthLE, screenWidthUnitCO));
+	rc.screen_limit = !rc.screen_width.zero();
+	// if rc.screen_width is an empty Length(), set it to 0
+	// otherwise, preferences will not parse correctly
+	if(!rc.screen_limit) {
+		rc.screen_width = Length(0.0, Length::defaultUnit());
+		screenWidthLE->clear();
+	}
 }
 
 
@@ -2892,9 +2920,10 @@ void PrefEdit::updateRC(LyXRC const & rc)
 	toggleTabbarCB->setChecked(rc.full_screen_tabbar);
 	toggleMenubarCB->setChecked(rc.full_screen_menubar);
 	lengthToWidgets(screenWidthLE, screenWidthUnitCO, rc.screen_width, Length::defaultUnit());
+	if(!rc.screen_limit)
+		screenWidthLE->clear();
 	screenWidthUnitCO->setEnabled(rc.screen_limit);
-	screenLimitCB->setChecked(rc.screen_limit);
-	screenWidthLE->setEnabled(rc.screen_limit);
+	screenWidthLA->setEnabled(rc.screen_limit);
 }
 
 
diff --git a/src/frontends/qt/GuiPrefs.h b/src/frontends/qt/GuiPrefs.h
index d23759089e..37e302a720 100644
--- a/src/frontends/qt/GuiPrefs.h
+++ b/src/frontends/qt/GuiPrefs.h
@@ -451,8 +451,8 @@ public:
 	void updateRC(LyXRC const & rc) override;
 
 public Q_SLOTS:
-	void on_screenLimitCB_toggled(bool);
 	void on_citationSearchCB_toggled(bool);
+	void on_screenWidthLE_textChanged(QString const & text);
 };
 
 
diff --git a/src/frontends/qt/ui/PrefEditUi.ui b/src/frontends/qt/ui/PrefEditUi.ui
index 2a6a08263b..379cf8d506 100644
--- a/src/frontends/qt/ui/PrefEditUi.ui
+++ b/src/frontends/qt/ui/PrefEditUi.ui
@@ -215,13 +215,16 @@
       <item row="10" column="0" colspan="3">
        <layout class="QHBoxLayout" name="horizontalLayout_4">
         <item>
-         <widget class="QCheckBox" name="screenLimitCB">
+         <widget class="QLabel" name="screenWidthLA">
           <property name="toolTip">
            <string>Limit the width of the text in the work area to the specified length</string>
           </property>
           <property name="text">
            <string>&amp;Limit text width</string>
           </property>
+          <property name="buddy">
+           <cstring>screenWidthLE</cstring>
+          </property>
          </widget>
         </item>
         <item>
-- 
2.38.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to