Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window arrangement #1541

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sdrbase/settings/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ QByteArray Configuration::serialize() const
s.writeBool(301 + i, m_workspaceAutoStackOptions[i]);
}

nitems = m_workspaceTabSubWindowsOptions.size() < 99 ? m_workspaceTabSubWindowsOptions.size() : 99;
s.writeS32(400, nitems);

for (int i = 0; i < nitems; i++) {
s.writeBool(401 + i, m_workspaceTabSubWindowsOptions[i]);
}

return s.final();
}

Expand Down Expand Up @@ -113,6 +120,14 @@ bool Configuration::deserialize(const QByteArray& data)
d.readBool(301 + i, &m_workspaceAutoStackOptions.back());
}

d.readS32(400, &nitems, 0);

for (int i = 0; i < nitems; i++)
{
m_workspaceTabSubWindowsOptions.push_back(true);
d.readBool(401 + i, &m_workspaceTabSubWindowsOptions.back());
}

return true;
}
else
Expand All @@ -128,4 +143,5 @@ void Configuration::clearData()
m_featureSetPreset.clearFeatures();
m_workspaceGeometries.clear();
m_workspaceAutoStackOptions.clear();
m_workspaceTabSubWindowsOptions.clear();
}
3 changes: 3 additions & 0 deletions sdrbase/settings/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class SDRBASE_API Configuration {
const QList<QByteArray>& getWorkspaceGeometries() const { return m_workspaceGeometries; }
QList<bool>& getWorkspaceAutoStackOptions() { return m_workspaceAutoStackOptions; }
const QList<bool>& getWorkspaceAutoStackOptions() const { return m_workspaceAutoStackOptions; }
QList<bool>& getWorkspaceTabSubWindowsOptions() { return m_workspaceTabSubWindowsOptions; }
const QList<bool>& getWorkspaceTabSubWindowsOptions() const { return m_workspaceTabSubWindowsOptions; }
FeatureSetPreset& getFeatureSetPreset() { return m_featureSetPreset; }
const FeatureSetPreset& getFeatureSetPreset() const { return m_featureSetPreset; }
QList<Preset>& getDeviceSetPresets() { return m_deviceSetPresets; }
Expand All @@ -76,6 +78,7 @@ class SDRBASE_API Configuration {
QString m_description;
QList<QByteArray> m_workspaceGeometries;
QList<bool> m_workspaceAutoStackOptions;
QList<bool> m_workspaceTabSubWindowsOptions;
FeatureSetPreset m_featureSetPreset;
QList<Preset> m_deviceSetPresets;
};
Expand Down
62 changes: 50 additions & 12 deletions sdrgui/channel/channelgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
#include <QObjectCleanupHandler>
#include <QDesktopServices>
#include <QOpenGLWidget>
#include <QMdiArea>

#include "mainwindow.h"
#include "gui/workspaceselectiondialog.h"
#include "gui/devicesetselectiondialog.h"
#include "gui/rollupcontents.h"
#include "gui/dialogpositioner.h"

#include "channelgui.h"

Expand All @@ -42,7 +44,8 @@ ChannelGUI::ChannelGUI(QWidget *parent) :
m_contextMenuType(ContextMenuNone),
m_drag(false),
m_resizer(this),
m_disableResize(false)
m_disableResize(false),
m_mdi(nullptr)
{
qDebug("ChannelGUI::ChannelGUI");
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
Expand Down Expand Up @@ -92,7 +95,7 @@ ChannelGUI::ChannelGUI(QWidget *parent) :
m_maximizeButton->setFixedSize(20, 20);
QIcon maximizeIcon(":/maximize.png");
m_maximizeButton->setIcon(maximizeIcon);
m_maximizeButton->setToolTip("Adjust window to maximum size");
m_maximizeButton->setToolTip("Adjust window to maximum size in workspace");

m_hideButton = new QPushButton();
m_hideButton->setFixedSize(20, 20);
Expand Down Expand Up @@ -311,7 +314,9 @@ void ChannelGUI::onWidgetRolled(QWidget *widget, bool show)
// onWidgetRolled being called twice.
// We need to make sure we don't save widget heights while this occurs. The
// window manager will take care of maximizing/restoring the window size.
if (!m_disableResize)
// We do need to resize when a widget is rolled up, but we also need to avoid
// resizing when a window is maximized when first shown in tabbed layout
if (!m_disableResize && !isMaximized())
{
if (show)
{
Expand Down Expand Up @@ -379,6 +384,9 @@ void ChannelGUI::sizeToContents()
size.setHeight(size.height() + getAdditionalHeight());
size.setWidth(size.width() + m_resizer.m_gripSize * 2);
setMinimumSize(size);

// Restrict size of window to size of desktop
DialogPositioner::sizeToDesktop(this);
}

void ChannelGUI::duplicateChannel()
Expand All @@ -398,24 +406,54 @@ void ChannelGUI::openMoveToDeviceSetDialog()

void ChannelGUI::maximizeWindow()
{
m_disableResize = true;
showMaximized();
m_disableResize = false;
// QOpenGLWidget widgets don't always paint properly first time after being maximized,
// so force an update. Should really fix why they aren't painted properly in the first place
QList<QOpenGLWidget *> widgets = findChildren<QOpenGLWidget *>();
for (auto widget : widgets) {
widget->update();
// If maximize is pressed when maximized, go full screen
if (isMaximized())
{
m_mdi = mdiArea();
if (m_mdi) {
m_mdi->removeSubWindow(this);
}
showNormal(); // If we don't go back to normal first, window doesn't get bigger
showFullScreen();
m_shrinkButton->setToolTip("Adjust window to maximum size in workspace");
}
else
{
m_disableResize = true;
showMaximized();
m_shrinkButton->setToolTip("Restore window to normal");
m_maximizeButton->setToolTip("Make window full screen");
m_disableResize = false;
// QOpenGLWidget widgets don't always paint properly first time after being maximized,
// so force an update. Should really fix why they aren't painted properly in the first place
QList<QOpenGLWidget *> widgets = findChildren<QOpenGLWidget *>();
for (auto widget : widgets) {
widget->update();
}
}
}

void ChannelGUI::shrinkWindow()
{
qDebug("ChannelGUI::shrinkWindow");
if (isMaximized())
// If m_normalParentWidget, window was made full screen
if (m_mdi)
{
m_disableResize = true;
showNormal();
m_mdi->addSubWindow(this);
show();
showMaximized();
m_shrinkButton->setToolTip("Restore window to normal");
m_disableResize = false;
m_mdi = nullptr;
}
else if (isMaximized())
{
m_disableResize = true;
showNormal();
m_shrinkButton->setToolTip("Adjust window to minimum size");
m_maximizeButton->setToolTip("Adjust window to maximum size in workspace");
m_disableResize = false;
}
else
Expand Down
1 change: 1 addition & 0 deletions sdrgui/channel/channelgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ protected slots:
QMap<QWidget*, int> m_heightsMap;
FramelessWindowResizer m_resizer;
bool m_disableResize;
QMdiArea *m_mdi; // Saved pointer to MDI when in full screen mode

private slots:
void activateSettingsDialog();
Expand Down
3 changes: 2 additions & 1 deletion sdrgui/device/devicegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ DeviceGUI::DeviceGUI(QWidget *parent) :
m_topLayout->addWidget(m_maximizeButton);
m_topLayout->addWidget(m_closeButton);

m_centerLayout = new QHBoxLayout();
m_centerLayout = new QVBoxLayout();
m_centerLayout->setContentsMargins(0, 0, 0, 0);
m_contents = new QWidget(); // Do not delete! Done in child's destructor with "delete ui"
m_centerLayout->addWidget(m_contents);
Expand Down Expand Up @@ -412,6 +412,7 @@ void DeviceGUI::deviceSetPresetsDialog()

void DeviceGUI::setTitle(const QString& title)
{
setWindowTitle(title + " Device");
m_titleLabel->setText(title);
}

Expand Down
5 changes: 3 additions & 2 deletions sdrgui/device/devicegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QString>
#include <QByteArray>
#include <QWidget>
#include <QLabel>

#include "gui/channeladddialog.h"
#include "gui/framelesswindowresizer.h"
Expand All @@ -32,7 +33,6 @@
class QCloseEvent;
class Message;
class MessageQueue;
class QLabel;
class QPushButton;
class QVBoxLayout;
class QHBoxLayout;
Expand Down Expand Up @@ -87,6 +87,7 @@ class SDRGUI_API DeviceGUI : public QMdiSubWindow {
void mouseMoveEvent(QMouseEvent* event) override;
void resetContextMenuType() { m_contextMenuType = ContextMenuNone; }
int getAdditionalHeight() const { return 22 + 22; }
void setStatus(const QString &status) { m_statusLabel->setText(status); }

DeviceUISet* m_deviceUISet;
DeviceType m_deviceType;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected slots:
QLabel *m_statusLabel;
QVBoxLayout *m_layouts;
QHBoxLayout *m_topLayout;
QHBoxLayout *m_centerLayout;
QVBoxLayout *m_centerLayout;
QHBoxLayout *m_bottomLayout;
QSizeGrip *m_sizeGripBottomRight;
bool m_drag;
Expand Down
57 changes: 45 additions & 12 deletions sdrgui/feature/featuregui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QObjectCleanupHandler>
#include <QDesktopServices>
#include <QOpenGLWidget>
#include <QMdiArea>

#include "mainwindow.h"
#include "gui/workspaceselectiondialog.h"
Expand All @@ -37,7 +38,8 @@ FeatureGUI::FeatureGUI(QWidget *parent) :
m_contextMenuType(ContextMenuNone),
m_drag(false),
m_resizer(this),
m_disableResize(false)
m_disableResize(false),
m_mdi(nullptr)
{
qDebug("FeatureGUI::FeatureGUI");
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
Expand Down Expand Up @@ -87,7 +89,7 @@ FeatureGUI::FeatureGUI(QWidget *parent) :
m_maximizeButton->setFixedSize(20, 20);
QIcon maximizeIcon(":/maximize.png");
m_maximizeButton->setIcon(maximizeIcon);
m_maximizeButton->setToolTip("Adjust window to maximum size");
m_maximizeButton->setToolTip("Adjust window to maximum size in workspace");

m_closeButton = new QPushButton();
m_closeButton->setFixedSize(20, 20);
Expand Down Expand Up @@ -264,7 +266,9 @@ void FeatureGUI::onWidgetRolled(QWidget *widget, bool show)
// onWidgetRolled being called twice.
// We need to make sure we don't save widget heights while this occurs. The
// window manager will take care of maximizing/restoring the window size.
if (!m_disableResize)
// We do need to resize when a widget is rolled up, but we also need to avoid
// resizing when a window is maximized when first shown in tabbed layout
if (!m_disableResize && !isMaximized())
{
if (show)
{
Expand Down Expand Up @@ -336,24 +340,53 @@ void FeatureGUI::sizeToContents()

void FeatureGUI::maximizeWindow()
{
m_disableResize = true;
showMaximized();
m_disableResize = false;
// QOpenGLWidget widgets don't always paint properly first time after being maximized,
// so force an update. Should really fix why they aren't painted properly in the first place
QList<QOpenGLWidget *> widgets = findChildren<QOpenGLWidget *>();
for (auto widget : widgets) {
widget->update();
// If maximize is pressed when maximized, go full screen
if (isMaximized())
{
m_mdi = mdiArea();
if (m_mdi) {
m_mdi->removeSubWindow(this);
}
showNormal(); // If we don't go back to normal first, window doesn't get bigger
showFullScreen();
m_shrinkButton->setToolTip("Adjust window to maximum size in workspace");
}
else
{
m_disableResize = true;
showMaximized();
m_shrinkButton->setToolTip("Restore window to normal");
m_maximizeButton->setToolTip("Make window full screen");
m_disableResize = false;
// QOpenGLWidget widgets don't always paint properly first time after being maximized,
// so force an update. Should really fix why they aren't painted properly in the first place
QList<QOpenGLWidget *> widgets = findChildren<QOpenGLWidget *>();
for (auto widget : widgets) {
widget->update();
}
}
}

void FeatureGUI::shrinkWindow()
{
qDebug("FeatureGUI::shrinkWindow");
if (isMaximized())
if (m_mdi)
{
m_disableResize = true;
showNormal();
m_mdi->addSubWindow(this);
show();
showMaximized();
m_shrinkButton->setToolTip("Restore window to normal");
m_disableResize = false;
m_mdi = nullptr;
}
else if (isMaximized())
{
m_disableResize = true;
showNormal();
m_shrinkButton->setToolTip("Adjust window to minimum size");
m_maximizeButton->setToolTip("Adjust window to maximum size in workspace");
m_disableResize = false;
}
else
Expand Down
1 change: 1 addition & 0 deletions sdrgui/feature/featuregui.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected slots:
QMap<QWidget*, int> m_heightsMap;
FramelessWindowResizer m_resizer;
bool m_disableResize;
QMdiArea *m_mdi; // Saved pointer to MDI when in full screen mode

private slots:
void activateSettingsDialog();
Expand Down
Loading