Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions WidgetInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QLineEdit>
#include <QPushButton>
#include <QSplitter>
#include <QTimer>
#include <QTreeView>
#include <QVBoxLayout>

Expand Down Expand Up @@ -70,6 +71,9 @@ WidgetInspector::WidgetInspector(RootObjectList* rootList, QWidget* parent)
m_pickButton = new QPushButton(tr("Pick Widget"),this);
setWidgetPicker(new DirectWidgetPicker(this));

QPushButton* flashButton = new QPushButton(tr("Flash Widget"),this);
connect(flashButton,SIGNAL(clicked()),this,SLOT(flashWidget()));

QPushButton* refreshButton = new QPushButton(tr("Refresh Tree"),this);
connect(refreshButton,SIGNAL(clicked()),this,SLOT(refreshTree()));

Expand All @@ -79,6 +83,7 @@ WidgetInspector::WidgetInspector(RootObjectList* rootList, QWidget* parent)
QHBoxLayout* actionLayout = new QHBoxLayout;
actionLayout->addStretch();
actionLayout->addWidget(m_pickButton);
actionLayout->addWidget(flashButton);
actionLayout->addWidget(copyToDebuggerButton);
actionLayout->addWidget(refreshButton);
actionLayout->addWidget(refreshObjectButton);
Expand Down Expand Up @@ -115,6 +120,35 @@ void WidgetInspector::copyDebuggerReference()
#endif
}

void WidgetInspector::flashWidget()
{
ObjectProxy::Pointer object = m_objectInspector->object();
if (!object)
{
return;
}

QString origStyle;
for (const auto &property : object->properties())
{
if (property.name == "styleSheet")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the widget is in the middle of an earlier flash sequence when the button is clicked, this loop may capture the flashed stylesheet. The result is that the flash effect remains on at the end of the sequence.

{
origStyle = property.value.toString();
break;
}
}
QString newStyle = origStyle + " background-color: red; color: limegreen;";

object->writeProperty("styleSheet", newStyle);

#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
QTimer::singleShot(500, [=]() { object->writeProperty("styleSheet", origStyle); });
QTimer::singleShot(1000, [=]() { object->writeProperty("styleSheet", newStyle); });
QTimer::singleShot(1500, [=]() { object->writeProperty("styleSheet", origStyle); });
Copy link
Owner

@robertknight robertknight Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a version check around these calls, as support for functor arguments to QTimer::singleShot was added only in Qt 5.4. The project ostensibly still supports Qt 4, although I think that support could probably be ended now.

#endif

}

void WidgetInspector::selectionChanged(const QModelIndex& current, const QModelIndex& previous)
{
Q_UNUSED(previous);
Expand Down
1 change: 1 addition & 0 deletions WidgetInspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class WidgetInspector : public QWidget
void pickerFinished(ObjectProxy::Pointer widget);
void selectionChanged(const QModelIndex& current, const QModelIndex& previous);
void copyDebuggerReference();
void flashWidget();

private:
void select(ObjectProxy::Pointer object);
Expand Down