source: trunk/qt/Formatter.h @ 14540

Last change on this file since 14540 was 14540, checked in by mikedld, 6 years ago

Instead of standard C headers include their C++ counterparts

  • Property svn:keywords set to Date Rev Author Id
File size: 1.1 KB
Line 
1/*
2 * This file Copyright (C) 2012-2015 Mnemosyne LLC
3 *
4 * It may be used under the GNU GPL versions 2 or 3
5 * or any future license endorsed by Mnemosyne LLC.
6 *
7 * $Id: Formatter.h 14540 2015-06-12 22:41:36Z mikedld $
8 */
9
10#ifndef QTR_FORMATTER_H
11#define QTR_FORMATTER_H
12
13#include <cstdint> // int64_t
14
15#include <QCoreApplication>
16#include <QString>
17
18class Speed;
19
20class Formatter
21{
22    Q_DECLARE_TR_FUNCTIONS (Formatter)
23
24  public:
25    enum Size
26    {
27      B,
28      KB,
29      MB,
30      GB,
31      TB
32    };
33
34    enum Type
35    {
36      SPEED,
37      SIZE,
38      MEM
39    };
40
41  public:
42    static QString memToString (int64_t bytes);
43    static QString sizeToString (int64_t bytes);
44    static QString speedToString (const Speed& speed);
45    static QString percentToString (double x);
46    static QString ratioToString (double ratio);
47    static QString timeToString (int seconds);
48    static QString uploadSpeedToString (const Speed& up);
49    static QString downloadSpeedToString (const Speed& down);
50
51    static QString unitStr (Type t, Size s) { return unitStrings[t][s]; }
52    static void initUnits ();
53
54  private:
55    static QString unitStrings[3][5];
56};
57
58#endif // QTR_FORMATTER_H
Note: See TracBrowser for help on using the repository browser.