1 /* 2 This file is part of Lokalize 3 4 SPDX-FileCopyrightText: 2007 Nick Shaforostoff <shafff@ukr.net> 5 SPDX-FileCopyrightText: 2004-2007 Trolltech ASA. All rights reserved. 6 SPDX-FileCopyrightText: 2018-2019 Simon Depiets <sdepiets@gmail.com> 7 8 SPDX-License-Identifier: GPL-2.0-or-later WITH LicenseRef-Qt-Commercial-exception-1.0 9 */ 10 #ifndef FLOWLAYOUT_H 11 #define FLOWLAYOUT_H 12 13 #include "glossary.h" 14 15 #include <QLayout> 16 #include <QVector> 17 class QAction; 18 19 /** 20 * used in glossary and kross views 21 * 22 * copied from 'pretty' docs 23 */ 24 class FlowLayout: public QLayout 25 { 26 public: 27 28 enum User { 29 glossary, 30 webquery, 31 standard 32 }; 33 34 /** 35 * c'tor for glossary view 36 */ 37 explicit FlowLayout(User user = standard, QWidget *signalingWidget = nullptr, 38 const QVector<QAction*>& actions = QVector<QAction*>(), int margin = 0, int spacing = -1); 39 40 ~FlowLayout() override; 41 42 void addItem(QLayoutItem *item) override; 43 Qt::Orientations expandingDirections() const override; 44 bool hasHeightForWidth() const override; 45 int heightForWidth(int) const override; 46 int count() const override; 47 QLayoutItem *itemAt(int index) const override; 48 QSize minimumSize() const override; 49 void setGeometry(const QRect &rect) override; 50 QSize sizeHint() const override; 51 QLayoutItem *takeAt(int index) override; 52 53 /** 54 * @param term is the term matched 55 * @param entryId is index of entry in the Glossary list 56 * @param capFirst whether the first letter should be capitalized 57 */ 58 void addTerm(const QString& term, const QByteArray& entryId, bool capFirst = false); 59 void clearTerms(); 60 61 private: 62 int doLayout(const QRect &rect, bool testOnly) const; 63 64 QList<QLayoutItem *> itemList; 65 int m_index; //of the nearest free label ; or the next index of btn 66 QWidget *m_receiver; 67 }; 68 69 70 #endif 71