CTextElider.h
Go to the documentation of this file.
1 #ifndef iwidgets_CTextElider_included
2 #define iwidgets_CTextElider_included
3 
4 
5 // Qt includes
6 #include <QtCore/QObject>
7 #include <QtCore/QString>
8 #include <QtCore/QMap>
9 #include <QtCore/QTimer>
10 
11 
12 namespace 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 */
24 class CTextElider: public QObject
25 {
26 public:
27  explicit CTextElider(QObject* parentPtr = NULL);
28  virtual ~CTextElider();
29 
30  bool RegisterElideObject(QObject* elideObject);
31  void UnregisterElideObject(QObject* elideObject);
33  void SetUpdateInterval(int updateInterval = 300);
34  void SetElideSuffix(QString elideSuffix);
35  QString GetElideSuffix() const;
36 
37 protected:
38  // reimplemented (QObject)
39  virtual bool eventFilter(QObject* objectPtr, QEvent* eventPtr);
40 
41 private:
42  void UpdateElidedText(QObject& elideObject);
43 
44  void OnTimeout();
45 
46 private:
47  struct ElideObjectInfo
48  {
49  QString baseString;
50  QString elideString;
51  };
52 
53  typedef QMap<QObject*, ElideObjectInfo> ElideObjectsMap;
54  ElideObjectsMap m_objectPtrMap;
55 
56  QTimer m_textObservingTimer;
57  int m_updateInterval;
58  QString m_elideSuffix;
59 };
60 
61 
62 } // namespace iwidgets
63 
64 
65 #endif // !iwidgets_CTextElider_included
66 
67 
CTextElider(QObject *parentPtr=NULL)
void SetElideSuffix(QString elideSuffix)
void UnregisterElideObject(QObject *elideObject)
QString GetElideSuffix() const
void UnregisterAllElideObjects()
void SetUpdateInterval(int updateInterval=300)
virtual bool eventFilter(QObject *objectPtr, QEvent *eventPtr)
#define NULL
Definition: istd.h:64
bool RegisterElideObject(QObject *elideObject)

© 2007-2017 Witold Gantzke and Kirill Lepskiy