Skip to content

Commit

Permalink
Qt5 compatibility
Browse files Browse the repository at this point in the history
This commit squashes all the changes in the Qt5 branch
relative to master.

Backward compatibility with Qt4 is retained.

Original authors:

- Philip Kaufmann <phil.kaufmann@t-online.de>
- Jonas Schnelli <jonas.schnelli@include7.ch>
  • Loading branch information
laanwj committed Jun 1, 2013
1 parent 365ab22 commit 25c0cce
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 14 deletions.
6 changes: 5 additions & 1 deletion bitcoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ TARGET = bitcoin-qt
macx:TARGET = "Bitcoin-Qt"
VERSION = 0.8.2
INCLUDEPATH += src src/json src/qt
QT += network
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd
CONFIG += thread
Expand Down Expand Up @@ -211,6 +212,7 @@ HEADERS += src/qt/bitcoingui.h \
src/leveldb.h \
src/threadsafety.h \
src/limitedmap.h \
src/qt/macnotificationhandler.h \

This comment has been minimized.

Copy link
@Diapolo

Diapolo Jun 5, 2013

AFAIK this is not needed here and seems to have sneaked back in by the Qt5 pull?
It's below in macx:HEADERS in my local build?

@jonasschnelli Can you take a look?

src/qt/splashscreen.h

SOURCES += src/qt/bitcoin.cpp \
Expand Down Expand Up @@ -312,6 +314,7 @@ DEFINES += BITCOIN_QT_TEST
macx: CONFIG -= app_bundle
}

# Todo: Remove this line when switching to Qt5, as that option was removed
CODECFORTR = UTF-8

# for lrelease/lupdate
Expand All @@ -335,6 +338,7 @@ QMAKE_EXTRA_COMPILERS += TSQM
OTHER_FILES += README.md \
doc/*.rst \
doc/*.txt \
doc/*.md \
src/qt/res/bitcoin-qt.rc \
src/test/*.cpp \
src/test/*.h \
Expand Down
6 changes: 6 additions & 0 deletions doc/readme-qt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ for Ubuntu >= 12.04 (please read the 'Berkely DB version warning' below):
libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev \
libssl-dev libdb++-dev libminiupnpc-dev

For Qt 5 you need the following, otherwise you get an error with lrelease when running qmake:

::

apt-get install qt5-qmake libqt5gui5 libqt5core5 libqt5dbus5 qttools5-dev-tools

then execute the following:

::
Expand Down
5 changes: 5 additions & 0 deletions src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ void AddressBookPage::setModel(AddressTableModel *model)
ui->tableView->sortByColumn(0, Qt::AscendingOrder);

// Set column widths
#if QT_VERSION < 0x050000
ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents);
#else
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setSectionResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents);
#endif

connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(selectionChanged()));
Expand Down
4 changes: 4 additions & 0 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "splashscreen.h"

#include <QMessageBox>
#if QT_VERSION < 0x050000
#include <QTextCodec>
#endif
#include <QLocale>
#include <QTimer>
#include <QTranslator>
Expand Down Expand Up @@ -118,9 +120,11 @@ int main(int argc, char *argv[])
// Command-line options take precedence:
ParseParameters(argc, argv);

#if QT_VERSION < 0x050000
// Internal string conversion is all UTF-8
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
#endif

Q_INIT_RESOURCE(bitcoin);
QApplication app(argc, argv);
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#include <QMovie>
#include <QTimer>
#include <QDragEnterEvent>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif
#include <QMimeData>
#include <QStyle>
#include <QSettings>
Expand Down
20 changes: 19 additions & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
#include <QDoubleValidator>
#include <QFont>
#include <QLineEdit>
#if QT_VERSION >= 0x050000

This comment has been minimized.

Copy link
@Gitju

Gitju Jan 17, 2014

Is

if QT_VERSION >= 0x050000

correct or did you meant

if QT_VERSION < 0x050000

in src/qt/guiutil.cpp

This comment has been minimized.

Copy link
@laanwj

laanwj via email Jan 17, 2014

Author Member

This comment has been minimized.

Copy link
@Gitju

Gitju Jan 17, 2014

Wonder why b/c I read in https://bitcointalk.org/index.php?topic=149479.0 that

if QT_VERSION < 0x050000 has to be inserted

and in every file I found it but not in this line.
Here I found >=

This comment has been minimized.

Copy link
@Diapolo

Diapolo Jan 17, 2014

QUrlQuery is only available for Qt versions >= 5.0.0, so this is correct IMHO.

This comment has been minimized.

Copy link
@Gitju

Gitju Jan 17, 2014

Ok found it.
Its correct.

#include <QUrlQuery>
#else
#include <QUrl>
#include <QTextDocument> // For Qt::escape
#endif
#include <QTextDocument> // for Qt::mightBeRichText
#include <QAbstractItemView>
#include <QClipboard>
#include <QFileDialog>
Expand Down Expand Up @@ -86,7 +90,13 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
SendCoinsRecipient rv;
rv.address = uri.path();
rv.amount = 0;

#if QT_VERSION < 0x050000
QList<QPair<QString, QString> > items = uri.queryItems();
#else
QUrlQuery uriQuery(uri);
QList<QPair<QString, QString> > items = uriQuery.queryItems();
#endif
for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
{
bool fShouldReturnFalse = false;
Expand Down Expand Up @@ -139,7 +149,11 @@ bool parseBitcoinURI(QString uri, SendCoinsRecipient *out)

QString HtmlEscape(const QString& str, bool fMultiLine)
{
#if QT_VERSION < 0x050000
QString escaped = Qt::escape(str);
#else
QString escaped = str.toHtmlEscaped();
#endif
if(fMultiLine)
{
escaped = escaped.replace("\n", "<br>\n");
Expand Down Expand Up @@ -176,7 +190,11 @@ QString getSaveFileName(QWidget *parent, const QString &caption,
QString myDir;
if(dir.isEmpty()) // Default to user documents location
{
#if QT_VERSION < 0x050000
myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
}
else
{
Expand Down
30 changes: 22 additions & 8 deletions src/qt/macdockiconhandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <QMenu>
#include <QWidget>

extern void qt_mac_set_dock_menu(QMenu*);
#include <QTemporaryFile>
#include <QImageWriter>

#undef slots
#include <Cocoa/Cocoa.h>
Expand Down Expand Up @@ -47,11 +47,11 @@ - (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAp
MacDockIconHandler::MacDockIconHandler() : QObject()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];

this->m_dockIconClickEventHandler = [[DockIconClickEventHandler alloc] initWithDockIconHandler:this];
this->m_dummyWidget = new QWidget();
this->m_dockMenu = new QMenu(this->m_dummyWidget);
qt_mac_set_dock_menu(this->m_dockMenu);

[pool release];
}

Expand All @@ -74,15 +74,29 @@ - (void)handleDockClickEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAp
void MacDockIconHandler::setIcon(const QIcon &icon)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *image;
NSImage *image = nil;
if (icon.isNull())
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
else {
// generate NSImage from QIcon and use this as dock icon.
QSize size = icon.actualSize(QSize(128, 128));
QPixmap pixmap = icon.pixmap(size);
CGImageRef cgImage = pixmap.toMacCGImageRef();
image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
CFRelease(cgImage);

// write temp file hack (could also be done through QIODevice [memory])
QTemporaryFile notificationIconFile;
if (!pixmap.isNull() && notificationIconFile.open()) {
QImageWriter writer(&notificationIconFile, "PNG");
if (writer.write(pixmap.toImage())) {
const char *cString = notificationIconFile.fileName().toUtf8().data();
NSString *macString = [NSString stringWithCString:cString encoding:NSUTF8StringEncoding];
image = [[NSImage alloc] initWithContentsOfFile:macString];
}
}

if(!image) {
// if testnet image could not be created, load std. app icon
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
}
}

[NSApp setApplicationIconImage:image];
Expand Down
2 changes: 2 additions & 0 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <QLocalServer>
#include <QLocalSocket>
#include <QStringList>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif

using namespace boost;

Expand Down
2 changes: 2 additions & 0 deletions src/qt/qrcodedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include "optionsmodel.h"

#include <QPixmap>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif

#include <qrencode.h>

Expand Down
2 changes: 2 additions & 0 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <QTime>
#include <QThread>
#include <QKeyEvent>
#if QT_VERSION < 0x050000
#include <QUrl>
#endif
#include <QScrollBar>

#include <openssl/crypto.h>
Expand Down
4 changes: 4 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ void SendCoinsDialog::on_sendButton_clicked()
QStringList formatted;
foreach(const SendCoinsRecipient &rcp, recipients)
{
#if QT_VERSION < 0x050000
formatted.append(tr("<b>%1</b> to %2 (%3)").arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount), Qt::escape(rcp.label), rcp.address));
#else
formatted.append(tr("<b>%1</b> to %2 (%3)").arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount), rcp.label.toHtmlEscaped(), rcp.address));
#endif
}

fNewRecipientAllowed = false;
Expand Down
1 change: 1 addition & 0 deletions src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "util.h"

#include <QPainter>
#undef loop /* ugh, remove this when the #define loop is gone from util.h */
#include <QApplication>

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :
Expand Down
4 changes: 4 additions & 0 deletions src/qt/transactionview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ void TransactionView::setModel(WalletModel *model)
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Status, 23);
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Date, 120);
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Type, 120);
#if QT_VERSION < 0x050000
transactionView->horizontalHeader()->setResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
#else
transactionView->horizontalHeader()->setSectionResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
#endif
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Amount, 100);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/qt/walletframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
#include "bitcoingui.h"
#include "walletstack.h"

#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>

#include <stdio.h>

WalletFrame::WalletFrame(BitcoinGUI *_gui) :
QFrame(_gui),
gui(_gui),
Expand Down
3 changes: 2 additions & 1 deletion src/qt/walletframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class WalletStack;
class WalletFrame : public QFrame
{
Q_OBJECT

public:
explicit WalletFrame(BitcoinGUI *_gui);
explicit WalletFrame(BitcoinGUI *_gui = 0);
~WalletFrame();

void setClientModel(ClientModel *clientModel);
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ QT_END_NAMESPACE
class WalletStack : public QStackedWidget
{
Q_OBJECT

public:
explicit WalletStack(QWidget *parent = 0);
~WalletStack();
Expand Down
8 changes: 8 additions & 0 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QAction>
#if QT_VERSION < 0x050000
#include <QDesktopServices>
#else
#include <QStandardPaths>
#endif
#include <QFileDialog>
#include <QPushButton>

Expand Down Expand Up @@ -232,7 +236,11 @@ void WalletView::encryptWallet(bool status)

void WalletView::backupWallet()
{
#if QT_VERSION < 0x050000
QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
QString saveDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
if (!filename.isEmpty()) {
if (!walletModel->backupWallet(filename)) {
Expand Down

0 comments on commit 25c0cce

Please sign in to comment.