Skip to content

Commit

Permalink
improved support for lower display resolutions down to 1024x768 by dy…
Browse files Browse the repository at this point in the history
…namically adjusting the view area in the recording tab, stretching font sizes and gui elements in control consoles within the OpenGL output windows and reloading user defined height of message console at startup
  • Loading branch information
spectralcode committed Mar 3, 2024
1 parent bf14153 commit 094df9e
Show file tree
Hide file tree
Showing 9 changed files with 478 additions and 262 deletions.
31 changes: 27 additions & 4 deletions octproz_project/octproz/src/glwindow2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QTimer>
#include <QToolTip>
#include <QGuiApplication>
#include <QSizePolicy>


GLWindow2D::GLWindow2D(QWidget *parent) : QOpenGLWidget(parent) {
Expand All @@ -41,8 +42,8 @@ GLWindow2D::GLWindow2D(QWidget *parent) : QOpenGLWidget(parent) {
this->screenHeightScaled = 1.0;
this->xTranslation = 0.0;
this->yTranslation = 0.0;
this->setMinimumWidth(448);
this->setMinimumHeight(448);
this->setMinimumWidth(256);
this->setMinimumHeight(256);
this->initialized = false;
this->changeBufferSizeFlag = false;
this->keepAspectRatio = true;
Expand Down Expand Up @@ -597,12 +598,13 @@ ControlPanel2D::ControlPanel2D(QWidget *parent) : QWidget(parent) {
this->spinBoxFrame->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->doubleSpinBoxRotationAngle = new QDoubleSpinBox(this->panel);
this->doubleSpinBoxRotationAngle->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
this->labelFrame = new QLabel(tr("Display frame:"), this->panel);
this->labelFrame = new QLabel(tr("Frame:"), this->panel);
this->labelRotationAngle = new QLabel(tr("Rotation:"), this->panel);
this->slider = new QSlider(Qt::Horizontal, this->panel);
this->slider->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);
this->stringBoxFunctions = new StringSpinBox(this->panel);
this->labelDisplayFunction = new QLabel(tr("Display mode:"), this->panel);
this->stringBoxFunctions->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
this->labelDisplayFunction = new QLabel(tr("Mode:"), this->panel);
this->labelDisplayFunctionFrames = new QLabel(tr("Frames:"), this->panel);

this->doubleSpinBoxStretchX = new QDoubleSpinBox(this->panel);
Expand Down Expand Up @@ -806,6 +808,27 @@ void ControlPanel2D::disconnectGuiFromSettingsChangedSignal() {
}
}

void ControlPanel2D::adjustFontSize() {
const int thresholdWidth = 270;
QFont font = this->font();

if(this->width() <= thresholdWidth){
font.setStretch(80);
} else {
font.setStretch(100);
}
this->setFont(font);

for (auto& widget : this->findChildren<QWidget*>()) {
widget->setFont(font);
}
}

void ControlPanel2D::resizeEvent(QResizeEvent *event) {
this->adjustFontSize();
QWidget::resizeEvent(event);
}

void ControlPanel2D::setParams(GLWindow2DParams params) {
this->disconnectGuiFromSettingsChangedSignal();
this->params = params;
Expand Down
3 changes: 2 additions & 1 deletion octproz_project/octproz/src/glwindow2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class ControlPanel2D : public QWidget
void updateParams();
void connectGuiToSettingsChangedSignal();
void disconnectGuiFromSettingsChangedSignal();
void adjustFontSize();

GLWindow2DParams params;
bool extendedView;
Expand Down Expand Up @@ -330,7 +331,7 @@ class ControlPanel2D : public QWidget


protected:

void resizeEvent(QResizeEvent *event) override;

public slots:
void setParams(GLWindow2DParams params);
Expand Down
38 changes: 33 additions & 5 deletions octproz_project/octproz/src/messageconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
** This file is part of OCTproZ.
** OCTproZ is an open source software for processig of optical
** coherence tomography (OCT) raw data.
** Copyright (C) 2019-2022 Miroslav Zabic
** Copyright (C) 2019-2024 Miroslav Zabic
**
** OCTproZ is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,7 +36,8 @@ MessageConsole::MessageConsole(QWidget *parent) : QWidget(parent){
this->gridLayout->setMargin(0);
this->gridLayout->addWidget(this->textEdit, 0, 0, 1, 1);
this->setMinimumWidth(320);
this->setMinimumHeight(160);
this->setMinimumHeight(30);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

this->messages = QVector<QString>(MAX_MESSAGES);

Expand All @@ -46,9 +47,7 @@ MessageConsole::MessageConsole(QWidget *parent) : QWidget(parent){
this->messagesIndex = 0;

this->params.newestMessageAtBottom = false;



this->params.preferredHeight = 100;
}

MessageConsole::~MessageConsole(){
Expand All @@ -58,6 +57,11 @@ MessageConsole::~MessageConsole(){
void MessageConsole::setParams(MessageConsoleParams params) {
this->params = params;
this->insertNewMessagesAtBottom(this->params.newestMessageAtBottom);
this->adjustSize();
}

QSize MessageConsole::sizeHint() const {
return QSize(QWidget::sizeHint().width(), this->params.preferredHeight);
}

//todo: rethink and redo this. there is probably a much better way than recreating the entire message string for every new message
Expand Down Expand Up @@ -122,6 +126,30 @@ void MessageConsole::refreshMessages() {
}
}

void MessageConsole::resizeEvent(QResizeEvent *event) {
//this code saves the console size in params to restore it on app restart.
//however, due to a bug in Qt 5.11, the MessageConsole gets resized without user action when other docks are modified.
//see Qt bug report:https://bugreports.qt.io/browse/QTBUG-65592.
//this bug has been fixed for qt 5.12, see here: https://code.qt.io/cgit/qt/qtbase.git/commit/src/widgets/widgets/qdockarealayout.cpp?id=e2d79b496335e8d8666014e900930c66cf722eb6
//the following code serves as a workaround for Qt version older than 5.12.
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
const int heightChangeThreshold = 50;
if (qAbs(event->oldSize().height() - event->size().height()) < heightChangeThreshold) {
this->params.preferredHeight = this->height();
} else {
this->displayInfo("auto");

int minHeight = this->minimumHeight();
this->setFixedHeight(this->params.preferredHeight);
this->setMinimumHeight(minHeight);
this->setMaximumHeight(QWIDGETSIZE_MAX);
}
#else
this->params.preferredHeight = this->height();
#endif
QWidget::resizeEvent(event);
}

void MessageConsole::insertNewMessagesAtBottom(bool enable) {
if(this->params.newestMessageAtBottom == enable){
return;
Expand Down
9 changes: 8 additions & 1 deletion octproz_project/octproz/src/messageconsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
** This file is part of OCTproZ.
** OCTproZ is an open source software for processig of optical
** coherence tomography (OCT) raw data.
** Copyright (C) 2019-2022 Miroslav Zabic
** Copyright (C) 2019-2024 Miroslav Zabic
**
** OCTproZ is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,11 +36,13 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QCoreApplication>
#include <QSize>

#define MAX_MESSAGES 512

struct MessageConsoleParams {
bool newestMessageAtBottom;
int preferredHeight;
};

class MessageConsole : public QWidget
Expand All @@ -53,6 +55,8 @@ class MessageConsole : public QWidget
QDockWidget* getDock(){return this->dock;}
void setParams(MessageConsoleParams params);
MessageConsoleParams getParams(){return this->params;}
QSize sizeHint() const override;


private:
QTextEdit* textEdit;
Expand All @@ -67,6 +71,9 @@ class MessageConsole : public QWidget
void contextMenuEvent(QContextMenuEvent* event) override;
void refreshMessages();

protected:
void resizeEvent(QResizeEvent* event) override;

signals:
void error(QString);
void info(QString);
Expand Down
2 changes: 2 additions & 0 deletions octproz_project/octproz/src/octproz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ void OCTproZ::updateSettingsMap() {

//message console
this->mainWindowSettings.insert(MESSAGE_CONSOLE_BOTTOM, this->console->getParams().newestMessageAtBottom);
this->mainWindowSettings.insert(MESSAGE_CONSOLE_HEIGHT, this->console->getParams().preferredHeight);
}

void OCTproZ::loadResamplingCurveFromFile(QString fileName){
Expand Down Expand Up @@ -1024,6 +1025,7 @@ void OCTproZ::loadMainWindowSettings(){

MessageConsoleParams consoleParams;
consoleParams.newestMessageAtBottom = this->mainWindowSettings.value(MESSAGE_CONSOLE_BOTTOM).toBool();
consoleParams.preferredHeight = this->mainWindowSettings.value(MESSAGE_CONSOLE_HEIGHT).toInt();
this->console->setParams(consoleParams);
}

Expand Down
1 change: 1 addition & 0 deletions octproz_project/octproz/src/octproz.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define MAIN_STATE "main_state"
#define MAIN_ACTIVE_SYSTEM "main_active_system"
#define MESSAGE_CONSOLE_BOTTOM "message_console_bottom"
#define MESSAGE_CONSOLE_HEIGHT "message_console_height"



Expand Down
Loading

0 comments on commit 094df9e

Please sign in to comment.