1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

dialogs:use same code for changesindicators

This commit is contained in:
Michail Vourlakos 2021-04-10 20:52:49 +03:00
parent b78b7e1fe8
commit f42fe460b3
4 changed files with 15 additions and 63 deletions

View File

@ -193,11 +193,13 @@ QRect drawChangesIndicatorBackground(QPainter *painter, const QStyleOptionViewIt
QStyleOptionViewItem indicatorOption = option; QStyleOptionViewItem indicatorOption = option;
indicatorOption.text = ""; indicatorOption.text = "";
//! Remove the focus dotted lines
indicatorOption.state = (option.state & ~QStyle::State_HasFocus);
if (qApp->layoutDirection() == Qt::RightToLeft) { if (qApp->layoutDirection() == Qt::RightToLeft) {
indicatorOption.rect = QRect(option.rect.x(), option.rect.y(), tsize, option.rect.height() + 1); indicatorOption.rect = QRect(option.rect.x(), option.rect.y(), tsize, option.rect.height());
} else { } else {
indicatorOption.rect = QRect(option.rect.x() + option.rect.width() - tsize, option.rect.y(), tsize, option.rect.height() + 1); indicatorOption.rect = QRect(option.rect.x() + option.rect.width() - tsize, option.rect.y(), tsize, option.rect.height());
} }
option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &indicatorOption, painter); option.widget->style()->drawControl(QStyle::CE_ItemViewItem, &indicatorOption, painter);

View File

@ -75,44 +75,6 @@ void LayoutName::setModelData(QWidget *editor, QAbstractItemModel *model, const
} }
} }
void LayoutName::drawHasChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
//! draw changes circle indicator
int csize{INDICATORCHANGESLENGTH};
int tsize{INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN*2};
//! Draw indicator background
QStandardItemModel *model = (QStandardItemModel *) index.model();
if (qApp->layoutDirection() == Qt::RightToLeft) {
QStyleOptionViewItem indicatorOption = option;
indicatorOption.rect = QRect(option.rect.x(), option.rect.y(), tsize, option.rect.height());
QStyledItemDelegate::paint(painter, indicatorOption, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
} else {
QStyleOptionViewItem indicatorOption = option;
indicatorOption.rect = QRect(option.rect.x() + option.rect.width() - tsize, option.rect.y(), tsize, option.rect.height());
QStyledItemDelegate::paint(painter, indicatorOption, model->index(index.row(), Model::Layouts::HIDDENTEXTCOLUMN));
}
bool isNewLayout = index.data(Model::Layouts::ISNEWLAYOUTROLE).toBool();
bool hasChanges = index.data(Model::Layouts::LAYOUTHASCHANGESROLE).toBool();
bool isChanged = (isNewLayout || hasChanges);
if (isChanged) {
QRect changesRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + INDICATORCHANGESMARGIN, option.rect.y() + option.rect.height()/2 - csize/2, csize, csize) :
QRect(option.rect.x() + option.rect.width() - csize - INDICATORCHANGESMARGIN, option.rect.y() + option.rect.height()/2 - csize/2, csize, csize);
QColor plasmaOrange(246, 116, 0); //orangish color used from plasma systemsettings #f67400
QBrush backBrush(plasmaOrange);
QPen pen; pen.setWidth(1);
pen.setColor(plasmaOrange);
painter->setBrush(backBrush);
painter->setPen(pen);
painter->drawEllipse(changesRect);
}
}
void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
bool inMultiple = index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool(); bool inMultiple = index.data(Model::Layouts::INMULTIPLELAYOUTSROLE).toBool();
@ -137,10 +99,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
painter->setRenderHint(QPainter::Antialiasing, true); painter->setRenderHint(QPainter::Antialiasing, true);
int indicatorLength = INDICATORCHANGESLENGTH + INDICATORCHANGESMARGIN * 2; QRect optionRect = Latte::drawChangesIndicatorBackground(painter, option);
QRect optionRect = (qApp->layoutDirection() == Qt::RightToLeft) ? QRect(option.rect.x() + indicatorLength, option.rect.y(), option.rect.width() - indicatorLength, option.rect.height()) :
QRect(option.rect.x(), option.rect.y(), option.rect.width() - indicatorLength, option.rect.height());
adjustedOption.rect = optionRect; adjustedOption.rect = optionRect;
if (isLocked || isConsideredActive) { if (isLocked || isConsideredActive) {
@ -213,23 +172,21 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
} }
} }
//! in order to paint also the background if (isChanged) {
QStyleOptionViewItem indicatorOption = adjustedOption; Latte::drawChangesIndicator(painter, option);
indicatorOption.rect = option.rect; }
drawHasChangesIndicator(painter, indicatorOption, index);
return; return;
} }
//! in order to paint also the background
QStyleOptionViewItem indicatorOption = adjustedOption;
indicatorOption.rect = option.rect;
drawHasChangesIndicator(painter, indicatorOption, index);
//! Draw valid text area //! Draw valid text area
adjustedOption.font.setBold(isActive); adjustedOption.font.setBold(isActive);
adjustedOption.font.setItalic(isChanged); adjustedOption.font.setItalic(isChanged);
QStyledItemDelegate::paint(painter, adjustedOption, index); QStyledItemDelegate::paint(painter, adjustedOption, index);
if (isChanged) {
Latte::drawChangesIndicator(painter, option);
}
} }
} }

View File

@ -37,9 +37,6 @@ public:
void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
private:
void drawHasChangesIndicator(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
}; };
} }

View File

@ -49,21 +49,17 @@ void NameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
bool isChanged = (index.data(Model::Views::ISCHANGEDROLE).toBool() || index.data(Model::Views::HASCHANGEDVIEWROLE).toBool()); bool isChanged = (index.data(Model::Views::ISCHANGEDROLE).toBool() || index.data(Model::Views::HASCHANGEDVIEWROLE).toBool());
if (isEmpty) { if (isEmpty) {
myOptions.displayAlignment = (Qt::AlignHCenter | Qt::AlignVCenter); myOptions.text = "< " + i18n("optional") + " >";
myOptions.text = " <" + i18n("optional") + "> ";
// QBrush placeholderBrush = option.palette.placeholderText();
//style="color:blue;"
QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text; QPalette::ColorRole applyColor = Latte::isSelected(option) ? QPalette::HighlightedText : QPalette::Text;
QBrush placeholderBrush = option.palette.brush(Latte::colorGroup(option), applyColor); QBrush placeholderBrush = option.palette.brush(Latte::colorGroup(option), applyColor);
QColor placeholderColor = placeholderBrush.color(); QColor placeholderColor = placeholderBrush.color();
placeholderColor.setAlpha(125);
QString cssplaceholdercolor = "rgba("; QString cssplaceholdercolor = "rgba(";
cssplaceholdercolor += QString::number(placeholderColor.red()) + ","; cssplaceholdercolor += QString::number(placeholderColor.red()) + ",";
cssplaceholdercolor += QString::number(placeholderColor.green()) + ", "; cssplaceholdercolor += QString::number(placeholderColor.green()) + ", ";
cssplaceholdercolor += QString::number(placeholderColor.blue()) + ", "; cssplaceholdercolor += QString::number(placeholderColor.blue()) + ", ";
cssplaceholdercolor += "110)"; cssplaceholdercolor += "128)";
myOptions.text = "<label style='color:" + cssplaceholdercolor + ";'>" + myOptions.text + "</label>"; myOptions.text = "<label style='color:" + cssplaceholdercolor + ";'>" + myOptions.text + "</label>";
} }