diff --git a/articleinspector.cc b/articleinspector.cc index e0653c2b..7ab091a7 100644 --- a/articleinspector.cc +++ b/articleinspector.cc @@ -1,5 +1,7 @@ #include "articleinspector.hh" +#if QT_VERSION >= 0x040600 + #include using std::list; @@ -49,3 +51,5 @@ void ArticleInspector::showEvent( QShowEvent * event ) QWebInspector::showEvent( event ); } + +#endif // QT_VERSION diff --git a/articleinspector.hh b/articleinspector.hh index f9d25fe5..97f0b593 100644 --- a/articleinspector.hh +++ b/articleinspector.hh @@ -1,6 +1,10 @@ #ifndef ARTICLEINSPECTOR_HH #define ARTICLEINSPECTOR_HH +#include + +#if QT_VERSION >= 0x040600 + #include #include #include "config.hh" @@ -28,4 +32,6 @@ private: static std::list< ArticleInspector * > openedInspectors; }; +#endif // QT_VERSION + #endif // ARTICLEINSPECTOR_HH diff --git a/articleview.cc b/articleview.cc index 76034deb..7e6594cc 100644 --- a/articleview.cc +++ b/articleview.cc @@ -19,9 +19,12 @@ #include "dprintf.hh" #include "ffmpegaudio.hh" #include -#include #include +#if QT_VERSION >= 0x040600 +#include +#endif + #include #ifdef Q_OS_WIN32 @@ -1236,6 +1239,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) } } +#if QT_VERSION >= 0x040600 QWebElement el = r.element(); QUrl imageUrl; if( !popupView && el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 ) @@ -1255,6 +1259,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) saveSoundAction = new QAction( tr( "Save s&ound..." ), &menu ); menu.addAction( saveSoundAction ); } +#endif QString selectedText = ui.definition->selectedText(); @@ -1432,6 +1437,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) else if( result == saveImageAction || result == saveSoundAction ) { +#if QT_VERSION >= 0x040600 QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl; QString savePath; QString fileName; @@ -1480,6 +1486,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos ) emit storeResourceSavePath( QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ) ); saveResource( url, ui.definition->url(), fileName ); } +#endif } else { @@ -1777,8 +1784,9 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check if ( ui.searchCaseSensitive->isChecked() ) f |= QWebPage::FindCaseSensitively; - +#if QT_VERSION >= 0x040600 f |= QWebPage::HighlightAllOccurrences; +#endif ui.definition->findText( "", f ); diff --git a/articlewebview.cc b/articlewebview.cc index 66ed6a03..b2b081dc 100644 --- a/articlewebview.cc +++ b/articlewebview.cc @@ -7,10 +7,11 @@ #include #include "articleinspector.hh" - ArticleWebView::ArticleWebView( QWidget *parent ): QWebView( parent ), +#if QT_VERSION >= 0x040600 inspector( NULL ), +#endif midButtonPressed( false ), selectionBySingleClick( false ), showInspectorDirectly( true ) @@ -19,8 +20,10 @@ ArticleWebView::ArticleWebView( QWidget *parent ): ArticleWebView::~ArticleWebView() { +#if QT_VERSION >= 0x040600 if ( inspector ) inspector->deleteLater(); +#endif } void ArticleWebView::setUp( Config::Class * cfg ) @@ -30,6 +33,7 @@ void ArticleWebView::setUp( Config::Class * cfg ) void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked ) { +#if QT_VERSION >= 0x040600 if ( action == QWebPage::InspectElement ) { // Get or create inspector instance for current view. @@ -50,6 +54,7 @@ void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked return; } } +#endif QWebView::triggerPageAction( action, checked ); } @@ -102,9 +107,13 @@ void ArticleWebView::mouseReleaseEvent( QMouseEvent * event ) void ArticleWebView::mouseDoubleClickEvent( QMouseEvent * event ) { QWebView::mouseDoubleClickEvent( event ); - +#if QT_VERSION >= 0x040600 int scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width(); int scrollBarHeight = page()->mainFrame()->scrollBarGeometry( Qt::Horizontal ).height(); +#else + int scrollBarWidth = 0; + int scrollBarHeight = 0; +#endif // emit the signal only if we are not double-clicking on scrollbars if ( ( event->x() < width() - scrollBarWidth ) && diff --git a/extlineedit.cc b/extlineedit.cc index a404f76e..89834d59 100644 --- a/extlineedit.cc +++ b/extlineedit.cc @@ -5,6 +5,10 @@ #include +#if QT_VERSION >= 0x040600 +#include +#endif + ExtLineEdit::ExtLineEdit(QWidget *parent) : QLineEdit(parent) { @@ -95,10 +99,9 @@ void ExtLineEdit::updateMargins() int leftMargin = iconButtons[realLeft]->pixmap().width() + 8; int rightMargin = iconButtons[realRight]->pixmap().width() + 8; - QMargins margins((iconEnabled[realLeft] ? leftMargin : 0), 1, - (iconEnabled[realRight] ? rightMargin : 0), 1); - - setTextMargins(margins); + setTextMargins( + (iconEnabled[realLeft] ? leftMargin : 0), 1, + (iconEnabled[realRight] ? rightMargin : 0), 1); } void ExtLineEdit::updateButtonPositions() @@ -110,10 +113,14 @@ void ExtLineEdit::updateButtonPositions() iconPos = (iconPos == Left ? Right : Left); if (iconPos == ExtLineEdit::Right) { - const int iconoffset = textMargins().right() + 4; + int right; + getTextMargins(0, 0, &right, 0); + const int iconoffset = right + 4; iconButtons[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0)); } else { - const int iconoffset = textMargins().left() + 4; + int left; + getTextMargins(&left, 0, 0, 0); + const int iconoffset = left + 4; iconButtons[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0)); } } @@ -172,6 +179,7 @@ void IconButton::paintEvent(QPaintEvent *) void IconButton::animate(bool visible) { +#if QT_VERSION >= 0x040600 QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity"); animation->setDuration(250); if (visible) @@ -183,4 +191,7 @@ void IconButton::animate(bool visible) animation->setEndValue(0.0); } animation->start(QAbstractAnimation::DeleteWhenStopped); +#else + setOpacity(visible ? 1.0 : 0.0); +#endif } diff --git a/extlineedit.hh b/extlineedit.hh index 6a480fa7..15adfdff 100644 --- a/extlineedit.hh +++ b/extlineedit.hh @@ -6,7 +6,6 @@ #include #include -#include class IconButton: public QAbstractButton { diff --git a/gdappstyle.cc b/gdappstyle.cc index 0caa8b7d..fa7ef7ef 100644 --- a/gdappstyle.cc +++ b/gdappstyle.cc @@ -2,6 +2,9 @@ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #include "gdappstyle.hh" + +#if QT_VERSION >= 0x040600 + #include "dictionarybar.hh" #include @@ -44,3 +47,5 @@ bool GdAppStyle::dictionaryBarButton(const QWidget * widget) const { return false; } + +#endif // QT_VERSION diff --git a/gdappstyle.hh b/gdappstyle.hh index 28591b4d..006804fc 100644 --- a/gdappstyle.hh +++ b/gdappstyle.hh @@ -4,6 +4,11 @@ #ifndef GDAPPSTYLE_HH #define GDAPPSTYLE_HH +#include + +#if QT_VERSION >= 0x040600 + +#include #include #include @@ -25,4 +30,6 @@ private: }; +#endif // QT_VERSION + #endif // GDAPPSTYLE_HH diff --git a/main.cc b/main.cc index fc09a520..af4ba0b3 100644 --- a/main.cc +++ b/main.cc @@ -113,7 +113,9 @@ int main( int argc, char ** argv ) app.setApplicationName( "GoldenDict" ); app.setOrganizationDomain( "http://goldendict.org/" ); +#if QT_VERSION >= 0x040600 app.setStyle(new GdAppStyle); +#endif #ifndef Q_OS_MAC app.setWindowIcon( QIcon( ":/icons/programicon.png" ) ); diff --git a/xdxf.cc b/xdxf.cc index 2a4ec915..699fd419 100644 --- a/xdxf.cc +++ b/xdxf.cc @@ -678,12 +678,27 @@ QString readXhtmlData( QXmlStreamReader & stream ) return result; } +namespace { + +/// Deal with Qt 4.5 incompatibility +QString readElementText( QXmlStreamReader & stream ) +{ +#if QT_VERSION >= 0x040600 + return stream.readElementText( QXmlStreamReader::SkipChildElements ); +#else + return stream.readElementText(); +#endif +} + +} + + void addAllKeyTags( QXmlStreamReader & stream, list< QString > & words ) { // todo implement support for tag , that overrides the article sorting order if ( stream.name() == "k" ) { - words.push_back( stream.readElementText( QXmlStreamReader::SkipChildElements ) ); + words.push_back( readElementText( stream ) ); return; } @@ -1156,12 +1171,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( stream.readNext(); if ( stream.isStartElement() && stream.name() == "abbr_k" ) { - s = stream.readElementText( QXmlStreamReader::SkipChildElements ); + s = readElementText( stream ); keys.push_back( gd::toWString( s ) ); } else if ( stream.isStartElement() && stream.name() == "abbr_v" ) { - s = stream.readElementText( QXmlStreamReader::SkipChildElements ); + s = readElementText( stream ); value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) ); for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i ) { @@ -1180,12 +1195,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( stream.readNext(); if ( stream.isStartElement() && stream.name() == "k" ) { - s = stream.readElementText( QXmlStreamReader::SkipChildElements ); + s = readElementText( stream ); keys.push_back( gd::toWString( s ) ); } else if ( stream.isStartElement() && stream.name() == "v" ) { - s = stream.readElementText( QXmlStreamReader::SkipChildElements ); + s = readElementText( stream ); value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) ); for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i ) {