2012-02-21 13:41:02 +00:00
|
|
|
#include "basepreview.h"
|
2012-02-06 20:54:23 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
#include <QVector>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
2012-02-06 20:54:23 +00:00
|
|
|
#include <QWheelEvent>
|
2012-07-01 13:27:57 +00:00
|
|
|
#include <QLabel>
|
2012-07-04 17:50:32 +00:00
|
|
|
#include <QMenu>
|
2012-08-09 17:45:39 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
2012-06-02 09:46:24 +00:00
|
|
|
#include "tools.h"
|
2012-07-01 13:27:57 +00:00
|
|
|
#include "../lib_paysages/system.h"
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
/*************** PreviewChunk ***************/
|
2012-04-29 15:14:37 +00:00
|
|
|
class PreviewChunk
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
PreviewChunk(BasePreview* preview, int xstart, int ystart, int xsize, int ysize)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
_preview = preview;
|
|
|
|
_xstart = xstart;
|
|
|
|
_ystart = ystart;
|
|
|
|
_xsize = xsize;
|
|
|
|
_ysize = ysize;
|
|
|
|
|
|
|
|
_need_render = true;
|
2012-08-09 17:45:39 +00:00
|
|
|
_rendering = false;
|
2012-04-30 19:25:30 +00:00
|
|
|
_alive = true;
|
2012-08-09 17:45:39 +00:00
|
|
|
_priority = xstart;
|
2012-01-18 16:20:14 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-06-27 13:05:57 +00:00
|
|
|
inline BasePreview* preview()
|
|
|
|
{
|
|
|
|
return _preview;
|
|
|
|
}
|
|
|
|
|
2012-08-09 17:45:39 +00:00
|
|
|
inline int priority()
|
|
|
|
{
|
|
|
|
return _priority;
|
|
|
|
}
|
|
|
|
|
2012-06-02 14:17:01 +00:00
|
|
|
inline bool isOnFront()
|
|
|
|
{
|
|
|
|
return _preview->isVisible() && _preview->window()->isActiveWindow();
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
bool isFrom(BasePreview* preview)
|
2012-01-18 16:20:14 +00:00
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
return _preview == preview;
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-30 19:25:30 +00:00
|
|
|
void interrupt()
|
|
|
|
{
|
|
|
|
_alive = false;
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void update()
|
2012-04-16 20:43:01 +00:00
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
_priority = _xstart;
|
2012-04-29 15:14:37 +00:00
|
|
|
_need_render = true;
|
2012-04-16 20:43:01 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
bool render()
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
bool changed = false;
|
2012-04-29 20:42:36 +00:00
|
|
|
int revision;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-08-09 17:45:39 +00:00
|
|
|
if (_rendering)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_rendering = true;
|
|
|
|
_alive = true;
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
if (_need_render)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-06-02 14:17:01 +00:00
|
|
|
if (!isOnFront())
|
2012-06-02 09:46:24 +00:00
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
_priority = -1;
|
|
|
|
_rendering = false;
|
2012-06-02 09:46:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_need_render = false;
|
2012-05-01 11:39:04 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
QImage pixbuf = _preview->startChunkTransaction(_xstart, _ystart, _xsize, _ysize, &revision);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
for (int x = 0; x < _xsize; x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < _ysize; y++)
|
|
|
|
{
|
2012-04-29 20:42:36 +00:00
|
|
|
QRgb col = pixbuf.pixel(x, y);
|
2012-04-30 19:25:30 +00:00
|
|
|
if (!_alive)
|
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
_need_render = true;
|
|
|
|
_preview->rollbackChunkTransaction();
|
|
|
|
_rendering = false;
|
|
|
|
return true;
|
2012-04-30 19:25:30 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
if (qAlpha(col) < 255)
|
|
|
|
{
|
|
|
|
QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y);
|
|
|
|
newcol.setAlpha(255);
|
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
pixbuf.setPixel(x, y, newcol.rgb());
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
_need_render = not _preview->commitChunkTransaction(&pixbuf, _xstart, _ystart, _xsize, _ysize, revision);
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
2012-07-23 16:56:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_preview->rollbackChunkTransaction();
|
|
|
|
}
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-08-09 17:45:39 +00:00
|
|
|
if (not _need_render)
|
|
|
|
{
|
|
|
|
_priority = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_rendering = false;
|
|
|
|
return _need_render;
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
2012-01-18 16:20:14 +00:00
|
|
|
private:
|
2012-02-21 13:41:02 +00:00
|
|
|
BasePreview* _preview;
|
2012-08-09 17:45:39 +00:00
|
|
|
int _priority;
|
2012-04-30 19:25:30 +00:00
|
|
|
bool _alive;
|
2012-04-29 15:14:37 +00:00
|
|
|
bool _need_render;
|
2012-08-09 17:45:39 +00:00
|
|
|
bool _rendering;
|
2012-04-29 15:14:37 +00:00
|
|
|
int _xstart;
|
|
|
|
int _ystart;
|
|
|
|
int _xsize;
|
|
|
|
int _ysize;
|
2011-12-26 21:53:29 +00:00
|
|
|
};
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
static PreviewDrawingManager* _drawing_manager = NULL;
|
|
|
|
|
|
|
|
/*************** PreviewDrawingThread ***************/
|
|
|
|
PreviewDrawingThread::PreviewDrawingThread() :
|
|
|
|
QThread()
|
|
|
|
{
|
|
|
|
_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewDrawingThread::askStop()
|
|
|
|
{
|
|
|
|
_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewDrawingThread::run()
|
|
|
|
{
|
|
|
|
_running = true;
|
|
|
|
while (_running)
|
|
|
|
{
|
|
|
|
_drawing_manager->performOneThreadJob();
|
2012-05-01 11:39:04 +00:00
|
|
|
QThread::usleep(5000);
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************** PreviewDrawingManager ***************/
|
|
|
|
PreviewDrawingManager::PreviewDrawingManager()
|
|
|
|
{
|
2012-07-01 13:27:57 +00:00
|
|
|
_thread_count = systemGetCoreCount();
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewDrawingManager::startThreads()
|
|
|
|
{
|
2012-05-01 11:39:04 +00:00
|
|
|
for (int i = 0; i < _thread_count; i++)
|
2012-04-29 15:14:37 +00:00
|
|
|
{
|
|
|
|
PreviewDrawingThread* thread = new PreviewDrawingThread();
|
|
|
|
_threads.append(thread);
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-30 19:25:30 +00:00
|
|
|
void PreviewDrawingManager::stopThreads()
|
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
logDebug(QString("[Previews] Stopping all render threads"));
|
2012-04-30 19:25:30 +00:00
|
|
|
for (int i = 0; i < _threads.size(); i++)
|
|
|
|
{
|
|
|
|
_threads.at(i)->askStop();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < _chunks.size(); i++)
|
|
|
|
{
|
|
|
|
_chunks.at(i)->interrupt();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < _threads.size(); i++)
|
|
|
|
{
|
|
|
|
_threads.at(i)->wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void PreviewDrawingManager::addChunk(PreviewChunk* chunk)
|
|
|
|
{
|
|
|
|
_lock.lock();
|
|
|
|
_chunks.append(chunk);
|
|
|
|
_updateQueue.append(chunk);
|
|
|
|
_lock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewDrawingManager::removeChunks(BasePreview* preview)
|
|
|
|
{
|
2012-06-07 20:17:04 +00:00
|
|
|
int removed = 0;
|
2012-04-29 15:14:37 +00:00
|
|
|
for (int i = 0; i < _chunks.size(); i++)
|
|
|
|
{
|
|
|
|
PreviewChunk* chunk;
|
|
|
|
chunk = _chunks.at(i);
|
|
|
|
if (chunk->isFrom(preview))
|
|
|
|
{
|
|
|
|
_lock.lock();
|
|
|
|
_chunks.remove(i);
|
|
|
|
_updateQueue.removeAll(chunk);
|
|
|
|
_lock.unlock();
|
|
|
|
|
2012-06-07 20:17:04 +00:00
|
|
|
removed++;
|
2012-04-29 15:14:37 +00:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2012-06-07 20:17:04 +00:00
|
|
|
|
|
|
|
logDebug(QString("[Previews] %1 chunks removed, %2 remaining").arg(removed).arg(_chunks.size()));
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 16:56:24 +00:00
|
|
|
void PreviewDrawingManager::suspendChunks(BasePreview* preview)
|
|
|
|
{
|
|
|
|
_lock.lock();
|
|
|
|
for (int i = 0; i < _updateQueue.size(); i++)
|
|
|
|
{
|
|
|
|
PreviewChunk* chunk;
|
|
|
|
chunk = _updateQueue.at(i);
|
|
|
|
if (chunk->isFrom(preview))
|
|
|
|
{
|
|
|
|
_updateQueue.takeAt(i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2012-08-09 17:45:39 +00:00
|
|
|
for (int i = 0; i < _chunks.size(); i++)
|
|
|
|
{
|
|
|
|
_chunks.at(i)->interrupt();
|
|
|
|
}
|
2012-07-23 16:56:24 +00:00
|
|
|
_lock.unlock();
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void PreviewDrawingManager::updateChunks(BasePreview* preview)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < _chunks.size(); i++)
|
|
|
|
{
|
|
|
|
PreviewChunk* chunk;
|
|
|
|
chunk = _chunks.at(i);
|
|
|
|
if (chunk->isFrom(preview))
|
|
|
|
{
|
|
|
|
chunk->update();
|
|
|
|
_lock.lock();
|
|
|
|
if (!_updateQueue.contains(chunk))
|
2012-06-27 13:05:57 +00:00
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
_updateQueue.prepend(chunk);
|
|
|
|
}
|
|
|
|
_lock.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-02 09:46:24 +00:00
|
|
|
void PreviewDrawingManager::updateAllChunks()
|
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
logDebug(QString("[Previews] Reviving all %1 preview chunks").arg(_chunks.size()));
|
2012-06-02 09:46:24 +00:00
|
|
|
for (int i = 0; i < _chunks.size(); i++)
|
|
|
|
{
|
|
|
|
PreviewChunk* chunk;
|
|
|
|
chunk = _chunks.at(i);
|
2012-06-02 14:17:01 +00:00
|
|
|
if (chunk->isOnFront())
|
|
|
|
{
|
|
|
|
chunk->update();
|
|
|
|
_lock.lock();
|
|
|
|
if (!_updateQueue.contains(chunk))
|
2012-06-27 13:05:57 +00:00
|
|
|
{
|
2012-06-02 14:17:01 +00:00
|
|
|
_updateQueue.prepend(chunk);
|
|
|
|
}
|
|
|
|
_lock.unlock();
|
2012-06-02 09:46:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-09 17:45:39 +00:00
|
|
|
static bool _cmpChunkPriority(const PreviewChunk* chunk1, const PreviewChunk* chunk2)
|
|
|
|
{
|
|
|
|
return ((PreviewChunk*)chunk1)->priority() < ((PreviewChunk*)chunk2)->priority();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void PreviewDrawingManager::performOneThreadJob()
|
|
|
|
{
|
|
|
|
PreviewChunk* chunk;
|
2012-04-30 19:25:30 +00:00
|
|
|
|
|
|
|
chunk = NULL;
|
|
|
|
_lock.lock();
|
|
|
|
if (!_updateQueue.isEmpty())
|
2012-04-29 15:14:37 +00:00
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
qSort(_updateQueue.begin(), _updateQueue.end(), _cmpChunkPriority);
|
|
|
|
chunk = _updateQueue.takeFirst();
|
2012-04-30 19:25:30 +00:00
|
|
|
}
|
|
|
|
_lock.unlock();
|
|
|
|
|
|
|
|
if (chunk)
|
|
|
|
{
|
2012-08-09 17:45:39 +00:00
|
|
|
if (chunk->render())
|
|
|
|
{
|
|
|
|
_lock.lock();
|
|
|
|
if (!_updateQueue.contains(chunk))
|
|
|
|
{
|
|
|
|
_updateQueue.append(chunk);
|
|
|
|
}
|
|
|
|
_lock.unlock();
|
|
|
|
}
|
2012-04-30 19:25:30 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
|
2012-06-07 20:17:04 +00:00
|
|
|
int PreviewDrawingManager::chunkCount()
|
|
|
|
{
|
|
|
|
return _chunks.size();
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
/*************** BasePreview ***************/
|
2012-02-21 13:41:02 +00:00
|
|
|
BasePreview::BasePreview(QWidget* parent) :
|
2012-04-29 15:14:37 +00:00
|
|
|
QWidget(parent)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_lock_drawing = new QMutex();
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
this->conf_scroll_xmin = 0.0;
|
|
|
|
this->conf_scroll_xmax = 0.0;
|
2012-04-15 20:08:01 +00:00
|
|
|
this->conf_scroll_xinit = 0.0;
|
2011-12-26 21:53:29 +00:00
|
|
|
this->conf_scroll_ymin = 0.0;
|
|
|
|
this->conf_scroll_ymax = 0.0;
|
2012-04-15 20:08:01 +00:00
|
|
|
this->conf_scroll_yinit = 0.0;
|
2011-12-26 21:53:29 +00:00
|
|
|
this->conf_scale_min = 1.0;
|
|
|
|
this->conf_scale_max = 1.0;
|
2012-04-12 20:02:31 +00:00
|
|
|
this->conf_scale_init = 1.0;
|
2011-12-26 21:53:29 +00:00
|
|
|
this->conf_scale_step = 0.0;
|
2012-04-24 12:22:17 +00:00
|
|
|
this->conf_scroll_logarithmic = false;
|
2011-12-26 21:53:29 +00:00
|
|
|
this->scaling = 1.0;
|
2012-04-24 12:22:17 +00:00
|
|
|
this->scalingbase = 1.0;
|
2011-12-26 21:53:29 +00:00
|
|
|
this->xoffset = 0.0;
|
|
|
|
this->yoffset = 0.0;
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_pixbuf = new QImage(this->size(), QImage::Format_ARGB32);
|
|
|
|
this->_pixbuf->fill(0x00000000);
|
2012-04-29 15:14:37 +00:00
|
|
|
_width = width();
|
|
|
|
_height = height();
|
2012-04-29 20:42:36 +00:00
|
|
|
_revision = 0;
|
2012-07-23 16:56:24 +00:00
|
|
|
_transactions_count = 0;
|
|
|
|
_redraw_requested = false;
|
2012-06-27 09:48:55 +00:00
|
|
|
|
|
|
|
_info = new QLabel(this);
|
|
|
|
_info->setVisible(false);
|
|
|
|
_info->setStyleSheet("QLabel { background-color: white; color: black; }");
|
2012-01-16 21:29:21 +00:00
|
|
|
|
|
|
|
this->alive = true;
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-04-16 20:43:01 +00:00
|
|
|
QObject::connect(this, SIGNAL(contentChange()), this, SLOT(update()));
|
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
this->setMinimumSize(256, 256);
|
|
|
|
this->setMaximumSize(256, 256);
|
|
|
|
this->resize(256, 256);
|
2012-07-23 16:56:24 +00:00
|
|
|
|
|
|
|
startTimer(50);
|
2012-01-16 21:29:21 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
BasePreview::~BasePreview()
|
2012-01-16 21:29:21 +00:00
|
|
|
{
|
2012-01-18 16:20:14 +00:00
|
|
|
alive = false;
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
_drawing_manager->removeChunks(this);
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2012-06-27 09:48:55 +00:00
|
|
|
delete _info;
|
2012-07-04 17:50:32 +00:00
|
|
|
delete _pixbuf;
|
|
|
|
delete _lock_drawing;
|
2012-02-05 12:17:51 +00:00
|
|
|
}
|
2012-01-25 22:32:06 +00:00
|
|
|
|
2012-06-25 20:11:15 +00:00
|
|
|
void BasePreview::addOsd(QString name)
|
|
|
|
{
|
|
|
|
_osd.append(PreviewOsd::getInstance(name));
|
2012-06-27 09:48:55 +00:00
|
|
|
setMouseTracking(true);
|
2012-06-25 20:11:15 +00:00
|
|
|
}
|
|
|
|
|
2012-06-27 10:30:00 +00:00
|
|
|
void BasePreview::savePack(PackStream* stream)
|
|
|
|
{
|
|
|
|
packWriteDouble(stream, &this->xoffset);
|
|
|
|
packWriteDouble(stream, &this->yoffset);
|
2012-07-10 19:39:12 +00:00
|
|
|
packWriteDouble(stream, &this->scalingbase);
|
2012-07-04 17:50:32 +00:00
|
|
|
|
|
|
|
// TODO Save choices and toggles
|
2012-06-27 10:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::loadPack(PackStream* stream)
|
|
|
|
{
|
|
|
|
packReadDouble(stream, &this->xoffset);
|
|
|
|
packReadDouble(stream, &this->yoffset);
|
2012-07-10 19:39:12 +00:00
|
|
|
packReadDouble(stream, &this->scalingbase);
|
2012-07-04 17:50:32 +00:00
|
|
|
|
|
|
|
// TODO Save choices and toggles
|
|
|
|
|
2012-07-10 19:39:12 +00:00
|
|
|
updateScaling();
|
2012-06-27 10:30:00 +00:00
|
|
|
emit contentChange();
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void BasePreview::initDrawers()
|
|
|
|
{
|
|
|
|
_drawing_manager = new PreviewDrawingManager();
|
|
|
|
_drawing_manager->startThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::stopDrawers()
|
|
|
|
{
|
2012-04-30 19:25:30 +00:00
|
|
|
_drawing_manager->stopThreads();
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 09:46:24 +00:00
|
|
|
void BasePreview::reviveAll()
|
|
|
|
{
|
|
|
|
_drawing_manager->updateAllChunks();
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
void BasePreview::updateData()
|
2012-01-25 22:32:06 +00:00
|
|
|
{
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
QColor BasePreview::getColor(double, double)
|
2012-01-18 19:49:03 +00:00
|
|
|
{
|
|
|
|
return QColor(0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double size = (double) width();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
if (size >= 1.0)
|
|
|
|
{
|
|
|
|
conf_scale_min = min / size;
|
|
|
|
conf_scale_max = max / size;
|
|
|
|
conf_scale_step = step / size;
|
|
|
|
conf_scale_init = init / size;
|
2012-04-24 12:22:17 +00:00
|
|
|
conf_scroll_logarithmic = logarithmic;
|
|
|
|
scalingbase = init / size;
|
|
|
|
if (conf_scroll_logarithmic && conf_scale_max - conf_scale_min > 0.0000001)
|
|
|
|
{
|
|
|
|
scalingbase = pow((scalingbase - conf_scale_min) / (conf_scale_max - conf_scale_min), 0.5) * (conf_scale_max - conf_scale_min) + conf_scale_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateScaling();
|
2012-04-12 20:02:31 +00:00
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void BasePreview::configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit)
|
2012-04-15 20:08:01 +00:00
|
|
|
{
|
|
|
|
conf_scroll_xmin = xmin;
|
|
|
|
conf_scroll_xmax = xmax;
|
|
|
|
conf_scroll_xinit = xinit;
|
|
|
|
conf_scroll_ymin = ymin;
|
|
|
|
conf_scroll_ymax = ymax;
|
|
|
|
conf_scroll_yinit = yinit;
|
|
|
|
xoffset = xinit;
|
|
|
|
yoffset = yinit;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
void BasePreview::addChoice(const QString& key, const QString& title, const QStringList& choices, int init_value)
|
|
|
|
{
|
|
|
|
_ContextChoice choice;
|
|
|
|
choice.title = title;
|
|
|
|
choice.items << choices;
|
|
|
|
choice.current = init_value;
|
|
|
|
|
|
|
|
_choices.insert(key, choice);
|
|
|
|
|
|
|
|
choiceChangeEvent(key, init_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::choiceChangeEvent(const QString&, int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::addToggle(const QString& key, const QString& text, bool init_value)
|
|
|
|
{
|
|
|
|
_ContextToggle toggle;
|
|
|
|
toggle.title = text;
|
|
|
|
toggle.value = init_value;
|
|
|
|
|
|
|
|
_toggles.insert(key, toggle);
|
|
|
|
|
|
|
|
toggleChangeEvent(key, init_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::toggleChangeEvent(QString, bool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
void BasePreview::redraw()
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
2012-07-23 16:56:24 +00:00
|
|
|
_drawing_manager->suspendChunks(this);
|
|
|
|
_redraw_requested = true;
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
QImage BasePreview::startChunkTransaction(int x, int y, int w, int h, int* revision)
|
|
|
|
{
|
2012-07-23 16:56:24 +00:00
|
|
|
QImage result;
|
|
|
|
|
|
|
|
_lock_drawing->lock();
|
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
*revision = _revision;
|
2012-07-23 16:56:24 +00:00
|
|
|
result = _pixbuf->copy(x, y, w, h);
|
|
|
|
_transactions_count++;
|
|
|
|
|
|
|
|
_lock_drawing->unlock();
|
|
|
|
|
|
|
|
return result;
|
2012-04-29 20:42:36 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 16:56:24 +00:00
|
|
|
bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision)
|
2012-04-29 20:42:36 +00:00
|
|
|
{
|
2012-07-23 16:56:24 +00:00
|
|
|
bool result;
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
2012-07-23 16:56:24 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
if (revision == _revision)
|
|
|
|
{
|
|
|
|
for (int ix = 0; ix < w; ix++)
|
|
|
|
{
|
|
|
|
for (int iy = 0; iy < h; iy++)
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
_pixbuf->setPixel(x + ix, y + iy, chunk->pixel(ix, iy));
|
2012-04-29 20:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
emit contentChange();
|
2012-07-23 16:56:24 +00:00
|
|
|
result = true;
|
2012-04-29 20:42:36 +00:00
|
|
|
}
|
2012-07-23 16:56:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_transactions_count--;
|
|
|
|
|
|
|
|
_lock_drawing->unlock();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::rollbackChunkTransaction()
|
|
|
|
{
|
|
|
|
_lock_drawing->lock();
|
|
|
|
|
|
|
|
_transactions_count--;
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
2012-04-29 20:42:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
QColor BasePreview::getPixelColor(int x, int y)
|
2011-12-27 19:03:46 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset);
|
2012-01-25 22:32:06 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 16:56:24 +00:00
|
|
|
void BasePreview::timerEvent(QTimerEvent*)
|
2012-01-25 22:32:06 +00:00
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-23 16:56:24 +00:00
|
|
|
if (_redraw_requested && _transactions_count == 0)
|
|
|
|
{
|
|
|
|
updateData();
|
|
|
|
invalidatePixbuf(128);
|
|
|
|
_redraw_requested = false;
|
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::choiceSelected(QAction* action)
|
|
|
|
{
|
|
|
|
switch (action->property("mode").toInt())
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
QString key = action->property("key").toString();
|
|
|
|
int value = action->property("value").toInt();
|
|
|
|
|
|
|
|
_choices[key].current = value;
|
|
|
|
|
|
|
|
choiceChangeEvent(key, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
QString key = action->property("key").toString();
|
|
|
|
bool value = action->property("value").toBool();
|
|
|
|
|
|
|
|
_toggles[key].value = value;
|
|
|
|
|
|
|
|
toggleChangeEvent(key, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2011-12-27 19:03:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
void BasePreview::showEvent(QShowEvent*)
|
2012-05-01 11:39:04 +00:00
|
|
|
{
|
|
|
|
updateChunks();
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
void BasePreview::resizeEvent(QResizeEvent* event)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
|
|
|
QImage* image;
|
2012-06-07 20:17:04 +00:00
|
|
|
int added = 0;
|
2011-12-26 21:53:29 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_lock_drawing->lock();
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
image = this->_pixbuf;
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-04-29 15:14:37 +00:00
|
|
|
_width = event->size().width();
|
|
|
|
_height = event->size().height();
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_pixbuf = new QImage(this->size(), QImage::Format_ARGB32);
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_pixbuf->fill(0x00000000);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
|
|
|
_drawing_manager->removeChunks(this);
|
|
|
|
for (int x = 0; x < _width; x += 32)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < _height; y += 32)
|
|
|
|
{
|
2012-04-29 20:42:36 +00:00
|
|
|
_drawing_manager->addChunk(new PreviewChunk(this, x, y, x + 32 > _width ? _width - x : 32, y + 32 > _height ? _height - y : 32));
|
2012-06-07 20:17:04 +00:00
|
|
|
added++;
|
2012-04-29 15:14:37 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-07 20:17:04 +00:00
|
|
|
logDebug(QString("[Previews] %1 chunks added, %2 total").arg(added).arg(_drawing_manager->chunkCount()));
|
2012-01-22 18:39:42 +00:00
|
|
|
|
2011-12-26 21:53:29 +00:00
|
|
|
delete image;
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
this->_lock_drawing->unlock();
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
void BasePreview::paintEvent(QPaintEvent*)
|
2011-12-26 21:53:29 +00:00
|
|
|
{
|
|
|
|
QPainter painter(this);
|
2012-07-04 17:50:32 +00:00
|
|
|
painter.drawImage(0, 0, *this->_pixbuf);
|
2012-06-25 20:11:15 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
QImage osd(_pixbuf->size(), _pixbuf->format());
|
2012-06-25 20:11:15 +00:00
|
|
|
osd.fill(0x00000000);
|
|
|
|
for (int i = 0; i < _osd.size(); i++)
|
|
|
|
{
|
|
|
|
_osd[i]->apply(&osd, xoffset, yoffset, scaling);
|
|
|
|
}
|
|
|
|
painter.drawImage(0, 0, osd);
|
2011-12-26 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 12:22:17 +00:00
|
|
|
void BasePreview::updateScaling()
|
|
|
|
{
|
|
|
|
if (conf_scroll_logarithmic && conf_scale_max - conf_scale_min > 0.0000001)
|
|
|
|
{
|
|
|
|
scaling = pow((scalingbase - conf_scale_min) / (conf_scale_max - conf_scale_min), 2.0) * (conf_scale_max - conf_scale_min) + conf_scale_min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scaling = scalingbase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
void BasePreview::updateChunks()
|
|
|
|
{
|
|
|
|
_drawing_manager->updateChunks(this);
|
|
|
|
_revision++;
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:41:15 +00:00
|
|
|
void BasePreview::invalidatePixbuf(int value)
|
|
|
|
{
|
|
|
|
for (int ix = 0; ix < _width; ix++)
|
|
|
|
{
|
|
|
|
for (int iy = 0; iy < _height; iy++)
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
QRgb col = _pixbuf->pixel(ix, iy);
|
2012-05-03 18:41:15 +00:00
|
|
|
if (qAlpha(col) == 255)
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
_pixbuf->setPixel(ix, iy, qRgba(qRed(col), qGreen(col), qBlue(col), value));
|
2012-05-03 18:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateChunks();
|
|
|
|
}
|
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
void BasePreview::contextMenuEvent(QContextMenuEvent* event)
|
|
|
|
{
|
|
|
|
QMenu menu(this);
|
|
|
|
|
|
|
|
// TODO Get menu items from OSDs
|
|
|
|
|
|
|
|
// Fill with choices
|
|
|
|
QHashIterator<QString, _ContextChoice> iter1(_choices);
|
|
|
|
while (iter1.hasNext())
|
|
|
|
{
|
|
|
|
if (not menu.isEmpty())
|
|
|
|
{
|
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
iter1.next();
|
|
|
|
menu.addAction(QString(" %1 ").arg(iter1.value().title))->setDisabled(true);
|
|
|
|
|
|
|
|
QStringList list = iter1.value().items;
|
|
|
|
for (int i = 0; i < list.count(); i++)
|
|
|
|
{
|
|
|
|
QAction* action = menu.addAction(list[i]);
|
|
|
|
action->setProperty("mode", 1);
|
|
|
|
action->setProperty("key", iter1.key());
|
|
|
|
action->setProperty("value", i);
|
|
|
|
if (i == iter1.value().current)
|
|
|
|
{
|
|
|
|
action->setIcon(QIcon("images/choice_on.png"));
|
|
|
|
action->setIconVisibleInMenu(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill with toggles
|
|
|
|
QHashIterator<QString, _ContextToggle> iter2(_toggles);
|
|
|
|
while (iter2.hasNext())
|
|
|
|
{
|
|
|
|
if (not menu.isEmpty() and not iter2.hasPrevious())
|
|
|
|
{
|
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
iter2.next();
|
|
|
|
|
|
|
|
QAction* action = menu.addAction(iter2.value().title);
|
|
|
|
action->setProperty("mode", 2);
|
|
|
|
action->setProperty("key", iter2.key());
|
|
|
|
action->setProperty("value", not iter2.value().value);
|
|
|
|
if (iter2.value().value)
|
|
|
|
{
|
|
|
|
action->setIcon(QIcon("images/toggle_on.png"));
|
|
|
|
action->setIconVisibleInMenu(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not menu.isEmpty())
|
|
|
|
{
|
|
|
|
connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(choiceSelected(QAction*)));
|
|
|
|
|
|
|
|
menu.exec(event->globalPos());
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-15 20:08:01 +00:00
|
|
|
void BasePreview::mousePressEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
mousex = event->x();
|
|
|
|
mousey = event->y();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BasePreview::mouseMoveEvent(QMouseEvent* event)
|
|
|
|
{
|
|
|
|
int width, height;
|
2012-06-27 09:48:55 +00:00
|
|
|
|
|
|
|
width = this->width();
|
|
|
|
height = this->height();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-15 20:08:01 +00:00
|
|
|
if (event->buttons() & Qt::LeftButton)
|
|
|
|
{
|
2012-06-27 09:48:55 +00:00
|
|
|
int dx, dy;
|
|
|
|
int ndx, ndy;
|
|
|
|
|
2012-04-15 20:08:01 +00:00
|
|
|
dx = event->x() - mousex;
|
|
|
|
dy = event->y() - mousey;
|
|
|
|
|
|
|
|
ndx = dx;
|
|
|
|
ndy = dy;
|
|
|
|
if (xoffset - dx * scaling > conf_scroll_xmax)
|
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
ndx = (int) floor((conf_scroll_xmax - xoffset) / scaling);
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
if (xoffset - dx * scaling < conf_scroll_xmin)
|
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
ndx = (int) floor((conf_scroll_xmin - xoffset) / scaling);
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
if (yoffset - dy * scaling > conf_scroll_ymax)
|
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
ndy = (int) floor((conf_scroll_ymax - yoffset) / scaling);
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
if (yoffset - dy * scaling < conf_scroll_ymin)
|
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
ndy = (int) floor((conf_scroll_ymin - yoffset) / scaling);
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
if (ndx != 0 || ndy != 0)
|
|
|
|
{
|
|
|
|
if (ndx <= -width || ndx >= width || ndy <= -height || ndy >= height)
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
xoffset -= (double) ndx * scaling;
|
|
|
|
yoffset -= (double) ndy * scaling;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
|
|
|
_pixbuf->fill(0x00000000);
|
2012-04-29 20:42:36 +00:00
|
|
|
updateChunks();
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int xstart, xsize, ystart, ysize;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
2012-04-15 20:08:01 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
xoffset -= (double) ndx * scaling;
|
|
|
|
yoffset -= (double) ndy * scaling;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-15 20:08:01 +00:00
|
|
|
if (ndx < 0)
|
|
|
|
{
|
|
|
|
xstart = -ndx;
|
|
|
|
xsize = width + ndx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xstart = 0;
|
|
|
|
xsize = width - ndx;
|
|
|
|
}
|
|
|
|
if (ndy < 0)
|
|
|
|
{
|
|
|
|
ystart = -ndy;
|
|
|
|
ysize = height + ndy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ystart = 0;
|
|
|
|
ysize = height - ndy;
|
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
QImage part = _pixbuf->copy(xstart, ystart, xsize, ysize);
|
|
|
|
_pixbuf->fill(0x00000000);
|
|
|
|
QPainter painter(_pixbuf);
|
2012-04-15 20:08:01 +00:00
|
|
|
painter.drawImage(xstart + ndx, ystart + ndy, part);
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-29 20:42:36 +00:00
|
|
|
updateChunks();
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-16 15:26:56 +00:00
|
|
|
emit contentChange();
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mousex = event->x();
|
|
|
|
mousey = event->y();
|
|
|
|
}
|
2012-06-27 09:48:55 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get text info from OSD
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < _osd.size(); i++)
|
|
|
|
{
|
|
|
|
double x = xoffset + (event->x() - width / 2) * scaling;
|
|
|
|
double y = yoffset + (event->y() - height / 2) * scaling;
|
|
|
|
QString info = _osd[i]->getToolTip(x, y, scaling);
|
|
|
|
if (not info.isEmpty())
|
|
|
|
{
|
|
|
|
_info->setText(info);
|
|
|
|
_info->setVisible(true);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (not found)
|
|
|
|
{
|
|
|
|
_info->setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
2012-04-15 20:08:01 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
void BasePreview::wheelEvent(QWheelEvent* event)
|
2012-02-06 20:54:23 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double factor;
|
|
|
|
double old_scaling;
|
2012-04-15 20:08:01 +00:00
|
|
|
int width, height;
|
|
|
|
int new_width, new_height;
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-12 20:02:31 +00:00
|
|
|
if (event->modifiers() & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
factor = 5.0;
|
|
|
|
}
|
|
|
|
else if (event->modifiers() & Qt::ControlModifier)
|
|
|
|
{
|
|
|
|
factor = 0.2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
factor = 1.0;
|
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-02-06 20:54:23 +00:00
|
|
|
if (event->orientation() == Qt::Vertical)
|
|
|
|
{
|
2012-04-29 15:14:37 +00:00
|
|
|
if (event->delta() > 0 && scalingbase > conf_scale_min)
|
2012-02-06 20:54:23 +00:00
|
|
|
{
|
2012-04-24 12:22:17 +00:00
|
|
|
scalingbase -= factor * conf_scale_step;
|
|
|
|
if (scalingbase < conf_scale_min)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2012-04-24 12:22:17 +00:00
|
|
|
scalingbase = conf_scale_min;
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
2012-02-06 20:54:23 +00:00
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
else if (event->delta() < 0 && scalingbase < conf_scale_max)
|
2012-02-06 20:54:23 +00:00
|
|
|
{
|
2012-04-24 12:22:17 +00:00
|
|
|
scalingbase += factor * conf_scale_step;
|
|
|
|
if (scalingbase > conf_scale_max)
|
2012-04-12 20:02:31 +00:00
|
|
|
{
|
2012-04-24 12:22:17 +00:00
|
|
|
scalingbase = conf_scale_max;
|
2012-04-12 20:02:31 +00:00
|
|
|
}
|
2012-02-06 20:54:23 +00:00
|
|
|
}
|
2012-04-24 12:22:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
2012-02-06 20:54:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event->ignore();
|
2012-04-24 12:22:17 +00:00
|
|
|
return;
|
2012-02-06 20:54:23 +00:00
|
|
|
}
|
2012-04-24 12:22:17 +00:00
|
|
|
|
|
|
|
old_scaling = scaling;
|
|
|
|
updateScaling();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-07-04 17:50:32 +00:00
|
|
|
width = _pixbuf->width();
|
|
|
|
height = _pixbuf->height();
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-24 12:22:17 +00:00
|
|
|
if (scaling < old_scaling)
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
2012-06-17 09:40:40 +00:00
|
|
|
new_width = (int) floor(((double) width) * scaling / old_scaling);
|
|
|
|
new_height = (int) floor(((double) height) * scaling / old_scaling);
|
2012-07-04 17:50:32 +00:00
|
|
|
QImage part = _pixbuf->copy((width - new_width) / 2, (height - new_height) / 2, new_width, new_height).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
_pixbuf->fill(0x00000000);
|
|
|
|
QPainter painter(_pixbuf);
|
2012-04-24 12:22:17 +00:00
|
|
|
painter.drawImage(0, 0, part);
|
2012-05-03 18:41:15 +00:00
|
|
|
invalidatePixbuf(254);
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
2012-04-24 12:22:17 +00:00
|
|
|
|
|
|
|
emit contentChange();
|
|
|
|
}
|
|
|
|
else if (scaling > old_scaling)
|
|
|
|
{
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->lock();
|
|
|
|
QImage part = _pixbuf->scaled((int) floor(((double) width) * old_scaling / scaling), (int) floor(((double) height) * old_scaling / scaling), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
_pixbuf->fill(0x00000000);
|
|
|
|
QPainter painter(_pixbuf);
|
2012-04-24 12:22:17 +00:00
|
|
|
painter.drawImage((width - part.width()) / 2, (height - part.height()) / 2, part);
|
2012-05-03 18:41:15 +00:00
|
|
|
invalidatePixbuf(254);
|
2012-07-04 17:50:32 +00:00
|
|
|
_lock_drawing->unlock();
|
2012-04-24 12:22:17 +00:00
|
|
|
|
|
|
|
emit contentChange();
|
|
|
|
}
|
2012-04-29 15:14:37 +00:00
|
|
|
|
2012-04-24 12:22:17 +00:00
|
|
|
event->accept();
|
2012-02-06 20:54:23 +00:00
|
|
|
}
|
2012-06-27 09:48:55 +00:00
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
void BasePreview::leaveEvent(QEvent*)
|
2012-06-27 09:48:55 +00:00
|
|
|
{
|
|
|
|
_info->setVisible(false);
|
|
|
|
}
|