mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Add buttons on mapping layers
This commit is contained in:
@@ -49,6 +49,7 @@ public:
|
||||
static const int BOTTOM_TOOLBAR_ICON_SIZE = 32;
|
||||
static const int ZOOM_TOOLBAR_ICON_SIZE = 22;
|
||||
static const int ZOOM_TOOLBAR_BUTTON_SIZE = 32;
|
||||
static const int MAPPING_LIST_ICON_SIZE = 16;
|
||||
|
||||
// Style.
|
||||
static const QColor WHITE;
|
||||
|
||||
+65
-70
@@ -131,12 +131,13 @@ void MainWindow::handlePaintItemSelectionChanged()
|
||||
updateCanvases();
|
||||
}
|
||||
|
||||
void MainWindow::mappingItemSelectionChanged(const QModelIndex &index)
|
||||
void MainWindow::handleMappingItemSelectionChanged(const QModelIndex &index)
|
||||
{
|
||||
// Set current paint and mappings.
|
||||
uid mappingId = mappingListModel->getItemId(index);
|
||||
Mapping::ptr mapping = mappingManager->getMappingById(mappingId);
|
||||
uid paintId = mapping->getPaint()->getId();
|
||||
// Set current mapping and paint
|
||||
setCurrentMapping(mappingId);
|
||||
setCurrentPaint(paintId);
|
||||
// Enable some menus and buttons
|
||||
@@ -145,27 +146,34 @@ void MainWindow::mappingItemSelectionChanged(const QModelIndex &index)
|
||||
destinationCanvas->enableZoomToolBar(true);
|
||||
destinationMenu->setEnabled(true);
|
||||
|
||||
// // Update canvases.
|
||||
// updateCanvases();
|
||||
// Update canvases.
|
||||
updateCanvases();
|
||||
}
|
||||
|
||||
void MainWindow::handleMappingItemChanged(const QModelIndex &index)
|
||||
{
|
||||
// Toggle visibility of mapping depending on checkbox of item.
|
||||
uid mappingId = mappingListModel->getItemId(index);
|
||||
setMappingVisible(mappingId, index.data(Qt::CheckStateRole) == Qt::Checked);
|
||||
// Toggle visibility of mapping depending on checkbox of item.
|
||||
setMappingVisible(mappingId, index.data(Qt::CheckStateRole).toBool());
|
||||
// Toggle mapping solo mode
|
||||
setMappingSolo(mappingId, index.data(Qt::CheckStateRole + 1).toBool());
|
||||
// Toggle mapping lock state
|
||||
setMappingLocked(mappingId, index.data(Qt::CheckStateRole + 2).toBool());
|
||||
// Set mapping name if changed
|
||||
renameMapping(mappingId, index.data(Qt::EditRole).toString());
|
||||
}
|
||||
|
||||
void MainWindow::handleMappingIndexesMoved()
|
||||
{
|
||||
// Reorder mappings.
|
||||
//QVector<uid> newOrder;
|
||||
for (int row=mappingList->model()->rowCount()-1; row>=0; row--)
|
||||
{
|
||||
//uid layerId = mappingList->item(row)->data(Qt::UserRole).toInt();
|
||||
//newOrder.push_back(layerId);
|
||||
}
|
||||
//mappingManager->reorderMappings(newOrder);
|
||||
// QVector<uid> newOrder;
|
||||
// for (int row=mappingListModel->rowCount()-1; row>=0; row--)
|
||||
// {
|
||||
// uid layerId = mappingListModel->index(row, 0).data(Qt::UserRole).toInt();
|
||||
// //mappingList->item(row)->data(Qt::UserRole).toInt();
|
||||
// newOrder.push_back(layerId);
|
||||
// }
|
||||
// mappingManager->reorderMappings(newOrder);
|
||||
|
||||
// Update canvases according to new order.
|
||||
updateCanvases();
|
||||
@@ -747,10 +755,9 @@ void MainWindow::deleteMappingItem()
|
||||
void MainWindow::renameMappingItem()
|
||||
{
|
||||
// Set current item editable and rename it
|
||||
// QListWidgetItem* item = mappingList->currentItem();
|
||||
// item->setFlags(item->flags() | Qt::ItemIsEditable);
|
||||
QModelIndex index = mappingList->currentIndex();
|
||||
// // Used by context menu
|
||||
// mappingList->editItem(item);
|
||||
mappingList->edit(index);
|
||||
// Switch to mapping tab.
|
||||
contentTab->setCurrentWidget(mappingSplitter);
|
||||
}
|
||||
@@ -772,17 +779,10 @@ void MainWindow::setMappingItemSolo(bool solo)
|
||||
|
||||
void MainWindow::renameMapping(uid mappingId, const QString &name)
|
||||
{
|
||||
// Mapping::ptr mapping = mappingManager->getMappingById(mappingId);
|
||||
// if (!mapping.isNull()) {
|
||||
// getItemFromId(*mappingList, mappingId)->setText(name);
|
||||
// mapping->setName(name);
|
||||
// }
|
||||
}
|
||||
|
||||
void MainWindow::mappingListEditEnd(QWidget *editor)
|
||||
{
|
||||
QString name = reinterpret_cast<QLineEdit*>(editor)->text();
|
||||
renameMapping(currentMappingItemId(), name);
|
||||
Mapping::ptr mapping = mappingManager->getMappingById(mappingId);
|
||||
if (!mapping.isNull()) {
|
||||
mapping->setName(name);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::deletePaintItem()
|
||||
@@ -847,8 +847,7 @@ bool MainWindow::clearProject()
|
||||
removeCurrentMapping();
|
||||
|
||||
// Empty list widgets.
|
||||
for (int i = 0; i < mappingList->model()->rowCount(); i++)
|
||||
mappingList->model()->removeRow(i);
|
||||
mappingListModel->clear();
|
||||
paintList->clear();
|
||||
|
||||
// Clear property panel.
|
||||
@@ -1132,8 +1131,8 @@ void MainWindow::setMappingVisible(uid mappingId, bool visible)
|
||||
{
|
||||
mapping->setVisible(visible);
|
||||
// Change list item check state
|
||||
//QModelIndex index = mappingListModel->getIndexFromId(mappingId);
|
||||
//mappingListModel->setData(index, visible, Qt::CheckStateRole);
|
||||
QModelIndex index = mappingListModel->getIndexFromId(mappingId);
|
||||
mappingListModel->setData(index, visible, Qt::CheckStateRole);
|
||||
// Update canvases.
|
||||
updateCanvases();
|
||||
}
|
||||
@@ -1145,6 +1144,9 @@ void MainWindow::setMappingSolo(uid mappingId, bool solo)
|
||||
if (!mapping.isNull()) {
|
||||
// Turn this mapping into solo mode
|
||||
mapping->setSolo(solo);
|
||||
// Change list item check state
|
||||
QModelIndex index = mappingListModel->getIndexFromId(mappingId);
|
||||
mappingListModel->setData(index, solo, Qt::CheckStateRole + 1);
|
||||
// Update canvases
|
||||
updateCanvases();
|
||||
}
|
||||
@@ -1159,6 +1161,9 @@ void MainWindow::setMappingLocked(uid mappingId, bool locked)
|
||||
mapping->setLocked(locked);
|
||||
// Lock shape too.
|
||||
mapping->getShape()->setLocked(locked);
|
||||
// Change list item check state
|
||||
QModelIndex index = mappingListModel->getIndexFromId(mappingId);
|
||||
mappingListModel->setData(index, locked, Qt::CheckStateRole + 2);
|
||||
// Update canvases
|
||||
updateCanvases();
|
||||
}
|
||||
@@ -1286,15 +1291,15 @@ void MainWindow::createLayout()
|
||||
mappingList->setMinimumHeight(MAPPING_LIST_MINIMUM_HEIGHT);
|
||||
mappingList->setContentsMargins(0, 0, 0, 0);
|
||||
// Set view delegate
|
||||
mappingList->setItemDelegate(new MappingItemDelegate(this));
|
||||
mappingListModel = new MappingListModel(this);
|
||||
mappingListModel = new MappingListModel;
|
||||
mappingItemDelegate = new MappingItemDelegate;
|
||||
mappingList->setModel(mappingListModel);
|
||||
mappingList->setItemDelegate(mappingItemDelegate);
|
||||
// Pimp Mapping table widget
|
||||
mappingList->horizontalHeader()->setStretchLastSection(true);
|
||||
mappingList->horizontalHeader()->setHighlightSections(false);
|
||||
mappingList->setFrameShape(QFrame::NoFrame);
|
||||
mappingList->horizontalHeader()->setVisible(false);
|
||||
mappingList->verticalHeader()->setVisible(false);
|
||||
mappingList->setShowGrid(false);
|
||||
mappingList->horizontalHeader()->hide();
|
||||
mappingList->verticalHeader()->hide();
|
||||
mappingList->setMouseTracking(true);// Important
|
||||
|
||||
// Create property panel.
|
||||
@@ -1517,7 +1522,6 @@ void MainWindow::createActions()
|
||||
// Lock mapping.
|
||||
mappingLockedAction = new QAction(tr("Lock mapping"), this);
|
||||
mappingLockedAction->setToolTip(tr("Lock mapping item"));
|
||||
mappingLockedAction->setIconVisibleInMenu(false);
|
||||
mappingLockedAction->setCheckable(true);
|
||||
mappingLockedAction->setChecked(false);
|
||||
addAction(mappingLockedAction);
|
||||
@@ -1526,7 +1530,6 @@ void MainWindow::createActions()
|
||||
// Mute mapping.
|
||||
mappingMuteAction = new QAction(tr("Mute mapping"), this);
|
||||
mappingMuteAction->setToolTip(tr("Mute mapping item"));
|
||||
mappingMuteAction->setIconVisibleInMenu(false);
|
||||
mappingMuteAction->setCheckable(true);
|
||||
mappingMuteAction->setChecked(false);
|
||||
addAction(mappingMuteAction);
|
||||
@@ -1535,7 +1538,6 @@ void MainWindow::createActions()
|
||||
// Solo mapping.
|
||||
mappingSoloAction = new QAction(tr("Solo mapping"), this);
|
||||
mappingSoloAction->setToolTip(tr("solo mapping item"));
|
||||
mappingSoloAction->setIconVisibleInMenu(false);
|
||||
mappingSoloAction->setCheckable(true);
|
||||
mappingSoloAction->setChecked(false);
|
||||
addAction(mappingSoloAction);
|
||||
@@ -1543,14 +1545,13 @@ void MainWindow::createActions()
|
||||
|
||||
// Delete paint.
|
||||
deletePaintAction = new QAction(tr("Delete paint"), this);
|
||||
//deletePaintAction->setShortcut(tr("CTRL+DEL"));
|
||||
deletePaintAction->setShortcut(tr("CTRL+DEL"));
|
||||
deletePaintAction->setToolTip(tr("Delete item"));
|
||||
deletePaintAction->setIconVisibleInMenu(false);
|
||||
connect(deletePaintAction, SIGNAL(triggered()), this, SLOT(deletePaintItem()));
|
||||
|
||||
// Rename paint.
|
||||
renamePaintAction = new QAction(tr("Rename"), this);
|
||||
//renamePaintAction->setShortcut(Qt::Key_F2);
|
||||
renamePaintAction->setShortcut(Qt::Key_F2);
|
||||
renamePaintAction->setToolTip(tr("Rename item"));
|
||||
renamePaintAction->setIconVisibleInMenu(false);
|
||||
addAction(renamePaintAction);
|
||||
@@ -1829,12 +1830,10 @@ void MainWindow::createMappingContextMenu()
|
||||
mappingContextMenu->addAction(mappingSoloAction);
|
||||
|
||||
// Set context menu policy
|
||||
mappingList->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
destinationCanvas->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
outputWindow->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
// Context Menu Connexions
|
||||
connect(mappingList->horizontalHeader(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&)));
|
||||
connect(destinationCanvas, SIGNAL(shapeContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&)));
|
||||
connect(outputWindow->getCanvas(), SIGNAL(shapeContextMenuRequested(const QPoint&)), this, SLOT(showMappingContextMenu(const QPoint&)));
|
||||
}
|
||||
@@ -2435,16 +2434,18 @@ void MainWindow::removeMappingItem(uid mappingId)
|
||||
|
||||
|
||||
|
||||
// // Remove widget from mappingList.
|
||||
// QModelIndex index = getIndexFromId(*mappingListModel, mappingId);
|
||||
// //Q_ASSERT( row >= 0 );
|
||||
// QStandardItem* item = mappingListModel->itemFromIndex(index);
|
||||
// if (item == currentSelectedMappingItem)
|
||||
// currentSelectedMappingItem= NULL;
|
||||
// delete item;
|
||||
// Remove widget from mappingList.
|
||||
int row = mappingListModel->getItemRowFromId(mappingId);
|
||||
Q_ASSERT( row >= 0 );
|
||||
mappingListModel->removeItem(row);
|
||||
|
||||
// Update list.
|
||||
//mappingList->update();
|
||||
mappingListModel->updateModel();
|
||||
|
||||
int nextSelectedRow = row == mappingListModel->rowCount() ? row - 1 : row;
|
||||
QModelIndex index = mappingListModel->getIndexFromRow(nextSelectedRow);
|
||||
mappingList->selectionModel()->select(index, QItemSelectionModel::Select);
|
||||
mappingList->setCurrentIndex(index);
|
||||
|
||||
// Update everything.
|
||||
updateCanvases();
|
||||
@@ -2664,7 +2665,7 @@ void MainWindow::connectProjectWidgets()
|
||||
this, SLOT(paintListEditEnd(QWidget*)));
|
||||
|
||||
connect(mappingList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(mappingItemSelectionChanged(QModelIndex)));
|
||||
this, SLOT(handleMappingItemSelectionChanged(QModelIndex)));
|
||||
|
||||
connect(mappingListModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(handleMappingItemChanged(QModelIndex)));
|
||||
@@ -2678,14 +2679,12 @@ void MainWindow::connectProjectWidgets()
|
||||
// connect(mappingList, SIGNAL(indexesMoved(const QModelIndexList&)),
|
||||
// this, SLOT(handleMappingIndexesMoved()));
|
||||
|
||||
// connect(mappingList->model(), SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex &, int)),
|
||||
// connect(mappingListModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
|
||||
// this, SLOT(handleMappingIndexesMoved()));
|
||||
// // Rename mapping with double click
|
||||
// connect(mappingList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
// this, SLOT(renameMappingItem()));
|
||||
// // When finish to edit mapping item
|
||||
// connect(mappingList->itemDelegate(), SIGNAL(commitData(QWidget*)),
|
||||
// this, SLOT(mappingListEditEnd(QWidget*)));
|
||||
connect(mappingItemDelegate, SIGNAL(itemDuplicated(uid)),
|
||||
this, SLOT(duplicateMapping(uid)));
|
||||
connect(mappingItemDelegate, SIGNAL(itemRemoved(uid)),
|
||||
this, SLOT(deleteMapping(uid)));
|
||||
}
|
||||
|
||||
void MainWindow::disconnectProjectWidgets()
|
||||
@@ -2700,12 +2699,12 @@ void MainWindow::disconnectProjectWidgets()
|
||||
this, SLOT(handlePaintItemSelected(QListWidgetItem*)));
|
||||
|
||||
disconnect(mappingList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(mappingItemSelectionChanged(QModelIndex)));
|
||||
this, SLOT(handleMappingItemSelectionChanged(QModelIndex)));
|
||||
|
||||
disconnect(mappingListModel, SIGNAL(itemChanged(QStandardItem*)),
|
||||
this, SLOT(handleMappingItemChanged(QStandardItem*)));
|
||||
disconnect(mappingListModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(handleMappingItemChanged(QModelIndex)));
|
||||
|
||||
disconnect(mappingList, SIGNAL(pressed(const QModelIndex&)),
|
||||
disconnect(mappingList, SIGNAL(pressed(QModelIndex)),
|
||||
this, SLOT(handleMappingItemSelected(const QModelIndex&)));
|
||||
|
||||
disconnect(mappingList, SIGNAL(activated(const QModelIndex&)),
|
||||
@@ -2717,9 +2716,6 @@ void MainWindow::disconnectProjectWidgets()
|
||||
disconnect(mappingList->model(), SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex &, int)),
|
||||
this, SLOT(handleMappingIndexesMoved()));
|
||||
|
||||
disconnect(mappingList, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
|
||||
this, SLOT(renameMappingItem()));
|
||||
|
||||
disconnect(mappingList->itemDelegate(), SIGNAL(commitData(QWidget*)),
|
||||
this, SLOT(mappingListEditEnd(QWidget*)));
|
||||
}
|
||||
@@ -2771,7 +2767,7 @@ QIcon MainWindow::createImageIcon(const QString& filename) {
|
||||
|
||||
uid MainWindow::currentMappingItemId() const
|
||||
{
|
||||
return mappingList->selectionModel()->selectedRows().first().data(Qt::UserRole).toInt();
|
||||
return mappingListModel->getItemId(currentSelectedIndex);
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentPaint(int uid)
|
||||
@@ -2795,8 +2791,7 @@ void MainWindow::setCurrentMapping(int uid)
|
||||
else {
|
||||
if (currentMappingId != uid) {
|
||||
currentMappingId = uid;
|
||||
currentSelectedIndex = mappingListModel->selectedIndex(mappingListModel->getItemRowFromId(uid));
|
||||
mappingList->selectionModel()->select(currentSelectedIndex, QItemSelectionModel::Select);
|
||||
currentSelectedIndex = mappingListModel->getIndexFromRow(mappingListModel->getItemRowFromId(uid));
|
||||
mappingList->setCurrentIndex(currentSelectedIndex);
|
||||
mappingPropertyPanel->setCurrentWidget(mappers[uid]->getPropertiesEditor());
|
||||
}
|
||||
|
||||
+2
-2
@@ -104,7 +104,6 @@ private slots:
|
||||
void setMappingitemLocked(bool locked);
|
||||
void setMappingitemVisible(bool visible);
|
||||
void setMappingItemSolo(bool solo);
|
||||
void mappingListEditEnd(QWidget* editor);
|
||||
// Context menu for paints
|
||||
void deletePaintItem();
|
||||
void renamePaintItem();
|
||||
@@ -113,7 +112,7 @@ private slots:
|
||||
// Widget callbacks.
|
||||
void handlePaintItemSelectionChanged();
|
||||
// void handleItemDoubleClicked(QListWidgetItem* item);
|
||||
void mappingItemSelectionChanged(const QModelIndex &index);
|
||||
void handleMappingItemSelectionChanged(const QModelIndex &index);
|
||||
void handleMappingItemChanged(const QModelIndex &index);
|
||||
void handleMappingIndexesMoved();
|
||||
void handlePaintItemSelected(QListWidgetItem* item);
|
||||
@@ -390,6 +389,7 @@ private:
|
||||
// Model.
|
||||
MappingManager* mappingManager;
|
||||
MappingListModel *mappingListModel;
|
||||
MappingItemDelegate *mappingItemDelegate;
|
||||
|
||||
// OSC.
|
||||
#ifdef HAVE_OSC
|
||||
|
||||
+51
-28
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* LayerItemDelegate.h
|
||||
* MppingItemDelegate.h
|
||||
*
|
||||
* (c) 2016 Dame Diongue -- baydamd(@)gmail(.)com
|
||||
* (c) 20MM::MAPPING_LIST_ICON_SIZE Dame Diongue -- baydamd(@)gmail(.)com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -43,14 +43,14 @@ void MappingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||
if (index.column() == MM::MuteColunm) {
|
||||
bool isVisible = index.model()->data(index, Qt::CheckStateRole).toBool();
|
||||
if (isVisible) {
|
||||
QStyleOptionButton mappingMuteButton;
|
||||
QStyleOptionToolButton mappingMuteButton;
|
||||
mappingMuteButton.state |= QStyle::State_Enabled;
|
||||
mappingMuteButton.rect = QRect(x + 7, y + 12, 16, 16);
|
||||
mappingMuteButton.rect = QRect(x + 4, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
mappingMuteButton.icon = QIcon(":/visible-mapping");
|
||||
mappingMuteButton.iconSize = QSize(16, 16);
|
||||
mappingMuteButton.iconSize = QSize(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
QApplication::style()->drawControl(
|
||||
QStyle::CE_PushButtonLabel, &mappingMuteButton, painter);
|
||||
QStyle::CE_ToolButtonLabel, &mappingMuteButton, painter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,38 +73,38 @@ void MappingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||
|
||||
if (index.column() == MM::GroupButtonColum) {
|
||||
// Draw Buttons
|
||||
QStyleOptionButton mappingSoloButton;
|
||||
QStyleOptionToolButton mappingSoloButton;
|
||||
mappingSoloButton.state |= QStyle::State_Enabled;
|
||||
mappingSoloButton.rect = QRect(x + 10, y + 12, 16, 16);
|
||||
mappingSoloButton.rect = QRect(x + 10, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
mappingSoloButton.icon = QIcon(":/solo-mapping");
|
||||
mappingSoloButton.iconSize = QSize(16, 16);
|
||||
mappingSoloButton.iconSize = QSize(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
QStyleOptionButton mappingLockButton;
|
||||
QStyleOptionToolButton mappingLockButton;
|
||||
mappingLockButton.state |= QStyle::State_Enabled;
|
||||
mappingLockButton.rect = QRect(x + 40, y + 12, 16, 16);
|
||||
mappingLockButton.rect = QRect(x + 40, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
mappingLockButton.icon = QIcon(":/lock-mapping");
|
||||
mappingLockButton.iconSize = QSize(16, 16);
|
||||
mappingLockButton.iconSize = QSize(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
QStyleOptionButton mappingDuplicateButton;
|
||||
QStyleOptionToolButton mappingDuplicateButton;
|
||||
mappingDuplicateButton.state |= QStyle::State_Enabled;
|
||||
mappingDuplicateButton.rect = QRect(x + 70, y + 12, 16, 16);
|
||||
mappingDuplicateButton.rect = QRect(x + 70, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
mappingDuplicateButton.icon = QIcon(":/duplicate-mapping");
|
||||
mappingDuplicateButton.iconSize = QSize(16, 16);
|
||||
mappingDuplicateButton.iconSize = QSize(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
QStyleOptionButton mappingDeleteButton;
|
||||
QStyleOptionToolButton mappingDeleteButton;
|
||||
mappingDeleteButton.state |= QStyle::State_Enabled;
|
||||
mappingDeleteButton.rect = QRect(x + 100, y + 12, 16, 16);
|
||||
mappingDeleteButton.rect = QRect(x + 100, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
mappingDeleteButton.icon = QIcon(":/delete-mapping");
|
||||
mappingDeleteButton.iconSize = QSize(16, 16);
|
||||
mappingDeleteButton.iconSize = QSize(MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
QApplication::style()->drawControl(
|
||||
QStyle::CE_PushButtonLabel, &mappingSoloButton, painter);
|
||||
QStyle::CE_ToolButtonLabel, &mappingSoloButton, painter);
|
||||
QApplication::style()->drawControl(
|
||||
QStyle::CE_PushButtonLabel, &mappingLockButton, painter);
|
||||
QStyle::CE_ToolButtonLabel, &mappingLockButton, painter);
|
||||
QApplication::style()->drawControl(
|
||||
QStyle::CE_PushButtonLabel, &mappingDuplicateButton, painter);
|
||||
QStyle::CE_ToolButtonLabel, &mappingDuplicateButton, painter);
|
||||
QApplication::style()->drawControl(
|
||||
QStyle::CE_PushButtonLabel, &mappingDeleteButton, painter);
|
||||
QStyle::CE_ToolButtonLabel, &mappingDeleteButton, painter);
|
||||
|
||||
}
|
||||
} else {
|
||||
@@ -114,7 +114,6 @@ void MappingItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
|
||||
|
||||
QWidget *MappingItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
qDebug() << "createEditor";
|
||||
if (index.column() == MM::IconAndNameColum) {
|
||||
QLineEdit *editor = new QLineEdit(parent);
|
||||
editor->setFixedHeight(option.rect.height());
|
||||
@@ -130,12 +129,10 @@ void MappingItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde
|
||||
|
||||
QLineEdit *nameEdit = static_cast<QLineEdit*>(editor); // TODO: use reinterpret_cast instead static_cast
|
||||
nameEdit->setText(value);
|
||||
qDebug() << "setEditorData";
|
||||
}
|
||||
|
||||
void MappingItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
qDebug() << "setModelData";
|
||||
QLineEdit *nameEdit = static_cast<QLineEdit*>(editor); // TODO: use reinterpret_cast instead static_cast
|
||||
model->setData(index, nameEdit->text(), Qt::EditRole);
|
||||
}
|
||||
@@ -148,10 +145,36 @@ void MappingItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOpti
|
||||
|
||||
bool MappingItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
|
||||
{
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
QRect rect = option.rect;
|
||||
int x = rect.x();
|
||||
int y = rect.y();
|
||||
|
||||
QRect soloButtonRect = QRect(x + 10, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
QRect lockButtonRect = QRect(x + 40, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
QRect duplicateButtonRect = QRect(x + 70, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
QRect deleteButtonRect = QRect(x + 100, y + 12, MM::MAPPING_LIST_ICON_SIZE, MM::MAPPING_LIST_ICON_SIZE);
|
||||
|
||||
if (event->type() == QEvent::MouseMove) {
|
||||
// TODO: handle tooltip
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
|
||||
if (index.column() == MM::GroupButtonColum)
|
||||
qDebug() << "Mouse pos" << mouseEvent->pos();
|
||||
|
||||
if (index.column() == MM::GroupButtonColum) {
|
||||
|
||||
if (soloButtonRect.contains(mouseEvent->pos()))
|
||||
model->setData(index, !(index.data(Qt::CheckStateRole + 1).toBool()), Qt::CheckStateRole + 1);
|
||||
|
||||
if (lockButtonRect.contains(mouseEvent->pos()))
|
||||
model->setData(index, !(index.data(Qt::CheckStateRole + 2).toBool()), Qt::CheckStateRole + 2);
|
||||
|
||||
if (duplicateButtonRect.contains(mouseEvent->pos()))
|
||||
emit itemDuplicated(index.data(Qt::UserRole).toInt());
|
||||
|
||||
if (deleteButtonRect.contains(mouseEvent->pos()))
|
||||
emit itemRemoved(index.data(Qt::UserRole).toInt());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+13
-6
@@ -26,10 +26,12 @@
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "MM.h"
|
||||
|
||||
typedef int uid;
|
||||
|
||||
class MappingItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -39,14 +41,19 @@ public:
|
||||
~MappingItemDelegate();
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const /*Q_DECL_OVERRIDE*/;
|
||||
const QModelIndex &index) const;
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const /*Q_DECL_OVERRIDE*/;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const /*Q_DECL_OVERRIDE*/;
|
||||
const QModelIndex &index) const;
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const /*Q_DECL_OVERRIDE*/;
|
||||
const QModelIndex &index) const;
|
||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const /*Q_DECL_OVERRIDE*/;
|
||||
const QModelIndex &index) const;
|
||||
|
||||
signals:
|
||||
void itemDuplicated(uid itemId);
|
||||
void itemRemoved(uid itemId);
|
||||
|
||||
protected:
|
||||
bool editorEvent(QEvent *event, QAbstractItemModel *model,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index);
|
||||
|
||||
+80
-58
@@ -45,55 +45,54 @@ QVariant MappingListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.column() == MM::MuteColunm) {
|
||||
|
||||
if (role == Qt::CheckStateRole)
|
||||
return mappingList.at(index.row()).isVisible ? Qt::Checked : Qt::Unchecked;
|
||||
|
||||
if (role == Qt::SizeHintRole)
|
||||
return QSize(30, 40);
|
||||
|
||||
} else {
|
||||
|
||||
if (role == Qt::EditRole || role == Qt::DisplayRole)
|
||||
return QVariant(mappingList.at(index.row()).name);
|
||||
|
||||
if (role == Qt::UserRole)
|
||||
return QVariant(mappingList.at(index.row()).id);
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
return mappingList.at(index.row()).icon;
|
||||
|
||||
if (role == Qt::SizeHintRole)
|
||||
return QSize(130, 40);
|
||||
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
return int(Qt::AlignVCenter);
|
||||
|
||||
switch (role) {
|
||||
case Qt::CheckStateRole:
|
||||
return mappingList.at(index.row()).isVisible ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
case Qt::SizeHintRole:
|
||||
if (index.column() == MM::MuteColunm)
|
||||
return QSize(20, 40);
|
||||
if (index.column() == MM::IconAndNameColum)
|
||||
return QSize(140, 40);
|
||||
break;
|
||||
case Qt::CheckStateRole + 1:
|
||||
return mappingList.at(index.row()).isSolo ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
case Qt::CheckStateRole + 2:
|
||||
return mappingList.at(index.row()).isLocked ? Qt::Checked : Qt::Unchecked;
|
||||
break;
|
||||
case Qt::UserRole:
|
||||
return QVariant(mappingList.at(index.row()).id);
|
||||
break;
|
||||
case Qt::EditRole:
|
||||
return QVariant(mappingList.at(index.row()).name);
|
||||
break;
|
||||
case Qt::DisplayRole:
|
||||
return QVariant(mappingList.at(index.row()).name);
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
return mappingList.at(index.row()).icon;
|
||||
break;
|
||||
default:
|
||||
return QVariant();
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant MappingListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
return QString::number(section);
|
||||
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
Qt::ItemFlags MappingListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
|
||||
if (index.column() == MM::MuteColunm)
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |
|
||||
Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;;
|
||||
if (index.column() == MM::IconAndNameColum)
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
|
||||
Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable |
|
||||
Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable |
|
||||
Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
bool MappingListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
@@ -102,15 +101,35 @@ bool MappingListModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
return false;
|
||||
|
||||
if (role == Qt::CheckStateRole && value.type() == QVariant::Bool) {
|
||||
mappingList[index.row()].isVisible = value.toBool();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
if (mappingList[index.row()].isVisible != value.toBool()) {
|
||||
mappingList[index.row()].isVisible = value.toBool();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (role == Qt::CheckStateRole + 1 && value.type() == QVariant::Bool) {
|
||||
if (mappingList[index.row()].isSolo != value.toBool()) {
|
||||
mappingList[index.row()].isSolo = value.toBool();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (role == Qt::CheckStateRole + 2 && value.type() == QVariant::Bool) {
|
||||
if (mappingList[index.row()].isLocked != value.toBool()) {
|
||||
mappingList[index.row()].isLocked = value.toBool();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (role == Qt::EditRole && index.column() == MM::IconAndNameColum) {
|
||||
mappingList[index.row()].name = value.toString();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
if (mappingList[index.row()].name != value.toString()) {
|
||||
mappingList[index.row()].name = value.toString();
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -129,6 +148,8 @@ void MappingListModel::addItem(const QIcon &icon, const QString &name, int id)
|
||||
item.icon = icon;
|
||||
item.name = name;
|
||||
item.isVisible = true;
|
||||
item.isLocked = false;
|
||||
item.isSolo = false;
|
||||
item.id = id;
|
||||
mappingList.insert(0, item);
|
||||
}
|
||||
@@ -139,36 +160,37 @@ void MappingListModel::updateModel()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QModelIndex MappingListModel::selectedIndex(int row)
|
||||
void MappingListModel::clear()
|
||||
{
|
||||
for (QList<MappingItem>::iterator it = mappingList.end() - 1;
|
||||
it >= mappingList.begin(); --it) {
|
||||
mappingList.erase(it);
|
||||
updateModel();
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex MappingListModel::getIndexFromRow(int row)
|
||||
{
|
||||
return this->createIndex(row, 1);
|
||||
}
|
||||
|
||||
void MappingListModel::setSelectedRow(int row)
|
||||
{
|
||||
selectedRow = row;
|
||||
}
|
||||
|
||||
int MappingListModel::getSelectedRow() const
|
||||
{
|
||||
return selectedRow;
|
||||
}
|
||||
|
||||
int MappingListModel::getItemRowFromId(int id) const
|
||||
int MappingListModel::getItemRowFromId(uid id) const
|
||||
{
|
||||
for ( int row = 0; row < mappingList.size(); row++) {
|
||||
int itemId = mappingList.at(row).id;
|
||||
if (itemId == id)
|
||||
return row;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
QModelIndex MappingListModel::getIndexFromId(int id) const
|
||||
QModelIndex MappingListModel::getIndexFromId(uid id) const
|
||||
{
|
||||
return this->createIndex(getItemRowFromId(id), 0);
|
||||
}
|
||||
|
||||
int MappingListModel::getItemId(const QModelIndex &index) const
|
||||
uid MappingListModel::getItemId(const QModelIndex &index) const
|
||||
{
|
||||
return mappingList.at(index.row()).id;
|
||||
}
|
||||
|
||||
+9
-10
@@ -28,6 +28,8 @@
|
||||
|
||||
#include "MM.h"
|
||||
|
||||
typedef int uid;
|
||||
|
||||
class MappingListModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -39,8 +41,6 @@ public:
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex & parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
@@ -49,13 +49,12 @@ public:
|
||||
void addItem(const QIcon &icon, const QString &name, int id);
|
||||
|
||||
void updateModel();
|
||||
QModelIndex selectedIndex(int row);
|
||||
void clear();
|
||||
|
||||
void setSelectedRow(int row);
|
||||
int getSelectedRow() const;
|
||||
int getItemRowFromId(int id) const;
|
||||
int getItemId(const QModelIndex &index) const;
|
||||
QModelIndex getIndexFromId(int id) const;
|
||||
QModelIndex getIndexFromRow(int row);
|
||||
int getItemRowFromId(uid id) const;
|
||||
uid getItemId(const QModelIndex &index) const;
|
||||
QModelIndex getIndexFromId(uid id) const;
|
||||
|
||||
public slots:
|
||||
void setVisibility(const QModelIndex &index);
|
||||
@@ -65,12 +64,12 @@ private:
|
||||
int id;
|
||||
QIcon icon;
|
||||
QString name;
|
||||
bool isLocked;
|
||||
bool isVisible;
|
||||
bool isSolo;
|
||||
};
|
||||
|
||||
QList<MappingItem> mappingList;
|
||||
|
||||
int selectedRow;
|
||||
};
|
||||
|
||||
#endif // MAPPINGLISTMODEL_H
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 784 B After Width: | Height: | Size: 863 B |
Binary file not shown.
|
Before Width: | Height: | Size: 612 B After Width: | Height: | Size: 686 B |
Reference in New Issue
Block a user