@@ -231,7 +231,8 @@ class FilesModel : public QFileSystemModel
231
231
232
232
QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override
233
233
{
234
- const auto isDir = fileInfo (index ).isDir ();
234
+ const auto info = fileInfo (index );
235
+ const auto isDir = info.isDir ();
235
236
if (MediaTypeStringRole == role || (index .column () == 2 && Qt::DisplayRole == role)) {
236
237
QString names[] = {
237
238
tr (" Video" ),
@@ -245,18 +246,19 @@ class FilesModel : public QFileSystemModel
245
246
}
246
247
switch (role) {
247
248
case Qt::ToolTipRole:
248
- return QDir::toNativeSeparators (filePath (index ));
249
+ return QDir::toNativeSeparators (info. filePath ());
249
250
case DateRole:
250
- return fileInfo ( index ) .lastModified ();
251
+ return info .lastModified ();
251
252
case MediaTypeRole:
252
253
return isDir ? PlaylistModel::Other : mediaType (index );
253
254
case ThumbnailRole: {
254
- const auto path = filePath (index );
255
+ const auto path = info. filePath ();
255
256
const auto thumbnailKey = FilesThumbnailTask::cacheKey (path);
256
257
auto image = DB.getThumbnail (thumbnailKey);
257
258
if (image.isNull ()) {
258
259
::cacheThumbnail (const_cast <FilesModel *>(this ), path, image, index);
259
- if (!path.endsWith (QStringLiteral (" .mlt" ), Qt::CaseInsensitive))
260
+ if (!path.endsWith (QStringLiteral (" .mlt" ), Qt::CaseInsensitive)
261
+ && !info.isShortcut ())
260
262
QThreadPool::globalInstance ()->start (
261
263
new FilesThumbnailTask (const_cast <FilesModel *>(this ), path, index ));
262
264
}
@@ -385,11 +387,13 @@ class FilesTileDelegate : public QStyledItemDelegate
385
387
}
386
388
387
389
auto thumbRect = thumb.rect ();
388
- const float width = qRound (16 .f / 9 .f * option.rect .height ());
389
- thumbRect = QRect (0 , 0 , width, qRound (width * thumbRect.height () / thumbRect.width ()));
390
- thumbRect.moveCenter (option.rect .center ());
391
- thumbRect.moveLeft (0 );
392
- painter->drawImage (thumbRect, thumb);
390
+ if (thumbRect.width () > 0 ) {
391
+ const float width = qRound (16 .f / 9 .f * option.rect .height ());
392
+ thumbRect = QRect (0 , 0 , width, qRound (width * thumbRect.height () / thumbRect.width ()));
393
+ thumbRect.moveCenter (option.rect .center ());
394
+ thumbRect.moveLeft (0 );
395
+ painter->drawImage (thumbRect, thumb);
396
+ }
393
397
auto textRect = option.rect ;
394
398
textRect.setHeight (lineHeight * 3 + kTilePaddingPx );
395
399
textRect.moveCenter (option.rect .center ());
@@ -398,10 +402,9 @@ class FilesTileDelegate : public QStyledItemDelegate
398
402
QPoint textPoint = textRect.topLeft ();
399
403
textPoint.setY (textPoint.y () + lineHeight);
400
404
painter->setFont (boldFont);
401
- painter->drawText (textPoint,
402
- painter->fontMetrics ().elidedText (fileInfo.fileName (),
403
- Qt::ElideMiddle,
404
- textRect.width ()));
405
+ auto name = fileInfo.isShortcut () ? fileInfo.baseName () : fileInfo.fileName ();
406
+ name = painter->fontMetrics ().elidedText (name, Qt::ElideMiddle, textRect.width ());
407
+ painter->drawText (textPoint, name);
405
408
painter->setFont (oldFont);
406
409
407
410
textPoint.setY (textPoint.y () + lineHeight);
@@ -411,11 +414,11 @@ class FilesTileDelegate : public QStyledItemDelegate
411
414
.toDateTime ()
412
415
.toString (" yyyy-MM-dd HH:mm:ss" )));
413
416
textPoint.setY (textPoint.y () + lineHeight);
414
- if (! fileInfo.isDir ()) {
417
+ if (fileInfo.isFile ()) {
415
418
// Get the text of the second (size) column
416
419
auto myindex = index .model ()->index (index .row (), 1 , index .parent ());
417
- auto mediaType = myindex.data (Qt::DisplayRole).toString ();
418
- painter->drawText (textPoint, tr (" Size: %1" ).arg (mediaType ));
420
+ auto size = myindex.data (Qt::DisplayRole).toString ();
421
+ painter->drawText (textPoint, tr (" Size: %1" ).arg (size ));
419
422
}
420
423
}
421
424
@@ -682,19 +685,12 @@ FilesDock::FilesDock(QWidget *parent)
682
685
ui->tableView ->horizontalHeader ()->setSectionsMovable (true );
683
686
ui->tableView ->setColumnWidth (1 , 100 );
684
687
connect (ui->tableView , &QAbstractItemView::activated, this , [=](const QModelIndex &index ) {
685
- auto sourceIndex = m_filesProxyModel->mapToSource (index );
686
- auto filePath = m_filesModel->filePath (sourceIndex);
688
+ const auto sourceIndex = m_filesProxyModel->mapToSource (index );
689
+ const auto filePath = m_filesModel->filePath (sourceIndex);
687
690
688
691
LOG_DEBUG () << " activated" << filePath;
689
692
if (m_filesModel->isDir (sourceIndex)) {
690
- m_filesModel->setRootPath (filePath);
691
- Settings.setFilesCurrentDir (filePath);
692
- changeFilesDirectory (index );
693
- m_view->setCurrentIndex (QModelIndex ());
694
- const auto dirsIndex = m_dirsModel->index (filePath);
695
- ui->treeView ->setExpanded (dirsIndex, true );
696
- ui->treeView ->scrollTo (dirsIndex);
697
- ui->treeView ->setCurrentIndex (dirsIndex);
693
+ changeDirectory (filePath);
698
694
return ;
699
695
}
700
696
m_selectionModel->setCurrentIndex (index , QItemSelectionModel::SelectCurrent);
@@ -1106,7 +1102,8 @@ void FilesDock::changeDirectory(const QString &filePath, bool updateLocation)
1106
1102
}
1107
1103
index = m_filesModel->setRootPath (path);
1108
1104
Settings.setFilesCurrentDir (path);
1109
- ui->locationsCombo ->setToolTip (QDir::toNativeSeparators (path));
1105
+ path = QDir::toNativeSeparators (path);
1106
+ ui->locationsCombo ->setToolTip (path);
1110
1107
if (updateLocation && path != ui->locationsCombo ->currentText ())
1111
1108
ui->locationsCombo ->setCurrentText (path);
1112
1109
m_view->setRootIndex (m_filesProxyModel->mapFromSource (index ));
0 commit comments