per layout icons for errors and warnings

work/spdx
Michail Vourlakos 4 years ago
parent 07c5f1ac03
commit b6c85eac57

@ -191,18 +191,27 @@ void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &
}
}
QRect remainedFromIcon(const QStyleOption &option)
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment)
{
int iconsize = option.rect.height() - 2*MARGIN;
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
QRect optionRemainedRect = (qApp->layoutDirection() == Qt::LeftToRight) ? QRect(option.rect.x() + total, option.rect.y(), option.rect.width() - total, option.rect.height()) :
QRect(option.rect.x(), option.rect.y(), option.rect.width() - total, option.rect.height());
Qt::AlignmentFlag curalign = alignment;
if (qApp->layoutDirection() == Qt::LeftToRight) {
curalign = alignment;
} else {
curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
}
QRect optionRemainedRect = (curalign == Qt::AlignLeft) ? QRect(option.rect.x() + total, option.rect.y(), option.rect.width() - total, option.rect.height()) :
QRect(option.rect.x(), option.rect.y(), option.rect.width() - total, option.rect.height());
return optionRemainedRect;
}
void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option)
void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option, Qt::AlignmentFlag alignment)
{
int iconsize = option.rect.height() - 2*MARGIN;
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
@ -210,9 +219,17 @@ void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOpti
QStyleOptionMenuItem iconOption = option;
iconOption.text = "";
//! Remove the focus dotted lines
// iconOption.state = (option.state & ~QStyle::State_HasFocus);
// iconOption.state = (option.state & ~QStyle::State_HasFocus);
Qt::AlignmentFlag curalign = alignment;
if (qApp->layoutDirection() == Qt::LeftToRight) {
curalign = alignment;
} else {
curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
}
if (curalign == Qt::AlignLeft) {
iconOption.rect = QRect(option.rect.x(), option.rect.y(), total, option.rect.height());
} else {
iconOption.rect = QRect(option.rect.x() + option.rect.width() - total, option.rect.y(), total, option.rect.height());
@ -221,7 +238,35 @@ void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOpti
style->drawControl(QStyle::CE_MenuItem, &iconOption, painter);
}
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon)
void drawIconBackground(QPainter *painter, const QStyleOptionViewItem &option, Qt::AlignmentFlag alignment)
{
int iconsize = option.rect.height() - 2*MARGIN;
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
QStyleOptionViewItem iconOption = option;
iconOption.text = "";
//! Remove the focus dotted lines
iconOption.state = (option.state & ~QStyle::State_HasFocus);
Qt::AlignmentFlag curalign = alignment;
if (qApp->layoutDirection() == Qt::LeftToRight) {
curalign = alignment;
} else {
curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
}
if (curalign == Qt::AlignLeft) {
iconOption.rect = QRect(option.rect.x(), option.rect.y(), total, option.rect.height());
} else {
iconOption.rect = QRect(option.rect.x() + option.rect.width() - total, option.rect.y(), total, option.rect.height());
}
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &iconOption, painter);
}
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment)
{
int iconsize = option.rect.height() - 2*MARGIN;
int total = iconsize + 2*ICONMARGIN + 2*MARGIN;
@ -232,12 +277,20 @@ void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon
QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal);
QRect target;
Qt::AlignmentFlag curalign = alignment;
if (qApp->layoutDirection() == Qt::RightToLeft) {
target = QRect(option.rect.x() + option.rect.width() - total + ICONMARGIN + MARGIN, option.rect.y(), iconsize, iconsize);
if (qApp->layoutDirection() == Qt::LeftToRight) {
curalign = alignment;
} else {
curalign = alignment == Qt::AlignLeft ? Qt::AlignRight : Qt::AlignLeft;
}
QRect target;
if (curalign == Qt::AlignLeft) {
target = QRect(option.rect.x() + MARGIN + ICONMARGIN, option.rect.y(), iconsize, iconsize);
} else {
target = QRect(option.rect.x() + option.rect.width() - total + ICONMARGIN + MARGIN, option.rect.y(), iconsize, iconsize);
}
painter->drawPixmap(target, QIcon::fromTheme(icon).pixmap(target.height(), target.height(), mode));

@ -51,9 +51,10 @@ void drawFormattedText(QPainter *painter, const QStyleOptionViewItem &option, co
void drawLayoutIcon(QPainter *painter, const QStyleOption &option, const QRect &target, const Latte::Data::LayoutIcon &icon);
//! simple icon
QRect remainedFromIcon(const QStyleOption &option);
void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option);
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon);
QRect remainedFromIcon(const QStyleOption &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
void drawIconBackground(QPainter *painter, const QStyleOptionViewItem &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
void drawIconBackground(QPainter *painter, const QStyle *style, const QStyleOptionMenuItem &option, Qt::AlignmentFlag alignment = Qt::AlignLeft);
void drawIcon(QPainter *painter, const QStyleOption &option, const QString &icon, Qt::AlignmentFlag alignment = Qt::AlignLeft);
//! changes indicator
QRect remainedFromChangesIndicator(const QStyleOptionViewItem &option);

@ -85,109 +85,66 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
bool isNewLayout = index.data(Model::Layouts::ISNEWLAYOUTROLE).toBool();
bool hasChanges = index.data(Model::Layouts::LAYOUTHASCHANGESROLE).toBool();
bool hasErrors = index.data(Model::Layouts::ERRORSROLE).toBool();
bool hasWarnings = index.data(Model::Layouts::WARNINGSROLE).toBool();
QString name = index.data(Qt::UserRole).toString();
bool isChanged = (isNewLayout || hasChanges);
bool drawTwoIcons = isLocked && isConsideredActive;
QStyleOptionViewItem adjustedOption = option;
QStyleOptionViewItem myOptions = option;
myOptions.text = name;
//! Remove the focus dotted lines
adjustedOption.state = (adjustedOption.state & ~QStyle::State_HasFocus);
adjustedOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
myOptions.state = (myOptions.state & ~QStyle::State_HasFocus);
myOptions.displayAlignment = static_cast<Qt::Alignment>(index.model()->data(index, Qt::TextAlignmentRole).toInt());;
painter->setRenderHint(QPainter::Antialiasing, true);
QRect optionRect = Latte::remainedFromChangesIndicator(option);
Latte::drawChangesIndicatorBackground(painter, option);
adjustedOption.rect = optionRect;
if (isLocked || isConsideredActive) {
QStandardItemModel *model = (QStandardItemModel *) index.model();
bool active = Latte::isActive(option);
bool enabled = Latte::isEnabled(option);
bool selected = Latte::isSelected(option);
bool focused = Latte::isFocused(option);
bool hovered = Latte::isHovered(option);
//! font metrics
QFontMetrics fm(option.font);
int textWidth = fm.boundingRect(name).width();
int thick = optionRect.height();
int length = drawTwoIcons ? (2*thick /*+ 2*/) : thick;
int startWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? length : 0;
int endWidth = (qApp->layoutDirection() == Qt::RightToLeft) ? 0 : length;
QRect destinationS(optionRect.x(), optionRect.y(), startWidth, thick);
QRect destinationE(optionRect.x() + optionRect.width() - endWidth, optionRect.y(), endWidth, thick);
QStyleOptionViewItem myOptionS = adjustedOption;
QStyleOptionViewItem myOptionE = adjustedOption;
QStyleOptionViewItem myOptionMain = adjustedOption;
myOptionMain.font.setBold(isActive);
myOptionMain.font.setItalic(isChanged);
myOptionS.rect = destinationS;
myOptionE.rect = destinationE;
myOptionMain.rect.moveLeft(optionRect.x() + startWidth);
myOptionMain.rect.setWidth(optionRect.width() - startWidth - endWidth);
QStyledItemDelegate::paint(painter, myOptionMain, index);
//! draw background below icons
//! HIDDENTEXTCOLUMN is just needed to draw empty background rectangles
QStyledItemDelegate::paint(painter, myOptionS, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
QStyledItemDelegate::paint(painter, myOptionE, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
//! First Icon
QIcon firstIcon = isLocked && !drawTwoIcons ? QIcon::fromTheme("object-locked") : QIcon::fromTheme("favorites");
QIcon::Mode mode = ((active && (selected || focused)) ? QIcon::Selected : QIcon::Normal);
if (qApp->layoutDirection() == Qt::LeftToRight) {
int firstIconX = optionRect.x() + optionRect.width() - endWidth;
painter->drawPixmap(QRect(firstIconX, optionRect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
//debug
//painter->drawLine(firstIconX, optionRect.y(), firstIconX, optionRect.y()+thick);
//painter->drawLine(firstIconX+thick - 1, optionRect.y(), firstIconX+thick - 1, optionRect.y()+thick);
if (drawTwoIcons) {
int secondIconX = optionRect.x() + optionRect.width() - thick;
QIcon secondIcon = QIcon::fromTheme("object-locked");
painter->drawPixmap(QRect(secondIconX, optionRect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
//debug
//painter->drawLine(secondIconX, optionRect.y(), secondIconX, optionRect.y()+thick);
//painter->drawLine(secondIconX + thick - 1, optionRect.y(), secondIconX + thick - 1,optionRect.y()+thick);
}
} else {
painter->drawPixmap(QRect(optionRect.x(), optionRect.y(), thick, thick), firstIcon.pixmap(thick, thick, mode));
if (drawTwoIcons) {
QIcon secondIcon = QIcon::fromTheme("object-locked");
painter->drawPixmap(QRect(optionRect.x() + thick, optionRect.y(), thick, thick), secondIcon.pixmap(thick, thick, mode));
}
}
//! Changes Indicator
QRect remainedrect = Latte::remainedFromChangesIndicator(myOptions);
Latte::drawChangesIndicatorBackground(painter, myOptions);
if (isChanged) {
Latte::drawChangesIndicator(painter, option);
}
myOptions.rect = remainedrect;
if (isChanged) {
Latte::drawChangesIndicator(painter, option);
if (hasErrors || hasWarnings) {
remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight);
Latte::drawIconBackground(painter, myOptions, Qt::AlignRight);
if (hasErrors) {
Latte::drawIcon(painter, myOptions, "data-error", Qt::AlignRight);
} else if (hasWarnings) {
Latte::drawIcon(painter, myOptions, "data-warning", Qt::AlignRight);
}
return;
myOptions.rect = remainedrect;
}
//! Draw valid text area
adjustedOption.font.setBold(isActive);
adjustedOption.font.setItalic(isChanged);
if (isConsideredActive) {
remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight);
Latte::drawIconBackground(painter, myOptions, Qt::AlignRight);
Latte::drawIcon(painter, myOptions, "favorites", Qt::AlignRight);
myOptions.rect = remainedrect;
}
if (isLocked) {
remainedrect = Latte::remainedFromIcon(myOptions, Qt::AlignRight);
Latte::drawIconBackground(painter, myOptions, Qt::AlignRight);
Latte::drawIcon(painter, myOptions, "object-locked", Qt::AlignRight);
myOptions.rect = remainedrect;
}
QStyledItemDelegate::paint(painter, adjustedOption, index);
if (isActive) {
myOptions.text = "<b>" + myOptions.text + "</b>";
}
if (isChanged) {
Latte::drawChangesIndicator(painter, option);
myOptions.text = "<i>" + myOptions.text + "</i>";
}
Latte::drawFormattedText(painter, myOptions);
}
}

@ -237,13 +237,15 @@ void Layouts::removeLayout(const QString &id)
void Layouts::setLayoutProperties(const Latte::Data::Layout &layout)
{
if (m_layoutsTable.containsId(layout.id) && m_layoutsTable[layout.id] != layout) {
if (m_layoutsTable.containsId(layout.id)) {
m_layoutsTable[layout.id] = layout;
int dataRow = m_layoutsTable.indexOf(layout.id);
QVector<int> roles;
roles << Qt::DisplayRole;
roles << Qt::UserRole;
roles << ERRORSROLE;
roles << WARNINGSROLE;
emit dataChanged(index(dataRow, IDCOLUMN), index(dataRow, ACTIVITYCOLUMN), roles);
}
}
@ -560,6 +562,10 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
QVariant iconVariant;
iconVariant.setValue<Latte::Data::LayoutIcon>(_icon);
return iconVariant;
} else if (role == ERRORSROLE) {
return m_layoutsTable[row].errors;
} else if (role == WARNINGSROLE) {
return m_layoutsTable[row].warnings;
}
switch (column) {

@ -72,6 +72,8 @@ public:
ORIGINALISSHOWNINMENUROLE,
ORIGINALHASBORDERSROLE,
ORIGINALASSIGNEDACTIVITIESROLE,
ERRORSROLE,
WARNINGSROLE
};
enum SortingPriority

Loading…
Cancel
Save