[Companion][MixersListWidget] Enable multiple selection capability on Inputs and Mixes editors (closes #5029); Fix bug with custom style propagation; cosmetics.
This commit is contained in:
@@ -20,6 +20,14 @@
|
|||||||
|
|
||||||
#include "mixerslistwidget.h"
|
#include "mixerslistwidget.h"
|
||||||
|
|
||||||
|
#include <QAbstractTextDocumentLayout>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDropEvent>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QTextFrame>
|
||||||
|
|
||||||
#define GRP_IS_PARENT 0x01
|
#define GRP_IS_PARENT 0x01
|
||||||
#define GRP_HAS_SIBLING 0x02
|
#define GRP_HAS_SIBLING 0x02
|
||||||
#define GRP_HAS_DATA 0x04
|
#define GRP_HAS_DATA 0x04
|
||||||
@@ -44,14 +52,14 @@ MixersListWidget::MixersListWidget(QWidget * parent, bool expo) :
|
|||||||
|
|
||||||
setFont(defaultFont);
|
setFont(defaultFont);
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
setDragDropMode(QAbstractItemView::DragDrop);
|
setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
setDropIndicatorShown(true);
|
setDropIndicatorShown(true);
|
||||||
setItemDelegate(new MixersDelegate(this)); // set custom paint handler
|
setItemDelegate(new MixersDelegate(this)); // set custom paint handler
|
||||||
setStyle(new MixerItemViewProxyStyle(style())); // custom element style painter
|
setStyle(new MixerItemViewProxyStyle()); // custom element style painter
|
||||||
|
|
||||||
itemMimeFmt = (expo ? "application/x-companion-expo-item" : "application/x-companion-mix-item");
|
itemMimeFmt = (expo ? "application/x-companion-expo-item" : "application/x-companion-mix-item");
|
||||||
|
|
||||||
@@ -186,8 +194,7 @@ void MixersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
|||||||
options.text.clear();
|
options.text.clear();
|
||||||
|
|
||||||
QAbstractTextDocumentLayout::PaintContext ctx;
|
QAbstractTextDocumentLayout::PaintContext ctx;
|
||||||
if (options.widget)
|
ctx.palette = (options.widget ? options.widget->palette() : QApplication::palette("QListWidgetItem"));
|
||||||
ctx.palette = options.widget->palette();
|
|
||||||
|
|
||||||
QBrush brush = ((index.data(GroupIdRole).toUInt() % 2) ? ctx.palette.base() : ctx.palette.alternateBase());
|
QBrush brush = ((index.data(GroupIdRole).toUInt() % 2) ? ctx.palette.base() : ctx.palette.alternateBase());
|
||||||
options.backgroundBrush = brush;
|
options.backgroundBrush = brush;
|
||||||
@@ -206,17 +213,16 @@ void MixersDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
|||||||
QStyle * style = (options.widget ? options.widget->style() : QApplication::style());
|
QStyle * style = (options.widget ? options.widget->style() : QApplication::style());
|
||||||
style->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
|
style->drawControl(QStyle::CE_ItemViewItem, &options, painter, options.widget);
|
||||||
|
|
||||||
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &options);
|
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &options, options.widget);
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
// Workaround for buggy Linux native styles (https://github.com/opentx/opentx/issues/5633)
|
// Workaround for buggy Linux native styles (https://github.com/opentx/opentx/issues/5633)
|
||||||
if (options.widget && textRect.width() < options.widget->geometry().width() * 0.75f)
|
if (options.widget && textRect.width() < options.widget->geometry().width() / 2)
|
||||||
textRect.setWidth(options.widget->geometry().width());
|
textRect.setWidth(options.widget->geometry().width());
|
||||||
#endif
|
#endif
|
||||||
QRectF clipRect = textRect.translated(-textRect.topLeft());
|
ctx.clip = textRect.translated(-textRect.topLeft());
|
||||||
ctx.clip = clipRect;
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(textRect.topLeft());
|
painter->translate(textRect.topLeft());
|
||||||
painter->setClipRect(clipRect);
|
painter->setClipRect(ctx.clip);
|
||||||
doc.documentLayout()->draw(painter, ctx);
|
doc.documentLayout()->draw(painter, ctx);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,11 @@
|
|||||||
#ifndef _MIXERSLISTWIDGET_H_
|
#ifndef _MIXERSLISTWIDGET_H_
|
||||||
#define _MIXERSLISTWIDGET_H_
|
#define _MIXERSLISTWIDGET_H_
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QListWidget>
|
||||||
#include <QProxyStyle>
|
#include <QProxyStyle>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
class MixersListWidget : public QListWidget
|
class MixersListWidget : public QListWidget
|
||||||
{
|
{
|
||||||
@@ -78,9 +79,9 @@ class MixersDelegate : public QStyledItemDelegate
|
|||||||
class MixerItemViewProxyStyle: public QProxyStyle
|
class MixerItemViewProxyStyle: public QProxyStyle
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MixerItemViewProxyStyle(QStyle * style = 0) : QProxyStyle(style) {}
|
explicit MixerItemViewProxyStyle(QStyle * style = nullptr) : QProxyStyle(style) {}
|
||||||
|
|
||||||
void drawPrimitive(PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = 0) const;
|
virtual void drawPrimitive(PrimitiveElement element, const QStyleOption * option, QPainter * painter, const QWidget * widget = nullptr) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MIXERSLISTWIDGET_H_
|
#endif // _MIXERSLISTWIDGET_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user