Fix compilation errors on Qt 4.5

This commit is contained in:
Tvangeste 2013-07-18 15:02:39 +02:00
parent 0db2ae6e57
commit 99526b98d3
10 changed files with 82 additions and 16 deletions

View file

@ -1,5 +1,7 @@
#include "articleinspector.hh" #include "articleinspector.hh"
#if QT_VERSION >= 0x040600
#include <algorithm> #include <algorithm>
using std::list; using std::list;
@ -49,3 +51,5 @@ void ArticleInspector::showEvent( QShowEvent * event )
QWebInspector::showEvent( event ); QWebInspector::showEvent( event );
} }
#endif // QT_VERSION

View file

@ -1,6 +1,10 @@
#ifndef ARTICLEINSPECTOR_HH #ifndef ARTICLEINSPECTOR_HH
#define ARTICLEINSPECTOR_HH #define ARTICLEINSPECTOR_HH
#include <QtGlobal>
#if QT_VERSION >= 0x040600
#include <QWebInspector> #include <QWebInspector>
#include <list> #include <list>
#include "config.hh" #include "config.hh"
@ -28,4 +32,6 @@ private:
static std::list< ArticleInspector * > openedInspectors; static std::list< ArticleInspector * > openedInspectors;
}; };
#endif // QT_VERSION
#endif // ARTICLEINSPECTOR_HH #endif // ARTICLEINSPECTOR_HH

View file

@ -19,9 +19,12 @@
#include "dprintf.hh" #include "dprintf.hh"
#include "ffmpegaudio.hh" #include "ffmpegaudio.hh"
#include <QDebug> #include <QDebug>
#include <QWebElement>
#include <QCryptographicHash> #include <QCryptographicHash>
#if QT_VERSION >= 0x040600
#include <QWebElement>
#endif
#include <assert.h> #include <assert.h>
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
@ -1236,6 +1239,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
} }
} }
#if QT_VERSION >= 0x040600
QWebElement el = r.element(); QWebElement el = r.element();
QUrl imageUrl; QUrl imageUrl;
if( !popupView && el.tagName().compare( "img", Qt::CaseInsensitive ) == 0 ) 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 ); saveSoundAction = new QAction( tr( "Save s&ound..." ), &menu );
menu.addAction( saveSoundAction ); menu.addAction( saveSoundAction );
} }
#endif
QString selectedText = ui.definition->selectedText(); QString selectedText = ui.definition->selectedText();
@ -1432,6 +1437,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
else else
if( result == saveImageAction || result == saveSoundAction ) if( result == saveImageAction || result == saveSoundAction )
{ {
#if QT_VERSION >= 0x040600
QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl; QUrl url = ( result == saveImageAction ) ? imageUrl : targetUrl;
QString savePath; QString savePath;
QString fileName; QString fileName;
@ -1480,6 +1486,7 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
emit storeResourceSavePath( QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ) ); emit storeResourceSavePath( QDir::toNativeSeparators( fileInfo.absoluteDir().absolutePath() ) );
saveResource( url, ui.definition->url(), fileName ); saveResource( url, ui.definition->url(), fileName );
} }
#endif
} }
else else
{ {
@ -1777,8 +1784,9 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check
if ( ui.searchCaseSensitive->isChecked() ) if ( ui.searchCaseSensitive->isChecked() )
f |= QWebPage::FindCaseSensitively; f |= QWebPage::FindCaseSensitively;
#if QT_VERSION >= 0x040600
f |= QWebPage::HighlightAllOccurrences; f |= QWebPage::HighlightAllOccurrences;
#endif
ui.definition->findText( "", f ); ui.definition->findText( "", f );

View file

@ -7,10 +7,11 @@
#include <QApplication> #include <QApplication>
#include "articleinspector.hh" #include "articleinspector.hh"
ArticleWebView::ArticleWebView( QWidget *parent ): ArticleWebView::ArticleWebView( QWidget *parent ):
QWebView( parent ), QWebView( parent ),
#if QT_VERSION >= 0x040600
inspector( NULL ), inspector( NULL ),
#endif
midButtonPressed( false ), midButtonPressed( false ),
selectionBySingleClick( false ), selectionBySingleClick( false ),
showInspectorDirectly( true ) showInspectorDirectly( true )
@ -19,8 +20,10 @@ ArticleWebView::ArticleWebView( QWidget *parent ):
ArticleWebView::~ArticleWebView() ArticleWebView::~ArticleWebView()
{ {
#if QT_VERSION >= 0x040600
if ( inspector ) if ( inspector )
inspector->deleteLater(); inspector->deleteLater();
#endif
} }
void ArticleWebView::setUp( Config::Class * cfg ) void ArticleWebView::setUp( Config::Class * cfg )
@ -30,6 +33,7 @@ void ArticleWebView::setUp( Config::Class * cfg )
void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked ) void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked )
{ {
#if QT_VERSION >= 0x040600
if ( action == QWebPage::InspectElement ) if ( action == QWebPage::InspectElement )
{ {
// Get or create inspector instance for current view. // Get or create inspector instance for current view.
@ -50,6 +54,7 @@ void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked
return; return;
} }
} }
#endif
QWebView::triggerPageAction( action, checked ); QWebView::triggerPageAction( action, checked );
} }
@ -102,9 +107,13 @@ void ArticleWebView::mouseReleaseEvent( QMouseEvent * event )
void ArticleWebView::mouseDoubleClickEvent( QMouseEvent * event ) void ArticleWebView::mouseDoubleClickEvent( QMouseEvent * event )
{ {
QWebView::mouseDoubleClickEvent( event ); QWebView::mouseDoubleClickEvent( event );
#if QT_VERSION >= 0x040600
int scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width(); int scrollBarWidth = page()->mainFrame()->scrollBarGeometry( Qt::Vertical ).width();
int scrollBarHeight = page()->mainFrame()->scrollBarGeometry( Qt::Horizontal ).height(); 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 // emit the signal only if we are not double-clicking on scrollbars
if ( ( event->x() < width() - scrollBarWidth ) && if ( ( event->x() < width() - scrollBarWidth ) &&

View file

@ -5,6 +5,10 @@
#include <QPainter> #include <QPainter>
#if QT_VERSION >= 0x040600
#include <QPropertyAnimation>
#endif
ExtLineEdit::ExtLineEdit(QWidget *parent) : ExtLineEdit::ExtLineEdit(QWidget *parent) :
QLineEdit(parent) QLineEdit(parent)
{ {
@ -95,10 +99,9 @@ void ExtLineEdit::updateMargins()
int leftMargin = iconButtons[realLeft]->pixmap().width() + 8; int leftMargin = iconButtons[realLeft]->pixmap().width() + 8;
int rightMargin = iconButtons[realRight]->pixmap().width() + 8; int rightMargin = iconButtons[realRight]->pixmap().width() + 8;
QMargins margins((iconEnabled[realLeft] ? leftMargin : 0), 1, setTextMargins(
(iconEnabled[realRight] ? rightMargin : 0), 1); (iconEnabled[realLeft] ? leftMargin : 0), 1,
(iconEnabled[realRight] ? rightMargin : 0), 1);
setTextMargins(margins);
} }
void ExtLineEdit::updateButtonPositions() void ExtLineEdit::updateButtonPositions()
@ -110,10 +113,14 @@ void ExtLineEdit::updateButtonPositions()
iconPos = (iconPos == Left ? Right : Left); iconPos = (iconPos == Left ? Right : Left);
if (iconPos == ExtLineEdit::Right) { 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)); iconButtons[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
} else { } 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)); iconButtons[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
} }
} }
@ -172,6 +179,7 @@ void IconButton::paintEvent(QPaintEvent *)
void IconButton::animate(bool visible) void IconButton::animate(bool visible)
{ {
#if QT_VERSION >= 0x040600
QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity"); QPropertyAnimation *animation = new QPropertyAnimation(this, "opacity");
animation->setDuration(250); animation->setDuration(250);
if (visible) if (visible)
@ -183,4 +191,7 @@ void IconButton::animate(bool visible)
animation->setEndValue(0.0); animation->setEndValue(0.0);
} }
animation->start(QAbstractAnimation::DeleteWhenStopped); animation->start(QAbstractAnimation::DeleteWhenStopped);
#else
setOpacity(visible ? 1.0 : 0.0);
#endif
} }

View file

@ -6,7 +6,6 @@
#include <QLineEdit> #include <QLineEdit>
#include <QAbstractButton> #include <QAbstractButton>
#include <QPropertyAnimation>
class IconButton: public QAbstractButton class IconButton: public QAbstractButton
{ {

View file

@ -2,6 +2,9 @@
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "gdappstyle.hh" #include "gdappstyle.hh"
#if QT_VERSION >= 0x040600
#include "dictionarybar.hh" #include "dictionarybar.hh"
#include <QWidget> #include <QWidget>
@ -44,3 +47,5 @@ bool GdAppStyle::dictionaryBarButton(const QWidget * widget) const {
return false; return false;
} }
#endif // QT_VERSION

View file

@ -4,6 +4,11 @@
#ifndef GDAPPSTYLE_HH #ifndef GDAPPSTYLE_HH
#define GDAPPSTYLE_HH #define GDAPPSTYLE_HH
#include <QtGlobal>
#if QT_VERSION >= 0x040600
#include <QStyle>
#include <QProxyStyle> #include <QProxyStyle>
#include <QStyleOption> #include <QStyleOption>
@ -25,4 +30,6 @@ private:
}; };
#endif // QT_VERSION
#endif // GDAPPSTYLE_HH #endif // GDAPPSTYLE_HH

View file

@ -113,7 +113,9 @@ int main( int argc, char ** argv )
app.setApplicationName( "GoldenDict" ); app.setApplicationName( "GoldenDict" );
app.setOrganizationDomain( "http://goldendict.org/" ); app.setOrganizationDomain( "http://goldendict.org/" );
#if QT_VERSION >= 0x040600
app.setStyle(new GdAppStyle); app.setStyle(new GdAppStyle);
#endif
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
app.setWindowIcon( QIcon( ":/icons/programicon.png" ) ); app.setWindowIcon( QIcon( ":/icons/programicon.png" ) );

25
xdxf.cc
View file

@ -678,12 +678,27 @@ QString readXhtmlData( QXmlStreamReader & stream )
return result; 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 ) void addAllKeyTags( QXmlStreamReader & stream, list< QString > & words )
{ {
// todo implement support for tag <srt>, that overrides the article sorting order // todo implement support for tag <srt>, that overrides the article sorting order
if ( stream.name() == "k" ) if ( stream.name() == "k" )
{ {
words.push_back( stream.readElementText( QXmlStreamReader::SkipChildElements ) ); words.push_back( readElementText( stream ) );
return; return;
} }
@ -1156,12 +1171,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
stream.readNext(); stream.readNext();
if ( stream.isStartElement() && stream.name() == "abbr_k" ) if ( stream.isStartElement() && stream.name() == "abbr_k" )
{ {
s = stream.readElementText( QXmlStreamReader::SkipChildElements ); s = readElementText( stream );
keys.push_back( gd::toWString( s ) ); keys.push_back( gd::toWString( s ) );
} }
else if ( stream.isStartElement() && stream.name() == "abbr_v" ) else if ( stream.isStartElement() && stream.name() == "abbr_v" )
{ {
s = stream.readElementText( QXmlStreamReader::SkipChildElements ); s = readElementText( stream );
value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) ); value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) );
for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i ) for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i )
{ {
@ -1180,12 +1195,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
stream.readNext(); stream.readNext();
if ( stream.isStartElement() && stream.name() == "k" ) if ( stream.isStartElement() && stream.name() == "k" )
{ {
s = stream.readElementText( QXmlStreamReader::SkipChildElements ); s = readElementText( stream );
keys.push_back( gd::toWString( s ) ); keys.push_back( gd::toWString( s ) );
} }
else if ( stream.isStartElement() && stream.name() == "v" ) else if ( stream.isStartElement() && stream.name() == "v" )
{ {
s = stream.readElementText( QXmlStreamReader::SkipChildElements ); s = readElementText( stream );
value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) ); value = Utf8::encode( Folding::trimWhitespace( gd::toWString( s ) ) );
for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i ) for( list< wstring >::iterator i = keys.begin(); i != keys.end(); ++i )
{ {