?? transactionthread.cpp
字號:
#include <QtGui>#include "transactionthread.h"using namespace std;FlipTransaction::FlipTransaction(Qt::Orientation orientation){ this->orientation = orientation;}QImage FlipTransaction::apply(const QImage &image){ return image.mirrored(orientation == Qt::Horizontal, orientation == Qt::Vertical);}QString FlipTransaction::message(){ if (orientation == Qt::Horizontal) { return QObject::tr("Flipping image horizontally..."); } else { return QObject::tr("Flipping image vertically..."); }}ResizeTransaction::ResizeTransaction(const QSize &size){ this->size = size;}QString ResizeTransaction::message(){ return QObject::tr("Resizing image...");}QImage ResizeTransaction::apply(const QImage &image){ return image.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);}ConvertDepthTransaction::ConvertDepthTransaction(int depth){ this->depth = depth;}QImage ConvertDepthTransaction::apply(const QImage &image){ QImage::Format format; switch (depth) { case 1: format = QImage::Format_Mono; break; case 8: format = QImage::Format_Indexed8; break; case 24: default: format = QImage::Format_RGB32; } return image.convertToFormat(format);}QString ConvertDepthTransaction::message(){ return QObject::tr("Converting image depth...");}void TransactionThread::addTransaction(Transaction *transact){ QMutexLocker locker(&mutex); transactions.enqueue(transact); if (!isRunning()) start();}void TransactionThread::run(){ Transaction *transact; forever { mutex.lock(); if (transactions.isEmpty()) { mutex.unlock(); break; } QImage oldImage = currentImage; transact = transactions.dequeue(); mutex.unlock(); emit transactionStarted(transact->message()); QImage newImage = transact->apply(oldImage); delete transact; mutex.lock(); currentImage = newImage; mutex.unlock(); }}void TransactionThread::setImage(const QImage &image){ QMutexLocker locker(&mutex); currentImage = image;}QImage TransactionThread::image(){ QMutexLocker locker(&mutex); return currentImage;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -