cutter/src/widgets/CutterDockWidget.cpp

106 lines
2.6 KiB
C++
Raw Normal View History

#include "CutterDockWidget.h"
#include "core/MainWindow.h"
2019-03-14 09:28:42 +00:00
#include <QEvent>
#include <QtWidgets/QShortcut>
2021-01-24 14:50:13 +00:00
CutterDockWidget::CutterDockWidget(MainWindow *parent, QAction *) : CutterDockWidget(parent) {}
2021-01-24 14:50:13 +00:00
CutterDockWidget::CutterDockWidget(MainWindow *parent) : QDockWidget(parent), mainWindow(parent)
{
// Install event filter to catch redraw widgets when needed
installEventFilter(this);
2019-01-12 19:25:43 +00:00
updateIsVisibleToUser();
connect(toggleViewAction(), &QAction::triggered, this, &QWidget::raise);
}
CutterDockWidget::~CutterDockWidget() = default;
bool CutterDockWidget::eventFilter(QObject *object, QEvent *event)
{
2021-01-24 14:50:13 +00:00
if (event->type() == QEvent::FocusIn || event->type() == QEvent::ZOrderChange
|| event->type() == QEvent::Paint || event->type() == QEvent::Close
|| event->type() == QEvent::Show || event->type() == QEvent::Hide) {
updateIsVisibleToUser();
}
return QDockWidget::eventFilter(object, event);
}
QVariantMap CutterDockWidget::serializeViewProprties()
{
return {};
}
2021-01-24 14:50:13 +00:00
void CutterDockWidget::deserializeViewProperties(const QVariantMap &) {}
void CutterDockWidget::ignoreVisibilityStatus(bool ignore)
{
this->ignoreVisibility = ignore;
updateIsVisibleToUser();
}
void CutterDockWidget::raiseMemoryWidget()
{
show();
raise();
widgetToFocusOnRaise()->setFocus(Qt::FocusReason::TabFocusReason);
}
void CutterDockWidget::toggleDockWidget(bool show)
{
2018-03-21 20:32:32 +00:00
if (!show) {
this->hide();
2018-03-21 20:32:32 +00:00
} else {
this->show();
this->raise();
}
}
QWidget *CutterDockWidget::widgetToFocusOnRaise()
{
return this;
}
void CutterDockWidget::updateIsVisibleToUser()
{
// Check if the user can actually see the widget.
bool visibleToUser = isVisible() && !visibleRegion().isEmpty() && !ignoreVisibility;
if (visibleToUser == isVisibleToUserCurrent) {
return;
}
isVisibleToUserCurrent = visibleToUser;
if (isVisibleToUserCurrent) {
emit becameVisibleToUser();
}
}
2018-03-21 20:32:32 +00:00
void CutterDockWidget::closeEvent(QCloseEvent *event)
{
QDockWidget::closeEvent(event);
2019-04-27 09:46:29 +00:00
if (isTransient) {
if (mainWindow) {
mainWindow->removeWidget(this);
}
2021-01-24 14:50:13 +00:00
// remove parent, otherwise dock layout may still decide to use this widget which is about
// to be deleted
setParent(nullptr);
2019-04-27 09:46:29 +00:00
deleteLater();
}
emit closed();
}
QString CutterDockWidget::getDockNumber()
{
auto name = this->objectName();
if (name.contains(';')) {
auto parts = name.split(';');
if (parts.size() >= 2) {
return parts[1];
}
}
return QString();
}