Implemented showing/hiding navigator
This commit is contained in:
parent
b6aa627ea7
commit
dd716f3d97
15 changed files with 98 additions and 79 deletions
|
@ -74,9 +74,11 @@ public:
|
|||
virtual std::vector<std::string> toolbarActions(const std::string& toolbarName) const = 0;
|
||||
virtual void setToolbarActions(const std::string& toolbarName, const std::vector<std::string>& actions) = 0;
|
||||
|
||||
virtual NavigatorOrientation navigatorOrientation() const = 0;
|
||||
virtual ValCh<bool> isNavigatorVisible() const = 0;
|
||||
virtual void setNavigatorVisible(bool visible) = 0;
|
||||
|
||||
virtual ValCh<NavigatorOrientation> navigatorOrientation() const = 0;
|
||||
virtual void setNavigatorOrientation(NavigatorOrientation orientation) = 0;
|
||||
virtual async::Channel<NavigatorOrientation> navigatorOrientationChanged() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ public:
|
|||
|
||||
virtual void addText(TextType type) = 0;
|
||||
|
||||
virtual void toggleNavigatorOrientation() = 0;
|
||||
virtual void toggleNavigator() = 0;
|
||||
};
|
||||
|
||||
using INotationInteractionPtr = std::shared_ptr<INotationInteraction>;
|
||||
|
|
|
@ -133,6 +133,9 @@ void Notation::init()
|
|||
Ms::MScore::setNudgeStep10(1.0); // Ctrl + cursor key (default 1.0)
|
||||
Ms::MScore::setNudgeStep50(0.01); // Alt + cursor key (default 0.01)
|
||||
|
||||
bool isVertical = configuration()->navigatorOrientation().val == NavigatorOrientation::Vertical;
|
||||
Ms::MScore::setVerticalOrientation(isVertical);
|
||||
|
||||
Ms::MScore::pixelRatio = Ms::DPI / QGuiApplication::primaryScreen()->logicalDotsPerInch();
|
||||
}
|
||||
|
||||
|
|
|
@ -975,7 +975,7 @@ void NotationActionController::toggleNavigatorOrientation()
|
|||
return;
|
||||
}
|
||||
|
||||
interaction->toggleNavigatorOrientation();
|
||||
interaction->toggleNavigator();
|
||||
}
|
||||
|
||||
void NotationActionController::startNoteInputIfNeed()
|
||||
|
|
|
@ -584,6 +584,10 @@ const ActionList NotationActions::m_actions = {
|
|||
ActionItem("tuplet-dialog",
|
||||
ShortcutContext::NotationActive,
|
||||
QT_TRANSLATE_NOOP("action", "Other")
|
||||
),
|
||||
ActionItem("toggle-navigator",
|
||||
ShortcutContext::NotationActive,
|
||||
QT_TRANSLATE_NOOP("action", "Toggle Navigator")
|
||||
)
|
||||
};
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ static const Settings::Key IS_MIDI_INPUT_ENABLED(module_name, "io/midi/enableInp
|
|||
|
||||
static const Settings::Key TOOLBAR_KEY(module_name, "ui/toolbar/");
|
||||
|
||||
static const Settings::Key NAVIGATOR_VISIBLE_KEY(module_name, "ui/application/startup/showNavigator");
|
||||
static const Settings::Key NAVIGATOR_ORIENTATION(module_name, "ui/canvas/scroll/verticalOrientation");
|
||||
static const bool NAVIGATOR_ORIENTATION_VERTICAL(true);
|
||||
|
||||
|
@ -99,16 +100,18 @@ void NotationConfiguration::init()
|
|||
settings()->setDefaultValue(SELECTION_PROXIMITY, Val(6));
|
||||
settings()->setDefaultValue(IS_MIDI_INPUT_ENABLED, Val(false));
|
||||
|
||||
settings()->setDefaultValue(NAVIGATOR_VISIBLE_KEY, Val(false));
|
||||
settings()->valueChanged(NAVIGATOR_VISIBLE_KEY).onReceive(nullptr, [this](const Val&) {
|
||||
m_navigatorVisibleChanged.send(isNavigatorVisible().val);
|
||||
});
|
||||
|
||||
settings()->setDefaultValue(NAVIGATOR_ORIENTATION, Val(NAVIGATOR_ORIENTATION_VERTICAL));
|
||||
settings()->valueChanged(NAVIGATOR_ORIENTATION).onReceive(nullptr, [this](const Val&) {
|
||||
m_navigatorOrientationChanged.send(navigatorOrientation());
|
||||
m_navigatorOrientationChanged.send(navigatorOrientation().val);
|
||||
});
|
||||
|
||||
// libmscore
|
||||
preferences().setBackupDirPath(globalConfiguration()->backupPath().toQString());
|
||||
|
||||
bool isVertical = navigatorOrientation() == NavigatorOrientation::Vertical;
|
||||
Ms::MScore::setVerticalOrientation(isVertical);
|
||||
}
|
||||
|
||||
QColor NotationConfiguration::anchorLineColor() const
|
||||
|
@ -264,10 +267,28 @@ void NotationConfiguration::setToolbarActions(const std::string& toolbarName, co
|
|||
settings()->setValue(toolbarSettingsKey(toolbarName), value);
|
||||
}
|
||||
|
||||
NavigatorOrientation NotationConfiguration::navigatorOrientation() const
|
||||
ValCh<bool> NotationConfiguration::isNavigatorVisible() const
|
||||
{
|
||||
ValCh<bool> visible;
|
||||
visible.ch = m_navigatorVisibleChanged;
|
||||
visible.val = settings()->value(NAVIGATOR_VISIBLE_KEY).toBool();
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
void NotationConfiguration::setNavigatorVisible(bool visible)
|
||||
{
|
||||
settings()->setValue(NAVIGATOR_VISIBLE_KEY, Val(visible));
|
||||
}
|
||||
|
||||
ValCh<NavigatorOrientation> NotationConfiguration::navigatorOrientation() const
|
||||
{
|
||||
ValCh<NavigatorOrientation> orientation;
|
||||
orientation.ch = m_navigatorOrientationChanged;
|
||||
bool isVertical = settings()->value(NAVIGATOR_ORIENTATION).toBool() == NAVIGATOR_ORIENTATION_VERTICAL;
|
||||
return isVertical ? NavigatorOrientation::Vertical : NavigatorOrientation::Horizontal;
|
||||
orientation.val = isVertical ? NavigatorOrientation::Vertical : NavigatorOrientation::Horizontal;
|
||||
|
||||
return orientation;
|
||||
}
|
||||
|
||||
void NotationConfiguration::setNavigatorOrientation(NavigatorOrientation orientation)
|
||||
|
@ -276,11 +297,6 @@ void NotationConfiguration::setNavigatorOrientation(NavigatorOrientation orienta
|
|||
settings()->setValue(NAVIGATOR_ORIENTATION, Val(isVertical));
|
||||
}
|
||||
|
||||
async::Channel<NavigatorOrientation> NotationConfiguration::navigatorOrientationChanged() const
|
||||
{
|
||||
return m_navigatorOrientationChanged;
|
||||
}
|
||||
|
||||
std::vector<std::string> NotationConfiguration::parseToolbarActions(const std::string& actions) const
|
||||
{
|
||||
if (actions.empty()) {
|
||||
|
|
|
@ -76,9 +76,11 @@ public:
|
|||
std::vector<std::string> toolbarActions(const std::string& toolbarName) const override;
|
||||
void setToolbarActions(const std::string& toolbarName, const std::vector<std::string>& actions) override;
|
||||
|
||||
NavigatorOrientation navigatorOrientation() const;
|
||||
ValCh<bool> isNavigatorVisible() const override;
|
||||
void setNavigatorVisible(bool visible) override;
|
||||
|
||||
ValCh<NavigatorOrientation> navigatorOrientation() const override;
|
||||
void setNavigatorOrientation(NavigatorOrientation orientation) override;
|
||||
async::Channel<NavigatorOrientation> navigatorOrientationChanged() const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> parseToolbarActions(const std::string& actions) const;
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
async::Channel<QColor> m_backgroundColorChanged;
|
||||
async::Channel<QColor> m_foregroundColorChanged;
|
||||
async::Channel<int> m_currentZoomChanged;
|
||||
async::Channel<bool> m_navigatorVisibleChanged;
|
||||
async::Channel<NavigatorOrientation> m_navigatorOrientationChanged;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2211,23 +2211,10 @@ void NotationInteraction::addText(TextType type)
|
|||
notifyAboutSelectionChanged();
|
||||
}
|
||||
|
||||
void NotationInteraction::toggleNavigatorOrientation()
|
||||
void NotationInteraction::toggleNavigator()
|
||||
{
|
||||
NavigatorOrientation orientation = configuration()->navigatorOrientation();
|
||||
|
||||
if (orientation == NavigatorOrientation::Vertical) {
|
||||
orientation = NavigatorOrientation::Horizontal;
|
||||
} else {
|
||||
orientation = NavigatorOrientation::Vertical;
|
||||
}
|
||||
|
||||
bool isVertical = orientation == NavigatorOrientation::Vertical;
|
||||
Ms::MScore::setVerticalOrientation(isVertical);
|
||||
score()->doLayout();
|
||||
|
||||
configuration()->setNavigatorOrientation(orientation);
|
||||
|
||||
notifyAboutNotationChanged();
|
||||
bool visible = configuration()->isNavigatorVisible().val;
|
||||
configuration()->setNavigatorVisible(!visible);
|
||||
}
|
||||
|
||||
bool NotationInteraction::needEndTextEditing(const std::vector<Element*>& newSelectedElements) const
|
||||
|
|
|
@ -129,7 +129,7 @@ public:
|
|||
|
||||
void addText(TextType type) override;
|
||||
|
||||
void toggleNavigatorOrientation() override;
|
||||
void toggleNavigator() override;
|
||||
|
||||
private:
|
||||
Ms::Score* score() const;
|
||||
|
|
|
@ -313,7 +313,7 @@ QRectF NotationNoteInput::cursorRect() const
|
|||
|
||||
QRectF result = QRectF(x, y, w, h);
|
||||
|
||||
if (configuration()->navigatorOrientation() == NavigatorOrientation::Horizontal) {
|
||||
if (configuration()->navigatorOrientation().val == NavigatorOrientation::Horizontal) {
|
||||
result.translate(system->page()->pos());
|
||||
}
|
||||
|
||||
|
|
|
@ -92,9 +92,6 @@ void NotationModule::registerExports()
|
|||
readers->reg({ "mscz", "mscx" }, std::make_shared<MsczNotationReader>());
|
||||
framework::ioc()->registerExport<INotationReadersRegister>(moduleName(), readers);
|
||||
framework::ioc()->registerExport<INotationWritersRegister>(moduleName(), std::make_shared<NotationWritersRegister>());
|
||||
|
||||
//! FIXME: init of notation should be in NotationModule::onInit
|
||||
Notation::init();
|
||||
}
|
||||
|
||||
void NotationModule::resolveImports()
|
||||
|
|
|
@ -44,7 +44,7 @@ FocusScope {
|
|||
}
|
||||
|
||||
onViewportChanged: {
|
||||
notationNavigator.setViewRect(viewport)
|
||||
notationNavigator.setCursorRect(viewport)
|
||||
}
|
||||
|
||||
onHorizontalScrollChanged: {
|
||||
|
|
|
@ -28,10 +28,8 @@ NotationNavigator::NotationNavigator(QQuickItem* parent)
|
|||
setAcceptedMouseButtons(Qt::AllButtons);
|
||||
setReadonly(true);
|
||||
|
||||
configuration()->navigatorOrientationChanged().onReceive(this, [this](NavigatorOrientation) {
|
||||
moveCanvasToPosition(QPoint(0, 0));
|
||||
emit orientationChanged();
|
||||
});
|
||||
initOrientation();
|
||||
initVisible();
|
||||
|
||||
theme()->themeChanged().onNotify(this, [this]() {
|
||||
update();
|
||||
|
@ -40,7 +38,7 @@ NotationNavigator::NotationNavigator(QQuickItem* parent)
|
|||
|
||||
bool NotationNavigator::isVerticalOrientation() const
|
||||
{
|
||||
return configuration()->navigatorOrientation() == NavigatorOrientation::Vertical;
|
||||
return configuration()->navigatorOrientation().val == NavigatorOrientation::Vertical;
|
||||
}
|
||||
|
||||
QRectF NotationNavigator::notationContentRect() const
|
||||
|
@ -98,11 +96,11 @@ void NotationNavigator::mousePressEvent(QMouseEvent* event)
|
|||
{
|
||||
QPoint logicPos = toLogical(event->pos());
|
||||
m_startMove = logicPos;
|
||||
if (m_viewRect.contains(logicPos)) {
|
||||
if (m_cursorRect.contains(logicPos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QRectF viewRect = m_viewRect;
|
||||
QRectF viewRect = m_cursorRect;
|
||||
double dx = logicPos.x() - (viewRect.x() + (viewRect.width() / 2));
|
||||
double dy = logicPos.y() - (viewRect.y() + (viewRect.height() / 2));
|
||||
|
||||
|
@ -164,40 +162,25 @@ void NotationNavigator::moveCanvasToRect(const QRect& viewRect)
|
|||
moveCanvas(-dx, -dy);
|
||||
}
|
||||
|
||||
void NotationNavigator::setViewRect(const QRect& rect)
|
||||
void NotationNavigator::setCursorRect(const QRect& rect)
|
||||
{
|
||||
QRect newViewRect = rect;
|
||||
if (!newViewRect.isValid()) {
|
||||
QRect newCursorRect = rect;
|
||||
if (!newCursorRect.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
newViewRect = notationContentRect().intersected(QRectF(newViewRect)).toRect();
|
||||
newCursorRect = notationContentRect().intersected(QRectF(newCursorRect)).toRect();
|
||||
|
||||
moveCanvasToRect(newViewRect);
|
||||
moveCanvasToRect(newCursorRect);
|
||||
|
||||
m_viewRect = newViewRect;
|
||||
m_cursorRect = newCursorRect;
|
||||
rescale();
|
||||
update();
|
||||
}
|
||||
|
||||
int NotationNavigator::orientation() const
|
||||
{
|
||||
return static_cast<int>(configuration()->navigatorOrientation());
|
||||
}
|
||||
|
||||
void NotationNavigator::onCurrentNotationChanged()
|
||||
{
|
||||
auto notation = currentNotation();
|
||||
setVisible(notation != nullptr);
|
||||
|
||||
if (!notation) {
|
||||
return;
|
||||
}
|
||||
|
||||
notation->notationChanged().onNotify(this, [this]() {
|
||||
rescale();
|
||||
update();
|
||||
});
|
||||
return static_cast<int>(configuration()->navigatorOrientation().val);
|
||||
}
|
||||
|
||||
INotationPtr NotationNavigator::currentNotation() const
|
||||
|
@ -205,6 +188,28 @@ INotationPtr NotationNavigator::currentNotation() const
|
|||
return globalContext()->currentNotation();
|
||||
}
|
||||
|
||||
void NotationNavigator::initOrientation()
|
||||
{
|
||||
ValCh<NavigatorOrientation> orientation = configuration()->navigatorOrientation();
|
||||
orientation.ch.onReceive(this, [this](NavigatorOrientation) {
|
||||
moveCanvasToPosition(QPoint(0, 0));
|
||||
emit orientationChanged();
|
||||
});
|
||||
|
||||
emit orientationChanged();
|
||||
}
|
||||
|
||||
void NotationNavigator::initVisible()
|
||||
{
|
||||
ValCh<bool> visible = configuration()->isNavigatorVisible();
|
||||
visible.ch.onReceive(this, [this](bool visible) {
|
||||
setVisible(visible);
|
||||
update();
|
||||
});
|
||||
|
||||
setVisible(visible.val);
|
||||
}
|
||||
|
||||
ViewMode NotationNavigator::notationViewMode() const
|
||||
{
|
||||
auto notation = currentNotation();
|
||||
|
@ -217,22 +222,24 @@ ViewMode NotationNavigator::notationViewMode() const
|
|||
|
||||
void NotationNavigator::paint(QPainter* painter)
|
||||
{
|
||||
painter->fillRect(viewport(), configuration()->backgroundColor());
|
||||
if (!isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
NotationPaintView::paint(painter);
|
||||
paintViewRect(painter);
|
||||
paintCursor(painter);
|
||||
|
||||
paintPageNumbers(painter);
|
||||
}
|
||||
|
||||
void NotationNavigator::paintViewRect(QPainter* painter)
|
||||
void NotationNavigator::paintCursor(QPainter* painter)
|
||||
{
|
||||
QColor color(configuration()->selectionColor());
|
||||
QPen pen(color, configuration()->borderWidth());
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(QColor(color.red(), color.green(), color.blue(), configuration()->cursorOpacity()));
|
||||
|
||||
painter->drawRect(m_viewRect);
|
||||
painter->drawRect(m_cursorRect);
|
||||
}
|
||||
|
||||
void NotationNavigator::paintPageNumbers(QPainter* painter)
|
||||
|
|
|
@ -43,13 +43,10 @@ class NotationNavigator : public NotationPaintView
|
|||
public:
|
||||
NotationNavigator(QQuickItem* parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void setViewRect(const QRect& rect);
|
||||
Q_INVOKABLE void setCursorRect(const QRect& rect);
|
||||
|
||||
int orientation() const;
|
||||
|
||||
public slots:
|
||||
void onCurrentNotationChanged();
|
||||
|
||||
signals:
|
||||
void moveNotationRequested(int dx, int dy);
|
||||
void orientationChanged();
|
||||
|
@ -57,6 +54,9 @@ signals:
|
|||
private:
|
||||
INotationPtr currentNotation() const;
|
||||
|
||||
void initOrientation();
|
||||
void initVisible();
|
||||
|
||||
ViewMode notationViewMode() const;
|
||||
|
||||
void rescale();
|
||||
|
@ -67,7 +67,7 @@ private:
|
|||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
|
||||
void paintViewRect(QPainter* painter);
|
||||
void paintCursor(QPainter* painter);
|
||||
void paintPageNumbers(QPainter* painter);
|
||||
|
||||
void moveCanvasToRect(const QRect& viewRect);
|
||||
|
@ -77,7 +77,7 @@ private:
|
|||
QRectF notationContentRect() const;
|
||||
PageList pages() const;
|
||||
|
||||
QRect m_viewRect;
|
||||
QRect m_cursorRect;
|
||||
QPoint m_startMove;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ void NotationPaintView::initBackground()
|
|||
|
||||
void NotationPaintView::initNavigatorOrientation()
|
||||
{
|
||||
configuration()->navigatorOrientationChanged().onReceive(this, [this](NavigatorOrientation) {
|
||||
configuration()->navigatorOrientation().ch.onReceive(this, [this](NavigatorOrientation) {
|
||||
moveCanvasToPosition(QPoint(0, 0));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue