X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fqt%2Fguiutil.cpp;h=6c40eb47d0118cca183386a3a00e5c7746a24e27;hb=47d3ceb3da845e216fc9577cbf52f8b5600e5f93;hp=bc10f1c3ed91a778b443958215c1a184fd68c4e8;hpb=84a4a7763f386934da90e2bd1e355b70023fa9ca;p=novacoin.git diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index bc10f1c..6c40eb4 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -10,8 +10,12 @@ #include #include #include +#if QT_VERSION >= 0x050000 +#include +#else #include -#include // For Qt::escape +#endif +#include // For Qt::mightBeRichText #include #include #include @@ -19,18 +23,19 @@ #include #include +#ifndef Q_MOC_RUN #include #include +#if BOOST_FILESYSTEM_VERSION >= 3 +#include +#endif +#endif #ifdef WIN32 #ifdef _WIN32_WINNT #undef _WIN32_WINNT #endif -#define _WIN32_WINNT 0x0501 -#ifdef _WIN32_IE -#undef _WIN32_IE -#endif -#define _WIN32_IE 0x0501 +#define _WIN32_WINNT 0x0601 #define WIN32_LEAN_AND_MEAN 1 #ifndef NOMINMAX #define NOMINMAX @@ -40,8 +45,33 @@ #include "shellapi.h" #endif +#if BOOST_FILESYSTEM_VERSION >= 3 +static boost::filesystem::detail::utf8_codecvt_facet utf8; +#endif + namespace GUIUtil { +#if BOOST_FILESYSTEM_VERSION >= 3 +boost::filesystem::path qstringToBoostPath(const QString &path) +{ + return boost::filesystem::path(path.toStdString(), utf8); +} +QString boostPathToQString(const boost::filesystem::path &path) +{ + return QString::fromStdString(path.string(utf8)); +} +#else +#warning Conversion between boost path and QString can use invalid character encoding with boost_filesystem v2 and older +boost::filesystem::path qstringToBoostPath(const QString &path) +{ + return boost::filesystem::path(path.toStdString()); +} +QString boostPathToQString(const boost::filesystem::path &path) +{ + return QString::fromStdString(path.string()); +} +#endif + QString dateTimeStr(const QDateTime &date) { return date.date().toString(Qt::SystemLocaleShortDate) + QString(" ") + date.toString("hh:mm"); @@ -77,13 +107,19 @@ void setupAmountWidget(QLineEdit *widget, QWidget *parent) bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { - if(uri.scheme() != QString("bitcoin")) + // NovaCoin: check prefix + if(uri.scheme() != QString("novacoin")) return false; 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; @@ -122,13 +158,13 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) bool parseBitcoinURI(QString uri, SendCoinsRecipient *out) { - // Convert bitcoin:// to bitcoin: + // Convert novacoin:// to novacoin: // // Cannot handle this later, because bitcoin:// will cause Qt to see the part after // as host, // which will lower-case it (and thus invalidate the address). - if(uri.startsWith("bitcoin://")) + if(uri.startsWith("novacoin://")) { - uri.replace(0, 10, "bitcoin:"); + uri.replace(0, 10, "novacoin:"); } QUrl uriInstance(uri); return parseBitcoinURI(uriInstance, out); @@ -136,7 +172,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"); @@ -171,7 +211,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 { @@ -245,6 +289,15 @@ void openDebugLogfile() QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathDebug.string()))); } +void openConfigfile() +{ + boost::filesystem::path pathConfig = GetConfigFile(); + + /* Open novacoin.conf with the associated application */ + if (boost::filesystem::exists(pathConfig)) + QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromStdString(pathConfig.string()))); +} + ToolTipToRichTextFilter::ToolTipToRichTextFilter(int size_threshold, QObject *parent) : QObject(parent), size_threshold(size_threshold) { @@ -257,11 +310,11 @@ bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt) { QWidget *widget = static_cast(obj); QString tooltip = widget->toolTip(); - if(tooltip.size() > size_threshold && !tooltip.startsWith("") && !Qt::mightBeRichText(tooltip)) + if(tooltip.size() > size_threshold && !tooltip.startsWith("") && !Qt::mightBeRichText(tooltip)) { // Prefix to make sure Qt detects this as rich text // Escape the current message as HTML and replace \n by
- tooltip = "" + HtmlEscape(tooltip, true); + tooltip = "" + HtmlEscape(tooltip, true) + ""; widget->setToolTip(tooltip); return true; } @@ -429,10 +482,15 @@ HelpMessageBox::HelpMessageBox(QWidget *parent) : " -splash " + tr("Show splash screen on startup (default: 1)") + "\n"; setWindowTitle(tr("NovaCoin-Qt")); + setFont(bitcoinAddressFont()); setTextFormat(Qt::PlainText); // setMinimumWidth is ignored for QMessageBox so put in non-breaking spaces to make it wider. setText(header + QString(QChar(0x2003)).repeated(50)); setDetailedText(coreOptions + "\n" + uiOptions); + addButton("OK", QMessageBox::RejectRole); //кнопка OK будет справа от кнопки "Скрыть подробности" + //addButton("OK", QMessageBox::NoRole); //кнопка OK будет слева от кнопки "Скрыть подробности" + setMouseTracking(true); + setSizeGripEnabled(true); } void HelpMessageBox::printToConsole() @@ -453,5 +511,25 @@ void HelpMessageBox::showOrPrint() #endif } +QString formatDurationStr(int secs) +{ + QStringList strList; + int days = secs / 86400; + int hours = (secs % 86400) / 3600; + int mins = (secs % 3600) / 60; + int seconds = secs % 60; + + if (days) + strList.append(QString(QObject::tr("%1 d")).arg(days)); + if (hours) + strList.append(QString(QObject::tr("%1 h")).arg(hours)); + if (mins) + strList.append(QString(QObject::tr("%1 m")).arg(mins)); + if (seconds || (!days && !hours && !mins)) + strList.append(QString(QObject::tr("%1 s")).arg(seconds)); + + return strList.join(" "); +} + } // namespace GUIUtil