put Q_OBJECT everywhere it should be (removes warnings when running lupdate)
[novacoin.git] / src / qt / optionsdialog.cpp
index 1b5b2fe..7267e3d 100644 (file)
@@ -3,6 +3,8 @@
 #include "bitcoinamountfield.h"
 #include "monitoreddatamapper.h"
 #include "guiutil.h"
+#include "bitcoinunits.h"
+#include "qvaluecombobox.h"
 
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QIntValidator>
 #include <QDoubleValidator>
 #include <QRegExpValidator>
+#include <QDialogButtonBox>
 
-/* First (currently only) page of options */
+/* First page of options */
 class MainOptionsPage : public QWidget
 {
+    Q_OBJECT
 public:
     explicit MainOptionsPage(QWidget *parent=0);
 
@@ -40,9 +44,27 @@ public slots:
 
 };
 
+class DisplayOptionsPage : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit DisplayOptionsPage(QWidget *parent=0);
+
+    void setMapper(MonitoredDataMapper *mapper);
+private:
+    QValueComboBox *unit;
+    QCheckBox *display_addresses;
+signals:
+
+public slots:
+
+};
+
+#include "optionsdialog.moc"
+
 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);
@@ -52,8 +74,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);
 
@@ -64,17 +91,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"));
@@ -89,9 +109,10 @@ 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()));
+    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)
@@ -99,18 +120,15 @@ 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));
-    }
+    pages_widget->setCurrentIndex(index);
 }
 
 void OptionsDialog::okClicked()
@@ -230,3 +248,34 @@ 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 to show amounts in: "));
+    unit_hbox->addWidget(unit_label);
+    unit = new QValueComboBox(this);
+    unit->setModel(new BitcoinUnits(this));
+    unit->setToolTip(tr("Choose the default subdivision unit to show in the interface, and when sending coins"));
+
+    unit_label->setBuddy(unit);
+    unit_hbox->addWidget(unit);
+
+    layout->addLayout(unit_hbox);
+
+    display_addresses = new QCheckBox(tr("Display addresses in transaction list"), this);
+    layout->addWidget(display_addresses);
+
+    layout->addStretch();
+
+    setLayout(layout);
+}
+
+void DisplayOptionsPage::setMapper(MonitoredDataMapper *mapper)
+{
+    mapper->addMapping(unit, OptionsModel::DisplayUnit);
+    mapper->addMapping(display_addresses, OptionsModel::DisplayAddresses);
+}