TextAbbrev.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2007 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_TEXT_ABBREV_H
17 #define SV_TEXT_ABBREV_H
18 
19 #include <QString>
20 #include <QStringList>
21 
22 class QFontMetrics;
23 
24 class TextAbbrev
25 {
26 public:
27  enum Policy {
32  };
33 
43  static QString abbreviate(QString text, int maxLength,
44  Policy policy = ElideEnd,
45  bool fuzzy = true,
46  QString ellipsis = "");
47 
56  static QString abbreviate(QString text,
57  const QFontMetrics &metrics,
58  int &maxWidth,
59  Policy policy = ElideEnd,
60  QString ellipsis = "");
61 
71  static QStringList abbreviate(const QStringList &texts, int maxLength,
73  bool fuzzy = true,
74  QString ellipsis = "");
75 
85  static QStringList abbreviate(const QStringList &texts,
86  const QFontMetrics &metrics,
87  int &maxWidth,
89  QString ellipsis = "");
90 
91 protected:
92  static QString getDefaultEllipsis();
93  static int getFuzzLength(QString ellipsis);
94  static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis);
95  static QString abbreviateTo(QString text, int characters,
96  Policy policy, QString ellipsis);
97  static QStringList elidePrefixes(const QStringList &texts,
98  int targetReduction,
99  QString ellipsis);
100  static QStringList elidePrefixes(const QStringList &texts,
101  const QFontMetrics &metrics,
102  int targetWidthReduction,
103  QString ellipsis);
104  static int getPrefixLength(const QStringList &texts);
105 };
106 
107 #endif
108 
static int getFuzzLength(QString ellipsis)
Definition: TextAbbrev.cpp:30
static QString getDefaultEllipsis()
Definition: TextAbbrev.cpp:24
static QString abbreviateTo(QString text, int characters, Policy policy, QString ellipsis)
Definition: TextAbbrev.cpp:51
static QString abbreviate(QString text, int maxLength, Policy policy=ElideEnd, bool fuzzy=true, QString ellipsis="")
Abbreviate the given text to the given maximum length (including ellipsis), using the given abbreviat...
Definition: TextAbbrev.cpp:79
static QStringList elidePrefixes(const QStringList &texts, int targetReduction, QString ellipsis)
Definition: TextAbbrev.cpp:189
static int getPrefixLength(const QStringList &texts)
Definition: TextAbbrev.cpp:250
static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis)
Definition: TextAbbrev.cpp:39