Skip to content

Commit

Permalink
#125 [UI] fixed popup windows issue: now windows must disappear when …
Browse files Browse the repository at this point in the history
…switching between applications (Alt+Tab etc.)
  • Loading branch information
cas4ey committed Mar 23, 2019
1 parent e68abb2 commit 0ccb564
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
43 changes: 39 additions & 4 deletions profiler_gui/blocks_graphics_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsScene>
#include <QGraphicsProxyWidget>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QKeyEvent>
Expand Down Expand Up @@ -556,18 +555,28 @@ bool BackgroundItem::contains(const QPointF& scenePos) const
return y >= visibleSceneRect.height();
}

void BackgroundItem::onIdleTimeout()
void BackgroundItem::onWindowActivationChanged(bool isActiveWindow)
{
if (m_bookmark < EASY_GLOBALS.bookmarks.size())
if (!isActiveWindow)
{
delete m_tooltip;
m_tooltip = nullptr;
}
}

void BackgroundItem::onIdleTimeout()
{
auto parent = static_cast<QWidget*>(scene()->parent());

delete m_tooltip;
m_tooltip = nullptr;

if (m_bookmark < EASY_GLOBALS.bookmarks.size() && parent->window()->isActiveWindow())
{
const auto& text = EASY_GLOBALS.bookmarks[m_bookmark].text;
if (text.empty())
return;

auto parent = static_cast<QWidget*>(scene()->parent());
m_tooltip = new QLabel(QString::fromStdString(text),
parent, Qt::ToolTip | Qt::WindowTransparentForInput);

Expand Down Expand Up @@ -693,6 +702,15 @@ BlocksGraphicsView::~BlocksGraphicsView()

//////////////////////////////////////////////////////////////////////////

void BlocksGraphicsView::onWindowActivationChanged()
{
const bool isActive = window()->isActiveWindow();
if (!isActive)
removePopup();
if (m_backgroundItem != nullptr)
m_backgroundItem->onWindowActivationChanged(isActive);
}

void BlocksGraphicsView::removePopup()
{
delete m_popupWidget;
Expand Down Expand Up @@ -2160,6 +2178,9 @@ void BlocksGraphicsView::onIdleTimeout()
if (m_popupWidget != nullptr)
return;

if (!window()->isActiveWindow())
return;

auto focusWidget = qApp->focusWidget();
while (focusWidget != nullptr && !focusWidget->property("stayVisible").toBool())
focusWidget = focusWidget->parentWidget();
Expand Down Expand Up @@ -2721,6 +2742,11 @@ BlocksGraphicsView* DiagramWidget::view()
return m_view;
}

ThreadNamesWidget* DiagramWidget::threadsView()
{
return m_threadNamesWidget;
}

void DiagramWidget::clear()
{
m_scrollbar->clear();
Expand Down Expand Up @@ -2890,7 +2916,13 @@ ThreadNamesWidget::ThreadNamesWidget(BlocksGraphicsView* _view, int _additionalH

ThreadNamesWidget::~ThreadNamesWidget()
{
removePopup();
}

void ThreadNamesWidget::onWindowActivationChanged()
{
if (!window()->isActiveWindow())
removePopup();
}

void ThreadNamesWidget::removePopup()
Expand Down Expand Up @@ -2967,6 +2999,9 @@ void ThreadNamesWidget::onIdleTimeout()
if (m_popupWidget != nullptr)
return;

if (!window()->isActiveWindow())
return;

auto focusWidget = qApp->focusWidget();
while (focusWidget != nullptr && !focusWidget->property("stayVisible").toBool())
focusWidget = focusWidget->parentWidget();
Expand Down
11 changes: 10 additions & 1 deletion profiler_gui/blocks_graphics_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

class QGraphicsProxyWidget;
class BlocksGraphicsView;
class GraphicsBlockItem;
class GraphicsScrollbar;
Expand Down Expand Up @@ -146,6 +145,9 @@ class BackgroundItem : public AuxItem
void bookmarkChanged(size_t index);
void moved();

public slots:
void onWindowActivationChanged(bool isActiveWindow);

private slots:

void onIdleTimeout();
Expand Down Expand Up @@ -261,6 +263,9 @@ class BlocksGraphicsView : public QGraphicsView
onInspectCurrentView(_strict);
}

public slots:
void onWindowActivationChanged();

signals:

// Signals
Expand Down Expand Up @@ -397,6 +402,9 @@ class ThreadNamesWidget : public QGraphicsView
return m_view;
}

public slots:
void onWindowActivationChanged();

private:

void removePopup();
Expand Down Expand Up @@ -429,6 +437,7 @@ class DiagramWidget : public QWidget
~DiagramWidget() override;

BlocksGraphicsView* view();
ThreadNamesWidget* threadsView();
void clear();

void save(class QSettings& settings);
Expand Down
10 changes: 10 additions & 0 deletions profiler_gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ MainWindow::MainWindow() : Parent(), m_theme("default"), m_lastAddress("localhos

auto graphicsView = new DiagramWidget(this);
graphicsView->setObjectName("ProfilerGUI_Diagram_GraphicsView");
connect(this, &MainWindow::activationChanged, graphicsView->view(), &BlocksGraphicsView::onWindowActivationChanged);
connect(this, &MainWindow::activationChanged, graphicsView->threadsView(), &ThreadNamesWidget::onWindowActivationChanged);
m_graphicsView->setWidget(graphicsView);

m_treeWidget = new DockWidget("Hierarchy", this);
Expand Down Expand Up @@ -1547,6 +1549,14 @@ void MainWindow::closeEvent(QCloseEvent* close_event)
Parent::closeEvent(close_event);
}

void MainWindow::changeEvent(QEvent* event)
{
if (event->type() == QEvent::ActivationChange)
{
emit activationChanged();
}
}

//////////////////////////////////////////////////////////////////////////

void MainWindow::loadSettings()
Expand Down
4 changes: 4 additions & 0 deletions profiler_gui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,15 @@ class MainWindow : public QMainWindow

void showEvent(QShowEvent* event) override;
void closeEvent(QCloseEvent* close_event) override;
void changeEvent(QEvent* event) override;
void dragEnterEvent(QDragEnterEvent* drag_event) override;
void dragMoveEvent(QDragMoveEvent* drag_event) override;
void dragLeaveEvent(QDragLeaveEvent* drag_event) override;
void dropEvent(QDropEvent* drop_event) override;

signals:
void activationChanged();

protected slots:

void onThemeChange(bool);
Expand Down

0 comments on commit 0ccb564

Please sign in to comment.