Mercurial > hg > easyhg
comparison src/textabbrev.h @ 370:b9c153e00e84
Move source files to src/
author | Chris Cannam |
---|---|
date | Thu, 24 Mar 2011 10:27:51 +0000 |
parents | textabbrev.h@8fd71f570884 |
children | 533519ebc0cb |
comparison
equal
deleted
inserted
replaced
369:19cce6d2c470 | 370:b9c153e00e84 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 EasyMercurial | |
5 | |
6 Based on HgExplorer by Jari Korhonen | |
7 Copyright (c) 2010 Jari Korhonen | |
8 Copyright (c) 2011 Chris Cannam | |
9 Copyright (c) 2011 Queen Mary, University of London | |
10 | |
11 This program is free software; you can redistribute it and/or | |
12 modify it under the terms of the GNU General Public License as | |
13 published by the Free Software Foundation; either version 2 of the | |
14 License, or (at your option) any later version. See the file | |
15 COPYING included with this distribution for more information. | |
16 */ | |
17 | |
18 #ifndef _TEXT_ABBREV_H_ | |
19 #define _TEXT_ABBREV_H_ | |
20 | |
21 #include <QString> | |
22 #include <QStringList> | |
23 | |
24 class QFontMetrics; | |
25 | |
26 class TextAbbrev | |
27 { | |
28 public: | |
29 enum Policy { | |
30 ElideEnd, | |
31 ElideEndAndCommonPrefixes, | |
32 ElideStart, | |
33 ElideMiddle | |
34 }; | |
35 | |
36 /** | |
37 * Abbreviate the given text to the given maximum length | |
38 * (including ellipsis), using the given abbreviation policy. If | |
39 * fuzzy is true, the text will be left alone if it is "not much | |
40 * more than" the maximum length. | |
41 * | |
42 * If ellipsis is non-empty, it will be used to show elisions in | |
43 * preference to the default (which is "..."). | |
44 */ | |
45 static QString abbreviate(QString text, int maxLength, | |
46 Policy policy = ElideEnd, | |
47 bool fuzzy = true, | |
48 QString ellipsis = ""); | |
49 | |
50 /** | |
51 * Abbreviate the given text to the given maximum painted width, | |
52 * using the given abbreviation policy. maxWidth is also modified | |
53 * so as to return the painted width of the abbreviated text. | |
54 * | |
55 * If ellipsis is non-empty, it will be used to show elisions in | |
56 * preference to the default (which is tr("...")). | |
57 */ | |
58 static QString abbreviate(QString text, | |
59 const QFontMetrics &metrics, | |
60 int &maxWidth, | |
61 Policy policy = ElideEnd, | |
62 QString ellipsis = "", | |
63 int wrapLines = 1); | |
64 | |
65 /** | |
66 * Abbreviate all of the given texts to the given maximum length, | |
67 * using the given abbreviation policy. If fuzzy is true, texts | |
68 * that are "not much more than" the maximum length will be left | |
69 * alone. | |
70 * | |
71 * If ellipsis is non-empty, it will be used to show elisions in | |
72 * preference to the default (which is tr("...")). | |
73 */ | |
74 static QStringList abbreviate(const QStringList &texts, int maxLength, | |
75 Policy policy = ElideEndAndCommonPrefixes, | |
76 bool fuzzy = true, | |
77 QString ellipsis = ""); | |
78 | |
79 /** | |
80 * Abbreviate all of the given texts to the given maximum painted | |
81 * width, using the given abbreviation policy. maxWidth is also | |
82 * modified so as to return the maximum painted width of the | |
83 * abbreviated texts. | |
84 * | |
85 * If ellipsis is non-empty, it will be used to show elisions in | |
86 * preference to the default (which is tr("...")). | |
87 */ | |
88 static QStringList abbreviate(const QStringList &texts, | |
89 const QFontMetrics &metrics, | |
90 int &maxWidth, | |
91 Policy policy = ElideEndAndCommonPrefixes, | |
92 QString ellipsis = ""); | |
93 | |
94 protected: | |
95 static QString getDefaultEllipsis(); | |
96 static int getFuzzLength(QString ellipsis); | |
97 static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis); | |
98 static QString abbreviateTo(QString text, int characters, | |
99 Policy policy, QString ellipsis); | |
100 static QStringList elidePrefixes(const QStringList &texts, | |
101 int targetReduction, | |
102 QString ellipsis); | |
103 static QStringList elidePrefixes(const QStringList &texts, | |
104 const QFontMetrics &metrics, | |
105 int targetWidthReduction, | |
106 QString ellipsis); | |
107 static int getPrefixLength(const QStringList &texts); | |
108 }; | |
109 | |
110 #endif | |
111 |