2018-01-05 01:27:32 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RoomInfoListItem.h"
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <mtx/events/collections.hpp>
|
|
|
|
|
|
|
|
namespace utils {
|
|
|
|
|
|
|
|
using TimelineEvent = mtx::events::collections::TimelineEvents;
|
|
|
|
|
|
|
|
//! Human friendly timestamp representation.
|
|
|
|
QString
|
|
|
|
descriptiveTime(const QDateTime &then);
|
|
|
|
|
|
|
|
//! Generate a message description from the event to be displayed
|
|
|
|
//! in the RoomList.
|
|
|
|
DescInfo
|
2018-04-21 16:34:50 +03:00
|
|
|
getMessageDescription(const TimelineEvent &event, const QString &localUser, const QString &room_id);
|
2018-01-12 11:21:53 +03:00
|
|
|
|
|
|
|
//! Get the first character of a string, taking into account that
|
|
|
|
//! surrogate pairs might be in use.
|
|
|
|
QString
|
|
|
|
firstChar(const QString &input);
|
2018-02-18 23:52:31 +03:00
|
|
|
|
|
|
|
//! Get a human readable file size with the appropriate units attached.
|
|
|
|
QString
|
2018-02-19 23:09:21 +03:00
|
|
|
humanReadableFileSize(uint64_t bytes);
|
2018-02-20 00:32:37 +03:00
|
|
|
|
|
|
|
//! Scale down an image to fit to the given width & height limitations.
|
|
|
|
template<class ImageType>
|
|
|
|
ImageType
|
|
|
|
scaleDown(uint64_t max_width, uint64_t max_height, const ImageType &source)
|
|
|
|
{
|
|
|
|
if (source.isNull())
|
2018-02-20 00:33:11 +03:00
|
|
|
return QPixmap();
|
2018-02-20 00:32:37 +03:00
|
|
|
|
|
|
|
auto width_ratio = (double)max_width / (double)source.width();
|
|
|
|
auto height_ratio = (double)max_height / (double)source.height();
|
|
|
|
|
|
|
|
auto min_aspect_ratio = std::min(width_ratio, height_ratio);
|
|
|
|
|
|
|
|
int final_width = 0;
|
|
|
|
int final_height = 0;
|
|
|
|
|
|
|
|
if (min_aspect_ratio > 1) {
|
|
|
|
final_width = source.width();
|
|
|
|
final_height = source.height();
|
|
|
|
} else {
|
|
|
|
final_width = source.width() * min_aspect_ratio;
|
|
|
|
final_height = source.height() * min_aspect_ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
return source.scaled(
|
|
|
|
final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
}
|
2018-03-25 00:16:15 +03:00
|
|
|
|
|
|
|
//! Calculate the Levenshtein distance between two strings with character skipping.
|
|
|
|
int
|
|
|
|
levenshtein_distance(const std::string &s1, const std::string &s2);
|
2018-01-05 01:27:32 +03:00
|
|
|
}
|