PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/merchantlist.cpp

https://github.com/cqtenq/feathercoin_core
C++ | 275 lines | 231 code | 36 blank | 8 comment | 43 complexity | 1737799f4405463f324358d0e78eda90 MD5 | raw file
Possible License(s): 0BSD, GPL-3.0, BSD-3-Clause
  1. // Copyright (c) 2013-2014 The Feathercoin developers
  2. // from overviewpage
  3. #include "merchantlist.h"
  4. #include "ui_merchantlist.h"
  5. #include "bitcoinunits.h"
  6. #include "clientmodel.h"
  7. #include "guiconstants.h"
  8. #include "guiutil.h"
  9. #include "optionsmodel.h"
  10. #include "transactionfilterproxy.h"
  11. #include "transactiontablemodel.h"
  12. #include "walletmodel.h"
  13. #include <QAbstractItemDelegate>
  14. #include <QPainter>
  15. #include <QDesktopServices>
  16. #include <QUrl>
  17. #define DECORATION_SIZE 64
  18. #define NUM_ITEMS 3
  19. class MerViewDelegate : public QAbstractItemDelegate
  20. {
  21. Q_OBJECT
  22. public:
  23. MerViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::FTC)
  24. {
  25. }
  26. inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
  27. const QModelIndex &index ) const
  28. {
  29. painter->save();
  30. QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
  31. QRect mainRect = option.rect;
  32. QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
  33. int xspace = DECORATION_SIZE + 8;
  34. int ypad = 6;
  35. int halfheight = (mainRect.height() - 2*ypad)/2;
  36. QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
  37. QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
  38. icon.paint(painter, decorationRect);
  39. QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
  40. QString address = index.data(Qt::DisplayRole).toString();
  41. qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
  42. bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
  43. QVariant value = index.data(Qt::ForegroundRole);
  44. QColor foreground = option.palette.color(QPalette::Text);
  45. if(value.canConvert<QBrush>())
  46. {
  47. QBrush brush = qvariant_cast<QBrush>(value);
  48. foreground = brush.color();
  49. }
  50. painter->setPen(foreground);
  51. painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address);
  52. if(amount < 0)
  53. {
  54. foreground = COLOR_NEGATIVE;
  55. }
  56. else if(!confirmed)
  57. {
  58. foreground = COLOR_UNCONFIRMED;
  59. }
  60. else
  61. {
  62. foreground = option.palette.color(QPalette::Text);
  63. }
  64. painter->setPen(foreground);
  65. QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true);
  66. if(!confirmed)
  67. {
  68. amountText = QString("[") + amountText + QString("]");
  69. }
  70. painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
  71. painter->setPen(option.palette.color(QPalette::Text));
  72. painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
  73. painter->restore();
  74. }
  75. inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
  76. {
  77. return QSize(DECORATION_SIZE, DECORATION_SIZE);
  78. }
  79. int unit;
  80. };
  81. #include "merchantlist.moc"
  82. MerchantListView::MerchantListView(QWidget *parent) :
  83. QWidget(parent),
  84. ui(new Ui::MerchantListView),
  85. clientModel(0),
  86. walletModel(0),
  87. currentBalance(-1),
  88. currentUnconfirmedBalance(-1),
  89. currentImmatureBalance(-1),
  90. txdelegate(new MerViewDelegate()),
  91. filter(0)
  92. {
  93. ui->setupUi(this);
  94. ui->label_Map->installEventFilter(this);
  95. ui->label_left_1->installEventFilter(this);
  96. ui->label_left_2->installEventFilter(this);
  97. ui->label_left_3->installEventFilter(this);
  98. ui->label_left_4->installEventFilter(this);
  99. ui->label_left_5->installEventFilter(this);
  100. ui->label_left_6->installEventFilter(this);
  101. ui->label_right_1->installEventFilter(this);
  102. ui->label_right_2->installEventFilter(this);
  103. ui->label_right_3->installEventFilter(this);
  104. ui->label_right_4->installEventFilter(this);
  105. ui->label_right_5->installEventFilter(this);
  106. ui->label_right_6->installEventFilter(this);
  107. ui->label_right_7->installEventFilter(this);
  108. // start with displaying the "out of sync" warnings
  109. showOutOfSyncWarning(true);
  110. }
  111. void MerchantListView::handleTransactionClicked(const QModelIndex &index)
  112. {
  113. if(filter)
  114. emit transactionClicked(filter->mapToSource(index));
  115. }
  116. bool MerchantListView::eventFilter(QObject *obj, QEvent *event)
  117. {
  118. if (event->type() == QEvent::MouseButtonPress) {
  119. if (obj == ui->label_Map) {
  120. QDesktopServices::openUrl(QUrl("http://map.ftc-c.com"));
  121. return true;
  122. }
  123. if (obj == ui->label_left_1) {
  124. QDesktopServices::openUrl(QUrl("http://www.bitcoinbazaar.co.uk"));
  125. return true;
  126. }
  127. if (obj == ui->label_left_2) {
  128. QDesktopServices::openUrl(QUrl("https://pock.io"));
  129. return true;
  130. }
  131. if (obj == ui->label_left_3) {
  132. QDesktopServices::openUrl(QUrl("http://bitbooks.co"));
  133. return true;
  134. }
  135. if (obj == ui->label_left_4) {
  136. QDesktopServices::openUrl(QUrl("http://coinverted.com"));
  137. return true;
  138. }
  139. if (obj == ui->label_left_5) {
  140. QDesktopServices::openUrl(QUrl("https://bittrex.com/Market/?MarketName=BTC-FTC"));
  141. return true;
  142. }
  143. if (obj == ui->label_left_6) {
  144. QDesktopServices::openUrl(QUrl("https://vircurex.com/welcome/index?alt=btc&base=ftc"));
  145. return true;
  146. }
  147. if (obj == ui->label_right_1) {
  148. QDesktopServices::openUrl(QUrl("https://crypto-trade.com/currencies/trade/ftc_usd"));
  149. return true;
  150. }
  151. if (obj == ui->label_right_2) {
  152. QDesktopServices::openUrl(QUrl("https://btc-e.com/exchange/ftc_btc"));
  153. return true;
  154. }
  155. if (obj == ui->label_right_3) {
  156. QDesktopServices::openUrl(QUrl("https://www.cryptsy.com/markets/view/5"));
  157. return true;
  158. }
  159. if (obj == ui->label_right_4) {
  160. QDesktopServices::openUrl(QUrl("https://coinmkt.com"));
  161. return true;
  162. }
  163. if (obj == ui->label_right_5) {
  164. QDesktopServices::openUrl(QUrl("https://bter.com/trade/ftc_cny"));
  165. return true;
  166. }
  167. if (obj == ui->label_right_6) {
  168. QDesktopServices::openUrl(QUrl("https://bittylicious.com/"));
  169. return true;
  170. }
  171. if (obj == ui->label_right_7) {
  172. QDesktopServices::openUrl(QUrl("http://shapeshift.io"));
  173. return true;
  174. }
  175. }
  176. return QWidget::eventFilter(obj, event);
  177. }
  178. MerchantListView::~MerchantListView()
  179. {
  180. delete ui;
  181. }
  182. void MerchantListView::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance)
  183. {
  184. int unit = walletModel->getOptionsModel()->getDisplayUnit();
  185. int shareBalance=0; //Ready for POS
  186. currentBalance = balance;
  187. currentUnconfirmedBalance = unconfirmedBalance;
  188. currentImmatureBalance = immatureBalance;
  189. }
  190. void MerchantListView::setOverview()
  191. {
  192. }
  193. void MerchantListView::setClientModel(ClientModel *model)
  194. {
  195. this->clientModel = model;
  196. if(model)
  197. {
  198. // Show warning if this is a prerelease version
  199. connect(model, SIGNAL(alertsChanged(QString)), this, SLOT(updateAlerts(QString)));
  200. updateAlerts(model->getStatusBarWarnings());
  201. }
  202. }
  203. void MerchantListView::setWalletModel(WalletModel *model)
  204. {
  205. this->walletModel = model;
  206. if(model && model->getOptionsModel())
  207. {
  208. // Set up transaction list
  209. filter = new TransactionFilterProxy();
  210. filter->setSourceModel(model->getTransactionTableModel());
  211. filter->setLimit(NUM_ITEMS);
  212. filter->setDynamicSortFilter(true);
  213. filter->setSortRole(Qt::EditRole);
  214. filter->setShowInactive(false);
  215. filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
  216. // Keep up to date with wallet
  217. setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance());
  218. connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64)));
  219. connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
  220. }
  221. // update the display unit, to not use the default ("FTC")
  222. updateDisplayUnit();
  223. }
  224. void MerchantListView::updateDisplayUnit()
  225. {
  226. if(walletModel && walletModel->getOptionsModel())
  227. {
  228. if(currentBalance != -1)
  229. setBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance);
  230. // Update txdelegate->unit with the current unit
  231. txdelegate->unit = walletModel->getOptionsModel()->getDisplayUnit();
  232. }
  233. }
  234. void MerchantListView::updateAlerts(const QString &warnings)
  235. {
  236. }
  237. void MerchantListView::showOutOfSyncWarning(bool fShow)
  238. {
  239. }