Merge element-picker into shortcut-bar (search results drag fix)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-27 01:59:59 +12:00
3 changed files with 47 additions and 4 deletions
@@ -55,6 +55,32 @@
#include <QStatusBar>
#include <QLineEdit>
namespace {
/**
@brief The SearchResultsView class
The flat list of search results. Rows are not backed by the collection
model, so the drag is built here from the path each row carries, with
the same content and pixmap as a drag from the tree.
*/
class SearchResultsView : public QListView
{
public:
using QListView::QListView;
protected:
void startDrag(Qt::DropActions supportedActions) override
{
const QString path =
currentIndex().data(Qt::UserRole + 2).toString();
if (path.isEmpty()) {
QListView::startDrag(supportedActions);
return;
}
ElementsTreeView::execElementDrag(this, ElementsLocation(path));
}
};
}
/**
@brief ElementsCollectionWidget::ElementsCollectionWidget
Default constructor.
@@ -230,8 +256,9 @@ void ElementsCollectionWidget::setUpWidget()
//ranked list instead, and takes the tab widget's place while a search
//is active.
m_search_model = new QStandardItemModel(this);
m_search_results = new QListView(this);
m_search_results = new SearchResultsView(this);
m_search_results->setModel(m_search_model);
m_search_results->setDragDropMode(QAbstractItemView::DragOnly);
m_search_results->setIconSize(QSize(50, 50));
m_search_results->setUniformItemSizes(false);
m_search_results->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
@@ -82,13 +82,27 @@ void ElementsTreeView::startDrag(Qt::DropActions supportedActions)
@param location : location to use for create the content of the QDrag
*/
void ElementsTreeView::startElementDrag(const ElementsLocation &location)
{
execElementDrag(this, location);
}
/**
@brief ElementsTreeView::execElementDrag
Build and run the QDrag for @a location, from @a source.
Static so that a view which is not an ElementsTreeView -- the flat list
of search results -- starts exactly the same drag as the tree.
@param source : the widget the drag starts from
@param location : location to use for create the content of the QDrag
*/
void ElementsTreeView::execElementDrag(QWidget *source,
const ElementsLocation &location)
{
if (! location.exist()) return;
#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
QDrag* drag = new QDrag(this);
QDrag* drag = new QDrag(source);
#else
QScopedPointer<QDrag> drag(new QDrag(this));
QScopedPointer<QDrag> drag(new QDrag(source));
#endif
QString location_str = location.toString();
@@ -209,7 +223,7 @@ void ElementsTreeView::startElementDrag(const ElementsLocation &location)
&elmt_creation_state));
if (elmt_creation_state) { return; }
QPixmap elmt_pixmap(QET::Palette::forPalette(temp_elmt->pixmap(), palette()));
QPixmap elmt_pixmap(QET::Palette::forPalette(temp_elmt->pixmap(), source->palette()));
QPoint elmt_hotspot(temp_elmt->hotspot());
//Adjust the size of the pixmap if he is too big
@@ -32,6 +32,8 @@ class ElementsTreeView : public QTreeView
{
public:
ElementsTreeView(QWidget *parent = nullptr);
static void execElementDrag(QWidget *source,
const ElementsLocation &location);
protected:
void startDrag(Qt::DropActions supportedActions) override;