Commit 4f53a68d authored by Christoffer Ackelman's avatar Christoffer Ackelman

QT: Fixed CoWow ListWidget calling both apply/ok and then cancel.

parent f955dc2c
...@@ -205,6 +205,8 @@ void CoWowListWidgetQt::list_row_activated_cb(QTreeWidgetItem* item, int i) ...@@ -205,6 +205,8 @@ void CoWowListWidgetQt::list_row_activated_cb(QTreeWidgetItem* item, int i)
void CoWowListWidgetQt::list_apply_cb() void CoWowListWidgetQt::list_apply_cb()
{ {
button_pressed = 0;
QString selected_text; QString selected_text;
QList<QTreeWidgetItem*> selected_items = list->selectedItems(); QList<QTreeWidgetItem*> selected_items = list->selectedItems();
...@@ -213,21 +215,16 @@ void CoWowListWidgetQt::list_apply_cb() ...@@ -213,21 +215,16 @@ void CoWowListWidgetQt::list_apply_cb()
selected_text = item->text(0); selected_text = item->text(0);
} }
if (action_cb) { if (action_cb) {
(action_cb)(parent_ctx, qPrintableLatin1(selected_text), ok_pressed); (action_cb)(parent_ctx, qPrintableLatin1(selected_text), button_pressed);
} }
close();
} }
void CoWowListWidgetQt::list_ok_cb() void CoWowListWidgetQt::list_ok_cb()
{ {
ok_pressed = 1; button_pressed = 1;
list_apply_cb(); list_apply_cb();
} close();
void CoWowListWidgetQt::list_cancel_cb()
{
if (cancel_cb) {
(cancel_cb)(parent_ctx);
}
} }
CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title, CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title,
...@@ -236,22 +233,18 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title, ...@@ -236,22 +233,18 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title,
: QWidget(), action_cb(action_cb), cancel_cb(cancel_cb), : QWidget(), action_cb(action_cb), cancel_cb(cancel_cb),
parent_ctx(parent_ctx) parent_ctx(parent_ctx)
{ {
QVBoxLayout* vbox = new QVBoxLayout(this); QDialogButtonBox* buttons = new QDialogButtonBox();
QHBoxLayout* hbox = new QHBoxLayout();
QPushButton* ok_button = new QPushButton("OK"); buttons->addButton(QDialogButtonBox::Ok);
connect(ok_button, SIGNAL(clicked()), this, SLOT(list_ok_cb())); connect(buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(list_ok_cb()));
hbox->addWidget(ok_button, 1, Qt::AlignRight);
if (show_apply_button) { if (show_apply_button) {
QPushButton* apply_button = new QPushButton(translate_utf8("Apply")); buttons->addButton(QDialogButtonBox::Apply);
connect(apply_button, SIGNAL(clicked()), this, SLOT(list_apply_cb())); connect(buttons->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(list_apply_cb()));
hbox->addWidget(apply_button, 0);
} }
QPushButton* cancel_button = new QPushButton("Cancel"); buttons->addButton(QDialogButtonBox::Cancel);
connect(cancel_button, SIGNAL(clicked()), this, SLOT(list_cancel_cb())); connect(buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(close()));
hbox->addWidget(cancel_button, 0);
list = new QTreeWidget(); list = new QTreeWidget();
...@@ -271,8 +264,9 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title, ...@@ -271,8 +264,9 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title,
connect(list, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, connect(list, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this,
SLOT(list_row_activated_cb(QTreeWidgetItem*, int))); SLOT(list_row_activated_cb(QTreeWidgetItem*, int)));
QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->addWidget(list, 1, Qt::AlignTop); vbox->addWidget(list, 1, Qt::AlignTop);
vbox->addLayout(hbox); vbox->addWidget(buttons);
setLayout(vbox); setLayout(vbox);
...@@ -288,14 +282,16 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title, ...@@ -288,14 +282,16 @@ CoWowListWidgetQt::CoWowListWidgetQt(QWidget* parent, const char* title,
void CoWowListWidgetQt::focusInEvent(QFocusEvent* event) void CoWowListWidgetQt::focusInEvent(QFocusEvent* event)
{ {
QWidget::focusInEvent(event);
pop(this); pop(this);
QWidget::focusInEvent(event);
} }
void CoWowListWidgetQt::closeEvent(QCloseEvent* event) void CoWowListWidgetQt::closeEvent(QCloseEvent* event)
{ {
if (button_pressed < 0 && cancel_cb) {
(cancel_cb)(parent_ctx);
}
QWidget::closeEvent(event); QWidget::closeEvent(event);
list_cancel_cb();
} }
void* CoWowQt::CreateList(const char* title, const char* texts, int textsize, void* CoWowQt::CreateList(const char* title, const char* texts, int textsize,
......
...@@ -152,13 +152,12 @@ private: ...@@ -152,13 +152,12 @@ private:
void (*action_cb)(void*, char*, int); void (*action_cb)(void*, char*, int);
void (*cancel_cb)(void*); void (*cancel_cb)(void*);
void* parent_ctx; void* parent_ctx;
int ok_pressed; int button_pressed = -1;
public slots: public slots:
void list_row_activated_cb(QTreeWidgetItem* item, int i); void list_row_activated_cb(QTreeWidgetItem* item, int i);
void list_apply_cb(); void list_apply_cb();
void list_ok_cb(); void list_ok_cb();
void list_cancel_cb();
}; };
class CoWowQtObject; class CoWowQtObject;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment