diff --git a/app/settings/generic/generictools.cpp b/app/settings/generic/generictools.cpp index 4cbc05186..f22e13e87 100644 --- a/app/settings/generic/generictools.cpp +++ b/app/settings/generic/generictools.cpp @@ -204,10 +204,10 @@ QRect drawChangesIndicatorBackground(QPainter *painter, const QStyleOptionViewIt option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &indicatorOption, painter); - QRect availableRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + tsize, option.rect.y(), option.rect.width() - tsize, option.rect.height()) : - QRect(option.rect.x(), option.rect.y(), option.rect.width() - tsize, option.rect.height()); + QRect optionRemainedRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + tsize, option.rect.y(), option.rect.width() - tsize, option.rect.height()) : + QRect(option.rect.x(), option.rect.y(), option.rect.width() - tsize, option.rect.height()); - return availableRect; + return optionRemainedRect; } void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option) @@ -233,4 +233,87 @@ void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option) painter->restore(); } +QRect drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option) +{ + int total_length = option.rect.height() * 1.8 + MARGIN * 2; + + QStyleOptionViewItem screenOption = option; + screenOption.text = ""; + //! Remove the focus dotted lines + screenOption.state = (option.state & ~QStyle::State_HasFocus); + + if (qApp->layoutDirection() == Qt::RightToLeft) { + screenOption.rect = QRect(option.rect.x() + option.rect.width() - total_length, option.rect.y(), total_length, option.rect.height()); + } else { + screenOption.rect = QRect(option.rect.x(), option.rect.y(), total_length, option.rect.height()); + } + + option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &screenOption, painter); + + QRect optionRemainedRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x(), option.rect.y(), option.rect.width() - total_length, option.rect.height()) : + QRect(option.rect.x() + total_length, option.rect.y(), option.rect.width() - total_length, option.rect.height()); + + return optionRemainedRect; } + +QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option) +{ + int total_length = option.rect.height() * 1.8 + MARGIN * 2; + int pen_width = 2; + + painter->save(); + painter->setRenderHint(QPainter::Antialiasing, true); + + //! horizontal layout scenario + int scr_height = option.rect.height() - MARGIN * 6; + int scr_width = 1.6 * scr_height; + + QRect screenMaximumRect = (qApp->layoutDirection() == Qt::RightToLeft) ? + QRect(option.rect.x() + option.rect.width() - total_length + MARGIN, option.rect.y() + MARGIN, total_length, option.rect.height() - MARGIN*2) : + QRect(option.rect.x() + MARGIN , option.rect.y() + MARGIN, total_length, option.rect.height() - MARGIN*2); + + int topScreenMargin = (screenMaximumRect.height() - scr_height) / 2; + int leftScreenMargin = (screenMaximumRect.width() - scr_width) / 2; + + QRect screenRect(screenMaximumRect.x() + leftScreenMargin, screenMaximumRect.y() + topScreenMargin, scr_width, scr_height); + QRect screenAvailableRect(screenRect.x() + MARGIN, screenRect.y() + MARGIN, screenRect.width() - 2*MARGIN, screenRect.height() - 2*MARGIN); + + bool selected = Latte::isSelected(option); + QPalette::ColorRole textColorRole = selected ? QPalette::HighlightedText : QPalette::Text; + + QPen pen; pen.setWidth(pen_width); + pen.setColor(option.palette.color(Latte::colorGroup(option), textColorRole)); + + //painter->setBrush(imageBrush); + painter->setPen(pen); + painter->drawRect(screenRect); + + painter->restore(); + + return screenAvailableRect; +} + +void drawView(QPainter *painter, const QStyleOptionViewItem &option, const QRect &availableScreenRect) +{ + int pen_width = 3; + painter->save(); + + bool selected = Latte::isSelected(option); + QPalette::ColorRole viewColorRole = !selected ? QPalette::Highlight : QPalette::Text; + QPen pen; pen.setWidth(pen_width); + pen.setColor(option.palette.color(Latte::colorGroup(option), viewColorRole)); + painter->setPen(pen); + + int x = availableScreenRect.x(); + int y = availableScreenRect.bottom(); + + painter->drawLine(x, y, x + availableScreenRect.width() - 1, y); + + painter->restore(); +} + + + + +} + diff --git a/app/settings/generic/generictools.h b/app/settings/generic/generictools.h index c53d42bd0..c2867df29 100644 --- a/app/settings/generic/generictools.h +++ b/app/settings/generic/generictools.h @@ -52,6 +52,9 @@ void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect & void drawChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option); QRect drawChangesIndicatorBackground(QPainter *painter, const QStyleOptionViewItem &option); +QRect drawScreen(QPainter *painter, const QStyleOptionViewItem &option); // returns screen available rect +QRect drawScreenBackground(QPainter *painter, const QStyleOptionViewItem &option); // returns option.rect remained rect +void drawView(QPainter *painter, const QStyleOptionViewItem &option, const QRect &availableScreenRect); } diff --git a/app/settings/viewsdialog/delegates/namedelegate.cpp b/app/settings/viewsdialog/delegates/namedelegate.cpp index 5b97b878b..4e81273e1 100644 --- a/app/settings/viewsdialog/delegates/namedelegate.cpp +++ b/app/settings/viewsdialog/delegates/namedelegate.cpp @@ -72,11 +72,18 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, myOptions.text = "<i>" + myOptions.text + "</i>"; } + // draw changes indicator QRect availableTextRect = Latte::drawChangesIndicatorBackground(painter, option); if (isChanged) { Latte::drawChangesIndicator(painter, option); } + myOptions.rect = availableTextRect; + + // draw screen icon + availableTextRect = Latte::drawScreenBackground(painter, myOptions); + QRect availableScreenRect = Latte::drawScreen(painter, myOptions); + Latte::drawView(painter, myOptions, availableScreenRect); myOptions.rect = availableTextRect; Latte::drawFormattedText(painter, myOptions);