1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -05:00

Merge pull request #1601 from srcejon/autostack_fix_wide_channels_on_start

Autostack: Fix channel windows being made to wide when SDRangel starts
This commit is contained in:
Edouard Griffiths 2023-02-17 17:36:03 +01:00 committed by GitHub
commit 79030198d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -49,7 +49,8 @@ Workspace::Workspace(int index, QWidget *parent, Qt::WindowFlags flags) :
m_featureAddDialog(this), m_featureAddDialog(this),
m_stacking(false), m_stacking(false),
m_autoStack(false), m_autoStack(false),
m_userChannelMinWidth(0) m_userChannelMinWidth(0),
m_autoStackChannelMinWidth(0)
{ {
m_mdi = new QMdiArea(this); m_mdi = new QMdiArea(this);
m_mdi->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); m_mdi->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
@ -692,7 +693,7 @@ void Workspace::stackSubWindows()
} }
// Calculate width & height needed for channels // Calculate width & height needed for channels
int channelMinWidth = m_userChannelMinWidth; // channels.size() > 0 ? m_userChannelMinWidth : 0; int channelMinWidth = m_userChannelMinWidth;
int channelTotalMinHeight = 0; int channelTotalMinHeight = 0;
int expandingChannels = 0; int expandingChannels = 0;
for (auto window : channels) for (auto window : channels)
@ -756,6 +757,8 @@ void Workspace::stackSubWindows()
if ((spectrumFeaturesMinWidth == 0) && expandingChannels > 0) { if ((spectrumFeaturesMinWidth == 0) && expandingChannels > 0) {
channelMinWidth = mdiSize.width() - devicesFeaturesWidth - spacing1; channelMinWidth = mdiSize.width() - devicesFeaturesWidth - spacing1;
} }
// Save min width, for use in resize event handling
m_autoStackChannelMinWidth = channelMinWidth;
// Now position the windows // Now position the windows
int x = 0; int x = 0;
@ -1022,6 +1025,9 @@ bool Workspace::eventFilter(QObject *obj, QEvent *event)
} }
else if (event->type() == QEvent::Resize) else if (event->type() == QEvent::Resize)
{ {
// We try to use m_stacking to ignore resize event as the result of a resize called in stackSubWindows
// However, this isn't reliable, as sometimes the resize event arrives after stackSubWindows has finished, and so m_stacking has been cleared
// What is a better way of doing this?
if (!m_stacking && m_autoStack) if (!m_stacking && m_autoStack)
{ {
QWidget *widget = qobject_cast<QWidget *>(obj); QWidget *widget = qobject_cast<QWidget *>(obj);
@ -1033,10 +1039,14 @@ bool Workspace::eventFilter(QObject *obj, QEvent *event)
// but we can tell as window size matches mdi size // but we can tell as window size matches mdi size
if (m_mdi->size() != resizeEvent->size()) if (m_mdi->size() != resizeEvent->size())
{ {
// Allow width of channels column to be set by user when they // Allow width of channels column to be set by user when they resize a channel window
// resize a channel window // We use m_autoStackChannelMinWidth to indicate the width was set by stackSubWindows, rather than the user
m_userChannelMinWidth = resizeEvent->size().width(); int width = resizeEvent->size().width();
stackSubWindows(); if (width != m_autoStackChannelMinWidth)
{
m_userChannelMinWidth = width;
stackSubWindows();
}
} }
} }
} }
@ -1115,3 +1125,4 @@ void Workspace::adjustSubWindowsAfterRestore()
} }
} }
} }

View File

@ -95,6 +95,7 @@ private:
bool m_stacking; // Set when stackSubWindows() is running bool m_stacking; // Set when stackSubWindows() is running
bool m_autoStack; // Automatically stack bool m_autoStack; // Automatically stack
int m_userChannelMinWidth; // Minimum width of channels column for stackSubWindows(), set by user resizing a channel window int m_userChannelMinWidth; // Minimum width of channels column for stackSubWindows(), set by user resizing a channel window
int m_autoStackChannelMinWidth; // Width of channel requested by stackSubWindows()
void unmaximizeSubWindows(); void unmaximizeSubWindows();