Window Size/Pos Tracking

This commit is contained in:
mwalker33 2020-04-13 09:32:47 +10:00
commit 69eef755d3
5 changed files with 53 additions and 27 deletions

View file

@ -24,7 +24,7 @@
#include "cmdparser.h"
#include <ctype.h>
//#include "proxgui.h"
extern void SetWindowsPosition (void);
//extern void SetWindowsPosition (void);
static int CmdHelp(const char *Cmd);
// Load all settings into memory (struct)
@ -445,7 +445,7 @@ static int CmdPrefSet (const char *Cmd)
// Need to work out how to change live....
// calling data plot seems to work
//plotwidget->MoveWindows ();
SetWindowsPosition();
// SetWindowsPosition();
showPlotPosState ();
break;
case prefOVERLAY:
@ -468,7 +468,7 @@ static int CmdPrefSet (const char *Cmd)
if (y != -99999) session.window_overlay_ypos = y;
if (h != -99999) session.window_overlay_hsize = h;
if (w != -99999) session.window_overlay_wsize = w;
SetWindowsPosition();
// SetWindowsPosition();
showOverlayPosState ();
// Need to work out how to change live....
break;

View file

@ -54,9 +54,6 @@ extern "C" void MainGraphics(void) {
gui->MainLoop();
}
extern "C" void SetWindowsPosition (void) {
gui->SetWindowsPosition ();
}
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
#ifdef Q_WS_X11

View file

@ -24,7 +24,6 @@ void ShowGraphWindow(void);
void HideGraphWindow(void);
void RepaintGraphWindow(void);
void MainGraphics(void);
void SetWindowsPosition (void);
void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool stayInCommandLoop);
void ExitGraphics(void);
#ifndef MAX_GRAPH_TRACE_LEN

View file

@ -128,10 +128,30 @@ ProxGuiQT::~ProxGuiQT(void) {
plotapp = NULL;
}
}
void ProxGuiQT::SetWindowsPosition (void)
{
plotwidget->SetWindowsPosition ();
// -------------------------------------------------
// Slider Widget form based on a class to enable
// Event override functions
// -------------------------------------------------
SliderWidget::SliderWidget() {
// Set the initail postion and size from settings
if (session.preferences_loaded)
setGeometry (session.window_overlay_xpos,session.window_overlay_ypos,session.window_overlay_wsize,session.window_overlay_hsize);
else
resize(800, 400);
}
void SliderWidget::resizeEvent (QResizeEvent *event) {
session.window_overlay_hsize = event->size().height();
session.window_overlay_wsize = event->size().width();
}
void SliderWidget::moveEvent (QMoveEvent *event) {
session.window_overlay_xpos = event->pos().x();
session.window_overlay_ypos = event->pos().y();
}
//--------------------
void ProxWidget::applyOperation() {
//printf("ApplyOperation()");
@ -179,7 +199,7 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
resize(800, 400);
// Setup the controller widget
controlWidget = new QWidget();
controlWidget = new SliderWidget ();//new QWidget();
opsController = new Ui::Form();
opsController->setupUi(controlWidget);
//Due to quirks in QT Designer, we need to fiddle a bit
@ -192,7 +212,6 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
opsController->horizontalSlider_askedge->setValue(25);
opsController->horizontalSlider_window->setValue(4000);
QObject::connect(opsController->pushButton_apply, SIGNAL(clicked()), this, SLOT(applyOperation()));
QObject::connect(opsController->pushButton_sticky, SIGNAL(clicked()), this, SLOT(stickOperation()));
QObject::connect(opsController->horizontalSlider_window, SIGNAL(valueChanged(int)), this, SLOT(vchange_autocorr(int)));
@ -200,6 +219,8 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
QObject::connect(opsController->horizontalSlider_dirthr_down, SIGNAL(valueChanged(int)), this, SLOT(vchange_dthr_down(int)));
QObject::connect(opsController->horizontalSlider_askedge, SIGNAL(valueChanged(int)), this, SLOT(vchange_askedge(int)));
controlWidget->setGeometry (session.window_overlay_xpos,session.window_overlay_ypos,session.window_overlay_wsize,session.window_overlay_hsize);
// Set up the plot widget, which does the actual plotting
plot = new Plot(this);
QVBoxLayout *layout = new QVBoxLayout;
@ -213,9 +234,8 @@ ProxWidget::ProxWidget(QWidget *parent, ProxGuiQT *master) : QWidget(parent) {
// shows plot window on the screen.
show();
if (session.preferences_loaded)
controlWidget->setGeometry (session.window_overlay_xpos,session.window_overlay_ypos,session.window_overlay_wsize,session.window_overlay_hsize);
else {
// Set Slider/Overlay position if no settings.
if (!session.preferences_loaded){
// Move controller widget below plot
controlWidget->move(x(), y() + frameSize().height());
controlWidget->resize(size().width(), 200);
@ -261,15 +281,14 @@ void ProxWidget::showEvent(QShowEvent *event) {
controlWidget->show();
plot->show();
}
void ProxWidget::SetWindowsPosition(void) {
void ProxWidget::moveEvent(QMoveEvent *event) {
session.window_plot_xpos = event->pos().x();
session.window_plot_ypos = event->pos().y();
// plotwidget->update();
if (session.preferences_loaded) {
setGeometry (session.window_plot_xpos,session.window_plot_ypos,session.window_plot_wsize,session.window_plot_hsize);
controlWidget->setGeometry (session.window_overlay_xpos,session.window_overlay_ypos,session.window_overlay_wsize,session.window_overlay_hsize);
update();
controlWidget->update();
}
void ProxWidget::resizeEvent(QResizeEvent *event) {
session.window_plot_hsize = event->size().height();
session.window_plot_wsize = event->size().width();
}
//----------- Plotting

View file

@ -56,9 +56,19 @@ class Plot: public QWidget {
};
class ProxGuiQT;
// Added class for SliderWidget to allow move/resize event override
class SliderWidget : public QWidget {
protected:
void resizeEvent (QResizeEvent *event);
void moveEvent (QMoveEvent *event);
public:
SliderWidget();
};
/**
* The window with plot and controls
*/
class ProxWidget : public QWidget {
Q_OBJECT; //needed for slot/signal classes
@ -66,8 +76,8 @@ class ProxWidget : public QWidget {
ProxGuiQT *master;
Plot *plot;
Ui::Form *opsController;
QWidget *controlWidget;
// QWidget *controlWidget;
SliderWidget *controlWidget;
public:
ProxWidget(QWidget *parent = 0, ProxGuiQT *master = NULL);
~ProxWidget(void);
@ -78,6 +88,8 @@ class ProxWidget : public QWidget {
void closeEvent(QCloseEvent *event);
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
void moveEvent(QMoveEvent *event);
void resizeEvent(QResizeEvent *event);
// void mouseMoveEvent(QMouseEvent *event);
// void mousePressEvent(QMouseEvent *event) { mouseMoveEvent(event); }
// void keyPressEvent(QKeyEvent *event);
@ -88,7 +100,6 @@ class ProxWidget : public QWidget {
void vchange_askedge(int v);
void vchange_dthr_up(int v);
void vchange_dthr_down(int v);
void SetWindowsPosition(void);
};
class WorkerThread : public QThread {