From 5ca4d80fb181790b1c8afa61340ab29041dc3b5f Mon Sep 17 00:00:00 2001 From: leogeier Date: Sat, 16 Jun 2018 01:27:30 +0200 Subject: [PATCH 1/3] refs #94: added custom mail dialog class --- src/mailDialog.cpp | 28 ++++++++++++++++++++++++++++ src/mailDialog.hpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/mailDialog.cpp create mode 100644 src/mailDialog.hpp diff --git a/src/mailDialog.cpp b/src/mailDialog.cpp new file mode 100644 index 0000000..1ff95b2 --- /dev/null +++ b/src/mailDialog.cpp @@ -0,0 +1,28 @@ +// +// Created by Leonard Geier on 15.06.18. +// + +#include +#include "mailDialog.hpp" + +MailDialog::MailDialog() + : QDialog() + , m_title("Bitte gib deine E-Mail an:") + , m_buttonOk("OK") + , m_buttonCancel("Cancel") + , m_input() + , m_layout() { + + QObject::connect(&m_buttonOk, &QPushButton::clicked, [=](){ + emit enteredMail(this->m_input.text().toStdString()); + this->done(0); + }); + QObject::connect(&m_buttonOk, &QPushButton::clicked, [=](){ + this->done(1); + }); + m_layout.addWidget(&m_title, 0, 0, 1, 10); + m_layout.addWidget(&m_input, 1, 0, 1, 10); + m_layout.addWidget(&m_buttonOk, 2, 0, 1, 1); + m_layout.addWidget(&m_buttonCancel, 2, 1, 1, 1); + this->setLayout(&m_layout); +} \ No newline at end of file diff --git a/src/mailDialog.hpp b/src/mailDialog.hpp new file mode 100644 index 0000000..b78f298 --- /dev/null +++ b/src/mailDialog.hpp @@ -0,0 +1,35 @@ +// +// Created by Leonard Geier on 15.06.18. +// + +#ifndef SNAILSNAP_MAILDIALOG_H +#define SNAILSNAP_MAILDIALOG_H + + +#include +#include +#include +#include +#include + +class MailDialog : public QDialog { + + Q_OBJECT + +public: + MailDialog(); + +private: + QLabel m_title; + QLineEdit m_input; + QPushButton m_buttonOk; + QPushButton m_buttonCancel; + + QGridLayout m_layout; + +signals: + void enteredMail(std::string address); +}; + + +#endif //SNAILSNAP_MAILDIALOG_H From 03d13eacfd3616ad35ab91d3a8ea1f6aa635fd8a Mon Sep 17 00:00:00 2001 From: leogeier Date: Sat, 16 Jun 2018 01:29:53 +0200 Subject: [PATCH 2/3] refs 94: updated CMakeLists.txt --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c967259..6ea88ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,8 @@ set(sources ${source_dir}/helpers/painter.cpp ${source_dir}/helpers/boundingbox.cpp ${source_dir}/helpers/positionGenerator.cpp - ${source_dir}/sidebar.cpp) + ${source_dir}/sidebar.cpp + ${source_dir}/mailDialog.cpp) set(headers ${source_dir}/mosaic.hpp @@ -81,7 +82,8 @@ set(headers ${source_dir}/helpers/painter.hpp ${source_dir}/helpers/boundingbox.hpp ${source_dir}/helpers/positionGenerator.hpp - ${source_dir}/sidebar.hpp) + ${source_dir}/sidebar.hpp + ${source_dir}/mailDialog.hpp) # target and required libs From 07847679a4d3085796083a2232bf0fbb60706903 Mon Sep 17 00:00:00 2001 From: leogeier Date: Sat, 16 Jun 2018 01:40:10 +0200 Subject: [PATCH 3/3] refs #94: using custom dialog now --- src/mailDialog.cpp | 2 +- src/mailDialog.hpp | 2 +- src/mainwindow.cpp | 37 +++++++++++++++++++++++++------------ src/mainwindow.hpp | 3 +++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/mailDialog.cpp b/src/mailDialog.cpp index 1ff95b2..b6ded45 100644 --- a/src/mailDialog.cpp +++ b/src/mailDialog.cpp @@ -14,7 +14,7 @@ MailDialog::MailDialog() , m_layout() { QObject::connect(&m_buttonOk, &QPushButton::clicked, [=](){ - emit enteredMail(this->m_input.text().toStdString()); + emit enteredMail(this->m_input.text()); this->done(0); }); QObject::connect(&m_buttonOk, &QPushButton::clicked, [=](){ diff --git a/src/mailDialog.hpp b/src/mailDialog.hpp index b78f298..a74ae8c 100644 --- a/src/mailDialog.hpp +++ b/src/mailDialog.hpp @@ -28,7 +28,7 @@ class MailDialog : public QDialog { QGridLayout m_layout; signals: - void enteredMail(std::string address); + void enteredMail(QString address); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 713d7a8..6276bc0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -35,6 +35,7 @@ MainWindow::MainWindow(QWidget *parent, bool useCam, QString outputPath, , m_maxNumOfMolluscs(maxNumOfMolluscs) , m_data(data) , m_mailClient(MailClient::fromCredentials("resources/credentials.txt")) + , m_mailDialog() { m_molluscPalette->loadData(data); @@ -70,6 +71,17 @@ MainWindow::MainWindow(QWidget *parent, bool useCam, QString outputPath, this->showDia(); initializeSidebar(); + + QObject::connect(&m_mailDialog, &MailDialog::enteredMail, [=](QString text){ + std::cout << "sdfsdf\n"; + if (!text.isEmpty()) { + if (!text.contains("@") || !text.contains(".")) { + //TODO: show user? + return; + } + m_mailClient.sendImage(text, *m_result); + } + }); } MainWindow::~MainWindow() = default; @@ -302,18 +314,19 @@ void MainWindow::stopDia() } void MainWindow::shareButtonClick() { - bool ok; - QString text = QInputDialog::getText(this, tr("Schneckenpost"), - tr("Sende dir das Bild an deine Mailadresse:"), QLineEdit::Normal, - "", &ok); - std::string adr = text.toStdString(); - if (ok && !text.isEmpty()) { - if (!text.contains("@") || !text.contains(".")) { - //TODO: show user? - return; - } - m_mailClient.sendImage(text, *m_result); - } +// bool ok; + m_mailDialog.exec(); +// QString text = QInputDialog::getText(this, tr("Schneckenpost"), +// tr("Sende dir das Bild an deine Mailadresse:"), QLineEdit::Normal, +// "", &ok); +// std::string adr = text.toStdString(); +// if (ok && !text.isEmpty()) { +// if (!text.contains("@") || !text.contains(".")) { +// //TODO: show user? +// return; +// } +// m_mailClient.sendImage(text, *m_result); +// } } void MainWindow::sendMail() diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index cbf0f6a..86e9013 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -20,6 +20,7 @@ #include "helpers/painter.hpp" #include "algorithms/voronoi.hpp" +#include "mailDialog.hpp" class MainWindow : public QMainWindow { Q_OBJECT @@ -93,6 +94,8 @@ class MainWindow : public QMainWindow { void processAndShowPicture(std::shared_ptr image); void initializeSidebar(); + MailDialog m_mailDialog; + public slots: void shareButtonClick(); void showDia();