• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • render
katerenderrange.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2003-2005 Hamish Rodda <rodda@kde.org>
4  * Copyright (C) 2007 Mirko Stocker <me@misto.ch>
5  * Copyright (C) 2008 David Nolden <david.nolden.kdevelop@art-master.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "katerenderrange.h"
24 
25 #include <limits.h>
26 
27 #include <kcolorutils.h>
28 
29 void mergeAttributes(KTextEditor::Attribute::Ptr base, KTextEditor::Attribute::Ptr add)
30 {
31  if(!add)
32  return;
33 
34  bool hadBg = base->hasProperty(KTextEditor::Attribute::BackgroundBrush);
35  bool hasBg = add->hasProperty(KTextEditor::Attribute::BackgroundBrush);
36 
37  bool hadFg = base->hasProperty(KTextEditor::Attribute::ForegroundBrush);
38  bool hasFg = add->hasProperty(KTextEditor::Attribute::ForegroundBrush);
39 
40  if(((!hadBg || !hasBg) && (!hadFg || !hasFg))) {
41  //Nothing to blend
42  *base += *add;
43  return;
44  }
45 
46  //We eventually have to blend
47 
48  QBrush baseBgBrush, baseFgBrush;
49 
50  if(hadBg)
51  baseBgBrush = base->background();
52 
53  if(hadFg)
54  baseFgBrush = base->foreground();
55 
56  *base += *add;
57 
58  if(hadBg && hasBg)
59  {
60  QBrush bg = add->background();
61  if(!bg.isOpaque()) {
62  QColor mixWithColor = bg.color();
63  mixWithColor.setAlpha(255);
64  bg.setColor(KColorUtils::mix(baseBgBrush.color(), mixWithColor, bg.color().alphaF()));
65  base->setBackground(bg);
66  }
67  }
68  if(hadFg && hasFg)
69  {
70  QBrush fg = add->foreground();
71  if(!fg.isOpaque()) {
72  QColor mixWithColor = fg.color();
73  mixWithColor.setAlpha(255);
74  fg.setColor(KColorUtils::mix(baseFgBrush.color(), mixWithColor, fg.color().alphaF()));
75  base->setForeground(fg);
76  }
77  }
78 }
79 
80 bool KateRenderRange::isReady() const {
81  return false;
82 }
83 
84 NormalRenderRange::NormalRenderRange()
85  : m_currentRange(0)
86 {
87 }
88 
89 NormalRenderRange::~NormalRenderRange()
90 {
91  QListIterator<pairRA> it = m_ranges;
92  while (it.hasNext())
93  delete it.next().first;
94 }
95 
96 void NormalRenderRange::addRange(KTextEditor::Range* range, KTextEditor::Attribute::Ptr attribute)
97 {
98  m_ranges.append(pairRA(range, attribute));
99 }
100 
101 KTextEditor::Cursor NormalRenderRange::nextBoundary() const
102 {
103  return m_nextBoundary;
104 }
105 
106 bool NormalRenderRange::advanceTo(const KTextEditor::Cursor& pos)
107 {
108  int index = m_currentRange;
109  while (index < m_ranges.count()) {
110  const pairRA& p = m_ranges.at(index);
111  KTextEditor::Range* r = p.first;
112  if (r->end() <= pos) {
113  ++index;
114  } else {
115  bool ret = index != m_currentRange;
116  m_currentRange = index;
117 
118  if (r->start() > pos) {
119  m_nextBoundary = r->start();
120  } else {
121  m_nextBoundary = r->end();
122  }
123  if (r->contains(pos)) {
124  m_currentAttribute = p.second;
125  } else {
126  m_currentAttribute.clear();
127  }
128 
129  return ret;
130  }
131  }
132 
133  m_nextBoundary = KTextEditor::Cursor(INT_MAX, INT_MAX);
134  m_currentAttribute.clear();
135  return false;
136 }
137 
138 KTextEditor::Attribute::Ptr NormalRenderRange::currentAttribute() const
139 {
140  return m_currentAttribute;
141 }
142 
143 KTextEditor::Cursor RenderRangeList::nextBoundary() const
144 {
145  KTextEditor::Cursor ret = m_currentPos;
146  bool first = true;
147  foreach (KateRenderRange* r, *this) {
148  if (first) {
149  ret = r->nextBoundary();
150  first = false;
151 
152  } else {
153  KTextEditor::Cursor nb = r->nextBoundary();
154  if (ret > nb)
155  ret = nb;
156  }
157  }
158  return ret;
159 }
160 
161 RenderRangeList::~RenderRangeList()
162 {
163 }
164 
165 void RenderRangeList::advanceTo(const KTextEditor::Cursor& pos)
166 {
167  foreach (KateRenderRange* r, *this)
168  r->advanceTo(pos);
169 
170  //Delete lists that are ready, else the list may get too large due to temporaries
171  for(int a = size()-1; a >= 0; --a) {
172  KateRenderRange* r = at(a);
173  if(r->isReady()) {
174  delete r;
175  removeAt(a);
176  }
177  }
178 }
179 
180 bool RenderRangeList::hasAttribute() const
181 {
182  foreach (KateRenderRange* r, *this)
183  if (r->currentAttribute())
184  return true;
185 
186  return false;
187 }
188 
189 KTextEditor::Attribute::Ptr RenderRangeList::generateAttribute() const
190 {
191  KTextEditor::Attribute::Ptr a;
192  bool ownsAttribute = false;
193 
194  foreach (KateRenderRange* r, *this) {
195  if (KTextEditor::Attribute::Ptr a2 = r->currentAttribute()) {
196  if(!a) {
197  a = a2;
198  }else {
199  if(!ownsAttribute) {
200  //Make an own copy of the attribute..
201  ownsAttribute = true;
202  a = new KTextEditor::Attribute(*a);
203  }
204  mergeAttributes(a, a2);
205  }
206  }
207  }
208 
209  return a;
210 }
211 
NormalRenderRange::addRange
void addRange(KTextEditor::Range *range, KTextEditor::Attribute::Ptr attribute)
Definition: katerenderrange.cpp:96
NormalRenderRange::NormalRenderRange
NormalRenderRange()
Definition: katerenderrange.cpp:84
KateRenderRange::isReady
virtual bool isReady() const
Definition: katerenderrange.cpp:80
RenderRangeList::advanceTo
void advanceTo(const KTextEditor::Cursor &pos)
Definition: katerenderrange.cpp:165
QListIterator::next
const T & next()
QColor::alphaF
qreal alphaF() const
NormalRenderRange::currentAttribute
virtual KTextEditor::Attribute::Ptr currentAttribute() const
Definition: katerenderrange.cpp:138
NormalRenderRange::nextBoundary
virtual KTextEditor::Cursor nextBoundary() const
Definition: katerenderrange.cpp:101
QList< KateRenderRange * >::at
const T & at(int i) const
QList< KateRenderRange * >::removeAt
void removeAt(int i)
QColor::setAlpha
void setAlpha(int alpha)
QBrush
KateRenderRange::currentAttribute
virtual KTextEditor::Attribute::Ptr currentAttribute() const =0
QList< KateRenderRange * >::size
int size() const
QBrush::isOpaque
bool isOpaque() const
QBrush::color
const QColor & color() const
RenderRangeList::~RenderRangeList
~RenderRangeList()
Definition: katerenderrange.cpp:161
NormalRenderRange::advanceTo
virtual bool advanceTo(const KTextEditor::Cursor &pos)
Definition: katerenderrange.cpp:106
NormalRenderRange::~NormalRenderRange
virtual ~NormalRenderRange()
Definition: katerenderrange.cpp:89
QList< KateRenderRange * >::first
T & first()
QColor
katerenderrange.h
QPair
RenderRangeList::hasAttribute
bool hasAttribute() const
Definition: katerenderrange.cpp:180
pairRA
QPair< KTextEditor::Range *, KTextEditor::Attribute::Ptr > pairRA
Definition: katerenderrange.h:45
mergeAttributes
void mergeAttributes(KTextEditor::Attribute::Ptr base, KTextEditor::Attribute::Ptr add)
Definition: katerenderrange.cpp:29
RenderRangeList::generateAttribute
KTextEditor::Attribute::Ptr generateAttribute() const
Definition: katerenderrange.cpp:189
QListIterator
RenderRangeList::nextBoundary
KTextEditor::Cursor nextBoundary() const
Definition: katerenderrange.cpp:143
QBrush::setColor
void setColor(const QColor &color)
KateRenderRange::advanceTo
virtual bool advanceTo(const KTextEditor::Cursor &pos)=0
KateRenderRange
Definition: katerenderrange.h:35
KateRenderRange::nextBoundary
virtual KTextEditor::Cursor nextBoundary() const =0
QListIterator::hasNext
bool hasNext() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal