Chris@50: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@50: Chris@50: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 Queen Mary, University of London Chris@50: Chris@50: This program is free software; you can redistribute it and/or Chris@50: modify it under the terms of the GNU General Public License as Chris@50: published by the Free Software Foundation; either version 2 of the Chris@50: License, or (at your option) any later version. See the file Chris@50: COPYING included with this distribution for more information. Chris@50: */ Chris@50: Chris@50: #ifndef _TEXT_ABBREV_H_ Chris@50: #define _TEXT_ABBREV_H_ Chris@50: Chris@50: #include Chris@50: #include Chris@50: Chris@50: class QFontMetrics; Chris@50: Chris@50: class TextAbbrev Chris@50: { Chris@50: public: Chris@50: enum Policy { Chris@50: ElideEnd, Chris@50: ElideEndAndCommonPrefixes, Chris@50: ElideStart, Chris@50: ElideMiddle Chris@50: }; Chris@50: Chris@50: /** Chris@50: * Abbreviate the given text to the given maximum length Chris@50: * (including ellipsis), using the given abbreviation policy. If Chris@50: * fuzzy is true, the text will be left alone if it is "not much Chris@50: * more than" the maximum length. Chris@50: * Chris@50: * If ellipsis is non-empty, it will be used to show elisions in Chris@50: * preference to the default (which is "..."). Chris@50: */ Chris@50: static QString abbreviate(QString text, int maxLength, Chris@50: Policy policy = ElideEnd, Chris@50: bool fuzzy = true, Chris@50: QString ellipsis = ""); Chris@50: Chris@50: /** Chris@50: * Abbreviate the given text to the given maximum painted width, Chris@50: * using the given abbreviation policy. maxWidth is also modified Chris@50: * so as to return the painted width of the abbreviated text. Chris@50: * Chris@50: * If ellipsis is non-empty, it will be used to show elisions in Chris@50: * preference to the default (which is tr("...")). Chris@50: */ Chris@50: static QString abbreviate(QString text, Chris@50: const QFontMetrics &metrics, Chris@50: int &maxWidth, Chris@50: Policy policy = ElideEnd, Chris@53: QString ellipsis = "", Chris@53: int wrapLines = 1); Chris@50: Chris@50: /** Chris@50: * Abbreviate all of the given texts to the given maximum length, Chris@50: * using the given abbreviation policy. If fuzzy is true, texts Chris@50: * that are "not much more than" the maximum length will be left Chris@50: * alone. Chris@50: * Chris@50: * If ellipsis is non-empty, it will be used to show elisions in Chris@50: * preference to the default (which is tr("...")). Chris@50: */ Chris@50: static QStringList abbreviate(const QStringList &texts, int maxLength, Chris@50: Policy policy = ElideEndAndCommonPrefixes, Chris@50: bool fuzzy = true, Chris@50: QString ellipsis = ""); Chris@50: Chris@50: /** Chris@50: * Abbreviate all of the given texts to the given maximum painted Chris@50: * width, using the given abbreviation policy. maxWidth is also Chris@50: * modified so as to return the maximum painted width of the Chris@50: * abbreviated texts. Chris@50: * Chris@50: * If ellipsis is non-empty, it will be used to show elisions in Chris@50: * preference to the default (which is tr("...")). Chris@50: */ Chris@50: static QStringList abbreviate(const QStringList &texts, Chris@50: const QFontMetrics &metrics, Chris@50: int &maxWidth, Chris@50: Policy policy = ElideEndAndCommonPrefixes, Chris@50: QString ellipsis = ""); Chris@50: Chris@50: protected: Chris@50: static QString getDefaultEllipsis(); Chris@50: static int getFuzzLength(QString ellipsis); Chris@50: static int getFuzzWidth(const QFontMetrics &metrics, QString ellipsis); Chris@50: static QString abbreviateTo(QString text, int characters, Chris@50: Policy policy, QString ellipsis); Chris@50: static QStringList elidePrefixes(const QStringList &texts, Chris@50: int targetReduction, Chris@50: QString ellipsis); Chris@50: static QStringList elidePrefixes(const QStringList &texts, Chris@50: const QFontMetrics &metrics, Chris@50: int targetWidthReduction, Chris@50: QString ellipsis); Chris@50: static int getPrefixLength(const QStringList &texts); Chris@50: }; Chris@50: Chris@50: #endif Chris@50: