1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
paintanalyzerwidget.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2012 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Volker Krause <volker.krause@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include "paintanalyzerwidget.h"
#include "ui_paintanalyzerwidget.h"
#include "paintbufferclientmodel.h"
#include <ui/clientpropertymodel.h>
#include <ui/contextmenuextension.h>
#include <ui/searchlinecontroller.h>
#include <ui/propertyeditor/propertyeditordelegate.h>
#include <ui/uiresources.h>
#include <common/paintanalyzerinterface.h>
#include <common/paintbuffermodelroles.h>
#include <common/objectbroker.h>
#include <common/sourcelocation.h>
#include <QActionGroup>
#include <QComboBox>
#include <QDebug>
#include <QLabel>
#include <QMenu>
#include <QToolBar>
using namespace GammaRay;
PaintAnalyzerWidget::PaintAnalyzerWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::PaintAnalyzerWidget)
, m_iface(nullptr)
{
ui->setupUi(this);
ui->commandView->header()->setObjectName("commandViewHeader");
ui->commandView->setItemDelegate(new PropertyEditorDelegate(this));
ui->commandView->setStretchLastSection(false);
ui->commandView->setDeferredResizeMode(0, QHeaderView::ResizeToContents);
ui->commandView->setDeferredResizeMode(1, QHeaderView::Stretch);
ui->commandView->setDeferredResizeMode(2, QHeaderView::ResizeToContents);
ui->argumentView->setItemDelegate(new PropertyEditorDelegate(this));
ui->argumentView->header()->setObjectName("argumentViewHeader");
ui->stackTraceView->setItemDelegate(new PropertyEditorDelegate(this));
ui->stackTraceView->header()->setObjectName("stackTraceViewHeader");
auto toolbar = new QToolBar;
// Our icons are 16x16 and support hidpi, so let force iconSize on every styles
toolbar->setIconSize(QSize(16, 16));
toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
ui->replayContainer->setMenuBar(toolbar);
foreach (auto action, ui->replayWidget->interactionModeActions()->actions())
toolbar->addAction(action);
toolbar->addSeparator();
toolbar->addAction(ui->replayWidget->zoomOutAction());
auto zoom = new QComboBox;
zoom->setModel(ui->replayWidget->zoomLevelModel());
toolbar->addWidget(zoom);
toolbar->addAction(ui->replayWidget->zoomInAction());
toolbar->addSeparator();
toolbar->addAction(ui->actionShowClipArea);
ui->replayWidget->setSupportedInteractionModes(
RemoteViewWidget::ViewInteraction | RemoteViewWidget::Measuring | RemoteViewWidget::ColorPicking);
ui->paintAnalyzerSplitter->setStretchFactor(0, 1);
ui->paintAnalyzerSplitter->setStretchFactor(1, 2);
connect(zoom, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
ui->replayWidget, &RemoteViewWidget::setZoomLevel);
connect(ui->replayWidget, &RemoteViewWidget::zoomLevelChanged, zoom, &QComboBox::setCurrentIndex);
zoom->setCurrentIndex(ui->replayWidget->zoomLevelIndex());
ui->actionShowClipArea->setIcon(UIResources::themedIcon(QLatin1String("visualize-clipping.png")));
connect(ui->actionShowClipArea, &QAction::toggled, ui->replayWidget, &PaintAnalyzerReplayView::setShowClipArea);
ui->actionShowClipArea->setChecked(ui->replayWidget->showClipArea());
connect(ui->commandView, &QWidget::customContextMenuRequested, this, &PaintAnalyzerWidget::commandContextMenu);
connect(ui->stackTraceView, &QWidget::customContextMenuRequested, this, &PaintAnalyzerWidget::stackTraceContextMenu);
}
PaintAnalyzerWidget::~PaintAnalyzerWidget() = default;
void PaintAnalyzerWidget::setBaseName(const QString &name)
{
auto model = ObjectBroker::model(name + QStringLiteral(".paintBufferModel"));
auto proxy = new PaintBufferClientModel(this);
proxy->setSourceModel(model);
ui->commandView->setModel(proxy);
ui->commandView->setSelectionModel(ObjectBroker::selectionModel(proxy));
new SearchLineController(ui->commandSearchLine, proxy);
auto clientPropModel = new ClientPropertyModel(this);
clientPropModel->setSourceModel(ObjectBroker::model(name + QStringLiteral(".argumentProperties")));
ui->argumentView->setModel(clientPropModel);
ui->stackTraceView->setModel(ObjectBroker::model(name + QStringLiteral(".stackTrace")));
ui->replayWidget->setName(name + QStringLiteral(".remoteView"));
m_iface = ObjectBroker::object<PaintAnalyzerInterface *>(name);
connect(m_iface, &PaintAnalyzerInterface::hasArgumentDetailsChanged, this, &PaintAnalyzerWidget::detailsChanged);
connect(m_iface, &PaintAnalyzerInterface::hasStackTraceChanged, this, &PaintAnalyzerWidget::detailsChanged);
detailsChanged();
}
void PaintAnalyzerWidget::detailsChanged()
{
const auto hasAnyDetails = m_iface->hasArgumentDetails() || m_iface->hasStackTrace();
ui->detailsTabWidget->setVisible(hasAnyDetails);
if (!hasAnyDetails)
return;
const auto hasAllDetails = m_iface->hasArgumentDetails() && m_iface->hasStackTrace();
ui->detailsTabWidget->tabBar()->setVisible(hasAllDetails);
if (hasAllDetails)
return;
ui->detailsTabWidget->setCurrentWidget(m_iface->hasArgumentDetails() ? ui->argumentTab : ui->stackTraceTab);
}
void PaintAnalyzerWidget::commandContextMenu(QPoint pos)
{
const auto idx = ui->commandView->indexAt(pos);
if (!idx.isValid())
return;
const auto objectId = idx.data(PaintBufferModelRoles::ObjectIdRole).value<ObjectId>();
QMenu contextMenu;
ContextMenuExtension cme(objectId);
cme.populateMenu(&contextMenu);
contextMenu.exec(ui->commandView->viewport()->mapToGlobal(pos));
}
void PaintAnalyzerWidget::stackTraceContextMenu(QPoint pos)
{
const auto idx = ui->stackTraceView->indexAt(pos);
if (!idx.isValid())
return;
const auto loc = idx.sibling(idx.row(), 1).data().value<SourceLocation>();
if (!loc.isValid())
return;
QMenu contextMenu;
ContextMenuExtension cme;
cme.setLocation(ContextMenuExtension::ShowSource, loc);
cme.populateMenu(&contextMenu);
contextMenu.exec(ui->stackTraceView->viewport()->mapToGlobal(pos));
}
|