annotate textabbrev.h @ 50:c76782c14371

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