2018-03-16 21:46:57 +00:00
|
|
|
#include "CutterDockWidget.h"
|
|
|
|
#include "MainWindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
CutterDockWidget::CutterDockWidget(MainWindow *main, QAction *action) :
|
|
|
|
QDockWidget(main),
|
|
|
|
action(action)
|
|
|
|
{
|
|
|
|
if (action) {
|
2018-05-25 14:30:59 +00:00
|
|
|
main->addToDockWidgetList(this);
|
2018-03-16 21:46:57 +00:00
|
|
|
main->addDockWidgetAction(this, action);
|
|
|
|
connect(action, &QAction::triggered, this, &CutterDockWidget::toggleDockWidget);
|
|
|
|
}
|
2019-01-12 17:02:51 +00:00
|
|
|
|
|
|
|
// Install event filter to catch redraw widgets when needed
|
|
|
|
installEventFilter(this);
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 17:02:51 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-03-16 21:46:57 +00:00
|
|
|
|
|
|
|
void CutterDockWidget::toggleDockWidget(bool show)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!show) {
|
2018-03-16 21:46:57 +00:00
|
|
|
this->close();
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-03-16 21:46:57 +00:00
|
|
|
this->show();
|
|
|
|
this->raise();
|
2019-01-12 17:02:51 +00:00
|
|
|
this->refreshIfNeeded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CutterDockWidget::refreshIfNeeded()
|
|
|
|
{
|
|
|
|
if (doRefresh) {
|
|
|
|
refreshContent();
|
|
|
|
doRefresh = false;
|
2018-03-16 21:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void CutterDockWidget::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2018-03-16 21:46:57 +00:00
|
|
|
if (action) {
|
|
|
|
this->action->setChecked(false);
|
|
|
|
}
|
|
|
|
QDockWidget::closeEvent(event);
|
|
|
|
}
|
|
|
|
|
2019-01-12 17:02:51 +00:00
|
|
|
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;
|
|
|
|
}
|