Changeset View
Changeset View
Standalone View
Standalone View
src/kconfigdialog.cpp
Show All 31 Lines | |||||
32 | #include <QDialogButtonBox> | 32 | #include <QDialogButtonBox> | ||
33 | #include <QIcon> | 33 | #include <QIcon> | ||
34 | #include <QLayout> | 34 | #include <QLayout> | ||
35 | #include <QPushButton> | 35 | #include <QPushButton> | ||
36 | #include <QMap> | 36 | #include <QMap> | ||
37 | #include <QCoreApplication> | 37 | #include <QCoreApplication> | ||
38 | #include <QDesktopServices> | 38 | #include <QDesktopServices> | ||
39 | #include <QScrollArea> | 39 | #include <QScrollArea> | ||
40 | #include <QScrollBar> | ||||
40 | 41 | | |||
41 | class Q_DECL_HIDDEN KConfigDialog::KConfigDialogPrivate | 42 | class Q_DECL_HIDDEN KConfigDialog::KConfigDialogPrivate | ||
42 | { | 43 | { | ||
43 | public: | 44 | public: | ||
44 | KConfigDialogPrivate(KConfigDialog *q, const QString &name, KCoreConfigSkeleton *config) | 45 | KConfigDialogPrivate(KConfigDialog *q, const QString &name, KCoreConfigSkeleton *config) | ||
45 | : q(q), shown(false), manager(nullptr) | 46 | : q(q), shown(false), manager(nullptr) | ||
46 | { | 47 | { | ||
47 | q->setObjectName(name); | 48 | q->setObjectName(name); | ||
Show All 27 Lines | |||||
75 | 76 | | |||
76 | manager = new KConfigDialogManager(q, config); | 77 | manager = new KConfigDialogManager(q, config); | ||
77 | setupManagerConnections(manager); | 78 | setupManagerConnections(manager); | ||
78 | 79 | | |||
79 | setApplyButtonEnabled(false); | 80 | setApplyButtonEnabled(false); | ||
80 | } | 81 | } | ||
81 | 82 | | |||
82 | KPageWidgetItem *addPageInternal(QWidget *page, const QString &itemName, | 83 | KPageWidgetItem *addPageInternal(QWidget *page, const QString &itemName, | ||
84 | PageContentAlignment contentAlignment, | ||||
83 | const QString &pixmapName, const QString &header); | 85 | const QString &pixmapName, const QString &header); | ||
84 | 86 | | |||
85 | void setupManagerConnections(KConfigDialogManager *manager); | 87 | void setupManagerConnections(KConfigDialogManager *manager); | ||
86 | void setApplyButtonEnabled(bool enabled); | 88 | void setApplyButtonEnabled(bool enabled); | ||
87 | void setRestoreDefaultsButtonEnabled(bool enabled); | 89 | void setRestoreDefaultsButtonEnabled(bool enabled); | ||
88 | 90 | | |||
89 | void _k_updateButtons(); | 91 | void _k_updateButtons(); | ||
90 | void _k_settingsChangedSlot(); | 92 | void _k_settingsChangedSlot(); | ||
Show All 27 Lines | |||||
118 | } | 120 | } | ||
119 | 121 | | |||
120 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | 122 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | ||
121 | const QString &itemName, | 123 | const QString &itemName, | ||
122 | const QString &pixmapName, | 124 | const QString &pixmapName, | ||
123 | const QString &header, | 125 | const QString &header, | ||
124 | bool manage) | 126 | bool manage) | ||
125 | { | 127 | { | ||
128 | return addPage(page, itemName, NoAlignment, pixmapName, header, manage); | ||||
129 | } | ||||
130 | | ||||
131 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | ||||
132 | const QString &itemName, | ||||
133 | PageContentAlignment contentAlignment, | ||||
134 | const QString &pixmapName, | ||||
135 | const QString &header, | ||||
136 | bool manage) | ||||
137 | { | ||||
126 | Q_ASSERT(page); | 138 | Q_ASSERT(page); | ||
127 | if (!page) { | 139 | if (!page) { | ||
128 | return nullptr; | 140 | return nullptr; | ||
129 | } | 141 | } | ||
130 | 142 | | |||
131 | KPageWidgetItem *item = d->addPageInternal(page, itemName, pixmapName, header); | 143 | KPageWidgetItem *item = d->addPageInternal(page, itemName, contentAlignment, | ||
144 | pixmapName, header); | ||||
132 | if (manage) { | 145 | if (manage) { | ||
133 | d->manager->addWidget(page); | 146 | d->manager->addWidget(page); | ||
134 | } | 147 | } | ||
135 | 148 | | |||
136 | if (d->shown && manage) { | 149 | if (d->shown && manage) { | ||
137 | // update the default button if the dialog is shown | 150 | // update the default button if the dialog is shown | ||
138 | QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); | 151 | QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); | ||
139 | if (defaultButton) { | 152 | if (defaultButton) { | ||
140 | bool is_default = defaultButton->isEnabled() && d->manager->isDefault(); | 153 | bool is_default = defaultButton->isEnabled() && d->manager->isDefault(); | ||
141 | defaultButton->setEnabled(!is_default); | 154 | defaultButton->setEnabled(!is_default); | ||
142 | } | 155 | } | ||
143 | } | 156 | } | ||
144 | return item; | 157 | return item; | ||
145 | } | 158 | } | ||
146 | 159 | | |||
147 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | 160 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | ||
148 | KCoreConfigSkeleton *config, | 161 | KCoreConfigSkeleton *config, | ||
149 | const QString &itemName, | 162 | const QString &itemName, | ||
150 | const QString &pixmapName, | 163 | const QString &pixmapName, | ||
151 | const QString &header) | 164 | const QString &header) | ||
152 | { | 165 | { | ||
166 | return addPage(page, config, itemName, NoAlignment, pixmapName, header); | ||||
167 | } | ||||
168 | | ||||
169 | KPageWidgetItem *KConfigDialog::addPage(QWidget *page, | ||||
170 | KCoreConfigSkeleton *config, | ||||
171 | const QString &itemName, | ||||
172 | PageContentAlignment contentAlignment, | ||||
173 | const QString &pixmapName, | ||||
174 | const QString &header) | ||||
175 | { | ||||
153 | Q_ASSERT(page); | 176 | Q_ASSERT(page); | ||
154 | if (!page) { | 177 | if (!page) { | ||
155 | return nullptr; | 178 | return nullptr; | ||
156 | } | 179 | } | ||
157 | 180 | | |||
158 | KPageWidgetItem *item = d->addPageInternal(page, itemName, pixmapName, header); | 181 | KPageWidgetItem *item = d->addPageInternal(page, itemName, contentAlignment, | ||
182 | pixmapName, header); | ||||
159 | d->managerForPage[page] = new KConfigDialogManager(page, config); | 183 | d->managerForPage[page] = new KConfigDialogManager(page, config); | ||
160 | d->setupManagerConnections(d->managerForPage[page]); | 184 | d->setupManagerConnections(d->managerForPage[page]); | ||
161 | 185 | | |||
162 | if (d->shown) { | 186 | if (d->shown) { | ||
163 | // update the default button if the dialog is shown | 187 | // update the default button if the dialog is shown | ||
164 | QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); | 188 | QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); | ||
165 | if (defaultButton) { | 189 | if (defaultButton) { | ||
166 | bool is_default = defaultButton->isEnabled() && d->managerForPage[page]->isDefault(); | 190 | bool is_default = defaultButton->isEnabled() && d->managerForPage[page]->isDefault(); | ||
167 | defaultButton->setEnabled(!is_default); | 191 | defaultButton->setEnabled(!is_default); | ||
168 | } | 192 | } | ||
169 | } | 193 | } | ||
170 | return item; | 194 | return item; | ||
171 | } | 195 | } | ||
172 | 196 | | |||
197 | | ||||
198 | // Helper class overriding sizeHint() in QScrollArea to fit the content QWidget horizontally. | ||||
199 | class FittingScrollArea : public QScrollArea | ||||
200 | { | ||||
201 | public: | ||||
202 | FittingScrollArea(QWidget* parent, KConfigDialog::PageContentAlignment alignment) | ||||
203 | : QScrollArea(parent), | ||||
204 | alignment(alignment) | ||||
205 | {} | ||||
206 | | ||||
207 | QSize sizeHint() const override | ||||
208 | { | ||||
209 | const QWidget* const contentWidget = widget(); | ||||
210 | if (contentWidget == nullptr) { | ||||
211 | return QScrollArea::sizeHint(); | ||||
212 | } | ||||
213 | | ||||
214 | | ||||
215 | switch (alignment) { | ||||
216 | case KConfigDialog::NoAlignment: | ||||
217 | return QScrollArea::sizeHint(); | ||||
218 | case KConfigDialog::FitWidth: { | ||||
219 | const int width = contentWidget->sizeHint().width() + verticalScrollBar()->width(); | ||||
220 | const int height = QScrollArea::sizeHint().height(); | ||||
221 | return QSize(width, height); | ||||
222 | } | ||||
223 | default: | ||||
224 | // Should never occur | ||||
225 | return QScrollArea::sizeHint(); | ||||
226 | } | ||||
227 | } | ||||
228 | | ||||
229 | private: | ||||
230 | const KConfigDialog::PageContentAlignment alignment; | ||||
231 | }; | ||||
232 | | ||||
173 | KPageWidgetItem *KConfigDialog::KConfigDialogPrivate::addPageInternal(QWidget *page, | 233 | KPageWidgetItem *KConfigDialog::KConfigDialogPrivate::addPageInternal(QWidget *page, | ||
174 | const QString &itemName, | 234 | const QString &itemName, | ||
235 | PageContentAlignment contentAlignment, | ||||
175 | const QString &pixmapName, | 236 | const QString &pixmapName, | ||
176 | const QString &header) | 237 | const QString &header) | ||
177 | { | 238 | { | ||
178 | QWidget *frame = new QWidget(q); | 239 | QWidget *frame = new QWidget(q); | ||
179 | QVBoxLayout *boxLayout = new QVBoxLayout(frame); | 240 | QVBoxLayout *boxLayout = new QVBoxLayout(frame); | ||
180 | boxLayout->setMargin(0); | 241 | boxLayout->setMargin(0); | ||
181 | boxLayout->setMargin(0); | 242 | boxLayout->setMargin(0); | ||
182 | 243 | | |||
183 | QScrollArea *scroll = new QScrollArea(q); | 244 | QScrollArea *scroll = nullptr; | ||
245 | if (contentAlignment == NoAlignment) { | ||||
246 | scroll = new QScrollArea(q); | ||||
247 | scroll->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); | ||||
248 | } else { | ||||
249 | scroll = new FittingScrollArea(q, contentAlignment); | ||||
250 | scroll->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); | ||||
251 | } | ||||
184 | scroll->setFrameShape(QFrame::NoFrame); | 252 | scroll->setFrameShape(QFrame::NoFrame); | ||
185 | scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | 253 | scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
186 | scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); | 254 | scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); | ||
187 | scroll->setWidget(page); | 255 | scroll->setWidget(page); | ||
188 | scroll->setWidgetResizable(true); | 256 | scroll->setWidgetResizable(true); | ||
189 | scroll->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); | | |||
190 | 257 | | |||
191 | boxLayout->addWidget(scroll); | 258 | boxLayout->addWidget(scroll); | ||
192 | KPageWidgetItem *item = new KPageWidgetItem(frame, itemName); | 259 | KPageWidgetItem *item = new KPageWidgetItem(frame, itemName); | ||
193 | item->setHeader(header); | 260 | item->setHeader(header); | ||
194 | if (!pixmapName.isEmpty()) { | 261 | if (!pixmapName.isEmpty()) { | ||
195 | item->setIcon(QIcon::fromTheme(pixmapName)); | 262 | item->setIcon(QIcon::fromTheme(pixmapName)); | ||
196 | } | 263 | } | ||
197 | 264 | | |||
▲ Show 20 Lines • Show All 183 Lines • Show Last 20 Lines |