Overhaul quick settings for VDS and PrintingSelector (#5602)

* Move show folders option next to the search bar.

* Add a new settings button and settings popup, move the folder visibility checkbox there and the ability to hide tags.

* Make popup not close when interacting with child widgets.

* Fix mocks.

* Include cog icon.

* Move PrintingSelector Display options to new quick settings widget.

* Adjust size before first show so as to not overflow.

* Add option to hide card size slider in VDS.

* Qt5 support.

* Fix some warnings by containerizing layouts because addChildLayout is silly.

* Fix an incorrect slot/signal assignment.

* Correct sub-categories for settings to persist them.

* Shuffle some slots and signals around to distinguish between the tag filter and the tags on the deck preview widgets.

* Add a quick setting to draw unused color identities and center them.

* Respect the setting on startup.

* Move card size slider to the quick settings menu.

* Move PrintingSelector card size slider to quick menu, adjust other layout from other options.

* Improve layout, add a gray border.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-02-10 17:50:08 +01:00 committed by GitHub
parent d1102939a2
commit 7c9bf75393
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 413 additions and 409 deletions

View file

@ -0,0 +1,80 @@
#include "settings_button_widget.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QScreen>
SettingsButtonWidget::SettingsButtonWidget(QWidget *parent)
: QWidget(parent), button(new QToolButton(this)), popup(new SettingsPopupWidget(this))
{
button->setIcon(QPixmap("theme:icons/cogwheel"));
button->setCheckable(true);
button->setFixedSize(32, 32);
connect(button, &QToolButton::clicked, this, &SettingsButtonWidget::togglePopup);
connect(popup, &SettingsPopupWidget::aboutToClose, this, &SettingsButtonWidget::onPopupClosed);
layout = new QHBoxLayout(this);
layout->addWidget(button);
layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout);
}
void SettingsButtonWidget::addSettingsWidget(QWidget *toAdd) const
{
popup->addSettingsWidget(toAdd);
}
void SettingsButtonWidget::togglePopup()
{
if (popup->isVisible()) {
popup->close();
} else {
// Ensure popup size is known before positioning
popup->adjustSize();
QSize popupSize = popup->size();
// Get button position
QPoint buttonGlobalPos = button->mapToGlobal(QPoint(0, button->height()));
// Get screen geometry
QScreen *screen = QApplication::screenAt(buttonGlobalPos);
QRect screenGeom = screen ? screen->availableGeometry() : QApplication::primaryScreen()->availableGeometry();
int x = buttonGlobalPos.x();
int y = buttonGlobalPos.y();
// Adjust X position if popup overflows the right side of the screen
if (x + popupSize.width() > screenGeom.right()) {
x = buttonGlobalPos.x() - popupSize.width() + button->width(); // Move left
}
// Adjust Y position if popup overflows the bottom of the screen
if (y + popupSize.height() > screenGeom.bottom()) {
y = buttonGlobalPos.y() - popupSize.height() - button->height(); // Move up
}
popup->move(x, y);
popup->show();
popup->setFocus();
button->setChecked(true); // Ensure button is checked when popup is visible
}
}
void SettingsButtonWidget::onPopupClosed() const
{
button->setChecked(false); // Ensure button unchecks when popup closes
}
void SettingsButtonWidget::mousePressEvent(QMouseEvent *event)
{
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
if (popup->isVisible() && !popup->geometry().contains(event->globalPosition().toPoint())) {
#else
if (popup->isVisible() && !popup->geometry().contains(event->globalPos())) {
#endif
popup->close();
}
QWidget::mousePressEvent(event);
}

View file

@ -0,0 +1,30 @@
#ifndef SETTINGS_BUTTON_WIDGET_H
#define SETTINGS_BUTTON_WIDGET_H
#include "settings_popup_widget.h"
#include <QToolButton>
#include <QWidget>
class SettingsButtonWidget : public QWidget
{
Q_OBJECT
public:
explicit SettingsButtonWidget(QWidget *parent = nullptr);
void addSettingsWidget(QWidget *toAdd) const;
protected:
void mousePressEvent(QMouseEvent *event) override;
private slots:
void togglePopup();
void onPopupClosed() const;
private:
QHBoxLayout *layout;
QToolButton *button;
SettingsPopupWidget *popup;
};
#endif // SETTINGS_BUTTON_WIDGET_H

View file

@ -0,0 +1,37 @@
#include "settings_popup_widget.h"
#include <QApplication>
#include <QFocusEvent>
#include <QPainter>
SettingsPopupWidget::SettingsPopupWidget(QWidget *parent) : QWidget(parent, Qt::Popup | Qt::FramelessWindowHint)
{
layout = new QVBoxLayout(this);
}
void SettingsPopupWidget::addSettingsWidget(QWidget *toAdd) const
{
layout->addWidget(toAdd);
}
void SettingsPopupWidget::focusOutEvent(QFocusEvent *event)
{
if (!this->isAncestorOf(QApplication::focusWidget())) {
close();
}
QWidget::focusOutEvent(event);
}
void SettingsPopupWidget::closeEvent(QCloseEvent *event)
{
emit aboutToClose();
QWidget::closeEvent(event);
}
void SettingsPopupWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::gray);
painter.drawRect(rect().adjusted(0, 0, -1, -1));
QWidget::paintEvent(event);
}

View file

@ -0,0 +1,27 @@
#ifndef SETTINGS_POPUP_WIDGET_H
#define SETTINGS_POPUP_WIDGET_H
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
class SettingsPopupWidget : public QWidget
{
Q_OBJECT
public:
explicit SettingsPopupWidget(QWidget *parent = nullptr);
void addSettingsWidget(QWidget *toAdd) const;
signals:
void aboutToClose();
protected:
void focusOutEvent(QFocusEvent *event) override;
void closeEvent(QCloseEvent *event) override;
void paintEvent(QPaintEvent *event) override;
QVBoxLayout *layout;
};
#endif // SETTINGSPOPUP_H