[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/kolf-ng
From: Huan Zeng <zh.issac () gmail ! com>
Date: 2009-08-11 8:33:51
Message-ID: 1249979631.418204.13644.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1009918 by hzeng:
blender and heightmap creator integration finished.
M +8 -5 editor/blender-configwidget.cpp
M +1 -1 editor/blender-configwidget.h
M +25 -6 editor/blender-manager.cpp
M +7 -0 editor/blender-manager.h
M +35 -24 engine/game-editor.cpp
M +4 -0 engine/kolf-editorui.rc
--- trunk/playground/games/kolf-ng/editor/blender-configwidget.cpp #1009917:1009918
@@ -17,6 +17,7 @@
***************************************************************************/
#include "blender-configwidget.h"
+#include <KLocalizedString>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
@@ -24,14 +25,16 @@
#include <QSpinBox>
#include <QVBoxLayout>
-Kolf::BlenderConfigWidget::BlenderConfigWidget(QObject* manager, const QString& \
title)
- : GameUIDockWidget(title)
+Kolf::BlenderConfigWidget::BlenderConfigWidget(QObject* manager)
+ : GameUIDockWidget(i18n("Configuration"))
, m_manager(manager)
, m_width(new QSpinBox(this))
, m_height(new QSpinBox(this))
, m_brightController(new QSlider(Qt::Horizontal, this))
, m_button(new QPushButton(tr("OK"), this))
{
+ setObjectName("BlenderConfigWidget");
+ setPreferredArea(Qt::LeftDockWidgetArea);
m_width->setRange(50, 1000);
m_height->setRange(50, 1000);
m_width->setValue(512);
@@ -39,13 +42,12 @@
m_brightController->setRange(0,100);
m_brightController->setTickInterval(5);
m_brightController->setTickPosition(QSlider::TicksBothSides);
-
+ QWidget* wholeWidget = new QWidget(this);
QLabel *labelWidth = new QLabel(tr("Width"), this);
QLabel *labelHeight = new QLabel(tr("Height"));
QLabel *labelSlider = new QLabel(tr("Brightness"));
QVBoxLayout *vLayout = new QVBoxLayout();
QGridLayout *layout = new QGridLayout();
- //QVboxLayout *hLayout = new QHboxLayout(this);
layout->addWidget(labelWidth, 0, 0);
layout->addWidget(labelHeight, 0, 3);
layout->addWidget(m_width, 1, 0, 1, 2);
@@ -55,7 +57,8 @@
vLayout->addWidget(labelSlider);
vLayout->addWidget(m_brightController);
vLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
- setLayout(vLayout);
+ wholeWidget->setLayout(vLayout);
+ setWidget(wholeWidget);
connect(m_brightController, SIGNAL(valueChanged(int)), m_manager, \
SLOT(changeBrightness(int))); connect(m_width, SIGNAL(valueChanged(int)), m_manager, \
SLOT(setOutputWidth(int))); connect(m_height, SIGNAL(valueChanged(int)), m_manager, \
SLOT(setOutputHeight(int)));
--- trunk/playground/games/kolf-ng/editor/blender-configwidget.h #1009917:1009918
@@ -30,7 +30,7 @@
{
Q_OBJECT
public:
- explicit BlenderConfigWidget(QObject* manager, const QString& title);
+ explicit BlenderConfigWidget(QObject* manager);
private Q_SLOTS:
void boxValueChanged();
--- trunk/playground/games/kolf-ng/editor/blender-manager.cpp #1009917:1009918
@@ -22,6 +22,7 @@
#include "blender-model.h"
#include "blender-manager.h"
#include "blender-texture.h"
+#include <KAction>
#include <QFileDialog>
#include <QListView>
@@ -35,6 +36,8 @@
, m_isConfigurable(true)
, m_outputWidth(512)
, m_outputHeight(512)
+ , m_startBlendingAction(0)
+ , m_showHeightmapAction(0)
{
m_view->setModel(m_model);
m_view->setItemDelegate(m_delegate);
@@ -59,7 +62,7 @@
tr("Open Image"), "./", tr("Image Files (*.png *.jpg *.bmp)"));
m_model->insertRows(fileNames, 0);
- //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_startBlendingAction->setEnabled(m_model->textureList().count() != 0 && \
m_heightmap != 0); m_isConfigurable = true;
}
@@ -70,7 +73,7 @@
return;
m_isConfigurable = false;
m_model->insertRows(fileNames, 0);
- //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_startBlendingAction->setEnabled(m_model->textureList().count() != 0 && \
m_heightmap != 0); m_isConfigurable = true;
}
@@ -159,8 +162,8 @@
}
m_imageViewer->setLeftText(QString("Heightmap loaded\nHeight range: \
(%1,%2)").arg(min).arg(max)); }
- //m_showHeightmapAction->setEnabled(m_heightmap != 0);
- //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_showHeightmapAction->setEnabled(m_heightmap != 0);
+ m_startBlendingAction->setEnabled(m_model->textureList().count() != 0 && \
m_heightmap != 0); m_isConfigurable = true;
}
@@ -185,11 +188,17 @@
}
m_imageViewer->setLeftText(QString("Heightmap loaded\nHeight range: \
(%1,%2)").arg(min).arg(max)); }
- //m_showHeightmapAction->setEnabled(m_heightmap != 0);
- //m_startAction->setEnabled(m_model->textureList().count() != 0 && m_heightmap != \
0); + m_showHeightmapAction->setEnabled(m_heightmap != 0);
+ m_startBlendingAction->setEnabled(m_model->textureList().count() != 0 && \
m_heightmap != 0); m_isConfigurable = true;
}
+void Kolf::BlenderManager::showHeightmap()
+{
+ if(m_heightmap)
+ m_imageViewer->showImage(*m_heightmap);
+}
+
void Kolf::BlenderManager::changeBrightness(int value)
{
if(!m_isConfigurable || m_blendResult.isNull() )
@@ -225,4 +234,14 @@
m_imageViewer->setRightText(QString("Output texture\n size: \
(%1,%2)").arg(m_outputWidth).arg(m_outputHeight)); }
+void Kolf::BlenderManager::saveResult()
+{
+ if(m_brightEffect.isNull())
+ return;
+ QString fileName = QFileDialog::getSaveFileName(m_imageViewer, tr("Save File"), \
"./untitled.png", tr("Images (*.png *.xpm *.jpg)")); + if (!fileName.isEmpty())
+ m_brightEffect.save(fileName);
+}
+
+
#include "blender-manager.moc"
--- trunk/playground/games/kolf-ng/editor/blender-manager.h #1009917:1009918
@@ -21,6 +21,7 @@
#include <QImage>
#include <QObject>
+class KAction;
class QListView;
namespace Kolf
{
@@ -42,6 +43,8 @@
const QImage& blendingResult() const {return m_brightEffect;}
QImage& blendingResult() {return m_brightEffect;}
void setImageViewer(ImageViewer* imageViewer) {m_imageViewer = imageViewer;}
+ void setStartBlendingAction(KAction* action) {m_startBlendingAction = action;}
+ void setShowHeightmapAction(KAction* action) {m_showHeightmapAction = action;}
private Q_SLOTS:
void addTextures();
@@ -50,9 +53,11 @@
void startBlending();
void loadHeightmap();
void loadHeightmap(Heightmap* heightmap);
+ void showHeightmap();
void changeBrightness(int value);
void setOutputWidth(int width);
void setOutputHeight(int height);
+ void saveResult();
private:
TextureListModel* m_model;
@@ -66,6 +71,8 @@
bool m_isConfigurable;
int m_outputWidth;
int m_outputHeight;
+ KAction* m_startBlendingAction;
+ KAction* m_showHeightmapAction;
};
}
--- trunk/playground/games/kolf-ng/engine/game-editor.cpp #1009917:1009918
@@ -20,6 +20,7 @@
#include "component-basicviews.h"
#include "course.h"
#include "player.h"
+#include "../editor/blender-configwidget.h"
#include "../editor/blender-imageviewer.h"
#include "../editor/blender-manager.h"
#include "../editor/blender-texturelistwidget.h"
@@ -64,6 +65,7 @@
addPageWidget(imageViewer);
Kolf::TextureListWidget* textureListWidget = new \
Kolf::TextureListWidget(imageViewer); addDockWidget(textureListWidget);
+ addDockWidget(new Kolf::BlenderConfigWidget(textureListWidget->blenderManager()));
Kolf::DrawingBoard* drawingBoard = new Kolf::DrawingBoard;
addPageWidget(drawingBoard);
addDockWidget(new Kolf::ToolBox(drawingBoard));
@@ -76,6 +78,7 @@
actionCollection()->addAction("blender-addTexture", addTexAction);
connect(addTexAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(addTextures()));
+ //Action: texture blender -- delete textures
KAction* delTexAction = new KAction(KIcon("archive-remove"), i18n("&Delete \
texture"), actionCollection()); delTexAction->setShortcut(i18n("Ctrl+D"));
delTexAction->setStatusTip(i18n("Delete a texture in the list"));
@@ -83,33 +86,41 @@
actionCollection()->addAction("blender-delTexture", delTexAction);
connect(delTexAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(delTextures()));
-/*
- m_loadHeightmapAction = new KAction(KIcon("document-open"),tr("&Load \
heightmap"),this);
- m_loadHeightmapAction->setShortcut(tr("Ctrl+L"));
- m_loadHeightmapAction->setStatusTip(tr("Load the heightmap"));
- m_loadHeightmapAction->setToolTip(tr("Load the heightmap, Ctrl+L"));
- connect(m_loadHeightmapAction, SIGNAL(triggered()), this, SLOT(loadHeightmap()));
+ //Action: texture blender -- load heightmap
+ KAction* loadHeightmapAction = new KAction(KIcon("document-open"),i18n("&Load \
heightmap"), actionCollection()); + loadHeightmapAction->setShortcut(i18n("Ctrl+L"));
+ loadHeightmapAction->setStatusTip(i18n("Load the heightmap"));
+ loadHeightmapAction->setToolTip(i18n("Load the heightmap, Ctrl+L"));
+ actionCollection()->addAction("blender-loadHeightmap", loadHeightmapAction);
+ connect(loadHeightmapAction, SIGNAL(triggered()), \
textureListWidget->blenderManager(), SLOT(loadHeightmap()));
- m_showHeightmapAction = new KAction(KIcon("games-config-board"),tr("S&how \
heightmap"),this);
- m_showHeightmapAction->setShortcut(tr("Ctrl+H"));
- m_showHeightmapAction->setStatusTip(tr("Show the heightmap"));
- m_showHeightmapAction->setToolTip(tr("Show the heightmap, Ctrl+H"));
- m_showHeightmapAction->setEnabled(false); //will become available when a heightmap \
is loaded
- connect(m_showHeightmapAction, SIGNAL(triggered()), this, SLOT(showHeightmap()));
+ //Action: texture blender -- show heightmap
+ KAction* showHeightmapAction = new KAction(KIcon("games-config-board"),i18n("S&how \
heightmap"), actionCollection()); + showHeightmapAction->setShortcut(i18n("Ctrl+H"));
+ showHeightmapAction->setStatusTip(i18n("Show the heightmap"));
+ showHeightmapAction->setToolTip(i18n("Show the heightmap, Ctrl+H"));
+ showHeightmapAction->setEnabled(false); //will become available when a heightmap is \
loaded + actionCollection()->addAction("blender-showHeightmap", showHeightmapAction);
+ textureListWidget->blenderManager()->setShowHeightmapAction(showHeightmapAction);//FIXME: \
how can I avoid this method? + connect(showHeightmapAction, SIGNAL(triggered()), \
textureListWidget->blenderManager(), SLOT(showHeightmap()));
- m_startAction = new KAction(KIcon("run-build"),tr("Start &Blending"),this);
- m_startAction->setShortcut(tr("Ctrl+B"));
- m_startAction->setStatusTip(tr("Start blending"));
- m_startAction->setToolTip(tr("start blending"));
- m_startAction->setEnabled(false); //will become available when a heightmap and \
textures are loaded
- connect(m_startAction, SIGNAL(triggered()), this, SLOT(start()));
+ //Action: texture blender -- start blending
+ KAction* startAction = new KAction(KIcon("run-build"), i18n("Start &Blending"), \
actionCollection()); + startAction->setShortcut(i18n("Ctrl+B"));
+ startAction->setStatusTip(i18n("Start blending"));
+ startAction->setToolTip(i18n("start blending"));
+ startAction->setEnabled(false); //will become available when a heightmap and \
textures are loaded + actionCollection()->addAction("blender-startBlending", \
startAction); + textureListWidget->blenderManager()->setStartBlendingAction(startAction);
+ connect(startAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(startBlending()));
- m_saveAction = new KAction(KIcon("document-save"),tr("&Save"),this);
- m_saveAction->setShortcut(tr("Ctrl+S"));
- m_saveAction->setStatusTip(tr("Save texture"));
- m_saveAction->setToolTip(tr("Save the result"));
- connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save()));
-*/
+ //Action: texture blender -- save blending result
+ KAction* saveAction = new KAction(KIcon("document-save"), i18n("&Save"), \
actionCollection()); + saveAction->setShortcut(i18n("Ctrl+S"));
+ saveAction->setStatusTip(i18n("Save texture"));
+ saveAction->setToolTip(i18n("Save the result"));
+ actionCollection()->addAction("blender-saveResult", saveAction);
+ connect(saveAction, SIGNAL(triggered()), textureListWidget->blenderManager(), \
SLOT(saveResult())); }
void Kolf::EditorGameUI::setCleanDispatcher(bool clean)
--- trunk/playground/games/kolf-ng/engine/kolf-editorui.rc #1009917:1009918
@@ -13,5 +13,9 @@
<Separator/>
<Action name="blender-addTexture" />
<Action name="blender-delTexture" />
+ <Action name="blender-loadHeightmap" />
+ <Action name="blender-showHeightmap" />
+ <Action name="blender-startBlending" />
+ <Action name="blender-saveResult" />
</ToolBar>
</gui>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic