cutter/src/widgets/CutterDockWidget.cpp

67 lines
1.6 KiB
C++
Raw Normal View History

#include "CutterDockWidget.h"
#include "MainWindow.h"
CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) :
QDockWidget(main),
action(action)
{
if (action) {
main->addToDockWidgetList(this);
main->addDockWidgetAction(this, action);
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
}
// Install event filter to catch redraw widgets when needed
installEventFilter(this);
}
CutterDockWidget::~CutterDockWidget() {}
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::FocusIn || event->type() == QEvent::Paint) {
qDebug() << object << "is now focused in";
refreshIfNeeded();
}
return QDockWidget::eventFilter(object, event);
}
void CutterDockWidget::toggleDockWidget(bool show)
{
2018-03-21 20:32:32 +00:00
if (!show) {
this->close();
2018-03-21 20:32:32 +00:00
} else {
this->show();
this->raise();
this->refreshIfNeeded();
}
}
void CutterDockWidget::refreshIfNeeded()
{
if (doRefresh) {
refreshContent();
doRefresh = false;
}
}
2018-03-21 20:32:32 +00:00
void CutterDockWidget::closeEvent(QCloseEvent *event)
{
if (action) {
this->action->setChecked(false);
}
QDockWidget::closeEvent(event);
}
bool CutterDockWidget::isVisibleToUser()
{
// Check if the user can actually see the widget.
bool visibleToUser = this->isVisible() && !this->visibleRegion().isEmpty();
if (!visibleToUser) {
// If this is called and not visible, it must be refreshed later
doRefresh = true;
}
return visibleToUser;
}