Changeset View
Changeset View
Standalone View
Standalone View
plugins/grepview/grepoutputdelegate.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 72 | QPalette::ColorGroup cg = (options.state & QStyle::State_Enabled) | |||
---|---|---|---|---|---|
73 | ? QPalette::Normal : QPalette::Disabled; | 73 | ? QPalette::Normal : QPalette::Disabled; | ||
74 | QPalette::ColorRole cr = (options.state & QStyle::State_Selected) | 74 | QPalette::ColorRole cr = (options.state & QStyle::State_Selected) | ||
75 | ? QPalette::HighlightedText : QPalette::Text; | 75 | ? QPalette::HighlightedText : QPalette::Text; | ||
76 | QTextCharFormat fmt = cur.charFormat(); | 76 | QTextCharFormat fmt = cur.charFormat(); | ||
77 | fmt.setFont(options.font); | 77 | fmt.setFont(options.font); | ||
78 | 78 | | |||
79 | if(item && item->isText()) | 79 | if(item && item->isText()) | ||
80 | { | 80 | { | ||
81 | // Use custom manual highlighting | 81 | if (item->hasChildren()) { | ||
82 | | ||||
83 | const KTextEditor::Range rng = item->change()->m_range; | | |||
84 | | ||||
85 | // the line number appears grayed | 82 | // the line number appears grayed | ||
86 | fmt.setForeground(options.palette.brush(QPalette::Disabled, cr)); | 83 | fmt.setForeground(options.palette.brush(QPalette::Disabled, cr)); | ||
87 | cur.insertText(i18n("Line %1: ",item->lineNumber()), fmt); | 84 | cur.insertText(i18n("Line %1: ",item->lineNumber()), fmt); | ||
85 | fmt.setForeground(options.palette.brush(cg, cr)); | ||||
86 | | ||||
87 | int firstStart = static_cast<GrepOutputItem*>(item->child(0))->change()->m_range.start().column(); | ||||
88 | cur.insertText(item->text().left(firstStart).remove(leftspaces), fmt); | ||||
89 | KTextEditor::Range previousRange(item->lineNumber(), 0, item->lineNumber(), firstStart); | ||||
90 | for (int i = 0; i < item->rowCount(); ++i) { | ||||
91 | const KTextEditor::Range range = static_cast<GrepOutputItem*>(item->child(i))->change()->m_range; | ||||
92 | fmt.setForeground(options.palette.brush(cg, cr)); | ||||
93 | cur.insertText(item->text().mid(previousRange.end().column(), range.start().column() - previousRange.end().column()), fmt); | ||||
94 | fmt.setFontWeight(QFont::Bold); | ||||
95 | if ( !(options.state & QStyle::State_Selected) ) { | ||||
96 | QColor bgHighlight = option.palette.color(QPalette::AlternateBase); | ||||
97 | fmt.setBackground(bgHighlight); | ||||
98 | } | ||||
99 | cur.insertText(item->text().mid(range.start().column(), range.columnWidth()), fmt); | ||||
100 | fmt.clearBackground(); | ||||
101 | previousRange = range; | ||||
102 | } | ||||
103 | fmt.setFontWeight(QFont::Normal); | ||||
104 | cur.insertText(item->text().mid(previousRange.end().column()), fmt); | ||||
105 | } else { | ||||
106 | // Use custom manual highlighting | ||||
107 | | ||||
108 | const KTextEditor::Range rng = item->change()->m_range; | ||||
88 | 109 | | |||
89 | // switch to normal color | 110 | // switch to normal color | ||
90 | fmt.setForeground(options.palette.brush(cg, cr)); | 111 | fmt.setForeground(options.palette.brush(cg, cr)); | ||
91 | cur.insertText(item->text().left(rng.start().column()).remove(leftspaces), fmt); | 112 | cur.insertText(item->text().left(rng.start().column()).remove(leftspaces), fmt); | ||
92 | 113 | | |||
93 | fmt.setFontWeight(QFont::Bold); | 114 | fmt.setFontWeight(QFont::Bold); | ||
94 | if ( !(options.state & QStyle::State_Selected) ) { | 115 | if ( !(options.state & QStyle::State_Selected) ) { | ||
95 | QColor bgHighlight = option.palette.color(QPalette::AlternateBase); | 116 | QColor bgHighlight = option.palette.color(QPalette::AlternateBase); | ||
96 | fmt.setBackground(bgHighlight); | 117 | fmt.setBackground(bgHighlight); | ||
97 | } | 118 | } | ||
98 | cur.insertText(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column()), fmt); | 119 | cur.insertText(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column()), fmt); | ||
99 | fmt.clearBackground(); | 120 | fmt.clearBackground(); | ||
100 | 121 | | |||
101 | fmt.setFontWeight(QFont::Normal); | 122 | fmt.setFontWeight(QFont::Normal); | ||
102 | cur.insertText(item->text().mid(rng.end().column()), fmt); | 123 | cur.insertText(item->text().mid(rng.end().column()), fmt); | ||
124 | } | ||||
103 | }else{ | 125 | }else{ | ||
104 | QString text; | 126 | QString text; | ||
105 | if(item) | 127 | if(item) | ||
106 | text = item->text(); | 128 | text = item->text(); | ||
107 | else | 129 | else | ||
108 | text = index.data().toString(); | 130 | text = index.data().toString(); | ||
109 | // Simply insert the text as html. We use this for the titles. | 131 | // Simply insert the text as html. We use this for the titles. | ||
110 | doc.setHtml(text); | 132 | doc.setHtml(text); | ||
Show All 30 Lines | 157 | { | |||
141 | //take account of additional width required for highlighting (bold text) | 163 | //take account of additional width required for highlighting (bold text) | ||
142 | //and line numbers. These are not included in the default Qt size calculation. | 164 | //and line numbers. These are not included in the default Qt size calculation. | ||
143 | if(item && item->isText()) | 165 | if(item && item->isText()) | ||
144 | { | 166 | { | ||
145 | QFont font = option.font; | 167 | QFont font = option.font; | ||
146 | QFontMetrics metrics(font); | 168 | QFontMetrics metrics(font); | ||
147 | font.setBold(true); | 169 | font.setBold(true); | ||
148 | QFontMetrics bMetrics(font); | 170 | QFontMetrics bMetrics(font); | ||
171 | if (item->hasChildren()) { | ||||
172 | int bWidth = 0; | ||||
173 | for (int i = 0; i < item->rowCount(); ++i) { | ||||
174 | bWidth += static_cast<GrepOutputItem*>(item->child(i))->change()->m_range.columnWidth(); | ||||
175 | } | ||||
176 | int width = option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) + | ||||
177 | metrics.width(item->text().length() - bWidth) + bMetrics.width(bWidth) + | ||||
178 | std::max(option.decorationSize.width(), 0); | ||||
149 | 179 | | |||
180 | ret.setWidth(width); | ||||
181 | } else { | ||||
150 | const KTextEditor::Range rng = item->change()->m_range; | 182 | const KTextEditor::Range rng = item->change()->m_range; | ||
151 | 183 | | |||
152 | int width = metrics.width(item->text().left(rng.start().column())) + | 184 | int width = metrics.width(item->text().left(rng.start().column())) + | ||
153 | metrics.width(item->text().mid(rng.end().column())) + | 185 | metrics.width(item->text().mid(rng.end().column())) + | ||
154 | bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) + | 186 | bMetrics.width(item->text().mid(rng.start().column(), rng.end().column() - rng.start().column())) + | ||
155 | option.fontMetrics.width(i18n("Line %1: ",item->lineNumber())) + | | |||
156 | std::max(option.decorationSize.width(), 0); | 187 | std::max(option.decorationSize.width(), 0); | ||
157 | ret.setWidth(width); | 188 | ret.setWidth(width); | ||
189 | } | ||||
158 | }else{ | 190 | }else{ | ||
159 | // This is only used for titles, so not very performance critical | 191 | // This is only used for titles, so not very performance critical | ||
160 | QString text; | 192 | QString text; | ||
161 | if(item) | 193 | if(item) | ||
162 | text = item->text(); | 194 | text = item->text(); | ||
163 | else | 195 | else | ||
164 | text = index.data().toString(); | 196 | text = index.data().toString(); | ||
165 | 197 | | |||
Show All 9 Lines |