mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -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
|
|
@ -327,6 +327,8 @@ set(cockatrice_SOURCES
|
||||||
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_bracket_navigation_widget.h
|
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_bracket_navigation_widget.h
|
||||||
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.cpp
|
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.cpp
|
||||||
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.h
|
src/interface/widgets/tabs/api/edhrec/display/commander/edhrec_commander_api_response_budget_navigation_widget.h
|
||||||
|
src/interface/widgets/utility/compact_push_button.cpp
|
||||||
|
src/interface/widgets/utility/compact_push_button.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(sounds)
|
add_subdirectory(sounds)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -72,7 +72,7 @@ VisualDeckDisplayOptionsWidget::VisualDeckDisplayOptionsWidget(QWidget *parent)
|
||||||
sortCriteriaButton->addSettingsWidget(sortLabel);
|
sortCriteriaButton->addSettingsWidget(sortLabel);
|
||||||
sortCriteriaButton->addSettingsWidget(sortByListWidget);
|
sortCriteriaButton->addSettingsWidget(sortByListWidget);
|
||||||
|
|
||||||
displayTypeButton = new QPushButton(this);
|
displayTypeButton = new CompactPushButton(this);
|
||||||
connect(displayTypeButton, &QPushButton::clicked, this, &VisualDeckDisplayOptionsWidget::updateDisplayType);
|
connect(displayTypeButton, &QPushButton::clicked, this, &VisualDeckDisplayOptionsWidget::updateDisplayType);
|
||||||
|
|
||||||
groupAndSortLayout->addWidget(groupByLabel);
|
groupAndSortLayout->addWidget(groupByLabel);
|
||||||
|
|
@ -91,7 +91,8 @@ void VisualDeckDisplayOptionsWidget::retranslateUi()
|
||||||
sortByLabel->setText(tr("Sort by:"));
|
sortByLabel->setText(tr("Sort by:"));
|
||||||
sortLabel->setText(tr("Click and drag to change the sort order within the groups"));
|
sortLabel->setText(tr("Click and drag to change the sort order within the groups"));
|
||||||
sortCriteriaButton->setToolTip(tr("Configure how cards are sorted within their groups"));
|
sortCriteriaButton->setToolTip(tr("Configure how cards are sorted within their groups"));
|
||||||
displayTypeButton->setText(tr("Toggle Layout: Overlap"));
|
displayTypeButton->setButtonText(tr("Toggle Layout: Overlap"));
|
||||||
|
displayTypeButton->setButtonIcon(QPixmap("theme:icons/scales"));
|
||||||
displayTypeButton->setToolTip(
|
displayTypeButton->setToolTip(
|
||||||
tr("Change how cards are displayed within zones (i.e. overlapped or fully visible.)"));
|
tr("Change how cards are displayed within zones (i.e. overlapped or fully visible.)"));
|
||||||
}
|
}
|
||||||
|
|
@ -115,11 +116,32 @@ void VisualDeckDisplayOptionsWidget::updateDisplayType()
|
||||||
// Update UI and emit signal
|
// Update UI and emit signal
|
||||||
switch (currentDisplayType) {
|
switch (currentDisplayType) {
|
||||||
case DisplayType::Flat:
|
case DisplayType::Flat:
|
||||||
displayTypeButton->setText(tr("Toggle Layout: Flat"));
|
displayTypeButton->setButtonText(tr("Toggle Layout: Flat"));
|
||||||
|
displayTypeButton->setButtonIcon(QPixmap("theme:icons/scroll"));
|
||||||
break;
|
break;
|
||||||
case DisplayType::Overlap:
|
case DisplayType::Overlap:
|
||||||
displayTypeButton->setText(tr("Toggle Layout: Overlap"));
|
displayTypeButton->setButtonText(tr("Toggle Layout: Overlap"));
|
||||||
|
displayTypeButton->setButtonIcon(QPixmap("theme:icons/scales"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emit displayTypeChanged(currentDisplayType);
|
emit displayTypeChanged(currentDisplayType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDeckDisplayOptionsWidget::updateCompactMode(bool mode)
|
||||||
|
{
|
||||||
|
displayTypeButton->setCompact(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int VisualDeckDisplayOptionsWidget::expandedWidth() const
|
||||||
|
{
|
||||||
|
return groupByLabel->sizeHint().width() + groupByComboBox->sizeHint().width() + sortByLabel->sizeHint().width() +
|
||||||
|
sortCriteriaButton->sizeHint().width() + displayTypeButton->expandedWidth() +
|
||||||
|
(groupAndSortLayout->spacing() * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
int VisualDeckDisplayOptionsWidget::compactWidth() const
|
||||||
|
{
|
||||||
|
return groupByLabel->sizeHint().width() + groupByComboBox->sizeHint().width() + sortByLabel->sizeHint().width() +
|
||||||
|
sortCriteriaButton->sizeHint().width() + displayTypeButton->compactWidth() +
|
||||||
|
(groupAndSortLayout->spacing() * 4);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ public slots:
|
||||||
* Called when the application language changes.
|
* Called when the application language changes.
|
||||||
*/
|
*/
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
void updateCompactMode(bool mode);
|
||||||
|
int expandedWidth() const;
|
||||||
|
int compactWidth() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -108,7 +111,7 @@ private:
|
||||||
DisplayType currentDisplayType = DisplayType::Overlap;
|
DisplayType currentDisplayType = DisplayType::Overlap;
|
||||||
|
|
||||||
/// Button used to toggle the display layout.
|
/// Button used to toggle the display layout.
|
||||||
QPushButton *displayTypeButton;
|
CompactPushButton *displayTypeButton;
|
||||||
|
|
||||||
/// Label for the group-by selector.
|
/// Label for the group-by selector.
|
||||||
QLabel *groupByLabel;
|
QLabel *groupByLabel;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include "../general/layout_containers/flow_widget.h"
|
#include "../general/layout_containers/flow_widget.h"
|
||||||
#include "../tabs/visual_deck_editor/tab_deck_editor_visual.h"
|
#include "../tabs/visual_deck_editor/tab_deck_editor_visual.h"
|
||||||
#include "../tabs/visual_deck_editor/tab_deck_editor_visual_tab_widget.h"
|
#include "../tabs/visual_deck_editor/tab_deck_editor_visual_tab_widget.h"
|
||||||
|
#include "../utility/compact_push_button.h"
|
||||||
#include "visual_deck_display_options_widget.h"
|
#include "visual_deck_display_options_widget.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
|
@ -141,7 +142,8 @@ void VisualDeckEditorWidget::initializeSearchBarAndCompleter()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Search button functionality
|
// Search button functionality
|
||||||
searchPushButton = new QPushButton(searchContainer);
|
searchPushButton = new CompactPushButton(searchContainer);
|
||||||
|
searchPushButton->setButtonIcon(QPixmap("theme:icons/search"));
|
||||||
connect(searchPushButton, &QPushButton::clicked, this, [=, this]() {
|
connect(searchPushButton, &QPushButton::clicked, this, [=, this]() {
|
||||||
ExactCard card = CardDatabaseManager::query()->getCard({searchBar->text()});
|
ExactCard card = CardDatabaseManager::query()->getCard({searchBar->text()});
|
||||||
if (card) {
|
if (card) {
|
||||||
|
|
@ -211,7 +213,7 @@ void VisualDeckEditorWidget::connectDeckListModel()
|
||||||
void VisualDeckEditorWidget::retranslateUi()
|
void VisualDeckEditorWidget::retranslateUi()
|
||||||
{
|
{
|
||||||
searchBar->setPlaceholderText(tr("Type a card name here for suggestions from the database..."));
|
searchBar->setPlaceholderText(tr("Type a card name here for suggestions from the database..."));
|
||||||
searchPushButton->setText(tr("Quick search and add card"));
|
searchPushButton->setButtonText(tr("Quick search and add card"));
|
||||||
searchPushButton->setToolTip(tr("Search for closest match in the database (with auto-suggestions) and add "
|
searchPushButton->setToolTip(tr("Search for closest match in the database (with auto-suggestions) and add "
|
||||||
"preferred printing to the deck on pressing enter"));
|
"preferred printing to the deck on pressing enter"));
|
||||||
|
|
||||||
|
|
@ -220,6 +222,44 @@ void VisualDeckEditorWidget::retranslateUi()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
updateCompactMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisualDeckEditorWidget::updateCompactMode()
|
||||||
|
{
|
||||||
|
const int spacing = displayOptionsAndSearch->layout()->spacing();
|
||||||
|
|
||||||
|
const int available = displayOptionsAndSearch->width();
|
||||||
|
|
||||||
|
const int searchExpanded =
|
||||||
|
searchBar->sizeHint().width() + searchPushButton->expandedWidth() + searchLayout->spacing();
|
||||||
|
|
||||||
|
const int fullWidth = displayOptionsWidget->expandedWidth() + spacing + searchExpanded;
|
||||||
|
|
||||||
|
const int displayCompactWidth = displayOptionsWidget->compactWidth() + spacing + searchExpanded;
|
||||||
|
|
||||||
|
// everything expanded
|
||||||
|
if (available >= fullWidth) {
|
||||||
|
displayOptionsWidget->updateCompactMode(false);
|
||||||
|
searchPushButton->setCompact(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only display compact
|
||||||
|
if (available >= displayCompactWidth) {
|
||||||
|
displayOptionsWidget->updateCompactMode(true);
|
||||||
|
searchPushButton->setCompact(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// both compact
|
||||||
|
displayOptionsWidget->updateCompactMode(true);
|
||||||
|
searchPushButton->setCompact(true);
|
||||||
|
}
|
||||||
|
|
||||||
void VisualDeckEditorWidget::updatePlaceholderVisibility()
|
void VisualDeckEditorWidget::updatePlaceholderVisibility()
|
||||||
{
|
{
|
||||||
if (placeholderWidget) {
|
if (placeholderWidget) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../cards/card_size_widget.h"
|
#include "../cards/card_size_widget.h"
|
||||||
#include "../general/layout_containers/overlap_control_widget.h"
|
#include "../general/layout_containers/overlap_control_widget.h"
|
||||||
#include "../quick_settings/settings_button_widget.h"
|
#include "../quick_settings/settings_button_widget.h"
|
||||||
|
#include "../utility/compact_push_button.h"
|
||||||
#include "visual_deck_editor_placeholder_widget.h"
|
#include "visual_deck_editor_placeholder_widget.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
|
@ -39,6 +40,7 @@ class VisualDeckEditorWidget : public QWidget
|
||||||
public:
|
public:
|
||||||
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
|
explicit VisualDeckEditorWidget(QWidget *parent, DeckListModel *deckListModel, QItemSelectionModel *selectionModel);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
void updateCompactMode();
|
||||||
void clearAllDisplayWidgets();
|
void clearAllDisplayWidgets();
|
||||||
|
|
||||||
void setDeckList(const DeckList &_deckListModel);
|
void setDeckList(const DeckList &_deckListModel);
|
||||||
|
|
@ -82,8 +84,11 @@ protected slots:
|
||||||
void onHover(const ExactCard &hoveredCard);
|
void onHover(const ExactCard &hoveredCard);
|
||||||
void onCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
|
void onCardClick(QMouseEvent *event, CardInfoPictureWithTextOverlayWidget *instance, QString zoneName);
|
||||||
void decklistModelReset();
|
void decklistModelReset();
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int expandedWidthAll = -1;
|
||||||
|
int expandedWidthDisplayCompact = -1;
|
||||||
DeckListModel *deckListModel;
|
DeckListModel *deckListModel;
|
||||||
QItemSelectionModel *selectionModel;
|
QItemSelectionModel *selectionModel;
|
||||||
QVBoxLayout *mainLayout;
|
QVBoxLayout *mainLayout;
|
||||||
|
|
@ -95,7 +100,7 @@ private:
|
||||||
QCompleter *completer;
|
QCompleter *completer;
|
||||||
FlowWidget *displayOptionsAndSearch;
|
FlowWidget *displayOptionsAndSearch;
|
||||||
VisualDeckDisplayOptionsWidget *displayOptionsWidget;
|
VisualDeckDisplayOptionsWidget *displayOptionsWidget;
|
||||||
QPushButton *searchPushButton;
|
CompactPushButton *searchPushButton;
|
||||||
QScrollArea *scrollArea;
|
QScrollArea *scrollArea;
|
||||||
QWidget *zoneContainer;
|
QWidget *zoneContainer;
|
||||||
QVBoxLayout *zoneContainerLayout;
|
QVBoxLayout *zoneContainerLayout;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue