Better implementation, spacing now correct, drag&drop working.
Inputs tab still needs spaces converted to
This commit is contained in:
@@ -34,11 +34,12 @@ bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction
|
|||||||
QList<QVariant> lsVars;
|
QList<QVariant> lsVars;
|
||||||
lsVars = v.values();
|
lsVars = v.values();
|
||||||
QString itemString = lsVars.at(0).toString();
|
QString itemString = lsVars.at(0).toString();
|
||||||
qba.append(lsVars.last().toByteArray().mid(1));
|
qba.append(lsVars.at(1).toByteArray().mid(1));
|
||||||
qDebug() << "MixersList::dropMimeData() added data " << lsVars;
|
qDebug() << "MixersList::dropMimeData() added data " << lsVars.count() << lsVars;
|
||||||
if(itemString.isEmpty()) {};
|
if(itemString.isEmpty()) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << "MixersList::dropMimeData() qba.length() " << qba.length();
|
||||||
if(qba.length()>0)
|
if(qba.length()>0)
|
||||||
{
|
{
|
||||||
QMimeData *mimeData = new QMimeData;
|
QMimeData *mimeData = new QMimeData;
|
||||||
@@ -47,6 +48,7 @@ bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction
|
|||||||
else
|
else
|
||||||
mimeData->setData("application/x-companion-mix", qba);
|
mimeData->setData("application/x-companion-mix", qba);
|
||||||
|
|
||||||
|
qDebug() << "MixersList::dropMimeData() emit mimeDropped " << index << mimeData << action;
|
||||||
emit mimeDropped(index, mimeData, action);
|
emit mimeDropped(index, mimeData, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,115 +72,63 @@ void MixersList::mousePressEvent(QMouseEvent *event)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define QFIXED_MAX (INT_MAX/256)
|
|
||||||
|
|
||||||
QRect __textLayoutBounds(const QStyleOptionViewItemV2 &option)
|
#define ADDED_SPACE 20
|
||||||
{
|
|
||||||
QRect rect = option.rect;
|
|
||||||
const bool wrapText = option.features & QStyleOptionViewItemV2::WrapText;
|
|
||||||
switch (option.decorationPosition) {
|
|
||||||
case QStyleOptionViewItem::Left:
|
|
||||||
case QStyleOptionViewItem::Right:
|
|
||||||
rect.setWidth(wrapText && rect.isValid() ? rect.width() : (QFIXED_MAX));
|
|
||||||
break;
|
|
||||||
case QStyleOptionViewItem::Top:
|
|
||||||
case QStyleOptionViewItem::Bottom:
|
|
||||||
rect.setWidth(wrapText ? option.decorationSize.width() : (QFIXED_MAX));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MixersDelegate::paint(QPainter *painter,
|
void MixersDelegate::paint(QPainter *painter,
|
||||||
const QStyleOptionViewItem &option,
|
const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
//Q_D(const QItemDelegate);
|
QStyleOptionViewItemV4 options = option;
|
||||||
Q_ASSERT(index.isValid());
|
initStyleOption(&options, index);
|
||||||
|
|
||||||
QStyleOptionViewItemV4 opt = setOptions(index, option);
|
|
||||||
//qDebug() << "MixersDelegate::paint" << opt.rect;
|
|
||||||
|
|
||||||
const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
|
|
||||||
opt.features = v2 ? v2->features
|
|
||||||
: QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
|
|
||||||
const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
|
|
||||||
opt.locale = v3 ? v3->locale : QLocale();
|
|
||||||
opt.widget = v3 ? v3->widget : 0;
|
|
||||||
|
|
||||||
// prepare
|
|
||||||
painter->save();
|
|
||||||
if (false /*d->clipPainting*/)
|
|
||||||
painter->setClipRect(opt.rect);
|
|
||||||
|
|
||||||
// get the data and the rectangles
|
|
||||||
|
|
||||||
QVariant value;
|
|
||||||
|
|
||||||
|
|
||||||
QString text;
|
|
||||||
QRect displayRect;
|
|
||||||
value = index.data(Qt::DisplayRole);
|
|
||||||
if (value.isValid() && !value.isNull()) {
|
|
||||||
text = value.toString();
|
|
||||||
displayRect = textRectangle(painter, __textLayoutBounds(opt), opt.font, text);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect checkRect;
|
|
||||||
Qt::CheckState checkState = Qt::Unchecked;
|
|
||||||
value = index.data(Qt::CheckStateRole);
|
|
||||||
if (value.isValid()) {
|
|
||||||
checkState = static_cast<Qt::CheckState>(value.toInt());
|
|
||||||
checkRect = check(opt, opt.rect, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the layout
|
|
||||||
QRect dummy;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
doLayout(opt, &checkRect, &dummy, &displayRect, false);
|
|
||||||
|
|
||||||
// draw the item
|
|
||||||
|
|
||||||
drawBackground(painter, opt, index);
|
|
||||||
drawCheck(painter, opt, checkRect, checkState);
|
|
||||||
//drawDecoration(painter, opt, decorationRect, pixmap);
|
|
||||||
drawDisplay(painter, opt, displayRect, text);
|
|
||||||
drawFocus(painter, opt, displayRect);
|
|
||||||
|
|
||||||
// done
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MixersDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
|
||||||
const QRect &rect, const QString &text) const
|
|
||||||
{
|
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
QTextDocument doc;
|
QTextDocument doc;
|
||||||
doc.setHtml(text);
|
doc.setHtml(options.text);
|
||||||
doc.setDefaultFont(option.font);
|
doc.setDefaultFont(option.font);
|
||||||
|
|
||||||
painter->translate(rect.left(), rect.top());
|
options.text = "";
|
||||||
QRect clip(0, 0, rect.width(), rect.height());
|
options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
|
||||||
doc.drawContents(painter, clip);
|
|
||||||
|
if ( index.model()->data(index, Qt::UserRole + 2).toInt() > 0 ) {
|
||||||
|
//qDebug() << "MixersDelegate::sizeHint() detected channel head";
|
||||||
|
painter->translate(options.rect.left(), options.rect.top() + ADDED_SPACE);
|
||||||
|
QRect clip(0, 0, options.rect.width(), options.rect.height() - ADDED_SPACE);
|
||||||
|
doc.drawContents(painter, clip);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
painter->translate(options.rect.left(), options.rect.top());
|
||||||
|
QRect clip(0, 0, options.rect.width(), options.rect.height());
|
||||||
|
doc.drawContents(painter, clip);
|
||||||
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
// {
|
{
|
||||||
// QStyleOptionViewItemV4 options = option;
|
QStyleOptionViewItemV4 options = option;
|
||||||
// initStyleOption(&options, index);
|
initStyleOption(&options, index);
|
||||||
|
|
||||||
// QTextDocument doc;
|
QTextDocument doc;
|
||||||
// doc.setHtml(options.text);
|
doc.setHtml(options.text);
|
||||||
// doc.setDefaultFont(option.font);
|
doc.setDefaultFont(option.font);
|
||||||
// doc.setTextWidth(options.rect.width());
|
doc.setTextWidth(options.rect.width());
|
||||||
// return QSize(doc.idealWidth(), doc.size().height());
|
|
||||||
// }
|
//qDebug() << "MixersDelegate::sizeHint() UserRole-> " << index.model()->data(index, Qt::UserRole + 2);
|
||||||
|
|
||||||
|
int height = doc.size().height();
|
||||||
|
if ( index.model()->data(index, Qt::UserRole + 2).toInt() > 0 ) {
|
||||||
|
//qDebug() << "MixersDelegate::sizeHint() detected channel head";
|
||||||
|
height = doc.size().height() + ADDED_SPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//qDebug() << "MixersDelegate::sizeHint() options.rect " << options.rect;
|
||||||
|
//qDebug() << "MixersDelegate::sizeHint() result " << QSize(doc.idealWidth(), height);
|
||||||
|
|
||||||
|
return QSize(doc.idealWidth(), height);
|
||||||
|
}
|
||||||
@@ -27,16 +27,14 @@ class MixersList : public QListWidget
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MixersDelegate : public QItemDelegate
|
class MixersDelegate : public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
inline MixersDelegate(QObject *parent) : QItemDelegate(parent) {}
|
inline MixersDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
||||||
|
|
||||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
const QRect &rect, const QString &text) const ;
|
|
||||||
//QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -106,9 +106,10 @@ bool MixesPanel::AddMixerLine(int dest, const MixData * md)
|
|||||||
#if MIX_ROW_HEIGHT_INCREASE > 0
|
#if MIX_ROW_HEIGHT_INCREASE > 0
|
||||||
if ((new_ch && (dest > 0)) || (dest < 0)) {
|
if ((new_ch && (dest > 0)) || (dest < 0)) {
|
||||||
//increase size of this row
|
//increase size of this row
|
||||||
QFontMetrics * fm = new QFontMetrics(itm->font());
|
//QFontMetrics * fm = new QFontMetrics(itm->font());
|
||||||
QRect rect = fm->boundingRect("C)");
|
//QRect rect = fm->boundingRect("C)");
|
||||||
itm->setSizeHint(QSize(-1, (rect.height() * (14+MIX_ROW_HEIGHT_INCREASE))/10));
|
//itm->setSizeHint(QSize(-1, (rect.height() * (14+MIX_ROW_HEIGHT_INCREASE))/10));
|
||||||
|
itm->setData(Qt::UserRole+2, 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
MixerlistWidget->addItem(itm);
|
MixerlistWidget->addItem(itm);
|
||||||
@@ -211,7 +212,7 @@ QString MixesPanel::getMixerText(int dest, bool * new_ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str.replace(" ", " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MixesPanel::gm_insertMix(int idx)
|
bool MixesPanel::gm_insertMix(int idx)
|
||||||
|
|||||||
Reference in New Issue
Block a user