2 * W.J. van der Laan 2011
4 #include "BitcoinGUI.h"
5 #include "TransactionTableModel.h"
7 #include <QApplication>
13 #include <QVBoxLayout>
20 #include <QPushButton>
21 #include <QHeaderView>
26 BitcoinGUI::BitcoinGUI(QWidget *parent):
30 setWindowTitle(tr("Bitcoin"));
31 setWindowIcon(QIcon(":icons/bitcoin"));
33 QAction *quit = new QAction(QIcon(":/icons/quit"), "&Quit", this);
34 QAction *sendcoins = new QAction(QIcon(":/icons/send"), "&Send coins", this);
35 QAction *addressbook = new QAction(QIcon(":/icons/address-book"), "&Address book", this);
36 QAction *about = new QAction(QIcon(":/icons/bitcoin"), "&About", this);
39 QMenu *file = menuBar()->addMenu("&File");
40 file->addAction(sendcoins);
42 file->addAction(quit);
44 QMenu *settings = menuBar()->addMenu("&Settings");
45 settings->addAction(addressbook);
47 QMenu *help = menuBar()->addMenu("&Help");
48 help->addAction(about);
51 QToolBar *toolbar = addToolBar("Main toolbar");
52 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
53 toolbar->addAction(sendcoins);
54 toolbar->addAction(addressbook);
56 /* Address: <address>: New... : Paste to clipboard */
57 QHBoxLayout *hbox_address = new QHBoxLayout();
58 hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
59 QLineEdit *edit_address = new QLineEdit();
60 edit_address->setReadOnly(true);
61 hbox_address->addWidget(edit_address);
63 QPushButton *button_new = new QPushButton(trUtf8("&New\u2026"));
64 QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
65 hbox_address->addWidget(button_new);
66 hbox_address->addWidget(button_clipboard);
68 /* Balance: <balance> */
69 QHBoxLayout *hbox_balance = new QHBoxLayout();
70 hbox_balance->addWidget(new QLabel(tr("Balance:")));
71 hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
73 QLabel *label_balance = new QLabel(QLocale::system().toString(1345.54));
74 label_balance->setFont(QFont("Teletype"));
75 hbox_balance->addWidget(label_balance);
76 hbox_balance->addStretch(1);
79 QVBoxLayout *vbox = new QVBoxLayout();
80 vbox->addLayout(hbox_address);
81 vbox->addLayout(hbox_balance);
87 QTableView *transaction_table = new QTableView(this);
89 TransactionTableModel *transaction_model = new TransactionTableModel(this);
90 transaction_table->setModel(transaction_model);
91 transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
92 transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
94 transaction_table->horizontalHeader()->resizeSection(
95 TransactionTableModel::Status, 112);
96 transaction_table->horizontalHeader()->resizeSection(
97 TransactionTableModel::Date, 112);
98 transaction_table->horizontalHeader()->setResizeMode(
99 TransactionTableModel::Description, QHeaderView::Stretch);
100 transaction_table->horizontalHeader()->resizeSection(
101 TransactionTableModel::Debit, 79);
102 transaction_table->horizontalHeader()->resizeSection(
103 TransactionTableModel::Credit, 79);
106 QTabBar *tabs = new QTabBar(this);
107 tabs->addTab(tr("All transactions"));
108 tabs->addTab(tr("Sent/Received"));
109 tabs->addTab(tr("Sent"));
110 tabs->addTab(tr("Received"));
111 /* QSortFilterProxyModel
112 setFilterRole : filter on user role
114 setFilterRegExp / setFilterFixedString
121 vbox->addWidget(tabs);
122 vbox->addWidget(transaction_table);
124 QWidget *centralwidget = new QWidget(this);
125 centralwidget->setLayout(vbox);
126 setCentralWidget(centralwidget);
131 QLabel *label_connections = new QLabel("6 connections", this);
132 label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
133 label_connections->setMinimumWidth(100);
135 QLabel *label_blocks = new QLabel("6 blocks", this);
136 label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
137 label_blocks->setMinimumWidth(100);
139 QLabel *label_transactions = new QLabel("6 transactions", this);
140 label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
141 label_transactions->setMinimumWidth(100);
144 statusBar()->addPermanentWidget(label_connections);
145 statusBar()->addPermanentWidget(label_blocks);
146 statusBar()->addPermanentWidget(label_transactions);
149 /* Action bindings */
151 connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
152 connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
155 void BitcoinGUI::currentChanged(int tab)
157 std::cout << "Switched to tab: " << tab << std::endl;