mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
Rework DropLineEdit. Make it type-sensitive
This commit is contained in:
parent
8aba52170f
commit
27ece7f36a
7 changed files with 143 additions and 50 deletions
|
@ -75,7 +75,7 @@ opencs_units_noqt (view/world
|
|||
|
||||
opencs_units (view/widget
|
||||
scenetoolbar scenetool scenetoolmode pushbutton scenetooltoggle scenetoolrun modebutton
|
||||
scenetooltoggle2 completerpopup coloreditor colorpickerpopup
|
||||
scenetooltoggle2 completerpopup coloreditor colorpickerpopup droplineedit
|
||||
)
|
||||
|
||||
opencs_units (view/render
|
||||
|
|
82
apps/opencs/view/widget/droplineedit.cpp
Normal file
82
apps/opencs/view/widget/droplineedit.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "droplineedit.hpp"
|
||||
|
||||
#include <QDropEvent>
|
||||
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
const CSMWorld::TableMimeData *getEventMimeData(QDropEvent *event)
|
||||
{
|
||||
Q_ASSERT(event != NULL);
|
||||
return dynamic_cast<const CSMWorld::TableMimeData *>(event->mimeData());
|
||||
}
|
||||
}
|
||||
|
||||
CSVWidget::DropLineEdit::DropLineEdit(QWidget *parent, CSMWorld::UniversalId::Type type)
|
||||
: QLineEdit(parent),
|
||||
mDropType(type)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void CSVWidget::DropLineEdit::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (canAcceptEventData(event))
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWidget::DropLineEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (canAcceptEventData(event))
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void CSVWidget::DropLineEdit::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const CSMWorld::TableMimeData *data = getEventMimeData(event);
|
||||
if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int dataIndex = getAcceptedDataIndex(*data);
|
||||
if (dataIndex != -1)
|
||||
{
|
||||
setText(data->getData()[dataIndex].getId().c_str());
|
||||
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
|
||||
}
|
||||
}
|
||||
|
||||
bool CSVWidget::DropLineEdit::canAcceptEventData(QDropEvent *event) const
|
||||
{
|
||||
const CSMWorld::TableMimeData *data = getEventMimeData(event);
|
||||
if (data == NULL) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return getAcceptedDataIndex(*data) != -1;
|
||||
}
|
||||
|
||||
int CSVWidget::DropLineEdit::getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const
|
||||
{
|
||||
if (mDropType == CSMWorld::UniversalId::Type_None)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::vector<CSMWorld::UniversalId> idData = data.getData();
|
||||
int size = static_cast<int>(idData.size());
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if (idData[i].getType() == mDropType)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
50
apps/opencs/view/widget/droplineedit.hpp
Normal file
50
apps/opencs/view/widget/droplineedit.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef CSV_WIDGET_DROPLINEEDIT_HPP
|
||||
#define CSV_WIDGET_DROPLINEEDIT_HPP
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class TableMimeData;
|
||||
}
|
||||
|
||||
namespace CSVWidget
|
||||
{
|
||||
class DropLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMWorld::UniversalId::Type mDropType;
|
||||
///< The accepted ID type for this LineEdit.
|
||||
///< If \a mDropType has Type_None type, this LineEdit accepts all ID types
|
||||
|
||||
bool canAcceptEventData(QDropEvent *event) const;
|
||||
///< Checks whether the \a event contains CSMWorld::TableMimeData with a proper ID type
|
||||
|
||||
int getAcceptedDataIndex(const CSMWorld::TableMimeData &data) const;
|
||||
///< Checks whether the \a data has a proper type
|
||||
///< \return -1 if there is no suitable data (ID type)
|
||||
|
||||
public:
|
||||
DropLineEdit(QWidget *parent = 0,
|
||||
CSMWorld::UniversalId::Type type = CSMWorld::UniversalId::Type_None);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
signals:
|
||||
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId> &data,
|
||||
const CSMDoc::Document *document);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -34,6 +34,7 @@
|
|||
#include "../../model/doc/document.hpp"
|
||||
|
||||
#include "../widget/coloreditor.hpp"
|
||||
#include "../widget/droplineedit.hpp"
|
||||
|
||||
#include "recordstatusdelegate.hpp"
|
||||
#include "util.hpp"
|
||||
|
@ -306,7 +307,7 @@ QWidget* CSVWorld::DialogueDelegateDispatcher::makeEditor(CSMWorld::ColumnBase::
|
|||
|
||||
// NOTE: For each entry in CSVWorld::CommandDelegate::createEditor() a corresponding entry
|
||||
// is required here
|
||||
if (qobject_cast<DropLineEdit*>(editor))
|
||||
if (qobject_cast<CSVWidget::DropLineEdit*>(editor))
|
||||
{
|
||||
connect(editor, SIGNAL(editingFinished()), proxy, SLOT(editorDataCommited()));
|
||||
|
||||
|
@ -850,7 +851,7 @@ void CSVWorld::DialogueSubView::tableMimeDataDropped (QWidget* editor,
|
|||
{
|
||||
if (document == &mDocument)
|
||||
{
|
||||
qobject_cast<DropLineEdit*>(editor)->setText(id.getId().c_str());
|
||||
qobject_cast<CSVWidget::DropLineEdit*>(editor)->setText(id.getId().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "../../model/world/idcompletionmanager.hpp"
|
||||
|
||||
#include "../widget/droplineedit.hpp"
|
||||
|
||||
CSVWorld::IdCompletionDelegate::IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||
CSMDoc::Document& document,
|
||||
QObject *parent)
|
||||
|
@ -26,7 +28,7 @@ QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent,
|
|||
}
|
||||
|
||||
CSMWorld::IdCompletionManager &completionManager = getDocument().getIdCompletionManager();
|
||||
DropLineEdit *editor = new DropLineEdit(parent);
|
||||
CSVWidget::DropLineEdit *editor = new CSVWidget::DropLineEdit(parent);
|
||||
editor->setCompleter(completionManager.getCompleter(display).get());
|
||||
return editor;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
#include "../../model/world/commands.hpp"
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
#include "../../model/world/commanddispatcher.hpp"
|
||||
|
||||
#include "../widget/coloreditor.hpp"
|
||||
#include "../widget/droplineedit.hpp"
|
||||
|
||||
#include "dialoguespinbox.hpp"
|
||||
#include "scriptedit.hpp"
|
||||
|
||||
|
@ -250,7 +253,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
|
|||
case CSMWorld::ColumnBase::Display_Video:
|
||||
case CSMWorld::ColumnBase::Display_GlobalVariable:
|
||||
|
||||
return new DropLineEdit(parent);
|
||||
return new CSVWidget::DropLineEdit(parent);
|
||||
|
||||
case CSMWorld::ColumnBase::Display_ScriptLines:
|
||||
|
||||
|
@ -324,29 +327,3 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
CSVWorld::DropLineEdit::DropLineEdit(QWidget* parent) :
|
||||
QLineEdit(parent)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void CSVWorld::DropLineEdit::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void CSVWorld::DropLineEdit::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void CSVWorld::DropLineEdit::dropEvent(QDropEvent *event)
|
||||
{
|
||||
const CSMWorld::TableMimeData* data(dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData()));
|
||||
if (!data) // May happen when non-records (e.g. plain text) are dragged and dropped
|
||||
return;
|
||||
|
||||
emit tableMimeDataDropped(data->getData(), data->getDocumentPtr());
|
||||
//WIP
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "../../model/world/columnbase.hpp"
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
@ -91,24 +90,6 @@ namespace CSVWorld
|
|||
|
||||
};
|
||||
|
||||
class DropLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DropLineEdit(QWidget *parent);
|
||||
|
||||
private:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
signals:
|
||||
void tableMimeDataDropped(const std::vector<CSMWorld::UniversalId>& data, const CSMDoc::Document* document);
|
||||
};
|
||||
|
||||
///< \brief Use commands instead of manipulating the model directly
|
||||
class CommandDelegate : public QStyledItemDelegate
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue