mirror of
https://github.com/wownero/wowlet.git
synced 2026-10-26 18:58:35 +01:00
RestoreHeightDialog: rework
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#include "RestoreHeightWidget.h"
|
||||
#include "ui_RestoreHeightWidget.h"
|
||||
|
||||
#include <QValidator>
|
||||
|
||||
#include "AppData.h"
|
||||
#include "constants.h"
|
||||
|
||||
RestoreHeightWidget::RestoreHeightWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::RestoreHeightWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
QRegExp yearRe(R"(\d{2,4}-\d{1,2}-\d{1,2})");
|
||||
QValidator *yearValidator = new QRegExpValidator(yearRe, this);
|
||||
ui->line_creationDate->setValidator(yearValidator);
|
||||
|
||||
QRegExp heightRe(R"(\d{7})");
|
||||
QValidator *heightValidator = new QRegExpValidator(heightRe, this);
|
||||
ui->line_restoreHeight->setValidator(heightValidator);
|
||||
|
||||
connect(ui->line_creationDate, &QLineEdit::textEdited, this, &RestoreHeightWidget::onCreationDateChanged);
|
||||
connect(ui->line_restoreHeight, &QLineEdit::textEdited, this, &RestoreHeightWidget::onRestoreHeightChanged);
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::setHeight(quint64 restoreHeight) {
|
||||
ui->line_restoreHeight->setText(QString::number(restoreHeight));
|
||||
this->onRestoreHeightChanged();
|
||||
}
|
||||
|
||||
int RestoreHeightWidget::getHeight() {
|
||||
return ui->line_restoreHeight->text().toInt();
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::onCreationDateChanged() {
|
||||
auto curDate = QDateTime::currentDateTime().addDays(-7);
|
||||
auto date = QDateTime::fromString(ui->line_creationDate->text(), "yyyy-MM-dd");
|
||||
if (!date.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDateTime restoreDate = date > curDate ? curDate : date;
|
||||
qint64 timestamp = restoreDate.toSecsSinceEpoch();
|
||||
|
||||
QString restoreHeight = QString::number(appData()->restoreHeights[constants::networkType]->dateToHeight(timestamp));
|
||||
ui->line_restoreHeight->setText(restoreHeight);
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::onRestoreHeightChanged() {
|
||||
int restoreHeight = ui->line_restoreHeight->text().toInt();
|
||||
QDateTime date = appData()->restoreHeights[constants::networkType]->heightToDate(restoreHeight);
|
||||
ui->line_creationDate->setText(date.toString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
RestoreHeightWidget::~RestoreHeightWidget() {
|
||||
delete ui;
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#ifndef RESTOREHEIGHTWIDGET_H
|
||||
#define RESTOREHEIGHTWIDGET_H
|
||||
#ifndef FEATHER_RESTOREHEIGHTWIDGET_H
|
||||
#define FEATHER_RESTOREHEIGHTWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QItemSelection>
|
||||
|
||||
#include "appcontext.h"
|
||||
|
||||
namespace Ui {
|
||||
class RestoreHeightWidget;
|
||||
@@ -19,17 +16,18 @@ class RestoreHeightWidget : public QWidget
|
||||
|
||||
public:
|
||||
explicit RestoreHeightWidget(QWidget *parent = nullptr);
|
||||
void initRestoreHeights(RestoreHeightLookup *lookup);
|
||||
void setHeight(int height);
|
||||
int getHeight();
|
||||
void hideSlider();
|
||||
~RestoreHeightWidget() override;
|
||||
|
||||
private:
|
||||
void updateTimestamp(int date);
|
||||
void setHeight(quint64 restoreHeight);
|
||||
int getHeight();
|
||||
|
||||
RestoreHeightLookup *m_restoreHeightLookup = nullptr;
|
||||
private slots:
|
||||
void onCreationDateChanged();
|
||||
void onRestoreHeightChanged();
|
||||
|
||||
private:
|
||||
Ui::RestoreHeightWidget *ui;
|
||||
};
|
||||
|
||||
#endif // RESTOREHEIGHTWIDGET_H
|
||||
|
||||
#endif //FEATHER_RESTOREHEIGHTWIDGET_H
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RestoreHeightWidget</class>
|
||||
<widget class="QWidget" name="RestoreHeightWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>622</width>
|
||||
<height>88</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Wallet creation date:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="line_creationDate"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>(YYYY-MM-DD)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Restore height:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="line_restoreHeight"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<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>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -1,71 +0,0 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// Copyright (c) 2020-2021, The Monero Project.
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "restoreheightwidget.h"
|
||||
#include "ui_restoreheightwidget.h"
|
||||
|
||||
RestoreHeightWidget::RestoreHeightWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::RestoreHeightWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->lineEdit_restoreHeight->setValidator(new QIntValidator(0, 2147483647, this));
|
||||
|
||||
connect(ui->lineEdit_restoreHeight, &QLineEdit::textEdited, [this](const QString &val){
|
||||
if (val.isEmpty()) return;
|
||||
this->setHeight(val.toInt());
|
||||
});
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::hideSlider(){
|
||||
ui->restoreGrid->hide();
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::setHeight(int height) {
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
|
||||
// Update lineEdit
|
||||
ui->lineEdit_restoreHeight->setText(QString::number(height));
|
||||
|
||||
// Update slider
|
||||
int date = m_restoreHeightLookup->heightToTimestamp(height);
|
||||
ui->restoreSlider->setValue(date);
|
||||
|
||||
this->updateTimestamp(date);
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::initRestoreHeights(RestoreHeightLookup *lookup) {
|
||||
// init slider
|
||||
m_restoreHeightLookup = lookup;
|
||||
int now = std::time(nullptr);
|
||||
QList<int> blockDates = m_restoreHeightLookup->data.keys();
|
||||
ui->restoreSlider->setMinimum(blockDates[0]);
|
||||
ui->restoreSlider->setMaximum(now);
|
||||
|
||||
connect(ui->restoreSlider, &QSlider::sliderMoved, [this](int date){
|
||||
// Update lineEdit
|
||||
int blockHeight = m_restoreHeightLookup->dateToHeight(date);
|
||||
ui->lineEdit_restoreHeight->setText(QString::number(blockHeight));
|
||||
|
||||
this->updateTimestamp(date);
|
||||
});
|
||||
}
|
||||
|
||||
void RestoreHeightWidget::updateTimestamp(int date) {
|
||||
QDateTime timestamp;
|
||||
timestamp.setTime_t(date);
|
||||
ui->label_restoreHeightDate->setText(timestamp.toString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
int RestoreHeightWidget::getHeight() {
|
||||
return ui->lineEdit_restoreHeight->text().toInt();
|
||||
}
|
||||
|
||||
RestoreHeightWidget::~RestoreHeightWidget() {
|
||||
delete ui;
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RestoreHeightWidget</class>
|
||||
<widget class="QWidget" name="RestoreHeightWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>89</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="restoreGrid">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_restoreHeightDate">
|
||||
<property name="text">
|
||||
<string>2014-04-18</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_restoreHeight">
|
||||
<property name="text">
|
||||
<string>Restore height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QSlider" name="restoreSlider">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="restoreHeightLayout">
|
||||
<item row="4" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_restoreHeight">
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</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>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user