diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index da52178..117fa1e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,62 @@ -cmake_minimum_required (VERSION 3.8) +cmake_minimum_required(VERSION 3.5) -add_executable (WayNetConverter "main.cpp" "Converter.cpp" "Converter.h" "Waypoint.h") +project(WayNetConverter_QT VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + Converter.cpp + Converter.h + Waypoint.h + mainwindow.ui +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(WayNetConverter_QT + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET WayNetConverter_QT APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(WayNetConverter_QT SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(WayNetConverter_QT + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(WayNetConverter_QT PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +set_target_properties(WayNetConverter_QT PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +install(TARGETS WayNetConverter_QT + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(WayNetConverter_QT) +endif() diff --git a/src/main.cpp b/src/main.cpp index 9c7582d..80f6059 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,25 +1,98 @@ #include #include #include "Converter.h" +#include +#include +#include +#include +#include +#include + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr) : QMainWindow(parent) + { + auto layout = new QVBoxLayout(); + + openZenButton = new QPushButton(tr("Zen öffnen"), this); + layout->addWidget(openZenButton); + + convertButton = new QPushButton(tr("Konvertieren"), this); + convertButton->setEnabled(false); + layout->addWidget(convertButton); + + auto centralWidget = new QWidget(); + centralWidget->setLayout(layout); + setCentralWidget(centralWidget); + + setStatusBar(new QStatusBar()); + statusBar()->showMessage(tr("Bitte wählen Sie eine ZEN-Datei.")); + connect(openZenButton, &QPushButton::clicked, this, &MainWindow::openZen); + connect(convertButton, &QPushButton::clicked, this, &MainWindow::convert); + } + +private slots: + void openZen() + { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open .zen File"), QDir::homePath(), tr(".zen Files (*.zen)")); + if (!fileName.isEmpty()) { + // call the read function of the Converter class with the selected file name + selectedFile = fileName; + statusBar()->showMessage(selectedFile); + convertButton->setEnabled(true); + } + } + + void convert() + { + QString outputFile = QFileDialog::getSaveFileName(this, tr("Save Converted File"), QDir::homePath(), tr(".wp Files (*.wp)")); + if (!outputFile.isEmpty()) { + // call the read and write functions of the Converter class with the selected file names + Converter converter; + converter.read(selectedFile.toStdString()); + converter.write(outputFile.toStdString()); + statusBar()->showMessage("Konvertierung abgeschlossen."); + } + } + + + +private: + QPushButton *openZenButton; + QPushButton *convertButton; + QString selectedFile; +}; int main(int argc, char **argv) { - std::cout << "Reveares' Waypoint Converter" << std::endl << std::endl; + /* + std::cout << "Reveares' Waypoint Converter" << std::endl << std::endl; - if (argc != 3) - { - std::cerr << "2 Arguments are needed!" << std::endl << "first: path/to/file.zen" << std::endl << "second: filename.wp" << std::endl; - return -1; - } + if (argc != 3) + { + std::cerr << "2 Arguments are needed!" << std::endl << "first: path/to/file.zen" << std::endl << "second: filename.wp" << std::endl; + return -1; + } - auto start = std::chrono::high_resolution_clock::now(); + auto start = std::chrono::high_resolution_clock::now(); - Converter converter; - converter.read(argv[1]); - converter.write(argv[2]); + Converter converter; + converter.read(argv[1]); + converter.write(argv[2]); - auto end = std::chrono::high_resolution_clock::now(); - std::cout << "Which took " << std::chrono::duration(end - start).count() << " seconds." << std::endl; + auto end = std::chrono::high_resolution_clock::now(); + std::cout << "Which took " << std::chrono::duration(end - start).count() << " seconds." << std::endl; + */ - return 0; + QApplication app(argc, argv); + + MainWindow mainWindow; + mainWindow.show(); + + return app.exec(); } + +#include "main.moc" diff --git a/src/mainwindow.ui b/src/mainwindow.ui new file mode 100644 index 0000000..a82d478 --- /dev/null +++ b/src/mainwindow.ui @@ -0,0 +1,84 @@ + + + MainWindow + + + + 0 + 0 + 560 + 174 + + + + MainWindow + + + + + + 200 + 20 + 88 + 34 + + + + false + + + Öffne eine Zen Datei + + + Zen öffnen + + + + + + + 0 + 0 + 560 + 30 + + + + + Datei + + + + + + + + Zen öffnen + + + + + Beenden + + + + + + + openZenButton + clicked() + openZenButton + click() + + + 77 + 267 + + + 77 + 267 + + + + +