improved palette configuration

This commit is contained in:
Igor Korsukov 2020-07-10 10:02:26 +02:00
parent 1bdd9057d1
commit 9221b9d60c
21 changed files with 130 additions and 103 deletions

View file

@ -99,7 +99,8 @@ public:
virtual void message(Type type, const std::string& title, const std::string& text) const = 0;
// files
virtual io::path selectOpeningFile(const std::string& title, const std::string& dir, const std::string& filter) = 0;
virtual io::path selectOpeningFile(const QString& title, const QString& dir, const QString& filter) = 0;
virtual io::path selectSavingFile(const QString& title, const QString& dir, const QString& filter) = 0;
// custom
virtual RetVal<Val> require(const std::string& uri) const = 0;

View file

@ -146,14 +146,15 @@ void Interactive::message(Type type, const std::string& title, const std::string
msgBox.exec();
}
mu::io::path Interactive::selectOpeningFile(const std::string& title,
const std::string& dir,
const std::string& filter)
mu::io::path Interactive::selectOpeningFile(const QString& title, const QString& dir, const QString& filter)
{
QString path = QFileDialog::getOpenFileName(nullptr, /*parent*/
QString::fromStdString(title),
QString::fromStdString(dir),
QString::fromStdString(filter));
QString path = QFileDialog::getOpenFileName(mainWindow()->qMainWindow(), title, dir, filter);
return io::pathFromQString(path);
}
io::path Interactive::selectSavingFile(const QString& title, const QString& dir, const QString& filter)
{
QString path = QFileDialog::getSaveFileName(mainWindow()->qMainWindow(), title, dir, filter);
return io::pathFromQString(path);
}

View file

@ -22,12 +22,15 @@
#include "iinteractive.h"
#include "modularity/ioc.h"
#include "ui/iqmllaunchprovider.h"
#include "framework/ui/imainwindow.h"
namespace mu {
namespace framework {
class Interactive : public IInteractive
{
INJECT(global, IQmlLaunchProvider, provider)
INJECT(palette, mu::framework::IMainWindow, mainWindow)
public:
Interactive() = default;
@ -47,7 +50,8 @@ public:
void message(Type type, const std::string& title, const std::string& text) const override;
// files
io::path selectOpeningFile(const std::string& title, const std::string& dir, const std::string& filter) override;
io::path selectOpeningFile(const QString& title, const QString& dir, const QString& filter) override;
io::path selectSavingFile(const QString& title, const QString& dir, const QString& filter) override;
// custom
RetVal<Val> require(const std::string& uri) const override;

View file

@ -1,10 +1,10 @@
#include "uiconfiguration.h"
#include "settings.h"
#include "mscore/globals.h"
namespace mu {
namespace framework {
using ThemeType = mu::framework::IUiConfiguration::ThemeType;
static const std::string module_name("ui");
@ -18,17 +18,17 @@ UiConfiguration::UiConfiguration()
settings()->addItem(FONT_FAMILY_KEY, Val("FreeSans"));
settings()->addItem(FONT_SIZE_KEY, Val(12));
settings()->valueChanged(THEME_TYPE_KEY).onReceive(nullptr, [this] (const Val& val) {
m_currentThemeTypeChannel.send(static_cast<ThemeType>(val.toInt()));
});
settings()->valueChanged(THEME_TYPE_KEY).onReceive(nullptr, [this](const Val& val) {
m_currentThemeTypeChannel.send(static_cast<ThemeType>(val.toInt()));
});
settings()->valueChanged(FONT_FAMILY_KEY).onReceive(nullptr, [this] (const Val& val) {
m_currentFontFamilyChannel.send(QString::fromStdString(val.toString()));
});
settings()->valueChanged(FONT_FAMILY_KEY).onReceive(nullptr, [this](const Val& val) {
m_currentFontFamilyChannel.send(QString::fromStdString(val.toString()));
});
settings()->valueChanged(FONT_SIZE_KEY).onReceive(nullptr, [this] (const Val& val) {
m_currentFontSizeChannel.send(val.toInt());
});
settings()->valueChanged(FONT_SIZE_KEY).onReceive(nullptr, [this](const Val& val) {
m_currentFontSizeChannel.send(val.toInt());
});
}
ThemeType UiConfiguration::themeType() const
@ -61,5 +61,9 @@ async::Channel<int> UiConfiguration::fontSizeChanged()
return m_currentFontSizeChannel;
}
float UiConfiguration::guiScaling() const
{
return static_cast<float>(Ms::guiScaling);
}
}
}

View file

@ -27,6 +27,7 @@ namespace framework {
class UiConfiguration : public IUiConfiguration
{
public:
UiConfiguration();
ThemeType themeType() const override;
@ -38,6 +39,8 @@ public:
int fontSize() const override;
async::Channel<int> fontSizeChanged() override;
float guiScaling() const override;
private:
async::Channel<ThemeType> m_currentThemeTypeChannel;

View file

@ -47,6 +47,8 @@ public:
virtual int fontSize() const = 0;
virtual async::Channel<int> fontSizeChanged() = 0;
virtual float guiScaling() const = 0;
};
}
}

View file

@ -21,6 +21,7 @@
#include "log.h"
#include "settings.h"
using namespace mu;
using namespace mu::scene::notation;
using namespace mu::framework;
using namespace mu::async;
@ -28,16 +29,32 @@ using namespace mu::async;
static std::string module_name("notation_scene");
static const Settings::Key BACKGROUND_COLOR(module_name, "ui/canvas/background/color");
static const Settings::Key FOREGROUND_COLOR(module_name, "ui/canvas/foreground/color");
static const Settings::Key FOREGROUND_USE_USER_COLOR(module_name, "ui/canvas/foreground/useColor");
static const Settings::Key SELECTION_PROXIMITY(module_name, "ui/canvas/misc/selectionProximity");
void SceneNotationConfiguration::init()
{
settings()->addItem(BACKGROUND_COLOR, Val(QColor("#D6E0E9")));
settings()->addItem(BACKGROUND_COLOR, Val(QColor("#142433")));
settings()->valueChanged(BACKGROUND_COLOR).onReceive(nullptr, [this](const Val& val) {
LOGD() << "BACKGROUND_COLOR changed: " << val.toString();
m_backgroundColorChanged.send(val.toQColor());
});
settings()->addItem(FOREGROUND_COLOR, Val(QColor("#f9f9f9")));
settings()->valueChanged(FOREGROUND_COLOR).onReceive(nullptr, [this](const Val& val) {
LOGD() << "FOREGROUND_COLOR changed: " << val.toString();
m_foregroundColorChanged.send(foregroundColor());
});
settings()->addItem(FOREGROUND_USE_USER_COLOR, Val(true));
settings()->valueChanged(FOREGROUND_USE_USER_COLOR).onReceive(nullptr, [this](const Val& val) {
LOGD() << "FOREGROUND_USE_USER_COLOR changed: " << val.toString();
m_foregroundColorChanged.send(foregroundColor());
});
settings()->addItem(SELECTION_PROXIMITY, Val(6));
}
@ -46,11 +63,29 @@ QColor SceneNotationConfiguration::backgroundColor() const
return settings()->value(BACKGROUND_COLOR).toQColor();
}
Channel<QColor> SceneNotationConfiguration::backgroundColorChanged()
Channel<QColor> SceneNotationConfiguration::backgroundColorChanged() const
{
return m_backgroundColorChanged;
}
QColor SceneNotationConfiguration::defaultForegroundColor() const
{
return settings()->defaultValue(FOREGROUND_COLOR).toQColor();
}
QColor SceneNotationConfiguration::foregroundColor() const
{
if (settings()->value(FOREGROUND_USE_USER_COLOR).toBool()) {
return settings()->value(FOREGROUND_COLOR).toQColor();
}
return defaultForegroundColor();
}
Channel<QColor> SceneNotationConfiguration::foregroundColorChanged() const
{
return m_foregroundColorChanged;
}
int SceneNotationConfiguration::selectionProximity() const
{
return settings()->value(SELECTION_PROXIMITY).toInt();

View file

@ -31,12 +31,17 @@ public:
void init();
QColor backgroundColor() const override;
async::Channel<QColor> backgroundColorChanged() override;
async::Channel<QColor> backgroundColorChanged() const override;
QColor foregroundColor() const override;
QColor defaultForegroundColor() const override;
async::Channel<QColor> foregroundColorChanged() const override;
int selectionProximity() const override;
private:
async::Channel<QColor> m_backgroundColorChanged;
async::Channel<QColor> m_foregroundColorChanged;
};
}
}

View file

@ -34,7 +34,11 @@ public:
virtual ~ISceneNotationConfiguration() = default;
virtual QColor backgroundColor() const = 0;
virtual async::Channel<QColor> backgroundColorChanged() = 0;
virtual async::Channel<QColor> backgroundColorChanged() const = 0;
virtual QColor defaultForegroundColor() const = 0;
virtual QColor foregroundColor() const = 0;
virtual async::Channel<QColor> foregroundColorChanged() const = 0;
virtual int selectionProximity() const = 0;
};

View file

@ -13,7 +13,6 @@
#include "palette/palette.h"
#include "libmscore/element.h"
#include "libmscore/style.h"
#include "mscore/globals.h"
#include "libmscore/sym.h"
#include "libmscore/symbol.h"
#include "libmscore/score.h"
@ -29,7 +28,6 @@
#include "libmscore/page.h"
#include "libmscore/keysig.h"
#include "libmscore/timesig.h"
#include "mscore/preferences.h"
#include "libmscore/part.h"
#include "libmscore/textline.h"
#include "libmscore/measure.h"
@ -40,7 +38,6 @@
#include "thirdparty/qzip/qzipwriter_p.h"
#include "libmscore/slur.h"
#include "mscore/tourhandler.h"
#include "mscore/script/recorderwidget.h"
#include "libmscore/fret.h"
#include "mscore/scoreaccessibility.h"
@ -827,10 +824,7 @@ void Palette::paintEvent(QPaintEvent* /*event*/)
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing, true);
QColor bgColor(0xf6, 0xf0, 0xda);
if (preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR)) {
bgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR);
}
QColor bgColor = configuration()->foregroundColor();
#if 1
p.setBrush(bgColor);
p.drawRoundedRect(0, 0, width(), height(), 2, 2);

View file

@ -12,7 +12,6 @@
#include "palettelistview.h"
#include "palettemodel.h"
#include "mscore/preferences.h"
namespace Ms {
//---------------------------------------------------------
@ -117,13 +116,7 @@ void PaletteListView::keyPressEvent(QKeyEvent* event)
void PaletteListView::setupStyle()
{
QPalette pal = palette(); // color palette
QColor c;
if (preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR)
&& preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR_IN_PALETTES)) {
c = preferences.getColor(PREF_UI_CANVAS_FG_COLOR);
} else {
c = preferences.defaultValue(PREF_UI_CANVAS_FG_COLOR).value<QColor>();
}
QColor c = configuration()->foregroundColor();
pal.setColor(QPalette::Base, c);
setPalette(pal);
}

View file

@ -12,6 +12,9 @@
#ifndef __PALETTELISTVIEW_H__
#define __PALETTELISTVIEW_H__
#include "modularity/ioc.h"
#include "mu4/scenes/palette/ipaletteconfiguration.h"
namespace Ms {
class Element;
class PalettePanel;
@ -28,6 +31,8 @@ class PaletteListView : public QListView // see also QListWidget
{
Q_OBJECT
INJECT(palette, mu::scene::palette::IPaletteConfiguration, configuration)
public:
PaletteListView(PalettePanel* panel, QWidget* parent = nullptr);
const PaletteCell* currentCell() const;

View file

@ -25,7 +25,6 @@
#include "libmscore/select.h"
#include "palettetree.h"
#include "palette/palette.h"
#include "mscore/preferences.h"
#include "mscore/scoreaccessibility.h"

View file

@ -19,9 +19,6 @@
#include "palettetree.h"
#include "mscore/globals.h"
#include "mscore/preferences.h"
#include "libmscore/articulation.h"
#include "libmscore/fret.h"
#include "libmscore/icon.h"

View file

@ -32,8 +32,6 @@
#include "palettecelldialog.h"
#include "timedialog.h"
#include "mscore/preferences.h"
#include "io/path.h"
#include "mu4/scenes/common/commonscenetypes.h"
@ -982,57 +980,13 @@ QString PaletteWorkspace::getPaletteFilename(bool open, const QString& name)
defaultPath = myName.absoluteFilePath();
}
if (preferences.getBool(PREF_UI_APP_USENATIVEDIALOGS)) {
QString fn;
if (open) {
fn = QFileDialog::getOpenFileName(mainWindow()->qMainWindow(), title, defaultPath, filter);
} else {
fn = QFileDialog::getSaveFileName(mainWindow()->qMainWindow(), title, defaultPath, filter);
}
return fn;
}
QFileDialog* dialog;
QList<QUrl> urls;
urls.append(QUrl::fromLocalFile(QDir::homePath()));
urls.append(QUrl::fromLocalFile(QDir::currentPath()));
urls.append(QUrl::fromLocalFile(defaultPath));
mu::io::path fn;
if (open) {
QFileDialog* loadPaletteDialog = new QFileDialog(mainWindow()->qMainWindow());
loadPaletteDialog->setFileMode(QFileDialog::ExistingFile);
loadPaletteDialog->setOption(QFileDialog::DontUseNativeDialog, true);
loadPaletteDialog->setDirectory(defaultPath);
//restoreDialogState("loadPaletteDialog", loadPaletteDialog);
loadPaletteDialog->setAcceptMode(QFileDialog::AcceptOpen);
dialog = loadPaletteDialog;
fn = interactive()->selectOpeningFile(title, defaultPath, filter);
} else {
QFileDialog* savePaletteDialog = new QFileDialog(mainWindow()->qMainWindow());
savePaletteDialog->setAcceptMode(QFileDialog::AcceptSave);
savePaletteDialog->setFileMode(QFileDialog::AnyFile);
savePaletteDialog->setOption(QFileDialog::DontConfirmOverwrite, false);
savePaletteDialog->setOption(QFileDialog::DontUseNativeDialog, true);
savePaletteDialog->setDirectory(defaultPath);
//restoreDialogState("savePaletteDialog", savePaletteDialog);
savePaletteDialog->setAcceptMode(QFileDialog::AcceptSave);
dialog = savePaletteDialog;
fn = interactive()->selectSavingFile(title, defaultPath, filter);
}
dialog->setWindowTitle(title);
dialog->setNameFilter(filter);
// setup side bar urls
dialog->setSidebarUrls(urls);
if (dialog->exec()) {
QStringList result = dialog->selectedFiles();
return result.front();
}
delete dialog;
return QString();
return mu::io::pathToQString(fn);
}
//---------------------------------------------------------

View file

@ -24,6 +24,7 @@
#include "palettemodel.h"
#include "modularity/ioc.h"
#include "framework/ui/imainwindow.h"
#include "framework/global/iinteractive.h"
namespace Ms {
class AbstractPaletteController;
@ -194,6 +195,7 @@ class PaletteWorkspace : public QObject
Q_OBJECT
INJECT(palette, mu::framework::IMainWindow, mainWindow)
INJECT(palette, mu::framework::IInteractive, interactive)
PaletteTreeModel* userPalette;
PaletteTreeModel* masterPalette;

View file

@ -18,18 +18,19 @@
//=============================================================================
#include "paletteconfiguration.h"
#include "mscore/globals.h"
#include "log.h"
#include "settings.h"
using namespace mu::scene::palette;
using namespace mu::framework;
static const Settings::Key PALETTE_SCALE("palette", "application/paletteScale");
static const Settings::Key PALETTE_USESINGLE("palette", "application/useSinglePalette");
static const Settings::Key PALETTE_USE_SINGLE("palette", "application/useSinglePalette");
static const Settings::Key PALETTE_USE_USER_FG_COLOR("palette", "ui/canvas/foreground/useColorInPalettes");
void PaletteConfiguration::init()
{
settings()->addItem(PALETTE_USE_USER_FG_COLOR, Val(true));
}
double PaletteConfiguration::guiScale() const
@ -40,10 +41,12 @@ double PaletteConfiguration::guiScale() const
pref = val.toDouble();
}
if (Ms::guiScaling <= 1.0) { // low DPI: target is 100% life size
return pref * Ms::guiScaling;
} else if (Ms::guiScaling > 1.33) { // high DPI: target is 75% life size
return pref * Ms::guiScaling* 0.75;
float guiScaling = uiConfiguration()->guiScaling();
if (guiScaling <= 1.0) { // low DPI: target is 100% life size
return pref * guiScaling;
} else if (guiScaling > 1.33) { // high DPI: target is 75% life size
return pref * guiScaling * 0.75;
} else { // medium high DPI: no target, scaling dependent on resolution
return pref; // (will be 75-100% range)
}
@ -51,5 +54,13 @@ double PaletteConfiguration::guiScale() const
bool PaletteConfiguration::isSinglePalette() const
{
return settings()->value(PALETTE_USESINGLE).toBool();
return settings()->value(PALETTE_USE_SINGLE).toBool();
}
QColor PaletteConfiguration::foregroundColor() const
{
if (settings()->value(PALETTE_USE_USER_FG_COLOR).toBool()) {
return notationConfiguration()->foregroundColor();
}
return notationConfiguration()->defaultForegroundColor();
}

View file

@ -21,11 +21,18 @@
#include "../ipaletteconfiguration.h"
#include "modularity/ioc.h"
#include "ui/iuiconfiguration.h"
#include "scenes/notation/iscenenotationconfiguration.h"
namespace mu {
namespace scene {
namespace palette {
class PaletteConfiguration : public IPaletteConfiguration
{
INJECT(palette, framework::IUiConfiguration, uiConfiguration)
INJECT(palette, notation::ISceneNotationConfiguration, notationConfiguration)
public:
PaletteConfiguration() = default;
@ -33,6 +40,8 @@ public:
double guiScale() const override;
bool isSinglePalette() const override;
QColor foregroundColor() const override;
};
}
}

View file

@ -28,8 +28,6 @@
#include "libmscore/mscore.h"
#include "libmscore/xml.h"
#include "mscore/globals.h"
#include "mu4/scenes/common/commonscenetypes.h"
namespace Ms {

View file

@ -19,8 +19,12 @@
#ifndef MU_PALETTE_IPALETTECONFIGURATION_H
#define MU_PALETTE_IPALETTECONFIGURATION_H
#include <QColor>
#include "modularity/imoduleexport.h"
#include "retval.h"
namespace mu {
namespace scene {
namespace palette {
@ -32,6 +36,8 @@ public:
virtual double guiScale() const = 0;
virtual bool isSinglePalette() const = 0;
virtual QColor foregroundColor() const = 0;
};
}
}

View file

@ -83,7 +83,7 @@ void OpenScoreController::newScore()
io::path OpenScoreController::selectScoreFile(const QStringList &filter)
{
std::string filterStr = filter.join(";;").toStdString();
QString filterStr = filter.join(";;");
return interactive()->selectOpeningFile("Score", "", filterStr);
}