Terrain texture brush frame

pull/440/head
Nelsson Huotari 7 years ago
parent 3197ebd8e7
commit 4ae75d1d20

@ -88,7 +88,7 @@ opencs_units (view/render
scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget
previewwidget editmode instancemode instanceselectionmode instancemovemode previewwidget editmode instancemode instanceselectionmode instancemovemode
orbitcameramode pathgridmode selectionmode pathgridselectionmode cameracontroller orbitcameramode pathgridmode selectionmode pathgridselectionmode cameracontroller
cellwater cellwater terraintexturemode
) )
opencs_units_noqt (view/render opencs_units_noqt (view/render

@ -21,6 +21,7 @@
#include "mask.hpp" #include "mask.hpp"
#include "cameracontroller.hpp" #include "cameracontroller.hpp"
#include "cellarrow.hpp" #include "cellarrow.hpp"
#include "terraintexturemode.hpp"
bool CSVRender::PagedWorldspaceWidget::adjustCells() bool CSVRender::PagedWorldspaceWidget::adjustCells()
{ {
@ -136,7 +137,7 @@ void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain shape editing"), new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain shape editing"),
"terrain-shape"); "terrain-shape");
tool->addButton ( tool->addButton (
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain texture editing"), new TerrainTextureMode (this, tool),
"terrain-texture"); "terrain-texture");
tool->addButton ( tool->addButton (
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain vertex paint editing"), new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain vertex paint editing"),

@ -0,0 +1,214 @@
// To-do: Getting Texture Id and Texture Filenames to base class Terraintexturemode
// To-do: Better data handling options for mBrushTexture
// To-do: loading texture bitmaps from virtual file system (vfs) for texture overlay icon
#include "terraintexturemode.hpp"
#include "editmode.hpp"
#include <string>
#include <QWidget>
#include <QIcon>
#include <QSpinBox>
#include <QGroupBox>
#include <QSlider>
#include <QEvent>
#include <QDropEvent>
#include <QButtonGroup>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDragEnterEvent>
#include <QDrag>
#include "../widget/modebutton.hpp"
#include "../widget/scenetoolbar.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/tablemimedata.hpp"
#include "pagedworldspacewidget.hpp"
CSVRender::BrushSizeControls::BrushSizeControls(const QString &title, QWidget *parent)
: QGroupBox(title, parent)
{
brushSizeSlider = new QSlider(Qt::Horizontal);
brushSizeSlider->setTickPosition(QSlider::TicksBothSides);
brushSizeSlider->setTickInterval(10);
brushSizeSlider->setSingleStep(1);
brushSizeSpinBox = new QSpinBox;
brushSizeSpinBox->setRange(1, 100);
brushSizeSpinBox->setSingleStep(1);
layoutSliderSize = new QHBoxLayout;
layoutSliderSize->addWidget(brushSizeSlider);
layoutSliderSize->addWidget(brushSizeSpinBox);
connect(brushSizeSlider, SIGNAL(valueChanged(int)), brushSizeSpinBox, SLOT(setValue(int)));
connect(brushSizeSpinBox, SIGNAL(valueChanged(int)), brushSizeSlider, SLOT(setValue(int)));
setLayout(layoutSliderSize);
}
CSVRender::TextureBrushButton::TextureBrushButton (const QIcon & icon, const QString & text, QWidget * parent)
: QPushButton(icon, text, parent)
{
}
CSVRender::TextureBrushWindow::TextureBrushWindow(WorldspaceWidget *worldspaceWidget, QWidget *parent)
: QFrame(parent, Qt::Popup), mWorldspaceWidget (worldspaceWidget)
{
mBrushTextureLabel = "Brush: " + mBrushTexture;
selectedBrush = new QLabel(QString::fromUtf8(mBrushTextureLabel.c_str()), this);
const std::string& iconPoint = ":scenetoolbar/brush-point";
const std::string& iconSquare = ":scenetoolbar/brush-square";
const std::string& iconCircle = ":scenetoolbar/brush-circle";
const std::string& iconCustom = ":scenetoolbar/brush-custom";
TextureBrushButton *buttonPoint = new TextureBrushButton(QIcon (QPixmap (iconPoint.c_str())), "", this);
TextureBrushButton *buttonSquare = new TextureBrushButton(QIcon (QPixmap (iconSquare.c_str())), "", this);
TextureBrushButton *buttonCircle = new TextureBrushButton(QIcon (QPixmap (iconCircle.c_str())), "", this);
TextureBrushButton *buttonCustom = new TextureBrushButton(QIcon (QPixmap (iconCustom.c_str())), "", this);
QVBoxLayout *layoutMain = new QVBoxLayout;
layoutMain->setSpacing(0);
QHBoxLayout *layoutHorizontal = new QHBoxLayout;
layoutHorizontal->setContentsMargins (QMargins (0, 0, 0, 0));
layoutHorizontal->setSpacing(0);
configureButtonInitialSettings(buttonPoint);
configureButtonInitialSettings(buttonSquare);
configureButtonInitialSettings(buttonCircle);
configureButtonInitialSettings(buttonCustom);
QButtonGroup* brushButtonGroup = new QButtonGroup(this);
brushButtonGroup->addButton(buttonPoint);
brushButtonGroup->addButton(buttonSquare);
brushButtonGroup->addButton(buttonCircle);
brushButtonGroup->addButton(buttonCustom);
brushButtonGroup->setExclusive(true);
layoutHorizontal->addWidget(buttonPoint);
layoutHorizontal->addWidget(buttonSquare);
layoutHorizontal->addWidget(buttonCircle);
layoutHorizontal->addWidget(buttonCustom);
horizontalGroupBox = new QGroupBox(tr(""));
horizontalGroupBox->setLayout(layoutHorizontal);
BrushSizeControls* sizeSliders = new BrushSizeControls(tr(""), this);
layoutMain->addWidget(horizontalGroupBox);
layoutMain->addWidget(sizeSliders);
layoutMain->addWidget(selectedBrush);
setLayout(layoutMain);
connect(parent, SIGNAL(passBrushTexture(std::string)), this, SLOT(getBrushTexture(std::string)));
}
void CSVRender::TextureBrushWindow::configureButtonInitialSettings(TextureBrushButton *button)
{
button->setSizePolicy (QSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed));
button->setContentsMargins (QMargins (0, 0, 0, 0));
button->setIconSize (QSize (48-6, 48-6));
button->setFixedSize (48, 48);
button->setAcceptDrops(true);
button->setCheckable(true);
}
void CSVRender::TextureBrushWindow::getBrushTexture(std::string brushTexture)
{
mBrushTexture = brushTexture;
mBrushTextureLabel = "Brush:" + mBrushTexture;
selectedBrush->setText(QString::fromUtf8(mBrushTextureLabel.c_str()));
}
CSVRender::TerrainTextureMode::TerrainTextureMode (WorldspaceWidget *worldspaceWidget, QWidget *parent)
: EditMode (worldspaceWidget, QIcon {":scenetoolbar/editing-terrain-texture"}, Mask_Terrain | Mask_Reference, "Terrain texture editing", parent)
, textureBrushWindow(new TextureBrushWindow(worldspaceWidget, this))
{
connect(parent, SIGNAL(passEvent(QDragEnterEvent*)), this, SLOT(handleDragEnterEvent(QDragEnterEvent*)));
connect(parent, SIGNAL(passEvent(QDropEvent*)), this, SLOT(handleDropEvent(QDropEvent*)));
}
void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar)
{
EditMode::activate(toolbar);
}
void CSVRender::TerrainTextureMode::deactivate(CSVWidget::SceneToolbar* toolbar)
{
EditMode::deactivate(toolbar);
}
void CSVRender::TerrainTextureMode::primarySelectPressed(const WorldspaceHitResult& hit)
{
QPoint position = QCursor::pos();
textureBrushWindow->move (position);
textureBrushWindow->show();
}
void CSVRender::TerrainTextureMode::secondarySelectPressed(const WorldspaceHitResult& hit)
{
}
bool CSVRender::TerrainTextureMode::primaryEditStartDrag (const QPoint& pos)
{
return false;
}
bool CSVRender::TerrainTextureMode::secondaryEditStartDrag (const QPoint& pos)
{
return false;
}
bool CSVRender::TerrainTextureMode::primarySelectStartDrag (const QPoint& pos)
{
return false;
}
bool CSVRender::TerrainTextureMode::secondarySelectStartDrag (const QPoint& pos)
{
return false;
}
void CSVRender::TerrainTextureMode::drag (const QPoint& pos, int diffX, int diffY, double speedFactor) {
}
void CSVRender::TerrainTextureMode::dragCompleted(const QPoint& pos) {
}
void CSVRender::TerrainTextureMode::dragAborted() {
}
void CSVRender::TerrainTextureMode::dragWheel (int diff, double speedFactor) {}
void CSVRender::TerrainTextureMode::handleDragEnterEvent (QDragEnterEvent *event) {
event->accept();
}
void CSVRender::TerrainTextureMode::handleDropEvent (QDropEvent *event) {
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped
return;
if (mime->holdsType (CSMWorld::UniversalId::Type_LandTexture))
{
const std::vector<CSMWorld::UniversalId> ids = mime->getData();
for (const CSMWorld::UniversalId& uid : ids)
{
mBrushTexture = uid.getId();
emit passBrushTexture(mBrushTexture);
}
}
}
void CSVRender::TerrainTextureMode::dragMoveEvent (QDragMoveEvent *event) {
}

@ -0,0 +1,108 @@
#ifndef CSV_RENDER_TERRAINTEXTUREMODE_H
#define CSV_RENDER_TERRAINTEXTUREMODE_H
#include "editmode.hpp"
#include <string>
#include <QWidget>
#include <QLabel>
#include <QSpinBox>
#include <QGroupBox>
#include <QSlider>
#include <QIcon>
#include <QFrame>
#include <QEvent>
#include <QHBoxLayout>
#include <QPushButton>
namespace CSVWidget
{
class SceneToolMode;
}
namespace CSVRender
{
class BrushSizeControls : public QGroupBox
{
Q_OBJECT
public:
BrushSizeControls(const QString &title, QWidget *parent);
private:
QSlider *brushSizeSlider;
QSpinBox *brushSizeSpinBox;
QHBoxLayout *layoutSliderSize;
};
class TextureBrushButton : public QPushButton
{
Q_OBJECT
public:
TextureBrushButton (const QIcon& icon, const QString& tooltip = "",
QWidget *parent = 0);
};
class TextureBrushWindow : public QFrame
{
Q_OBJECT
public:
TextureBrushWindow(WorldspaceWidget *worldspaceWidget, QWidget *parent = 0);
void configureButtonInitialSettings(TextureBrushButton *button);
private:
QLabel *selectedBrush;
QGroupBox *horizontalGroupBox;
int mButtonSize;
int mIconSize;
WorldspaceWidget *mWorldspaceWidget;
std::string mBrushTexture;
std::string mBrushTextureLabel;
public slots:
void getBrushTexture(std::string brushTexture);
};
class TerrainTextureMode : public EditMode
{
Q_OBJECT
public:
std::string mBrushTexture;
TerrainTextureMode(WorldspaceWidget*, QWidget* parent = nullptr);
void primarySelectPressed(const WorldspaceHitResult&);
void secondarySelectPressed(const WorldspaceHitResult&);
void activate(CSVWidget::SceneToolbar*);
void deactivate(CSVWidget::SceneToolbar*);
virtual bool primaryEditStartDrag (const QPoint& pos);
virtual bool secondaryEditStartDrag (const QPoint& pos);
virtual bool primarySelectStartDrag (const QPoint& pos);
virtual bool secondarySelectStartDrag (const QPoint& pos);
virtual void drag (const QPoint& pos, int diffX, int diffY, double speedFactor);
virtual void dragCompleted(const QPoint& pos);
virtual void dragAborted();
virtual void dragWheel (int diff, double speedFactor);
virtual void dragMoveEvent (QDragMoveEvent *event);
private:
TextureBrushWindow *textureBrushWindow;
signals:
void passBrushTexture(std::string brushTexture);
public slots:
void handleDragEnterEvent (QDragEnterEvent *event);
void handleDropEvent(QDropEvent *event);
};
}
#endif

@ -577,6 +577,9 @@ void CSVRender::WorldspaceWidget::debugProfileAboutToBeRemoved (const QModelInde
void CSVRender::WorldspaceWidget::editModeChanged (const std::string& id) void CSVRender::WorldspaceWidget::editModeChanged (const std::string& id)
{ {
dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent()).setEditLock (mLocked); dynamic_cast<CSVRender::EditMode&> (*mEditMode->getCurrent()).setEditLock (mLocked);
if (mEditMode->getCurrentId() == "terrain-texture") mEditMode->setAcceptDrops(true);
else mEditMode->setAcceptDrops(false);
mDragging = false; mDragging = false;
mDragMode = InteractionType_None; mDragMode = InteractionType_None;
} }

@ -144,6 +144,15 @@ bool CSVWidget::SceneToolMode::event(QEvent* event)
return SceneTool::event(event); return SceneTool::event(event);
} }
void CSVWidget::SceneToolMode::dragEnterEvent (QDragEnterEvent *event)
{
emit passEvent(event);
}
void CSVWidget::SceneToolMode::dropEvent (QDropEvent *event)
{
emit passEvent(event);
}
void CSVWidget::SceneToolMode::selected() void CSVWidget::SceneToolMode::selected()
{ {
std::map<ModeButton *, std::string>::iterator iter = std::map<ModeButton *, std::string>::iterator iter =

@ -47,6 +47,8 @@ namespace CSVWidget
protected: protected:
bool event(QEvent* event); bool event(QEvent* event);
void dragEnterEvent (QDragEnterEvent *event);
void dropEvent (QDropEvent *event);
public: public:
@ -72,6 +74,8 @@ namespace CSVWidget
signals: signals:
void modeChanged (const std::string& id); void modeChanged (const std::string& id);
void passEvent (QDragEnterEvent *event);
void passEvent (QDropEvent *event);
private slots: private slots:

@ -68,7 +68,7 @@
<file alias="edit-preview">record-preview.png</file> <file alias="edit-preview">record-preview.png</file>
<file alias="edit-clone">record-clone.png</file> <file alias="edit-clone">record-clone.png</file>
<file alias="edit-add">record-add.png</file> <file alias="edit-add">record-add.png</file>
<file alias="resources-icon">resources-icon.png</file> <file alias="resources-icon">resources-icon.png</file>
<file alias="resources-mesh">resources-mesh.png</file> <file alias="resources-mesh">resources-mesh.png</file>
<file alias="resources-music">resources-music.png</file> <file alias="resources-music">resources-music.png</file>
<file alias="resources-sound">resources-sound.png</file> <file alias="resources-sound">resources-sound.png</file>
@ -149,6 +149,10 @@
<file alias="transform-scale">transform-scale.png</file> <file alias="transform-scale">transform-scale.png</file>
<file alias="selection-mode-cube">selection-mode-cube.png</file> <file alias="selection-mode-cube">selection-mode-cube.png</file>
<file alias="selection-mode-cube-corner">selection-mode-cube-corner.png</file> <file alias="selection-mode-cube-corner">selection-mode-cube-corner.png</file>
<file alias="selection-mode-cube-sphere">selection-mode-cube-sphere.png</file> <file alias="selection-mode-cube-sphere">selection-mode-cube-sphere.png</file>
<file alias="brush-point">brush-point.png</file>
<file alias="brush-square">brush-square.png</file>
<file alias="brush-circle">brush-circle.png</file>
<file alias="brush-custom">brush-custom.png</file>
</qresource> </qresource>
</RCC> </RCC>

Loading…
Cancel
Save