mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Move Image Uploader settings to the new tab
This commit is contained in:
parent
a0551ce41a
commit
097eb7ba79
2 changed files with 95 additions and 90 deletions
|
@ -100,51 +100,6 @@ ExternalToolsPage::ExternalToolsPage()
|
|||
lineEdit->setPlaceholderText("custom-player-scheme://");
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,19 @@
|
|||
#include "Application.hpp"
|
||||
#include "singletons/imageuploader/ImageUploader.hpp"
|
||||
#include "singletons/imageuploader/UploadedImageModel.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
#include "widgets/helper/EditableModelView.hpp"
|
||||
#include "widgets/listview/ImagePtrItemDelegate.hpp"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QDesktopServices>
|
||||
#include <QFormLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QPushButton>
|
||||
#include <QTableView>
|
||||
#include <QTabWidget>
|
||||
#include <QUrl>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -20,64 +24,110 @@ ImageUploaderPage::ImageUploaderPage()
|
|||
: imgDelegate_(new ImagePtrItemDelegate())
|
||||
{
|
||||
LayoutCreator<ImageUploaderPage> layoutCreator(this);
|
||||
auto layout = layoutCreator.emplace<QVBoxLayout>();
|
||||
auto tabs = layoutCreator.emplace<QTabWidget>();
|
||||
|
||||
auto *model = getApp()->imageUploader->createModel(nullptr);
|
||||
//EditableModelView *view =
|
||||
// layout.emplace<EditableModelView>(model).getElement();
|
||||
{
|
||||
auto layout = tabs.appendTab(new QVBoxLayout, "Logs");
|
||||
|
||||
auto container = layout.emplace<QVBoxLayout>();
|
||||
container->setContentsMargins(0, 0, 0, 0);
|
||||
auto *model = getApp()->imageUploader->createModel(nullptr);
|
||||
|
||||
auto buttons = container.emplace<QHBoxLayout>();
|
||||
auto *forget = buttons.emplace<QPushButton>().getElement();
|
||||
forget->setText("Remove image from log");
|
||||
buttons->addStretch();
|
||||
auto container = layout.emplace<QVBoxLayout>();
|
||||
container->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
auto *view = layout.emplace<QTableView>().getElement();
|
||||
view->setModel(model);
|
||||
auto buttons = container.emplace<QHBoxLayout>();
|
||||
auto *forget = buttons.emplace<QPushButton>().getElement();
|
||||
forget->setText("Remove image from log");
|
||||
buttons->addStretch();
|
||||
|
||||
view->setItemDelegateForColumn(0, this->imgDelegate_);
|
||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
auto *view = layout.emplace<QTableView>().getElement();
|
||||
view->setModel(model);
|
||||
|
||||
view->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
model->setHeaderData(0, Qt::Horizontal, "Image (double click to open)",
|
||||
Qt::DisplayRole);
|
||||
view->setItemDelegateForColumn(0, this->imgDelegate_);
|
||||
view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
|
||||
view->horizontalHeader()->setSectionResizeMode(
|
||||
1, QHeaderView::ResizeToContents);
|
||||
model->setHeaderData(1, Qt::Horizontal, "Date uploaded", Qt::DisplayRole);
|
||||
view->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
model->setHeaderData(0, Qt::Horizontal, "Image (double click to open)",
|
||||
Qt::DisplayRole);
|
||||
|
||||
view->horizontalHeader()->setSectionResizeMode(
|
||||
2, QHeaderView::ResizeToContents);
|
||||
model->setHeaderData(2, Qt::Horizontal, "Delete link", Qt::DisplayRole);
|
||||
view->horizontalHeader()->setSectionResizeMode(
|
||||
1, QHeaderView::ResizeToContents);
|
||||
model->setHeaderData(1, Qt::Horizontal, "Date uploaded",
|
||||
Qt::DisplayRole);
|
||||
|
||||
view->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Interactive);
|
||||
model->setHeaderData(3, Qt::Horizontal, "Path", Qt::DisplayRole);
|
||||
view->horizontalHeader()->setSectionResizeMode(
|
||||
2, QHeaderView::ResizeToContents);
|
||||
model->setHeaderData(2, Qt::Horizontal, "Delete link", Qt::DisplayRole);
|
||||
|
||||
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());
|
||||
}
|
||||
view->horizontalHeader()->setSectionResizeMode(
|
||||
3, QHeaderView::Interactive);
|
||||
model->setHeaderData(3, Qt::Horizontal, "Path", Qt::DisplayRole);
|
||||
|
||||
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)
|
||||
{
|
||||
model->removeRow(row);
|
||||
}
|
||||
getApp()->imageUploader->save();
|
||||
});
|
||||
QObject::connect(
|
||||
view, &QTableView::doubleClicked, [](const QModelIndex &clicked) {
|
||||
auto url = clicked.data(UploadedImageModel::DOUBLE_CLICK_LINK_ROLE)
|
||||
.toString();
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
std::sort(rows.begin(), rows.end(), std::greater{});
|
||||
|
||||
for (auto &&row : rows)
|
||||
{
|
||||
model->removeRow(row);
|
||||
}
|
||||
getApp()->imageUploader->save();
|
||||
});
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue