feat: reimplement contextmenu
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
e786f2ea62
commit
6527604b93
@ -872,9 +872,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
|||||||
{
|
{
|
||||||
view = new InstanceView(ui->centralWidget, APPLICATION->instances().get());
|
view = new InstanceView(ui->centralWidget, APPLICATION->instances().get());
|
||||||
|
|
||||||
view->installEventFilter(this);
|
connect(view, &InstanceView::showContextMenu, this, &MainWindow::showInstanceContextMenu);
|
||||||
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
||||||
connect(view, &QWidget::customContextMenuRequested, this, &MainWindow::showInstanceContextMenu);
|
|
||||||
|
|
||||||
ui->horizontalLayout->addWidget(view);
|
ui->horizontalLayout->addWidget(view);
|
||||||
}
|
}
|
||||||
@ -1047,30 +1045,27 @@ void MainWindow::konamiTriggered()
|
|||||||
qDebug() << "Super Secret Mode ACTIVATED!";
|
qDebug() << "Super Secret Mode ACTIVATED!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
void MainWindow::showInstanceContextMenu(const QPoint &pos, InstancePtr inst)
|
||||||
{
|
{
|
||||||
QList<QAction *> actions;
|
QList<QAction *> actions;
|
||||||
|
|
||||||
QAction *actionSep = new QAction("", this);
|
QAction *actionSep = new QAction("", this);
|
||||||
actionSep->setSeparator(true);
|
actionSep->setSeparator(true);
|
||||||
|
|
||||||
bool onInstance = view->currentView()->indexAt(pos).isValid();
|
actions = ui->instanceToolBar->actions();
|
||||||
if (onInstance)
|
|
||||||
{
|
|
||||||
actions = ui->instanceToolBar->actions();
|
|
||||||
|
|
||||||
// replace the change icon widget with an actual action
|
// replace the change icon widget with an actual action
|
||||||
actions.replace(0, ui->actionChangeInstIcon);
|
actions.replace(0, ui->actionChangeInstIcon);
|
||||||
|
|
||||||
// replace the rename widget with an actual action
|
// replace the rename widget with an actual action
|
||||||
actions.replace(1, ui->actionRenameInstance);
|
actions.replace(1, ui->actionRenameInstance);
|
||||||
|
|
||||||
|
// add header
|
||||||
|
actions.prepend(actionSep);
|
||||||
|
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
|
||||||
|
actionVoid->setEnabled(false);
|
||||||
|
actions.prepend(actionVoid);
|
||||||
|
|
||||||
// add header
|
|
||||||
actions.prepend(actionSep);
|
|
||||||
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
|
|
||||||
actionVoid->setEnabled(false);
|
|
||||||
actions.prepend(actionVoid);
|
|
||||||
}
|
|
||||||
QMenu myMenu;
|
QMenu myMenu;
|
||||||
myMenu.addActions(actions);
|
myMenu.addActions(actions);
|
||||||
/*
|
/*
|
||||||
|
@ -164,7 +164,7 @@ private slots:
|
|||||||
*/
|
*/
|
||||||
void iconUpdated(QString);
|
void iconUpdated(QString);
|
||||||
|
|
||||||
void showInstanceContextMenu(const QPoint &);
|
void showInstanceContextMenu(const QPoint &pos, InstancePtr inst);
|
||||||
|
|
||||||
void updateMainToolBar();
|
void updateMainToolBar();
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ void InstanceView::createTable() {
|
|||||||
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
|
connect(m_table, &QTableView::doubleClicked, this, &InstanceView::activateInstance);
|
||||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
|
connect(m_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstanceView::currentRowChanged);
|
||||||
connect(m_table->selectionModel(), &QItemSelectionModel::currentColumnChanged, this, &InstanceView::selectNameColumn);
|
connect(m_table->selectionModel(), &QItemSelectionModel::currentColumnChanged, this, &InstanceView::selectNameColumn);
|
||||||
|
connect(m_table, &QWidget::customContextMenuRequested, this, &InstanceView::contextMenuRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
InstancePtr InstanceView::currentInstance() {
|
InstancePtr InstanceView::currentInstance() {
|
||||||
@ -137,6 +138,16 @@ void InstanceView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InstanceView::contextMenuRequested(const QPoint pos) {
|
||||||
|
QModelIndex index = m_table->indexAt(pos);
|
||||||
|
|
||||||
|
if (index.isValid()) {
|
||||||
|
int row = mappedIndex(index).row();
|
||||||
|
InstancePtr inst = m_instances->at(row);
|
||||||
|
emit showContextMenu(m_table->mapToParent(pos), inst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const {
|
QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const {
|
||||||
return m_proxy->mapToSource(index);
|
return m_proxy->mapToSource(index);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void instanceActivated(InstancePtr inst);
|
void instanceActivated(InstancePtr inst);
|
||||||
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
void currentInstanceChanged(InstancePtr current, InstancePtr previous);
|
||||||
|
void showContextMenu(const QPoint pos, InstancePtr inst);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void activateInstance(const QModelIndex& index);
|
void activateInstance(const QModelIndex& index);
|
||||||
@ -51,6 +52,7 @@ private slots:
|
|||||||
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
void selectNameColumn(const QModelIndex& current, const QModelIndex& previous);
|
||||||
// emits currentRowChanged if a data update affected the current instance
|
// emits currentRowChanged if a data update affected the current instance
|
||||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||||
|
void contextMenuRequested(const QPoint pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createTable();
|
void createTable();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user