Save and load the layout of the Functions widget (#2844)

This commit is contained in:
Theofilos Pechlivanis 2022-02-05 09:00:08 +02:00 committed by GitHub
parent 2b50e2722b
commit 2dbf136de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 18 deletions

View File

@ -21,17 +21,16 @@
* and for light - only light ones.
*/
const QHash<QString, ColorFlags> Configuration::relevantThemes = {
{ "ayu", DarkFlag }, { "basic", DarkFlag }, { "behelit", DarkFlag },
{ "bold", DarkFlag }, { "bright", DarkFlag }, { "consonance", DarkFlag },
{ "darkda", DarkFlag }, { "defragger", DarkFlag }, { "focus", DarkFlag },
{ "gentoo", DarkFlag }, { "lima", DarkFlag }, { "monokai", DarkFlag },
{ "ogray", DarkFlag }, { "onedark", DarkFlag }, { "pink", DarkFlag },
{ "rasta", DarkFlag }, { "sepia", DarkFlag }, { "smyck", DarkFlag },
{ "solarized", DarkFlag }, { "twilight", DarkFlag }, { "white2", DarkFlag },
{ "xvilka", DarkFlag }, { "zenburn", DarkFlag },
{ "cga", LightFlag }, { "cutter", LightFlag }, { "dark", LightFlag },
{ "gb", LightFlag }, { "matrix", LightFlag }, { "tango", LightFlag },
{ "white", LightFlag }
{ "ayu", DarkFlag }, { "basic", DarkFlag }, { "behelit", DarkFlag },
{ "bold", DarkFlag }, { "bright", DarkFlag }, { "consonance", DarkFlag },
{ "darkda", DarkFlag }, { "defragger", DarkFlag }, { "focus", DarkFlag },
{ "gentoo", DarkFlag }, { "lima", DarkFlag }, { "monokai", DarkFlag },
{ "ogray", DarkFlag }, { "onedark", DarkFlag }, { "pink", DarkFlag },
{ "rasta", DarkFlag }, { "sepia", DarkFlag }, { "smyck", DarkFlag },
{ "solarized", DarkFlag }, { "twilight", DarkFlag }, { "white2", DarkFlag },
{ "xvilka", DarkFlag }, { "zenburn", DarkFlag }, { "cga", LightFlag },
{ "cutter", LightFlag }, { "dark", LightFlag }, { "gb", LightFlag },
{ "matrix", LightFlag }, { "tango", LightFlag }, { "white", LightFlag }
};
static const QString DEFAULT_LIGHT_COLOR_THEME = "cutter";
static const QString DEFAULT_DARK_COLOR_THEME = "ayu";
@ -251,8 +250,8 @@ bool Configuration::setLocaleByName(const QString &language)
QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
for (auto &it : allLocales) {
if (QString::compare(it.nativeLanguageName(), language, Qt::CaseInsensitive) == 0 ||
it.name() == language) {
if (QString::compare(it.nativeLanguageName(), language, Qt::CaseInsensitive) == 0
|| it.name() == language) {
setLocale(it);
return true;
}
@ -289,7 +288,8 @@ void Configuration::loadNativeStylesheet()
QTextStream ts(&f);
QString stylesheet = ts.readAll();
#ifdef Q_OS_MACOS
QFile mf(nativeWindowIsDark() ? ":native/native-macos-dark.qss" : ":native/native-macos-light.qss");
QFile mf(nativeWindowIsDark() ? ":native/native-macos-dark.qss"
: ":native/native-macos-light.qss");
if (mf.exists()) {
mf.open(QFile::ReadOnly | QFile::Text);
QTextStream mts(&mf);
@ -667,11 +667,13 @@ QStringList Configuration::getAvailableTranslations()
for (auto i : fileNames) {
QString localeName = i.mid(sizeof("cutter_") - 1, 2); // TODO:#2321 don't asume 2 characters
// language code is sometimes 3 characters, and there could also be language_COUNTRY. Qt supports that.
// language code is sometimes 3 characters, and there could also be language_COUNTRY. Qt
// supports that.
QLocale locale(localeName);
if (locale.language() != QLocale::C) {
currLanguageName = locale.nativeLanguageName();
if (currLanguageName.isEmpty()) { // Qt doesn't have native language name for some languages
if (currLanguageName
.isEmpty()) { // Qt doesn't have native language name for some languages
currLanguageName = QLocale::languageToString(locale.language());
}
if (!currLanguageName.isEmpty()) {
@ -774,7 +776,7 @@ bool Configuration::getOutputRedirectionEnabled() const
return outputRedirectEnabled;
}
void Configuration::setPreviewValue( bool checked )
void Configuration::setPreviewValue(bool checked)
{
s.setValue("asm.preview", checked);
}
@ -821,3 +823,13 @@ void Configuration::addRecentProject(QString file)
files.prepend(file);
setRecentProjects(files);
}
QString Configuration::getFunctionsWidgetLayout()
{
return s.value("functionsWidgetLayout").toString();
}
void Configuration::setFunctionsWidgetLayout(const QString &layout)
{
s.setValue("functionsWidgetLayout", layout);
}

View File

@ -228,6 +228,19 @@ public:
void setRecentProjects(const QStringList &list);
void addRecentProject(QString file);
// Functions Widget Layout
/**
* @brief Get the layout of the Functions widget.
* @return The layout.
*/
QString getFunctionsWidgetLayout();
/**
* @brief Set the layout of the Functions widget
* @param layout The layout of the Functions widget, either horizontal or vertical.
*/
void setFunctionsWidgetLayout(const QString &layout);
public slots:
void refreshFont();
signals:

View File

@ -526,7 +526,11 @@ FunctionsWidget::FunctionsWidget(MainWindow *main)
addActions(itemConextMenu->actions());
// Use a custom context menu on the dock title bar
actionHorizontal.setChecked(true);
if (Config()->getFunctionsWidgetLayout() == "horizontal") {
actionHorizontal.setChecked(true);
} else {
actionVertical.setChecked(true);
}
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested, this,
&FunctionsWidget::showTitleContextMenu);
@ -617,6 +621,7 @@ void FunctionsWidget::showTitleContextMenu(const QPoint &pt)
void FunctionsWidget::onActionHorizontalToggled(bool enable)
{
if (enable) {
Config()->setFunctionsWidgetLayout("horizontal");
functionModel->setNested(false);
ui->treeView->setIndentation(8);
}
@ -625,6 +630,7 @@ void FunctionsWidget::onActionHorizontalToggled(bool enable)
void FunctionsWidget::onActionVerticalToggled(bool enable)
{
if (enable) {
Config()->setFunctionsWidgetLayout("vertical");
functionModel->setNested(true);
ui->treeView->setIndentation(20);
}