Browse Source

Merge pull request #2721 from laanwj/2013_05_qt5

Qt5 compatibility
0.10
Wladimir J. van der Laan 12 years ago
parent
commit
34d03f2474
  1. 6
      bitcoin-qt.pro
  2. 6
      doc/readme-qt.rst
  3. 5
      src/qt/addressbookpage.cpp
  4. 4
      src/qt/bitcoin.cpp
  5. 2
      src/qt/bitcoingui.cpp
  6. 20
      src/qt/guiutil.cpp
  7. 30
      src/qt/macdockiconhandler.mm
  8. 2
      src/qt/paymentserver.cpp
  9. 2
      src/qt/qrcodedialog.cpp
  10. 2
      src/qt/rpcconsole.cpp
  11. 4
      src/qt/sendcoinsdialog.cpp
  12. 1
      src/qt/splashscreen.cpp
  13. 4
      src/qt/transactionview.cpp
  14. 4
      src/qt/walletframe.cpp
  15. 3
      src/qt/walletframe.h
  16. 1
      src/qt/walletstack.h
  17. 8
      src/qt/walletview.cpp

6
bitcoin-qt.pro

@ -3,7 +3,8 @@ TARGET = bitcoin-qt
macx:TARGET = "Bitcoin-Qt" macx:TARGET = "Bitcoin-Qt"
VERSION = 0.8.2 VERSION = 0.8.2
INCLUDEPATH += src src/json src/qt 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 DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE
CONFIG += no_include_pwd CONFIG += no_include_pwd
CONFIG += thread CONFIG += thread
@ -211,6 +212,7 @@ HEADERS += src/qt/bitcoingui.h \
src/leveldb.h \ src/leveldb.h \
src/threadsafety.h \ src/threadsafety.h \
src/limitedmap.h \ src/limitedmap.h \
src/qt/macnotificationhandler.h \
src/qt/splashscreen.h src/qt/splashscreen.h
SOURCES += src/qt/bitcoin.cpp \ SOURCES += src/qt/bitcoin.cpp \
@ -312,6 +314,7 @@ DEFINES += BITCOIN_QT_TEST
macx: CONFIG -= app_bundle macx: CONFIG -= app_bundle
} }
# Todo: Remove this line when switching to Qt5, as that option was removed
CODECFORTR = UTF-8 CODECFORTR = UTF-8
# for lrelease/lupdate # for lrelease/lupdate
@ -335,6 +338,7 @@ QMAKE_EXTRA_COMPILERS += TSQM
OTHER_FILES += README.md \ OTHER_FILES += README.md \
doc/*.rst \ doc/*.rst \
doc/*.txt \ doc/*.txt \
doc/*.md \
src/qt/res/bitcoin-qt.rc \ src/qt/res/bitcoin-qt.rc \
src/test/*.cpp \ src/test/*.cpp \
src/test/*.h \ src/test/*.h \

6
doc/readme-qt.rst

@ -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 \ libboost-filesystem-dev libboost-program-options-dev libboost-thread-dev \
libssl-dev libdb++-dev libminiupnpc-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: then execute the following:
:: ::

5
src/qt/addressbookpage.cpp

@ -143,8 +143,13 @@ void AddressBookPage::setModel(AddressTableModel *model)
ui->tableView->sortByColumn(0, Qt::AscendingOrder); ui->tableView->sortByColumn(0, Qt::AscendingOrder);
// Set column widths // Set column widths
#if QT_VERSION < 0x050000
ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Label, QHeaderView::Stretch); ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Label, QHeaderView::Stretch);
ui->tableView->horizontalHeader()->setResizeMode(AddressTableModel::Address, QHeaderView::ResizeToContents); 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)), connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(selectionChanged())); this, SLOT(selectionChanged()));

4
src/qt/bitcoin.cpp

@ -17,7 +17,9 @@
#include "splashscreen.h" #include "splashscreen.h"
#include <QMessageBox> #include <QMessageBox>
#if QT_VERSION < 0x050000
#include <QTextCodec> #include <QTextCodec>
#endif
#include <QLocale> #include <QLocale>
#include <QTimer> #include <QTimer>
#include <QTranslator> #include <QTranslator>
@ -118,9 +120,11 @@ int main(int argc, char *argv[])
// Command-line options take precedence: // Command-line options take precedence:
ParseParameters(argc, argv); ParseParameters(argc, argv);
#if QT_VERSION < 0x050000
// Internal string conversion is all UTF-8 // Internal string conversion is all UTF-8
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForTr()); QTextCodec::setCodecForCStrings(QTextCodec::codecForTr());
#endif
Q_INIT_RESOURCE(bitcoin); Q_INIT_RESOURCE(bitcoin);
QApplication app(argc, argv); QApplication app(argc, argv);

2
src/qt/bitcoingui.cpp

@ -44,7 +44,9 @@
#include <QMovie> #include <QMovie>
#include <QTimer> #include <QTimer>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#if QT_VERSION < 0x050000
#include <QUrl> #include <QUrl>
#endif
#include <QMimeData> #include <QMimeData>
#include <QStyle> #include <QStyle>
#include <QSettings> #include <QSettings>

20
src/qt/guiutil.cpp

@ -13,8 +13,12 @@
#include <QDoubleValidator> #include <QDoubleValidator>
#include <QFont> #include <QFont>
#include <QLineEdit> #include <QLineEdit>
#if QT_VERSION >= 0x050000
#include <QUrlQuery>
#else
#include <QUrl> #include <QUrl>
#include <QTextDocument> // For Qt::escape #endif
#include <QTextDocument> // for Qt::mightBeRichText
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QClipboard> #include <QClipboard>
#include <QFileDialog> #include <QFileDialog>
@ -86,7 +90,13 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
SendCoinsRecipient rv; SendCoinsRecipient rv;
rv.address = uri.path(); rv.address = uri.path();
rv.amount = 0; rv.amount = 0;
#if QT_VERSION < 0x050000
QList<QPair<QString, QString> > items = uri.queryItems(); 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++) for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
{ {
bool fShouldReturnFalse = false; bool fShouldReturnFalse = false;
@ -139,7 +149,11 @@ bool parseBitcoinURI(QString uri, SendCoinsRecipient *out)
QString HtmlEscape(const QString& str, bool fMultiLine) QString HtmlEscape(const QString& str, bool fMultiLine)
{ {
#if QT_VERSION < 0x050000
QString escaped = Qt::escape(str); QString escaped = Qt::escape(str);
#else
QString escaped = str.toHtmlEscaped();
#endif
if(fMultiLine) if(fMultiLine)
{ {
escaped = escaped.replace("\n", "<br>\n"); escaped = escaped.replace("\n", "<br>\n");
@ -176,7 +190,11 @@ QString getSaveFileName(QWidget *parent, const QString &caption,
QString myDir; QString myDir;
if(dir.isEmpty()) // Default to user documents location if(dir.isEmpty()) // Default to user documents location
{ {
#if QT_VERSION < 0x050000
myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); myDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation);
#else
myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
#endif
} }
else else
{ {

30
src/qt/macdockiconhandler.mm

@ -2,8 +2,8 @@
#include <QMenu> #include <QMenu>
#include <QWidget> #include <QWidget>
#include <QTemporaryFile>
extern void qt_mac_set_dock_menu(QMenu*); #include <QImageWriter>
#undef slots #undef slots
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
@ -47,11 +47,11 @@ extern void qt_mac_set_dock_menu(QMenu*);
MacDockIconHandler::MacDockIconHandler() : QObject() MacDockIconHandler::MacDockIconHandler() : QObject()
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 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_dummyWidget = new QWidget();
this->m_dockMenu = new QMenu(this->m_dummyWidget); this->m_dockMenu = new QMenu(this->m_dummyWidget);
qt_mac_set_dock_menu(this->m_dockMenu);
[pool release]; [pool release];
} }
@ -74,15 +74,29 @@ QMenu *MacDockIconHandler::dockMenu()
void MacDockIconHandler::setIcon(const QIcon &icon) void MacDockIconHandler::setIcon(const QIcon &icon)
{ {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSImage *image; NSImage *image = nil;
if (icon.isNull()) if (icon.isNull())
image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; image = [[NSImage imageNamed:@"NSApplicationIcon"] retain];
else { else {
// generate NSImage from QIcon and use this as dock icon.
QSize size = icon.actualSize(QSize(128, 128)); QSize size = icon.actualSize(QSize(128, 128));
QPixmap pixmap = icon.pixmap(size); QPixmap pixmap = icon.pixmap(size);
CGImageRef cgImage = pixmap.toMacCGImageRef();
image = [[NSImage alloc] initWithCGImage:cgImage size:NSZeroSize]; // write temp file hack (could also be done through QIODevice [memory])
CFRelease(cgImage); 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]; [NSApp setApplicationIconImage:image];

2
src/qt/paymentserver.cpp

@ -18,7 +18,9 @@
#include <QLocalServer> #include <QLocalServer>
#include <QLocalSocket> #include <QLocalSocket>
#include <QStringList> #include <QStringList>
#if QT_VERSION < 0x050000
#include <QUrl> #include <QUrl>
#endif
using namespace boost; using namespace boost;

2
src/qt/qrcodedialog.cpp

@ -7,7 +7,9 @@
#include "optionsmodel.h" #include "optionsmodel.h"
#include <QPixmap> #include <QPixmap>
#if QT_VERSION < 0x050000
#include <QUrl> #include <QUrl>
#endif
#include <qrencode.h> #include <qrencode.h>

2
src/qt/rpcconsole.cpp

@ -8,7 +8,9 @@
#include <QTime> #include <QTime>
#include <QThread> #include <QThread>
#include <QKeyEvent> #include <QKeyEvent>
#if QT_VERSION < 0x050000
#include <QUrl> #include <QUrl>
#endif
#include <QScrollBar> #include <QScrollBar>
#include <openssl/crypto.h> #include <openssl/crypto.h>

4
src/qt/sendcoinsdialog.cpp

@ -93,7 +93,11 @@ void SendCoinsDialog::on_sendButton_clicked()
QStringList formatted; QStringList formatted;
foreach(const SendCoinsRecipient &rcp, recipients) 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)); 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; fNewRecipientAllowed = false;

1
src/qt/splashscreen.cpp

@ -3,6 +3,7 @@
#include "util.h" #include "util.h"
#include <QPainter> #include <QPainter>
#undef loop /* ugh, remove this when the #define loop is gone from util.h */
#include <QApplication> #include <QApplication>
SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) : SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) :

4
src/qt/transactionview.cpp

@ -176,7 +176,11 @@ void TransactionView::setModel(WalletModel *model)
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Status, 23); transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Status, 23);
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Date, 120); transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Date, 120);
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Type, 120); transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Type, 120);
#if QT_VERSION < 0x050000
transactionView->horizontalHeader()->setResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch); transactionView->horizontalHeader()->setResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
#else
transactionView->horizontalHeader()->setSectionResizeMode(TransactionTableModel::ToAddress, QHeaderView::Stretch);
#endif
transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Amount, 100); transactionView->horizontalHeader()->resizeSection(TransactionTableModel::Amount, 100);
} }
} }

4
src/qt/walletframe.cpp

@ -8,11 +8,9 @@
#include "bitcoingui.h" #include "bitcoingui.h"
#include "walletstack.h" #include "walletstack.h"
#include <QVBoxLayout> #include <QHBoxLayout>
#include <QMessageBox> #include <QMessageBox>
#include <stdio.h>
WalletFrame::WalletFrame(BitcoinGUI *_gui) : WalletFrame::WalletFrame(BitcoinGUI *_gui) :
QFrame(_gui), QFrame(_gui),
gui(_gui), gui(_gui),

3
src/qt/walletframe.h

@ -17,8 +17,9 @@ class WalletStack;
class WalletFrame : public QFrame class WalletFrame : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WalletFrame(BitcoinGUI *_gui); explicit WalletFrame(BitcoinGUI *_gui = 0);
~WalletFrame(); ~WalletFrame();
void setClientModel(ClientModel *clientModel); void setClientModel(ClientModel *clientModel);

1
src/qt/walletstack.h

@ -40,6 +40,7 @@ QT_END_NAMESPACE
class WalletStack : public QStackedWidget class WalletStack : public QStackedWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WalletStack(QWidget *parent = 0); explicit WalletStack(QWidget *parent = 0);
~WalletStack(); ~WalletStack();

8
src/qt/walletview.cpp

@ -21,7 +21,11 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QAction> #include <QAction>
#if QT_VERSION < 0x050000
#include <QDesktopServices> #include <QDesktopServices>
#else
#include <QStandardPaths>
#endif
#include <QFileDialog> #include <QFileDialog>
#include <QPushButton> #include <QPushButton>
@ -232,7 +236,11 @@ void WalletView::encryptWallet(bool status)
void WalletView::backupWallet() void WalletView::backupWallet()
{ {
#if QT_VERSION < 0x050000
QString saveDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); 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)")); QString filename = QFileDialog::getSaveFileName(this, tr("Backup Wallet"), saveDir, tr("Wallet Data (*.dat)"));
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
if (!walletModel->backupWallet(filename)) { if (!walletModel->backupWallet(filename)) {

Loading…
Cancel
Save