0b81f72faa4eb73f53e507036202215aa9cf0148
[novacoin.git] / BitcoinGUI.cpp
1 /*
2  * W.J. van der Laan 2011
3  */
4 #include "BitcoinGUI.h"
5 #include "TransactionTableModel.h"
6
7 #include <QApplication>
8 #include <QMainWindow>
9 #include <QMenuBar>
10 #include <QMenu>
11 #include <QIcon>
12 #include <QTabBar>
13 #include <QVBoxLayout>
14 #include <QWidget>
15 #include <QToolBar>
16 #include <QStatusBar>
17 #include <QLabel>
18 #include <QTableView>
19 #include <QLineEdit>
20 #include <QPushButton>
21
22 #include <iostream>
23
24 BitcoinGUI::BitcoinGUI(QWidget *parent):
25     QMainWindow(parent)
26 {
27     resize(850, 550);
28     setWindowTitle("Bitcoin");
29     setWindowIcon(QIcon("bitcoin.png"));
30     
31     QAction *quit = new QAction(QIcon("quit.png"), "&Quit", this);
32     QAction *sendcoins = new QAction(QIcon("send.png"), "&Send coins", this);
33     QAction *addressbook = new QAction(QIcon("address-book.png"), "&Address book", this);
34     QAction *about = new QAction(QIcon("bitcoin.png"), "&About", this);
35     
36     /* Menus */
37     QMenu *file = menuBar()->addMenu("&File");
38     file->addAction(sendcoins);
39     file->addSeparator();
40     file->addAction(quit);
41     
42     QMenu *settings = menuBar()->addMenu("&Settings");
43     settings->addAction(addressbook);
44
45     QMenu *help = menuBar()->addMenu("&Help");
46     help->addAction(about);
47     
48     /* Toolbar */
49     QToolBar *toolbar = addToolBar("Main toolbar");
50     toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
51     toolbar->addAction(sendcoins);
52     toolbar->addAction(addressbook);
53
54     /* Address: <address>: New... : Paste to clipboard */
55     QHBoxLayout *hbox_address = new QHBoxLayout();
56     hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:")));
57     QLineEdit *edit_address = new QLineEdit();
58     edit_address->setReadOnly(true);
59     hbox_address->addWidget(edit_address);
60     
61     QPushButton *button_new = new QPushButton(trUtf8("&New\u2026"));
62     QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard"));
63     hbox_address->addWidget(button_new);
64     hbox_address->addWidget(button_clipboard);
65     
66     /* Balance: <balance> */
67     QHBoxLayout *hbox_balance = new QHBoxLayout();
68     hbox_balance->addWidget(new QLabel("Balance:"));
69     hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */
70     QLabel *label_balance = new QLabel("1,234.54");
71     label_balance->setFont(QFont("Teletype"));
72     hbox_balance->addWidget(label_balance);
73     hbox_balance->addStretch(1);
74     
75     /* Tab widget */
76     QVBoxLayout *vbox = new QVBoxLayout();
77     vbox->addLayout(hbox_address);
78     vbox->addLayout(hbox_balance);
79     
80     /* Transaction table:
81      * TransactionView
82      * TransactionModel
83      * Selection behavior
84      * selection mode
85      * QAbstractItemView::SelectItems
86      * QAbstractItemView::ExtendedSelection
87      */
88     QTableView *transaction_table = new QTableView(this);
89     TransactionTableModel *transaction_model = new TransactionTableModel(this);
90     transaction_table->setModel(transaction_model);
91     
92     QTabBar *tabs = new QTabBar(this);
93     tabs->addTab("All transactions");
94     tabs->addTab("Sent/Received");
95     tabs->addTab("Sent");
96     tabs->addTab("Received");
97    
98     vbox->addWidget(tabs);
99     vbox->addWidget(transaction_table);
100     
101     QWidget *centralwidget = new QWidget(this);
102     centralwidget->setLayout(vbox);
103     setCentralWidget(centralwidget);
104     
105     /* Status bar */
106     statusBar();
107     
108     QLabel *label_connections = new QLabel("6 connections", this);
109     label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
110     label_connections->setMinimumWidth(100);
111     
112     QLabel *label_blocks = new QLabel("6 blocks", this);
113     label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
114     label_blocks->setMinimumWidth(100);
115     
116     QLabel *label_transactions = new QLabel("6 transactions", this);
117     label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
118     label_transactions->setMinimumWidth(100);
119     
120     
121     statusBar()->addPermanentWidget(label_connections);
122     statusBar()->addPermanentWidget(label_blocks);
123     statusBar()->addPermanentWidget(label_transactions);
124     
125      
126     /* Action bindings */
127
128     connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
129     connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
130 }
131
132 void BitcoinGUI::currentChanged(int tab)
133 {
134     std::cout << "Switched to tab: " << tab << std::endl;
135 }