annotate textabbrev.h @ 53:3c46b2ac45d3

* Put proper labels &c in changeset items; colour branches and users; etc
author Chris Cannam
date Fri, 12 Nov 2010 16:48:18 +0000
parents c76782c14371
children f583e44d9d31
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@53 60 QString ellipsis = "",
Chris@53 61 int wrapLines = 1);
Chris@50 62
Chris@50 63 /**
Chris@50 64 * Abbreviate all of the given texts to the given maximum length,
Chris@50 65 * using the given abbreviation policy. If fuzzy is true, texts
Chris@50 66 * that are "not much more than" the maximum length will be left
Chris@50 67 * alone.
Chris@50 68 *
Chris@50 69 * If ellipsis is non-empty, it will be used to show elisions in
Chris@50 70 * preference to the default (which is tr("...")).
Chris@50 71 */
Chris@50 72 static QStringList abbreviate(const QStringList &texts, int maxLength,
Chris@50 73 Policy policy = ElideEndAndCommonPrefixes,
Chris@50 74 bool fuzzy = true,
Chris@50 75 QString ellipsis = "");
Chris@50 76
Chris@50 77 /**
Chris@50 78 * Abbreviate all of the given texts to the given maximum painted
Chris@50 79 * width, using the given abbreviation policy. maxWidth is also
Chris@50 80 * modified so as to return the maximum painted width of the
Chris@50 81 * abbreviated texts.
Chris@50 82 *
Chris@50 83 * If ellipsis is non-empty, it will be used to show elisions in
Chris@50 84 * preference to the default (which is tr("...")).
Chris@50 85 */
Chris@50 86 static QStringList abbreviate(const QStringList &texts,
Chris@50 87 const QFontMetrics &metrics,
Chris@50 88 int &maxWidth,
Chris@50 89 Policy policy = ElideEndAndCommonPrefixes,
Chris@50 90 QString ellipsis = "");
Chris@50 91
Chris@50 92 protected:
Chris@50 93 static QString getDefaultEllipsis();
Chris@50 94 static int getFuzzLength(QString ellipsis);
Chris@50 95 static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis);
Chris@50 96 static QString abbreviateTo(QString text, int characters,
Chris@50 97 Policy policy, QString ellipsis);
Chris@50 98 static QStringList elidePrefixes(const QStringList &texts,
Chris@50 99 int targetReduction,
Chris@50 100 QString ellipsis);
Chris@50 101 static QStringList elidePrefixes(const QStringList &texts,
Chris@50 102 const QFontMetrics &metrics,
Chris@50 103 int targetWidthReduction,
Chris@50 104 QString ellipsis);
Chris@50 105 static int getPrefixLength(const QStringList &texts);
Chris@50 106 };
Chris@50 107
Chris@50 108 #endif
Chris@50 109