mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-02 14:14:10 +00:00
Removed some double selection Problem
This commit is contained in:
parent
b50b622a25
commit
929e4b6a0e
|
@ -2407,6 +2407,8 @@ void Document::setPageTextSelection( int page, RegularAreaRect * rect, const QCo
|
|||
if ( !d->m_generator || !kp )
|
||||
return;
|
||||
|
||||
// cout << "color: " << color.red() << "," << color.green() << "," << color.blue() << endl;
|
||||
|
||||
// add or remove the selection basing whether rect is null or not
|
||||
if ( rect )
|
||||
kp->d->setTextSelections( rect, color );
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
|
||||
#include <limits>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#ifdef PAGE_PROFILE
|
||||
#include <QtCore/QTime>
|
||||
#endif
|
||||
|
|
96
core/textpage.cpp
Executable file → Normal file
96
core/textpage.cpp
Executable file → Normal file
|
@ -540,7 +540,6 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const
|
|||
for ( ; it != itEnd; ++it ){
|
||||
|
||||
rect= (*it)->area;
|
||||
printRect(rect.geometry(scaleX,scaleY));
|
||||
|
||||
if(rect.isBottomOrLevel(startC) && rect.isRight(startC)){
|
||||
count++;
|
||||
|
@ -1323,7 +1322,8 @@ void TextPagePrivate::makeWordFromCharacters(){
|
|||
}
|
||||
|
||||
|
||||
void TextPagePrivate::makeAndSortLines(TextList &wordsTmp, SortedTextList &lines, LineRect &line_rects){
|
||||
void TextPagePrivate::makeAndSortLines(TextList &wordsTmp,
|
||||
SortedTextList &lines, LineRect &line_rects, bool debug=false){
|
||||
|
||||
/**
|
||||
we cannot assume that the generator will give us texts in the right order. We can only assume
|
||||
|
@ -1346,6 +1346,14 @@ void TextPagePrivate::makeAndSortLines(TextList &wordsTmp, SortedTextList &lines
|
|||
// Step:1 .......................................
|
||||
qSort(words.begin(),words.end(),compareTinyTextEntityY);
|
||||
|
||||
if(debug){
|
||||
cout << endl << endl << "After Y sorting: " << endl;
|
||||
for(int i = 0 ; i < words.length() ; i++){
|
||||
TinyTextEntity* ent = words.at(i);
|
||||
cout << ent->text().toAscii().data();
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// Step 2: .......................................
|
||||
|
||||
|
@ -1386,40 +1394,58 @@ void TextPagePrivate::makeAndSortLines(TextList &wordsTmp, SortedTextList &lines
|
|||
|
||||
|
||||
// if the font sizes vary very much, they will not make a line
|
||||
if(lineArea.height() > 2 * elementArea.height()) continue;
|
||||
// if(lineArea.height() > 2 * elementArea.height()) continue;
|
||||
// try to collect font info here
|
||||
|
||||
// if the new text and the line has y overlapping parts of more than 80%,
|
||||
// the text will be added to this line
|
||||
int overlap,percentage;
|
||||
// int overlap,percentage;
|
||||
|
||||
if(doesConsumeY(elementArea,lineArea,70)){
|
||||
|
||||
TextList tmp = lines.at(i);
|
||||
tmp.append((*it));
|
||||
|
||||
lines.replace(i,tmp);
|
||||
|
||||
newLeft = line_x1 < text_x1 ? line_x1 : text_x1;
|
||||
newRight = line_x2 > text_x2 ? line_x2 : text_x2;
|
||||
newTop = line_y1 < text_y1 ? line_y1 : text_y1;
|
||||
newBottom = text_y2 > line_y2 ? text_y2 : line_y2;
|
||||
|
||||
line_rects.replace( i, QRect( newLeft,newTop, newRight - newLeft, newBottom - newTop ) );
|
||||
found = true;
|
||||
}
|
||||
|
||||
// if there is overlap
|
||||
if(text_y2 >= line_y1 && line_y2 >= text_y1){
|
||||
// if(text_y2 >= line_y1 && line_y2 >= text_y1){
|
||||
|
||||
if(text_y2 > line_y2) overlap = line_y2 - text_y1;
|
||||
else overlap = text_y2 - line_y1;
|
||||
// if(text_y2 > line_y2) overlap = line_y2 - text_y1;
|
||||
// else overlap = text_y2 - line_y1;
|
||||
|
||||
if( (text_y2 - text_y1) > (line_y2 - line_y1) )
|
||||
percentage = overlap * 100 / (line_y2 - line_y1);
|
||||
else percentage = overlap * 100 / (text_y2 - text_y1);
|
||||
// if( (text_y2 - text_y1) > (line_y2 - line_y1) )
|
||||
// percentage = overlap * 100 / (line_y2 - line_y1);
|
||||
// else percentage = overlap * 100 / (text_y2 - text_y1);
|
||||
|
||||
//the overlap percentage is more than 70% of the smaller y
|
||||
if(percentage >= 70){
|
||||
// //the overlap percentage is more than 70% of the smaller y
|
||||
// if(percentage >= 70){
|
||||
|
||||
TextList tmp = lines.at(i);
|
||||
tmp.append((*it));
|
||||
// TextList tmp = lines.at(i);
|
||||
// tmp.append((*it));
|
||||
|
||||
lines.replace(i,tmp);
|
||||
// lines.replace(i,tmp);
|
||||
|
||||
newLeft = line_x1 < text_x1 ? line_x1 : text_x1;
|
||||
newRight = line_x2 > text_x2 ? line_x2 : text_x2;
|
||||
newTop = line_y1 < text_y1 ? line_y1 : text_y1;
|
||||
newBottom = text_y2 > line_y2 ? text_y2 : line_y2;
|
||||
// newLeft = line_x1 < text_x1 ? line_x1 : text_x1;
|
||||
// newRight = line_x2 > text_x2 ? line_x2 : text_x2;
|
||||
// newTop = line_y1 < text_y1 ? line_y1 : text_y1;
|
||||
// newBottom = text_y2 > line_y2 ? text_y2 : line_y2;
|
||||
|
||||
line_rects.replace( i, QRect( newLeft,newTop, newRight - newLeft, newBottom - newTop ) );
|
||||
found = true;
|
||||
}
|
||||
// line_rects.replace( i, QRect( newLeft,newTop, newRight - newLeft, newBottom - newTop ) );
|
||||
// found = true;
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
if(found) break;
|
||||
|
||||
}
|
||||
|
||||
|
@ -1442,7 +1468,8 @@ void TextPagePrivate::makeAndSortLines(TextList &wordsTmp, SortedTextList &lines
|
|||
qSort(list.begin(),list.end(),compareTinyTextEntityX);
|
||||
lines.replace(i,list);
|
||||
|
||||
printTextList(i,list);
|
||||
if(debug)
|
||||
printTextList(i,list);
|
||||
}
|
||||
|
||||
//we cannot delete words here, as lines contains the same pointers as words does
|
||||
|
@ -1867,8 +1894,27 @@ void TextPagePrivate::addNecessarySpace(){
|
|||
SortedTextList lines;
|
||||
LineRect line_rects;
|
||||
|
||||
cout << endl << "Before making Line: ..................... " << j << endl;
|
||||
for(i = 0 ; i < tmpList.length() ; i++){
|
||||
TinyTextEntity* ent = tmpList.at(i);
|
||||
cout << ent->text().toAscii().data();
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
makeAndSortLines(tmpList,lines,line_rects);
|
||||
// This makeAndSortLines is not working perfectly. We may remove it and
|
||||
// replace it by something so that everything works perfectly.
|
||||
makeAndSortLines(tmpList,lines,line_rects,true);
|
||||
|
||||
cout << "After making Line: " << endl;
|
||||
|
||||
for( i = 0; i < lines.length() ; i++){
|
||||
TextList list = lines.at(i);
|
||||
for(k = 0 ; k < list.length() ; k++){
|
||||
TinyTextEntity* ent = list.at(k);
|
||||
cout << ent->text().toAscii().data();
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
|
||||
// 4. Now, we add space in between texts in a region
|
||||
|
|
|
@ -82,7 +82,7 @@ class TextPagePrivate
|
|||
/**
|
||||
Create lines from TextList and sort them according to their position
|
||||
**/
|
||||
void makeAndSortLines(TextList &words,SortedTextList &lines,LineRect &line_rects);
|
||||
void makeAndSortLines(TextList &words,SortedTextList &lines,LineRect &line_rects, bool debug);
|
||||
|
||||
/**
|
||||
Caluclate statistical info like, word spacing, column spacing, line spacing from the Lines
|
||||
|
|
|
@ -1610,11 +1610,13 @@ void PageView::mouseMoveEvent( QMouseEvent * e )
|
|||
// clear the selection from pages not selected anymore
|
||||
foreach( int p, noMoreSelectedPages )
|
||||
{
|
||||
// cout << "Pages with selection set color Black " << endl;
|
||||
d->document->setPageTextSelection( p, 0, QColor() );
|
||||
}
|
||||
// set the new selection for the selected pages
|
||||
foreach( int p, pagesWithSelectionSet )
|
||||
{
|
||||
// cout << "Pages with selection set color Blue " << endl;
|
||||
d->document->setPageTextSelection( p, selections[ p - first ], palette().color( QPalette::Active, QPalette::Highlight ) );
|
||||
}
|
||||
d->pagesWithTextSelection = pagesWithSelectionSet;
|
||||
|
@ -2123,6 +2125,7 @@ void PageView::mouseReleaseEvent( QMouseEvent * e )
|
|||
d->aPrevAction = 0;
|
||||
}
|
||||
}break;
|
||||
|
||||
case MouseTextSelect:
|
||||
setCursor( Qt::ArrowCursor );
|
||||
if ( d->mouseTextSelecting )
|
||||
|
|
Loading…
Reference in a new issue