diff options
| author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-11-25 13:01:17 +0100 | 
|---|---|---|
| committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-11-25 15:05:18 +0100 | 
| commit | 09c4508aee96ca20d084b8a60b4c6603de8bff8b (patch) | |
| tree | fa17b39bb6018b96b8045b3af6bdfbd8e1ca5af5 /src/session | |
| parent | Add QT_NO_DEBUG to non-debug builds (diff) | |
| download | smolbote-09c4508aee96ca20d084b8a60b4c6603de8bff8b.tar.xz | |
Add Session Dialog
Diffstat (limited to 'src/session')
| -rw-r--r-- | src/session/sessiondialog.cpp | 87 | ||||
| -rw-r--r-- | src/session/sessiondialog.h | 34 | ||||
| -rw-r--r-- | src/session/sessiondialog.ui | 96 | ||||
| -rw-r--r-- | src/session/sessionform.cpp | 36 | ||||
| -rw-r--r-- | src/session/sessionform.h | 37 | ||||
| -rw-r--r-- | src/session/sessionform.ui | 41 | 
6 files changed, 331 insertions, 0 deletions
diff --git a/src/session/sessiondialog.cpp b/src/session/sessiondialog.cpp new file mode 100644 index 0000000..e31a42f --- /dev/null +++ b/src/session/sessiondialog.cpp @@ -0,0 +1,87 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "sessiondialog.h" +#include "../browser.h" +#include "../util.h" +#include "sessionform.h" +#include "ui_sessiondialog.h" +#include "ui_sessionform.h" +#include <QFile> +#include <QFileDialog> +#include <QToolButton> +#include <QStyle> + +SessionDialog::SessionDialog(QWidget *parent) +    : QDialog(parent) +    , ui(new Ui::SessionDialog) +{ +    ui->setupUi(this); +    ui->open->setIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)); + +    auto *browser = qobject_cast<Browser *>(qApp); +    Q_CHECK_PTR(browser); + +    for(const QString &path : Util::files(browser->configuration("browser.session.path"), { "*.json" })) { +        auto *item = new QListWidgetItem(ui->listWidget); +        auto *widget = new SessionForm(path, this); +        connect(widget->ui->delete_toolButton, &QToolButton::clicked, this, [item, widget]() { +            delete item; +            delete widget; +        }); +        ui->listWidget->setItemWidget(item, widget); +    } + +#ifdef QT_DEBUG +    ui->listWidget->addItem(tr("Start new session")); +#endif + +    connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *currentItem, QListWidgetItem *previousItem) { +        auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(currentItem)); +        if(currentWidget) +            currentWidget->ui->delete_toolButton->show(); + +        auto *previousWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(previousItem)); +        if(previousWidget) +            previousWidget->ui->delete_toolButton->hide(); +    }); + +    connect(ui->open, &QPushButton::clicked, this, [this]() { +        const QString filename = QFileDialog::getOpenFileName(this, tr("Select Session file"), QDir::homePath(), tr("JSON (*.json)")); +        if(!filename.isEmpty()) { +            this->openSession(filename); +            // close the dialog window; reject so it doesn't open another session +            this->reject(); +        } +    }); + +    connect(this, &SessionDialog::accepted, this, [this]() { +        auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem())); +        if(currentWidget) +            this->openSession(currentWidget->ui->label->text()); +    }); +} + +SessionDialog::~SessionDialog() +{ +    delete ui; +} + +void SessionDialog::openSession(const QString &filename) +{ +    auto *browser = qobject_cast<Browser *>(qApp); +    Q_CHECK_PTR(browser); + +    QFile json(filename); +    if(json.open(QIODevice::ReadOnly | QIODevice::Text)) { +        auto *browser = qobject_cast<Browser *>(qApp); +        auto doc = QJsonDocument::fromJson(json.readAll()); +        browser->createSession(doc.object()); +        json.close(); +    } +} diff --git a/src/session/sessiondialog.h b/src/session/sessiondialog.h new file mode 100644 index 0000000..7fea3c2 --- /dev/null +++ b/src/session/sessiondialog.h @@ -0,0 +1,34 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef SMOLBOTE_SESSIONDIALOG_H +#define SMOLBOTE_SESSIONDIALOG_H + +#include <QDialog> + +namespace Ui +{ +class SessionDialog; +} + +class SessionDialog : public QDialog +{ +    Q_OBJECT + +public: +    explicit SessionDialog(QWidget *parent = nullptr); +    ~SessionDialog() override; + +private: +    void openSession(const QString &filename); + +private: +    Ui::SessionDialog *ui; +}; + +#endif // SMOLBOTE_SESSIONDIALOG_H diff --git a/src/session/sessiondialog.ui b/src/session/sessiondialog.ui new file mode 100644 index 0000000..3a61dc1 --- /dev/null +++ b/src/session/sessiondialog.ui @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SessionDialog</class> + <widget class="QDialog" name="SessionDialog"> +  <property name="geometry"> +   <rect> +    <x>0</x> +    <y>0</y> +    <width>1000</width> +    <height>600</height> +   </rect> +  </property> +  <property name="windowTitle"> +   <string>Select Session</string> +  </property> +  <layout class="QVBoxLayout" name="verticalLayout"> +   <item> +    <layout class="QHBoxLayout" name="horizontalLayout"> +     <item> +      <widget class="QLabel" name="label"> +       <property name="text"> +        <string>Filter</string> +       </property> +      </widget> +     </item> +     <item> +      <widget class="QLineEdit" name="lineEdit"> +       <property name="placeholderText"> +        <string>Search</string> +       </property> +      </widget> +     </item> +    </layout> +   </item> +   <item> +    <widget class="QListWidget" name="listWidget"/> +   </item> +   <item> +    <layout class="QHBoxLayout" name="horizontalLayout_2"> +     <item> +      <widget class="QPushButton" name="open"> +       <property name="text"> +        <string>Open from File</string> +       </property> +      </widget> +     </item> +     <item> +      <widget class="QDialogButtonBox" name="buttonBox"> +       <property name="orientation"> +        <enum>Qt::Horizontal</enum> +       </property> +       <property name="standardButtons"> +        <set>QDialogButtonBox::Close|QDialogButtonBox::Open</set> +       </property> +      </widget> +     </item> +    </layout> +   </item> +  </layout> + </widget> + <resources/> + <connections> +  <connection> +   <sender>buttonBox</sender> +   <signal>accepted()</signal> +   <receiver>SessionDialog</receiver> +   <slot>accept()</slot> +   <hints> +    <hint type="sourcelabel"> +     <x>248</x> +     <y>254</y> +    </hint> +    <hint type="destinationlabel"> +     <x>157</x> +     <y>274</y> +    </hint> +   </hints> +  </connection> +  <connection> +   <sender>buttonBox</sender> +   <signal>rejected()</signal> +   <receiver>SessionDialog</receiver> +   <slot>reject()</slot> +   <hints> +    <hint type="sourcelabel"> +     <x>316</x> +     <y>260</y> +    </hint> +    <hint type="destinationlabel"> +     <x>286</x> +     <y>274</y> +    </hint> +   </hints> +  </connection> + </connections> +</ui> diff --git a/src/session/sessionform.cpp b/src/session/sessionform.cpp new file mode 100644 index 0000000..761cb42 --- /dev/null +++ b/src/session/sessionform.cpp @@ -0,0 +1,36 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "sessionform.h" +#include "ui_sessionform.h" +#include <QStyle> + +SessionForm::SessionForm(const QString &path, QWidget *parent) +    : QWidget(parent) +    , ui(new Ui::SessionForm) +{ +    ui->setupUi(this); +    ui->label->setText(path); +    ui->delete_toolButton->setIcon(style()->standardIcon(QStyle::SP_TrashIcon)); +    ui->delete_toolButton->hide(); +} + +SessionForm::~SessionForm() +{ +    delete ui; +} + +void SessionForm::showDetails() +{ +    ui->delete_toolButton->show(); +} + +void SessionForm::hideDetails() +{ +    ui->delete_toolButton->hide(); +} diff --git a/src/session/sessionform.h b/src/session/sessionform.h new file mode 100644 index 0000000..5e5f52e --- /dev/null +++ b/src/session/sessionform.h @@ -0,0 +1,37 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef SMOLBOTE_SESSIONFORM_H +#define SMOLBOTE_SESSIONFORM_H + +#include <QWidget> + +namespace Ui +{ +class SessionForm; +} + +class SessionForm : public QWidget +{ +    Q_OBJECT + +    friend class SessionDialog; + +public: +    explicit SessionForm(const QString &path, QWidget *parent = nullptr); +    ~SessionForm() override; + +public slots: +    void showDetails(); +    void hideDetails(); + +private: +    Ui::SessionForm *ui; +}; + +#endif // SMOLBOTE_SESSIONFORM_H diff --git a/src/session/sessionform.ui b/src/session/sessionform.ui new file mode 100644 index 0000000..dbf0237 --- /dev/null +++ b/src/session/sessionform.ui @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SessionForm</class> + <widget class="QWidget" name="SessionForm"> +  <property name="geometry"> +   <rect> +    <x>0</x> +    <y>0</y> +    <width>711</width> +    <height>34</height> +   </rect> +  </property> +  <property name="windowTitle"> +   <string>Form</string> +  </property> +  <layout class="QHBoxLayout" name="horizontalLayout"> +   <property name="topMargin"> +    <number>0</number> +   </property> +   <property name="bottomMargin"> +    <number>0</number> +   </property> +   <item> +    <widget class="QLabel" name="label"> +     <property name="text"> +      <string>TextLabel</string> +     </property> +    </widget> +   </item> +   <item> +    <widget class="QToolButton" name="delete_toolButton"> +     <property name="text"> +      <string>...</string> +     </property> +    </widget> +   </item> +  </layout> + </widget> + <resources/> + <connections/> +</ui>  | 
