From f21b9a2daf257e7485a5a4712f74e333164801ea Mon Sep 17 00:00:00 2001 From: Felanbird <41973452+Felanbird@users.noreply.github.com> Date: Sun, 17 Mar 2024 20:07:53 -0400 Subject: [PATCH] Revert "Show line indicator instead of rectangle while dragging in tables" (#5255) This reverts commit 0322d37650c9b5b3b644ecb22f9c1e54b619bef0. --- CHANGELOG.md | 1 - src/CMakeLists.txt | 2 - src/widgets/helper/EditableModelView.cpp | 3 -- src/widgets/helper/TableStyles.cpp | 66 ------------------------ src/widgets/helper/TableStyles.hpp | 32 ------------ 5 files changed, 104 deletions(-) delete mode 100644 src/widgets/helper/TableStyles.cpp delete mode 100644 src/widgets/helper/TableStyles.hpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cac0b0f..56fd1309 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +49,6 @@ - Minor: Add permissions to experimental plugins feature. (#5231) - Minor: Added warning message if you have multiple commands with the same trigger. (#4322) - Minor: Add support to send /announce[color] commands. (#5250) -- Minor: Added drop indicator line while dragging in tables. (#5252) - Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840) - Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848) - Bugfix: Trimmed custom streamlink paths on all platforms making sure you don't accidentally add spaces at the beginning or end of its path. (#4834) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24853e75..ba5e85b4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -651,8 +651,6 @@ set(SOURCE_FILES widgets/helper/SettingsDialogTab.hpp widgets/helper/SignalLabel.cpp widgets/helper/SignalLabel.hpp - widgets/helper/TableStyles.cpp - widgets/helper/TableStyles.hpp widgets/helper/TitlebarButton.cpp widgets/helper/TitlebarButton.hpp widgets/helper/TitlebarButtons.cpp diff --git a/src/widgets/helper/EditableModelView.cpp b/src/widgets/helper/EditableModelView.cpp index cbc04c03..b549c9e9 100644 --- a/src/widgets/helper/EditableModelView.cpp +++ b/src/widgets/helper/EditableModelView.cpp @@ -1,7 +1,6 @@ #include "EditableModelView.hpp" #include "widgets/helper/RegExpItemDelegate.hpp" -#include "widgets/helper/TableStyles.hpp" #include #include @@ -29,8 +28,6 @@ EditableModelView::EditableModelView(QAbstractTableModel *model, bool movable) this->tableView_->verticalHeader()->setVisible(false); this->tableView_->horizontalHeader()->setSectionsClickable(false); - TableRowDragStyle::applyTo(this->tableView_); - // create layout QVBoxLayout *vbox = new QVBoxLayout(this); vbox->setContentsMargins(0, 0, 0, 0); diff --git a/src/widgets/helper/TableStyles.cpp b/src/widgets/helper/TableStyles.cpp deleted file mode 100644 index 27ace07a..00000000 --- a/src/widgets/helper/TableStyles.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "widgets/helper/TableStyles.hpp" - -#include -#include -#include -#include -#include - -namespace chatterino { - -TableRowDragStyle::TableRowDragStyle(QStyle *target) - : QProxyStyle(target) -{ -} - -void TableRowDragStyle::applyTo(QTableView *view) -{ - auto *proxyStyle = new TableRowDragStyle(view->style()); - proxyStyle->setParent(view); - view->setStyle(proxyStyle); -} - -void TableRowDragStyle::drawPrimitive(QStyle::PrimitiveElement element, - const QStyleOption *option, - QPainter *painter, - const QWidget *widget) const -{ - if (element != QStyle::PE_IndicatorItemViewItemDrop) - { - QProxyStyle::drawPrimitive(element, option, painter, widget); - return; - } - - const auto *view = dynamic_cast(widget); - if (!view) - { - assert(false && "TableStyle must be used on a QAbstractItemView"); - return; - } - - if (option->rect.isNull()) - { - return; - } - - // Get the direction a row is dragged in - auto selected = view->currentIndex(); - auto hovered = view->indexAt(option->rect.center()); - if (!selected.isValid() || !hovered.isValid()) - { - // This shouldn't happen as we're in a drag operation - assert(false && "Got bad indices"); - return; - } - - int y = option->rect.top(); // move up - if (hovered.row() >= selected.row()) - { - y = option->rect.bottom(); // move down - } - - painter->setPen({Qt::white, 2}); - painter->drawLine(0, y, widget->width(), y); -} - -} // namespace chatterino diff --git a/src/widgets/helper/TableStyles.hpp b/src/widgets/helper/TableStyles.hpp deleted file mode 100644 index c71d889d..00000000 --- a/src/widgets/helper/TableStyles.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -class QTableView; - -namespace chatterino { - -/// @brief A custom style for drag operations of rows on tables -/// -/// This style overwrites how `PE_IndicatorItemViewItemDrop`, the drop -/// indicator of item-views, is drawn. It's intended to be used on QTableViews -/// where entire rows are moved (not individual cells). The indicator is shown -/// as a line at the position where the dragged item should be inserted. If no -/// such position exists, a red border is drawn around the viewport. -class TableRowDragStyle : public QProxyStyle -{ -public: - /// Applies the style to @a view - static void applyTo(QTableView *view); - - void drawPrimitive(QStyle::PrimitiveElement element, - const QStyleOption *option, QPainter *painter, - const QWidget *widget = nullptr) const override; - -private: - /// @param target The style to wrap. This is **not** the parent of this - /// object. This object will become the parent of @a target. - TableRowDragStyle(QStyle *target); -}; - -} // namespace chatterino