fixed code-review and rebasing issues

This commit is contained in:
Roman Pudashkin 2021-08-02 09:27:25 +02:00
parent 71d82318dd
commit b173ee8da3
10 changed files with 101 additions and 55 deletions

View file

@ -196,7 +196,7 @@ DockPanelHolder* DockPage::panelHolderByLocation(DockBase::DockLocation location
return nullptr;
}
bool DockPage::isDockOpened(const QString& dockName) const
bool DockPage::isDockOpen(const QString& dockName) const
{
const DockBase* dock = dockByName(dockName);
return dock ? dock->isOpen() : false;
@ -204,17 +204,17 @@ bool DockPage::isDockOpened(const QString& dockName) const
void DockPage::toggleDock(const QString& dockName)
{
setDockOpened(dockName, !isDockOpened(dockName));
setDockOpen(dockName, !isDockOpen(dockName));
}
void DockPage::setDockOpened(const QString& dockName, bool opened)
void DockPage::setDockOpen(const QString& dockName, bool open)
{
DockBase* dock = dockByName(dockName);
if (!dock) {
return;
}
if (opened) {
if (open) {
dock->open();
} else {
dock->close();

View file

@ -77,9 +77,9 @@ public:
DockToolBarHolder* toolBarHolderByLocation(DockBase::DockLocation location) const;
DockPanelHolder* panelHolderByLocation(DockBase::DockLocation location) const;
bool isDockOpened(const QString& dockName) const;
bool isDockOpen(const QString& dockName) const;
void toggleDock(const QString& dockName);
void setDockOpened(const QString& dockName, bool opened);
void setDockOpen(const QString& dockName, bool open);
public slots:
void setUri(const QString& uri);

View file

@ -203,10 +203,10 @@ void DockWindow::loadPage(const QString& uri)
emit currentPageUriChanged(uri);
}
bool DockWindow::isDockOpened(const QString& dockName) const
bool DockWindow::isDockOpen(const QString& dockName) const
{
const DockPage* currPage = currentPage();
return currPage ? currPage->isDockOpened(dockName) : false;
return currPage ? currPage->isDockOpen(dockName) : false;
}
void DockWindow::toggleDock(const QString& dockName)
@ -217,11 +217,11 @@ void DockWindow::toggleDock(const QString& dockName)
}
}
void DockWindow::setDockOpened(const QString& dockName, bool opened)
void DockWindow::setDockOpen(const QString& dockName, bool open)
{
DockPage* currPage = currentPage();
if (currPage) {
currPage->setDockOpened(dockName, opened);
currPage->setDockOpen(dockName, open);
}
}

View file

@ -74,9 +74,9 @@ public:
Q_INVOKABLE void loadPage(const QString& uri);
bool isDockOpened(const QString& dockName) const;
bool isDockOpen(const QString& dockName) const;
void toggleDock(const QString& dockName);
void setDockOpened(const QString& dockName, bool opened);
void setDockOpen(const QString& dockName, bool open);
public slots:
void setMainToolBarDockingHolder(DockToolBarHolder* mainToolBarDockingHolder);

View file

@ -116,7 +116,7 @@ void NotationPageModel::init(QQuickItem* dockWindow)
std::map<PanelType, bool> initialState;
for (PanelType type : m_panelTypeToDockName.keys()) {
initialState[type] = m_window->isDockOpened(m_panelTypeToDockName[type]);
initialState[type] = m_window->isDockOpen(m_panelTypeToDockName[type]);
}
pageState()->setIsPanelsVisible(initialState);
@ -132,7 +132,7 @@ void NotationPageModel::init(QQuickItem* dockWindow)
{ "toggle-noteinput", PanelType::NoteInputBar },
{ "toggle-notationtoolbar", PanelType::NotationToolBar },
{ "toggle-undoredo", PanelType::UndoRedoToolBar },
{ "toggle-transport", PanelType::PlaybackToolBar },
{ "toggle-transport", PanelType::PlaybackToolBar }
};
for (const std::string& actionCode : actionToPanelType.keys()) {
@ -168,7 +168,7 @@ void NotationPageModel::togglePanel(PanelType type)
void NotationPageModel::updateDrumsetPanelVisibility()
{
auto setDrumsetPanelVisible = [this](bool visible) {
m_window->setDockOpened(m_panelTypeToDockName[PanelType::DrumsetPanel], visible);
m_window->setDockOpen(m_panelTypeToDockName[PanelType::DrumsetPanel], visible);
pageState()->setIsPanelsVisible({ { PanelType::DrumsetPanel, visible } });
};

View file

@ -1,6 +1,27 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "drumsetpanelview.h"
#include "internal/widgets/drumsetpalette.h"
#include "widgets/drumsetpalette.h"
using namespace mu::notation;
@ -9,42 +30,42 @@ class DrumsetPaletteAdapter : public ui::IDisplayableWidget
{
public:
DrumsetPaletteAdapter()
: m_msDrumsetPalette(new Ms::DrumsetPalette())
: m_drumsetPaletteWidget(new DrumsetPalette())
{
}
~DrumsetPaletteAdapter() override
{
delete m_msDrumsetPalette;
delete m_drumsetPaletteWidget;
}
void setNotation(INotationPtr notation)
{
m_msDrumsetPalette->setNotation(notation);
m_drumsetPaletteWidget->setNotation(notation);
}
void updateDrumset()
{
m_msDrumsetPalette->updateDrumset();
m_drumsetPaletteWidget->updateDrumset();
}
async::Channel<QString> pitchNameChanged() const
{
return m_msDrumsetPalette->pitchNameChanged();
return m_drumsetPaletteWidget->pitchNameChanged();
}
private:
QWidget* qWidget() override
{
return m_msDrumsetPalette;
return m_drumsetPaletteWidget;
}
bool handleEvent(QEvent* event) override
{
return m_msDrumsetPalette->handleEvent(event);
return m_drumsetPaletteWidget->handleEvent(event);
}
Ms::DrumsetPalette* m_msDrumsetPalette = nullptr;
DrumsetPalette* m_drumsetPaletteWidget = nullptr;
};
}

View file

@ -25,30 +25,30 @@
#include "translation.h"
#include "log.h"
#include "libmscore/chord.h"
#include "libmscore/note.h"
#include "libmscore/drumset.h"
#include "libmscore/score.h"
#include "libmscore/staff.h"
#include "libmscore/part.h"
#include "libmscore/stem.h"
#include "libmscore/mscore.h"
#include "libmscore/undo.h"
#include "engraving/libmscore/chord.h"
#include "engraving/libmscore/note.h"
#include "engraving/libmscore/drumset.h"
#include "engraving/libmscore/score.h"
#include "engraving/libmscore/staff.h"
#include "engraving/libmscore/part.h"
#include "engraving/libmscore/stem.h"
#include "engraving/libmscore/mscore.h"
#include "engraving/libmscore/undo.h"
using namespace mu::notation;
using namespace mu::palette;
namespace Ms {
DrumsetPalette::DrumsetPalette(QWidget* parent)
: PaletteScrollArea(nullptr, parent)
{
setObjectName("DrumsetPalette");
setFocusPolicy(Qt::NoFocus);
m_drumPalette = new Palette(this);
m_drumPalette = new PaletteWidget(this);
m_drumPalette->setMag(0.8);
m_drumPalette->setSelectable(true);
m_drumPalette->setUseDoubleClickToActivate(true);
m_drumPalette->setGrid(28, 60);
m_drumPalette->setUseDoubleClickForApplyingElements(true);
m_drumPalette->setGridSize(28, 60);
m_drumPalette->setContextMenuPolicy(Qt::PreventContextMenu);
setWidget(m_drumPalette);
@ -136,12 +136,7 @@ void DrumsetPalette::updateDrumset()
note->setCachedNoteheadSym(noteheadSym); // we use the cached notehead so we don't recompute it at each layout
chord->add(note);
int sc = m_drumset->shortcut(pitch);
QString shortcut;
if (sc) {
shortcut = QChar(sc);
}
m_drumPalette->append(chord, mu::qtrc("drumset", m_drumset->name(pitch).toUtf8().data()), shortcut);
m_drumPalette->appendElement(chord, mu::qtrc("drumset", m_drumset->name(pitch).toUtf8().data()));
}
noteInput->setDrumNote(selectedDrumNote());
@ -160,7 +155,7 @@ void DrumsetPalette::drumNoteSelected(int val)
return;
}
ElementPtr element = m_drumPalette->element(val);
Ms::ElementPtr element = m_drumPalette->elementForCellAt(val);
if (!element || element->type() != ElementType::CHORD) {
return;
}
@ -184,12 +179,12 @@ void DrumsetPalette::drumNoteSelected(int val)
int DrumsetPalette::selectedDrumNote()
{
int idx = m_drumPalette->getSelectedIdx();
int idx = m_drumPalette->selectedIdx();
if (idx < 0) {
return -1;
}
ElementPtr element = m_drumPalette->element(idx);
Ms::ElementPtr element = m_drumPalette->elementForCellAt(idx);
if (element && element->type() == ElementType::CHORD) {
const Chord* ch = dynamic_cast<Chord*>(element.get());
const Note* note = ch->downNote();
@ -243,4 +238,3 @@ INotationNoteInputPtr DrumsetPalette::noteInput() const
{
return m_notation ? m_notation->interaction()->noteInput() : nullptr;
}
}

View file

@ -23,17 +23,17 @@
#ifndef MU_PALETTE_DRUMSETPALETTE_H
#define MU_PALETTE_DRUMSETPALETTE_H
#include "palette/palette.h"
#include "palettewidget.h"
#include "notation/inotation.h"
#include "modularity/ioc.h"
#include "actions/iactionsdispatcher.h"
namespace Ms {
class Score;
class Drumset;
class Staff;
}
namespace mu::palette {
class DrumsetPalette : public PaletteScrollArea
{
Q_OBJECT
@ -66,12 +66,11 @@ private:
mu::notation::INotationNoteInputPtr noteInput() const;
Palette* m_drumPalette = nullptr;
const Drumset* m_drumset = nullptr;
PaletteWidget* m_drumPalette = nullptr;
const Ms::Drumset* m_drumset = nullptr;
mu::notation::INotationPtr m_notation;
mu::async::Channel<QString> m_pitchNameChanged;
};
} // namespace Ms
}
#endif // MU_PALETTE_DRUMSETPALETTE_H

View file

@ -380,6 +380,16 @@ void PaletteWidget::setApplyingElementsDisabled(bool val)
m_isApplyingElementsDisabled = val;
}
bool PaletteWidget::useDoubleClickForApplyingElements() const
{
return m_useDoubleClickForApplyingElements;
}
void PaletteWidget::setUseDoubleClickForApplyingElements(bool val)
{
m_useDoubleClickForApplyingElements = val;
}
void PaletteWidget::applyCurrentElementToScore()
{
applyElementAtIndex(m_currentIdx);
@ -676,6 +686,13 @@ void PaletteWidget::mousePressEvent(QMouseEvent* ev)
update();
}
void PaletteWidget::mouseDoubleClickEvent(QMouseEvent* ev)
{
if (m_useDoubleClickForApplyingElements) {
applyElementAtPosition(ev->pos(), ev->modifiers());
}
}
void PaletteWidget::mouseMoveEvent(QMouseEvent* ev)
{
if ((m_currentIdx != -1) && (m_dragIdx == m_currentIdx) && (ev->buttons() & Qt::LeftButton)
@ -723,7 +740,10 @@ void PaletteWidget::mouseReleaseEvent(QMouseEvent* event)
m_pressedIndex = -1;
update();
applyElementAtPosition(event->pos(), event->modifiers());
if (!m_useDoubleClickForApplyingElements) {
applyElementAtPosition(event->pos(), event->modifiers());
}
}
void PaletteWidget::leaveEvent(QEvent*)
@ -1092,6 +1112,11 @@ void PaletteWidget::writeToFile(const QString& path) const
m_palette->writeToFile(path);
}
bool PaletteWidget::handleEvent(QEvent* event)
{
return QWidget::event(event);
}
// ====================================================
// PaletteScrollArea
// ====================================================

View file

@ -107,6 +107,8 @@ public:
// Applying elements
bool isApplyingElementsDisabled() const;
void setApplyingElementsDisabled(bool val);
bool useDoubleClickForApplyingElements() const;
void setUseDoubleClickForApplyingElements(bool val);
void applyCurrentElementToScore();
@ -127,6 +129,9 @@ public:
bool readFromFile(const QString& path);
void writeToFile(const QString& path) const;
// events
bool handleEvent(QEvent* event);
signals:
void changed();
void boxClicked(int index);
@ -135,6 +140,7 @@ private:
bool event(QEvent*) override;
void mousePressEvent(QMouseEvent*) override;
void mouseDoubleClickEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void mouseMoveEvent(QMouseEvent*) override;
void leaveEvent(QEvent*) override;
@ -171,6 +177,7 @@ private:
bool m_selectable = false;
bool m_isReadOnly = false;
bool m_isApplyingElementsDisabled = false;
bool m_useDoubleClickForApplyingElements = false;
bool m_showContextMenu = true;
int m_currentIdx = -1;