add all (unpopulated) dialogs
[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 #include <QHeaderView>
22
23 #include <iostream>
24
25 BitcoinGUI::BitcoinGUI(QWidget *parent):
26     QMainWindow(parent)
27 {
28     resize(850, 550);
29     setWindowTitle("Bitcoin");
30     setWindowIcon(QIcon("bitcoin.png"));
31     
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);
36     
37     /* Menus */
38     QMenu *file = menuBar()->addMenu("&File");
39     file->addAction(sendcoins);
40     file->addSeparator();
41     file->addAction(quit);
42     
43     QMenu *settings = menuBar()->addMenu("&Settings");
44     settings->addAction(addressbook);
45
46     QMenu *help = menuBar()->addMenu("&Help");
47     help->addAction(about);
48     
49     /* Toolbar */
50     QToolBar *toolbar = addToolBar("Main toolbar");
51     toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
52     toolbar->addAction(sendcoins);
53     toolbar->addAction(addressbook);
54
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);
61     
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);
66     
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);
75     
76     /* Tab widget */
77     QVBoxLayout *vbox = new QVBoxLayout();
78     vbox->addLayout(hbox_address);
79     vbox->addLayout(hbox_balance);
80     
81     /* Transaction table:
82      * TransactionView
83      * TransactionModel
84      * Selection behavior
85      * selection mode
86      * QAbstractItemView::SelectItems
87      * QAbstractItemView::ExtendedSelection
88      */
89     QTableView *transaction_table = new QTableView(this);
90
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);
95
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 */
107
108     QTabBar *tabs = new QTabBar(this);
109     tabs->addTab("All transactions");
110     tabs->addTab("Sent/Received");
111     tabs->addTab("Sent");
112     tabs->addTab("Received");
113    
114     vbox->addWidget(tabs);
115     vbox->addWidget(transaction_table);
116     
117     QWidget *centralwidget = new QWidget(this);
118     centralwidget->setLayout(vbox);
119     setCentralWidget(centralwidget);
120     
121     /* Status bar */
122     statusBar();
123     
124     QLabel *label_connections = new QLabel("6 connections", this);
125     label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
126     label_connections->setMinimumWidth(100);
127     
128     QLabel *label_blocks = new QLabel("6 blocks", this);
129     label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
130     label_blocks->setMinimumWidth(100);
131     
132     QLabel *label_transactions = new QLabel("6 transactions", this);
133     label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken);
134     label_transactions->setMinimumWidth(100);
135     
136     
137     statusBar()->addPermanentWidget(label_connections);
138     statusBar()->addPermanentWidget(label_blocks);
139     statusBar()->addPermanentWidget(label_transactions);
140     
141      
142     /* Action bindings */
143
144     connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
145     connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int)));
146 }
147
148 void BitcoinGUI::currentChanged(int tab)
149 {
150     std::cout << "Switched to tab: " << tab << std::endl;
151 }