0.2.0 finalization

This commit is contained in:
Blue 2022-01-09 17:32:23 +03:00
parent 8a2658e4fc
commit 4d3ba6b11f
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
12 changed files with 194 additions and 179 deletions

View file

@ -25,9 +25,8 @@ constexpr int maxAttachmentHeight = 500;
QFont Preview::font;
QFontMetrics Preview::metrics(Preview::font);
Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos, bool pRight, QWidget* pParent):
Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos, QWidget* pParent):
info(Shared::Global::getFileInfo(pPath)),
path(pPath),
maxSize(pMaxSize),
actualSize(constrainAttachSize(info.size, maxSize)),
cachedLabelSize(0, 0),
@ -37,8 +36,7 @@ Preview::Preview(const QString& pPath, const QSize& pMaxSize, const QPoint& pos,
parent(pParent),
movie(0),
fileReachable(true),
actualPreview(false),
right(pRight)
actualPreview(false)
{
initializeElements();
@ -104,9 +102,6 @@ void Preview::actualize(const QString& newPath, const QSize& newSize, const QPoi
}
} else if (maxSizeChanged) {
applyNewMaxSize();
if (right) {
positionChanged = true;
}
}
if (positionChanged || !actualPreview) {
positionElements();
@ -135,9 +130,6 @@ void Preview::setSize(const QSize& newSize)
}
if (maxSizeChanged || !actualPreview) {
applyNewMaxSize();
if (right) {
positionElements();
}
}
}
}
@ -146,7 +138,7 @@ void Preview::applyNewSize()
{
switch (info.preview) {
case Shared::Global::FileInfo::Preview::picture: {
QImageReader img(path);
QImageReader img(info.path);
if (!img.canRead()) {
delete widget;
fileReachable = false;
@ -216,9 +208,8 @@ void Preview::setPosition(const QPoint& newPoint)
bool Preview::setPath(const QString& newPath)
{
if (path != newPath) {
path = newPath;
info = Shared::Global::getFileInfo(path);
if (info.path != newPath) {
info = Shared::Global::getFileInfo(newPath);
actualSize = constrainAttachSize(info.size, maxSize);
clean();
initializeElements();
@ -235,7 +226,7 @@ void Preview::initializeElements()
{
switch (info.preview) {
case Shared::Global::FileInfo::Preview::picture: {
QImageReader img(path);
QImageReader img(info.path);
if (!img.canRead()) {
fileReachable = false;
} else {
@ -248,7 +239,7 @@ void Preview::initializeElements()
}
break;
case Shared::Global::FileInfo::Preview::animation:{
movie = new QMovie(path);
movie = new QMovie(info.path);
QObject::connect(movie, &QMovie::error,
std::bind(&Preview::handleQMovieError, this, std::placeholders::_1)
);
@ -289,9 +280,6 @@ void Preview::initializeElements()
void Preview::positionElements()
{
int start = position.x();
if (right) {
start += maxSize.width() - size().width();
}
widget->move(start, position.y());
if (!actualPreview) {
int x = start + actualSize.width() + margin;
@ -300,11 +288,36 @@ void Preview::positionElements()
}
}
bool Preview::canVisualize(const Shared::Global::FileInfo& info)
{
switch (info.preview) {
case Shared::Global::FileInfo::Preview::picture: {
QImageReader img(info.path);
return img.canRead();
}
break;
case Shared::Global::FileInfo::Preview::animation:{
QMovie movie(info.path);
return movie.isValid();
}
break;
default: {
return false;
}
}
}
QSize Preview::calculateAttachSize(const QString& path, const QRect& bounds)
{
Shared::Global::FileInfo info = Shared::Global::getFileInfo(path);
return constrainAttachSize(info.size, bounds.size());
QSize constrained = constrainAttachSize(info.size, bounds.size());
if (!canVisualize(info)) {
int maxLabelWidth = bounds.width() - info.size.width() - margin;
QString elidedName = metrics.elidedText(info.name, Qt::ElideMiddle, maxLabelWidth);
int labelWidth = metrics.boundingRect(elidedName).size().width();
constrained.rwidth() += margin + labelWidth;
}
return constrained;
}
QSize Preview::constrainAttachSize(QSize src, QSize bounds)