Re: Indentation and (un)commenting in local layout and preamble

2022-12-27 Thread Daniel

On 2022-09-14 09:04, Daniel wrote:

On 13/09/2022 18:27, Jean-Marc Lasgouttes wrote:

Le 13/09/2022 à 16:12, Daniel a écrit :

And I guess more importantly in license.rtf it says:

"LyX. You can redistribute LyX and/or modify it under the terms of 
the GNU General Public License as published by the Free Software 
Foundation; either version 2 of the License, or (at your option) any 
later version."


That means that QtCreator can take code from LyX and use it as GPLv3 ;)

JMarc


Or LyX can take code from LyX. ;)

Well, looks like open source isn't as open as I thought.

I see a couple of possible routes to resolve this:

1) I seem to remember that it was stated in the Qt Creator code 
somewhere that smaller parts of the code can be used without license. 
So, I could check with the Qt people what they mean by smaller parts. My 
guess is that re-use of smaller parts would be in their interest since 
it gives people a source of example code that allows people to work more 
easily with Qt. This would also be helpful for the future since 
something like "look at how Qt Creator does it" often comes up.


2) Check whether a previous Qt Creator release under another license has 
the same or similar code.


3) Re-invent the wheel, i.e. I could start from scratch and try to come 
up with my own method for the (un)commenting part.


Any suggestions?

Daniel


Went for 3 at https://www.lyx.org/trac/ticket/12577.

Daniel



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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-14 Thread Daniel

On 13/09/2022 18:27, Jean-Marc Lasgouttes wrote:

Le 13/09/2022 à 16:12, Daniel a écrit :

And I guess more importantly in license.rtf it says:

"LyX. You can redistribute LyX and/or modify it under the terms of the 
GNU General Public License as published by the Free Software 
Foundation; either version 2 of the License, or (at your option) any 
later version."


That means that QtCreator can take code from LyX and use it as GPLv3 ;)

JMarc


Or LyX can take code from LyX. ;)

Well, looks like open source isn't as open as I thought.

I see a couple of possible routes to resolve this:

1) I seem to remember that it was stated in the Qt Creator code 
somewhere that smaller parts of the code can be used without license. 
So, I could check with the Qt people what they mean by smaller parts. My 
guess is that re-use of smaller parts would be in their interest since 
it gives people a source of example code that allows people to work more 
easily with Qt. This would also be helpful for the future since 
something like "look at how Qt Creator does it" often comes up.


2) Check whether a previous Qt Creator release under another license has 
the same or similar code.


3) Re-invent the wheel, i.e. I could start from scratch and try to come 
up with my own method for the (un)commenting part.


Any suggestions?

Daniel


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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-13 Thread Jean-Marc Lasgouttes

Le 13/09/2022 à 16:12, Daniel a écrit :

And I guess more importantly in license.rtf it says:

"LyX. You can redistribute LyX and/or modify it under the terms of the 
GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version."


That means that QtCreator can take code from LyX and use it as GPLv3 ;)

JMarc

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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-13 Thread José Matos
On Tue, 2022-09-13 at 16:12 +0200, Daniel wrote:
> And I guess more importantly in license.rtf it says:
> 
> "LyX. You can redistribute LyX and/or modify it under the terms of
> the 
> GNU General Public License as published by the Free Software
> Foundation; 
> either version 2 of the License, or (at your option) any later
> version."
> 
> Daniel

IANAL but incorporating that code makes the effective license of LyX
GPLv3.

Is it worth?
And if GPLv4 ever arrives the "later version" does not apply anymore
because of this code.

-- 
José Abílio
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Indentation and (un)commenting in local layout and preamble

2022-09-13 Thread Daniel

On 13/09/2022 15:56, Daniel wrote:

On 13/09/2022 12:56, Jean-Marc Lasgouttes wrote:

Le 10/08/2022 à 04:15, Daniel a écrit :
In the attached Qt project, I implemented those features. It probably 
needs some more cleaning up. But it seems to work and you could 
already try it out if you like. The (un)commenting feature leans 
heavily on code from QtCreator. (I tried to improve a bit upon it, 
e.g. comments are added at the deepest common indentation as in


Hello Daniel,

I see that QtCreator is licensed under GPLv3. Are we allowed to take 
code from there in our GPLv2 source? I would think that we can't.


JMarc


You might be mistaken:

"9. The Free Software Foundation may publish revised and/or new versions 
of the General Public License from time to time. Such new versions will 
be similar in spirit to the present version, but may differ in detail to 
address new problems or concerns.


Each version is given a distinguishing version number. If the Program 
specifies a version number of this License which applies to it and "any 
later version", you have the option of following the terms and 
conditions either of that version or of any later version published by 
the Free Software Foundation. If the Program does not specify a version 
number of this License, you may choose any version ever published by the 
Free Software Foundation." (https://www.lyx.org/License)


Daniel




And I guess more importantly in license.rtf it says:

"LyX. You can redistribute LyX and/or modify it under the terms of the 
GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version."


Daniel


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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-13 Thread Daniel

On 13/09/2022 12:56, Jean-Marc Lasgouttes wrote:

Le 10/08/2022 à 04:15, Daniel a écrit :
In the attached Qt project, I implemented those features. It probably 
needs some more cleaning up. But it seems to work and you could 
already try it out if you like. The (un)commenting feature leans 
heavily on code from QtCreator. (I tried to improve a bit upon it, 
e.g. comments are added at the deepest common indentation as in


Hello Daniel,

I see that QtCreator is licensed under GPLv3. Are we allowed to take 
code from there in our GPLv2 source? I would think that we can't.


JMarc


You might be mistaken:

"9. The Free Software Foundation may publish revised and/or new versions 
of the General Public License from time to time. Such new versions will 
be similar in spirit to the present version, but may differ in detail to 
address new problems or concerns.


Each version is given a distinguishing version number. If the Program 
specifies a version number of this License which applies to it and "any 
later version", you have the option of following the terms and 
conditions either of that version or of any later version published by 
the Free Software Foundation. If the Program does not specify a version 
number of this License, you may choose any version ever published by the 
Free Software Foundation." (https://www.lyx.org/License)


Daniel


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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-13 Thread Jean-Marc Lasgouttes

Le 10/08/2022 à 04:15, Daniel a écrit :
In the attached Qt project, I implemented those features. It probably 
needs some more cleaning up. But it seems to work and you could already 
try it out if you like. The (un)commenting feature leans heavily on code 
from QtCreator. (I tried to improve a bit upon it, e.g. comments are 
added at the deepest common indentation as in


Hello Daniel,

I see that QtCreator is licensed under GPLv3. Are we allowed to take 
code from there in our GPLv2 source? I would think that we can't.


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


Re: Indentation and (un)commenting in local layout and preamble

2022-09-04 Thread Daniel

On 2022-08-14 20:20, Daniel wrote:

On 2022-08-14 18:38, Kornel Benko wrote:
Applies cleanly and compiles. Rudimentary test looks good. (At least 
writing local

format feels better than what we have now).

Kornel


Thanks for testing. I realized that I changed the tab stop size before 
setting the font which could lead to a wrong size. Very slightly 
modified patch attached. I only added


preambleTE->setTabStop(4);

and

locallayoutTE->setTabStop(4);

at the correct positions.

Daniel



I have moved the finalized patch to https://www.lyx.org/trac/ticket/12577.

Daniel


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


Re: Indentation and (un)commenting in local layout and preamble

2022-08-14 Thread Daniel

On 2022-08-14 18:38, Kornel Benko wrote:

Applies cleanly and compiles. Rudimentary test looks good. (At least writing 
local
format feels better than what we have now).

Kornel


Thanks for testing. I realized that I changed the tab stop size before 
setting the font which could lead to a wrong size. Very slightly 
modified patch attached. I only added


preambleTE->setTabStop(4);

and

locallayoutTE->setTabStop(4);

at the correct positions.

DanielFrom aef456245b29a2563204b021d58c944641be4a0e Mon Sep 17 00:00:00 2001
From: Daniel Ramoeller 
Date: Sun, 14 Aug 2022 20:16:02 +0200
Subject: [PATCH] Extended comment and indentation for source code

- automatically inherit indentation from previous block
- (un)indent blocks
- (un)comment blocks
---
 src/frontends/qt/GuiDocument.cpp |  23 +--
 src/frontends/qt/GuiSourceEdit.cpp   | 258 +++
 src/frontends/qt/GuiSourceEdit.h |  57 ++
 src/frontends/qt/Makefile.am |   2 +
 src/frontends/qt/ui/LocalLayoutUi.ui |   9 +-
 src/frontends/qt/ui/PreambleUi.ui|   9 +-
 6 files changed, 336 insertions(+), 22 deletions(-)
 create mode 100644 src/frontends/qt/GuiSourceEdit.cpp
 create mode 100644 src/frontends/qt/GuiSourceEdit.h

diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index b3f31302dd..7543d7126e 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -480,7 +480,8 @@ PreambleModule::PreambleModule(QWidget * parent)
// @ is letter in the LyX user preamble
(void) new LaTeXHighlighter(preambleTE->document(), true);
preambleTE->setFont(guiApp->typewriterSystemFont());
-   preambleTE->setWordWrapMode(QTextOption::NoWrap);
+   preambleTE->setTabStop(4);
+   preambleTE->setSingleLine("%");
setFocusProxy(preambleTE);
connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
connect(findLE, SIGNAL(textEdited(const QString &)), this, 
SLOT(checkFindButton()));
@@ -488,15 +489,6 @@ PreambleModule::PreambleModule(QWidget * parent)
connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
checkFindButton();
-   int const tabStop = 4;
-   QFontMetrics metrics(preambleTE->currentFont());
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
-   // horizontalAdvance() is available starting in 5.11.0
-   // setTabStopDistance() is available starting in 5.10.0
-   preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' 
'));
-#else
-   preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
-#endif
 }
 
 
@@ -606,20 +598,11 @@ LocalLayout::LocalLayout(QWidget * parent)
: UiWidget(parent), current_id_(nullptr), 
validated_(false)
 {
locallayoutTE->setFont(guiApp->typewriterSystemFont());
-   locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
+   locallayoutTE->setTabStop(4);
connect(locallayoutTE, SIGNAL(textChanged()), this, 
SLOT(textChanged()));
connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
-   int const tabStop = 4;
-   QFontMetrics metrics(locallayoutTE->currentFont());
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
-   // horizontalAdvance() is available starting in 5.11.0
-   // setTabStopDistance() is available starting in 5.10.0
-   locallayoutTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' 
'));
-#else
-   locallayoutTE->setTabStopWidth(tabStop * metrics.width(' '));
-#endif
 }
 
 
diff --git a/src/frontends/qt/GuiSourceEdit.cpp 
b/src/frontends/qt/GuiSourceEdit.cpp
new file mode 100644
index 00..d011a8aad6
--- /dev/null
+++ b/src/frontends/qt/GuiSourceEdit.cpp
@@ -0,0 +1,258 @@
+// -*- C++ -*-
+/**
+ * \file GuiSourceEdit.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include "GuiSourceEdit.h"
+
+namespace lyx {
+namespace frontend {
+
+GuiSourceEdit::GuiSourceEdit(QWidget * parent) : QTextEdit(parent)
+{
+   setWordWrapMode(QTextOption::NoWrap);
+   setTabStop(tabStop_);
+}
+
+void GuiSourceEdit::setTabStop(int spaces) {
+   tabStop_ = spaces;
+   QFontMetrics metrics(currentFont());
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
+   // horizontalAdvance() is available starting in 5.11.0
+   // setTabStopDistance() is available starting in 5.10.0
+   setTabStopDistance(tabStop_ * metrics.horizontalAdvance(' '));
+#else
+   setTabStopWidth(tabStop_ * metrics.width(' '));
+#endif
+}
+
+GuiSourceEdit::BlockRangeInfo GuiSourceEdit::getBlockRangeInfo(
+   QTextCursor const & cursorIn) const {
+   QTextCursor cursor = 

Re: Indentation and (un)commenting in local layout and preamble

2022-08-14 Thread Kornel Benko
Am Sun, 14 Aug 2022 09:27:40 +0200
schrieb Daniel :

> On 2022-08-10 04:15, Daniel wrote:
> > It would be nice if LyX's source editors (for Local Layout and LaTeX 
> > Preamble) would have proper indentation and (un)commenting support.
> > 
> > I know that the external editing is supported now, but I consider this 
> > more of a pro feature since it presupposes already having set up an 
> > editor (other than the standard Windows and macOS text editors) and even 
> > then it seems often unnecessary cumbersome to use.
> > 
> > In the attached Qt project, I implemented those features. It probably 
> > needs some more cleaning up. But it seems to work and you could already 
> > try it out if you like. The (un)commenting feature leans heavily on code 
> > from QtCreator. (I tried to improve a bit upon it, e.g. comments are 
> > added at the deepest common indentation as in
> > 
> > 
> > Begin
> >  % Comment
> >  Code
> > End
> > 
> > 
> > and it is possible to start a comment in an empty line. Both seem to me 
> > quite a bit of an oversight in Qt Creator.)
> > 
> > If there is interest, what I would at least need help with for bringing 
> > this over to LyX is a basic setup of the "GuiSourceEdit" class. I tried 
> > it but failed (linker error). I guess it should be in its own
> > h/.cpp file. It could already have the constructor as in the attached 
> > "mainwindow.h" which is code from the source text edits in 
> > "GuiDocument.cpp". I could then add all the other stuff when it is ready 
> > but, first, I wanted to make sure that there is some interest.
> > 
> > Daniel
> >   
> 
> Managed to get the files working. Attached is the patch to extend LyX's 
> source code editing facilities. (I would have posted it on trac but the 
> login is not working currently.)
> 
> Daniel

Applies cleanly and compiles. Rudimentary test looks good. (At least writing 
local
format feels better than what we have now).

Kornel


pgpCqbZrzlr2B.pgp
Description: Digitale Signatur von OpenPGP
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel


Re: Indentation and (un)commenting in local layout and preamble

2022-08-14 Thread Daniel

On 2022-08-10 04:15, Daniel wrote:
It would be nice if LyX's source editors (for Local Layout and LaTeX 
Preamble) would have proper indentation and (un)commenting support.


I know that the external editing is supported now, but I consider this 
more of a pro feature since it presupposes already having set up an 
editor (other than the standard Windows and macOS text editors) and even 
then it seems often unnecessary cumbersome to use.


In the attached Qt project, I implemented those features. It probably 
needs some more cleaning up. But it seems to work and you could already 
try it out if you like. The (un)commenting feature leans heavily on code 
from QtCreator. (I tried to improve a bit upon it, e.g. comments are 
added at the deepest common indentation as in



Begin
 % Comment
 Code
End


and it is possible to start a comment in an empty line. Both seem to me 
quite a bit of an oversight in Qt Creator.)


If there is interest, what I would at least need help with for bringing 
this over to LyX is a basic setup of the "GuiSourceEdit" class. I tried 
it but failed (linker error). I guess it should be in its own
h/.cpp file. It could already have the constructor as in the attached 
"mainwindow.h" which is code from the source text edits in 
"GuiDocument.cpp". I could then add all the other stuff when it is ready 
but, first, I wanted to make sure that there is some interest.


Daniel



Managed to get the files working. Attached is the patch to extend LyX's 
source code editing facilities. (I would have posted it on trac but the 
login is not working currently.)


DanielFrom a367b6d1e25fad1c12b7e72223ade88760d158e5 Mon Sep 17 00:00:00 2001
From: Daniel Ramoeller 
Date: Sun, 14 Aug 2022 09:22:13 +0200
Subject: [PATCH] Extended comment and indentation for source code

- automatically inherit indentation from previous block
- (un)indent blocks
- (un)comment blocks
---
 src/frontends/qt/GuiDocument.cpp |  21 +--
 src/frontends/qt/GuiSourceEdit.cpp   | 258 +++
 src/frontends/qt/GuiSourceEdit.h |  57 ++
 src/frontends/qt/Makefile.am |   2 +
 src/frontends/qt/ui/LocalLayoutUi.ui |   9 +-
 src/frontends/qt/ui/PreambleUi.ui|   9 +-
 6 files changed, 334 insertions(+), 22 deletions(-)
 create mode 100644 src/frontends/qt/GuiSourceEdit.cpp
 create mode 100644 src/frontends/qt/GuiSourceEdit.h

diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index b3f31302dd..fb78757299 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -480,7 +480,7 @@ PreambleModule::PreambleModule(QWidget * parent)
// @ is letter in the LyX user preamble
(void) new LaTeXHighlighter(preambleTE->document(), true);
preambleTE->setFont(guiApp->typewriterSystemFont());
-   preambleTE->setWordWrapMode(QTextOption::NoWrap);
+   preambleTE->setSingleLine("%");
setFocusProxy(preambleTE);
connect(preambleTE, SIGNAL(textChanged()), this, SIGNAL(changed()));
connect(findLE, SIGNAL(textEdited(const QString &)), this, 
SLOT(checkFindButton()));
@@ -488,15 +488,6 @@ PreambleModule::PreambleModule(QWidget * parent)
connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
connect(findLE, SIGNAL(returnPressed()), this, SLOT(findText()));
checkFindButton();
-   int const tabStop = 4;
-   QFontMetrics metrics(preambleTE->currentFont());
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
-   // horizontalAdvance() is available starting in 5.11.0
-   // setTabStopDistance() is available starting in 5.10.0
-   preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' 
'));
-#else
-   preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
-#endif
 }
 
 
@@ -606,20 +597,10 @@ LocalLayout::LocalLayout(QWidget * parent)
: UiWidget(parent), current_id_(nullptr), 
validated_(false)
 {
locallayoutTE->setFont(guiApp->typewriterSystemFont());
-   locallayoutTE->setWordWrapMode(QTextOption::NoWrap);
connect(locallayoutTE, SIGNAL(textChanged()), this, 
SLOT(textChanged()));
connect(validatePB, SIGNAL(clicked()), this, SLOT(validatePressed()));
connect(convertPB, SIGNAL(clicked()), this, SLOT(convertPressed()));
connect(editPB, SIGNAL(clicked()), this, SLOT(editExternal()));
-   int const tabStop = 4;
-   QFontMetrics metrics(locallayoutTE->currentFont());
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
-   // horizontalAdvance() is available starting in 5.11.0
-   // setTabStopDistance() is available starting in 5.10.0
-   locallayoutTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' 
'));
-#else
-   locallayoutTE->setTabStopWidth(tabStop * metrics.width(' '));
-#endif
 }
 
 
diff --git a/src/frontends/qt/GuiSourceEdit.cpp 
b/src/frontends/qt/GuiSourceEdit.cpp
new file mode 100644
index 00..d011a8aad6
--- /dev/null
+++