mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 12:45:36 +00:00
Create a context menu handler for dialogue editors with ID information
This commit is contained in:
parent
2cd62e19d8
commit
efed2556be
2 changed files with 93 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include "../../model/world/nestedtableproxymodel.hpp"
|
#include "../../model/world/nestedtableproxymodel.hpp"
|
||||||
#include "../../model/world/columnbase.hpp"
|
#include "../../model/world/columnbase.hpp"
|
||||||
|
@ -314,6 +315,74 @@ CSVWorld::DialogueDelegateDispatcher::~DialogueDelegateDispatcher()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CSVWorld::IdContextMenu::IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Display display)
|
||||||
|
: QObject(widget),
|
||||||
|
mWidget(widget),
|
||||||
|
mIdType(CSMWorld::TableMimeData::convertEnums(display))
|
||||||
|
{
|
||||||
|
Q_ASSERT(mWidget != NULL);
|
||||||
|
Q_ASSERT(CSMWorld::ColumnBase::isId(display));
|
||||||
|
Q_ASSERT(mIdType != CSMWorld::UniversalId::Type_None);
|
||||||
|
|
||||||
|
mWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(mWidget,
|
||||||
|
SIGNAL(customContextMenuRequested(const QPoint &)),
|
||||||
|
this,
|
||||||
|
SLOT(showContextMenu(const QPoint &)));
|
||||||
|
|
||||||
|
mEditIdAction = new QAction(this);
|
||||||
|
|
||||||
|
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget);
|
||||||
|
if (lineEdit != NULL)
|
||||||
|
{
|
||||||
|
mContextMenu = lineEdit->createStandardContextMenu();
|
||||||
|
mContextMenu->setParent(mWidget);
|
||||||
|
|
||||||
|
QAction *action = mContextMenu->actions().first();
|
||||||
|
mContextMenu->insertAction(action, mEditIdAction);
|
||||||
|
mContextMenu->insertSeparator(action);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mContextMenu = new QMenu(mWidget);
|
||||||
|
mContextMenu->addAction(mEditIdAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CSVWorld::IdContextMenu::getWidgetValue() const
|
||||||
|
{
|
||||||
|
static QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget);
|
||||||
|
static QLabel *label = qobject_cast<QLabel *>(mWidget);
|
||||||
|
|
||||||
|
QString value = "";
|
||||||
|
if (lineEdit != NULL)
|
||||||
|
{
|
||||||
|
value = lineEdit->text();
|
||||||
|
}
|
||||||
|
else if (label != NULL)
|
||||||
|
{
|
||||||
|
value = label->text();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::IdContextMenu::showContextMenu(const QPoint &pos)
|
||||||
|
{
|
||||||
|
QString value = getWidgetValue();
|
||||||
|
if (!value.isEmpty())
|
||||||
|
{
|
||||||
|
mEditIdAction->setText("Edit '" + value + "'");
|
||||||
|
|
||||||
|
QAction *selectedAction = mContextMenu->exec(mWidget->mapToGlobal(pos));
|
||||||
|
if (selectedAction != NULL && selectedAction == mEditIdAction)
|
||||||
|
{
|
||||||
|
CSMWorld::UniversalId editId(mIdType, value.toUtf8().constData());
|
||||||
|
emit editIdRequest(editId, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
=============================================================EditWidget=====================================================
|
=============================================================EditWidget=====================================================
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,12 +11,14 @@
|
||||||
|
|
||||||
#include "../../model/world/columnbase.hpp"
|
#include "../../model/world/columnbase.hpp"
|
||||||
#include "../../model/world/commanddispatcher.hpp"
|
#include "../../model/world/commanddispatcher.hpp"
|
||||||
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
class QDataWidgetMapper;
|
class QDataWidgetMapper;
|
||||||
class QSize;
|
class QSize;
|
||||||
class QEvent;
|
class QEvent;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
|
@ -149,6 +151,28 @@ namespace CSVWorld
|
||||||
CSMWorld::ColumnBase::Display display);
|
CSMWorld::ColumnBase::Display display);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IdContextMenu : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QWidget *mWidget;
|
||||||
|
CSMWorld::UniversalId::Type mIdType;
|
||||||
|
|
||||||
|
QMenu *mContextMenu;
|
||||||
|
QAction *mEditIdAction;
|
||||||
|
|
||||||
|
QString getWidgetValue() const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Display display);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void showContextMenu(const QPoint &pos);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint);
|
||||||
|
};
|
||||||
|
|
||||||
class EditWidget : public QScrollArea
|
class EditWidget : public QScrollArea
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
Loading…
Reference in a new issue