File indexing completed on 2024-04-21 05:51:23

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
0003     SPDX-FileCopyrightText: 2018 Harald Sitter <sitter@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef LABELSALIGNER_H
0009 #define LABELSALIGNER_H
0010 
0011 #include <QObject>
0012 #include <QVector>
0013 
0014 class QWidget;
0015 class QGridLayout;
0016 
0017 namespace Konsole
0018 {
0019 /**
0020  * An utility class for aligning 0th column in multiple QGridLayouts.
0021  *
0022  * Limitations:
0023  * - a layout can't be nested in another layout
0024  * - reference widget must be an ancestor of all added layouts
0025  * - only 0th column is processed (widgets spanning multiple columns
0026  *   are ignored)
0027  */
0028 class LabelsAligner : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     explicit LabelsAligner(QWidget *refWidget);
0034 
0035     void addLayout(QGridLayout *layout);
0036     void addLayouts(const QVector<QGridLayout *> &layouts);
0037     void setReferenceWidget(QWidget *refWidget);
0038 
0039 public Q_SLOTS:
0040     void updateLayouts();
0041     void align();
0042 
0043 private:
0044     int getLeftMargin(const QGridLayout *layout);
0045 
0046     static constexpr int LABELS_COLUMN = 0;
0047 
0048     QWidget *_refWidget;
0049     QVector<QGridLayout *> _layouts;
0050 };
0051 
0052 }
0053 
0054 #endif