From e3efc04807f946cc75b06ec84b4af79d66b23cce Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Wed, 29 May 2024 22:46:29 -0400 Subject: Implement basic Welcome tab for greeting user --- CMakeLists.txt | 3 ++ src/mainwindow.cpp | 14 ++++++++- src/mainwindow.h | 4 ++- src/widgets/tab_welcome.cpp | 24 +++++++++++++++ src/widgets/tab_welcome.h | 29 ++++++++++++++++++ src/widgets/tab_welcome.ui | 73 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/widgets/tab_welcome.cpp create mode 100644 src/widgets/tab_welcome.h create mode 100644 src/widgets/tab_welcome.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index e95c601..55418ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,9 @@ set(PROJECT_SOURCES src/widgets/tab_actor_info.cpp src/widgets/tab_actor_info.h src/widgets/tab_actor_info.ui + src/widgets/tab_welcome.cpp + src/widgets/tab_welcome.h + src/widgets/tab_welcome.ui src/archive/base_archive.cpp src/archive/base_archive.h src/archive/mastodon.cpp diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 296c961..89351ae 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,12 @@ MainWindow::~MainWindow() } void MainWindow::create_initial_tabs() { + welcome_tab = new TabWelcome(); + ui->tabWidget->addTab(welcome_tab, tr("Welcome")); + connect(welcome_tab, &TabWelcome::show_file_open_dialog, this, &MainWindow::on_actionOpen_triggered); + // TODO: recent files + //connect(welcome_tab, &TabWelcome::show_recent_files, this, &MainWindow::); + activity_list_tab = new TabActivityList(&data_archive); ui->tabWidget->addTab(activity_list_tab, tr("Activity List")); activity_list_tab->view_actions = { @@ -88,13 +94,19 @@ void MainWindow::act_command_line(CommandLineParsedOptions &options, QCommandLin } } -void MainWindow::on_actionOpen_triggered(bool checked) { +void MainWindow::on_actionOpen_triggered() { QFileDialog fileDialog; fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setNameFilter(tr("Mastodon data export directory (outbox.json)")); if (fileDialog.exec()) { QStringList files = fileDialog.selectedFiles(); open_file(files[0]); + + // Close the welcome tab as it's not needed anymore + if (welcome_tab) { + welcome_tab->deleteLater(); + welcome_tab = nullptr; + } } } diff --git a/src/mainwindow.h b/src/mainwindow.h index cc43176..03daaad 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -10,6 +10,7 @@ #include "src/settingsdialog.h" #include "src/widgets/tab_activity_list.h" #include "src/widgets/tab_actor_info.h" +#include "src/widgets/tab_welcome.h" #include "command_line.h" QT_BEGIN_NAMESPACE @@ -35,7 +36,7 @@ signals: void new_archive_opened(bool is_valid); private slots: - void on_actionOpen_triggered(bool checked); + void on_actionOpen_triggered(); void on_actionSettings_triggered(bool checked); void on_actionQuit_triggered(bool checked); void on_actionAbout_triggered(bool checked); @@ -52,6 +53,7 @@ private: void settingsDialog_done(int result); SettingsDialog* settings_dialog = nullptr; + TabWelcome* welcome_tab = nullptr; TabActivityList* activity_list_tab = nullptr; TabActorInfo* actor_info_tab = nullptr; diff --git a/src/widgets/tab_welcome.cpp b/src/widgets/tab_welcome.cpp new file mode 100644 index 0000000..2c8dc56 --- /dev/null +++ b/src/widgets/tab_welcome.cpp @@ -0,0 +1,24 @@ +#include "tab_welcome.h" + +TabWelcome::TabWelcome(QWidget* parent) + : QWidget(parent), ui(new Ui::TabWelcome) +{ + ui->setupUi(this); + ui->horizontalLayout->setContentsMargins(0, 0, 0, 0); + + ui->welcomeLabel->setText(ui->welcomeLabel->text() + .arg(tr("Welcome to ActorViewer!")) + .arg(tr("Start by opening a Fediverse data export, using a button below."))); +} + +TabWelcome::~TabWelcome() { + delete ui; +} + +void TabWelcome::on_openFileButton_clicked(bool checked) { + emit show_file_open_dialog(); +} + +void TabWelcome::on_openRecentButton_clicked(bool checked) { + emit show_recent_files(); +} diff --git a/src/widgets/tab_welcome.h b/src/widgets/tab_welcome.h new file mode 100644 index 0000000..effc84f --- /dev/null +++ b/src/widgets/tab_welcome.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "./ui_tab_welcome.h" + +QT_BEGIN_NAMESPACE +namespace Ui { class TabWelcome; } +QT_END_NAMESPACE + +class TabWelcome : public QWidget { + Q_OBJECT + +public: + TabWelcome(QWidget* parent = nullptr); + ~TabWelcome(); + +signals: + // Show Open file dialog + void show_file_open_dialog(); + + // Show recents dropdown + void show_recent_files(); + +private slots: + void on_openFileButton_clicked(bool checked); + void on_openRecentButton_clicked(bool checked); + +private: + Ui::TabWelcome* ui; +}; diff --git a/src/widgets/tab_welcome.ui b/src/widgets/tab_welcome.ui new file mode 100644 index 0000000..2f1e514 --- /dev/null +++ b/src/widgets/tab_welcome.ui @@ -0,0 +1,73 @@ + + + TabWelcome + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + <html><head/><body><p align="center">%1<p/><p>%2</p></body></html> + + + true + + + + + + + + + + 0 + 0 + + + + + 30 + 0 + + + + Open file… + + + + + + + + 0 + 0 + + + + + 30 + 0 + + + + Recent files… + + + + + + + + + + -- cgit v1.2.3-54-g00ecf