annotate base/TextAbbrev.h @ 313:29485aa03da4

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