From 25c0cce7fb494fcb871d134e28b26504d30e34d3 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 31 May 2013 14:02:24 +0200 Subject: Qt5 compatibility This commit squashes all the changes in the Qt5 branch relative to master. Backward compatibility with Qt4 is retained. Original authors: - Philip Kaufmann - Jonas Schnelli --- src/qt/addressbookpage.cpp | 5 +++++ src/qt/bitcoin.cpp | 4 ++++ src/qt/bitcoingui.cpp | 2 ++ src/qt/guiutil.cpp | 20 +++++++++++++++++++- src/qt/macdockiconhandler.mm | 30 ++++++++++++++++++++++-------- src/qt/paymentserver.cpp | 2 ++ src/qt/qrcodedialog.cpp | 2 ++ src/qt/rpcconsole.cpp | 2 ++ src/qt/sendcoinsdialog.cpp | 4 ++++ src/qt/splashscreen.cpp | 1 + src/qt/transactionview.cpp | 4 ++++ src/qt/walletframe.cpp | 4 +--- src/qt/walletframe.h | 3 ++- src/qt/walletstack.h | 1 + src/qt/walletview.cpp | 8 ++++++++ 15 files changed, 79 insertions(+), 13 deletions(-) (limited to 'src/qt') diff --git a/src/qt/addressbookpage.cpp b/src/qt/addressbookpage.cpp index 8529c88b39..8906174d7d 100644 --- a/src/qt/addressbookpage.cpp +++ b/src/qt/addressbookpage.cpp @@ -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())); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index f525d1bb38..354c5af453 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -17,7 +17,9 @@ #include "splashscreen.h" #include +#if QT_VERSION < 0x050000 #include +#endif #include #include #include @@ -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); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 78a69af8b0..a4589860bf 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -44,7 +44,9 @@ #include #include #include +#if QT_VERSION < 0x050000 #include +#endif #include #include #include diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 2105f0730e..6937febfee 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -13,8 +13,12 @@ #include #include #include +#if QT_VERSION >= 0x050000 +#include +#else #include -#include // For Qt::escape +#endif +#include // for Qt::mightBeRichText #include #include #include @@ -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 > items = uri.queryItems(); +#else + QUrlQuery uriQuery(uri); + QList > items = uriQuery.queryItems(); +#endif for (QList >::iterator i = items.begin(); i != items.end(); i++) { bool fShouldReturnFalse = false; @@ -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", "
\n"); @@ -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 { diff --git a/src/qt/macdockiconhandler.mm b/src/qt/macdockiconhandler.mm index b6ea8e1d03..53b49c42e6 100644 --- a/src/qt/macdockiconhandler.mm +++ b/src/qt/macdockiconhandler.mm @@ -2,8 +2,8 @@ #include #include - -extern void qt_mac_set_dock_menu(QMenu*); +#include +#include #undef slots #include @@ -47,11 +47,11 @@ extern void qt_mac_set_dock_menu(QMenu*); 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]; } @@ -74,15 +74,29 @@ QMenu *MacDockIconHandler::dockMenu() 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(¬ificationIconFile, "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]; diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index a92e6fc329..0b0bce55bb 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -18,7 +18,9 @@ #include #include #include +#if QT_VERSION < 0x050000 #include +#endif using namespace boost; diff --git a/src/qt/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp index ca94975128..6ddcaaf5d9 100644 --- a/src/qt/qrcodedialog.cpp +++ b/src/qt/qrcodedialog.cpp @@ -7,7 +7,9 @@ #include "optionsmodel.h" #include +#if QT_VERSION < 0x050000 #include +#endif #include diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 50f22b877a..7f90f4a551 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -8,7 +8,9 @@ #include #include #include +#if QT_VERSION < 0x050000 #include +#endif #include #include diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index eb3ce48a6e..2c7bab2045 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -93,7 +93,11 @@ void SendCoinsDialog::on_sendButton_clicked() QStringList formatted; foreach(const SendCoinsRecipient &rcp, recipients) { +#if QT_VERSION < 0x050000 formatted.append(tr("%1 to %2 (%3)").arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount), Qt::escape(rcp.label), rcp.address)); +#else + formatted.append(tr("%1 to %2 (%3)").arg(BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, rcp.amount), rcp.label.toHtmlEscaped(), rcp.address)); +#endif } fNewRecipientAllowed = false; diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index f8d16699ca..95948a6cbd 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -3,6 +3,7 @@ #include "util.h" #include +#undef loop /* ugh, remove this when the #define loop is gone from util.h */ #include SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) : diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 9240b71c71..a43e29c476 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -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); } } diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 83e4255c9f..50c03ac62d 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -8,11 +8,9 @@ #include "bitcoingui.h" #include "walletstack.h" -#include +#include #include -#include - WalletFrame::WalletFrame(BitcoinGUI *_gui) : QFrame(_gui), gui(_gui), diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 3649185e8a..d7092f9879 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -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); diff --git a/src/qt/walletstack.h b/src/qt/walletstack.h index ea4cc121d1..506d595c0f 100644 --- a/src/qt/walletstack.h +++ b/src/qt/walletstack.h @@ -40,6 +40,7 @@ QT_END_NAMESPACE class WalletStack : public QStackedWidget { Q_OBJECT + public: explicit WalletStack(QWidget *parent = 0); ~WalletStack(); diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 6d44c174b7..277c056693 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -21,7 +21,11 @@ #include #include #include +#if QT_VERSION < 0x050000 #include +#else +#include +#endif #include #include @@ -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)) { -- cgit v1.2.3