Comment ALL the things.

This commit is contained in:
Lukas Brübach 2024-12-17 01:14:29 +01:00
parent 03b2253541
commit 6dd14a8832
13 changed files with 505 additions and 58 deletions

View file

@ -2,6 +2,13 @@
#include "../../../../settings/cache_settings.h"
/**
* @class CardSizeWidget
* @brief A widget for adjusting card sizes using a slider.
*
* This widget allows users to dynamically change the card size in a linked FlowWidget
* and updates the application's settings accordingly.
*/
CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defaultValue)
: parent(parent), flowWidget(flowWidget)
{
@ -10,9 +17,10 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defa
cardSizeLabel = new QLabel(tr("Card Size"), this);
cardSizeLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
cardSizeSlider = new QSlider(Qt::Horizontal, this);
cardSizeSlider->setRange(50, 250);
cardSizeSlider->setValue(defaultValue);
cardSizeSlider->setRange(50, 250); ///< Slider range for card size adjustment.
cardSizeSlider->setValue(defaultValue); ///< Initial slider value.
cardSizeLayout->addWidget(cardSizeLabel);
cardSizeLayout->addWidget(cardSizeSlider);
@ -24,11 +32,21 @@ CardSizeWidget::CardSizeWidget(QWidget *parent, FlowWidget *flowWidget, int defa
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardSizeWidget::updateCardSizeSetting);
}
/**
* @brief Updates the card size setting in the application's cache.
*
* @param newValue The new card size value set by the slider.
*/
void CardSizeWidget::updateCardSizeSetting(int newValue)
{
SettingsCache::instance().setPrintingSelectorCardSize(newValue);
}
/**
* @brief Gets the slider widget used for adjusting the card size.
*
* @return A pointer to the QSlider object.
*/
QSlider *CardSizeWidget::getSlider() const
{
return cardSizeSlider;

View file

@ -3,37 +3,61 @@
#include <QPaintEvent>
#include <QPainter>
/**
* @class ShadowBackgroundLabel
* @brief A QLabel with a semi-transparent black shadowed background and rounded corners.
*
* This label provides a styled appearance with centered white text and a translucent
* rounded background, making it suitable for overlay or emphasis in a UI.
*/
ShadowBackgroundLabel::ShadowBackgroundLabel(QWidget *parent, const QString &text) : QLabel(parent)
{
setAttribute(Qt::WA_TranslucentBackground); // Allows transparency
setText("<font color='white'>" + text + "</font>");
setAlignment(Qt::AlignCenter);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setAttribute(Qt::WA_TranslucentBackground); // Allows transparency.
setText("<font color='white'>" + text + "</font>"); ///< Ensures the text is rendered in white.
setAlignment(Qt::AlignCenter); ///< Centers the text within the label.
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); ///< Ensures minimum size constraints.
}
/**
* @brief Handles resizing of the label.
*
* Ensures the label updates its appearance when resized by triggering a repaint.
*
* @param event The resize event containing new size information.
*/
void ShadowBackgroundLabel::resizeEvent(QResizeEvent *event)
{
QLabel::resizeEvent(event);
update(); // Repaint borders explicitly
update(); // Repaint borders explicitly.
}
/**
* @brief Custom paint event for drawing the label's background.
*
* Renders a semi-transparent black rounded rectangle as the background
* and then delegates text rendering to QLabel.
*
* @param event The paint event for the widget.
*/
void ShadowBackgroundLabel::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
// Semi-transparent background
// Enable anti-aliasing for smoother edges.
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(QColor(0, 0, 0, 128)); // Semi-transparent black
painter.setPen(Qt::NoPen); // No border
// Compute the painting rectangle accounting for margins
// Set semi-transparent black brush and disable border pen.
painter.setBrush(QColor(0, 0, 0, 128)); // Semi-transparent black.
painter.setPen(Qt::NoPen); // No border.
// Adjust the rectangle to account for margins.
QRect adjustedRect = this->rect();
int margin = contentsMargins().left(); // Assuming equal margins
int margin = contentsMargins().left(); // Assuming equal margins.
adjustedRect.adjust(margin, margin, -margin, -margin);
// Draw rounded rectangle
painter.drawRoundedRect(adjustedRect, 5, 5); // Rounded corners (radius: 5)
// Draw a rounded rectangle with a corner radius of 5.
painter.drawRoundedRect(adjustedRect, 5, 5);
// Let QLabel handle text rendering
// Delegate text rendering to QLabel.
QLabel::paintEvent(event);
}

View file

@ -1,9 +1,21 @@
#include "all_zones_card_amount_widget.h"
#include "../general/display/shadow_background_label.h"
#include <QTimer>
/**
* @brief Constructor for the AllZonesCardAmountWidget class.
*
* Initializes the widget with its layout and sets up the connections and necessary
* UI elements for managing card counts in both the mainboard and sideboard zones.
*
* @param parent The parent widget.
* @param deckEditor Pointer to the TabDeckEditor.
* @param deckModel Pointer to the DeckListModel.
* @param deckView Pointer to the QTreeView for the deck display.
* @param cardSizeSlider Pointer to the QSlider used for dynamic font resizing.
* @param rootCard The root card for the widget.
* @param setInfoForCard The set information for the card.
*/
AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
TabDeckEditor *deckEditor,
DeckListModel *deckModel,
@ -40,6 +52,14 @@ AllZonesCardAmountWidget::AllZonesCardAmountWidget(QWidget *parent,
setMouseTracking(true);
}
/**
* @brief Adjusts the font size of the zone labels based on the slider value.
*
* This method calculates the new font size as a percentage of the original font size
* based on the slider value and applies it to the zone label text.
*
* @param scalePercentage The scale percentage from the slider.
*/
void AllZonesCardAmountWidget::adjustFontSize(int scalePercentage)
{
const int minFontSize = 8; // Minimum font size
@ -59,16 +79,34 @@ void AllZonesCardAmountWidget::adjustFontSize(int scalePercentage)
repaint();
}
/**
* @brief Gets the card count in the mainboard zone.
*
* @return The number of cards in the mainboard.
*/
int AllZonesCardAmountWidget::getMainboardAmount()
{
return buttonBoxMainboard->countCardsInZone(DECK_ZONE_MAIN);
}
/**
* @brief Gets the card count in the sideboard zone.
*
* @return The number of cards in the sideboard.
*/
int AllZonesCardAmountWidget::getSideboardAmount()
{
return buttonBoxSideboard->countCardsInZone(DECK_ZONE_SIDE);
}
/**
* @brief Handles the event when the mouse enters the widget.
*
* This method is triggered when the mouse enters the widget's area, allowing for updates
* or interactions such as UI feedback or layout changes.
*
* @param event The event information for the mouse entry.
*/
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
void AllZonesCardAmountWidget::enterEvent(QEnterEvent *event)
#else
@ -77,4 +115,4 @@ void AllZonesCardAmountWidget::enterEvent(QEvent *event)
{
QWidget::enterEvent(event);
update();
}
}

View file

@ -1,9 +1,19 @@
#include "card_amount_widget.h"
#include "../general/display/dynamic_font_size_push_button.h"
#include <QTimer>
/**
* @brief Constructs a widget for displaying and controlling the card count in a specific zone.
*
* @param parent The parent widget.
* @param deckEditor Pointer to the TabDeckEditor instance.
* @param deckModel Pointer to the DeckListModel instance.
* @param deckView Pointer to the QTreeView displaying the deck.
* @param cardSizeSlider Pointer to the QSlider for adjusting font size.
* @param rootCard The root card to manage within the widget.
* @param setInfoForCard Card set information for the root card.
* @param zoneName The zone name (e.g., DECK_ZONE_MAIN or DECK_ZONE_SIDE).
*/
CardAmountWidget::CardAmountWidget(QWidget *parent,
TabDeckEditor *deckEditor,
DeckListModel *deckModel,
@ -30,7 +40,7 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
decrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
// Set up connections
// Set up connections based on the zone (Mainboard or Sideboard)
if (zoneName == DECK_ZONE_MAIN) {
connect(incrementButton, &QPushButton::clicked, this, &CardAmountWidget::addPrintingMainboard);
connect(decrementButton, &QPushButton::clicked, this, &CardAmountWidget::removePrintingMainboard);
@ -53,7 +63,7 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
// Connect slider for dynamic font size adjustment
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
// Resize after a little delay since, initially, the parent widget has no size.
// Resize after a little delay to ensure parent size is available
QTimer::singleShot(10, this, [this]() {
adjustFontSize(this->cardSizeSlider->value());
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
@ -62,6 +72,11 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
});
}
/**
* @brief Handles the painting of the widget, drawing a semi-transparent background.
*
* @param event The paint event.
*/
void CardAmountWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
@ -75,11 +90,16 @@ void CardAmountWidget::paintEvent(QPaintEvent *event)
QWidget::paintEvent(event);
}
/**
* @brief Adjusts the font size of the card count label based on the slider value.
*
* @param scalePercentage The percentage value from the slider for scaling the font size.
*/
void CardAmountWidget::adjustFontSize(int scalePercentage)
{
const int minFontSize = 8; // Minimum font size
const int maxFontSize = 32; // Maximum font size
const int basePercentage = 100; // Scale at 100%
const int minFontSize = 8; ///< Minimum font size
const int maxFontSize = 32; ///< Maximum font size
const int basePercentage = 100; ///< Scale at 100%
int newFontSize = minFontSize + (scalePercentage - basePercentage) * (maxFontSize - minFontSize) / (250 - 25);
newFontSize = std::clamp(newFontSize, minFontSize, maxFontSize);
@ -92,10 +112,13 @@ void CardAmountWidget::adjustFontSize(int scalePercentage)
incrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
decrementButton->setFixedSize(parentWidget()->size().width() / 3, parentWidget()->size().height() / 9);
// Repaint the widget (if necessary)
// Repaint the widget
repaint();
}
/**
* @brief Updates the card count display in the widget.
*/
void CardAmountWidget::updateCardCount()
{
cardCountInZone->setText("<font color='white'>" + QString::number(countCardsInZone(zoneName)) + "</font>");
@ -103,6 +126,11 @@ void CardAmountWidget::updateCardCount()
layout->activate();
}
/**
* @brief Adds a printing of the card to the specified zone (Mainboard or Sideboard).
*
* @param zone The zone to add the card to (DECK_ZONE_MAIN or DECK_ZONE_SIDE).
*/
void CardAmountWidget::addPrinting(const QString &zone)
{
auto newCardIndex = deckModel->addCard(rootCard->getName(), setInfoForCard, zone);
@ -123,26 +151,43 @@ void CardAmountWidget::addPrinting(const QString &zone)
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
}
/**
* @brief Adds a printing to the mainboard zone.
*/
void CardAmountWidget::addPrintingMainboard()
{
addPrinting(DECK_ZONE_MAIN);
}
/**
* @brief Adds a printing to the sideboard zone.
*/
void CardAmountWidget::addPrintingSideboard()
{
addPrinting(DECK_ZONE_SIDE);
}
/**
* @brief Removes a printing from the mainboard zone.
*/
void CardAmountWidget::removePrintingMainboard()
{
decrementCardHelper(DECK_ZONE_MAIN);
}
/**
* @brief Removes a printing from the sideboard zone.
*/
void CardAmountWidget::removePrintingSideboard()
{
decrementCardHelper(DECK_ZONE_SIDE);
}
/**
* @brief Recursively expands the card in the deck view starting from the given index.
*
* @param index The model index of the card to expand.
*/
void CardAmountWidget::recursiveExpand(const QModelIndex &index)
{
if (index.parent().isValid()) {
@ -151,6 +196,12 @@ void CardAmountWidget::recursiveExpand(const QModelIndex &index)
deckView->expand(index);
}
/**
* @brief Offsets the card count at the specified index by the given amount.
*
* @param idx The model index of the card.
* @param offset The amount to add or subtract from the card count.
*/
void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
{
if (!idx.isValid() || offset == 0) {
@ -169,6 +220,11 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
deckEditor->setModified(true);
}
/**
* @brief Helper function to decrement the card count for a given zone.
*
* @param zone The zone from which to remove the card (DECK_ZONE_MAIN or DECK_ZONE_SIDE).
*/
void CardAmountWidget::decrementCardHelper(const QString &zone)
{
QModelIndex idx;
@ -177,6 +233,12 @@ void CardAmountWidget::decrementCardHelper(const QString &zone)
offsetCountAtIndex(idx, -1);
}
/**
* @brief Counts the number of cards in a specific zone (mainboard or sideboard).
*
* @param deckZone The name of the zone (e.g., DECK_ZONE_MAIN or DECK_ZONE_SIDE).
* @return The number of cards in the zone.
*/
int CardAmountWidget::countCardsInZone(const QString &deckZone)
{
int count = 0;

View file

@ -9,6 +9,19 @@
#include <QScrollBar>
/**
* @brief Constructs a PrintingSelector widget to display and manage card printings.
*
* This constructor initializes the PrintingSelector widget, setting up various child widgets
* such as sorting tools, search bar, card size options, and navigation controls. It also connects
* signals and slots to update the display when the deck model changes, and loads available printings
* for the selected card.
*
* @param parent The parent widget for the PrintingSelector.
* @param deckEditor The TabDeckEditor instance used for managing the deck.
* @param deckModel The DeckListModel instance that provides data for the deck's contents.
* @param deckView The QTreeView instance used to display the deck and its contents.
*/
PrintingSelector::PrintingSelector(QWidget *parent,
TabDeckEditor *deckEditor,
DeckListModel *deckModel,
@ -20,6 +33,7 @@ PrintingSelector::PrintingSelector(QWidget *parent,
setLayout(layout);
widgetLoadingBufferTimer = new QTimer(this);
// Initialize toolbar and widgets
viewOptionsToolbar = new PrintingSelectorViewOptionsToolbarWidget(this, this);
layout->addWidget(viewOptionsToolbar);
@ -42,12 +56,16 @@ PrintingSelector::PrintingSelector(QWidget *parent,
cardSelectionBar->setVisible(SettingsCache::instance().getPrintingSelectorNavigationButtonsVisible());
layout->addWidget(cardSelectionBar);
// Connect deck model data change signal to update display
connect(deckModel, &DeckListModel::dataChanged, this, [this]() {
// We have to delay this or else we hit a race condition where the data isn't actually updated yet.
// Delay the update to avoid race conditions
QTimer::singleShot(100, this, &PrintingSelector::updateDisplay);
});
}
/**
* @brief Updates the display by clearing the layout and loading new sets for the current card.
*/
void PrintingSelector::updateDisplay()
{
widgetLoadingBufferTimer->stop();
@ -60,6 +78,12 @@ void PrintingSelector::updateDisplay()
getAllSetsForCurrentCard();
}
/**
* @brief Sets the current card for the selector and updates the display.
*
* @param newCard The new card to set.
* @param _currentZone The current zone the card is in.
*/
void PrintingSelector::setCard(const CardInfoPtr &newCard, const QString &_currentZone)
{
if (newCard.isNull()) {
@ -75,16 +99,27 @@ void PrintingSelector::setCard(const CardInfoPtr &newCard, const QString &_curre
flowWidget->repaint();
}
/**
* @brief Selects the previous card in the list.
*/
void PrintingSelector::selectPreviousCard()
{
selectCard(-1);
}
/**
* @brief Selects the next card in the list.
*/
void PrintingSelector::selectNextCard()
{
selectCard(1);
}
/**
* @brief Selects a card based on the change direction.
*
* @param changeBy The direction to change, -1 for previous, 1 for next.
*/
void PrintingSelector::selectCard(int changeBy)
{
if (changeBy == 0) {
@ -116,6 +151,12 @@ void PrintingSelector::selectCard(int changeBy)
}
}
/**
* @brief Retrieves the card set for a specific UUID.
*
* @param uuid The UUID of the set to retrieve.
* @return The CardInfoPerSet associated with the UUID.
*/
CardInfoPerSet PrintingSelector::getSetForUUID(const QString &uuid)
{
CardInfoPerSetMap cardInfoPerSets = selectedCard->getSets();
@ -131,6 +172,9 @@ CardInfoPerSet PrintingSelector::getSetForUUID(const QString &uuid)
return CardInfoPerSet();
}
/**
* @brief Loads and displays all sets for the current selected card.
*/
void PrintingSelector::getAllSetsForCurrentCard()
{
if (selectedCard.isNull()) {
@ -170,21 +214,41 @@ void PrintingSelector::getAllSetsForCurrentCard()
widgetLoadingBufferTimer->start(0); // Process as soon as possible
}
/**
* @brief Toggles the visibility of the sorting options toolbar.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilitySortOptions(bool _state)
{
sortToolBar->setVisible(_state);
}
/**
* @brief Toggles the visibility of the search bar.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilitySearchBar(bool _state)
{
searchBar->setVisible(_state);
}
/**
* @brief Toggles the visibility of the card size slider.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilityCardSizeSlider(bool _state)
{
cardSizeWidget->setVisible(_state);
}
/**
* @brief Toggles the visibility of the navigation buttons.
*
* @param _state The visibility state to set.
*/
void PrintingSelector::toggleVisibilityNavigationButtons(bool _state)
{
cardSelectionBar->setVisible(_state);

View file

@ -10,6 +10,24 @@
#include <QStackedWidget>
#include <QVBoxLayout>
/**
* @brief Constructs a PrintingSelectorCardDisplayWidget to display card information.
*
* This widget is responsible for displaying the selected card's printing information, including
* the card's image and set details. It also handles the layout of the card's display, including
* its size, set name, and collectors number. The card is displayed within a `QVBoxLayout` with
* two main components: the overlay (which combines the card image and buttons) and the set name and collectors number
* display.
*
* @param parent The parent widget for this display.
* @param deckEditor The TabDeckEditor instance for deck management.
* @param deckModel The DeckListModel instance providing deck data.
* @param deckView The QTreeView instance displaying the deck.
* @param cardSizeSlider The slider controlling the size of the displayed card.
* @param rootCard The root card object, representing the card to be displayed.
* @param setInfoForCard The set-specific information for the card being displayed.
* @param currentZone The current zone in which the card is located.
*/
PrintingSelectorCardDisplayWidget::PrintingSelectorCardDisplayWidget(QWidget *parent,
TabDeckEditor *deckEditor,
DeckListModel *deckModel,
@ -25,22 +43,32 @@ PrintingSelectorCardDisplayWidget::PrintingSelectorCardDisplayWidget(QWidget *pa
setLayout(layout);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Create the overlay widget for the card display
overlayWidget = new PrintingSelectorCardOverlayWidget(this, deckEditor, deckModel, deckView, cardSizeSlider,
rootCard, setInfoForCard);
// Create the widget to display the set name and collector's number
const QString combinedSetName =
QString(setInfoForCard.getPtr()->getLongName() + " (" + setInfoForCard.getPtr()->getShortName() + ")");
setNameAndCollectorsNumberDisplayWidget = new SetNameAndCollectorsNumberDisplayWidget(
this, combinedSetName, setInfoForCard.getProperty("num"), cardSizeSlider);
// Add the widgets to the layout
layout->addWidget(overlayWidget, 0, Qt::AlignHCenter);
layout->addWidget(setNameAndCollectorsNumberDisplayWidget, 1, Qt::AlignHCenter | Qt::AlignBottom);
}
/**
* @brief Adjusts the width of the set name display to fit the card overlay widget.
*
* This method ensures that the set name and collector's number display widget does not exceed
* the width of the card's overlay widget. It clamps the set name widget to match the width of
* the overlay widget and updates the display.
*/
void PrintingSelectorCardDisplayWidget::clampSetNameToPicture()
{
if (overlayWidget != nullptr && setNameAndCollectorsNumberDisplayWidget != nullptr) {
setNameAndCollectorsNumberDisplayWidget->setMaximumWidth(overlayWidget->width());
}
update();
}
}

View file

@ -7,6 +7,21 @@
#include <QMouseEvent>
#include <QVBoxLayout>
/**
* @brief Constructs a PrintingSelectorCardOverlayWidget for displaying a card overlay.
*
* This widget is responsible for showing the card's image and providing interactive features such
* as a context menu and the ability to adjust the card's scale. It includes the card's image as well
* as a widget that displays the card amounts in different zones (mainboard, sideboard, etc.).
*
* @param parent The parent widget for this overlay.
* @param deckEditor The TabDeckEditor instance for deck management.
* @param deckModel The DeckListModel instance providing deck data.
* @param deckView The QTreeView instance displaying the deck.
* @param cardSizeSlider The slider controlling the size of the card.
* @param rootCard The root card object that contains information about the card.
* @param setInfoForCard The set-specific information for the card being displayed.
*/
PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *parent,
TabDeckEditor *deckEditor,
DeckListModel *deckModel,
@ -53,6 +68,14 @@ PrintingSelectorCardOverlayWidget::PrintingSelectorCardOverlayWidget(QWidget *pa
connect(cardSizeSlider, &QSlider::valueChanged, cardInfoPicture, &CardInfoPictureWidget::setScaleFactor);
}
/**
* @brief Handles the mouse press event for right-clicks to show the context menu.
*
* If the right mouse button is pressed, a custom context menu will appear. For other mouse buttons,
* the event is passed to the base class for default handling.
*
* @param event The mouse event triggered by the user.
*/
void PrintingSelectorCardOverlayWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
@ -62,6 +85,14 @@ void PrintingSelectorCardOverlayWidget::mousePressEvent(QMouseEvent *event)
}
}
/**
* @brief Resizes the overlay widget to match the card's size.
*
* This method ensures that the amount widget matches the card's size when the overlay widget is resized.
* It also resizes the card info picture widget to match the new size.
*
* @param event The resize event triggered when the widget is resized.
*/
void PrintingSelectorCardOverlayWidget::resizeEvent(QResizeEvent *event)
{
// Ensure the amount widget matches the parent size
@ -72,6 +103,14 @@ void PrintingSelectorCardOverlayWidget::resizeEvent(QResizeEvent *event)
resize(cardInfoPicture->size());
}
/**
* @brief Handles the mouse enter event when the cursor enters the overlay widget area.
*
* When the cursor enters the widget, the card information is updated, and the card amount widget
* is displayed if the amounts are zero for both the mainboard and sideboard.
*
* @param event The event triggered when the mouse enters the widget.
*/
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
void PrintingSelectorCardOverlayWidget::enterEvent(QEnterEvent *event)
#else
@ -91,6 +130,14 @@ void PrintingSelectorCardOverlayWidget::enterEvent(QEvent *event)
allZonesCardAmountWidget->setVisible(true);
}
/**
* @brief Handles the mouse leave event when the cursor leaves the overlay widget area.
*
* When the cursor leaves the widget, the card amount widget is hidden if both the mainboard and sideboard
* amounts are zero.
*
* @param event The event triggered when the mouse leaves the widget.
*/
void PrintingSelectorCardOverlayWidget::leaveEvent(QEvent *event)
{
QWidget::leaveEvent(event);
@ -105,6 +152,15 @@ void PrintingSelectorCardOverlayWidget::leaveEvent(QEvent *event)
allZonesCardAmountWidget->setVisible(false);
}
/**
* @brief Creates and shows a custom context menu when the right mouse button is clicked.
*
* The context menu includes an option to show related cards, which displays a submenu with actions
* for each related card. When an action is triggered, the card information is updated, and the
* printing selector is shown.
*
* @param point The position of the mouse when the right-click occurred.
*/
void PrintingSelectorCardOverlayWidget::customMenu(QPoint point)
{
QMenu menu;

View file

@ -1,5 +1,13 @@
#include "printing_selector_card_search_widget.h"
/**
* @brief Constructs a PrintingSelectorCardSearchWidget for searching cards by set name or set code.
*
* This widget provides a search bar that allows users to search for cards by either their set name
* or set code. It uses a debounced timer to trigger the search action after the user stops typing.
*
* @param parent The parent PrintingSelector widget that will handle the search results.
*/
PrintingSelectorCardSearchWidget::PrintingSelectorCardSearchWidget(PrintingSelector *parent) : parent(parent)
{
layout = new QHBoxLayout(this);
@ -9,7 +17,7 @@ PrintingSelectorCardSearchWidget::PrintingSelectorCardSearchWidget(PrintingSelec
searchBar->setPlaceholderText(tr("Search by set name or set code"));
layout->addWidget(searchBar);
// Add a debounce timer for the search bar
// Add a debounce timer for the search bar to limit frequent updates
searchDebounceTimer = new QTimer(this);
searchDebounceTimer->setSingleShot(true);
connect(searchBar, &QLineEdit::textChanged, this, [this]() {
@ -19,7 +27,12 @@ PrintingSelectorCardSearchWidget::PrintingSelectorCardSearchWidget(PrintingSelec
connect(searchDebounceTimer, &QTimer::timeout, parent, &PrintingSelector::updateDisplay);
}
/**
* @brief Retrieves the current text in the search bar.
*
* @return The text entered by the user in the search bar.
*/
QString PrintingSelectorCardSearchWidget::getSearchText()
{
return searchBar->text();
}
}

View file

@ -1,8 +1,17 @@
#include "printing_selector_card_selection_widget.h"
/**
* @brief Constructs a PrintingSelectorCardSelectionWidget for navigating through cards in the deck.
*
* This widget provides buttons that allow users to navigate between cards in the deck.
* It includes buttons for moving to the previous and next card in the deck.
*
* @param parent The parent PrintingSelector widget responsible for managing card selection.
*/
PrintingSelectorCardSelectionWidget::PrintingSelectorCardSelectionWidget(PrintingSelector *parent) : parent(parent)
{
cardSelectionBarLayout = new QHBoxLayout(this);
previousCardButton = new QPushButton(this);
previousCardButton->setText(tr("Previous Card in Deck"));
@ -15,8 +24,14 @@ PrintingSelectorCardSelectionWidget::PrintingSelectorCardSelectionWidget(Printin
cardSelectionBarLayout->addWidget(nextCardButton);
}
/**
* @brief Connects the signals from the buttons to the appropriate slots in the parent widget.
*
* This method connects the click signals of the previous and next card buttons to
* the selectPreviousCard and selectNextCard slots in the parent PrintingSelector widget.
*/
void PrintingSelectorCardSelectionWidget::connectSignals()
{
connect(previousCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectPreviousCard);
connect(nextCardButton, &QPushButton::clicked, parent, &PrintingSelector::selectNextCard);
}
}

View file

@ -1,18 +1,13 @@
#include "printing_selector_card_sorting_widget.h"
#include "../../../../settings/cache_settings.h"
#include "../../../../utility/card_set_comparator.h"
const QString PrintingSelectorCardSortingWidget::SORT_OPTIONS_ALPHABETICAL = tr("Alphabetical");
const QString PrintingSelectorCardSortingWidget::SORT_OPTIONS_PREFERENCE = tr("Preference");
const QString PrintingSelectorCardSortingWidget::SORT_OPTIONS_RELEASE_DATE = tr("Release Date");
const QString PrintingSelectorCardSortingWidget::SORT_OPTIONS_CONTAINED_IN_DECK = tr("Contained in Deck");
const QString PrintingSelectorCardSortingWidget::SORT_OPTIONS_POTENTIAL_CARDS = tr("Potential Cards in Deck");
const QStringList PrintingSelectorCardSortingWidget::SORT_OPTIONS = {
SORT_OPTIONS_ALPHABETICAL, SORT_OPTIONS_PREFERENCE, SORT_OPTIONS_RELEASE_DATE, SORT_OPTIONS_CONTAINED_IN_DECK,
SORT_OPTIONS_POTENTIAL_CARDS};
/**
* @brief A widget for sorting and filtering card sets in the Printing Selector.
*
* This widget allows users to choose sorting options for the card sets, such as alphabetical order, release date, or
* user-defined preferences. It also allows users to toggle the sorting order between ascending and descending.
*/
PrintingSelectorCardSortingWidget::PrintingSelectorCardSortingWidget(PrintingSelector *parent) : parent(parent)
{
sortToolBar = new QHBoxLayout(this);
@ -32,6 +27,11 @@ PrintingSelectorCardSortingWidget::PrintingSelectorCardSortingWidget(PrintingSel
sortToolBar->addWidget(toggleSortOrder);
}
/**
* @brief Updates the sorting order (ascending or descending).
*
* This function toggles the sort order between ascending and descending and updates the display.
*/
void PrintingSelectorCardSortingWidget::updateSortOrder()
{
if (descendingSort) {
@ -43,11 +43,29 @@ void PrintingSelectorCardSortingWidget::updateSortOrder()
parent->updateDisplay();
}
/**
* @brief Updates the sorting setting in the application settings.
*
* This function saves the selected sorting option (from the combobox) to the application settings.
*/
void PrintingSelectorCardSortingWidget::updateSortSetting()
{
SettingsCache::instance().setPrintingSelectorSortOrder(sortOptionsSelector->currentIndex());
}
/**
* @brief Sorts a list of card sets based on the selected sorting option.
*
* This function sorts the card sets according to the selected sorting option in the combobox. The options include:
* - Alphabetical
* - Preference
* - Release Date
* - Contained in Deck
* - Potential Cards in Deck
*
* @param cardInfoPerSets The list of card sets to be sorted.
* @return A sorted list of card sets.
*/
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(CardInfoPerSetMap cardInfoPerSets)
{
QList<CardSetPtr> sortedSets;
@ -90,6 +108,17 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::sortSets(CardInfoPerSet
return sortedCardInfoPerSets;
}
/**
* @brief Filters a list of card sets based on the search text.
*
* This function filters the given list of card sets by comparing their long and short names with the provided search
* text. If the search text matches either the long or short name of a card set, that set is included in the filtered
* list.
*
* @param sets The list of card sets to be filtered.
* @param searchText The search text used to filter the card sets.
* @return A filtered list of card sets.
*/
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::filterSets(const QList<CardInfoPerSet> &sets,
const QString searchText) const
{
@ -111,6 +140,17 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::filterSets(const QList<
return filteredSets;
}
/**
* @brief Prepend card printings that are contained in the deck to the list of card sets.
*
* This function adjusts the list of card sets by moving the printings that are already contained in the deck to the
* beginning of the list, sorted by the count of cards in the deck.
*
* @param sets The original list of card sets.
* @param selectedCard The currently selected card.
* @param deckModel The model representing the deck.
* @return A list of card sets with the printings contained in the deck prepended.
*/
QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::prependPrintingsInDeck(const QList<CardInfoPerSet> &sets,
CardInfoPtr selectedCard,
DeckListModel *deckModel)
@ -159,4 +199,4 @@ QList<CardInfoPerSet> PrintingSelectorCardSortingWidget::prependPrintingsInDeck(
}
return result;
}
}

View file

@ -4,20 +4,30 @@
#include <QLabel>
#include <QPushButton>
/**
* @class PrintingSelectorViewOptionsToolbarWidget
* @brief A widget that provides a toolbar for view options with collapsible and expandable functionality.
*
* This widget allows the user to collapse or expand the view options for the PrintingSelector,
* providing a more compact interface when collapsed and a full view of options when expanded.
*/
PrintingSelectorViewOptionsToolbarWidget::PrintingSelectorViewOptionsToolbarWidget(QWidget *_parent,
PrintingSelector *_printingSelector)
: QWidget(_parent), printingSelector(_printingSelector)
{
// Set up layout for the widget
layout = new QVBoxLayout();
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
setLayout(layout);
// Set up the expanded widget with its layout
expandedWidget = new QWidget(this);
QVBoxLayout *expandedLayout = new QVBoxLayout(expandedWidget);
expandedLayout->setContentsMargins(0, 0, 0, 0);
expandedLayout->setSpacing(0);
// Collapse button to toggle between expanded and collapsed states
collapseButton = new QPushButton("", this);
collapseButton->setFixedSize(20, 20);
collapseButton->setToolTip("Collapse");
@ -25,16 +35,19 @@ PrintingSelectorViewOptionsToolbarWidget::PrintingSelectorViewOptionsToolbarWidg
connect(collapseButton, &QPushButton::clicked, this, &PrintingSelectorViewOptionsToolbarWidget::collapse);
expandedLayout->addWidget(collapseButton, 0, Qt::AlignLeft);
// View options widget
viewOptions = new PrintingSelectorViewOptionsWidget(expandedWidget, printingSelector);
expandedLayout->addWidget(viewOptions);
expandedWidget->setLayout(expandedLayout);
// Set up the collapsed widget with its layout
collapsedWidget = new QWidget(this);
QHBoxLayout *collapsedLayout = new QHBoxLayout(collapsedWidget);
collapsedLayout->setContentsMargins(5, 0, 5, 0);
collapsedLayout->setSpacing(0);
// Expand button to show full options
expandButton = new QPushButton("", this);
expandButton->setFixedSize(20, 20);
expandButton->setToolTip("Expand");
@ -42,11 +55,13 @@ PrintingSelectorViewOptionsToolbarWidget::PrintingSelectorViewOptionsToolbarWidg
connect(expandButton, &QPushButton::clicked, this, &PrintingSelectorViewOptionsToolbarWidget::expand);
collapsedLayout->addWidget(expandButton);
// Label for collapsed state
QLabel *collapsedLabel = new QLabel(tr("Display Options"), this);
collapsedLayout->addWidget(collapsedLabel);
collapsedWidget->setLayout(collapsedLayout);
// Stack widget to switch between expanded and collapsed states
stackedWidget = new QStackedWidget(this);
stackedWidget->addWidget(expandedWidget);
stackedWidget->addWidget(collapsedWidget);
@ -55,25 +70,37 @@ PrintingSelectorViewOptionsToolbarWidget::PrintingSelectorViewOptionsToolbarWidg
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// Default to the expanded widget
stackedWidget->setCurrentWidget(expandedWidget);
// Connect the stacked widget to update the layout when it changes
connect(stackedWidget, &QStackedWidget::currentChanged, this,
&PrintingSelectorViewOptionsToolbarWidget::onWidgetChanged);
}
/**
* @brief Toggles the widget to the collapsed state.
*/
void PrintingSelectorViewOptionsToolbarWidget::collapse()
{
stackedWidget->setCurrentWidget(collapsedWidget);
updateGeometry();
}
/**
* @brief Toggles the widget to the expanded state.
*/
void PrintingSelectorViewOptionsToolbarWidget::expand()
{
stackedWidget->setCurrentWidget(expandedWidget);
updateGeometry();
}
// Handle Geometry Update
/**
* @brief Handles the geometry update when the stacked widget changes.
*
* This ensures that the parent layout is also updated when the widget's display state changes.
*/
void PrintingSelectorViewOptionsToolbarWidget::onWidgetChanged(int)
{
updateGeometry();
@ -82,18 +109,32 @@ void PrintingSelectorViewOptionsToolbarWidget::onWidgetChanged(int)
}
}
// Size Hints
/**
* @brief Provides the recommended size for the widget based on the current view.
*
* @return QSize The suggested size for the widget.
*/
QSize PrintingSelectorViewOptionsToolbarWidget::sizeHint() const
{
return stackedWidget->currentWidget()->sizeHint();
}
/**
* @brief Provides the minimum size required for the widget based on the current view.
*
* @return QSize The minimum size required for the widget.
*/
QSize PrintingSelectorViewOptionsToolbarWidget::minimumSizeHint() const
{
return stackedWidget->currentWidget()->minimumSizeHint();
}
/**
* @brief Returns the view options widget contained within this toolbar.
*
* @return PrintingSelectorViewOptionsWidget* The view options widget.
*/
PrintingSelectorViewOptionsWidget *PrintingSelectorViewOptionsToolbarWidget::getViewOptionsWidget() const
{
return viewOptions;
}
}

View file

@ -2,48 +2,66 @@
#include "../../../../settings/cache_settings.h"
/**
* @class PrintingSelectorViewOptionsWidget
* @brief A widget that provides the view options for the PrintingSelector, including checkboxes
* for sorting, search bar, card size slider, and navigation buttons.
*
* This widget allows the user to toggle the visibility of various interface components of the
* PrintingSelector through checkboxes. The state of the checkboxes is saved and restored using
* the `SettingsCache`.
*/
PrintingSelectorViewOptionsWidget::PrintingSelectorViewOptionsWidget(QWidget *parent,
PrintingSelector *_printingSelector)
: QWidget(parent), printingSelector(_printingSelector)
{
// Set up the layout for the widget
layout = new QHBoxLayout(this);
setLayout(layout);
// Create the flow widget to hold the checkboxes
flowWidget = new FlowWidget(this, Qt::ScrollBarPolicy::ScrollBarAlwaysOff, Qt::ScrollBarPolicy::ScrollBarAsNeeded);
// Create the checkbox for sorting options visibility
sortCheckBox = new QCheckBox(flowWidget);
sortCheckBox->setText(tr("Display Sorting Options"));
sortCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorSortOptionsVisible());
connect(sortCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilitySortOptions);
connect(sortCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
connect(sortCheckBox, &QCheckBox::stateChanged, printingSelector, &PrintingSelector::toggleVisibilitySortOptions);
connect(sortCheckBox, &QCheckBox::stateChanged, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorSortOptionsVisible);
// Create the checkbox for search bar visibility
searchCheckBox = new QCheckBox(flowWidget);
searchCheckBox->setText(tr("Display Search Bar"));
searchCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorSearchBarVisible());
connect(searchCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
&PrintingSelector::toggleVisibilitySearchBar);
connect(searchCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
connect(searchCheckBox, &QCheckBox::stateChanged, printingSelector, &PrintingSelector::toggleVisibilitySearchBar);
connect(searchCheckBox, &QCheckBox::stateChanged, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorSearchBarVisible);
// Create the checkbox for card size slider visibility
cardSizeCheckBox = new QCheckBox(flowWidget);
cardSizeCheckBox->setText(tr("Display Card Size Slider"));
cardSizeCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorCardSizeSliderVisible());
connect(cardSizeCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
connect(cardSizeCheckBox, &QCheckBox::stateChanged, printingSelector,
&PrintingSelector::toggleVisibilityCardSizeSlider);
connect(cardSizeCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
connect(cardSizeCheckBox, &QCheckBox::stateChanged, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorCardSizeSliderVisible);
// Create the checkbox for navigation buttons visibility
navigationCheckBox = new QCheckBox(flowWidget);
navigationCheckBox->setText(tr("Display Navigation Buttons"));
navigationCheckBox->setChecked(SettingsCache::instance().getPrintingSelectorNavigationButtonsVisible());
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, printingSelector,
connect(navigationCheckBox, &QCheckBox::stateChanged, printingSelector,
&PrintingSelector::toggleVisibilityNavigationButtons);
connect(navigationCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
connect(navigationCheckBox, &QCheckBox::stateChanged, &SettingsCache::instance(),
&SettingsCache::setPrintingSelectorNavigationButtonsVisible);
// Add checkboxes to the flow widget
flowWidget->addWidget(sortCheckBox);
flowWidget->addWidget(searchCheckBox);
flowWidget->addWidget(cardSizeCheckBox);
flowWidget->addWidget(navigationCheckBox);
// Add flow widget to the main layout
layout->addWidget(flowWidget);
}
}

View file

@ -2,34 +2,56 @@
#include <QSlider>
/**
* @class SetNameAndCollectorsNumberDisplayWidget
* @brief A widget to display the set name and collectors number with adjustable font size.
*
* This widget displays the set name and collectors number on two separate labels. The font size is resized dynamically
* when the card size is changed.
*/
SetNameAndCollectorsNumberDisplayWidget::SetNameAndCollectorsNumberDisplayWidget(QWidget *parent,
const QString &_setName,
const QString &_collectorsNumber,
QSlider *_cardSizeSlider)
: QWidget(parent)
{
// Set up the layout for the widget
layout = new QVBoxLayout(this);
setLayout(layout);
// Set the widget's size policy and minimum size
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
setMinimumSize(QWidget::sizeHint());
// Create and configure the set name label
setName = new QLabel(_setName);
setName->setWordWrap(true);
setName->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
setName->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
// Create and configure the collectors number label
collectorsNumber = new QLabel(_collectorsNumber);
collectorsNumber->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
collectorsNumber->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// Store the card size slider and connect its signal to the font size adjustment slot
cardSizeSlider = _cardSizeSlider;
connect(cardSizeSlider, &QSlider::valueChanged, this, &SetNameAndCollectorsNumberDisplayWidget::adjustFontSize);
// Add labels to the layout
layout->addWidget(setName);
layout->addWidget(collectorsNumber);
}
/**
* @brief Adjusts the font size of the labels based on the slider value.
*
* This method adjusts the font size of the set name and collectors number labels
* according to the scale percentage provided by the slider. The font size is clamped
* to a range between the defined minimum and maximum font sizes.
*
* @param scalePercentage The scale percentage from the slider.
*/
void SetNameAndCollectorsNumberDisplayWidget::adjustFontSize(int scalePercentage)
{
// Define the base font size and the range
@ -56,6 +78,14 @@ void SetNameAndCollectorsNumberDisplayWidget::adjustFontSize(int scalePercentage
adjustSize();
}
/**
* @brief Handles resize events to adjust the height of the set name label.
*
* This method calculates the height required to display the set name label with word wrapping.
* It adjusts the minimum height of the set name label to fit the text.
*
* @param event The resize event.
*/
void SetNameAndCollectorsNumberDisplayWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event); // Ensure the parent class handles the event first