mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 09:45:21 +03:00
Working, but drawing is not perfect
This commit is contained in:
parent
1f6e5544b8
commit
3df9fcb67a
4 changed files with 170 additions and 11 deletions
|
@ -8,8 +8,10 @@ MixersList::MixersList(QWidget *parent, bool expo) :
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
setDragEnabled(true);
|
setDragEnabled(true);
|
||||||
setAcceptDrops(true);
|
//setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
|
viewport()->setAcceptDrops(true);
|
||||||
setDropIndicatorShown(true);
|
setDropIndicatorShown(true);
|
||||||
|
setItemDelegate(new MixersDelegate(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MixersList::keyPressEvent(QKeyEvent *event)
|
void MixersList::keyPressEvent(QKeyEvent *event)
|
||||||
|
@ -19,6 +21,7 @@ void MixersList::keyPressEvent(QKeyEvent *event)
|
||||||
|
|
||||||
bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction action )
|
bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction action )
|
||||||
{
|
{
|
||||||
|
qDebug() << "MixersList::dropMimeData() " << index << data->formats();
|
||||||
QByteArray dropData = data->data("application/x-qabstractitemmodeldatalist");
|
QByteArray dropData = data->data("application/x-qabstractitemmodeldatalist");
|
||||||
QDataStream stream(&dropData, QIODevice::ReadOnly);
|
QDataStream stream(&dropData, QIODevice::ReadOnly);
|
||||||
QByteArray qba;
|
QByteArray qba;
|
||||||
|
@ -31,8 +34,8 @@ 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.at(1).toByteArray().mid(1));
|
qba.append(lsVars.last().toByteArray().mid(1));
|
||||||
|
qDebug() << "MixersList::dropMimeData() added data " << lsVars;
|
||||||
if(itemString.isEmpty()) {};
|
if(itemString.isEmpty()) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,3 +55,130 @@ bool MixersList::dropMimeData( int index, const QMimeData * data, Qt::DropAction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MixersList::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
qDebug() << "MixersList::mousePressEvent" ;
|
||||||
|
QListWidgetItem *item = currentItem();
|
||||||
|
if (item) {
|
||||||
|
qDebug() << "MixersList::mousePressEvent" << item->text();
|
||||||
|
}
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
//startPos = event->pos();
|
||||||
|
}
|
||||||
|
QListWidget::mousePressEvent(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define QFIXED_MAX (INT_MAX/256)
|
||||||
|
|
||||||
|
QRect __textLayoutBounds(const QStyleOptionViewItemV2 &option)
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
//Q_D(const QItemDelegate);
|
||||||
|
Q_ASSERT(index.isValid());
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
QTextDocument doc;
|
||||||
|
doc.setHtml(text);
|
||||||
|
doc.setDefaultFont(option.font);
|
||||||
|
|
||||||
|
painter->translate(rect.left(), rect.top());
|
||||||
|
QRect clip(0, 0, rect.width(), rect.height());
|
||||||
|
doc.drawContents(painter, clip);
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// QSize MixersDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
|
||||||
|
// {
|
||||||
|
// QStyleOptionViewItemV4 options = option;
|
||||||
|
// initStyleOption(&options, index);
|
||||||
|
|
||||||
|
// QTextDocument doc;
|
||||||
|
// doc.setHtml(options.text);
|
||||||
|
// doc.setDefaultFont(option.font);
|
||||||
|
// doc.setTextWidth(options.rect.width());
|
||||||
|
// return QSize(doc.idealWidth(), doc.size().height());
|
||||||
|
// }
|
|
@ -22,6 +22,23 @@ class MixersList : public QListWidget
|
||||||
QPoint dragStartPosition;
|
QPoint dragStartPosition;
|
||||||
bool expo;
|
bool expo;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MixersDelegate : public QItemDelegate
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
inline MixersDelegate(QObject *parent) : QItemDelegate(parent) {}
|
||||||
|
|
||||||
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
|
||||||
|
const QRect &rect, const QString &text) const ;
|
||||||
|
//QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // MIXERSLIST_H
|
#endif // MIXERSLIST_H
|
||||||
|
|
|
@ -79,7 +79,7 @@ void MixesPanel::update()
|
||||||
curDest++;
|
curDest++;
|
||||||
AddMixerLine(-curDest);
|
AddMixerLine(-curDest);
|
||||||
}
|
}
|
||||||
if (AddMixerLine(i)) {
|
if (AddMixerLine(i, md)) {
|
||||||
curDest++;
|
curDest++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,12 +92,17 @@ void MixesPanel::update()
|
||||||
|
|
||||||
#define MIX_ROW_HEIGHT_INCREASE 8 //how much space is added above mixer row (for new channel), if 0 space adding is disabled
|
#define MIX_ROW_HEIGHT_INCREASE 8 //how much space is added above mixer row (for new channel), if 0 space adding is disabled
|
||||||
|
|
||||||
bool MixesPanel::AddMixerLine(int dest)
|
bool MixesPanel::AddMixerLine(int dest, const MixData * md)
|
||||||
{
|
{
|
||||||
bool new_ch;
|
bool new_ch;
|
||||||
QString str = getMixerText(dest, &new_ch);
|
QString str = getMixerText(dest, &new_ch);
|
||||||
QListWidgetItem *itm = new QListWidgetItem();
|
QListWidgetItem *itm = new QListWidgetItem();
|
||||||
itm->setData(Qt::UserRole, QByteArray(1, (quint8)dest));
|
QByteArray qba(1, (quint8)dest);
|
||||||
|
if (md) {
|
||||||
|
qba.append((const char*)md, sizeof(MixData));
|
||||||
|
//qDebug() << "appended mixdata for dest: " << dest;
|
||||||
|
}
|
||||||
|
itm->setData(Qt::UserRole, qba);
|
||||||
#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
|
||||||
|
@ -107,8 +112,11 @@ bool MixesPanel::AddMixerLine(int dest)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
MixerlistWidget->addItem(itm);
|
MixerlistWidget->addItem(itm);
|
||||||
MixerlistWidget->setItemWidget(itm, getMixerWidget(str));
|
itm->setText(str);
|
||||||
// qDebug() << "MixesPanel::AddMixerLine(): " << str;
|
// if ((new_ch && (dest > 0)) || (dest < 0)) {
|
||||||
|
// MixerlistWidget->setItemWidget(itm, getMixerWidget(str));
|
||||||
|
// }
|
||||||
|
//qDebug() << "MixesPanel::AddMixerLine(): " << str;
|
||||||
return new_ch;
|
return new_ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +129,8 @@ QWidget * MixesPanel::getMixerWidget(const QString & mixer_text)
|
||||||
QString formated_str(mixer_text);
|
QString formated_str(mixer_text);
|
||||||
formated_str.replace(" ", " ");
|
formated_str.replace(" ", " ");
|
||||||
l->setText(formated_str);
|
l->setText(formated_str);
|
||||||
|
l->setAcceptDrops(true);
|
||||||
|
//l->setAutoFillBackground(true);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +357,7 @@ void MixesPanel::mixersCopy()
|
||||||
|
|
||||||
void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx)
|
void MixesPanel::pasteMixerMimeData(const QMimeData * mimeData, int destIdx)
|
||||||
{
|
{
|
||||||
|
qDebug() << "void MixesPanel::pasteMixerMimeData" << mimeData->formats();
|
||||||
if(mimeData->hasFormat("application/x-companion-mix")) {
|
if(mimeData->hasFormat("application/x-companion-mix")) {
|
||||||
int idx; // mixer index
|
int idx; // mixer index
|
||||||
int dch;
|
int dch;
|
||||||
|
@ -427,8 +438,8 @@ void MixesPanel::mixerHighlight()
|
||||||
for(int i=0; i<MixerlistWidget->count(); i++) {
|
for(int i=0; i<MixerlistWidget->count(); i++) {
|
||||||
int t = MixerlistWidget->item(i)->data(Qt::UserRole).toByteArray().at(0);
|
int t = MixerlistWidget->item(i)->data(Qt::UserRole).toByteArray().at(0);
|
||||||
bool dummy;
|
bool dummy;
|
||||||
QWidget *w = getMixerWidget(getMixerText(t, &dummy));
|
//QWidget *w = getMixerWidget();
|
||||||
MixerlistWidget->setItemWidget(MixerlistWidget->item(i), w);
|
MixerlistWidget->item(i)->setText(getMixerText(t, &dummy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -483,6 +494,7 @@ void MixesPanel::mixerlistWidget_customContextMenuRequested(QPoint pos)
|
||||||
void MixesPanel::mimeMixerDropped(int index, const QMimeData *data, Qt::DropAction /*action*/)
|
void MixesPanel::mimeMixerDropped(int index, const QMimeData *data, Qt::DropAction /*action*/)
|
||||||
{
|
{
|
||||||
int idx= MixerlistWidget->item(index > 0 ? index-1 : 0)->data(Qt::UserRole).toByteArray().at(0);
|
int idx= MixerlistWidget->item(index > 0 ? index-1 : 0)->data(Qt::UserRole).toByteArray().at(0);
|
||||||
|
qDebug() << "MixesPanel::mimeMixerDropped()" << index << data;
|
||||||
pasteMixerMimeData(data, idx);
|
pasteMixerMimeData(data, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class MixesPanel : public ModelPanel
|
||||||
QList<int> createMixListFromSelected();
|
QList<int> createMixListFromSelected();
|
||||||
void setSelectedByMixList(QList<int> list);
|
void setSelectedByMixList(QList<int> list);
|
||||||
QString getChannelLabel(int curDest);
|
QString getChannelLabel(int curDest);
|
||||||
bool AddMixerLine(int dest);
|
bool AddMixerLine(int dest, const MixData * md = 0);
|
||||||
QString getMixerText(int dest, bool * new_ch);
|
QString getMixerText(int dest, bool * new_ch);
|
||||||
QWidget * getMixerWidget(const QString & mixer_text);
|
QWidget * getMixerWidget(const QString & mixer_text);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue