Mercurial > hg > svcore
comparison base/TextAbbrev.h @ 286:20097c32d15d
* Better abbreviation modes for layer names in pane (and input model combo
of plugin parameter dialog)
* Avoid crash when loading SV file containing model derived from nonexistent
model (shouldn't happen of course, but see bug #1771769)
* Remember last-used input model in plugin parameter dialog
* Don't override a layer colour loaded from a session file with the generated
default colour when attaching it to a view
author | Chris Cannam |
---|---|
date | Fri, 10 Aug 2007 16:36:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
285:20028c634494 | 286:20097c32d15d |
---|---|
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 _TEXT_ABBREV_H_ | |
17 #define _TEXT_ABBREV_H_ | |
18 | |
19 #include <QString> | |
20 #include <QStringList> | |
21 | |
22 class QFontMetrics; | |
23 | |
24 class TextAbbrev | |
25 { | |
26 public: | |
27 enum Policy { | |
28 ElideEnd, | |
29 ElideEndAndCommonPrefixes, | |
30 ElideStart, | |
31 ElideMiddle | |
32 }; | |
33 | |
34 /** | |
35 * Abbreviate the given text to the given maximum length | |
36 * (including ellipsis), using the given abbreviation policy. If | |
37 * fuzzy is true, the text will be left alone if it is "not much | |
38 * more than" the maximum length. | |
39 * | |
40 * If ellipsis is non-empty, it will be used to show elisions in | |
41 * preference to the default (which is "..."). | |
42 */ | |
43 static QString abbreviate(QString text, int maxLength, | |
44 Policy policy = ElideEnd, | |
45 bool fuzzy = true, | |
46 QString ellipsis = ""); | |
47 | |
48 /** | |
49 * Abbreviate the given text to the given maximum painted width, | |
50 * using the given abbreviation policy. maxWidth is also modified | |
51 * so as to return the painted width of the abbreviated text. | |
52 * | |
53 * If ellipsis is non-empty, it will be used to show elisions in | |
54 * preference to the default (which is tr("...")). | |
55 */ | |
56 static QString abbreviate(QString text, | |
57 const QFontMetrics &metrics, | |
58 int &maxWidth, | |
59 Policy policy = ElideEnd, | |
60 QString ellipsis = ""); | |
61 | |
62 /** | |
63 * Abbreviate all of the given texts to the given maximum length, | |
64 * using the given abbreviation policy. If fuzzy is true, texts | |
65 * that are "not much more than" the maximum length will be left | |
66 * alone. | |
67 * | |
68 * If ellipsis is non-empty, it will be used to show elisions in | |
69 * preference to the default (which is tr("...")). | |
70 */ | |
71 static QStringList abbreviate(const QStringList &texts, int maxLength, | |
72 Policy policy = ElideEndAndCommonPrefixes, | |
73 bool fuzzy = true, | |
74 QString ellipsis = ""); | |
75 | |
76 /** | |
77 * Abbreviate all of the given texts to the given maximum painted | |
78 * width, using the given abbreviation policy. maxWidth is also | |
79 * modified so as to return the maximum painted width of the | |
80 * abbreviated texts. | |
81 * | |
82 * If ellipsis is non-empty, it will be used to show elisions in | |
83 * preference to the default (which is tr("...")). | |
84 */ | |
85 static QStringList abbreviate(const QStringList &texts, | |
86 const QFontMetrics &metrics, | |
87 int &maxWidth, | |
88 Policy policy = ElideEndAndCommonPrefixes, | |
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 |