ICF 3.1.1.10
Technical documentation of ICF Libraries
CTextElider.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#ifndef iwidgets_CTextElider_included
7#define iwidgets_CTextElider_included
8
9
10// Qt includes
11#include <QtCore/QObject>
12#include <QtCore/QString>
13#include <QtCore/QMap>
14#include <QtCore/QTimer>
15
16
17namespace iwidgets
18{
19
20
21/*
22 Helper class to control visual text behavoir during resizing of widgets, which contain text representation
23 (e.g. QAbstractButton, QLineEdit, etc.).
24 If the widget size is smaller than the size of the text, the text will be croped and shown with a specified suffix.
25 For example the text "blablabla" will be shown as "blabl...".
26 You can register multiple widget objects by the text elider with the method RegisterElideObject().
27 If you want specifiy your own elide suffix, use SetElideSuffix() method.
28*/
29class CTextElider: public QObject
30{
31 Q_OBJECT
32public:
33 explicit CTextElider(QObject* parentPtr = nullptr);
34 virtual ~CTextElider();
35
36 bool RegisterElideObject(QObject* elideObject);
37 void UnregisterElideObject(QObject* elideObject);
39 void SetUpdateInterval(int updateInterval = 300);
40 void SetElideSuffix(QString elideSuffix);
41 QString GetElideSuffix() const;
42
43protected:
44 // reimplemented (QObject)
45 virtual bool eventFilter(QObject* objectPtr, QEvent* eventPtr);
46
47private:
48 void UpdateElidedText(QObject& elideObject);
49
50 void OnTimeout();
51
52private Q_SLOTS:
53 void OnObjectDestroyed(QObject* objectPtr);
54
55private:
56 struct ElideObjectInfo
57 {
58 QString baseString;
59 QString elideString;
60 };
61
62 typedef QMap<QObject*, ElideObjectInfo> ElideObjectsMap;
63 ElideObjectsMap m_objectPtrMap;
64
65 QTimer m_textObservingTimer;
66 int m_updateInterval;
67 QString m_elideSuffix;
68};
69
70
71} // namespace iwidgets
72
73
74#endif // !iwidgets_CTextElider_included
75
76
CTextElider(QObject *parentPtr=nullptr)
void UnregisterAllElideObjects()
QString GetElideSuffix() const
virtual bool eventFilter(QObject *objectPtr, QEvent *eventPtr)
void UnregisterElideObject(QObject *elideObject)
void SetElideSuffix(QString elideSuffix)
bool RegisterElideObject(QObject *elideObject)
void SetUpdateInterval(int updateInterval=300)
Namespace contains implementation of Qt widget extensions.

© Witold Gantzke and Kirill Lepskiy