1 #include "optionsdialog.h"
2 #include "optionsmodel.h"
3 #include "monitoreddatamapper.h"
10 #include <QStackedWidget>
15 #include <QIntValidator>
16 #include <QDoubleValidator>
17 #include <QRegExpValidator>
19 /* First (currently only) page of options */
20 class MainOptionsPage : public QWidget
23 explicit MainOptionsPage(QWidget *parent=0);
25 void setMapper(MonitoredDataMapper *mapper);
27 QCheckBox *bitcoin_at_startup;
28 QCheckBox *minimize_to_tray;
29 QCheckBox *map_port_upnp;
30 QCheckBox *minimize_on_close;
31 QCheckBox *connect_socks4;
33 QLineEdit *proxy_port;
42 OptionsDialog::OptionsDialog(QWidget *parent):
43 QDialog(parent), contents_widget(0), pages_widget(0),
44 main_options_page(0), model(0)
46 contents_widget = new QListWidget();
47 contents_widget->setMaximumWidth(128);
49 pages_widget = new QStackedWidget();
50 pages_widget->setMinimumWidth(300);
52 QListWidgetItem *item_main = new QListWidgetItem(tr("Main"));
53 contents_widget->addItem(item_main);
54 main_options_page = new MainOptionsPage(this);
55 pages_widget->addWidget(main_options_page);
57 contents_widget->setCurrentRow(0);
59 QHBoxLayout *main_layout = new QHBoxLayout();
60 main_layout->addWidget(contents_widget);
61 main_layout->addWidget(pages_widget, 1);
63 QVBoxLayout *layout = new QVBoxLayout();
64 layout->addLayout(main_layout);
66 QHBoxLayout *buttons = new QHBoxLayout();
67 buttons->addStretch(1);
68 QPushButton *ok_button = new QPushButton(tr("OK"));
69 buttons->addWidget(ok_button);
70 QPushButton *cancel_button = new QPushButton(tr("Cancel"));
71 buttons->addWidget(cancel_button);
72 apply_button = new QPushButton(tr("Apply"));
73 apply_button->setEnabled(false);
74 buttons->addWidget(apply_button);
76 layout->addLayout(buttons);
79 setWindowTitle(tr("Options"));
81 /* Widget-to-option mapper */
82 mapper = new MonitoredDataMapper(this);
83 mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
84 mapper->setOrientation(Qt::Vertical);
85 /* enable apply button when data modified */
86 connect(mapper, SIGNAL(viewModified()), this, SLOT(enableApply()));
87 /* disable apply button when new data loaded */
88 connect(mapper, SIGNAL(currentIndexChanged(int)), this, SLOT(disableApply()));
91 connect(ok_button, SIGNAL(clicked()), this, SLOT(okClicked()));
92 connect(cancel_button, SIGNAL(clicked()), this, SLOT(cancelClicked()));
93 connect(apply_button, SIGNAL(clicked()), this, SLOT(applyClicked()));
96 void OptionsDialog::setModel(OptionsModel *model)
100 mapper->setModel(model);
101 main_options_page->setMapper(mapper);
106 void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
111 pages_widget->setCurrentIndex(contents_widget->row(current));
115 void OptionsDialog::okClicked()
121 void OptionsDialog::cancelClicked()
126 void OptionsDialog::applyClicked()
129 apply_button->setEnabled(false);
132 void OptionsDialog::enableApply()
134 apply_button->setEnabled(true);
137 void OptionsDialog::disableApply()
139 apply_button->setEnabled(false);
142 MainOptionsPage::MainOptionsPage(QWidget *parent):
145 QVBoxLayout *layout = new QVBoxLayout();
147 bitcoin_at_startup = new QCheckBox(tr("&Start Bitcoin on window system startup"));
148 bitcoin_at_startup->setToolTip(tr("Automatically start Bitcoin after the computer is turned on"));
149 layout->addWidget(bitcoin_at_startup);
151 minimize_to_tray = new QCheckBox(tr("&Minimize to the tray instead of the taskbar"));
152 minimize_to_tray->setToolTip(tr("Show only a tray icon after minimizing the window"));
153 layout->addWidget(minimize_to_tray);
155 map_port_upnp = new QCheckBox(tr("Map port using &UPnP"));
156 map_port_upnp->setToolTip(tr("Automatically open the Bitcoin client port on the router. This only works when your router supports UPnP and it is enabled."));
157 layout->addWidget(map_port_upnp);
159 minimize_on_close = new QCheckBox(tr("M&inimize on close"));
160 minimize_on_close->setToolTip(tr("Minimize instead of exit the application when the window is closed. When this option is enabled, the application will be closed only after selecting Quit in the menu."));
161 layout->addWidget(minimize_on_close);
163 connect_socks4 = new QCheckBox(tr("&Connect through SOCKS4 proxy:"));
164 connect_socks4->setToolTip(tr("Connect to the Bitcon network through a SOCKS4 proxy (e.g. when connecting through Tor)"));
165 layout->addWidget(connect_socks4);
167 QHBoxLayout *proxy_hbox = new QHBoxLayout();
168 proxy_hbox->addSpacing(18);
169 QLabel *proxy_ip_label = new QLabel(tr("Proxy &IP: "));
170 proxy_hbox->addWidget(proxy_ip_label);
171 proxy_ip = new QLineEdit();
172 proxy_ip->setMaximumWidth(140);
173 proxy_ip->setEnabled(false);
174 proxy_ip->setValidator(new QRegExpValidator(QRegExp("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"), this));
175 proxy_ip->setToolTip(tr("IP address of the proxy (e.g. 127.0.0.1)"));
176 proxy_ip_label->setBuddy(proxy_ip);
177 proxy_hbox->addWidget(proxy_ip);
178 QLabel *proxy_port_label = new QLabel(tr("&Port: "));
179 proxy_hbox->addWidget(proxy_port_label);
180 proxy_port = new QLineEdit();
181 proxy_port->setMaximumWidth(55);
182 proxy_port->setValidator(new QIntValidator(0, 65535, this));
183 proxy_port->setEnabled(false);
184 proxy_port->setToolTip(tr("Port of the proxy (e.g. 1234)"));
185 proxy_port_label->setBuddy(proxy_port);
186 proxy_hbox->addWidget(proxy_port);
187 proxy_hbox->addStretch(1);
189 layout->addLayout(proxy_hbox);
190 QLabel *fee_help = new QLabel(tr("Optional transaction fee per KB that helps make sure your transactions are processed quickly. Most transactions are 1KB. Fee 0.01 recommended."));
191 fee_help->setWordWrap(true);
192 layout->addWidget(fee_help);
194 QHBoxLayout *fee_hbox = new QHBoxLayout();
195 fee_hbox->addSpacing(18);
196 QLabel *fee_label = new QLabel(tr("Pay transaction &fee"));
197 fee_hbox->addWidget(fee_label);
198 fee_edit = new QLineEdit();
199 fee_edit->setMaximumWidth(100);
200 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."));
202 GUIUtil::setupAmountWidget(fee_edit, this);
204 fee_label->setBuddy(fee_edit);
205 fee_hbox->addWidget(fee_edit);
206 fee_hbox->addStretch(1);
208 layout->addLayout(fee_hbox);
210 layout->addStretch(1); /* Extra space at bottom */
214 connect(connect_socks4, SIGNAL(toggled(bool)), proxy_ip, SLOT(setEnabled(bool)));
215 connect(connect_socks4, SIGNAL(toggled(bool)), proxy_port, SLOT(setEnabled(bool)));
218 map_port_upnp->setDisabled(true);
222 void MainOptionsPage::setMapper(MonitoredDataMapper *mapper)
224 /* Map model to widgets */
225 mapper->addMapping(bitcoin_at_startup, OptionsModel::StartAtStartup);
226 mapper->addMapping(minimize_to_tray, OptionsModel::MinimizeToTray);
227 mapper->addMapping(map_port_upnp, OptionsModel::MapPortUPnP);
228 mapper->addMapping(minimize_on_close, OptionsModel::MinimizeOnClose);
229 mapper->addMapping(connect_socks4, OptionsModel::ConnectSOCKS4);
230 mapper->addMapping(proxy_ip, OptionsModel::ProxyIP);
231 mapper->addMapping(proxy_port, OptionsModel::ProxyPort);
232 mapper->addMapping(fee_edit, OptionsModel::Fee);