Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/mixxxutils.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                         mixxxutils.cpp - generic utilities useful in multiple
00003                         --------------   disparate places
00004 
00005             copyright            : (C) 2010 by Sean Pappalardo
00006             email                : spappalardo@mixxx.org
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <QTime>
00019 
00020 class MixxxUtils {
00021   public:
00023     static inline QString secondsToMinutes(int totalSeconds, bool showMillis=false) {
00024         if (totalSeconds < 0)
00025             return "?";
00026         return millisecondsToMinutes(totalSeconds*1000, showMillis);
00027     }
00028 
00030     static inline QString millisecondsToMinutes(int totalMilliseconds, bool showMillis=false) {
00031         if (totalMilliseconds < 0)
00032             return "?";
00033         QTime t = QTime().addMSecs(totalMilliseconds);
00034         QString formatString = (t.hour() >= 1) ? "hh:mm:ss" : "mm:ss";
00035         if (showMillis)
00036             formatString = formatString.append(".zzz");
00037         QString timeString = t.toString(formatString);
00038         // The format string gives us one extra digit of millisecond precision than
00039         // we care about. Slice it off.
00040         if (showMillis)
00041             timeString = timeString.left(timeString.length() - 1);
00042         return timeString;
00043     }
00044 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines