Move Image Uploader settings to the new tab

This commit is contained in:
Mm2PL 2023-12-02 01:35:37 +01:00
parent a0551ce41a
commit 097eb7ba79
No known key found for this signature in database
GPG key ID: 94AC9B80EFA15ED9
2 changed files with 95 additions and 90 deletions

View file

@ -100,51 +100,6 @@ ExternalToolsPage::ExternalToolsPage()
lineEdit->setPlaceholderText("custom-player-scheme://"); lineEdit->setPlaceholderText("custom-player-scheme://");
groupLayout->addRow("Custom stream player URI Scheme:", lineEdit); groupLayout->addRow("Custom stream player URI Scheme:", lineEdit);
} }
layout->addSpacing(16);
{
auto group = layout.emplace<QGroupBox>("Image Uploader");
auto groupLayout = group.setLayoutType<QFormLayout>();
const auto description = new QLabel(
"You can set custom host for uploading images, like "
"imgur.com or s-ul.eu.<br>Check " +
formatRichNamedLink("https://chatterino.com/help/image-uploader",
"this guide") +
" for help.");
description->setWordWrap(true);
description->setStyleSheet("color: #bbb");
description->setTextFormat(Qt::RichText);
description->setTextInteractionFlags(Qt::TextBrowserInteraction |
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByMouse);
description->setOpenExternalLinks(true);
groupLayout->setWidget(0, QFormLayout::SpanningRole, description);
groupLayout->addRow(this->createCheckBox(
"Enable image uploader", getSettings()->imageUploaderEnabled));
groupLayout->addRow(
this->createCheckBox("Ask for confirmation when uploading an image",
getSettings()->askOnImageUpload));
groupLayout->addRow(
"Request URL: ",
this->createLineEdit(getSettings()->imageUploaderUrl));
groupLayout->addRow(
"Form field: ",
this->createLineEdit(getSettings()->imageUploaderFormField));
groupLayout->addRow(
"Extra Headers: ",
this->createLineEdit(getSettings()->imageUploaderHeaders));
groupLayout->addRow(
"Image link: ",
this->createLineEdit(getSettings()->imageUploaderLink));
groupLayout->addRow(
"Deletion link: ",
this->createLineEdit(getSettings()->imageUploaderDeletionLink));
}
layout->addStretch(1); layout->addStretch(1);
} }

View file

@ -3,15 +3,19 @@
#include "Application.hpp" #include "Application.hpp"
#include "singletons/imageuploader/ImageUploader.hpp" #include "singletons/imageuploader/ImageUploader.hpp"
#include "singletons/imageuploader/UploadedImageModel.hpp" #include "singletons/imageuploader/UploadedImageModel.hpp"
#include "singletons/Settings.hpp"
#include "util/Helpers.hpp"
#include "util/LayoutCreator.hpp" #include "util/LayoutCreator.hpp"
#include "widgets/helper/EditableModelView.hpp" #include "widgets/helper/EditableModelView.hpp"
#include "widgets/listview/ImagePtrItemDelegate.hpp" #include "widgets/listview/ImagePtrItemDelegate.hpp"
#include <QBoxLayout> #include <QBoxLayout>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFormLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QPushButton> #include <QPushButton>
#include <QTableView> #include <QTableView>
#include <QTabWidget>
#include <QUrl> #include <QUrl>
namespace chatterino { namespace chatterino {
@ -20,64 +24,110 @@ ImageUploaderPage::ImageUploaderPage()
: imgDelegate_(new ImagePtrItemDelegate()) : imgDelegate_(new ImagePtrItemDelegate())
{ {
LayoutCreator<ImageUploaderPage> layoutCreator(this); LayoutCreator<ImageUploaderPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>(); auto tabs = layoutCreator.emplace<QTabWidget>();
auto *model = getApp()->imageUploader->createModel(nullptr); {
//EditableModelView *view = auto layout = tabs.appendTab(new QVBoxLayout, "Logs");
// layout.emplace<EditableModelView>(model).getElement();
auto container = layout.emplace<QVBoxLayout>(); auto *model = getApp()->imageUploader->createModel(nullptr);
container->setContentsMargins(0, 0, 0, 0);
auto buttons = container.emplace<QHBoxLayout>(); auto container = layout.emplace<QVBoxLayout>();
auto *forget = buttons.emplace<QPushButton>().getElement(); container->setContentsMargins(0, 0, 0, 0);
forget->setText("Remove image from log");
buttons->addStretch();
auto *view = layout.emplace<QTableView>().getElement(); auto buttons = container.emplace<QHBoxLayout>();
view->setModel(model); auto *forget = buttons.emplace<QPushButton>().getElement();
forget->setText("Remove image from log");
buttons->addStretch();
view->setItemDelegateForColumn(0, this->imgDelegate_); auto *view = layout.emplace<QTableView>().getElement();
view->setSelectionMode(QAbstractItemView::SingleSelection); view->setModel(model);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); view->setItemDelegateForColumn(0, this->imgDelegate_);
model->setHeaderData(0, Qt::Horizontal, "Image (double click to open)", view->setSelectionMode(QAbstractItemView::SingleSelection);
Qt::DisplayRole); view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->horizontalHeader()->setSectionResizeMode( view->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
1, QHeaderView::ResizeToContents); model->setHeaderData(0, Qt::Horizontal, "Image (double click to open)",
model->setHeaderData(1, Qt::Horizontal, "Date uploaded", Qt::DisplayRole); Qt::DisplayRole);
view->horizontalHeader()->setSectionResizeMode( view->horizontalHeader()->setSectionResizeMode(
2, QHeaderView::ResizeToContents); 1, QHeaderView::ResizeToContents);
model->setHeaderData(2, Qt::Horizontal, "Delete link", Qt::DisplayRole); model->setHeaderData(1, Qt::Horizontal, "Date uploaded",
Qt::DisplayRole);
view->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Interactive); view->horizontalHeader()->setSectionResizeMode(
model->setHeaderData(3, Qt::Horizontal, "Path", Qt::DisplayRole); 2, QHeaderView::ResizeToContents);
model->setHeaderData(2, Qt::Horizontal, "Delete link", Qt::DisplayRole);
QObject::connect(forget, &QPushButton::pressed, this, [view, model]() { view->horizontalHeader()->setSectionResizeMode(
auto selected = view->selectionModel()->selectedRows(0); 3, QHeaderView::Interactive);
std::vector<int> rows; model->setHeaderData(3, Qt::Horizontal, "Path", Qt::DisplayRole);
for (auto &&index : selected)
{
rows.push_back(index.row());
}
std::sort(rows.begin(), rows.end(), std::greater{}); QObject::connect(forget, &QPushButton::pressed, this, [view, model]() {
auto selected = view->selectionModel()->selectedRows(0);
std::vector<int> rows;
for (auto &&index : selected)
{
rows.push_back(index.row());
}
for (auto &&row : rows) std::sort(rows.begin(), rows.end(), std::greater{});
{
model->removeRow(row); for (auto &&row : rows)
} {
getApp()->imageUploader->save(); model->removeRow(row);
}); }
QObject::connect( getApp()->imageUploader->save();
view, &QTableView::doubleClicked, [](const QModelIndex &clicked) {
auto url = clicked.data(UploadedImageModel::DOUBLE_CLICK_LINK_ROLE)
.toString();
QDesktopServices::openUrl(QUrl(url));
}); });
QObject::connect(
view, &QTableView::doubleClicked, [](const QModelIndex &clicked) {
auto url =
clicked.data(UploadedImageModel::DOUBLE_CLICK_LINK_ROLE)
.toString();
QDesktopServices::openUrl(QUrl(url));
});
}
{
auto groupLayout = tabs.appendTab(new QFormLayout, "Settings");
auto *description = new QLabel(
"You can set custom host for uploading images, like "
"imgur.com or s-ul.eu.<br>Check " +
formatRichNamedLink("https://chatterino.com/help/image-uploader",
"this guide") +
" for help.");
description->setWordWrap(true);
description->setStyleSheet("color: #bbb");
description->setTextFormat(Qt::RichText);
description->setTextInteractionFlags(Qt::TextBrowserInteraction |
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByMouse);
description->setOpenExternalLinks(true);
groupLayout->setWidget(0, QFormLayout::SpanningRole, description);
groupLayout->addRow(this->createCheckBox(
"Enable image uploader", getSettings()->imageUploaderEnabled));
groupLayout->addRow(
this->createCheckBox("Ask for confirmation when uploading an image",
getSettings()->askOnImageUpload));
groupLayout->addRow(
"Request URL: ",
this->createLineEdit(getSettings()->imageUploaderUrl));
groupLayout->addRow(
"Form field: ",
this->createLineEdit(getSettings()->imageUploaderFormField));
groupLayout->addRow(
"Extra Headers: ",
this->createLineEdit(getSettings()->imageUploaderHeaders));
groupLayout->addRow(
"Image link: ",
this->createLineEdit(getSettings()->imageUploaderLink));
groupLayout->addRow(
"Deletion link: ",
this->createLineEdit(getSettings()->imageUploaderDeletionLink));
}
} }
ImageUploaderPage::~ImageUploaderPage() ImageUploaderPage::~ImageUploaderPage()