2012-02-21 13:41:02 +00:00
|
|
|
#ifndef _PAYSAGES_QT_BASEPREVIEW_H_
|
|
|
|
#define _PAYSAGES_QT_BASEPREVIEW_H_
|
2011-12-26 21:53:29 +00:00
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QWidget>
|
2012-01-18 16:20:14 +00:00
|
|
|
#include <QThread>
|
2012-04-29 15:14:37 +00:00
|
|
|
#include <QVector>
|
|
|
|
#include <QList>
|
2012-06-27 09:48:55 +00:00
|
|
|
#include <QLabel>
|
2012-07-04 17:57:51 +00:00
|
|
|
#include <QHash>
|
2012-06-25 20:11:15 +00:00
|
|
|
#include "previewosd.h"
|
2012-06-27 10:30:00 +00:00
|
|
|
#include "../lib_paysages/pack.h"
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
class _ContextChoice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString title;
|
|
|
|
QStringList items;
|
|
|
|
int current;
|
|
|
|
};
|
|
|
|
|
|
|
|
class _ContextToggle
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString title;
|
|
|
|
bool value;
|
|
|
|
};
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
class BasePreview : public QWidget {
|
2012-01-05 18:39:17 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
public:
|
2012-02-21 13:41:02 +00:00
|
|
|
BasePreview(QWidget* parent);
|
|
|
|
~BasePreview();
|
2012-06-25 20:11:15 +00:00
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
virtual void savePack(PackStream* stream);
|
|
|
|
virtual void loadPack(PackStream* stream);
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
static void initDrawers();
|
|
|
|
static void stopDrawers();
|
2012-06-02 09:46:24 +00:00
|
|
|
static void reviveAll();
|
2012-04-29 20:42:36 +00:00
|
|
|
|
2011-12-27 19:03:46 +00:00
|
|
|
void redraw();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
QImage startChunkTransaction(int x, int y, int w, int h, int* revision);
|
|
|
|
void commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
QColor getPixelColor(int x, int y);
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
protected:
|
2012-01-25 22:32:06 +00:00
|
|
|
virtual void updateData();
|
2012-06-17 09:40:40 +00:00
|
|
|
virtual QColor getColor(double x, double y);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void configScaling(double min, double max, double step, double init, bool logarithmic = true);
|
|
|
|
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
void addOsd(QString name);
|
|
|
|
|
|
|
|
void addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value);
|
|
|
|
virtual void choiceChangeEvent(const QString& key, int position);
|
|
|
|
|
|
|
|
void addToggle(const QString& key, const QString& text, bool init_value);
|
|
|
|
virtual void toggleChangeEvent(QString key, bool value);
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double xoffset;
|
|
|
|
double yoffset;
|
|
|
|
double scaling;
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
private:
|
2012-04-24 12:22:17 +00:00
|
|
|
void updateScaling();
|
2012-04-29 20:42:36 +00:00
|
|
|
void updateChunks();
|
2012-05-03 18:41:15 +00:00
|
|
|
void invalidatePixbuf(int value);
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2012-05-01 11:39:04 +00:00
|
|
|
void showEvent(QShowEvent* event);
|
2012-01-25 22:32:06 +00:00
|
|
|
void resizeEvent(QResizeEvent* event);
|
|
|
|
void paintEvent(QPaintEvent* event);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent* event);
|
2012-04-15 20:08:01 +00:00
|
|
|
void mousePressEvent(QMouseEvent* event);
|
|
|
|
void mouseMoveEvent(QMouseEvent* event);
|
2012-02-06 20:54:23 +00:00
|
|
|
void wheelEvent(QWheelEvent* event);
|
2012-06-27 09:48:55 +00:00
|
|
|
void leaveEvent(QEvent* event);
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
QMutex* _lock_drawing;
|
|
|
|
QImage* _pixbuf;
|
2012-06-25 20:11:15 +00:00
|
|
|
QVector<PreviewOsd*> _osd;
|
2012-07-04 17:50:32 +00:00
|
|
|
QHash<QString, _ContextChoice> _choices;
|
|
|
|
QHash<QString, _ContextToggle> _toggles;
|
2012-06-27 09:48:55 +00:00
|
|
|
|
|
|
|
QLabel* _info;
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
int _width;
|
|
|
|
int _height;
|
2012-04-29 20:42:36 +00:00
|
|
|
|
|
|
|
int _revision;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
int mousex;
|
|
|
|
int mousey;
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double scalingbase;
|
2012-04-24 12:22:17 +00:00
|
|
|
|
2012-01-16 21:29:21 +00:00
|
|
|
bool alive;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
double conf_scroll_xmin;
|
|
|
|
double conf_scroll_xmax;
|
|
|
|
double conf_scroll_xinit;
|
|
|
|
double conf_scroll_ymin;
|
|
|
|
double conf_scroll_ymax;
|
|
|
|
double conf_scroll_yinit;
|
|
|
|
|
|
|
|
double conf_scale_min;
|
|
|
|
double conf_scale_max;
|
|
|
|
double conf_scale_init;
|
|
|
|
double conf_scale_step;
|
2012-04-24 12:22:17 +00:00
|
|
|
bool conf_scroll_logarithmic;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
void contentChange();
|
2012-01-25 22:32:06 +00:00
|
|
|
void redrawRequested();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void handleRedraw();
|
2012-07-04 17:50:32 +00:00
|
|
|
void choiceSelected(QAction* action);
|
2011-12-26 21:53:29 +00:00
|
|
|
};
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*** Private section ***/
|
|
|
|
class PreviewChunk;
|
|
|
|
|
|
|
|
class PreviewDrawingThread : public QThread {
|
|
|
|
public:
|
|
|
|
PreviewDrawingThread();
|
|
|
|
void askStop();
|
|
|
|
|
|
|
|
static inline void usleep(int us) {
|
|
|
|
QThread::usleep(us);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool _running;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PreviewDrawingManager {
|
|
|
|
public:
|
|
|
|
PreviewDrawingManager();
|
|
|
|
void startThreads();
|
2012-04-30 19:25:30 +00:00
|
|
|
void stopThreads();
|
2012-04-29 15:14:37 +00:00
|
|
|
void addChunk(PreviewChunk* chunk);
|
|
|
|
void removeChunks(BasePreview* preview);
|
|
|
|
void updateChunks(BasePreview* preview);
|
2012-06-02 09:46:24 +00:00
|
|
|
void updateAllChunks();
|
2012-04-29 15:14:37 +00:00
|
|
|
void performOneThreadJob();
|
2012-06-07 20:17:04 +00:00
|
|
|
int chunkCount();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _thread_count;
|
|
|
|
QVector<PreviewDrawingThread*> _threads;
|
|
|
|
QVector<PreviewChunk*> _chunks;
|
|
|
|
QList<PreviewChunk*> _updateQueue;
|
2012-06-27 13:05:57 +00:00
|
|
|
BasePreview* _lastRendered;
|
2012-04-29 15:14:37 +00:00
|
|
|
QMutex _lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-16 21:29:21 +00:00
|
|
|
#endif
|