X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fimageviewer.cpp;h=cd034138f9aaa52ce79dc58b4aa638a24171293e;hb=66ce10aed5cd8c4b1df5b53645b92ee81b16d8e2;hp=7b1e425f3e64ef2438d7d9c8e43ea5fbb6189e75;hpb=97ac28e65ca20b5649552597afaeee1d67766f6a;p=apitrace diff --git a/gui/imageviewer.cpp b/gui/imageviewer.cpp index 7b1e425..cd03413 100644 --- a/gui/imageviewer.cpp +++ b/gui/imageviewer.cpp @@ -1,4 +1,5 @@ #include "imageviewer.h" +#include "pixelwidget.h" #include #include @@ -19,6 +20,8 @@ ImageViewer::ImageViewer(QWidget *parent) SLOT(slotUpdate())); connect(opaqueCheckBox, SIGNAL(stateChanged(int)), SLOT(slotUpdate())); + connect(alphaCheckBox, SIGNAL(stateChanged(int)), + SLOT(slotUpdate())); QPixmap px(32, 32); QPainter p(&px); @@ -32,14 +35,28 @@ ImageViewer::ImageViewer(QWidget *parent) pal.setBrush(QPalette::Base, QBrush(px)); scrollAreaWidgetContents->setPalette(pal); + + m_pixelWidget = new PixelWidget(scrollAreaWidgetContents); + verticalLayout_2->addWidget(m_pixelWidget); + + rectLabel->hide(); + pixelLabel->hide(); + + connect(m_pixelWidget, SIGNAL(zoomChanged(int)), + zoomSpinBox, SLOT(setValue(int))); + connect(zoomSpinBox, SIGNAL(valueChanged(int)), + m_pixelWidget, SLOT(setZoom(int))); + connect(m_pixelWidget, SIGNAL(mousePosition(int, int)), + this, SLOT(showPixel(int, int))); + connect(m_pixelWidget, SIGNAL(gridGeometry(const QRect &)), + this, SLOT(showGrid(const QRect &))); } void ImageViewer::setImage(const QImage &image) { m_image = image; m_temp = m_image; - QPixmap px = QPixmap::fromImage(m_temp); - imageLabel->setPixmap(px); + m_pixelWidget->setSurface(m_image); updateGeometry(); } @@ -62,8 +79,9 @@ void ImageViewer::slotUpdate() double upperValue = upperSpinBox->value(); bool opaque = opaqueCheckBox->isChecked(); + bool alpha = alphaCheckBox->isChecked(); - if (lowerValue != 0.0 || upperValue != 1.0 || opaque) { + if (lowerValue != 0.0 || upperValue != 1.0 || opaque || alpha) { /* * Rescale the image. * @@ -95,17 +113,21 @@ void ImageViewer::slotUpdate() int g = qGreen(pixel); int b = qBlue(pixel); int a = qAlpha(pixel); - r = clamp(((r + offset) * scale) >> 8); - g = clamp(((g + offset) * scale) >> 8); - b = clamp(((b + offset) * scale) >> 8); - a |= aMask; - scanline[x] = qRgba(r, g, b, a); + if (alpha) { + a = clamp(((a + offset) * scale) >> 8); + scanline[x] = qRgba(a, a, a, 0xff); + } else { + r = clamp(((r + offset) * scale) >> 8); + g = clamp(((g + offset) * scale) >> 8); + b = clamp(((b + offset) * scale) >> 8); + a |= aMask; + scanline[x] = qRgba(r, g, b, a); + } } } } - QPixmap px = QPixmap::fromImage(m_temp); - imageLabel->setPixmap(px); + m_pixelWidget->setSurface(m_temp); updateGeometry(); } @@ -122,7 +144,7 @@ QSize ImageViewer::sizeHint() const m_image.height() + hScrollHeight); QRect screenRect = QApplication::desktop()->availableGeometry(); - const float maxPercentOfDesktopSpace = 0.8; + const float maxPercentOfDesktopSpace = 0.8f; QSize maxAvailableSize(maxPercentOfDesktopSpace * screenRect.width(), maxPercentOfDesktopSpace * screenRect.height()); @@ -130,4 +152,36 @@ QSize ImageViewer::sizeHint() const qMin(optimalWindowSize.height(), maxAvailableSize.height())); } +void ImageViewer::resizeEvent(QResizeEvent *e) +{ + QWidget::resizeEvent(e); +} + +void ImageViewer::showPixel(int x, int y) +{ + xSpinBox->setValue(x); + ySpinBox->setValue(y); + QColor clr = m_pixelWidget->colorAtCurrentPosition(); + pixelLabel->setText(tr("RGBA: (%1, %2, %3, %4)") + .arg(clr.red()) + .arg(clr.green()) + .arg(clr.blue()) + .arg(clr.alpha())); + pixelLabel->show(); +} + +void ImageViewer::showGrid(const QRect &rect) +{ + if (rect.isEmpty()) { + rectLabel->hide(); + return; + } + rectLabel->setText(tr("Grid: [%1, %2, %3, %4]") + .arg(rect.x()) + .arg(rect.y()) + .arg(rect.width()) + .arg(rect.height())); + rectLabel->show(); +} + #include "imageviewer.moc"