4 * W.J. van der Laan 2011
6 #include "BitcoinGUI.h"
7 #include "TransactionTableModel.h"
8 #include "addressbookdialog.h"
9 #include "SendCoinsDialog.h"
10 #include "OptionsDialog.h"
11 #include "AboutDialog.h"
13 #include <QApplication>
14 #include <QMainWindow>
19 #include <QVBoxLayout>
26 #include <QPushButton>
27 #include <QHeaderView>
29 #include <QSortFilterProxyModel>
35 BitcoinGUI::BitcoinGUI(QWidget *parent):
39 setWindowTitle(tr("Bitcoin"));
40 setWindowIcon(QIcon(":icons/bitcoin"));
42 QAction *quit = new QAction(QIcon(":/icons/quit"), tr("&Quit"), this);
43 QAction *sendcoins = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this);
44 QAction *addressbook = new QAction(QIcon(":/icons/address-book"), tr("&Address book"), this);
45 QAction *about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this);
46 QAction *receiving_addresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this);
47 QAction *options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this);
50 QMenu *file = menuBar()->addMenu("&File");
51 file->addAction(sendcoins);
53 file->addAction(quit);
55 QMenu *settings = menuBar()->addMenu("&Settings");
56 settings->addAction(receiving_addresses);
57 settings->addAction(options);
59 QMenu *help = menuBar()->addMenu("&Help");
60 help->addAction(about);
63 QToolBar *toolbar = addToolBar("Main toolbar");
64 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
65 toolbar->addAction(sendcoins);
66 toolbar->addAction(addressbook);
68 /* Address: <address>: New... : Paste to clipboard */
69 QHBoxLayout *hbox_address = new QHBoxLayout();
70 hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
71 QLineEdit *edit_address = new QLineEdit();
72 edit_address->setReadOnly(true);
73 hbox_address->addWidget(edit_address);
75 QPushButton *button_new = new QPushButton(tr("&New..."));
76 QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
77 hbox_address->addWidget(button_new);
78 hbox_address->addWidget(button_clipboard);
80 /* Balance: <balance> */
81 QHBoxLayout *hbox_balance = new QHBoxLayout();
82 hbox_balance->addWidget(new QLabel(tr("Balance:")));
83 hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
85 QLabel *label_balance = new QLabel(QLocale::system().toString(1345.54));
86 label_balance->setFont(QFont("Teletype"));
87 hbox_balance->addWidget(label_balance);
88 hbox_balance->addStretch(1);
91 QVBoxLayout *vbox = new QVBoxLayout();
92 vbox->addLayout(hbox_address);
93 vbox->addLayout(hbox_balance);
95 TransactionTableModel *transaction_model = new TransactionTableModel(this);
98 QStringList tab_filters, tab_labels;
103 tab_labels << tr("All transactions")
104 << tr("Sent/Received")
107 QTabWidget *tabs = new QTabWidget(this);
109 for(int i = 0; i < tab_labels.size(); ++i)
111 QSortFilterProxyModel *proxy_model = new QSortFilterProxyModel(this);
112 proxy_model->setSourceModel(transaction_model);
113 proxy_model->setDynamicSortFilter(true);
114 proxy_model->setFilterRole(Qt::UserRole);
115 proxy_model->setFilterRegExp(QRegExp(tab_filters.at(i)));
117 QTableView *transaction_table = new QTableView(this);
118 transaction_table->setModel(proxy_model);
119 transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
120 transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
121 transaction_table->verticalHeader()->hide();
123 transaction_table->horizontalHeader()->resizeSection(
124 TransactionTableModel::Status, 112);
125 transaction_table->horizontalHeader()->resizeSection(
126 TransactionTableModel::Date, 112);
127 transaction_table->horizontalHeader()->setResizeMode(
128 TransactionTableModel::Description, QHeaderView::Stretch);
129 transaction_table->horizontalHeader()->resizeSection(
130 TransactionTableModel::Debit, 79);
131 transaction_table->horizontalHeader()->resizeSection(
132 TransactionTableModel::Credit, 79);
134 tabs->addTab(transaction_table, tab_labels.at(i));
137 vbox->addWidget(tabs);
139 QWidget *centralwidget = new QWidget(this);
140 centralwidget->setLayout(vbox);
141 setCentralWidget(centralwidget);
146 QLabel *label_connections = new QLabel("6 connections");
147 label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
148 label_connections->setMinimumWidth(100);
150 QLabel *label_blocks = new QLabel("6 blocks");
151 label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
152 label_blocks->setMinimumWidth(100);
154 QLabel *label_transactions = new QLabel("6 transactions");
155 label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
156 label_transactions->setMinimumWidth(100);
158 statusBar()->addPermanentWidget(label_connections);
159 statusBar()->addPermanentWidget(label_blocks);
160 statusBar()->addPermanentWidget(label_transactions);
162 /* Action bindings */
163 connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
164 connect(sendcoins, SIGNAL(triggered()), this, SLOT(sendcoinsClicked()));
165 connect(addressbook, SIGNAL(triggered()), this, SLOT(addressbookClicked()));
166 connect(receiving_addresses, SIGNAL(triggered()), this, SLOT(receivingAddressesClicked()));
167 connect(options, SIGNAL(triggered()), this, SLOT(optionsClicked()));
168 connect(button_new, SIGNAL(clicked()), this, SLOT(newAddressClicked()));
169 connect(button_clipboard, SIGNAL(clicked()), this, SLOT(copyClipboardClicked()));
170 connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked()));
173 void BitcoinGUI::sendcoinsClicked()
175 qDebug() << "Send coins clicked";
180 void BitcoinGUI::addressbookClicked()
182 qDebug() << "Address book clicked";
183 AddressBookDialog dlg;
184 dlg.setTab(AddressBookDialog::SendingTab);
188 void BitcoinGUI::receivingAddressesClicked()
190 qDebug() << "Receiving addresses clicked";
191 AddressBookDialog dlg;
192 dlg.setTab(AddressBookDialog::ReceivingTab);
196 void BitcoinGUI::optionsClicked()
198 qDebug() << "Options clicked";
203 void BitcoinGUI::aboutClicked()
205 qDebug() << "About clicked";
210 void BitcoinGUI::newAddressClicked()
212 qDebug() << "New address clicked";
213 /* TODO: generate new address */
216 void BitcoinGUI::copyClipboardClicked()
218 qDebug() << "Copy to clipboard";
219 /* TODO: copy to clipboard */