From 3f45640ecfc43ea5fc97d844cb0db567e98b3b54 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 25 Mar 2012 20:59:24 +0100 Subject: [PATCH] Make frame thumbnail size consistent. --- gui/apicalldelegate.cpp | 54 ++++++++++++++++++++++++++--------------- gui/apisurface.cpp | 3 ++- gui/mainwindow.cpp | 4 ++- gui/retracer.cpp | 5 ++-- gui/thumbnail.h | 13 ++++++++++ 5 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 gui/thumbnail.h diff --git a/gui/apicalldelegate.cpp b/gui/apicalldelegate.cpp index c687175..9ad9f24 100644 --- a/gui/apicalldelegate.cpp +++ b/gui/apicalldelegate.cpp @@ -2,6 +2,7 @@ #include "apitracecall.h" #include "apitracemodel.h" +#include "thumbnail.h" #include #include @@ -27,46 +28,47 @@ void ApiCallDelegate::paint(QPainter *painter, Q_ASSERT(index.column() == 0); if (event) { - QPoint offset = QPoint(0, 0); + QPoint offset = option.rect.topLeft(); QStaticText text = event->staticText(); + QSize textSize = text.size().toSize(); //text.setTextWidth(option.rect.width()); //QStyledItemDelegate::paint(painter, option, index); QStyle *style = QApplication::style(); style->drawControl(QStyle::CE_ItemViewItem, &option, painter, 0); // draw thumbnail of frame - if(event->type() == ApiTraceEvent::Frame) { + if (event->type() == ApiTraceEvent::Frame) { ApiTraceFrame *frame = static_cast(event); const QImage & thumbnail = frame->thumbnail(); if (!thumbnail.isNull()) { - painter->drawImage(option.rect.topLeft() + offset, thumbnail); - offset += QPoint(option.rect.height() + 16, 0); + painter->drawImage(offset, thumbnail); + offset += QPoint(textSize.height() + thumbnail.width(), option.rect.height()/2 - textSize.height()/2); } } if (event->hasState()) { - QPixmap px = m_stateEmblem.pixmap(option.rect.height(), - option.rect.height()); + QPixmap px = m_stateEmblem.pixmap(textSize.height(), + textSize.height()); painter->drawPixmap(option.rect.topLeft(), px); - offset = QPoint(option.rect.height() + 5, 0); + offset += QPoint(textSize.height() + 5, 0); } if (event->type() == ApiTraceEvent::Call) { ApiTraceCall *call = static_cast(event); if (call->hasError()) { - QPixmap px = m_errorEmblem.pixmap(option.rect.height(), - option.rect.height()); - painter->drawPixmap(option.rect.topLeft() + offset, px); - offset += QPoint(option.rect.height() + 5, 0); + QPixmap px = m_errorEmblem.pixmap(textSize.height(), + textSize.height()); + painter->drawPixmap(offset, px); + offset += QPoint(textSize.height() + 5, 0); } if (call->edited()) { - QPixmap px = m_editEmblem.pixmap(option.rect.height(), - option.rect.height()); - painter->drawPixmap(option.rect.topLeft() + offset, px); - offset += QPoint(option.rect.height() + 5, 0); + QPixmap px = m_editEmblem.pixmap(textSize.height(), + textSize.height()); + painter->drawPixmap(offset, px); + offset += QPoint(textSize.height() + 5, 0); } } - painter->drawStaticText(option.rect.topLeft() + offset, text); + painter->drawStaticText(offset, text); } else { QStyledItemDelegate::paint(painter, option, index); } @@ -75,8 +77,8 @@ void ApiCallDelegate::paint(QPainter *painter, QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { - ApiTraceEvent *event = - index.data(ApiTraceModel::EventRole).value(); + QVariant var = index.data(ApiTraceModel::EventRole); + ApiTraceEvent *event = var.value(); #ifndef __APPLE__ /* XXX: This fails on MacOSX, but seems safe to ignore */ @@ -87,7 +89,21 @@ QSize ApiCallDelegate::sizeHint(const QStyleOptionViewItem &option, QStaticText text = event->staticText(); //text.setTextWidth(option.rect.width()); //qDebug()<<"text size = "<type() == ApiTraceEvent::Frame) { + ApiTraceFrame *frame = static_cast(event); + const QImage & thumbnail = frame->thumbnail(); + if (!thumbnail.isNull()) { + size.rwidth() += thumbnail.width(); + if (size.height() < thumbnail.height()) { + size.setHeight(thumbnail.height()); + } + } + } + + return size; } return QStyledItemDelegate::sizeHint(option, index); } diff --git a/gui/apisurface.cpp b/gui/apisurface.cpp index 7bf3c8f..bfc6cfd 100644 --- a/gui/apisurface.cpp +++ b/gui/apisurface.cpp @@ -1,4 +1,5 @@ #include "apisurface.h" +#include "thumbnail.h" #include #include @@ -31,7 +32,7 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64) { QByteArray dataArray = QByteArray::fromBase64(base64); m_image.loadFromData(dataArray, "png"); - m_thumb = m_image.scaled(64, 64, Qt::KeepAspectRatio); + m_thumb = thumbnail(m_image); } QImage ApiSurface::image() const diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index fce9984..bf56115 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -14,6 +14,7 @@ #include "shaderssourcewidget.h" #include "tracedialog.h" #include "traceprocess.h" +#include "thumbnail.h" #include "ui_retracerdialog.h" #include "vertexdatainterpreter.h" @@ -554,7 +555,7 @@ void MainWindow::fillStateForFrame() if (textures.isEmpty() && fbos.isEmpty()) { m_ui.surfacesTab->setDisabled(false); } else { - m_ui.surfacesTreeWidget->setIconSize(QSize(64, 64)); + m_ui.surfacesTreeWidget->setIconSize(QSize(THUMBNAIL_SIZE, THUMBNAIL_SIZE)); if (!textures.isEmpty()) { QTreeWidgetItem *textureItem = new QTreeWidgetItem(m_ui.surfacesTreeWidget); @@ -863,6 +864,7 @@ void MainWindow::replayStateFound(ApiTraceState *state) void MainWindow::replayThumbnailsFound(const QList &thumbnails) { + m_ui.callView->setUniformRowHeights(false); m_trace->bindThumbnailsToFrames(thumbnails); } diff --git a/gui/retracer.cpp b/gui/retracer.cpp index fa22011..7c66f3e 100644 --- a/gui/retracer.cpp +++ b/gui/retracer.cpp @@ -1,6 +1,7 @@ #include "retracer.h" #include "apitracecall.h" +#include "thumbnail.h" #include "image.hpp" @@ -241,8 +242,8 @@ void RetraceProcess::replayFinished(int exitCode, QProcess::ExitStatus exitStatu m_process->read((char *) scanLine, rowBytes); } - QImage thumbnail = snapshot.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation); - thumbnails.append(thumbnail); + QImage thumb = thumbnail(snapshot); + thumbnails.append(thumb); } emit foundThumbnails(thumbnails); diff --git a/gui/thumbnail.h b/gui/thumbnail.h new file mode 100644 index 0000000..2315564 --- /dev/null +++ b/gui/thumbnail.h @@ -0,0 +1,13 @@ +#ifndef THUMBNAIL_H +#define THUMBNAIL_H + +#define THUMBNAIL_SIZE 64 + +#include + +inline QImage +thumbnail(const QImage &image, Qt::TransformationMode transformationMode = Qt::FastTransformation) { + return image.scaled(THUMBNAIL_SIZE, THUMBNAIL_SIZE, Qt::KeepAspectRatio, transformationMode); +} + +#endif -- 2.45.2