Skip to content

Commit

Permalink
Fix compilation errors on Qt 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Tvangeste committed Jul 18, 2013
1 parent 0db2ae6 commit 99526b9
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 16 deletions.
4 changes: 4 additions & 0 deletions articleinspector.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "articleinspector.hh"

#if QT_VERSION >= 0x040600

#include <algorithm>

using std::list;
Expand Down Expand Up @@ -49,3 +51,5 @@ void ArticleInspector::showEvent( QShowEvent * event )

QWebInspector::showEvent( event );
}

#endif // QT_VERSION
6 changes: 6 additions & 0 deletions articleinspector.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef ARTICLEINSPECTOR_HH
#define ARTICLEINSPECTOR_HH

#include <QtGlobal>

#if QT_VERSION >= 0x040600

#include <QWebInspector>
#include <list>
#include "config.hh"
Expand Down Expand Up @@ -28,4 +32,6 @@ private:
static std::list< ArticleInspector * > openedInspectors;
};

#endif // QT_VERSION

#endif // ARTICLEINSPECTOR_HH
12 changes: 10 additions & 2 deletions articleview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
#include "dprintf.hh"
#include "ffmpegaudio.hh"
#include <QDebug>
#include <QWebElement>
#include <QCryptographicHash>

#if QT_VERSION >= 0x040600
#include <QWebElement>
#endif

#include <assert.h>

#ifdef Q_OS_WIN32
Expand Down Expand Up @@ -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 )
Expand All @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );

Expand Down
13 changes: 11 additions & 2 deletions articlewebview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <QApplication>
#include "articleinspector.hh"


ArticleWebView::ArticleWebView( QWidget *parent ):
QWebView( parent ),
#if QT_VERSION >= 0x040600
inspector( NULL ),
#endif
midButtonPressed( false ),
selectionBySingleClick( false ),
showInspectorDirectly( true )
Expand All @@ -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 )
Expand All @@ -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.
Expand All @@ -50,6 +54,7 @@ void ArticleWebView::triggerPageAction( QWebPage::WebAction action, bool checked
return;
}
}
#endif

QWebView::triggerPageAction( action, checked );
}
Expand Down Expand Up @@ -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 ) &&
Expand Down
23 changes: 17 additions & 6 deletions extlineedit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include <QPainter>

#if QT_VERSION >= 0x040600
#include <QPropertyAnimation>
#endif

ExtLineEdit::ExtLineEdit(QWidget *parent) :
QLineEdit(parent)
{
Expand Down Expand Up @@ -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()
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
1 change: 0 additions & 1 deletion extlineedit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <QLineEdit>
#include <QAbstractButton>
#include <QPropertyAnimation>

class IconButton: public QAbstractButton
{
Expand Down
5 changes: 5 additions & 0 deletions gdappstyle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QWidget>
Expand Down Expand Up @@ -44,3 +47,5 @@ bool GdAppStyle::dictionaryBarButton(const QWidget * widget) const {

return false;
}

#endif // QT_VERSION
7 changes: 7 additions & 0 deletions gdappstyle.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#ifndef GDAPPSTYLE_HH
#define GDAPPSTYLE_HH

#include <QtGlobal>

#if QT_VERSION >= 0x040600

#include <QStyle>
#include <QProxyStyle>
#include <QStyleOption>

Expand All @@ -25,4 +30,6 @@ private:

};

#endif // QT_VERSION

#endif // GDAPPSTYLE_HH
2 changes: 2 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
Expand Down
25 changes: 20 additions & 5 deletions xdxf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srt>, that overrides the article sorting order
if ( stream.name() == "k" )
{
words.push_back( stream.readElementText( QXmlStreamReader::SkipChildElements ) );
words.push_back( readElementText( stream ) );
return;
}

Expand Down Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down

0 comments on commit 99526b9

Please sign in to comment.