diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index ea68cfa93..2b5e9ca59 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -49,7 +49,7 @@ void CSVRender::TerrainTextureMode::activate(CSVWidget::SceneToolbar* toolbar) { if(!mTextureBrushScenetool) { - mTextureBrushScenetool = new CSVWidget::SceneToolTextureBrush (toolbar, "scenetooltexturebrush"); + mTextureBrushScenetool = new CSVWidget::SceneToolTextureBrush (toolbar, "scenetooltexturebrush", getWorldspaceWidget().getDocument()); connect(mTextureBrushScenetool, SIGNAL (clicked()), mTextureBrushScenetool, SLOT (activate())); connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passBrushSize(int)), this, SLOT(setBrushSize(int))); connect(mTextureBrushScenetool->mTextureBrushWindow, SIGNAL(passBrushShape(int)), this, SLOT(setBrushShape(int))); diff --git a/apps/opencs/view/widget/scenetooltexturebrush.cpp b/apps/opencs/view/widget/scenetooltexturebrush.cpp index 2a41ce091..003ab12fd 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.cpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.cpp @@ -21,6 +21,11 @@ #include #include "scenetool.hpp" +#include "../../model/doc/document.hpp" +#include "../../model/world/data.hpp" +#include "../../model/world/idtable.hpp" +#include "../../model/world/landtexture.hpp" + CSVWidget::BrushSizeControls::BrushSizeControls(const QString &title, QWidget *parent) : QGroupBox(title, parent) @@ -45,14 +50,21 @@ CSVWidget::BrushSizeControls::BrushSizeControls(const QString &title, QWidget *p setLayout(mLayoutSliderSize); } -CSVWidget::TextureBrushWindow::TextureBrushWindow(QWidget *parent) +CSVWidget::TextureBrushWindow::TextureBrushWindow(CSMDoc::Document& document, QWidget *parent) : QFrame(parent, Qt::Popup), mBrushShape(0), mBrushSize(0), - mBrushTexture("L0#0") + mBrushTexture("L0#0"), + mDocument(document) { - mBrushTextureLabel = "Selected texture (id): " + mBrushTexture; - mSelectedBrush = new QLabel(QString::fromStdString(mBrushTextureLabel), this); + CSMWorld::IdTable& ltexTable = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); + + int landTextureFilename = ltexTable.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); + + QModelIndex index = ltexTable.getModelIndex (mBrushTexture, landTextureFilename); + mBrushTextureLabel = "Selected texture: " + mBrushTexture + " "; + mSelectedBrush = new QLabel(QString::fromStdString(mBrushTextureLabel) + ltexTable.data(index).value()); QVBoxLayout *layoutMain = new QVBoxLayout; layoutMain->setSpacing(0); @@ -111,10 +123,16 @@ void CSVWidget::TextureBrushWindow::configureButtonInitialSettings(QPushButton * void CSVWidget::TextureBrushWindow::setBrushTexture(std::string brushTexture) { + CSMWorld::IdTable& ltexTable = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); + int landTextureFilename = ltexTable.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); + mBrushTexture = brushTexture; - mBrushTextureLabel = "Selected texture (id): " + mBrushTexture; - mSelectedBrush->setText(QString::fromStdString(mBrushTextureLabel)); + mBrushTextureLabel = "Selected texture: " + mBrushTexture + " "; + QModelIndex index = ltexTable.getModelIndex (mBrushTexture, landTextureFilename); + mSelectedBrush->setText(QString::fromStdString(mBrushTextureLabel) + ltexTable.data(index).value()); emit passBrushShape(mBrushShape); // update icon + } void CSVWidget::TextureBrushWindow::setBrushSize(int brushSize) @@ -136,10 +154,11 @@ void CSVWidget::SceneToolTextureBrush::adjustToolTips() { } -CSVWidget::SceneToolTextureBrush::SceneToolTextureBrush (SceneToolbar *parent, const QString& toolTip) +CSVWidget::SceneToolTextureBrush::SceneToolTextureBrush (SceneToolbar *parent, const QString& toolTip, CSMDoc::Document& document) : SceneTool (parent, Type_TopAction), mToolTip (toolTip), - mTextureBrushWindow(new TextureBrushWindow(this)) + mDocument (document), + mTextureBrushWindow(new TextureBrushWindow(document, this)) { mBrushHistory.resize(1); mBrushHistory[0] = "L0#0"; @@ -161,10 +180,10 @@ CSVWidget::SceneToolTextureBrush::SceneToolTextureBrush (SceneToolbar *parent, c mTable->horizontalHeader()->hide(); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) mTable->horizontalHeader()->setSectionResizeMode (0, QHeaderView::Stretch); - mTable->horizontalHeader()->setSectionResizeMode (1, QHeaderView::ResizeToContents); + mTable->horizontalHeader()->setSectionResizeMode (1, QHeaderView::Stretch); #else mTable->horizontalHeader()->setResizeMode (0, QHeaderView::Stretch); - mTable->horizontalHeader()->setResizeMode (1, QHeaderView::ResizeToContents); + mTable->horizontalHeader()->setResizeMode (1, QHeaderView::Stretch); #endif mTable->setSelectionMode (QAbstractItemView::NoSelection); @@ -198,7 +217,14 @@ void CSVWidget::SceneToolTextureBrush::setButtonIcon (int brushShape) setIcon (QIcon (QPixmap (":scenetoolbar/brush-custom"))); tooltip += dynamic_cast (mTextureBrushWindow->toolTipCustom); } - tooltip += "

Selected texture: " + QString::fromStdString(mTextureBrushWindow->mBrushTexture); + tooltip += "

Selected texture: " + QString::fromStdString(mTextureBrushWindow->mBrushTexture) + " "; + + CSMWorld::IdTable& ltexTable = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); + int landTextureFilename = ltexTable.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); + QModelIndex index = ltexTable.getModelIndex (mTextureBrushWindow->mBrushTexture, landTextureFilename); + tooltip += ltexTable.data(index).value(); + tooltip += "
(drop texture here to change)"; setToolTip (tooltip); } @@ -214,11 +240,13 @@ void CSVWidget::SceneToolTextureBrush::updatePanel() { mTable->setRowCount (mBrushHistory.size()); - mTable->setItem (0, 1, new QTableWidgetItem ( - QApplication::style()->standardIcon (QStyle::SP_TitleBarCloseButton), "")); - for (int i = mBrushHistory.size()-1; i >= 0; --i) { + CSMWorld::IdTable& ltexTable = dynamic_cast ( + *mDocument.getData().getTableModel (CSMWorld::UniversalId::Type_LandTextures)); + int landTextureFilename = ltexTable.findColumnIndex(CSMWorld::Columns::ColumnId_Texture); + QModelIndex index = ltexTable.getModelIndex (mBrushHistory[i], landTextureFilename); + mTable->setItem (i, 1, new QTableWidgetItem (ltexTable.data(index).value())); mTable->setItem (i, 0, new QTableWidgetItem (QString::fromStdString(mBrushHistory[i]))); } } @@ -231,7 +259,7 @@ void CSVWidget::SceneToolTextureBrush::updateBrushHistory (const std::string& br void CSVWidget::SceneToolTextureBrush::clicked (const QModelIndex& index) { - if (index.column()==0) + if (index.column()==0 || index.column()==1) { std::string brushTexture = mBrushHistory[index.row()]; std::swap(mBrushHistory[index.row()], mBrushHistory[0]); @@ -240,10 +268,6 @@ void CSVWidget::SceneToolTextureBrush::clicked (const QModelIndex& index) updatePanel(); mPanel->hide(); } - else if (index.column()==1) - { - mPanel->hide(); - } } void CSVWidget::SceneToolTextureBrush::activate () diff --git a/apps/opencs/view/widget/scenetooltexturebrush.hpp b/apps/opencs/view/widget/scenetooltexturebrush.hpp index 982ccc3aa..1c0e0a334 100644 --- a/apps/opencs/view/widget/scenetooltexturebrush.hpp +++ b/apps/opencs/view/widget/scenetooltexturebrush.hpp @@ -16,6 +16,8 @@ #include "scenetool.hpp" +#include "../../model/doc/document.hpp" + class QTableWidget; namespace CSVWidget @@ -40,7 +42,7 @@ namespace CSVWidget Q_OBJECT public: - TextureBrushWindow(QWidget *parent = 0); + TextureBrushWindow(CSMDoc::Document& document, QWidget *parent = 0); void configureButtonInitialSettings(QPushButton *button); QPushButton *mButtonPoint = new QPushButton(QIcon (QPixmap (":scenetoolbar/brush-point")), "", this); @@ -57,6 +59,7 @@ namespace CSVWidget std::string mBrushTexture; private: + CSMDoc::Document& mDocument; QLabel *mSelectedBrush; QGroupBox *mHorizontalGroupBox; std::string mBrushTextureLabel; @@ -76,6 +79,7 @@ namespace CSVWidget Q_OBJECT QString mToolTip; + CSMDoc::Document& mDocument; QFrame *mPanel; QTableWidget *mTable; std::vector mBrushHistory; @@ -86,7 +90,7 @@ namespace CSVWidget public: - SceneToolTextureBrush (SceneToolbar *parent, const QString& toolTip); + SceneToolTextureBrush (SceneToolbar *parent, const QString& toolTip, CSMDoc::Document& document); virtual void showPanel (const QPoint& position); void updatePanel ();