svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006-2007 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _TEXT_ABBREV_H_ 00017 #define _TEXT_ABBREV_H_ 00018 00019 #include <QString> 00020 #include <QStringList> 00021 00022 class QFontMetrics; 00023 00024 class TextAbbrev 00025 { 00026 public: 00027 enum Policy { 00028 ElideEnd, 00029 ElideEndAndCommonPrefixes, 00030 ElideStart, 00031 ElideMiddle 00032 }; 00033 00043 static QString abbreviate(QString text, int maxLength, 00044 Policy policy = ElideEnd, 00045 bool fuzzy = true, 00046 QString ellipsis = ""); 00047 00056 static QString abbreviate(QString text, 00057 const QFontMetrics &metrics, 00058 int &maxWidth, 00059 Policy policy = ElideEnd, 00060 QString ellipsis = ""); 00061 00071 static QStringList abbreviate(const QStringList &texts, int maxLength, 00072 Policy policy = ElideEndAndCommonPrefixes, 00073 bool fuzzy = true, 00074 QString ellipsis = ""); 00075 00085 static QStringList abbreviate(const QStringList &texts, 00086 const QFontMetrics &metrics, 00087 int &maxWidth, 00088 Policy policy = ElideEndAndCommonPrefixes, 00089 QString ellipsis = ""); 00090 00091 protected: 00092 static QString getDefaultEllipsis(); 00093 static int getFuzzLength(QString ellipsis); 00094 static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis); 00095 static QString abbreviateTo(QString text, int characters, 00096 Policy policy, QString ellipsis); 00097 static QStringList elidePrefixes(const QStringList &texts, 00098 int targetReduction, 00099 QString ellipsis); 00100 static QStringList elidePrefixes(const QStringList &texts, 00101 const QFontMetrics &metrics, 00102 int targetWidthReduction, 00103 QString ellipsis); 00104 static int getPrefixLength(const QStringList &texts); 00105 }; 00106 00107 #endif 00108