annotate widgets/TextAbbrev.h @ 652:35c3323a78a2 tonioni

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