2019-03-27 08:24:54 +00:00
|
|
|
#include "MemoryDockWidget.h"
|
2019-06-18 13:02:41 +00:00
|
|
|
#include "common/CutterSeekable.h"
|
2019-07-19 19:21:12 +00:00
|
|
|
#include "MainWindow.h"
|
2019-03-27 08:24:54 +00:00
|
|
|
#include <QAction>
|
2019-07-19 19:21:12 +00:00
|
|
|
#include <QEvent>
|
2019-10-06 17:35:44 +00:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QContextMenuEvent>
|
2019-03-27 08:24:54 +00:00
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
MemoryDockWidget::MemoryDockWidget(MemoryWidgetType type, MainWindow *parent, QAction *action)
|
2019-03-27 08:24:54 +00:00
|
|
|
: CutterDockWidget(parent, action)
|
2019-10-06 17:35:44 +00:00
|
|
|
, mType(type)
|
|
|
|
, seekable(new CutterSeekable(this))
|
|
|
|
, syncAction(tr("Sync/unsync offset"), this)
|
2019-03-27 08:24:54 +00:00
|
|
|
{
|
2019-07-19 19:21:12 +00:00
|
|
|
if (parent) {
|
|
|
|
parent->addMemoryDockWidget(this);
|
|
|
|
}
|
2019-06-18 13:02:41 +00:00
|
|
|
connect(seekable, &CutterSeekable::syncChanged, this, &MemoryDockWidget::updateWindowTitle);
|
2019-10-06 17:35:44 +00:00
|
|
|
connect(&syncAction, &QAction::triggered, seekable, &CutterSeekable::toggleSynchronization);
|
|
|
|
|
|
|
|
dockMenu = new QMenu(this);
|
|
|
|
dockMenu->addAction(&syncAction);
|
|
|
|
|
|
|
|
setContextMenuPolicy(Qt::ContextMenuPolicy::DefaultContextMenu);
|
2019-03-27 08:24:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
bool MemoryDockWidget::tryRaiseMemoryWidget()
|
2019-03-27 08:24:54 +00:00
|
|
|
{
|
2019-06-18 22:59:24 +00:00
|
|
|
if (!seekable->isSynchronized()) {
|
2019-07-19 19:21:12 +00:00
|
|
|
return false;
|
2019-06-18 22:59:24 +00:00
|
|
|
}
|
2019-07-19 19:21:12 +00:00
|
|
|
|
|
|
|
if (mType == MemoryWidgetType::Graph && Core()->isGraphEmpty()) {
|
|
|
|
return false;
|
2019-03-27 08:24:54 +00:00
|
|
|
}
|
2019-07-19 19:21:12 +00:00
|
|
|
raiseMemoryWidget();
|
2019-03-27 08:24:54 +00:00
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-03-27 08:24:54 +00:00
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
void MemoryDockWidget::raiseMemoryWidget()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (getBoundAction()) {
|
|
|
|
getBoundAction()->setChecked(true);
|
2019-03-27 08:24:54 +00:00
|
|
|
}
|
2019-07-19 19:21:12 +00:00
|
|
|
|
|
|
|
show();
|
|
|
|
raise();
|
|
|
|
widgetToFocusOnRaise()->setFocus(Qt::FocusReason::TabFocusReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MemoryDockWidget::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
2019-09-09 13:18:30 +00:00
|
|
|
if (mainWindow && event->type() == QEvent::FocusIn) {
|
2019-07-19 19:21:12 +00:00
|
|
|
mainWindow->setCurrentMemoryWidget(this);
|
|
|
|
}
|
|
|
|
return CutterDockWidget::eventFilter(object, event);
|
2019-03-27 08:24:54 +00:00
|
|
|
}
|
2019-06-18 13:02:41 +00:00
|
|
|
|
|
|
|
void MemoryDockWidget::updateWindowTitle()
|
|
|
|
{
|
2019-07-19 19:21:12 +00:00
|
|
|
QString name = getWindowTitle();
|
|
|
|
QString id = getDockNumber();
|
|
|
|
if (!id.isEmpty()) {
|
|
|
|
name += " " + id;
|
|
|
|
}
|
|
|
|
if (!seekable->isSynchronized()) {
|
|
|
|
name += CutterSeekable::tr(" (unsynced)");
|
2019-06-18 13:02:41 +00:00
|
|
|
}
|
2019-07-19 19:21:12 +00:00
|
|
|
setWindowTitle(name);
|
2019-06-18 13:02:41 +00:00
|
|
|
}
|
|
|
|
|
2019-10-06 17:35:44 +00:00
|
|
|
void MemoryDockWidget::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
dockMenu->exec(mapToGlobal(event->pos()));
|
|
|
|
}
|
|
|
|
|
|
|
|
CutterSeekable *MemoryDockWidget::getSeekable() const
|
2019-06-18 13:02:41 +00:00
|
|
|
{
|
|
|
|
return seekable;
|
|
|
|
}
|