Skip to content

Commit

Permalink
Merge pull request #5353 from dmitrio95/palette4-squashed
Browse files Browse the repository at this point in the history
Palettes redesign, part 4
  • Loading branch information
anatoly-os committed Sep 30, 2019
2 parents 4e75169 + 973ba22 commit 7b2b7af
Show file tree
Hide file tree
Showing 26 changed files with 245 additions and 109 deletions.
35 changes: 24 additions & 11 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,8 @@ MuseScore::MuseScore()
menuDebug->addAction(a);
a = getAction("relayout");
menuDebug->addAction(a);
a = getAction("qml-reload-source");
menuDebug->addAction(a);
Workspace::addMenuAndString(menuDebug, "menu-debug");
#endif

Expand Down Expand Up @@ -1973,6 +1975,12 @@ MuseScore::~MuseScore()
autoUpdater->cleanup();

delete synti;

// A crash is possible if paletteWorkspace gets
// deleted before paletteWidget, so force the widget
// be deleted before paletteWorkspace.
delete paletteWidget;
paletteWidget = nullptr;
}

//---------------------------------------------------------
Expand Down Expand Up @@ -5868,29 +5876,20 @@ void MuseScore::cmd(QAction* a)
}
if (cmdn == "toggle-palette") {
showPalette(a->isChecked());
#if 0
PaletteBox* pb = mscore->getPaletteBox();
QLineEdit* sb = pb->searchBox();
if (a->isChecked()) {
lastFocusWidget = QApplication::focusWidget();
sb->setFocus();
if (pb->noSelection())
pb->setKeyboardNavigation(false);
else
pb->setKeyboardNavigation(true);
paletteWidget->activateSearchBox();
}
else {
if (lastFocusWidget)
lastFocusWidget->setFocus();
}
#endif
return;
}
if (cmdn == "palette-search") {
// TODO: use new search box, or rename command to just "palette"
showPalette(true);
if (paletteWidget)
paletteWidget->setFocus();
paletteWidget->activateSearchBox();
return;
}
if (cmdn == "apply-current-palette-element") {
Expand Down Expand Up @@ -6449,6 +6448,20 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
cs->update();
}
}
else if (cmd == "qml-reload-source") {
const QList<QmlDockWidget*> qmlWidgets = findChildren<QmlDockWidget*>();

const QString oldPrefix = QmlDockWidget::qmlSourcePrefix();
useSourceQmlFiles = true;
const QString newPrefix = QmlDockWidget::qmlSourcePrefix();

getQmlUiEngine()->clearComponentCache();

for (QmlDockWidget* w : qmlWidgets) {
const QString urlString = w->source().toString().replace(oldPrefix, newPrefix);
w->setSource(QUrl(urlString));
}
}
#endif
else {
if (cv) {
Expand Down
14 changes: 11 additions & 3 deletions mscore/palette/palettecelldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void PaletteCellPropertiesDialog::fillControlsWithData()
ui->yoffset->setValue(cell->yoffset);
ui->scale->setValue(cell->mag);
ui->drawStaff->setChecked(cell->drawStaff);
ui->name->setText(cell->name);
ui->name->setText(cell->translatedName());
}

PaletteCellPropertiesDialog::~PaletteCellPropertiesDialog()
Expand All @@ -68,13 +68,15 @@ void PaletteCellPropertiesDialog::drawStaffCheckBoxChanged(int state)
{
isDrawStaffCheckBoxChanged = (state != drawStaffCheckboxInitialState);
cell->drawStaff = ui->drawStaff->isChecked();
cell->custom = true;
emit changed();
}

void PaletteCellPropertiesDialog::nameChanged(const QString &text)
{
isNameChanged = (text != initialName);
cell->name = text;
isNameChanged = (text != initialTranslatedName);
cell->name = isNameChanged ? text : initialName; // preserve old name if possible to keep translations
// don't mark cell custom if only its name gets changed
emit changed();
}

Expand All @@ -83,6 +85,7 @@ void PaletteCellPropertiesDialog::xOffsetChanged(double xOffset)
//see https://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare to clarify using 1.f below
isXOffsetChanged = !qFuzzyCompare((1.f + xOffset), (1.f + initialXOffset));
cell->xoffset = xOffset;
cell->custom = true;
emit changed();
}

Expand All @@ -91,6 +94,7 @@ void PaletteCellPropertiesDialog::yOffsetChanged(double yOffset)
//see https://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare to clarify using 1.f below
isYOffsetChanged = !qFuzzyCompare((1.f + yOffset), (1.f + initialYOffset));
cell->yoffset = yOffset;
cell->custom = true;
emit changed();
}

Expand All @@ -99,6 +103,7 @@ void PaletteCellPropertiesDialog::scaleChanged(double scale)
//see https://doc.qt.io/qt-5/qtglobal.html#qFuzzyCompare to clarify using 1.f below
isScaleChanged = !qFuzzyCompare((1.f + scale), (1.f + initialScale));
cell->mag = scale;
cell->custom = true;
emit changed();
}
/*
Expand Down Expand Up @@ -140,9 +145,11 @@ void PaletteCellPropertiesDialog::setInitialProperties()
{
drawStaffCheckboxInitialState = cell->drawStaff ? Qt::Checked : Qt::Unchecked;
initialName = cell->name;
initialTranslatedName = cell->translatedName();
initialYOffset = cell->yoffset;
initialXOffset = cell->xoffset;
initialScale = cell->mag;
initialCustomState = cell->custom;
}

bool PaletteCellPropertiesDialog::areInitialPropertiesChanged() const
Expand All @@ -157,6 +164,7 @@ void PaletteCellPropertiesDialog::applyInitialPropertiesToThePalette()
cell->xoffset = initialXOffset;
cell->yoffset = initialYOffset;
cell->mag = initialScale;
cell->custom = initialCustomState;
}

} // namespace Ms
2 changes: 2 additions & 0 deletions mscore/palette/palettecelldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class PaletteCellPropertiesDialog : public QDialog {

int drawStaffCheckboxInitialState = 0;
QString initialName;
QString initialTranslatedName;
double initialXOffset = 0.f;
double initialYOffset = 0.f;
double initialScale = 0.f;
bool initialCustomState = false;

public:
PaletteCellPropertiesDialog(PaletteCell* p, QWidget* parent = 0);
Expand Down
7 changes: 4 additions & 3 deletions mscore/palette/palettedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ PalettePropertiesDialog::~PalettePropertiesDialog()

void PalettePropertiesDialog::fillControlsWithData()
{
ui->name->setText(palette->name());
ui->name->setText(palette->translatedName());
const QSize grid = palette->gridSize();
ui->cellWidth->setValue(grid.width());
ui->cellHeight->setValue(grid.height());
Expand Down Expand Up @@ -95,8 +95,8 @@ void PalettePropertiesDialog::gridCheckBoxChanged(int state)

void PalettePropertiesDialog::nameChanged(const QString &text)
{
isNameChanged = (text != initialName);
palette->setName(ui->name->text());
isNameChanged = (text != initialTranslatedName);
palette->setName(isNameChanged ? ui->name->text() : initialName); // preserve old name if possible to keep translations
emit changed();
}

Expand Down Expand Up @@ -168,6 +168,7 @@ void PalettePropertiesDialog::setInitialProperties()
{
gridCheckboxInitialState = palette->drawGrid() ? Qt::Checked : Qt::Unchecked;
initialName = palette->name();
initialTranslatedName = palette->translatedName();
initialWidth = palette->gridSize().width();
initialHeight = palette->gridSize().height();
initialOffset = palette->yOffset();
Expand Down
1 change: 1 addition & 0 deletions mscore/palette/palettedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PalettePropertiesDialog : public QDialog {

int gridCheckboxInitialState = 0;
QString initialName;
QString initialTranslatedName;
int initialWidth = 0;
int initialHeight = 0;
double initialOffset = 0.f;
Expand Down
2 changes: 1 addition & 1 deletion mscore/palette/palettemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ QVariant PaletteTreeModel::data(const QModelIndex& index, int role) const
switch (role) {
case Qt::DisplayRole:
case Qt::AccessibleTextRole:
return qApp->translate("Palette", pp->name().toUtf8());
return pp->translatedName();
case VisibleRole:
return pp->visible();
case CustomRole:
Expand Down
2 changes: 2 additions & 0 deletions mscore/palette/palettetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class PalettePanel {
const QString& name() const { return _name; }
void setName(const QString& str) { _name = str; }

QString translatedName() const { return qApp->translate("Palette", name().toUtf8()); }

QSize gridSize() const { return _gridSize; }
void setGrid(QSize s) { _gridSize = s; }
void setGrid(int w, int h) { _gridSize = QSize(w, h); }
Expand Down
12 changes: 11 additions & 1 deletion mscore/palette/palettewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ PaletteWidget::PaletteWidget(PaletteWorkspace* w, QQmlEngine* e, QWidget* parent
setupStyle();
ctx->setContextProperty("mscore", qmlInterface);

setSource(QUrl("qrc:/qml/palettes/PalettesWidget.qml"));
setSource(QUrl(qmlSourcePrefix() + "qml/palettes/PalettesWidget.qml"));

singlePaletteAction = new QAction(this);
singlePaletteAction->setCheckable(true);
Expand Down Expand Up @@ -121,6 +121,16 @@ void PaletteWidget::setupStyle()
qmlInterface->setPaletteBackground(QColor("#f9f9f9"));
}

//---------------------------------------------------------
// PaletteWidget::activateSearchBox
//---------------------------------------------------------

void PaletteWidget::activateSearchBox()
{
ensureQmlViewFocused();
qmlInterface->requestPaletteSearch();
}

//---------------------------------------------------------
// PaletteWidget::showEvent
//---------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions mscore/palette/palettewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PaletteQmlInterface : public QObject
signals:
void paletteWorkspaceChanged();
void paletteBackgroundChanged();
void paletteSearchRequested();

public:
PaletteQmlInterface(PaletteWorkspace* workspace, QmlNativeToolTip* t, QObject* parent = nullptr);
Expand All @@ -59,6 +60,8 @@ class PaletteQmlInterface : public QObject
QColor paletteBackground() const { return _paletteBackground; }
void setPaletteBackground(const QColor& val);

void requestPaletteSearch() { emit paletteSearchRequested(); }

Q_INVOKABLE Qt::KeyboardModifiers keyboardModifiers() const { return QGuiApplication::keyboardModifiers(); }
};

Expand Down Expand Up @@ -87,6 +90,8 @@ class PaletteWidget : public QmlDockWidget
PaletteWidget(PaletteWorkspace* w, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
PaletteWidget(PaletteWorkspace* w, QQmlEngine* e, QWidget* parent, Qt::WindowFlags flags = Qt::WindowFlags());

void activateSearchBox();

void showEvent(QShowEvent* event) override;
void changeEvent(QEvent* evt) override;
};
Expand Down
6 changes: 3 additions & 3 deletions mscore/palette/paletteworkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ AbstractPaletteController::RemoveAction UserPaletteController::showHideOrDeleteD
msg.setText(question);
msg.setTextFormat(Qt::PlainText);
QPushButton* deleteButton = msg.addButton(tr("Delete permanently"), QMessageBox::DestructiveRole);
QPushButton* hideButton = msg.addButton(tr("Keep a copy"), QMessageBox::AcceptRole);
QPushButton* hideButton = msg.addButton(tr("Hide"), QMessageBox::AcceptRole);
msg.addButton(QMessageBox::Cancel);
msg.setDefaultButton(hideButton);

Expand Down Expand Up @@ -333,7 +333,7 @@ AbstractPaletteController::RemoveAction UserPaletteController::queryRemoveAction
}

if (visible)
return showHideOrDeleteDialog(tr("Do you want to permanently delete this custom palette cell or keep a copy in the library?"));
return showHideOrDeleteDialog(tr("Do you want to hide this custom palette cell or permanently delete it?"));
else {
const auto answer = QMessageBox::question(
nullptr,
Expand All @@ -351,7 +351,7 @@ AbstractPaletteController::RemoveAction UserPaletteController::queryRemoveAction
}
else {
if (visible && custom)
return showHideOrDeleteDialog(tr("Do you want to permanently delete this custom palette or keep a copy in the \"More Palettes\" list?"));
return showHideOrDeleteDialog(tr("Do you want to hide this custom palette or permanently delete it?"));
return RemoveAction::Hide;
}
}
Expand Down
3 changes: 1 addition & 2 deletions mscore/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
<file>qml/palettes/utils.js</file>
<file>qml/palettes/icons/arrow_drop_down.png</file>
<file>qml/palettes/icons/arrow_right_black.png</file>
<file>qml/palettes/icons/backspace.png</file>
<file>qml/palettes/icons/clear.png</file>
<file>qml/palettes/icons/delete.png</file>
<file>qml/palettes/icons/more.png</file>
<file>qml/palettes/icons/pin.png</file>
<file>qml/palettes/icons/search.png</file>
</qresource>
</RCC>
2 changes: 1 addition & 1 deletion mscore/qml/nativetooltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QmlNativeToolTip : public QObject {
Q_PROPERTY(QString text READ text WRITE setText)

QWidget* _widget;
QQuickItem* _item = nullptr;
QPointer<QQuickItem> _item = nullptr;
QString _text;
QString _lastShownText;
QTimer _timer;
Expand Down
Loading

0 comments on commit 7b2b7af

Please sign in to comment.