Browse Source

Send page checkbox

recurring
Aditya Kulkarni 5 years ago
parent
commit
ace9038070
  1. 3
      src/mainwindow.h
  2. 72
      src/mainwindow.ui
  3. 199
      src/newrecurring.ui
  4. 60
      src/recurring.cpp
  5. 38
      src/recurring.h
  6. 30
      src/sendtab.cpp

3
src/mainwindow.h

@ -38,6 +38,7 @@ public:
~MainWindow();
void updateLabelsAutoComplete();
RPC* getRPC() { return rpc; }
void setDefaultPayFrom();
@ -76,6 +77,8 @@ private:
void addAddressSection();
void maxAmountChecked(int checked);
void editSchedule();
void addressChanged(int number, const QString& text);
void amountChanged (int number, const QString& text);

72
src/mainwindow.ui

@ -346,8 +346,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>928</width>
<height>380</height>
<width>920</width>
<height>301</height>
</rect>
</property>
<layout class="QVBoxLayout" name="sendToLayout">
@ -531,29 +531,36 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QLabel" name="minerFeeLabel">
<widget class="QCheckBox" name="chkRecurring">
<property name="text">
<string>Miner Fee</string>
<string>Recurring payment</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="minerFeeAmt">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QLabel" name="lblRecurDesc">
<property name="text">
<string>Every month, starting 12-May-2012, for 6 payments</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRecurSchedule">
<property name="text">
<string>0</string>
<string>Edit Schedule</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -565,34 +572,57 @@
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="lblMinerFeeUSD">
<widget class="QLabel" name="minerFeeLabel">
<property name="text">
<string/>
<string>Miner Fee</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<widget class="QLineEdit" name="minerFeeAmt">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>This transaction does not recur</string>
<string>0</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QLabel" name="lblMinerFeeUSD">
<property name="text">
<string>Setup Recurring Payment</string>
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string notr="true"> </string>
<string notr="true"/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="sendTransactionButton">
<property name="baseSize">
@ -1013,7 +1043,7 @@
<x>0</x>
<y>0</y>
<width>968</width>
<height>19</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

199
src/newrecurring.ui

@ -1,29 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<class>newRecurringDialog</class>
<widget class="QDialog" name="newRecurringDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>740</width>
<height>403</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Edit Schedule</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="lineEdit_4"/>
</item>
<item row="5" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboBox_3"/>
<widget class="QComboBox" name="cmbSchedule"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -37,10 +34,7 @@
</item>
</layout>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBox"/>
</item>
<item row="9" column="2">
<item row="10" column="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -50,85 +44,51 @@
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>To</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Schedule</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Number of payments</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Amount</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_8">
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Next Payment</string>
<string>Payment Description</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QLabel" name="label_9">
<item row="8" column="2">
<widget class="QLabel" name="lblNextPayment">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Payment Description</string>
<item row="7" column="1" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="lineEdit_5"/>
</item>
<item row="4" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item row="3" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Every</string>
<widget class="QLineEdit" name="txtAmt">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
<widget class="QComboBox" name="cmbCurrency"/>
</item>
<item>
<widget class="QComboBox" name="comboBox_2"/>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -142,17 +102,50 @@
</item>
</layout>
</item>
<item row="5" column="2">
<item row="0" column="2">
<widget class="QLineEdit" name="txtDesc"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Number of payments</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Amount</string>
</property>
</widget>
</item>
<item row="9" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="AddressCombo" name="cmbFromAddress"/>
</item>
<item row="6" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lineEdit_3"/>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Forever</string>
</property>
</widget>
<widget class="QLineEdit" name="txtNumPayments"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
@ -169,21 +162,57 @@
</item>
</layout>
</item>
<item row="6" column="1" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="8" column="1">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Next Payment</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="txtToAddr"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>To</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPlainTextEdit" name="txtMemo"/>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Memo</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AddressCombo</class>
<extends>QComboBox</extends>
<header>addresscombo.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>txtDesc</tabstop>
<tabstop>cmbFromAddress</tabstop>
<tabstop>txtToAddr</tabstop>
<tabstop>txtAmt</tabstop>
<tabstop>cmbCurrency</tabstop>
<tabstop>cmbSchedule</tabstop>
<tabstop>txtNumPayments</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<receiver>newRecurringDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@ -199,7 +228,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<receiver>newRecurringDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

60
src/recurring.cpp

@ -1,14 +1,48 @@
#include "recurring.h"
#include "ui_recurringdialog.h"
RecurringDialog::RecurringDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::RecurringDialog)
{
ui->setupUi(this);
}
RecurringDialog::~RecurringDialog()
{
delete ui;
}
#include "mainwindow.h"
#include "rpc.h"
#include "settings.h"
#include "ui_newrecurring.h"
void Recurring::showEditDialog(QWidget* parent, MainWindow* main, Tx tx) {
Ui_newRecurringDialog ui;
QDialog d(parent);
ui.setupUi(&d);
Settings::saveRestore(&d);
// Add all the from addresses
auto allBalances = main->getRPC()->getAllBalances();
for (QString addr : allBalances->keys()) {
ui.cmbFromAddress->addItem(addr, allBalances->value(addr));
}
if (!tx.fromAddr.isEmpty()) {
ui.cmbFromAddress->setCurrentText(tx.fromAddr);
ui.cmbFromAddress->setEnabled(false);
}
ui.cmbCurrency->addItem(Settings::getTokenName());
ui.cmbCurrency->addItem("USD");
if (tx.toAddrs.length() > 0) {
ui.txtToAddr->setText(tx.toAddrs[0].addr);
ui.txtToAddr->setEnabled(false);
ui.txtAmt->setText(Settings::getDecimalString(tx.toAddrs[0].amount));
ui.txtAmt->setEnabled(false);
ui.txtMemo->setPlainText(tx.toAddrs[0].txtMemo);
ui.txtMemo->setEnabled(false);
}
ui.cmbSchedule->addItem("Every Day", QVariant(Schedule::DAY));
ui.cmbSchedule->addItem("Every Week", QVariant(Schedule::WEEK));
ui.cmbSchedule->addItem("Every Month", QVariant(Schedule::MONTH));
ui.cmbSchedule->addItem("Every Year", QVariant(Schedule::YEAR));
ui.txtNumPayments->setText("10");
ui.txtDesc->setFocus();
d.exec();
}

38
src/recurring.h

@ -1,22 +1,36 @@
#ifndef RECURRING_H
#define RECURRING_H
#include <QDialog>
#include "precompiled.h"
namespace Ui {
class RecurringDialog;
}
#include "mainwindow.h"
class RecurringDialog : public QDialog
{
Q_OBJECT
enum Schedule {
DAY = 1,
WEEK,
MONTH,
YEAR
};
struct RecurringPaymentInfo {
QString desc;
QString fromAddr;
QString toAddr;
double amt;
QString currency;
Schedule schedule;
int numPayments;
long startBlock;
int completedPayments;
};
class Recurring
{
public:
explicit RecurringDialog(QWidget *parent = nullptr);
~RecurringDialog();
Recurring();
private:
Ui::RecurringDialog *ui;
static void showEditDialog(QWidget* parent, MainWindow* main, Tx tx);
};
#endif // RECURRING_H
#endif // RECURRING_H

30
src/sendtab.cpp

@ -3,8 +3,10 @@
#include "addressbook.h"
#include "ui_confirm.h"
#include "ui_memodialog.h"
#include "ui_newrecurring.h"
#include "settings.h"
#include "rpc.h"
#include "recurring.h"
using json = nlohmann::json;
@ -80,6 +82,29 @@ void MainWindow::setupSendTab() {
QFont f = ui->Address1->font();
f.setPointSize(f.pointSize() - 1);
ui->MemoTxt1->setFont(f);
// Recurring button
QObject::connect(ui->chkRecurring, &QCheckBox::stateChanged, [=] (int checked) {
if (checked) {
ui->btnRecurSchedule->setEnabled(true);
} else {
ui->btnRecurSchedule->setEnabled(false);
ui->lblRecurDesc->setText("");
}
});
// Recurring schedule button
QObject::connect(ui->btnRecurSchedule, &QPushButton::clicked, this, &MainWindow::editSchedule);
// Set the default state for the whole page
removeExtraAddresses();
}
void MainWindow::editSchedule() {
// Open the edit schedule dialog
Recurring::showEditDialog(this, this, createTxFromSendPage());
}
void MainWindow::updateLabelsAutoComplete() {
@ -354,6 +379,11 @@ void MainWindow::removeExtraAddresses() {
delete addressGroupBox;
}
// Reset the recurring button
ui->chkRecurring->setCheckState(Qt::Unchecked);
ui->btnRecurSchedule->setEnabled(false);
ui->lblRecurDesc->setText("");
}
void MainWindow::maxAmountChecked(int checked) {

Loading…
Cancel
Save