From 4d5b19cabec5072b5743af0509f874e0cf8fb8c1 Mon Sep 17 00:00:00 2001 From: amazing-username Date: Thu, 27 Jul 2017 12:04:10 -0500 Subject: [PATCH] Redirecting project's purpose into password encryption. Need to separate declaration from implementation --- CommonWindow.h | 6 +-- Conversions.h | 13 ++++++ KeyManagementWindow.cpp | 60 ++++++++++++++++--------- KeyManagementWindow.h | 21 ++------- Main.cpp | 4 +- MessagingControls.cpp => MainWindow.cpp | 39 +++++++--------- MessagingControls.h => MainWindow.h | 19 +++----- ViewingWindow.h | 7 +++ 8 files changed, 89 insertions(+), 80 deletions(-) rename MessagingControls.cpp => MainWindow.cpp (70%) rename MessagingControls.h => MainWindow.h (76%) diff --git a/CommonWindow.h b/CommonWindow.h index 3e0a9a6..d15da29 100644 --- a/CommonWindow.h +++ b/CommonWindow.h @@ -18,8 +18,8 @@ protected: unique_ptr selectionBox; unique_ptr actionButton; unique_ptr mainLayout; - unique_ptr subLayoutOne; - unique_ptr subLayoutTwo; - int height, width; + unique_ptr subLayoutOne; + unique_ptr subLayoutTwo; + int windowHeight, windowWidth; }; #endif diff --git a/Conversions.h b/Conversions.h index 378a211..f3b50b5 100644 --- a/Conversions.h +++ b/Conversions.h @@ -8,8 +8,10 @@ class Conversions { public: Conversions() = default; + ~Conversions()=default; std::string cstringToString(char[], const int); + //char stringToChar(const string&); private: }; @@ -22,4 +24,15 @@ std::string Conversions::cstringToString(char tmp[], const int size) cToS >> tmpString; return tmpString; } +/** +char Conversions::stringToChar(const string& tmp) +{ + char tmpChar{}; + stringstream sToC{}; + for (auto index=0; index!=tmp.size(); ++index) + sToC << tmpChar; + sToC >> tmpChar; + return tmpChar; +} +*/ #endif diff --git a/KeyManagementWindow.cpp b/KeyManagementWindow.cpp index bc0bde0..678f726 100644 --- a/KeyManagementWindow.cpp +++ b/KeyManagementWindow.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -10,37 +9,54 @@ #include"Encryption.h" #include"GenerateKeys.h" #include"KeyRetrieval.h" +#include"Conversions.h" KeyManagementWindow::KeyManagementWindow(QWidget* parent) : QDialog(parent) { - comboBoxOfKeys = unique_ptr{new QComboBox{}}; - valueOfKey = unique_ptr{new QLineEdit{}}; - generateNewDefaultKeys = unique_ptr{new QPushButton(tr("Generate New Default Key"))}; - closeButton = unique_ptr{new QPushButton(tr("close"))}; + windowWidth = 450; + windowHeight = 450; + + elementView = unique_ptr{new QTableView}; + + selectionBox = unique_ptr{new QComboBox{}}; + + generateNewKeys = unique_ptr{new QPushButton(tr("Generate New Default Key"))}; + closeButton = unique_ptr{new QPushButton(tr("close"))}; + actionButton = unique_ptr{new QPushButton}; + + mainLayout = unique_ptr{new QHBoxLayout}; + subLayoutOne = unique_ptr{new QVBoxLayout}; + subLayoutTwo = unique_ptr{new QVBoxLayout}; + + subLayoutGoonOne = unique_ptr{new QVBoxLayout}; + subLayoutGoonTwo = unique_ptr{new QVBoxLayout}; + + subLayoutOne.get()->addWidget(elementView.get()); + + subLayoutGoonOne.get()->addWidget(selectionBox.get()); + subLayoutGoonOne.get()->addWidget(actionButton.get()); + subLayoutGoonTwo.get()->addWidget(generateNewKeys.get()); + subLayoutGoonTwo.get()->addWidget(closeButton.get()); + + subLayoutTwo.get()->addLayout(subLayoutGoonOne.get()); + subLayoutTwo.get()->addLayout(subLayoutGoonTwo.get()); + + + mainLayout.get()->addLayout(subLayoutOne.get()); + mainLayout.get()->addLayout(subLayoutTwo.get()); - vBox = unique_ptr{new QVBoxLayout}; - hBox = unique_ptr{new QHBoxLayout}; - hBox2 = unique_ptr{new QHBoxLayout}; setContentsOfComboBox(); - hBox.get()->addWidget(comboBoxOfKeys.get()); - hBox.get()->addWidget(valueOfKey.get()); - hBox2.get()->addWidget(generateNewDefaultKeys.get()); - hBox2.get()->addWidget(closeButton.get()); - - vBox.get()->addLayout(hBox.get()); - vBox.get()->addLayout(hBox2.get()); - - setLayout(vBox.get()); + setLayout(mainLayout.get()); setFixedWidth(windowWidth); setFixedHeight(windowHeight); setWindowTitle("Key Management Window"); - QObject::connect(comboBoxOfKeys.get(), SIGNAL(currentIndexChanged(int)), SLOT(test())); - QObject::connect(generateNewDefaultKeys.get(), SIGNAL(clicked()), this, SLOT(generation())); + QObject::connect(selectionBox.get(), SIGNAL(currentIndexChanged(int)), SLOT(test())); + QObject::connect(generateNewKeys.get(), SIGNAL(clicked()), this, SLOT(generation())); QObject::connect(closeButton.get(), SIGNAL(clicked()), this, SLOT(exitApplication())); } @@ -54,7 +70,7 @@ void KeyManagementWindow::setContentsOfComboBox() { std::string ch{static_cast(c[index])}; QString bl = QString::fromStdString(ch); - comboBoxOfKeys.get()->addItem(bl); + selectionBox.get()->addItem(bl); } } void KeyManagementWindow::test() @@ -62,7 +78,7 @@ void KeyManagementWindow::test() std::string emp{"d"}; Encryption ec{emp}; std::map encrypted{ec.encryptedCharactersStructure()}; - QString bo{comboBoxOfKeys.get()->currentText()}; + QString bo{selectionBox.get()->currentText()}; std::string k{bo.toStdString()}; char f{}; @@ -72,7 +88,7 @@ void KeyManagementWindow::test() std::string value{encrypted[f]}; QString v{QString::fromStdString(value)}; - valueOfKey.get()->setText(v); + //valueOfKey.get()->setText(v); } void KeyManagementWindow::generation() { diff --git a/KeyManagementWindow.h b/KeyManagementWindow.h index a50c71d..749253e 100644 --- a/KeyManagementWindow.h +++ b/KeyManagementWindow.h @@ -8,16 +8,10 @@ #include #include #include +#include"CommonWindow.h" +#include"ViewingWindow.h" -class QHBoxLayout; -class QVBoxLayout; -class QComboBox; -class QLineEdit; -class QPushButton; - -using std::unique_ptr; - -class KeyManagementWindow : public QDialog +class KeyManagementWindow : public QDialog, public CommonWindow, public ViewingWindow { Q_OBJECT public: @@ -30,15 +24,6 @@ private slots: void generation(); void exitApplication(); private: - unique_ptr hBox; - unique_ptr hBox2; - unique_ptr vBox; - unique_ptr comboBoxOfKeys; - unique_ptr valueOfKey; - unique_ptr generateNewDefaultKeys; - unique_ptr closeButton; - const int windowWidth{400}; - const int windowHeight{400}; }; #endif diff --git a/Main.cpp b/Main.cpp index fcafda2..85c0aba 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,11 +1,11 @@ #include -#include"MessagingControls.h" +#include"MainWindow.h" int main(int argc, char* argv[]) { QApplication app(argc, argv); - MessagingControls stuff{}; + MainWindow stuff{}; stuff.show(); diff --git a/MessagingControls.cpp b/MainWindow.cpp similarity index 70% rename from MessagingControls.cpp rename to MainWindow.cpp index f3ea62f..c178a8a 100644 --- a/MessagingControls.cpp +++ b/MainWindow.cpp @@ -1,31 +1,30 @@ #include -#include -#include"MessagingControls.h" +#include"MainWindow.h" #include"Encryption.h" #include"Decryption.h" #include"KeyRetrieval.h" -MessagingControls::MessagingControls() +MainWindow::MainWindow() { - mainWindowWidth = 450; - mainWindowHeight = 450; + windowHeight = 450; + windowWidth = 450; setupMainWindow(); } -void MessagingControls::setupMainWindow() +void MainWindow::setupMainWindow() { kh = unique_ptr{new KeyManagementWindow}; textForCryption = unique_ptr{new QTextEdit{}}; - cryptionButon = unique_ptr{new QPushButton(tr("XO"))}; - cryptionSwitch = unique_ptr{new QPushButton(tr("encrypt chosen"))}; + actionButton = unique_ptr{new QPushButton(tr("encrypt"))}; + selectionBox = unique_ptr{new QComboBox{}}; buttonLayout = unique_ptr{new QVBoxLayout}; buttonWidget = unique_ptr{new QWidget}; buttonDockWidget = unique_ptr{new QDockWidget}; buttonDockWidget.get()->setWindowTitle(tr("Cryption Controls")); - buttonLayout.get()->addWidget(cryptionButon.get()); - buttonLayout.get()->addWidget(cryptionSwitch.get()); + buttonLayout.get()->addWidget(selectionBox.get()); + buttonLayout.get()->addWidget(actionButton.get()); buttonWidget.get()->setLayout(buttonLayout.get()); buttonDockWidget.get()->setWidget(buttonWidget.get()); buttonDockWidget.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); @@ -36,20 +35,16 @@ void MessagingControls::setupMainWindow() cryptionArea.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); addDockWidget(Qt::LeftDockWidgetArea, cryptionArea.get()); - addDockWidget(Qt::LeftDockWidgetArea, cryptionArea.get()); - createMenus(); QObject::connect(closeApplication.get(), SIGNAL(triggered()), this, SLOT(exitApplication())); - QObject::connect(cryptionSwitch.get(), SIGNAL(clicked()), this, SLOT(changeCryptionType())); - QObject::connect(cryptionButon.get(), SIGNAL(clicked()), this, SLOT(determineCryption())); QObject::connect(keyEdit.get(), SIGNAL(triggered()), this, SLOT(keyManagementWindow())); setWindowTitle("Encryption Decryption Messaging"); - setFixedHeight(mainWindowHeight); - setFixedWidth(mainWindowWidth); + setFixedHeight(windowHeight); + setFixedWidth(windowWidth); } -void MessagingControls::createMenus() +void MainWindow::createMenus() { fileMenu = unique_ptr{menuBar()->addMenu(tr("File"))}; editMenu = unique_ptr{menuBar()->addMenu(tr("Edit"))}; @@ -65,12 +60,12 @@ void MessagingControls::createMenus() } -void MessagingControls::changeCryptionType() +void MainWindow::changeCryptionType() { (cryptionChoice) ? cryptionSwitch->setText("decrypt chosen") : cryptionSwitch->setText("encrypt chosen"); cryptionChoice = (cryptionChoice) ? false : true; } -void MessagingControls::determineCryption() +void MainWindow::determineCryption() { if (cryptionChoice) { @@ -93,11 +88,11 @@ void MessagingControls::determineCryption() cryptionChoice = true; } } -void MessagingControls::keyManagementWindow() { kh.get()->show(); } -void MessagingControls::exitApplication() { exit(0); } +void MainWindow::keyManagementWindow() { kh.get()->show(); } +void MainWindow::exitApplication() { exit(0); } -std::string MessagingControls::grabCryptionText() +std::string MainWindow::grabCryptionText() { auto placeHolder = textForCryption.get()->toPlainText(); diff --git a/MessagingControls.h b/MainWindow.h similarity index 76% rename from MessagingControls.h rename to MainWindow.h index 0d01496..e7e99ba 100644 --- a/MessagingControls.h +++ b/MainWindow.h @@ -1,9 +1,8 @@ -#ifndef MESSAGINGCONTROLS_H -#define MESSAGINGCONTROLS_H +#ifndef MAINWINDOW_H_ +#define MAINWINDOW_H_ #include #include -#include #include #include #include @@ -15,16 +14,15 @@ #include #include #include"KeyManagementWindow.h" +#include"CommonWindow.h" -using std::unique_ptr; - -class MessagingControls : public QMainWindow +class MainWindow : public QMainWindow, public CommonWindow { Q_OBJECT public: - MessagingControls(); - ~MessagingControls() = default; + MainWindow(); + ~MainWindow() = default; signals: private slots: @@ -44,10 +42,8 @@ private: unique_ptr cryptionArea; unique_ptr lblOfEncryptedBox; - unique_ptr encryptedBox; unique_ptr textForCryption; - unique_ptr textToDecrypt; unique_ptr cryptionButon; unique_ptr cryptionSwitch; @@ -61,9 +57,6 @@ private: std::string grabCryptionText(); - int mainWindowHeight; - int mainWindowWidth; - bool cryptionChoice; }; #endif diff --git a/ViewingWindow.h b/ViewingWindow.h index 4255fbc..9c98f8d 100644 --- a/ViewingWindow.h +++ b/ViewingWindow.h @@ -1,6 +1,8 @@ #ifndef VIEWINGWINDOW_H_ #define VIEWINGWINDOW_H_ +#include +#include #include #include #include @@ -13,6 +15,11 @@ public: ViewingWindow() = default; ~ViewingWindow() = default; protected: + unique_ptr subLayoutGoonOne; + unique_ptr subLayoutGoonTwo; unique_ptr crypticText; + unique_ptr elementView; + unique_ptr closeButton; + unique_ptr generateNewKeys; }; #endif