mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-17 12:37:46 -07:00
[VDD] Fix minimum size by adding a compact mode to quickSettingsButtons (#6890)
* [VDD] Fix minimum size by adding a compact mode to quickSettingsButtons Took 17 minutes Took 5 seconds * Fix and use FlowWidget/FlowLayout Took 35 minutes Took 4 seconds * Set spacings. Took 12 minutes * Make VDE tools flow Took 1 hour 23 minutes Took 5 seconds * Squeeze and flow even more. Took 11 minutes * Make pushbutton compact. Took 54 minutes Took 7 seconds --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
762e742be0
commit
7153f7d4c1
21 changed files with 666 additions and 617 deletions
|
|
@ -0,0 +1,73 @@
|
|||
#include "compact_push_button.h"
|
||||
|
||||
CompactPushButton::CompactPushButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
setCheckable(true);
|
||||
setFixedHeight(32);
|
||||
|
||||
// default sizing
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
|
||||
connect(this, &QPushButton::clicked, this, [] {
|
||||
// your popup logic here
|
||||
});
|
||||
}
|
||||
|
||||
void CompactPushButton::setButtonText(const QString &text)
|
||||
{
|
||||
fullText = text;
|
||||
|
||||
if (!compact) {
|
||||
setText(fullText);
|
||||
}
|
||||
|
||||
updateGeometryState();
|
||||
}
|
||||
|
||||
void CompactPushButton::setButtonIcon(const QIcon &icon)
|
||||
{
|
||||
setIcon(icon);
|
||||
}
|
||||
|
||||
void CompactPushButton::setCompact(bool enabled)
|
||||
{
|
||||
compact = enabled;
|
||||
|
||||
if (compact) {
|
||||
setText(QString()); // icon only
|
||||
} else {
|
||||
setText(fullText);
|
||||
}
|
||||
|
||||
updateGeometryState();
|
||||
}
|
||||
|
||||
void CompactPushButton::updateGeometryState()
|
||||
{
|
||||
const int buttonHeight = 32;
|
||||
|
||||
setMinimumHeight(buttonHeight);
|
||||
setMaximumHeight(buttonHeight);
|
||||
|
||||
if (compact) {
|
||||
setMinimumWidth(buttonHeight);
|
||||
setMaximumWidth(buttonHeight);
|
||||
} else {
|
||||
setMinimumWidth(0);
|
||||
setMaximumWidth(QWIDGETSIZE_MAX);
|
||||
}
|
||||
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
int CompactPushButton::expandedWidth() const
|
||||
{
|
||||
QFontMetrics fm(font());
|
||||
|
||||
return fm.horizontalAdvance(fullText) + 48; // icon + padding
|
||||
}
|
||||
|
||||
int CompactPushButton::compactWidth() const
|
||||
{
|
||||
return 32;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef COCKATRICE_COMPACT_PUSH_BUTTON_H
|
||||
#define COCKATRICE_COMPACT_PUSH_BUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class CompactPushButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CompactPushButton(QWidget *parent = nullptr);
|
||||
|
||||
void setButtonText(const QString &text);
|
||||
|
||||
void setButtonIcon(const QIcon &icon);
|
||||
|
||||
void setCompact(bool enabled);
|
||||
|
||||
int expandedWidth() const;
|
||||
|
||||
int compactWidth() const;
|
||||
|
||||
private:
|
||||
void updateGeometryState();
|
||||
|
||||
private:
|
||||
QString fullText;
|
||||
bool compact = false;
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_COMPACT_PUSH_BUTTON_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue