#include <imagecomposer.h>
Inheritance diagram for ImageComposer:


Definition at line 34 of file imagecomposer.h.
Public Member Functions | |
| ImageComposer () | |
Private Slots | |
| void | chooseSource () |
| void | chooseDestination () |
| void | recalculateResult () |
Private Member Functions | |
| void | addOp (QPainter::CompositionMode mode, const QString &name) |
| void | chooseImage (const QString &title, QImage *image, QToolButton *button) |
| void | loadImage (const QString &fileName, QImage *image, QToolButton *button) |
| QPainter::CompositionMode | currentMode () const |
| QPoint | imagePos (const QImage &image) const |
Private Attributes | |
| QToolButton * | sourceButton |
| QToolButton * | destinationButton |
| QComboBox * | operatorComboBox |
| QLabel * | equalLabel |
| QLabel * | resultLabel |
| QImage | sourceImage |
| QImage | destinationImage |
| QImage | resultImage |
| ImageComposer::ImageComposer | ( | ) |
Definition at line 30 of file imagecomposer.cpp.
References addOp(), QGridLayout::addWidget(), chooseDestination(), chooseSource(), QPainter::CompositionMode_Clear, QPainter::CompositionMode_Destination, QPainter::CompositionMode_DestinationAtop, QPainter::CompositionMode_DestinationIn, QPainter::CompositionMode_DestinationOut, QPainter::CompositionMode_DestinationOver, QPainter::CompositionMode_Source, QPainter::CompositionMode_SourceAtop, QPainter::CompositionMode_SourceIn, QPainter::CompositionMode_SourceOut, QPainter::CompositionMode_SourceOver, QPainter::CompositionMode_Xor, QObject::connect(), destinationButton, destinationImage, equalLabel, QImage::Format_ARGB32_Premultiplied, loadImage(), operatorComboBox, recalculateResult(), resultImage, resultLabel, resultSize, QLayout::SetFixedSize, QAbstractButton::setIconSize(), QWidget::setLayout(), QWidget::setMinimumWidth(), QLayout::setSizeConstraint(), QWidget::setWindowTitle(), SIGNAL, SLOT, sourceButton, sourceImage, and QSize::width().
00031 { 00032 sourceButton = new QToolButton; 00033 sourceButton->setIconSize(resultSize); 00034 00035 operatorComboBox = new QComboBox; 00036 addOp(QPainter::CompositionMode_SourceOver, tr("SourceOver")); 00037 addOp(QPainter::CompositionMode_DestinationOver, tr("DestinationOver")); 00038 addOp(QPainter::CompositionMode_Clear, tr("Clear")); 00039 addOp(QPainter::CompositionMode_Source, tr("Source")); 00040 addOp(QPainter::CompositionMode_Destination, tr("Destination")); 00041 addOp(QPainter::CompositionMode_SourceIn, tr("SourceIn")); 00042 addOp(QPainter::CompositionMode_DestinationIn, tr("DestinationIn")); 00043 addOp(QPainter::CompositionMode_SourceOut, tr("SourceOut")); 00044 addOp(QPainter::CompositionMode_DestinationOut, tr("DestinationOut")); 00045 addOp(QPainter::CompositionMode_SourceAtop, tr("SourceAtop")); 00046 addOp(QPainter::CompositionMode_DestinationAtop, tr("DestinationAtop")); 00047 addOp(QPainter::CompositionMode_Xor, tr("Xor")); 00048 00049 destinationButton = new QToolButton; 00050 destinationButton->setIconSize(resultSize); 00051 00052 equalLabel = new QLabel(tr("=")); 00053 00054 resultLabel = new QLabel; 00055 resultLabel->setMinimumWidth(resultSize.width()); 00056 00057 connect(sourceButton, SIGNAL(clicked()), this, SLOT(chooseSource())); 00058 connect(operatorComboBox, SIGNAL(activated(int)), 00059 this, SLOT(recalculateResult())); 00060 connect(destinationButton, SIGNAL(clicked()), 00061 this, SLOT(chooseDestination())); 00062 00063 QGridLayout *mainLayout = new QGridLayout; 00064 mainLayout->addWidget(sourceButton, 0, 0, 3, 1); 00065 mainLayout->addWidget(operatorComboBox, 1, 1); 00066 mainLayout->addWidget(destinationButton, 0, 2, 3, 1); 00067 mainLayout->addWidget(equalLabel, 1, 3); 00068 mainLayout->addWidget(resultLabel, 0, 4, 3, 1); 00069 mainLayout->setSizeConstraint(QLayout::SetFixedSize); 00070 setLayout(mainLayout); 00071 00072 resultImage = QImage(resultSize, QImage::Format_ARGB32_Premultiplied); 00073 00074 loadImage(":/images/butterfly.png", &sourceImage, sourceButton); 00075 loadImage(":/images/checker.png", &destinationImage, destinationButton); 00076 00077 setWindowTitle(tr("Image Composition")); 00078 }
Here is the call graph for this function:

| void ImageComposer::chooseSource | ( | ) | [private, slot] |
Definition at line 80 of file imagecomposer.cpp.
References chooseImage(), sourceButton, and sourceImage.
Referenced by ImageComposer().
00081 { 00082 chooseImage(tr("Choose Source Image"), &sourceImage, sourceButton); 00083 }
| void ImageComposer::chooseDestination | ( | ) | [private, slot] |
Definition at line 85 of file imagecomposer.cpp.
References chooseImage(), destinationButton, and destinationImage.
Referenced by ImageComposer().
00086 { 00087 chooseImage(tr("Choose Destination Image"), &destinationImage, 00088 destinationButton); 00089 }
| void ImageComposer::recalculateResult | ( | ) | [private, slot] |
Definition at line 91 of file imagecomposer.cpp.
References QPainter::CompositionMode_DestinationOver, QPainter::CompositionMode_Source, QPainter::CompositionMode_SourceOver, currentMode(), destinationImage, QPainter::drawImage(), QPainter::end(), QPainter::fillRect(), QPixmap::fromImage(), QImage::rect(), resultImage, resultLabel, QPainter::setCompositionMode(), QLabel::setPixmap(), sourceImage, Qt::transparent, and Qt::white.
Referenced by ImageComposer(), and loadImage().
00092 { 00093 QPainter::CompositionMode mode = currentMode(); 00094 00095 QPainter painter(&resultImage); 00096 painter.setCompositionMode(QPainter::CompositionMode_Source); 00097 painter.fillRect(resultImage.rect(), Qt::transparent); 00098 painter.setCompositionMode(QPainter::CompositionMode_SourceOver); 00099 painter.drawImage(0, 0, destinationImage); 00100 painter.setCompositionMode(mode); 00101 painter.drawImage(0, 0, sourceImage); 00102 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); 00103 painter.fillRect(resultImage.rect(), Qt::white); 00104 painter.end(); 00105 00106 resultLabel->setPixmap(QPixmap::fromImage(resultImage)); 00107 }
| void ImageComposer::addOp | ( | QPainter::CompositionMode | mode, | |
| const QString & | name | |||
| ) | [private] |
Definition at line 109 of file imagecomposer.cpp.
References name.
Referenced by ImageComposer().
00110 { 00111 operatorComboBox->addItem(name, mode); 00112 }
| void ImageComposer::chooseImage | ( | const QString & | title, | |
| QImage * | image, | |||
| QToolButton * | button | |||
| ) | [private] |
Definition at line 114 of file imagecomposer.cpp.
References QFileDialog::getOpenFileName(), image, QString::isEmpty(), and loadImage().
Referenced by chooseDestination(), and chooseSource().
00116 { 00117 QString fileName = QFileDialog::getOpenFileName(this, title); 00118 if (!fileName.isEmpty()) 00119 loadImage(fileName, image, button); 00120 }
Here is the call graph for this function:

| void ImageComposer::loadImage | ( | const QString & | fileName, | |
| QImage * | image, | |||
| QToolButton * | button | |||
| ) | [private] |
Definition at line 122 of file imagecomposer.cpp.
References QPainter::CompositionMode_Source, QPainter::CompositionMode_SourceOver, QPainter::drawImage(), QPainter::end(), QPainter::fillRect(), QImage::Format_ARGB32_Premultiplied, QPixmap::fromImage(), image, imagePos(), recalculateResult(), QImage::rect(), resultSize, QPainter::setCompositionMode(), QAbstractButton::setIcon(), and Qt::transparent.
Referenced by chooseImage(), and ImageComposer().
00124 { 00125 image->load(fileName); 00126 00127 QImage fixedImage(resultSize, QImage::Format_ARGB32_Premultiplied); 00128 QPainter painter(&fixedImage); 00129 painter.setCompositionMode(QPainter::CompositionMode_Source); 00130 painter.fillRect(fixedImage.rect(), Qt::transparent); 00131 painter.setCompositionMode(QPainter::CompositionMode_SourceOver); 00132 painter.drawImage(imagePos(*image), *image); 00133 painter.end(); 00134 button->setIcon(QPixmap::fromImage(fixedImage)); 00135 00136 *image = fixedImage; 00137 00138 recalculateResult(); 00139 }
Here is the call graph for this function:

| QPainter::CompositionMode ImageComposer::currentMode | ( | ) | const [private] |
Definition at line 141 of file imagecomposer.cpp.
References QComboBox::currentIndex(), and operatorComboBox.
Referenced by recalculateResult().
00142 { 00143 return (QPainter::CompositionMode) 00144 operatorComboBox->itemData(operatorComboBox->currentIndex()).toInt(); 00145 }
Here is the call graph for this function:

Definition at line 147 of file imagecomposer.cpp.
References QSize::height(), image, resultSize, and QSize::width().
Referenced by loadImage().
00148 { 00149 return QPoint((resultSize.width() - image.width()) / 2, 00150 (resultSize.height() - image.height()) / 2); 00151 }
Here is the call graph for this function:

QToolButton* ImageComposer::sourceButton [private] |
QToolButton* ImageComposer::destinationButton [private] |
Definition at line 54 of file imagecomposer.h.
Referenced by chooseDestination(), and ImageComposer().
QComboBox* ImageComposer::operatorComboBox [private] |
QLabel* ImageComposer::equalLabel [private] |
QLabel* ImageComposer::resultLabel [private] |
Definition at line 57 of file imagecomposer.h.
Referenced by ImageComposer(), and recalculateResult().
QImage ImageComposer::sourceImage [private] |
Definition at line 59 of file imagecomposer.h.
Referenced by chooseSource(), ImageComposer(), and recalculateResult().
QImage ImageComposer::destinationImage [private] |
Definition at line 60 of file imagecomposer.h.
Referenced by chooseDestination(), ImageComposer(), and recalculateResult().
QImage ImageComposer::resultImage [private] |
Definition at line 61 of file imagecomposer.h.
Referenced by ImageComposer(), and recalculateResult().
1.5.1