2019-08-10 13:47:17 +02:00
|
|
|
#include "Helpers.hpp"
|
|
|
|
|
2021-03-06 15:03:33 +01:00
|
|
|
#include <QLocale>
|
2019-08-10 13:47:17 +02:00
|
|
|
#include <QUuid>
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-08-10 13:47:17 +02:00
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString generateUuid()
|
2019-08-10 13:47:17 +02:00
|
|
|
{
|
|
|
|
auto uuid = QUuid::createUuid();
|
|
|
|
return uuid.toString();
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString formatRichLink(const QString &url, bool file)
|
2019-08-10 13:47:17 +02:00
|
|
|
{
|
|
|
|
return QString("<a href=\"") + (file ? "file:///" : "") + url + "\">" +
|
|
|
|
url + "</a>";
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString formatRichNamedLink(const QString &url, const QString &name, bool file)
|
2019-08-10 13:47:17 +02:00
|
|
|
{
|
|
|
|
return QString("<a href=\"") + (file ? "file:///" : "") + url + "\">" +
|
|
|
|
name + "</a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString shortenString(const QString &str, unsigned maxWidth)
|
|
|
|
{
|
|
|
|
auto shortened = QString(str);
|
|
|
|
|
|
|
|
if (str.size() > int(maxWidth))
|
|
|
|
{
|
|
|
|
shortened.resize(int(maxWidth));
|
|
|
|
shortened += "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
return shortened;
|
|
|
|
}
|
|
|
|
|
2021-03-06 15:03:33 +01:00
|
|
|
QString localizeNumbers(const int &number)
|
|
|
|
{
|
|
|
|
QLocale locale;
|
|
|
|
return locale.toString(number);
|
|
|
|
}
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|