mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Use show() instead of exec(), properly size hint list item widgets.
This commit is contained in:
parent
9786fd5713
commit
22875f8df8
3 changed files with 28 additions and 17 deletions
|
|
@ -10,6 +10,7 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
DeckPreviewTagDialog::DeckPreviewTagDialog(const QStringList &knownTags, const QStringList &activeTags, QWidget *parent)
|
DeckPreviewTagDialog::DeckPreviewTagDialog(const QStringList &knownTags, const QStringList &activeTags, QWidget *parent)
|
||||||
|
|
@ -56,9 +57,15 @@ DeckPreviewTagDialog::DeckPreviewTagDialog(const QStringList &knownTags, const Q
|
||||||
newTagInput = new QLineEdit(this);
|
newTagInput = new QLineEdit(this);
|
||||||
addTagButton = new QPushButton(this);
|
addTagButton = new QPushButton(this);
|
||||||
editButton = new QPushButton(this);
|
editButton = new QPushButton(this);
|
||||||
connect(editButton, &QPushButton::clicked, this, [=]() {
|
connect(editButton, &QPushButton::clicked, this, [this]() {
|
||||||
auto defaultTagsEditor = new DlgDefaultTagsEditor(nullptr);
|
auto *editor = new DlgDefaultTagsEditor(this);
|
||||||
defaultTagsEditor->exec();
|
editor->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
editor->setModal(true);
|
||||||
|
editor->show();
|
||||||
|
QTimer::singleShot(0, editor, [editor]() {
|
||||||
|
editor->raise();
|
||||||
|
editor->activateWindow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
addTagLayout->addWidget(newTagInput);
|
addTagLayout->addWidget(newTagInput);
|
||||||
addTagLayout->addWidget(addTagButton);
|
addTagLayout->addWidget(addTagButton);
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,10 @@
|
||||||
|
|
||||||
DlgDefaultTagsEditor::DlgDefaultTagsEditor(QWidget *parent) : QDialog(parent)
|
DlgDefaultTagsEditor::DlgDefaultTagsEditor(QWidget *parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
setWindowModality(Qt::WindowModal); // Steals focus from parent dialog
|
mainLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
auto *mainLayout = new QVBoxLayout(this);
|
|
||||||
|
|
||||||
// Input field + Add button (horizontal layout)
|
// Input field + Add button (horizontal layout)
|
||||||
auto *inputLayout = new QHBoxLayout();
|
inputLayout = new QHBoxLayout();
|
||||||
inputField = new QLineEdit(this);
|
inputField = new QLineEdit(this);
|
||||||
addButton = new QPushButton(this);
|
addButton = new QPushButton(this);
|
||||||
inputLayout->addWidget(inputField);
|
inputLayout->addWidget(inputField);
|
||||||
|
|
@ -26,7 +24,7 @@ DlgDefaultTagsEditor::DlgDefaultTagsEditor(QWidget *parent) : QDialog(parent)
|
||||||
mainLayout->addWidget(listWidget);
|
mainLayout->addWidget(listWidget);
|
||||||
|
|
||||||
// Button layout (Confirm and Cancel)
|
// Button layout (Confirm and Cancel)
|
||||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
buttonLayout = new QHBoxLayout();
|
||||||
confirmButton = new QPushButton(this);
|
confirmButton = new QPushButton(this);
|
||||||
cancelButton = new QPushButton(this);
|
cancelButton = new QPushButton(this);
|
||||||
buttonLayout->addWidget(confirmButton);
|
buttonLayout->addWidget(confirmButton);
|
||||||
|
|
@ -57,28 +55,30 @@ void DlgDefaultTagsEditor::loadStringList()
|
||||||
listWidget->clear();
|
listWidget->clear();
|
||||||
QStringList tags = SettingsCache::instance().getVisualDeckStorageDefaultTagsList();
|
QStringList tags = SettingsCache::instance().getVisualDeckStorageDefaultTagsList();
|
||||||
for (const QString &tag : tags) {
|
for (const QString &tag : tags) {
|
||||||
auto *item = new QListWidgetItem(listWidget);
|
auto *item = new QListWidgetItem(); // Create item but don't insert yet
|
||||||
|
|
||||||
QWidget *widget = new QWidget(this);
|
QWidget *widget = new QWidget(this);
|
||||||
QHBoxLayout *layout = new QHBoxLayout(widget);
|
QHBoxLayout *layout = new QHBoxLayout(widget);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(2, 2, 2, 2);
|
||||||
|
layout->setSpacing(5);
|
||||||
|
|
||||||
// Editable tag label
|
|
||||||
QLineEdit *lineEdit = new QLineEdit(tag, this);
|
QLineEdit *lineEdit = new QLineEdit(tag, this);
|
||||||
lineEdit->setFrame(false);
|
lineEdit->setFrame(false);
|
||||||
lineEdit->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
lineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
layout->addWidget(lineEdit);
|
layout->addWidget(lineEdit);
|
||||||
|
|
||||||
// Delete button
|
|
||||||
QPushButton *deleteButton = new QPushButton(tr("✖"), this);
|
QPushButton *deleteButton = new QPushButton(tr("✖"), this);
|
||||||
deleteButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
deleteButton->setFixedSize(25, 25);
|
||||||
deleteButton->setFixedWidth(25);
|
|
||||||
layout->addSpacing(5); // Adds spacing before the delete button
|
|
||||||
layout->addWidget(deleteButton);
|
layout->addWidget(deleteButton);
|
||||||
|
|
||||||
widget->setLayout(layout);
|
widget->setLayout(layout);
|
||||||
|
|
||||||
|
// Set item height explicitly to match the widget (widgets get squished without it)
|
||||||
|
item->setSizeHint(widget->sizeHint());
|
||||||
|
|
||||||
|
listWidget->addItem(item);
|
||||||
listWidget->setItemWidget(item, widget);
|
listWidget->setItemWidget(item, widget);
|
||||||
|
|
||||||
// Delete button signal
|
|
||||||
connect(deleteButton, &QPushButton::clicked, this, [this, item]() { deleteItem(item); });
|
connect(deleteButton, &QPushButton::clicked, this, [this, item]() { deleteItem(item); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
class DlgDefaultTagsEditor : public QDialog
|
class DlgDefaultTagsEditor : public QDialog
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +20,10 @@ private slots:
|
||||||
void confirmChanges();
|
void confirmChanges();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QVBoxLayout *mainLayout;
|
||||||
|
QHBoxLayout *inputLayout;
|
||||||
QListWidget *listWidget;
|
QListWidget *listWidget;
|
||||||
|
QHBoxLayout *buttonLayout;
|
||||||
QLineEdit *inputField;
|
QLineEdit *inputField;
|
||||||
QPushButton *addButton;
|
QPushButton *addButton;
|
||||||
QPushButton *confirmButton;
|
QPushButton *confirmButton;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue