Changeset View
Changeset View
Standalone View
Standalone View
importer/dialogpage.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | */ | 20 | */ | ||
21 | // Self | 21 | // Self | ||
22 | #include "dialogpage.h" | 22 | #include "dialogpage.h" | ||
23 | 23 | | |||
24 | // Qt | 24 | // Qt | ||
25 | #include <QEventLoop> | 25 | #include <QEventLoop> | ||
26 | #include <QList> | 26 | #include <QList> | ||
27 | #include <QSignalMapper> | | |||
28 | #include <QVBoxLayout> | 27 | #include <QVBoxLayout> | ||
29 | #include <QPushButton> | 28 | #include <QPushButton> | ||
30 | 29 | | |||
31 | // KDE | 30 | // KDE | ||
32 | #include <KGuiItem> | 31 | #include <KGuiItem> | ||
33 | 32 | | |||
34 | // Local | 33 | // Local | ||
35 | #include <ui_dialogpage.h> | 34 | #include <ui_dialogpage.h> | ||
36 | 35 | | |||
37 | namespace Gwenview | 36 | namespace Gwenview | ||
38 | { | 37 | { | ||
39 | 38 | | |||
40 | struct DialogPagePrivate : public Ui_DialogPage | 39 | struct DialogPagePrivate : public Ui_DialogPage | ||
41 | { | 40 | { | ||
42 | QVBoxLayout* mLayout; | 41 | QVBoxLayout* mLayout; | ||
43 | QList<QPushButton*> mButtons; | 42 | QList<QPushButton*> mButtons; | ||
44 | QSignalMapper* mMapper; | | |||
45 | QEventLoop* mEventLoop; | 43 | QEventLoop* mEventLoop; | ||
46 | }; | 44 | }; | ||
47 | 45 | | |||
48 | DialogPage::DialogPage(QWidget* parent) | 46 | DialogPage::DialogPage(QWidget* parent) | ||
49 | : QWidget(parent) | 47 | : QWidget(parent) | ||
50 | , d(new DialogPagePrivate) | 48 | , d(new DialogPagePrivate) | ||
51 | { | 49 | { | ||
52 | d->setupUi(this); | 50 | d->setupUi(this); | ||
53 | d->mLayout = new QVBoxLayout(d->mButtonContainer); | 51 | d->mLayout = new QVBoxLayout(d->mButtonContainer); | ||
54 | d->mMapper = new QSignalMapper(this); | | |||
55 | connect(d->mMapper, SIGNAL(mapped(int)), SLOT(slotMapped(int))); | | |||
56 | } | 52 | } | ||
57 | 53 | | |||
58 | DialogPage::~DialogPage() | 54 | DialogPage::~DialogPage() | ||
59 | { | 55 | { | ||
60 | delete d; | 56 | delete d; | ||
61 | } | 57 | } | ||
62 | 58 | | |||
63 | void DialogPage::removeButtons() | 59 | void DialogPage::removeButtons() | ||
Show All 9 Lines | |||||
73 | 69 | | |||
74 | int DialogPage::addButton(const KGuiItem& item) | 70 | int DialogPage::addButton(const KGuiItem& item) | ||
75 | { | 71 | { | ||
76 | int id = d->mButtons.size(); | 72 | int id = d->mButtons.size(); | ||
77 | QPushButton* button = new QPushButton; | 73 | QPushButton* button = new QPushButton; | ||
78 | KGuiItem::assign(button, item); | 74 | KGuiItem::assign(button, item); | ||
79 | button->setFixedHeight(button->sizeHint().height() * 2); | 75 | button->setFixedHeight(button->sizeHint().height() * 2); | ||
80 | 76 | | |||
81 | connect(button, SIGNAL(clicked()), d->mMapper, SLOT(map())); | 77 | connect(button, &QAbstractButton::clicked, this, [this, id]() { | ||
78 | d->mEventLoop->exit(id); | ||||
79 | }); | ||||
82 | d->mLayout->addWidget(button); | 80 | d->mLayout->addWidget(button); | ||
83 | d->mMapper->setMapping(button, id); | | |||
84 | d->mButtons << button; | 81 | d->mButtons << button; | ||
85 | return id; | 82 | return id; | ||
86 | } | 83 | } | ||
87 | 84 | | |||
88 | int DialogPage::exec() | 85 | int DialogPage::exec() | ||
89 | { | 86 | { | ||
90 | QEventLoop loop; | 87 | QEventLoop loop; | ||
91 | d->mEventLoop = &loop; | 88 | d->mEventLoop = &loop; | ||
92 | return loop.exec(); | 89 | return loop.exec(); | ||
93 | } | 90 | } | ||
94 | 91 | | |||
95 | void DialogPage::slotMapped(int value) | | |||
96 | { | | |||
97 | d->mEventLoop->exit(value); | | |||
98 | } | | |||
99 | | ||||
100 | } // namespace | 92 | } // namespace |