mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 13:33:55 -07:00
Make pushbutton compact.
Took 54 minutes Took 7 seconds
This commit is contained in:
parent
5e00d9363d
commit
b3fa19eaba
7 changed files with 184 additions and 8 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue