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>
25 BitcoinGUI::BitcoinGUI(QWidget *parent):
29 setWindowTitle("Bitcoin");
30 setWindowIcon(QIcon("bitcoin.png"));
32 QAction *quit = new QAction(QIcon("quit.png"), "&Quit", this);
33 QAction *sendcoins = new QAction(QIcon("send.png"), "&Send coins", this);
34 QAction *addressbook = new QAction(QIcon("address-book.png"), "&Address book", this);
35 QAction *about = new QAction(QIcon("bitcoin.png"), "&About", this);
38 QMenu *file = menuBar()->addMenu("&File");
39 file->addAction(sendcoins);
41 file->addAction(quit);
43 QMenu *settings = menuBar()->addMenu("&Settings");
44 settings->addAction(addressbook);
46 QMenu *help = menuBar()->addMenu("&Help");
47 help->addAction(about);
50 QToolBar *toolbar = addToolBar("Main toolbar");
51 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
52 toolbar->addAction(sendcoins);
53 toolbar->addAction(addressbook);
55 /* Address: <address>: New... : Paste to clipboard */
56 QHBoxLayout *hbox_address = new QHBoxLayout();
57 hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
58 QLineEdit *edit_address = new QLineEdit();
59 edit_address->setReadOnly(true);
60 hbox_address->addWidget(edit_address);
62 QPushButton *button_new = new QPushButton(trUtf8("&New\u2026"));
63 QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
64 hbox_address->addWidget(button_new);
65 hbox_address->addWidget(button_clipboard);
67 /* Balance: <balance> */
68 QHBoxLayout *hbox_balance = new QHBoxLayout();
69 hbox_balance->addWidget(new QLabel("Balance:"));
70 hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
71 QLabel *label_balance = new QLabel("1,234.54");
72 label_balance->setFont(QFont("Teletype"));
73 hbox_balance->addWidget(label_balance);
74 hbox_balance->addStretch(1);
77 QVBoxLayout *vbox = new QVBoxLayout();
78 vbox->addLayout(hbox_address);
79 vbox->addLayout(hbox_balance);
86 * QAbstractItemView::SelectItems
87 * QAbstractItemView::ExtendedSelection
89 QTableView *transaction_table = new QTableView(this);
91 TransactionTableModel *transaction_model = new TransactionTableModel(this);
92 transaction_table->setModel(transaction_model);
93 transaction_table->setSelectionBehavior(QAbstractItemView::SelectRows);
94 transaction_table->setSelectionMode(QAbstractItemView::ExtendedSelection);
96 transaction_table->horizontalHeader()->resizeSection(
97 TransactionTableModel::Status, 112);
98 transaction_table->horizontalHeader()->resizeSection(
99 TransactionTableModel::Date, 112);
100 transaction_table->horizontalHeader()->setResizeMode(
101 TransactionTableModel::Description, QHeaderView::Stretch);
102 transaction_table->horizontalHeader()->resizeSection(
103 TransactionTableModel::Debit, 79);
104 transaction_table->horizontalHeader()->resizeSection(
105 TransactionTableModel::Credit, 79);
106 /* TODO: alignment; debit/credit columns must align right */
108 QTabBar *tabs = new QTabBar(this);
109 tabs->addTab("All transactions");
110 tabs->addTab("Sent/Received");
111 tabs->addTab("Sent");
112 tabs->addTab("Received");
114 vbox->addWidget(tabs);
115 vbox->addWidget(transaction_table);
117 QWidget *centralwidget = new QWidget(this);
118 centralwidget->setLayout(vbox);
119 setCentralWidget(centralwidget);
124 QLabel *label_connections = new QLabel("6 connections", this);
125 label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
126 label_connections->setMinimumWidth(100);
128 QLabel *label_blocks = new QLabel("6 blocks", this);
129 label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
130 label_blocks->setMinimumWidth(100);
132 QLabel *label_transactions = new QLabel("6 transactions", this);
133 label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
134 label_transactions->setMinimumWidth(100);
137 statusBar()->addPermanentWidget(label_connections);
138 statusBar()->addPermanentWidget(label_blocks);
139 statusBar()->addPermanentWidget(label_transactions);
142 /* Action bindings */
144 connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
145 connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
148 void BitcoinGUI::currentChanged(int tab)
150 std::cout << "Switched to tab: " << tab << std::endl;