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>
|
2011-12-26 21:53:29 +00:00
|
|
|
|
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-01-16 21:29:21 +00:00
|
|
|
|
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-01-18 19:49:03 +00:00
|
|
|
virtual QColor getColor(double x, double y);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
void configScaling(double min, double max, double step, double init, bool logarithmic = true);
|
2012-04-15 20:08:01 +00:00
|
|
|
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
|
2011-12-26 21:53:29 +00:00
|
|
|
|
|
|
|
double xoffset;
|
|
|
|
double yoffset;
|
|
|
|
double scaling;
|
|
|
|
|
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-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-01-25 22:32:06 +00:00
|
|
|
|
|
|
|
QMutex* lock_drawing;
|
2011-12-26 21:53:29 +00:00
|
|
|
QImage* pixbuf;
|
|
|
|
|
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-04-24 12:22:17 +00:00
|
|
|
double scalingbase;
|
|
|
|
|
2012-01-16 21:29:21 +00:00
|
|
|
bool alive;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
double conf_scroll_xmin;
|
|
|
|
double conf_scroll_xmax;
|
2012-04-15 20:08:01 +00:00
|
|
|
double conf_scroll_xinit;
|
2012-01-25 22:32:06 +00:00
|
|
|
double conf_scroll_ymin;
|
|
|
|
double conf_scroll_ymax;
|
2012-04-15 20:08:01 +00:00
|
|
|
double conf_scroll_yinit;
|
2012-01-25 22:32:06 +00:00
|
|
|
|
|
|
|
double conf_scale_min;
|
|
|
|
double conf_scale_max;
|
2012-04-12 20:02:31 +00:00
|
|
|
double conf_scale_init;
|
2012-01-25 22:32:06 +00:00
|
|
|
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();
|
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;
|
|
|
|
QMutex _lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-16 21:29:21 +00:00
|
|
|
#endif
|