diff --git a/src/widgets/settingspages/ExternalToolsPage.cpp b/src/widgets/settingspages/ExternalToolsPage.cpp index 6fb615d93..d471911fe 100644 --- a/src/widgets/settingspages/ExternalToolsPage.cpp +++ b/src/widgets/settingspages/ExternalToolsPage.cpp @@ -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("Image Uploader"); - auto groupLayout = group.setLayoutType(); - - const auto description = new QLabel( - "You can set custom host for uploading images, like " - "imgur.com or s-ul.eu.
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); } diff --git a/src/widgets/settingspages/ImageUploaderPage.cpp b/src/widgets/settingspages/ImageUploaderPage.cpp index 04104d620..5460630f9 100644 --- a/src/widgets/settingspages/ImageUploaderPage.cpp +++ b/src/widgets/settingspages/ImageUploaderPage.cpp @@ -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 #include +#include #include #include #include +#include #include namespace chatterino { @@ -20,64 +24,110 @@ ImageUploaderPage::ImageUploaderPage() : imgDelegate_(new ImagePtrItemDelegate()) { LayoutCreator layoutCreator(this); - auto layout = layoutCreator.emplace(); + auto tabs = layoutCreator.emplace(); - auto *model = getApp()->imageUploader->createModel(nullptr); - //EditableModelView *view = - // layout.emplace(model).getElement(); + { + auto layout = tabs.appendTab(new QVBoxLayout, "Logs"); - auto container = layout.emplace(); - container->setContentsMargins(0, 0, 0, 0); + auto *model = getApp()->imageUploader->createModel(nullptr); - auto buttons = container.emplace(); - auto *forget = buttons.emplace().getElement(); - forget->setText("Remove image from log"); - buttons->addStretch(); + auto container = layout.emplace(); + container->setContentsMargins(0, 0, 0, 0); - auto *view = layout.emplace().getElement(); - view->setModel(model); + auto buttons = container.emplace(); + auto *forget = buttons.emplace().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().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 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 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.
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()