preparations for multiple unit (uBTC, mBTC, BTC) support, fix amount entry issue
[novacoin.git] / src / qt / optionsdialog.cpp
index d46b48f..4f3a82d 100644 (file)
@@ -1,5 +1,6 @@
 #include "optionsdialog.h"
 #include "optionsmodel.h"
+#include "bitcoinamountfield.h"
 #include "monitoreddatamapper.h"
 #include "guiutil.h"
 
 #include <QIntValidator>
 #include <QDoubleValidator>
 #include <QRegExpValidator>
+#include <QDialogButtonBox>
+#include <QDebug>
 
-/* First (currently only) page of options */
+/* First page of options */
 class MainOptionsPage : public QWidget
 {
 public:
@@ -31,7 +34,7 @@ private:
     QCheckBox *connect_socks4;
     QLineEdit *proxy_ip;
     QLineEdit *proxy_port;
-    QLineEdit *fee_edit;
+    BitcoinAmountField *fee_edit;
 
 signals:
 
@@ -39,9 +42,23 @@ public slots:
 
 };
 
+class DisplayOptionsPage : public QWidget
+{
+public:
+    explicit DisplayOptionsPage(QWidget *parent=0);
+
+    void setMapper(MonitoredDataMapper *mapper);
+private:
+    QLineEdit *unit;
+signals:
+
+public slots:
+
+};
+
 OptionsDialog::OptionsDialog(QWidget *parent):
     QDialog(parent), contents_widget(0), pages_widget(0),
-    main_options_page(0), model(0)
+    model(0), main_page(0), display_page(0)
 {
     contents_widget = new QListWidget();
     contents_widget->setMaximumWidth(128);
@@ -51,8 +68,13 @@ OptionsDialog::OptionsDialog(QWidget *parent):
 
     QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
     contents_widget->addItem(item_main);
-    main_options_page = new MainOptionsPage(this);
-    pages_widget->addWidget(main_options_page);
+    main_page = new MainOptionsPage(this);
+    pages_widget->addWidget(main_page);
+
+    QListWidgetItem *item_display = new QListWidgetItem(tr("Display"));
+    //contents_widget->addItem(item_display);
+    display_page = new DisplayOptionsPage(this);
+    pages_widget->addWidget(display_page);
 
     contents_widget->setCurrentRow(0);
 
@@ -63,17 +85,10 @@ OptionsDialog::OptionsDialog(QWidget *parent):
     QVBoxLayout *layout = new QVBoxLayout();
     layout->addLayout(main_layout);
 
-    QHBoxLayout *buttons = new QHBoxLayout();
-    buttons->addStretch(1);
-    QPushButton *ok_button = new QPushButton(tr("OK"));
-    buttons->addWidget(ok_button);
-    QPushButton *cancel_button = new QPushButton(tr("Cancel"));
-    buttons->addWidget(cancel_button);
-    apply_button = new QPushButton(tr("Apply"));
-    apply_button->setEnabled(false);
-    buttons->addWidget(apply_button);
-
-    layout->addLayout(buttons);
+    QDialogButtonBox *buttonbox = new QDialogButtonBox();
+    buttonbox->setStandardButtons(QDialogButtonBox::Apply|QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
+    apply_button = buttonbox->button(QDialogButtonBox::Apply);
+    layout->addWidget(buttonbox);
 
     setLayout(layout);
     setWindowTitle(tr("Options"));
@@ -88,9 +103,11 @@ OptionsDialog::OptionsDialog(QWidget *parent):
     connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply()));
 
     /* Event bindings */
-    connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked()));
-    connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked()));
-    connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked()));
+    qDebug() << "setup";
+    connect(contents_widget, SIGNAL(currentRowChanged(int)), this, SLOT(changePage(int)));
+    connect(buttonbox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(okClicked()));
+    connect(buttonbox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(cancelClicked()));
+    connect(buttonbox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(applyClicked()));
 }
 
 void OptionsDialog::setModel(OptionsModel *model)
@@ -98,18 +115,16 @@ void OptionsDialog::setModel(OptionsModel *model)
     this->model = model;
 
     mapper->setModel(model);
-    main_options_page->setMapper(mapper);
+    main_page->setMapper(mapper);
+    display_page->setMapper(mapper);
 
     mapper->toFirst();
 }
 
-void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
+void OptionsDialog::changePage(int index)
 {
-    Q_UNUSED(previous);
-    if(current)
-    {
-        pages_widget->setCurrentIndex(contents_widget->row(current));
-    }
+    qDebug() << "page" << index;
+    pages_widget->setCurrentIndex(index);
 }
 
 void OptionsDialog::okClicked()
@@ -195,19 +210,16 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
     fee_hbox->addSpacing(18);
     QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
     fee_hbox->addWidget(fee_label);
-    fee_edit = new QLineEdit();
-    fee_edit->setMaximumWidth(100);
+    fee_edit = new BitcoinAmountField();
     fee_edit->setToolTip(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
 
-    GUIUtil::setupAmountWidget(fee_edit, this);
-
     fee_label->setBuddy(fee_edit);
     fee_hbox->addWidget(fee_edit);
     fee_hbox->addStretch(1);
 
     layout->addLayout(fee_hbox);
 
-    layout->addStretch(1); /* Extra space at bottom */
+    layout->addStretch(1); // Extra space at bottom
 
     setLayout(layout);
 
@@ -221,7 +233,7 @@ MainOptionsPage::MainOptionsPage(QWidget *parent):
 
 void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
 {
-    /* Map model to widgets */
+    // Map model to widgets
     mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
     mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
     mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
@@ -232,3 +244,25 @@ void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
     mapper->addMapping(fee_edit, OptionsModel::Fee);
 }
 
+DisplayOptionsPage::DisplayOptionsPage(QWidget *parent):
+        QWidget(parent)
+{
+    QVBoxLayout *layout = new QVBoxLayout();
+    QHBoxLayout *unit_hbox = new QHBoxLayout();
+    unit_hbox->addSpacing(18);
+    QLabel *unit_label = new QLabel(tr("&Unit: "));
+    unit_hbox->addWidget(unit_label);
+    unit = new QLineEdit();
+
+    unit_label->setBuddy(unit);
+    unit_hbox->addWidget(unit);
+
+    layout->addLayout(unit_hbox);
+    layout->addStretch();
+
+    setLayout(layout);
+}
+
+void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
+{
+}