WIP on new texture form

- Added FreeLayerHelper
- Added texture layers table
This commit is contained in:
Michaël Lemaire 2013-08-17 17:04:48 +02:00
parent 0a11c7d48a
commit c8f36643d0
10 changed files with 451 additions and 28 deletions

View file

@ -690,6 +690,8 @@ void BasePreview::resizeEvent(QResizeEvent* event)
void BasePreview::paintEvent(QPaintEvent*)
{
QPainter painter(this);
if (isEnabled())
{
painter.drawImage(0, 0, *this->_pixbuf);
QImage osd(_pixbuf->size(), _pixbuf->format());
@ -700,6 +702,11 @@ void BasePreview::paintEvent(QPaintEvent*)
}
painter.drawImage(0, 0, osd);
}
else
{
painter.fillRect(rect(), QColor(100, 100, 100));
}
}
void BasePreview::updateScaling()
{

View file

@ -149,6 +149,8 @@ void FreeFormHelper::setExploreButton(QPushButton* button)
{
_button_explore = button;
button->setToolTip(tr("Explore the scenery in 3D, with current changes applied"));
connect(button, SIGNAL(clicked()), this, SLOT(processExploreClicked()));
}
}
@ -164,6 +166,8 @@ void FreeFormHelper::setRenderButton(QPushButton* button)
{
_button_render = button;
button->setToolTip(tr("Quick render preview, with current changes applied"));
connect(button, SIGNAL(clicked()), this, SLOT(processRenderClicked()));
}
}

View file

@ -0,0 +1,117 @@
#include "freelayerhelper.h"
#include <QTableWidget>
#include <QPushButton>
FreeLayerHelper::FreeLayerHelper(Layers* layers, bool reverse)
{
_table = NULL;
_selected = -1;
_layers = layers;
_reverse = reverse;
}
FreeLayerHelper::~FreeLayerHelper()
{
}
void FreeLayerHelper::refreshLayers()
{
if (_table)
{
int selected = _selected;
emit tableUpdateNeeded();
int n = layersCount(_layers);
if (n == 0)
{
_selected = -1;
}
if (selected < 0)
{
_table->clearSelection();
emit selectionChanged(-1);
}
else
{
if (selected >= n)
{
selected = n - 1;
}
_table->setCurrentCell(selected, 0);
}
}
}
void FreeLayerHelper::setLayerTable(QTableWidget* table)
{
_table = table;
connect(table, SIGNAL(currentCellChanged(int, int, int, int)), this, SLOT(tableSelectionChanged(int, int)));
refreshLayers();
}
void FreeLayerHelper::setAddButton(QPushButton* button)
{
connect(button, SIGNAL(clicked()), this, SLOT(addLayer()));
}
void FreeLayerHelper::setDelButton(QPushButton* button)
{
connect(button, SIGNAL(clicked()), this, SLOT(deleteLayer()));
}
void FreeLayerHelper::setDownButton(QPushButton* button)
{
connect(button, SIGNAL(clicked()), this, SLOT(moveLayerDown()));
}
void FreeLayerHelper::setUpButton(QPushButton* button)
{
connect(button, SIGNAL(clicked()), this, SLOT(moveLayerUp()));
}
void FreeLayerHelper::addLayer()
{
_selected = layersAddLayer(_layers, NULL);
emit(layersChanged());
refreshLayers();
}
void FreeLayerHelper::deleteLayer()
{
if (_selected >= 0)
{
layersDeleteLayer(_layers, _selected);
emit(layersChanged());
}
refreshLayers();
}
void FreeLayerHelper::moveLayerDown()
{
}
void FreeLayerHelper::moveLayerUp()
{
}
void FreeLayerHelper::tableSelectionChanged(int row, int)
{
int n = layersCount(_layers);
if (n == 0 or row >= n)
{
_selected = -1;
}
else
{
_selected = _reverse ? n - 1 - row : row;
}
emit(selectionChanged(_selected));
}

View file

@ -0,0 +1,44 @@
#ifndef _EDITING_COMMON_FREELAYERHELPER_H_
#define _EDITING_COMMON_FREELAYERHELPER_H_
#include <QObject>
#include "rendering/layers.h"
class QTableWidget;
class QPushButton;
class FreeLayerHelper : public QObject {
Q_OBJECT
public:
FreeLayerHelper(Layers* layers, bool reverse=false);
~FreeLayerHelper();
void refreshLayers();
void setLayerTable(QTableWidget* table);
void setAddButton(QPushButton* button);
void setDelButton(QPushButton* button);
void setDownButton(QPushButton* button);
void setUpButton(QPushButton* button);
signals:
void selectionChanged(int layer);
void layersChanged();
void tableUpdateNeeded();
public slots:
void addLayer();
void deleteLayer();
void moveLayerDown();
void moveLayerUp();
void tableSelectionChanged(int row, int col);
private:
QTableWidget* _table;
Layers* _layers;
int _selected;
bool _reverse;
};
#endif

View file

@ -124,9 +124,9 @@ MainWindow::MainWindow() :
ui->tabs->setCurrentIndex(0);
// TODO Decide this according to platform / screen size
//ui->toolBar->hide();
ui->toolBar->hide();
ui->tool_panel->hide();
ui->menuBar->hide();
//ui->menuBar->hide();
scenerySetCustomDataCallback(MainWindow::guiSaveCallback, MainWindow::guiLoadCallback, this);

View file

@ -72,7 +72,8 @@ HEADERS += \
terrain/widgetterrainbasenoisepreview.h \
common/mainwindow.h \
terrain/dialogbaseterrainnoise.h \
textures/maintexturesform.h
textures/maintexturesform.h \
common/freelayerhelper.h
SOURCES += \
terrain/widgetheightmap.cpp \
@ -124,7 +125,8 @@ SOURCES += \
terrain/widgetterrainbasenoisepreview.cpp \
common/mainwindow.cpp \
terrain/dialogbaseterrainnoise.cpp \
textures/maintexturesform.cpp
textures/maintexturesform.cpp \
common/freelayerhelper.cpp
FORMS += \
terrain/dialogterrainpainting.ui \

View file

@ -74,6 +74,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
@ -116,6 +129,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_1">
<property name="title">
@ -185,6 +211,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
@ -224,6 +263,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
@ -329,6 +381,19 @@
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>

View file

@ -1,14 +1,106 @@
#include "maintexturesform.h"
#include "ui_maintexturesform.h"
MainTexturesForm::MainTexturesForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainTexturesForm)
#include "../common/freeformhelper.h"
#include "../common/freelayerhelper.h"
#include "rendering/scenery.h"
#include "previewmaterial.h"
MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm)
{
textures = (TexturesDefinition*) TexturesDefinitionClass.create();
ui->setupUi(this);
form_helper = new FreeFormHelper(this);
form_helper->setApplyButton(ui->button_apply);
form_helper->setRevertButton(ui->button_revert);
form_helper->setExploreButton(ui->button_explore);
form_helper->setRenderButton(ui->button_render);
form_helper->startManaging();
layer_helper = new FreeLayerHelper(textures->layers, true);
layer_helper->setLayerTable(ui->layersGrid);
layer_helper->setAddButton(ui->layer_add);
layer_helper->setDelButton(ui->layer_del);
layer_helper->setDownButton(ui->layer_down);
layer_helper->setUpButton(ui->layer_up);
connect(layer_helper, SIGNAL(tableUpdateNeeded()), this, SLOT(updateLayers()));
connect(layer_helper, SIGNAL(layersChanged()), form_helper, SLOT(processDataChange()));
connect(layer_helper, SIGNAL(selectionChanged(int)), this, SLOT(selectLayer(int)));
}
MainTexturesForm::~MainTexturesForm()
{
delete ui;
delete form_helper;
delete layer_helper;
}
void MainTexturesForm::updateLayers()
{
int i, n;
ui->layersGrid->clearContents();
n = layersCount(textures->layers);
ui->layersGrid->setRowCount(n);
for (i = 0; i < n; i++)
{
QTableWidgetItem* item;
TexturesLayerDefinition* layer = (TexturesLayerDefinition*) layersGetLayer(textures->layers, i);
item = new QTableWidgetItem(QString("%1").arg(i + 1));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->layersGrid->setItem(n - 1 - i, 0, item);
item = new QTableWidgetItem(QString(layersGetName(textures->layers, i)));
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->layersGrid->setItem(n - 1 - i, 1, item);
ui->layersGrid->setCellWidget(n - 1 - i, 2, new SmallMaterialPreview(ui->layersGrid, &layer->material));
}
ui->preview_cumul->setEnabled(n > 0);
ui->layersGrid->resizeColumnsToContents();
}
void MainTexturesForm::selectLayer(int layer)
{
if (layer < 0)
{
ui->preview_coverage->setEnabled(false);
ui->preview_texture->setEnabled(false);
}
else
{
ui->preview_coverage->setEnabled(true);
ui->preview_texture->setEnabled(true);
}
}
void MainTexturesForm::updateLocalDataFromScenery()
{
sceneryGetTextures(textures);
}
void MainTexturesForm::commitLocalDataToScenery()
{
scenerySetTextures(textures);
}
void MainTexturesForm::refreshFromLocalData()
{
layer_helper->refreshLayers();
}
void MainTexturesForm::refreshFromFellowData()
{
}
void MainTexturesForm::alterRenderer(Renderer* renderer)
{
TexturesRendererClass.bind(renderer, textures);
}

View file

@ -2,11 +2,15 @@
#define MAINTEXTURESFORM_H
#include <QWidget>
#include "rendering/textures/public.h"
namespace Ui {
class MainTexturesForm;
}
class FreeFormHelper;
class FreeLayerHelper;
class MainTexturesForm : public QWidget
{
Q_OBJECT
@ -15,8 +19,21 @@ public:
explicit MainTexturesForm(QWidget *parent = 0);
~MainTexturesForm();
public slots:
void updateLocalDataFromScenery();
void commitLocalDataToScenery();
void refreshFromLocalData();
void refreshFromFellowData();
void alterRenderer(Renderer* renderer);
void updateLayers();
void selectLayer(int layer);
private:
Ui::MainTexturesForm *ui;
TexturesDefinition* textures;
FreeFormHelper* form_helper;
FreeLayerHelper* layer_helper;
};
#endif // MAINTEXTURESFORM_H

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1008</width>
<height>664</height>
<width>997</width>
<height>742</height>
</rect>
</property>
<property name="windowTitle">
@ -46,7 +46,43 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTableView" name="tableView"/>
<widget class="QTableWidget" name="layersGrid">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Level</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Material</string>
</property>
</column>
<column>
<property name="text">
<string>Modify terrain</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -64,7 +100,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="layer_add">
<property name="text">
<string>Add layer</string>
</property>
@ -72,10 +108,19 @@
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/layer_add.png</normaloff>:/buttons/logo/images/layer_add.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="layer_del">
<property name="text">
<string>Remove layer</string>
</property>
@ -83,6 +128,12 @@
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/layer_del.png</normaloff>:/buttons/logo/images/layer_del.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
@ -90,6 +141,9 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
@ -99,14 +153,20 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="layer_edit">
<property name="text">
<string>Rename layer</string>
<string>Edit layer</string>
</property>
<property name="icon">
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/layer_rename.png</normaloff>:/buttons/logo/images/layer_rename.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
@ -114,6 +174,9 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
@ -123,7 +186,7 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<widget class="QPushButton" name="layer_down">
<property name="text">
<string>Move layer down</string>
</property>
@ -131,10 +194,16 @@
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/layer_down.png</normaloff>:/buttons/logo/images/layer_down.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="layer_up">
<property name="text">
<string>Move layer up</string>
</property>
@ -142,6 +211,12 @@
<iconset resource="../../../data/ui_pictures.qrc">
<normaloff>:/buttons/logo/images/layer_up.png</normaloff>:/buttons/logo/images/layer_up.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
</widget>
</item>
<item>
@ -171,7 +246,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="BasePreview" name="preview_shape_6" native="true">
<widget class="BasePreview" name="preview_texture" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -203,7 +278,7 @@
</widget>
</item>
<item row="2" column="0">
<widget class="BasePreview" name="preview_shape_2" native="true">
<widget class="BasePreview" name="preview_coverage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -258,7 +333,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="BasePreview" name="preview_shape" native="true">
<widget class="BasePreview" name="preview_cumul" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>