Added rounded drawing widgets
This commit is contained in:
parent
f199963867
commit
bc3f47e3b9
6 changed files with 73 additions and 27 deletions
|
@ -327,7 +327,7 @@ int PreviewDrawingManager::chunkCount()
|
||||||
|
|
||||||
/*************** BasePreview ***************/
|
/*************** BasePreview ***************/
|
||||||
BasePreview::BasePreview(QWidget* parent) :
|
BasePreview::BasePreview(QWidget* parent) :
|
||||||
QWidget(parent)
|
DrawingWidget(parent)
|
||||||
{
|
{
|
||||||
this->_lock_drawing = new QMutex();
|
this->_lock_drawing = new QMutex();
|
||||||
|
|
||||||
|
@ -687,12 +687,11 @@ void BasePreview::resizeEvent(QResizeEvent* event)
|
||||||
this->_lock_drawing->unlock();
|
this->_lock_drawing->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePreview::paintEvent(QPaintEvent*)
|
void BasePreview::doDrawing(QPainter* painter)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
|
||||||
if (isEnabled())
|
if (isEnabled())
|
||||||
{
|
{
|
||||||
painter.drawImage(0, 0, *this->_pixbuf);
|
painter->drawImage(0, 0, *this->_pixbuf);
|
||||||
|
|
||||||
QImage osd(_pixbuf->size(), _pixbuf->format());
|
QImage osd(_pixbuf->size(), _pixbuf->format());
|
||||||
osd.fill(0x00000000);
|
osd.fill(0x00000000);
|
||||||
|
@ -700,11 +699,11 @@ void BasePreview::paintEvent(QPaintEvent*)
|
||||||
{
|
{
|
||||||
_osd[i]->apply(&osd, xoffset, yoffset, scaling);
|
_osd[i]->apply(&osd, xoffset, yoffset, scaling);
|
||||||
}
|
}
|
||||||
painter.drawImage(0, 0, osd);
|
painter->drawImage(0, 0, osd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
painter.fillRect(rect(), QColor(100, 100, 100));
|
painter->fillRect(rect(), QColor(100, 100, 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,16 @@
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QWidget>
|
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include "previewosd.h"
|
|
||||||
#include "common/previewrenderer.h"
|
#include "editing/previewosd.h"
|
||||||
|
#include "editing/common/DrawingWidget.h"
|
||||||
|
#include "editing/common/previewrenderer.h"
|
||||||
|
|
||||||
#include "rendering/tools/pack.h"
|
#include "rendering/tools/pack.h"
|
||||||
#include "rendering/tools/color.h"
|
#include "rendering/tools/color.h"
|
||||||
|
|
||||||
|
@ -29,7 +31,9 @@ public:
|
||||||
bool value;
|
bool value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BasePreview : public QWidget
|
class QPainter;
|
||||||
|
|
||||||
|
class BasePreview : public DrawingWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -83,7 +87,8 @@ private:
|
||||||
void timerEvent(QTimerEvent* event);
|
void timerEvent(QTimerEvent* event);
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent* event);
|
||||||
void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
void paintEvent(QPaintEvent* event);
|
|
||||||
|
void doDrawing(QPainter* painter);
|
||||||
|
|
||||||
void contextMenuEvent(QContextMenuEvent* event);
|
void contextMenuEvent(QContextMenuEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
|
23
src/editing/common/DrawingWidget.cpp
Normal file
23
src/editing/common/DrawingWidget.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "DrawingWidget.h"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
DrawingWidget::DrawingWidget(QWidget* parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawingWidget::paintEvent(QPaintEvent*)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
QPainterPath mask;
|
||||||
|
mask.addRoundedRect(rect(), 8.0, 8.0);
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setClipPath(mask);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
|
||||||
|
doDrawing(&painter);
|
||||||
|
}
|
21
src/editing/common/DrawingWidget.h
Normal file
21
src/editing/common/DrawingWidget.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef DRAWINGWIDGET_H
|
||||||
|
#define DRAWINGWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class QPaintEvent;
|
||||||
|
class QPainter;
|
||||||
|
|
||||||
|
class DrawingWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DrawingWidget(QWidget* parent = 0);
|
||||||
|
protected:
|
||||||
|
virtual void doDrawing(QPainter* painter) = 0;
|
||||||
|
private:
|
||||||
|
virtual void paintEvent(QPaintEvent* event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* DRAWINGWIDGET_H */
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
WidgetTerrainBaseNoisePreview::WidgetTerrainBaseNoisePreview(QWidget* parent) :
|
WidgetTerrainBaseNoisePreview::WidgetTerrainBaseNoisePreview(QWidget* parent) :
|
||||||
QWidget(parent)
|
DrawingWidget(parent)
|
||||||
{
|
{
|
||||||
_noise = NULL;
|
_noise = NULL;
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,17 @@ void WidgetTerrainBaseNoisePreview::setNoise(NoiseGenerator* noise)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetTerrainBaseNoisePreview::paintEvent(QPaintEvent* event)
|
void WidgetTerrainBaseNoisePreview::doDrawing(QPainter* painter)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
painter->setBrush(Qt::SolidPattern);
|
||||||
|
painter->drawRect(rect());
|
||||||
painter.setBrush(Qt::SolidPattern);
|
|
||||||
painter.drawRect(rect());
|
|
||||||
|
|
||||||
int height = this->height();
|
int height = this->height();
|
||||||
|
|
||||||
if (_noise)
|
if (_noise)
|
||||||
{
|
{
|
||||||
QRect boundaries = event->region().boundingRect();
|
//QRect boundaries = event->region().boundingRect();
|
||||||
|
QRect boundaries = rect(); // TODO Limit to updated region
|
||||||
double value, factor;
|
double value, factor;
|
||||||
double minvalue, maxvalue;
|
double minvalue, maxvalue;
|
||||||
|
|
||||||
|
@ -38,8 +37,8 @@ void WidgetTerrainBaseNoisePreview::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
value = noiseGet1DTotal(_noise, 100.0 * ((double)x) / factor);
|
value = noiseGet1DTotal(_noise, 100.0 * ((double)x) / factor);
|
||||||
|
|
||||||
painter.setPen(Qt::white);
|
painter->setPen(Qt::white);
|
||||||
painter.drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
|
painter->drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#ifndef _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
|
#ifndef _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
|
||||||
#define _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
|
#define _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
|
||||||
|
|
||||||
#include <QWidget>
|
#include "editing/common/DrawingWidget.h"
|
||||||
|
|
||||||
#include "rendering/noise.h"
|
#include "rendering/noise.h"
|
||||||
|
|
||||||
class WidgetTerrainBaseNoisePreview : public QWidget
|
class QPainter;
|
||||||
|
|
||||||
|
class WidgetTerrainBaseNoisePreview : public DrawingWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -13,11 +16,7 @@ public:
|
||||||
void setNoise(NoiseGenerator* noise);
|
void setNoise(NoiseGenerator* noise);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent(QPaintEvent* event);
|
virtual void doDrawing(QPainter* painter);
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NoiseGenerator* _noise;
|
NoiseGenerator* _noise;
|
||||||
|
|
Loading…
Reference in a new issue