[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/graphics/okular/core
From: Pino Toscano <toscano.pino () tiscali ! it>
Date: 2006-12-23 16:18:57
Message-ID: 1166890737.451878.13281.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 616089 by pino:
Improved the text selection by using and ad-hoc function that takes care of adding or \
merging a new shape to the area, so the simply() at the end is no more needed. This \
gives another speedup when using the text selection. (And, rename okularDeleter to \
okularPtrUtils.)
M +42 -4 area.h
M +2 -3 textpage.cpp
--- trunk/playground/graphics/okular/core/area.h #616088:616089
@@ -275,24 +275,34 @@
/** @internal */
template <typename T>
-class okularDeleter
+class okularPtrUtils
{
public:
static void doDelete( T& t )
{
(void)t;
}
+
+ static T* givePtr( T& t )
+ {
+ return &t;
+ }
};
/** @internal */
template <typename T>
-class okularDeleter<T*>
+class okularPtrUtils<T*>
{
public:
static void doDelete( T* t )
{
delete t;
}
+
+ static T* givePtr( T* t )
+ {
+ return t;
+ }
};
/**
@@ -315,6 +325,7 @@
bool intersects (const RegularArea<NormalizedShape,Shape> * area) const;
bool intersects (const NormalizedShape& shape) const;
void appendArea (const RegularArea<NormalizedShape,Shape> *area);
+ void appendShape( const NormalizedShape& shape );
void simplify ();
bool isNull() const;
QList<Shape>* geometry( int xScale, int yScale, int dx=0,int dy=0 ) const;
@@ -325,7 +336,7 @@
{
int size = this->count();
for ( int i = 0; i < size; ++i )
- okularDeleter<NormalizedShape>::doDelete( (*this)[i] );
+ okularPtrUtils<NormalizedShape>::doDelete( (*this)[i] );
}
template <class NormalizedShape, class Shape>
@@ -342,7 +353,7 @@
*((*this)[x]) |= *((*this)[i+1]);
NormalizedShape tobedeleted = (*this)[i+1];
this->removeAt( i + 1 );
- okularDeleter<NormalizedShape>::doDelete( tobedeleted );
+ okularPtrUtils<NormalizedShape>::doDelete( tobedeleted );
--end;
--i;
}
@@ -421,6 +432,33 @@
template <class NormalizedShape, class Shape>
+void RegularArea<NormalizedShape, Shape>::appendShape( const NormalizedShape& shape \
) +{
+ if ( !this )
+ return;
+
+ int size = this->count();
+ // if the list is empty, adds the shape normally
+ if ( size == 0 )
+ {
+ this->append( shape );
+ }
+ else
+ {
+ // if the new shape intersects with the last shape in the list, then
+ // merge it with that and delete the shape
+ if ( (*this)[size - 1]->intersects( shape ) )
+ {
+ *((*this)[size - 1]) |= *okularPtrUtils<NormalizedShape>::givePtr( shape \
); + okularPtrUtils<NormalizedShape>::doDelete( shape );
+ }
+ else
+ this->append( shape );
+ }
+}
+
+
+template <class NormalizedShape, class Shape>
bool RegularArea<NormalizedShape, Shape>::contains( double x, double y ) const
{
if ( !this )
--- trunk/playground/graphics/okular/core/textpage.cpp #616088:616089
@@ -215,7 +215,7 @@
{
tmp=d->m_words[it]->area();
if (tmp->intersects(&first))
- ret->append(tmp);
+ ret->appendShape(tmp);
}
}
else*/
@@ -234,13 +234,12 @@
{
tmp=d->m_words[it]->transformedArea();
if (tmp->intersects(&first) || tmp->intersects(&second) || \
tmp->intersects(&third))
- ret->append(new NormalizedRect(*tmp));
+ ret->appendShape(new NormalizedRect(*tmp));
}
// }
}
- ret->simplify();
return ret;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic