Added rounded drawing widgets

This commit is contained in:
Michaël Lemaire 2013-08-18 17:12:54 +02:00
parent f199963867
commit bc3f47e3b9
6 changed files with 73 additions and 27 deletions

View file

@ -327,7 +327,7 @@ int PreviewDrawingManager::chunkCount()
/*************** BasePreview ***************/
BasePreview::BasePreview(QWidget* parent) :
QWidget(parent)
DrawingWidget(parent)
{
this->_lock_drawing = new QMutex();
@ -687,12 +687,11 @@ void BasePreview::resizeEvent(QResizeEvent* event)
this->_lock_drawing->unlock();
}
void BasePreview::paintEvent(QPaintEvent*)
void BasePreview::doDrawing(QPainter* painter)
{
QPainter painter(this);
if (isEnabled())
{
painter.drawImage(0, 0, *this->_pixbuf);
painter->drawImage(0, 0, *this->_pixbuf);
QImage osd(_pixbuf->size(), _pixbuf->format());
osd.fill(0x00000000);
@ -700,11 +699,11 @@ void BasePreview::paintEvent(QPaintEvent*)
{
_osd[i]->apply(&osd, xoffset, yoffset, scaling);
}
painter.drawImage(0, 0, osd);
painter->drawImage(0, 0, osd);
}
else
{
painter.fillRect(rect(), QColor(100, 100, 100));
painter->fillRect(rect(), QColor(100, 100, 100));
}
}

View file

@ -3,14 +3,16 @@
#include <QMutex>
#include <QImage>
#include <QWidget>
#include <QThread>
#include <QVector>
#include <QList>
#include <QLabel>
#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/color.h"
@ -29,7 +31,9 @@ public:
bool value;
};
class BasePreview : public QWidget
class QPainter;
class BasePreview : public DrawingWidget
{
Q_OBJECT
@ -83,7 +87,8 @@ private:
void timerEvent(QTimerEvent* event);
void showEvent(QShowEvent* event);
void resizeEvent(QResizeEvent* event);
void paintEvent(QPaintEvent* event);
void doDrawing(QPainter* painter);
void contextMenuEvent(QContextMenuEvent* event);
void mousePressEvent(QMouseEvent* event);

View 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);
}

View 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 */

View file

@ -5,7 +5,7 @@
#include "tools.h"
WidgetTerrainBaseNoisePreview::WidgetTerrainBaseNoisePreview(QWidget* parent) :
QWidget(parent)
DrawingWidget(parent)
{
_noise = NULL;
}
@ -16,18 +16,17 @@ void WidgetTerrainBaseNoisePreview::setNoise(NoiseGenerator* noise)
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();
if (_noise)
{
QRect boundaries = event->region().boundingRect();
//QRect boundaries = event->region().boundingRect();
QRect boundaries = rect(); // TODO Limit to updated region
double value, factor;
double minvalue, maxvalue;
@ -38,8 +37,8 @@ void WidgetTerrainBaseNoisePreview::paintEvent(QPaintEvent* event)
{
value = noiseGet1DTotal(_noise, 100.0 * ((double)x) / factor);
painter.setPen(Qt::white);
painter.drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
painter->setPen(Qt::white);
painter->drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
}
}
}

View file

@ -1,10 +1,13 @@
#ifndef _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
#define _PAYSAGES_EDITING_TERRAIN_WIDGETTERRAINBASENOISEPREVIEW_H_
#include <QWidget>
#include "editing/common/DrawingWidget.h"
#include "rendering/noise.h"
class WidgetTerrainBaseNoisePreview : public QWidget
class QPainter;
class WidgetTerrainBaseNoisePreview : public DrawingWidget
{
Q_OBJECT
public:
@ -13,11 +16,7 @@ public:
void setNoise(NoiseGenerator* noise);
protected:
virtual void paintEvent(QPaintEvent* event);
signals:
public slots:
virtual void doDrawing(QPainter* painter);
private:
NoiseGenerator* _noise;