Qt term enhancements

m sutton <[email protected]> Wed, 9 Feb 2022 20:28:13 -0500
Newsgroups gmane.comp.graphics.gnuplot.devel
Message-ID <[email protected]>
Hi All,

I modified the qt term so you can  set three options that are currently 
on the tools dialog.

The change will allow you to specify rounded|butt, {no}replotonresize 
and {no}antialias.  These are temporary settings.

This also fixed a bug with the {no}ctrl option.  If multiple "set term 
qt" command were given before the plot window was opend, the {no}ctrl 
setting would be lost.

The attached diff is based on v5.4.1.  Let me know if something needs 
changed.

Once again, many thank to all of you that make Gnuplot so awesome.

Regards,

MikeS

_______________________________________________
gnuplot-beta mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta
qt_term_options_r2.diff (text/plain, 9.3 KB)
diff --git a/src/mouse.c b/src/mouse.c
index dd4a3f5..74d6cf9 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -2330,13 +2330,12 @@ event_reset(struct gp_event_t *ge)
     /* This hack is necessary on some systems in order to prevent one
      * character of input from being swallowed when the plot window is
      * closed. But which systems, exactly, and in what circumstances?
-     * FIXME (June 2020):
-     * A change to readline.c:getc_wrapper may have made this unnecessary.
      */
     if (paused_for_mouse || !interactive) {
-	if (term && (!strncmp("x11",term->name,3)
-		 || !strncmp("wxt",term->name,3)
-		 || !strncmp("qt",term->name,2)))
+	if (term && term_initialised
+	&&  (   !strncmp("x11",term->name,3)
+	     || !strncmp("wxt",term->name,3)
+	     || !strncmp("qt",term->name,2)))
 	    ungetc('\n',stdin);
     }
 
diff --git a/src/qtterminal/QtGnuplotEvent.cpp b/src/qtterminal/QtGnuplotEvent.cpp
index 69f71e5..3a5d393 100644
--- a/src/qtterminal/QtGnuplotEvent.cpp
+++ b/src/qtterminal/QtGnuplotEvent.cpp
@@ -177,6 +177,9 @@ void QtGnuplotEventReceiver::swallowEvent(QtGnuplotEventType type, QDataStream&
 	else if (type == GEStatusText)       in >> string;   // 1005
 	else if (type == GETitle)            in >> string;   // 1006
 	else if (type == GESetCtrl)          in >> b;        // 1007
+	else if (type == GESetRounded)       in >> b;
+	else if (type == GESetAntiAlias)     in >> b;
+	else if (type == GESetReplotOnResize) in >> b;
 	else if (type == GECursor)           in >> i;        // 1009
 	else if (type == GEZoomStart)        in >> string;   // 1022
 	else if (type == GEZoomStop)         in >> string;   // 1023
diff --git a/src/qtterminal/QtGnuplotEvent.h b/src/qtterminal/QtGnuplotEvent.h
index 1b3214e..b6f26ab 100644
--- a/src/qtterminal/QtGnuplotEvent.h
+++ b/src/qtterminal/QtGnuplotEvent.h
@@ -53,6 +53,7 @@ enum QtGnuplotEventType {
 GESetCurrentWindow = 1000, GEInitWindow, GECloseWindow, GEExit, GEPersist,
 // Events for QtGnuplotWindow
 GEStatusText, GETitle, GESetCtrl, GESetPosition, GEPID,
+GESetRounded, GESetAntiAlias, GESetReplotOnResize,
 // Events for QtGnuplotWidget
 GESetWidgetSize, GECursor,
 // Events for QtGnuplotScene
diff --git a/src/qtterminal/QtGnuplotWindow.cpp b/src/qtterminal/QtGnuplotWindow.cpp
index d5e5060..0569c66 100644
--- a/src/qtterminal/QtGnuplotWindow.cpp
+++ b/src/qtterminal/QtGnuplotWindow.cpp
@@ -303,6 +303,21 @@ void QtGnuplotWindow::processEvent(QtGnuplotEventType type, QDataStream& in)
 		in >> m_ctrl;
 		m_widget->setCtrlQ(m_ctrl);
 	}
+	else if (type == GESetRounded)
+	{
+		in >> m_rounded;
+		m_widget->setRounded(m_rounded);
+	}
+	else if (type == GESetAntiAlias)
+	{
+		in >> m_antialias;
+		m_widget->setAntialias(m_antialias);
+	}
+	else if (type == GESetReplotOnResize)
+	{
+		in >> m_replotOnResize;
+		m_widget->setReplotOnResize(m_replotOnResize);
+	}
 	else if (type == GESetPosition)
 	{
 		QPoint pos;
diff --git a/src/qtterminal/QtGnuplotWindow.h b/src/qtterminal/QtGnuplotWindow.h
index 33c5418..cf57c24 100644
--- a/src/qtterminal/QtGnuplotWindow.h
+++ b/src/qtterminal/QtGnuplotWindow.h
@@ -91,6 +91,9 @@ private:
 
 private:
 	bool m_ctrl;
+	bool m_rounded;
+	bool m_antialias;
+	bool m_replotOnResize;
 	int m_id;
 	bool m_statusBarActive;
 	QStatusBar* m_statusBar;
diff --git a/src/qtterminal/qt_term.cpp b/src/qtterminal/qt_term.cpp
index ed2bba8..a1dd432 100644
--- a/src/qtterminal/qt_term.cpp
+++ b/src/qtterminal/qt_term.cpp
@@ -163,6 +163,9 @@ static bool qt_optionEnhanced = true;
 static bool qt_optionPersist  = false;
 static bool qt_optionRaise    = true;
 static bool qt_optionCtrl     = false;
+static bool qt_optionRounded  = true; 
+static bool qt_optionAntiAlias  = true;
+static bool qt_optionReplotOnResize  = true;
 static bool qt_optionDash     = true;
 static int  qt_optionWidth    = 640;
 static int  qt_optionHeight   = 480;
@@ -170,7 +173,10 @@ static int  qt_optionFontSize = 9;
 static double qt_optionDashLength = 1.0;
 static double qt_optionLineWidth = 1.0;
 
-static int qt_optionctrlq = -1;	// tristate -1 = not set 0 = false 1 = true 
+static int qt_optionctrlq = -1;	         // tristate -1 = not set 0 = false 1 = true 
+static int qt_optionrounded = -1;	 // tristate -1 = not set 0 = false 1 = true 
+static int qt_optionantialias = -1;	 // tristate -1 = not set 0 = false 1 = true 
+static int qt_optionreplotonresize = -1; // tristate -1 = not set 0 = false 1 = true 
 
 /* Encapsulates all Qt options that have a constructor and destructor. */
 struct QtOption {
@@ -571,6 +577,19 @@ void qt_graphics()
 		qt->out << GESetCtrl << qt_optionCtrl;
 		qt_optionctrlq = -1;
 	}
+	if (qt_optionantialias >= 0) {
+		qt->out << GESetAntiAlias << qt_optionAntiAlias;
+		qt_optionantialias = -1;
+	}
+	if (qt_optionreplotonresize >= 0) {
+		qt->out << GESetReplotOnResize << qt_optionReplotOnResize;
+		qt_optionreplotonresize = -1;
+	}
+
+	if (qt_optionrounded >= 0) {
+	  qt->out << GESetRounded << qt_optionRounded;
+	  qt_optionrounded = -1;
+	}
 
 	qt->out << GESetWidgetSize << QSize(term->xmax, term->ymax)/qt_oversampling;
 	// Initialize the scene
@@ -1321,7 +1340,13 @@ enum QT_id {
 	QT_DASHLENGTH,
 	QT_SOLID,
 	QT_LINEWIDTH,
-	QT_OTHER
+	QT_OTHER,
+	QT_ROUNDED,
+	QT_NOROUNDED,
+	QT_ANTIALIAS,
+	QT_NOANTILIAS,
+	QT_REPLOTONRESIZE,
+	QT_NOREPLOTONRESIZE
 };
 
 static struct gen_table qt_opts[] = {
@@ -1337,6 +1362,12 @@ static struct gen_table qt_opts[] = {
 	{"norai$se",    QT_NORAISE},
 	{"ct$rlq",      QT_CTRL},
 	{"noct$rlq",    QT_NOCTRL},
+	{"rou$nded",    QT_ROUNDED},
+	{"butt",        QT_NOROUNDED},
+	{"an$tialias",  QT_ANTIALIAS},
+	{"noan$tialias",QT_NOANTILIAS},
+	{"rep$lotonresize", QT_REPLOTONRESIZE},
+	{"norep$lotonresize", QT_NOREPLOTONRESIZE},
 	{"ti$tle",      QT_TITLE},
 	{"cl$ose",      QT_CLOSE},
 	{"dash$ed",     QT_DASH},
@@ -1368,6 +1399,9 @@ void qt_options()
 	bool set_dash = false;
 	bool set_dashlength = false;
 	bool set_linewidth = false;
+	bool set_rounded = false;
+	bool set_antialias = false;
+	bool set_replotonresize = false;
 	int previous_WindowId = qt_optionWindowId;
 
 #ifndef _WIN32
@@ -1460,6 +1494,31 @@ void qt_options()
 			SETCHECKDUP(set_ctrl);
 			qt_optionCtrl = false;
 			break;
+
+		case QT_ROUNDED:
+			SETCHECKDUP(set_rounded);
+			qt_optionRounded = true;
+			break;
+		case QT_NOROUNDED:
+			SETCHECKDUP(set_rounded);
+			qt_optionRounded = false;
+			break;
+		case QT_ANTIALIAS:
+			SETCHECKDUP(set_antialias);
+			qt_optionAntiAlias = true;
+			break;
+		case QT_NOANTILIAS:
+			SETCHECKDUP(set_antialias);
+			qt_optionAntiAlias = false;
+			break;
+		case QT_REPLOTONRESIZE:
+			SETCHECKDUP(set_replotonresize);
+			qt_optionReplotOnResize = true;
+			break;
+		case QT_NOREPLOTONRESIZE:
+			SETCHECKDUP(set_replotonresize);
+			qt_optionReplotOnResize = false;
+			break;
 		case QT_TITLE:
 			SETCHECKDUP(set_title);
 			if (!(s = try_to_get_string()))
@@ -1550,8 +1609,22 @@ void qt_options()
 	/// Only send the ctrlQ option if it is explicitly given in "set term qt {no}ctrlq"
 	if (set_ctrl)
 	    qt_optionctrlq = qt_optionCtrl;
-	else
-	    qt_optionctrlq = -1;
+
+	if (set_rounded) termOptions += qt_optionRounded ? " rounded" : " butt";
+
+	if (set_rounded)
+	  qt_optionrounded = qt_optionRounded;
+
+	if (set_antialias) termOptions += qt_optionAntiAlias ? " antialias" : " noantialias";
+
+	if (set_antialias)
+	  qt_optionantialias = qt_optionAntiAlias;
+
+	if (set_replotonresize) termOptions += qt_optionReplotOnResize ? " replotonresize" : " noreplotonresize";
+
+	if (set_replotonresize)
+	  qt_optionreplotonresize = qt_optionReplotOnResize;
+
 
 	/// @bug change Utf8 to local encoding
 	strncpy(term_options, termOptions.toUtf8().data(), MAX_LINE_LEN);
diff --git a/term/qt.trm b/term/qt.trm
index cdc5591..d8c7b50 100644
--- a/term/qt.trm
+++ b/term/qt.trm
@@ -90,6 +90,9 @@ START_HELP(qt)
 "                     {position <x>,<y>}",
 "                     {title \"title\"}",
 "                     {font <font>} {{no}enhanced}",
+"                     {rounded|butt}",
+"                     {{no}replotonresize}",
+"                     {{no}antialias}",
 "                     {linewidth <lw>} {dashlength <dl>}",
 "                     {{no}persist} {{no}raise} {{no}ctrl}",
 "                     {close}",
@@ -161,6 +164,19 @@ START_HELP(qt)
 " oversampling. The terminal will snap these lines to integer coordinates so",
 " that a one-pixel-wide line will actually be drawn on one and only one pixel.",
 "",
+" `butt` instructs the driver to use a line drawing method that does",
+" not overshoot the desired end point of a line.  This setting is only",
+" applicable for line widths greater than 1.  This setting is most useful when",
+" drawing horizontal or vertical lines.  Default is `rounded`.",
+"",
+" The option `replotonresize` replots the data when the plot window is",
+" resized. Without this option, the even-aspect-ratio scaling may result in the",
+" plot filling only part of the window after resizing.  With this option, gnuplot",
+" does a full replot on each resize event, resulting in better space",
+" utilization. This option is generally desirable, unless the potentially",
+" CPU-intensive replotting during resizing is a concern. Replots can be manually",
+" initiated with hotkey 'e' or the 'replot' command.",
+"",
 " By default, the window is raised to the top of your desktop when a plot is",
 " drawn. This can be controlled with the keyword \"raise\".",
 " The keyword \"persist\" will prevent gnuplot from exiting before you",