ACF $AcfVersion:0$
CTextElider.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QObject>
7#include <QtCore/QString>
8#include <QtCore/QMap>
9#include <QtCore/QTimer>
10
11
12namespace iwidgets
13{
14
15
16/*
17 Helper class to control visual text behavoir during resizing of widgets, which contain text representation
18 (e.g. QAbstractButton, QLineEdit, etc.).
19 If the widget size is smaller than the size of the text, the text will be croped and shown with a specified suffix.
20 For example the text "blablabla" will be shown as "blabl...".
21 You can register multiple widget objects by the text elider with the method RegisterElideObject().
22 If you want specifiy your own elide suffix, use SetElideSuffix() method.
23*/
24class CTextElider: public QObject
25{
26 Q_OBJECT
27public:
28 explicit CTextElider(QObject* parentPtr = NULL);
29 virtual ~CTextElider();
30
31 bool RegisterElideObject(QObject* elideObject);
32 void UnregisterElideObject(QObject* elideObject);
34 void SetUpdateInterval(int updateInterval = 300);
35 void SetElideSuffix(QString elideSuffix);
36 QString GetElideSuffix() const;
37
38protected:
39 // reimplemented (QObject)
40 virtual bool eventFilter(QObject* objectPtr, QEvent* eventPtr) override;
41
42private:
43 void UpdateElidedText(QObject& elideObject);
44
45 void OnTimeout();
46
47private Q_SLOTS:
48 void OnObjectDestroyed(QObject* objectPtr);
49
50private:
51 struct ElideObjectInfo
52 {
53 QString baseString;
54 QString elideString;
55 };
56
57 typedef QMap<QObject*, ElideObjectInfo> ElideObjectsMap;
58 ElideObjectsMap m_objectPtrMap;
59
60 QTimer m_textObservingTimer;
61 int m_updateInterval;
62 QString m_elideSuffix;
63};
64
65
66} // namespace iwidgets
67
68
69
70
void UnregisterAllElideObjects()
virtual bool eventFilter(QObject *objectPtr, QEvent *eventPtr) override
QString GetElideSuffix() const
CTextElider(QObject *parentPtr=NULL)
void UnregisterElideObject(QObject *elideObject)
void SetElideSuffix(QString elideSuffix)
bool RegisterElideObject(QObject *elideObject)
void SetUpdateInterval(int updateInterval=300)
#define NULL
Definition istd.h:74
Namespace contains implementation of Qt widget extensions.