Skip to content

Commit

Permalink
Fixed overlay icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugen Fischer authored and Eugen Fischer committed Nov 27, 2023
1 parent 620548c commit 81f5f70
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
68 changes: 38 additions & 30 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,36 +271,44 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
return toolTip;
}
case FolderStatusDelegate::FolderStatusIconRole:{
auto theme = Theme::instance();
return theme->folderIcon();
}
// case FolderStatusDelegate::FolderOverlayIconRole:
// if (accountConnected) {
// auto theme = Theme::instance();
// auto status = f->syncResult().status();
// if (f->syncPaused()) {
// return theme->folderDisabledIcon();
// } else {
// if (status == SyncResult::SyncPrepare || status == SyncResult::Undefined) {
// return theme->syncStateIcon(SyncResult::SyncRunning);
// } else {
// // The "Problem" *result* just means some files weren't
// // synced, so we show "Success" in these cases. But we
// // do use the "Problem" *icon* for unresolved conflicts.
// if (status == SyncResult::Success || status == SyncResult::Problem) {
// if (f->syncResult().hasUnresolvedConflicts()) {
// return theme->syncStateIcon(SyncResult::Problem);
// } else {
// return theme->syncStateIcon(SyncResult::Success);
// }
// } else {
// return theme->syncStateIcon(status);
// }
// }
// }
// } else {
// return Theme::instance()->folderOfflineIcon();
// }
if (accountConnected) {
auto theme = Theme::instance();
if (f->syncPaused()) {
return theme->folderDisabledIcon();
} else {
return theme->folderIcon();
}
} else {
return Theme::instance()->folderOfflineIcon();
}
}
case FolderStatusDelegate::FolderOverlayIconRole:
if (accountConnected) {
auto theme = Theme::instance();
auto status = f->syncResult().status();
if (f->syncPaused()) {
return theme->folderDisabledIcon();
} else {
if (status == SyncResult::SyncPrepare || status == SyncResult::Undefined) {
return theme->syncStateIcon(SyncResult::SyncRunning);
} else {
// The "Problem" *result* just means some files weren't
// synced, so we show "Success" in these cases. But we
// do use the "Problem" *icon* for unresolved conflicts.
if (status == SyncResult::Success || status == SyncResult::Problem) {
if (f->syncResult().hasUnresolvedConflicts()) {
return theme->syncStateIcon(SyncResult::Problem);
} else {
return theme->syncStateIcon(SyncResult::Success);
}
} else {
return theme->syncStateIcon(status);
}
}
}
} else {
return Theme::instance()->folderOfflineIcon();
}
case FolderStatusDelegate::SyncProgressItemString:
return progress._progressString;
case FolderStatusDelegate::WarningCount:
Expand Down
32 changes: 20 additions & 12 deletions src/gui/nmcgui/nmcfolderstatusdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void NMCFolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewIte

//Use our logic if the button needs to be paited ->paint an icon instead. If not, then go to base class and paint everything else
if (index.data(AddButton).toBool()) {
painter->save();

QStyleOptionButton opt;
static_cast<QStyleOption &>(opt) = option;

Expand All @@ -64,7 +66,6 @@ void NMCFolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewIte
const auto topMargin = 8;
const auto leftMargin = 8;

painter->save();
auto addIconRect = opt.rect;
auto headRect = opt.rect;

Expand Down Expand Up @@ -105,31 +106,38 @@ void NMCFolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewIte
painter->drawText(QStyle::visualRect(option.direction, textRect, textRect), textAlign|Qt::TextWordWrap, textLine);

painter->restore();

return;
}
//This one is for customized folder icons
else if(index.data(FolderOverlayIconRole).isValid())
else{
FolderStatusDelegate::paint(painter, option, index);
}
//This one is for customized folder icons, the paint function in base class should be called before we draw the overlay icons,
//so the folders are below the overlay icons
if(index.data(FolderOverlayIconRole).isValid())
{
painter->save();

auto statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
auto syncEnabled = qvariant_cast<bool>(index.data(FolderAccountConnected));

auto iconRect = option.rect;
const auto iconSize = iconRect.width();
//const auto iconSize = iconRect.width();
const auto iconSize = 48;

iconRect.setTop(iconRect.top() + aliasMargin); // (iconRect.height()-iconsize.height())/2);
const auto statusPixmap = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
//const auto statusPixmap = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);

auto overlayIcon = qvariant_cast<QIcon>(index.data(FolderOverlayIconRole));
int ovlSize = 24;
auto ovlRect = iconRect;
// the overlay icon position depends on the (variable) status icon size
ovlRect.setTop(iconRect.top() + statusPixmap.height() - ovlSize - margin);
ovlRect.setLeft(iconRect.left() + statusPixmap.width() - ovlSize);
ovlRect.setTop(iconRect.top() + iconSize - 3*margin);
ovlRect.setLeft(iconRect.left() + iconSize - margin);
QPixmap opm = overlayIcon.pixmap(ovlSize, ovlSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, ovlRect).left(),
ovlRect.top(), opm);
}
else{
FolderStatusDelegate::paint(painter, option, index);
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, ovlRect).left(), ovlRect.top(), opm);

painter->restore();
}
}

Expand Down

0 comments on commit 81f5f70

Please sign in to comment.