diff --git a/bitcoin.cpp b/bitcoin.cpp index ebc0570cc..ad9835628 100644 --- a/bitcoin.cpp +++ b/bitcoin.cpp @@ -13,5 +13,7 @@ int main(int argc, char *argv[]) window.show(); + /* Depending on settings: QApplication::setQuitOnLastWindowClosed(false); */ + return app.exec(); } diff --git a/bitcoingui.cpp b/bitcoingui.cpp index c78bb3c5a..01b18f1b8 100644 --- a/bitcoingui.cpp +++ b/bitcoingui.cpp @@ -27,24 +27,20 @@ #include #include #include +#include #include #include BitcoinGUI::BitcoinGUI(QWidget *parent): - QMainWindow(parent) + QMainWindow(parent), trayIcon(0) { resize(850, 550); setWindowTitle(tr("Bitcoin")); setWindowIcon(QIcon(":icons/bitcoin")); - - QAction *quit = new QAction(QIcon(":/icons/quit"), tr("&Quit"), this); - QAction *sendcoins = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this); - QAction *addressbook = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this); - QAction *about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this); - QAction *receiving_addresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this); - QAction *options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this); + + createActions(); /* Menus */ QMenu *file = menuBar()->addMenu("&File"); @@ -68,9 +64,10 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): /* Address:
: New... : Paste to clipboard */ QHBoxLayout *hbox_address = new QHBoxLayout(); hbox_address->addWidget(new QLabel(tr("Your Bitcoin Address:"))); - QLineEdit *edit_address = new QLineEdit(); - edit_address->setReadOnly(true); - hbox_address->addWidget(edit_address); + address = new QLineEdit(); + address->setReadOnly(true); + address->setText("0123456789"); + hbox_address->addWidget(address); QPushButton *button_new = new QPushButton(tr("&New...")); QPushButton *button_clipboard = new QPushButton(tr("&Copy to clipboard")); @@ -82,19 +79,84 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): hbox_balance->addWidget(new QLabel(tr("Balance:"))); hbox_balance->addSpacing(5);/* Add some spacing between the label and the text */ - QLabel *label_balance = new QLabel(QLocale::system().toString(1345.54)); - label_balance->setFont(QFont("Teletype")); - hbox_balance->addWidget(label_balance); + labelBalance = new QLabel(QLocale::system().toString(1345.54)); + labelBalance->setFont(QFont("Teletype")); + hbox_balance->addWidget(labelBalance); hbox_balance->addStretch(1); - /* Tab widget */ QVBoxLayout *vbox = new QVBoxLayout(); vbox->addLayout(hbox_address); vbox->addLayout(hbox_balance); - TransactionTableModel *transaction_model = new TransactionTableModel(this); + transaction_model = new TransactionTableModel(this); + + vbox->addWidget(createTabs()); - /* setupTabs */ + QWidget *centralwidget = new QWidget(this); + centralwidget->setLayout(vbox); + setCentralWidget(centralwidget); + + /* Create status bar */ + statusBar(); + + QLabel *label_connections = new QLabel("6 connections"); + label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken); + label_connections->setMinimumWidth(100); + + QLabel *label_blocks = new QLabel("6 blocks"); + label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); + label_blocks->setMinimumWidth(100); + + QLabel *label_transactions = new QLabel("6 transactions"); + label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken); + label_transactions->setMinimumWidth(100); + + statusBar()->addPermanentWidget(label_connections); + statusBar()->addPermanentWidget(label_blocks); + statusBar()->addPermanentWidget(label_transactions); + + /* Action bindings */ + connect(button_new, SIGNAL(clicked()), this, SLOT(newAddressClicked())); + connect(button_clipboard, SIGNAL(clicked()), this, SLOT(copyClipboardClicked())); + + createTrayIcon(); +} + +void BitcoinGUI::createActions() +{ + quit = new QAction(QIcon(":/icons/quit"), tr("&Exit"), this); + sendcoins = new QAction(QIcon(":/icons/send"), tr("&Send coins"), this); + addressbook = new QAction(QIcon(":/icons/address-book"), tr("&Address Book"), this); + about = new QAction(QIcon(":/icons/bitcoin"), tr("&About"), this); + receiving_addresses = new QAction(QIcon(":/icons/receiving-addresses"), tr("Your &Receiving Addresses..."), this); + options = new QAction(QIcon(":/icons/options"), tr("&Options..."), this); + openBitCoin = new QAction(QIcon(":/icons/bitcoin"), "Open Bitcoin", this); + + connect(quit, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(sendcoins, SIGNAL(triggered()), this, SLOT(sendcoinsClicked())); + connect(addressbook, SIGNAL(triggered()), this, SLOT(addressbookClicked())); + connect(receiving_addresses, SIGNAL(triggered()), this, SLOT(receivingAddressesClicked())); + connect(options, SIGNAL(triggered()), this, SLOT(optionsClicked())); + connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked())); +} + +void BitcoinGUI::createTrayIcon() +{ + QMenu *trayIconMenu = new QMenu(this); + trayIconMenu->addAction(openBitCoin); + trayIconMenu->addAction(sendcoins); + trayIconMenu->addAction(options); + trayIconMenu->addSeparator(); + trayIconMenu->addAction(quit); + + trayIcon = new QSystemTrayIcon(this); + trayIcon->setContextMenu(trayIconMenu); + trayIcon->setIcon(QIcon(":/icons/bitcoin")); + trayIcon->show(); +} + +QWidget *BitcoinGUI::createTabs() +{ QStringList tab_filters, tab_labels; tab_filters << "^." << "^[sr]" @@ -133,41 +195,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): tabs->addTab(transaction_table, tab_labels.at(i)); } - - vbox->addWidget(tabs); - - QWidget *centralwidget = new QWidget(this); - centralwidget->setLayout(vbox); - setCentralWidget(centralwidget); - - /* Status bar */ - statusBar(); - - QLabel *label_connections = new QLabel("6 connections"); - label_connections->setFrameStyle(QFrame::Panel | QFrame::Sunken); - label_connections->setMinimumWidth(100); - - QLabel *label_blocks = new QLabel("6 blocks"); - label_blocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); - label_blocks->setMinimumWidth(100); - - QLabel *label_transactions = new QLabel("6 transactions"); - label_transactions->setFrameStyle(QFrame::Panel | QFrame::Sunken); - label_transactions->setMinimumWidth(100); - - statusBar()->addPermanentWidget(label_connections); - statusBar()->addPermanentWidget(label_blocks); - statusBar()->addPermanentWidget(label_transactions); - - /* Action bindings */ - connect(quit, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(sendcoins, SIGNAL(triggered()), this, SLOT(sendcoinsClicked())); - connect(addressbook, SIGNAL(triggered()), this, SLOT(addressbookClicked())); - connect(receiving_addresses, SIGNAL(triggered()), this, SLOT(receivingAddressesClicked())); - connect(options, SIGNAL(triggered()), this, SLOT(optionsClicked())); - connect(button_new, SIGNAL(clicked()), this, SLOT(newAddressClicked())); - connect(button_clipboard, SIGNAL(clicked()), this, SLOT(copyClipboardClicked())); - connect(about, SIGNAL(triggered()), this, SLOT(aboutClicked())); + return tabs; } void BitcoinGUI::sendcoinsClicked() @@ -216,5 +244,6 @@ void BitcoinGUI::newAddressClicked() void BitcoinGUI::copyClipboardClicked() { qDebug() << "Copy to clipboard"; - /* TODO: copy to clipboard */ + /* Copy text in address to clipboard */ + QApplication::clipboard()->setText(address->text()); } diff --git a/bitcoingui.h b/bitcoingui.h index 0c9edad85..6e1003cd5 100644 --- a/bitcoingui.h +++ b/bitcoingui.h @@ -2,6 +2,12 @@ #define BITCOINGUI_H #include +#include + +/* Forward declarations */ +class TransactionTableModel; +class QLabel; +class QLineEdit; class BitcoinGUI : public QMainWindow { @@ -16,6 +22,26 @@ public: Sent = 2, Received = 3 } TabIndex; +private: + TransactionTableModel *transaction_model; + + QLineEdit *address; + QLabel *labelBalance; + + QAction *quit; + QAction *sendcoins; + QAction *addressbook; + QAction *about; + QAction *receiving_addresses; + QAction *options; + QAction *openBitCoin; + + QSystemTrayIcon *trayIcon; + + void createActions(); + QWidget *createTabs(); + void createTrayIcon(); + private slots: void sendcoinsClicked(); void addressbookClicked(); diff --git a/sendcoinsdialog.cpp b/sendcoinsdialog.cpp index 1eaa35884..d8ef78129 100644 --- a/sendcoinsdialog.cpp +++ b/sendcoinsdialog.cpp @@ -3,6 +3,9 @@ #include "addressbookdialog.h" +#include +#include + SendCoinsDialog::SendCoinsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SendCoinsDialog) @@ -27,7 +30,8 @@ void SendCoinsDialog::on_cancelButton_clicked() void SendCoinsDialog::on_pasteButton_clicked() { - + /* Paste text from clipboard into recipient field */ + ui->payTo->setText(QApplication::clipboard()->text()); } void SendCoinsDialog::on_addressBookButton_clicked()