diff --git a/README.md b/README.md index ac83c8f0..1c618d94 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ This code has been run and tested on Windows XP/Vista/7, Ubuntu Linux, Mac OS X. ### External Deps * Make, GCC, Git -* Qt framework. Minumal required version is 4.5. But Qt 4.7 or 4.8 is recommended. +* Qt framework. Minimum required version is 4.6 for Windows, 4.5 for all other platforms. But Qt 4.7 or 4.8 is recommended. +* If you want to use Qt 5.x then use branch qt4x5 * Qt Creator IDE is recommended for development * Various libraries on Linux (png, zlib, etc) * On Mac and Windows all the libraries are already included in the repository diff --git a/orderandprops.cc b/orderandprops.cc index de9fd9a2..73977db3 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -193,6 +193,8 @@ void OrderAndProps::disableDictionaryDescription() ui.dictionaryDescription->clear(); ui.dictionaryDescription->setVisible( false ); ui.dictionaryDescriptionLabel->setVisible( false ); + ui.infoVerticalSpacer->changeSize( 20, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ); + ui.infoVerticalLayout->invalidate(); } void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const & idx ) @@ -235,12 +237,15 @@ void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const ui.dictionaryDescription->setPlainText( descText ); ui.dictionaryDescription->setVisible( true ); ui.dictionaryDescriptionLabel->setVisible( true ); + ui.infoVerticalSpacer->changeSize( 0, 0, QSizePolicy::Minimum, QSizePolicy::Minimum ); } else { ui.dictionaryDescription->setVisible( false ); ui.dictionaryDescriptionLabel->setVisible( false ); + ui.infoVerticalSpacer->changeSize( 20, 5, QSizePolicy::Minimum, QSizePolicy::Expanding ); } + ui.infoVerticalLayout->invalidate(); } } diff --git a/orderandprops.ui b/orderandprops.ui index 93c6143e..62d48533 100644 --- a/orderandprops.ui +++ b/orderandprops.ui @@ -66,7 +66,7 @@ Dictionary information - + @@ -214,7 +214,7 @@ - + Qt::Vertical diff --git a/stardict.cc b/stardict.cc index 51b3e64c..56f14f20 100644 --- a/stardict.cc +++ b/stardict.cc @@ -562,7 +562,10 @@ QString const& StardictDictionary::getDescription() Ifo ifo( ifoFile ); if( !ifo.copyright.empty() ) - dictionaryDescription += "Copyright: " + QString::fromUtf8( ifo.copyright.c_str() ) + "\n\n"; + dictionaryDescription += "Copyright: " + + QString::fromUtf8( ifo.copyright.c_str() ) + .replace( "
", "\n", Qt::CaseInsensitive ) + + "\n\n"; if( !ifo.author.empty() ) dictionaryDescription += "Author: " + QString::fromUtf8( ifo.author.c_str() ) + "\n\n"; @@ -574,7 +577,8 @@ QString const& StardictDictionary::getDescription() { QString desc = QString::fromUtf8( ifo.description.c_str() ); desc.replace( "\t", "
" ); - desc.replace( "\\n", "
" ); + desc.replace( "\\n", "\n" ); + desc.replace( "
", "\n", Qt::CaseInsensitive ); dictionaryDescription += Html::unescape( desc ); } diff --git a/zim.cc b/zim.cc index 4ee359f8..e085a053 100644 --- a/zim.cc +++ b/zim.cc @@ -598,93 +598,80 @@ string ZimDictionary::convert( const string & in ) { QString text = QString::fromUtf8( in.c_str() ); + // replace background text.replace( QRegExp( "<\\s*body\\s*([^>]*)background:([^;\"]*)" ), QString( "]*)src=(\"|)/" ), + // pattern of img and script + text.replace( QRegExp( "<\\s*(img|script)\\s*([^>]*)src=(\"|)(\\.\\.|)/" ), QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); // Fix links without '"' - text.replace( QRegExp( "href=/([^\\s>]+)" ), QString( "href=\"/\\1\"" ) ); + text.replace( QRegExp( "href=(\\.\\.|)/([^\\s>]+)" ), QString( "href=\"\\1/\\2\"" ) ); - text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"/" ), + // pattern + text.replace( QRegExp( "<\\s*link\\s*([^>]*)href=\"(\\.\\.|)/" ), QString( "]*)href=\"/[^\"]*\"\\s*title=\"([^\"]*)\"", + // localize the http://en.wiki***.com|org/wiki/ series links + // excluding those keywords that have ":" in it + QString urlWiki = "\"http(s|)://en\\.(wiki(pedia|books|news|quote|source|voyage|versity)|wiktionary)\\.(org|com)/wiki/([^:\"]*)\""; + text.replace( QRegExp( "<\\s*a\\s+(class=\"external\"\\s+|)href=" + urlWiki ), + QString( ", excluding any known protocols such as http://, mailto:, #(comment) + // these links will be translated into local definitions + QRegExp rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>", Qt::CaseSensitive, QRegExp::RegExp2 ); - - QRegExp linkRegexp2( "<\\s*a\\s*([^>]*)href=\"/A/([^\"]*)\"", - Qt::CaseSensitive, - QRegExp::RegExp2 ); - - QRegExp linkRegexp3( ".(s|)htm(l|)", Qt::CaseInsensitive ); - int pos = 0; - while( pos >= 0 ) + while( (pos = rxLink.indexIn( text, pos )) >= 0 ) { - pos = linkRegexp1.indexIn( text, pos ); - if( pos < 0 ) - break; + QStringList list = rxLink.capturedTexts(); + QString tag = list[3]; // a url, ex: Precambrian_Chaotian.html + if ( !list[4].isEmpty() ) // a title, ex: title="Precambrian/Chaotian" + tag = list[4].split("\"")[1]; - QStringList list = linkRegexp1.capturedTexts(); - - QString tag = QString( "" ); + text.replace( pos, list[0].length(), tag ); pos += tag.length() + 1; } + // Occassionally words needs to be displayed in vertical, but
were changed to somewhere + // proper style:
N
e
o
p
t
e
r
a
+ QRegExp rxBR( "(]*>)\\s*((\\w\\s*<br(\\\\|/|)>\\s*)+\\w)\\s*", + Qt::CaseSensitive, + QRegExp::RegExp2 ); pos = 0; - while( pos >= 0 ) + while( (pos = rxBR.indexIn( text, pos )) >= 0 ) { - pos = linkRegexp2.indexIn( text, pos ); - if( pos < 0 ) - break; - - QStringList list = linkRegexp2.capturedTexts(); - - QString tag = QString( "" ). + prepend( list[1] ). + append( "" ); + text.replace( pos, list[0].length(), tag ); pos += tag.length() + 1; } + // // output all links in the page - only for analysis + // QRegExp rxPrintAllLinks( "<\\s*a\\s+[^>]*href=\"[^\"]*\"[^>]*>", + // Qt::CaseSensitive, + // QRegExp::RegExp2 ); + // pos = 0; + // while( (pos = rxPrintAllLinks.indexIn( text, pos )) >= 0 ) + // { + // QStringList list = rxPrintAllLinks.capturedTexts(); + // qDebug() << "\n--Alllinks--" << list[0]; + // pos += list[0].length() + 1; + // } + // Fix outstanding elements text += "
";