mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 17:10:47 +00:00
Add thumbnail strip widget to manage sizing and layout of thumb previews
This commit is contained in:
@@ -10,3 +10,11 @@ ResourcePreview::~ResourcePreview()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ResourcePreview::SetSize(QSize s)
|
||||
{
|
||||
setFixedWidth(s.width());
|
||||
setFixedHeight(s.height());
|
||||
setMinimumSize(s);
|
||||
setMaximumSize(s);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,21 @@ public:
|
||||
explicit ResourcePreview(QWidget *parent = 0);
|
||||
~ResourcePreview();
|
||||
|
||||
void setActive(bool b)
|
||||
{
|
||||
m_Active = b;
|
||||
if(b)
|
||||
show();
|
||||
else
|
||||
hide();
|
||||
}
|
||||
bool isActive() { return m_Active; }
|
||||
void SetSize(QSize s);
|
||||
|
||||
private:
|
||||
Ui::ResourcePreview *ui;
|
||||
|
||||
bool m_Active;
|
||||
};
|
||||
|
||||
#endif // RESOURCEPREVIEW_H
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include "ThumbnailStrip.h"
|
||||
#include <QDebug>
|
||||
#include <QScrollBar>
|
||||
#include "Widgets/ResourcePreview.h"
|
||||
#include "ui_ThumbnailStrip.h"
|
||||
|
||||
ThumbnailStrip::ThumbnailStrip(QWidget *parent) : QWidget(parent), ui(new Ui::ThumbnailStrip)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
layout = new QVBoxLayout(ui->scrollAreaWidgetContents);
|
||||
layout->setSpacing(6);
|
||||
layout->setContentsMargins(6, 6, 6, 6);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
}
|
||||
|
||||
ThumbnailStrip::~ThumbnailStrip()
|
||||
{
|
||||
delete layout;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ThumbnailStrip::AddPreview(ResourcePreview *prev)
|
||||
{
|
||||
layout->addWidget(prev);
|
||||
m_Thumbnails.push_back(prev);
|
||||
}
|
||||
|
||||
void ThumbnailStrip::ClearThumbnails()
|
||||
{
|
||||
for(ResourcePreview *p : m_Thumbnails)
|
||||
{
|
||||
layout->removeWidget(p);
|
||||
delete p;
|
||||
}
|
||||
|
||||
m_Thumbnails.clear();
|
||||
}
|
||||
|
||||
void ThumbnailStrip::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
RefreshLayout();
|
||||
}
|
||||
|
||||
void ThumbnailStrip::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
emit(mouseClick(event));
|
||||
}
|
||||
|
||||
void ThumbnailStrip::RefreshLayout()
|
||||
{
|
||||
QRect avail = geometry();
|
||||
avail.adjust(6, 6, -6, -6);
|
||||
|
||||
int numActive = 0;
|
||||
for(ResourcePreview *c : m_Thumbnails)
|
||||
if(c->isActive())
|
||||
numActive++;
|
||||
|
||||
// depending on overall aspect ratio, we either lay out the strip horizontally or
|
||||
// vertically. This tries to account for whether the strip is docked along one side
|
||||
// or another of the texture viewer
|
||||
if(avail.width() > avail.height())
|
||||
{
|
||||
avail.setWidth(avail.width() + 6); // controls implicitly have a 6 margin on the right
|
||||
|
||||
int aspectWidth = (int)((float)avail.height() * 1.3f);
|
||||
|
||||
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
delete layout;
|
||||
layout = new QHBoxLayout(ui->scrollAreaWidgetContents);
|
||||
for(ResourcePreview *w : m_Thumbnails)
|
||||
layout->addWidget(w);
|
||||
layout->setSpacing(6);
|
||||
layout->setContentsMargins(6, 6, 6, 6);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
int noscrollWidth = numActive * (aspectWidth + 20);
|
||||
|
||||
if(noscrollWidth <= avail.width())
|
||||
{
|
||||
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
for(ResourcePreview *c : m_Thumbnails)
|
||||
c->SetSize(QSize(aspectWidth, avail.height()));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
|
||||
QScrollBar *hs = ui->scrollArea->horizontalScrollBar();
|
||||
|
||||
avail.setHeight(avail.height() - hs->geometry().height());
|
||||
|
||||
aspectWidth = (int)((float)avail.height() * 1.3f);
|
||||
|
||||
int totalWidth = numActive * (aspectWidth + 20);
|
||||
hs->setEnabled(totalWidth > avail.width());
|
||||
|
||||
for(ResourcePreview *c : m_Thumbnails)
|
||||
c->SetSize(QSize(aspectWidth, avail.height()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
avail.setHeight(avail.height() + 6); // controls implicitly have a 6 margin on the bottom
|
||||
|
||||
int aspectHeight = (int)((float)avail.width() / 1.3f);
|
||||
|
||||
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
delete layout;
|
||||
layout = new QVBoxLayout(ui->scrollAreaWidgetContents);
|
||||
for(ResourcePreview *w : m_Thumbnails)
|
||||
layout->addWidget(w);
|
||||
layout->setSpacing(6);
|
||||
layout->setContentsMargins(6, 6, 6, 6);
|
||||
layout->setAlignment(Qt::AlignTop);
|
||||
|
||||
int noscrollHeight = numActive * (aspectHeight + 6);
|
||||
|
||||
if(noscrollHeight <= avail.height())
|
||||
{
|
||||
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
for(ResourcePreview *c : m_Thumbnails)
|
||||
c->SetSize(QSize(avail.width(), aspectHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
|
||||
QScrollBar *vs = ui->scrollArea->verticalScrollBar();
|
||||
|
||||
avail.setWidth(avail.width() - vs->geometry().width());
|
||||
|
||||
aspectHeight = (int)((float)avail.width() / 1.3f);
|
||||
|
||||
int totalHeight = numActive * (aspectHeight + 6);
|
||||
vs->setEnabled(totalHeight > avail.height());
|
||||
|
||||
for(ResourcePreview *c : m_Thumbnails)
|
||||
c->SetSize(QSize(avail.width(), aspectHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef THUMBNAILSTRIP_H
|
||||
#define THUMBNAILSTRIP_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class ThumbnailStrip;
|
||||
}
|
||||
|
||||
class ResourcePreview;
|
||||
class QBoxLayout;
|
||||
|
||||
class ThumbnailStrip : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ThumbnailStrip(QWidget *parent = 0);
|
||||
~ThumbnailStrip();
|
||||
|
||||
void AddPreview(ResourcePreview *prev);
|
||||
|
||||
void ClearThumbnails();
|
||||
const QVector<ResourcePreview *> &GetThumbs() { return m_Thumbnails; }
|
||||
void RefreshLayout();
|
||||
|
||||
signals:
|
||||
void mouseClick(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
QVector<ResourcePreview *> m_Thumbnails;
|
||||
|
||||
QBoxLayout *layout;
|
||||
|
||||
Ui::ThumbnailStrip *ui;
|
||||
};
|
||||
|
||||
#endif // THUMBNAILSTRIP_H
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ThumbnailStrip</class>
|
||||
<widget class="QWidget" name="ThumbnailStrip">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>159</width>
|
||||
<height>440</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="verticalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>159</width>
|
||||
<height>440</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -1066,86 +1066,25 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QScrollArea" name="inputThumbs">
|
||||
<widget class="ThumbnailStrip" name="inputThumbs" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>430</x>
|
||||
<y>460</y>
|
||||
<width>121</width>
|
||||
<height>81</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="inputThumbList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>119</width>
|
||||
<height>79</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="inputThumbLayout">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QScrollArea" name="outputThumbs">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>290</x>
|
||||
<x>300</x>
|
||||
<y>460</y>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</widget>
|
||||
<widget class="ThumbnailStrip" name="outputThumbs" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>440</x>
|
||||
<y>460</y>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="horizontalScrollBarPolicy">
|
||||
<enum>Qt::ScrollBarAlwaysOff</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="outputThumbList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>118</width>
|
||||
<height>78</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@@ -1159,6 +1098,12 @@
|
||||
<extends>QWidget</extends>
|
||||
<header>ToolWindowManager.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ThumbnailStrip</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Widgets/ThumbnailStrip.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
|
||||
@@ -93,7 +93,8 @@ SOURCES += Code/main.cpp \
|
||||
Widgets/RDLineEdit.cpp \
|
||||
3rdparty/flowlayout/FlowLayout.cpp \
|
||||
Widgets/ResourcePreview.cpp \
|
||||
Widgets/RDLabel.cpp
|
||||
Widgets/RDLabel.cpp \
|
||||
Widgets/ThumbnailStrip.cpp
|
||||
|
||||
HEADERS += Windows/MainWindow.h \
|
||||
Windows/EventBrowser.h \
|
||||
@@ -108,13 +109,15 @@ HEADERS += Windows/MainWindow.h \
|
||||
Widgets/RDLineEdit.h \
|
||||
3rdparty/flowlayout/FlowLayout.h \
|
||||
Widgets/ResourcePreview.h \
|
||||
Widgets/RDLabel.h
|
||||
Widgets/RDLabel.h \
|
||||
Widgets/ThumbnailStrip.h
|
||||
|
||||
FORMS += Windows/MainWindow.ui \
|
||||
Windows/EventBrowser.ui \
|
||||
Windows/TextureViewer.ui \
|
||||
Windows/AboutDialog.ui \
|
||||
Widgets/ResourcePreview.ui
|
||||
Widgets/ResourcePreview.ui \
|
||||
Widgets/ThumbnailStrip.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
||||
@@ -285,12 +285,14 @@
|
||||
<ClCompile Include="generated\moc_MainWindow.cpp" />
|
||||
<ClCompile Include="generated\moc_ResourcePreview.cpp" />
|
||||
<ClCompile Include="generated\moc_TextureViewer.cpp" />
|
||||
<ClCompile Include="generated\moc_ThumbnailStrip.cpp" />
|
||||
<ClCompile Include="generated\moc_ToolWindowManager.cpp" />
|
||||
<ClCompile Include="generated\moc_ToolWindowManagerArea.cpp" />
|
||||
<ClCompile Include="generated\moc_ToolWindowManagerWrapper.cpp" />
|
||||
<ClCompile Include="generated\qrc_resources.cpp" />
|
||||
<ClCompile Include="Widgets\ResourcePreview.cpp" />
|
||||
<ClCompile Include="Widgets\RDLabel.cpp" />
|
||||
<ClCompile Include="Widgets\ResourcePreview.cpp" />
|
||||
<ClCompile Include="Widgets\ThumbnailStrip.cpp" />
|
||||
<ClCompile Include="Windows\AboutDialog.cpp" />
|
||||
<ClCompile Include="Code\Core.cpp" />
|
||||
<ClCompile Include="Widgets\CustomPaintWidget.cpp" />
|
||||
@@ -319,8 +321,10 @@
|
||||
<ClInclude Include="generated\ui_MainWindow.h" />
|
||||
<ClInclude Include="generated\ui_ResourcePreview.h" />
|
||||
<ClInclude Include="generated\ui_TextureViewer.h" />
|
||||
<ClInclude Include="Widgets\ResourcePreview.h" />
|
||||
<ClInclude Include="generated\ui_ThumbnailStrip.h" />
|
||||
<ClInclude Include="Widgets\RDLabel.h" />
|
||||
<ClInclude Include="Widgets\ResourcePreview.h" />
|
||||
<ClInclude Include="Widgets\ThumbnailStrip.h" />
|
||||
<ClInclude Include="Windows\AboutDialog.h" />
|
||||
<ClInclude Include="Code\Core.h" />
|
||||
<ClInclude Include="Widgets\CustomPaintWidget.h" />
|
||||
@@ -336,6 +340,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Widgets\ResourcePreview.ui" />
|
||||
<None Include="Widgets\ThumbnailStrip.ui" />
|
||||
<None Include="Windows\AboutDialog.ui" />
|
||||
<None Include="Windows\EventBrowser.ui" />
|
||||
<None Include="Windows\MainWindow.ui" />
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Form Files">
|
||||
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
|
||||
<Extensions>ui</Extensions>
|
||||
<ParseFiles>false</ParseFiles>
|
||||
</Filter>
|
||||
<Filter Include="Generated Files">
|
||||
<UniqueIdentifier>{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;moc;h;def;odl;idl;res;</Extensions>
|
||||
@@ -14,24 +9,6 @@
|
||||
<UniqueIdentifier>{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;moc;h;def;odl;idl;res;</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}</UniqueIdentifier>
|
||||
<Extensions>qrc;*</Extensions>
|
||||
<ParseFiles>false</ParseFiles>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Forms">
|
||||
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
|
||||
<Extensions>ui</Extensions>
|
||||
<ParseFiles>false</ParseFiles>
|
||||
</Filter>
|
||||
<Filter Include="Resources">
|
||||
<UniqueIdentifier>{D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E}</UniqueIdentifier>
|
||||
<Extensions>qrc;*</Extensions>
|
||||
@@ -147,6 +124,12 @@
|
||||
<ClCompile Include="generated\moc_RDLabel.cpp">
|
||||
<Filter>Generated Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Widgets\ThumbnailStrip.cpp">
|
||||
<Filter>Widgets</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="generated\moc_ThumbnailStrip.cpp">
|
||||
<Filter>Generated Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="3rdparty\flowlayout\FlowLayout.h">
|
||||
@@ -188,11 +171,17 @@
|
||||
<ClInclude Include="Widgets\ResourcePreview.h">
|
||||
<Filter>Widgets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Widgets\RDLabel.h">
|
||||
<Filter>Widgets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Widgets\ThumbnailStrip.h">
|
||||
<Filter>Widgets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="generated\ui_ResourcePreview.h">
|
||||
<Filter>Generated Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Widgets\RDLabel.h">
|
||||
<Filter>Widgets</Filter>
|
||||
<ClInclude Include="generated\ui_ThumbnailStrip.h">
|
||||
<Filter>Generated Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -392,6 +381,9 @@
|
||||
<None Include="Widgets\ResourcePreview.ui">
|
||||
<Filter>Widgets</Filter>
|
||||
</None>
|
||||
<None Include="Widgets\ThumbnailStrip.ui">
|
||||
<Filter>Widgets</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="generated\ui_AboutDialog.h">
|
||||
|
||||
Reference in New Issue
Block a user