File indexing completed on 2024-04-21 05:31:00
0001 /* 0002 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "singletextdelegate.h" 0007 0008 // local 0009 #include "../viewsmodel.h" 0010 #include "../../generic/generictools.h" 0011 0012 namespace Latte { 0013 namespace Settings { 0014 namespace View { 0015 namespace Delegate { 0016 0017 SingleText::SingleText(QObject *parent) 0018 : QStyledItemDelegate(parent) 0019 { 0020 } 0021 0022 void SingleText::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const 0023 { 0024 QStyleOptionViewItem myOptions = option; 0025 //! Remove the focus dotted lines 0026 myOptions.state = (myOptions.state & ~QStyle::State_HasFocus); 0027 myOptions.text = index.model()->data(index, Qt::DisplayRole).toString(); 0028 myOptions.displayAlignment = static_cast<Qt::Alignment>(index.model()->data(index, Qt::TextAlignmentRole).toInt()); 0029 0030 bool isActive = index.data(Model::Views::ISACTIVEROLE).toBool(); 0031 bool isMoveOrigin = index.data(Model::Views::ISMOVEORIGINROLE).toBool(); 0032 bool isChanged = isMoveOrigin; 0033 0034 float textopacity = 1.0; 0035 0036 if (isActive) { 0037 myOptions.text = "<b>" + myOptions.text + "</b>"; 0038 } 0039 0040 if (isMoveOrigin) { 0041 textopacity = 0.25; 0042 } 0043 0044 Latte::drawBackground(painter, option); 0045 Latte::drawFormattedText(painter, myOptions, textopacity); 0046 } 0047 0048 } 0049 } 0050 } 0051 }