Changeset View
Changeset View
Standalone View
Standalone View
src/EditProfileDialog.h
Show All 20 Lines | |||||
21 | #ifndef EDITPROFILEDIALOG_H | 21 | #ifndef EDITPROFILEDIALOG_H | ||
22 | #define EDITPROFILEDIALOG_H | 22 | #define EDITPROFILEDIALOG_H | ||
23 | 23 | | |||
24 | // Qt | 24 | // Qt | ||
25 | #include <QAbstractItemDelegate> | 25 | #include <QAbstractItemDelegate> | ||
26 | #include <QDialog> | 26 | #include <QDialog> | ||
27 | #include <QHash> | 27 | #include <QHash> | ||
28 | #include <QPointer> | 28 | #include <QPointer> | ||
29 | #include <QButtonGroup> | ||||
30 | #include <QWidget> | ||||
31 | #include <QGridLayout> | ||||
32 | #include <QCheckBox> | ||||
33 | #include <QSpinBox> | ||||
29 | 34 | | |||
30 | // KDE | 35 | // KDE | ||
36 | #include <KPageDialog> | ||||
31 | #include <KNS3/Entry> | 37 | #include <KNS3/Entry> | ||
32 | 38 | | |||
33 | // Konsole | 39 | // Konsole | ||
34 | #include "Profile.h" | 40 | #include "Profile.h" | ||
35 | #include "Enumeration.h" | 41 | #include "Enumeration.h" | ||
36 | #include "ColorScheme.h" | 42 | #include "ColorScheme.h" | ||
37 | #include "ColorSchemeEditor.h" | 43 | #include "ColorSchemeEditor.h" | ||
38 | #include "KeyboardTranslatorManager.h" | 44 | #include "KeyboardTranslatorManager.h" | ||
45 | #include "FontDialog.h" | ||||
39 | 46 | | |||
40 | class QAbstractButton; | 47 | // Backward compatibility | ||
48 | #if QT_VERSION < QT_VERSION_CHECK(5, 7, 0) | ||||
49 | #define qAsConst(code) | ||||
50 | #endif | ||||
51 | | ||||
52 | class KPluralHandlingSpinBox; | ||||
53 | class KLocalizedString; | ||||
41 | class QItemSelectionModel; | 54 | class QItemSelectionModel; | ||
42 | class QTextCodec; | | |||
43 | class QDialogButtonBox; | | |||
44 | namespace Ui { | 55 | namespace Ui { | ||
45 | class EditProfileDialog; | 56 | class EditProfileGeneralPage; | ||
57 | class EditProfileTabsPage; | ||||
58 | class EditProfileAppearancePage; | ||||
59 | class EditProfileScrollingPage; | ||||
60 | class EditProfileKeyboardPage; | ||||
61 | class EditProfileMousePage; | ||||
62 | class EditProfileAdvancedPage; | ||||
46 | } | 63 | } | ||
47 | 64 | | |||
48 | namespace Konsole { | 65 | namespace Konsole { | ||
49 | /** | 66 | /** | ||
50 | * A dialog which allows the user to edit a profile. | 67 | * A dialog which allows the user to edit a profile. | ||
51 | * After the dialog is created, it can be initialized with the settings | 68 | * After the dialog is created, it can be initialized with the settings | ||
52 | * for a profile using setProfile(). When the user makes changes to the | 69 | * for a profile using setProfile(). When the user makes changes to the | ||
53 | * dialog and accepts the changes, the dialog will update the | 70 | * dialog and accepts the changes, the dialog will update the | ||
54 | * profile in the SessionManager by calling the SessionManager's | 71 | * profile in the SessionManager by calling the SessionManager's | ||
55 | * changeProfile() method. | 72 | * changeProfile() method. | ||
56 | * | 73 | * | ||
57 | * Some changes made in the dialog are preview-only changes which cause | 74 | * Some changes made in the dialog are preview-only changes which cause | ||
58 | * the SessionManager's changeProfile() method to be called with | 75 | * the SessionManager's changeProfile() method to be called with | ||
59 | * the persistent argument set to false. These changes are then | 76 | * the persistent argument set to false. These changes are then | ||
60 | * un-done when the dialog is closed. | 77 | * un-done when the dialog is closed. | ||
61 | */ | 78 | */ | ||
62 | class KONSOLEPRIVATE_EXPORT EditProfileDialog : public QDialog | 79 | class KONSOLEPRIVATE_EXPORT EditProfileDialog: public KPageDialog | ||
63 | { | 80 | { | ||
64 | Q_OBJECT | 81 | Q_OBJECT | ||
65 | 82 | | |||
66 | public: | 83 | public: | ||
67 | /** Constructs a new dialog with the specified parent. */ | 84 | /** Constructs a new dialog with the specified parent. */ | ||
68 | explicit EditProfileDialog(QWidget *parent = nullptr); | 85 | explicit EditProfileDialog(QWidget *parent = nullptr); | ||
69 | ~EditProfileDialog() Q_DECL_OVERRIDE; | 86 | ~EditProfileDialog() Q_DECL_OVERRIDE; | ||
70 | 87 | | |||
Show All 24 Lines | 108 | public Q_SLOTS: | |||
95 | void reject() Q_DECL_OVERRIDE; | 112 | void reject() Q_DECL_OVERRIDE; | ||
96 | 113 | | |||
97 | void apply(); | 114 | void apply(); | ||
98 | 115 | | |||
99 | protected: | 116 | protected: | ||
100 | bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; | 117 | bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; | ||
101 | 118 | | |||
102 | private Q_SLOTS: | 119 | private Q_SLOTS: | ||
120 | QSize sizeHint() const override; | ||||
121 | | ||||
103 | // sets up the specified tab page if necessary | 122 | // sets up the specified tab page if necessary | ||
104 | void preparePage(int); | 123 | void preparePage(KPageWidgetItem *current, KPageWidgetItem *before = nullptr); | ||
105 | 124 | | |||
106 | // saves changes to profile | 125 | // saves changes to profile | ||
107 | void save(); | 126 | void save(); | ||
108 | 127 | | |||
109 | // general page | 128 | // general page | ||
110 | void selectInitialDir(); | 129 | void selectInitialDir(); | ||
111 | void selectIcon(); | 130 | void selectIcon(); | ||
112 | 131 | | |||
113 | void profileNameChanged(const QString &name); | 132 | void profileNameChanged(const QString &name); | ||
114 | void initialDirChanged(const QString &dir); | 133 | void initialDirChanged(const QString &dir); | ||
115 | void startInSameDir(bool); | 134 | void startInSameDir(bool); | ||
116 | void commandChanged(const QString &command); | 135 | void commandChanged(const QString &command); | ||
117 | void tabTitleFormatChanged(const QString &format); | 136 | void tabTitleFormatChanged(const QString &format); | ||
118 | void remoteTabTitleFormatChanged(const QString &format); | 137 | void remoteTabTitleFormatChanged(const QString &format); | ||
119 | 138 | | |||
120 | void terminalColumnsEntryChanged(int); | 139 | void terminalColumnsEntryChanged(int); | ||
121 | void terminalRowsEntryChanged(int); | 140 | void terminalRowsEntryChanged(int); | ||
122 | void showTerminalSizeHint(bool); | 141 | void showTerminalSizeHint(bool); | ||
123 | void setDimWhenInactive(bool); | 142 | void setDimWhenInactive(bool); | ||
124 | void showEnvironmentEditor(); | 143 | void showEnvironmentEditor(); | ||
125 | void silenceSecondsChanged(int); | 144 | void silenceSecondsChanged(int); | ||
126 | 145 | | |||
127 | // appearance page | 146 | // appearance page | ||
128 | void setFontSize(double pointSize); | | |||
129 | void setFontInputValue(const QFont &); | | |||
130 | void showAllFontsButtonWarning(bool enable); | | |||
131 | void setAntialiasText(bool enable); | 147 | void setAntialiasText(bool enable); | ||
132 | void setBoldIntense(bool enable); | 148 | void setBoldIntense(bool enable); | ||
133 | void useFontLineCharacters(bool enable); | 149 | void useFontLineCharacters(bool enable); | ||
134 | void showFontDialog(); | | |||
135 | void newColorScheme(); | 150 | void newColorScheme(); | ||
136 | void editColorScheme(); | 151 | void editColorScheme(); | ||
137 | void saveColorScheme(const ColorScheme &scheme, bool isNewScheme); | 152 | void saveColorScheme(const ColorScheme &scheme, bool isNewScheme); | ||
138 | void removeColorScheme(); | 153 | void removeColorScheme(); | ||
139 | void gotNewColorSchemes(const KNS3::Entry::List &changedEntries); | 154 | void gotNewColorSchemes(const KNS3::Entry::List &changedEntries); | ||
140 | 155 | | |||
156 | void toggleBlinkingCursor(bool); | ||||
157 | void setCursorShape(int); | ||||
158 | void autoCursorColor(); | ||||
159 | void customCursorColor(); | ||||
160 | void customCursorColorChanged(const QColor &); | ||||
161 | void terminalMarginChanged(int margin); | ||||
162 | void lineSpacingChanged(int); | ||||
163 | void setTerminalCenter(bool enable); | ||||
164 | | ||||
141 | /** | 165 | /** | ||
142 | * Deletes the selected colorscheme from the user's home dir location | 166 | * Deletes the selected colorscheme from the user's home dir location | ||
143 | * so that the original one from the system-wide location can be used | 167 | * so that the original one from the system-wide location can be used | ||
144 | * instead | 168 | * instead | ||
145 | */ | 169 | */ | ||
146 | void resetColorScheme(); | 170 | void resetColorScheme(); | ||
147 | 171 | | |||
148 | void colorSchemeSelected(); | 172 | void colorSchemeSelected(); | ||
149 | void previewColorScheme(const QModelIndex &index); | 173 | void previewColorScheme(const QModelIndex &index); | ||
150 | void fontSelected(const QFont &); | 174 | void showFontDialog(); | ||
151 | void toggleMouseWheelZoom(bool enable); | 175 | void toggleMouseWheelZoom(bool enable); | ||
152 | 176 | | |||
153 | // scrolling page | 177 | // scrolling page | ||
154 | void historyModeChanged(Enum::HistoryModeEnum mode); | 178 | void historyModeChanged(Enum::HistoryModeEnum mode); | ||
155 | 179 | | |||
156 | void historySizeChanged(int); | 180 | void historySizeChanged(int); | ||
157 | 181 | | |||
158 | void hideScrollBar(); | | |||
159 | void showScrollBarLeft(); | | |||
160 | void showScrollBarRight(); | | |||
161 | | ||||
162 | void scrollFullPage(); | 182 | void scrollFullPage(); | ||
163 | void scrollHalfPage(); | 183 | void scrollHalfPage(); | ||
164 | 184 | | |||
165 | // keyboard page | 185 | // keyboard page | ||
166 | void editKeyBinding(); | 186 | void editKeyBinding(); | ||
167 | void newKeyBinding(); | 187 | void newKeyBinding(); | ||
168 | void keyBindingSelected(); | 188 | void keyBindingSelected(); | ||
169 | void removeKeyBinding(); | 189 | void removeKeyBinding(); | ||
Show All 15 Lines | |||||
185 | 205 | | |||
186 | void TripleClickModeChanged(int); | 206 | void TripleClickModeChanged(int); | ||
187 | void wordCharactersChanged(const QString &); | 207 | void wordCharactersChanged(const QString &); | ||
188 | 208 | | |||
189 | // advanced page | 209 | // advanced page | ||
190 | void toggleBlinkingText(bool); | 210 | void toggleBlinkingText(bool); | ||
191 | void toggleFlowControl(bool); | 211 | void toggleFlowControl(bool); | ||
192 | void togglebidiRendering(bool); | 212 | void togglebidiRendering(bool); | ||
193 | void lineSpacingChanged(int); | | |||
194 | void toggleBlinkingCursor(bool); | | |||
195 | void updateUrlHintsModifier(bool); | 213 | void updateUrlHintsModifier(bool); | ||
196 | void toggleReverseUrlHints(bool); | 214 | void toggleReverseUrlHints(bool); | ||
197 | 215 | | |||
198 | void setCursorShape(int); | | |||
199 | void autoCursorColor(); | | |||
200 | void customCursorColor(); | | |||
201 | void customCursorColorChanged(const QColor &); | | |||
202 | void setDefaultCodec(QTextCodec *); | 216 | void setDefaultCodec(QTextCodec *); | ||
203 | 217 | | |||
204 | // apply the first previewed changes stored up by delayedPreview() | 218 | // apply the first previewed changes stored up by delayedPreview() | ||
205 | void delayedPreviewActivate(); | 219 | void delayedPreviewActivate(); | ||
206 | 220 | | |||
207 | private: | 221 | private: | ||
208 | Q_DISABLE_COPY(EditProfileDialog) | 222 | Q_DISABLE_COPY(EditProfileDialog) | ||
209 | 223 | | |||
224 | enum PageID { | ||||
225 | GeneralPage = 0, | ||||
226 | TabsPage, | ||||
227 | AppearancePage, | ||||
228 | ScrollingPage, | ||||
229 | KeyboardPage, | ||||
230 | MousePage, | ||||
231 | AdvancedPage, | ||||
232 | | ||||
233 | PagesCount, | ||||
234 | }; | ||||
235 | | ||||
210 | // initialize various pages of the dialog | 236 | // initialize various pages of the dialog | ||
211 | void setupGeneralPage(const Profile::Ptr profile); | 237 | void setupGeneralPage(const Profile::Ptr &profile); | ||
212 | void setupTabsPage(const Profile::Ptr profile); | 238 | void setupTabsPage(const Profile::Ptr &profile); | ||
213 | void setupAppearancePage(const Profile::Ptr profile); | 239 | void setupAppearancePage(const Profile::Ptr &profile); | ||
214 | void setupKeyboardPage(const Profile::Ptr profile); | 240 | void setupKeyboardPage(const Profile::Ptr &profile); | ||
215 | void setupScrollingPage(const Profile::Ptr profile); | 241 | void setupScrollingPage(const Profile::Ptr &profile); | ||
216 | void setupAdvancedPage(const Profile::Ptr profile); | 242 | void setupAdvancedPage(const Profile::Ptr &profile); | ||
217 | void setupMousePage(const Profile::Ptr info); | 243 | void setupMousePage(const Profile::Ptr &profile); | ||
244 | | ||||
245 | int maxSpinBoxWidth(const KPluralHandlingSpinBox *spinBox, const KLocalizedString &suffix); | ||||
218 | 246 | | |||
219 | // Returns the name of the colorScheme used in the current profile | 247 | // Returns the name of the colorScheme used in the current profile | ||
220 | const QString currentColorSchemeName() const; | 248 | const QString currentColorSchemeName() const; | ||
221 | 249 | | |||
222 | // select @p selectedColorSchemeName after the changes are saved | 250 | // select @p selectedColorSchemeName after the changes are saved | ||
223 | // in the colorScheme editor | 251 | // in the colorScheme editor | ||
224 | void updateColorSchemeList(const QString &selectedColorSchemeName = QString()); | 252 | void updateColorSchemeList(const QString &selectedColorSchemeName = QString()); | ||
225 | 253 | | |||
Show All 15 Lines | |||||
241 | void delayedPreview(int property, const QVariant &value); | 269 | void delayedPreview(int property, const QVariant &value); | ||
242 | void unpreview(int property); | 270 | void unpreview(int property); | ||
243 | void unpreviewAll(); | 271 | void unpreviewAll(); | ||
244 | void enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel); | 272 | void enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel); | ||
245 | 273 | | |||
246 | void updateCaption(const Profile::Ptr profile); | 274 | void updateCaption(const Profile::Ptr profile); | ||
247 | void updateTransparencyWarning(); | 275 | void updateTransparencyWarning(); | ||
248 | 276 | | |||
277 | void updateFontPreview(QFont font); | ||||
278 | | ||||
249 | // Update _tempProfile in a way of respecting the apply button. | 279 | // Update _tempProfile in a way of respecting the apply button. | ||
250 | // When used with some previewed property, this method should | 280 | // When used with some previewed property, this method should | ||
251 | // always come after the preview operation. | 281 | // always come after the preview operation. | ||
252 | void updateTempProfileProperty(Profile::Property, const QVariant &value); | 282 | void updateTempProfileProperty(Profile::Property, const QVariant &value); | ||
253 | 283 | | |||
254 | // helper method for creating an empty & hidden profile and assigning | 284 | // helper method for creating an empty & hidden profile and assigning | ||
255 | // it to _tempProfile. | 285 | // it to _tempProfile. | ||
256 | void createTempProfile(); | 286 | void createTempProfile(); | ||
Show All 10 Lines | 294 | struct RadioOption { | |||
267 | const char *slot; | 297 | const char *slot; | ||
268 | }; | 298 | }; | ||
269 | void setupRadio(const QVector<RadioOption>& possibilities, int actual); | 299 | void setupRadio(const QVector<RadioOption>& possibilities, int actual); | ||
270 | struct BooleanOption { | 300 | struct BooleanOption { | ||
271 | QAbstractButton *button; | 301 | QAbstractButton *button; | ||
272 | Profile::Property property; | 302 | Profile::Property property; | ||
273 | const char *slot; | 303 | const char *slot; | ||
274 | }; | 304 | }; | ||
275 | void setupCheckBoxes(const QVector<BooleanOption>& options, const Profile::Ptr profile); | 305 | void setupCheckBoxes(const QVector<BooleanOption>& options, const Profile::Ptr &profile); | ||
306 | | ||||
307 | struct ButtonGroupOption { | ||||
308 | QAbstractButton *button; | ||||
309 | int value; | ||||
310 | }; | ||||
311 | struct ButtonGroupOptions { | ||||
312 | QButtonGroup *group; | ||||
313 | Profile::Property profileProperty; | ||||
314 | bool preview; | ||||
315 | QVector<ButtonGroupOption> buttons; | ||||
316 | }; | ||||
317 | void setupButtonGroup(const ButtonGroupOptions &options, const Profile::Ptr &profile); | ||||
276 | 318 | | |||
277 | // returns false if: | 319 | // returns false if: | ||
278 | // - the profile name is empty | 320 | // - the profile name is empty | ||
279 | // - the name matches the name of an already existing profile | 321 | // - the name matches the name of an already existing profile | ||
280 | // - the existing profile config file is read-only | 322 | // - the existing profile config file is read-only | ||
281 | // otherwise returns true. | 323 | // otherwise returns true. | ||
282 | bool isValidProfileName(); | 324 | bool isValidProfileName(); | ||
283 | 325 | | |||
284 | Ui::EditProfileDialog *_ui; | 326 | Ui::EditProfileGeneralPage *_generalUi; | ||
327 | Ui::EditProfileTabsPage *_tabsUi; | ||||
328 | Ui::EditProfileAppearancePage *_appearanceUi; | ||||
329 | Ui::EditProfileScrollingPage *_scrollingUi; | ||||
330 | Ui::EditProfileKeyboardPage *_keyboardUi; | ||||
331 | Ui::EditProfileMousePage *_mouseUi; | ||||
332 | Ui::EditProfileAdvancedPage *_advancedUi; | ||||
333 | | ||||
334 | using PageSetupMethod = void (EditProfileDialog::*)(const Profile::Ptr &); | ||||
335 | struct Page { | ||||
336 | Page(PageSetupMethod setupPage = nullptr, bool needsUpdate = false) | ||||
337 | : setupPage(setupPage) | ||||
338 | , needsUpdate(needsUpdate) | ||||
339 | {} | ||||
340 | | ||||
341 | PageSetupMethod setupPage; | ||||
342 | bool needsUpdate; | ||||
343 | }; | ||||
344 | | ||||
345 | QMap<KPageWidgetItem *, Page> _pages; | ||||
346 | | ||||
285 | Profile::Ptr _tempProfile; | 347 | Profile::Ptr _tempProfile; | ||
286 | Profile::Ptr _profile; | 348 | Profile::Ptr _profile; | ||
287 | 349 | | |||
288 | // keeps track of pages which need to be updated to match the current | | |||
289 | // profile. all elements in this vector are set to true when the | | |||
290 | // profile is changed and individual elements are set to false | | |||
291 | // after an update by a call to ensurePageLoaded() | | |||
292 | QVector<bool> _pageNeedsUpdate; | | |||
293 | QHash<int, QVariant> _previewedProperties; | 350 | QHash<int, QVariant> _previewedProperties; | ||
294 | 351 | | |||
295 | QHash<int, QVariant> _delayedPreviewProperties; | 352 | QHash<int, QVariant> _delayedPreviewProperties; | ||
296 | QTimer *_delayedPreviewTimer; | 353 | QTimer *_delayedPreviewTimer; | ||
297 | 354 | | |||
298 | ColorSchemeEditor *_colorDialog; | 355 | ColorSchemeEditor *_colorDialog; | ||
299 | QDialogButtonBox *mButtonBox; | 356 | QDialogButtonBox *_buttonBox; | ||
357 | FontDialog *_fontDialog; | ||||
300 | }; | 358 | }; | ||
301 | 359 | | |||
302 | /** | 360 | /** | ||
303 | * A delegate which can display and edit color schemes in a view. | 361 | * A delegate which can display and edit color schemes in a view. | ||
304 | */ | 362 | */ | ||
305 | class ColorSchemeViewDelegate : public QAbstractItemDelegate | 363 | class ColorSchemeViewDelegate : public QAbstractItemDelegate | ||
306 | { | 364 | { | ||
307 | Q_OBJECT | 365 | Q_OBJECT | ||
308 | 366 | | |||
309 | public: | 367 | public: | ||
310 | explicit ColorSchemeViewDelegate(QObject *parent = nullptr); | 368 | explicit ColorSchemeViewDelegate(QObject *parent = nullptr); | ||
311 | 369 | | |||
312 | // reimplemented | 370 | // reimplemented | ||
313 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | 371 | void paint(QPainter *painter, const QStyleOptionViewItem &option, | ||
314 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 372 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
315 | QSize sizeHint(const QStyleOptionViewItem &option, | 373 | QSize sizeHint(const QStyleOptionViewItem &option, | ||
316 | const QModelIndex &index) const Q_DECL_OVERRIDE; | 374 | const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
317 | }; | 375 | }; | ||
376 | | ||||
377 | /** | ||||
378 | * An utility class for aligning 0th column in multiple QGridLayouts. | ||||
379 | * | ||||
380 | * Limitations: | ||||
381 | * - a layout can't be nested in another layout | ||||
382 | * - reference widget must be an ancestor of all added layouts | ||||
383 | * - only 0th column is processed (widgets spanning multiple columns | ||||
384 | * are ignored) | ||||
385 | */ | ||||
386 | class LabelsAligner: public QObject { | ||||
387 | Q_OBJECT | ||||
388 | | ||||
389 | public: | ||||
390 | LabelsAligner(QWidget *refWidget): _refWidget(refWidget) {} | ||||
391 | | ||||
392 | void addLayout(QGridLayout *layout) { _layouts.append(layout); } | ||||
393 | void addLayouts(const QVector<QGridLayout *> &layouts) { _layouts.append(layouts); } | ||||
394 | void setReferenceWidget(QWidget *refWidget) { _refWidget = refWidget; } | ||||
395 | | ||||
396 | public Q_SLOTS: | ||||
397 | void updateLayouts() { | ||||
398 | for (const auto *layout: qAsConst(_layouts)) { | ||||
399 | QWidget *widget = layout->parentWidget(); | ||||
400 | Q_ASSERT(widget); | ||||
401 | do { | ||||
402 | QLayout *widgetLayout = widget->layout(); | ||||
403 | if (widgetLayout) { | ||||
404 | widgetLayout->update(); | ||||
405 | widgetLayout->activate(); | ||||
406 | } | ||||
407 | widget = widget->parentWidget(); | ||||
408 | } while (widget != _refWidget && widget != nullptr); | ||||
409 | } | ||||
410 | } | ||||
411 | | ||||
412 | void align() { | ||||
413 | Q_ASSERT(_refWidget); | ||||
414 | | ||||
415 | if (_layouts.count() <= 1) { | ||||
416 | return; | ||||
417 | } | ||||
418 | | ||||
419 | int maxRight = 0; | ||||
420 | for (const auto *layout: qAsConst(_layouts)) { | ||||
421 | int left = getLeftMargin(layout); | ||||
422 | for (int row = 0; row < layout->rowCount(); ++row) { | ||||
423 | QLayoutItem *layoutItem = layout->itemAtPosition(row, LABELS_COLUMN); | ||||
424 | if (!layoutItem) { | ||||
425 | continue; | ||||
426 | } | ||||
427 | QWidget *widget = layoutItem->widget(); | ||||
428 | if (!widget) { | ||||
429 | continue; | ||||
430 | } | ||||
431 | const int idx = layout->indexOf(widget); | ||||
432 | int rows, cols, rowSpan, colSpan; | ||||
433 | layout->getItemPosition(idx, &rows, &cols, &rowSpan, &colSpan); | ||||
434 | if (colSpan > 1) { | ||||
435 | continue; | ||||
436 | } | ||||
437 | | ||||
438 | const int right = left + widget->sizeHint().width(); | ||||
439 | if (maxRight < right) { | ||||
440 | maxRight = right; | ||||
441 | } | ||||
442 | } | ||||
443 | } | ||||
444 | | ||||
445 | for (auto *l: qAsConst(_layouts)) { | ||||
446 | int left = getLeftMargin(l); | ||||
447 | l->setColumnMinimumWidth(LABELS_COLUMN, maxRight - left); | ||||
448 | } | ||||
449 | } | ||||
450 | | ||||
451 | private: | ||||
452 | int getLeftMargin(const QGridLayout *layout) { | ||||
453 | int left = layout->contentsMargins().left(); | ||||
454 | | ||||
455 | if (layout->parent()->isWidgetType()) { | ||||
456 | auto *parentWidget = layout->parentWidget(); | ||||
457 | Q_ASSERT(parentWidget); | ||||
458 | left += parentWidget->contentsMargins().left(); | ||||
459 | } else { | ||||
460 | auto *parentLayout = qobject_cast<QLayout *>(layout->parent()); | ||||
461 | Q_ASSERT(parentLayout); | ||||
462 | left += parentLayout->contentsMargins().left(); | ||||
463 | } | ||||
464 | | ||||
465 | QWidget *parent = layout->parentWidget(); | ||||
466 | while (parent != _refWidget && parent != nullptr) { | ||||
467 | left = parent->mapToParent(QPoint(left, 0)).x(); | ||||
468 | parent = parent->parentWidget(); | ||||
469 | } | ||||
470 | return left; | ||||
471 | }; | ||||
472 | | ||||
473 | static constexpr int LABELS_COLUMN = 0; | ||||
474 | | ||||
475 | QWidget *_refWidget; | ||||
476 | QVector<QGridLayout *> _layouts; | ||||
477 | }; | ||||
478 | | ||||
318 | } | 479 | } | ||
319 | 480 | | |||
320 | #endif // EDITPROFILEDIALOG_H | 481 | #endif // EDITPROFILEDIALOG_H |