ui: Change screen scaling on Linux (issue #518, #523)

* Set environment variables QT_AUTO_SCREEN_SCALE_FACTOR and QT_SCALE_FACTOR on Linux on app start
* Added ScreenAutoScaling and ScreenScaleFactor to ApplicationSettings with dropdown boxes in the preferences
  only visible on Linux
* Removed QtFontPicker and QtTextEncodingPicker
* Moved logging into preferences category "output"

fortune cookie message = You will have a peace of mind when you talk to an old friend
This commit is contained in:
Eberhard Graether
2018-01-16 11:01:32 +01:00
parent 6672127c68
commit 43c223368c
15 changed files with 375 additions and 248 deletions
@@ -29,10 +29,16 @@
<scroll_speed><!-- DECIMAL: multiplier for default scroll speed in views --></scroll_speed>
<logging_enabled><!-- BOOL: define if console and file logging is enabled --></logging_enabled>
<verbose_indexer_logging_enabled><!-- BOOL: define if verbose indexer logging is enabled --></verbose_indexer_logging_enabled>
<graph_controls_visible><!-- BOOL: define if the graph controls are visible or collapsed --></graph_controls_visible>
</application>
<screen>
<auto_scaling><!-- INTEGER: 0 or 1 if auto scaling is enabled, -1 for system setting --></auto_scaling>
<scale_factor><!-- DECIMAL: defines highDPI scale factor, < 0 uses system setting --></scale_factor>
</screen>
<indexing>
<indexer_thread_count><!-- INTEGER: number of threads indexing the source code --></indexer_thread_count>
<multi_process_indexing><!-- BOOL: use different processes instead of threads during indexing --></multi_process_indexing>
+6 -4
View File
@@ -187,15 +187,17 @@ QCoreApplication* createApplication(int &argc, char *argv[], bool noGUI = false)
int main(int argc, char *argv[])
{
#ifdef __linux__
if (std::getenv("SOURCETRAIL_VIA_SCRIPT") == nullptr)
if (utility::getOsType() == OS_LINUX && std::getenv("SOURCETRAIL_VIA_SCRIPT") == nullptr)
{
std::cout << "ERROR: Please run Sourcetrail via the Sourcetrail.sh script!" << std::endl;
}
#endif
QApplication::setApplicationName("Sourcetrail");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
if (utility::getOsType() != OS_LINUX)
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
}
Version version(
VERSION_YEAR,
+20 -10
View File
@@ -225,6 +225,26 @@ void ApplicationSettings::setGraphControlsVisible(bool visible)
setValue<bool>("application/graph_controls_visible", visible);
}
int ApplicationSettings::getScreenAutoScaling() const
{
return getValue<int>("screen/auto_scaling", 1);
}
void ApplicationSettings::setScreenAutoScaling(int autoScaling)
{
setValue<int>("screen/auto_scaling", autoScaling);
}
float ApplicationSettings::getScreenScaleFactor() const
{
return getValue<float>("screen/scale_factor", -1.0);
}
void ApplicationSettings::setScreenScaleFactor(float scaleFactor)
{
setValue<float>("screen/scale_factor", scaleFactor);
}
bool ApplicationSettings::getLoggingEnabled() const
{
return getValue<bool>("application/logging_enabled", false);
@@ -265,16 +285,6 @@ int ApplicationSettings::getLogFilter() const
return getValue<int>("application/log_filter", Logger::LOG_WARNINGS | Logger::LOG_ERRORS);
}
std::vector<FilePath> ApplicationSettings::getIndexingFilePaths() const
{
return getPathValues("application/state/indexing_paths/indexing_path");
}
bool ApplicationSettings::setIndexingFilePaths(const std::vector<FilePath>& indexingFiles)
{
return setPathValues("application/state/indexing_paths/indexing_path", indexingFiles);
}
int ApplicationSettings::getIndexerThreadCount() const
{
return getValue<int>("indexing/indexer_thread_count", 0);
+7 -3
View File
@@ -62,6 +62,13 @@ public:
bool getGraphControlsVisible() const;
void setGraphControlsVisible(bool visible);
// screen
int getScreenAutoScaling() const;
void setScreenAutoScaling(int autoScaling);
float getScreenScaleFactor() const;
void setScreenScaleFactor(float scaleFactor);
// logging
bool getLoggingEnabled() const;
void setLoggingEnabled(bool loggingEnabled);
@@ -75,9 +82,6 @@ public:
int getStatusFilter() const;
void setStatusFilter(int mask);
std::vector<FilePath> getIndexingFilePaths() const;
bool setIndexingFilePaths(const std::vector<FilePath>& indexingFiles);
// indexing
int getIndexerThreadCount() const;
void setIndexerThreadCount(const int count);
+16 -12
View File
@@ -66,7 +66,9 @@ bool ConfigManager::getValue(const std::string& key, float& value) const
std::string valueString;
if (getValue(key, valueString))
{
value = static_cast<float>(atof(valueString.c_str()));
std::stringstream ss;
ss << valueString;
ss >> value;
return true;
}
return false;
@@ -91,8 +93,8 @@ bool ConfigManager::getValues(const std::string& key, std::vector<std::string>&
if (ret.first != ret.second)
{
std::multimap<std::string, std::string>::const_iterator cit = ret.first;
for(;cit!=ret.second;++cit)
for (std::multimap<std::string, std::string>::const_iterator cit = ret.first;
cit != ret.second; ++cit)
{
values.push_back(cit->second);
}
@@ -171,7 +173,9 @@ void ConfigManager::setValue(const std::string& key, const int value)
void ConfigManager::setValue(const std::string& key, const float value)
{
setValue(key, std::to_string(value));
std::stringstream ss;
ss << value;
setValue(key, ss.str());
}
void ConfigManager::setValue(const std::string& key, const bool value)
@@ -183,11 +187,11 @@ void ConfigManager::setValues(const std::string& key, const std::vector<std::str
{
std::multimap<std::string, std::string>::iterator it = m_values.find(key);
if(it != m_values.end())
if (it != m_values.end())
{
m_values.erase(key);
}
for(std::string s : values)
for (std::string s : values)
{
m_values.emplace(key, s);
}
@@ -196,7 +200,7 @@ void ConfigManager::setValues(const std::string& key, const std::vector<std::str
void ConfigManager::setValues(const std::string& key, const std::vector<int>& values)
{
std::vector<std::string> stringValues;
for(int i : values)
for (int i : values)
{
stringValues.push_back(std::to_string(i));
}
@@ -206,7 +210,7 @@ void ConfigManager::setValues(const std::string& key, const std::vector<int>& va
void ConfigManager::setValues(const std::string& key, const std::vector<float>& values)
{
std::vector<std::string> stringValues;
for(float f : values)
for (float f : values)
{
stringValues.push_back(std::to_string(f));
}
@@ -216,7 +220,7 @@ void ConfigManager::setValues(const std::string& key, const std::vector<float>&
void ConfigManager::setValues(const std::string& key, const std::vector<bool>& values)
{
std::vector<std::string> stringValues;
for(bool b : values)
for (bool b : values)
{
stringValues.push_back(std::string(b ? "1" : "0"));
}
@@ -267,7 +271,7 @@ bool ConfigManager::load(const std::shared_ptr<TextAccess> textAccess)
{
TiXmlHandle docHandle(&doc);
TiXmlNode *rootNode = docHandle.FirstChild("config").ToNode();
if(rootNode == nullptr)
if (rootNode == nullptr)
{
LOG_ERROR("No rootelement 'config' in the configfile");
return false;
@@ -316,7 +320,7 @@ bool ConfigManager::createXmlDocument(bool saveAsFile, const std::string filepat
TiXmlElement *root = new TiXmlElement("config");
doc.LinkEndChild(root);
for(std::multimap<std::string,std::string>::iterator it = m_values.begin(); it != m_values.end(); ++it)
for (std::multimap<std::string,std::string>::iterator it = m_values.begin(); it != m_values.end(); ++it)
{
if (!it->first.size() || !it->second.size())
{
@@ -345,7 +349,7 @@ bool ConfigManager::createXmlDocument(bool saveAsFile, const std::string filepat
child->LinkEndChild(text);
}
if(saveAsFile)
if (saveAsFile)
{
success = doc.SaveFile(filepath.c_str());
}
-4
View File
@@ -34,8 +34,6 @@ add_files(
qt/element/QtCodeSnippet.h
qt/element/QtDirectoryListBox.cpp
qt/element/QtDirectoryListBox.h
qt/element/QtFontPicker.cpp
qt/element/QtFontPicker.h
qt/element/QtHelpButton.cpp
qt/element/QtHelpButton.h
qt/element/QtHistoryList.cpp
@@ -60,8 +58,6 @@ add_files(
qt/element/QtStatusBar.h
qt/element/QtTable.cpp
qt/element/QtTable.h
qt/element/QtTextEncodingPicker.cpp
qt/element/QtTextEncodingPicker.h
qt/element/QtTooltip.cpp
qt/element/QtTooltip.h
qt/element/QtUndoRedo.cpp
+27 -2
View File
@@ -11,8 +11,35 @@
#include "utility/ResourcePaths.h"
#include "utility/UserPaths.h"
#include "settings/ApplicationSettings.h"
void setupPlatform(int argc, char *argv[])
{
std::string home = std::getenv("HOME");
UserPaths::setUserDataPath(FilePath(home + "/.config/sourcetrail/"));
// Set QT screen scaling factor
ApplicationSettings appSettings;
appSettings.load(UserPaths::getAppSettingsPath());
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR_SOURCETRAIL", qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR"));
qputenv("QT_SCALE_FACTOR_SOURCETRAIL", qgetenv("QT_SCALE_FACTOR"));
int autoScaling = appSettings.getScreenAutoScaling();
if (autoScaling != -1)
{
QByteArray bytes;
bytes.setNum(autoScaling);
qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", bytes);
}
float scaleFactor = appSettings.getScreenScaleFactor();
if (scaleFactor > 0.0)
{
QByteArray bytes;
bytes.setNum(scaleFactor);
qputenv("QT_SCALE_FACTOR", bytes);
}
}
void setupApp(int argc, char *argv[])
@@ -26,8 +53,6 @@ void setupApp(int argc, char *argv[])
QDir coatiDir((userdir + "/.config/coati").c_str());
userdir.append("/.config/sourcetrail/");
UserPaths::setUserDataPath(FilePath(userdir));
QString userDataPath(userdir.c_str());
QDir dataDir(userdir.c_str());
if (!dataDir.exists())
+2 -8
View File
@@ -12,10 +12,11 @@
#include "utility/ResourcePaths.h"
#include "utility/UserPaths.h"
bool appIsMacBundle = false;
void setupPlatform(int argc, char *argv[])
{
UserPaths::setUserDataPath(FilePath("./user/"));
// ----------------------------------------------------------------------------
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
// source: http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
@@ -81,19 +82,12 @@ void setupPlatform(int argc, char *argv[])
// ----------------------------------------------------------------------------
UserPaths::setUserDataPath(FilePath(dataPath.toStdString() + "/"));
appIsMacBundle = true;
}
void setupApp(int argc, char *argv[])
{
FilePath path(QDir::currentPath().toStdString());
AppPath::setAppPath(path.getAbsolute().str() + "/");
if (!appIsMacBundle)
{
UserPaths::setUserDataPath(FilePath("./user/"));
}
}
#endif // INCLUDES_MAC_H
-34
View File
@@ -1,34 +0,0 @@
#include "qt/element/QtFontPicker.h"
#include <QHBoxLayout>
#include <QFontComboBox>
QtFontPicker::QtFontPicker(QWidget *parent)
: QWidget(parent)
{
setObjectName("picker");
QBoxLayout* layout = new QHBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(1, 1, 1, 1);
layout->setAlignment(Qt::AlignTop);
m_box = new QFontComboBox();
m_box->setFontFilters(QFontComboBox::MonospacedFonts);
m_box->setEditable(false);
layout->addWidget(m_box);
setLayout(layout);
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
}
QString QtFontPicker::getText()
{
return m_box->currentText();
}
void QtFontPicker::setText(QString text)
{
m_box->setCurrentText(text);
}
-23
View File
@@ -1,23 +0,0 @@
#ifndef QT_FONT_PICKER_H
#define QT_FONT_PICKER_H
#include <QWidget>
class QFontComboBox;
class QtFontPicker
: public QWidget
{
Q_OBJECT
public:
QtFontPicker(QWidget *parent);
QString getText();
void setText(QString text);
private:
QFontComboBox* m_box;
};
#endif // QT_FONT_PICKER_H
@@ -1,39 +0,0 @@
#include "qt/element/QtTextEncodingPicker.h"
#include <QHBoxLayout>
#include <QTextCodec>
#include <QFontComboBox>
QtTextEncodingPicker::QtTextEncodingPicker(QWidget *parent)
: QWidget(parent)
{
setObjectName("picker");
QBoxLayout* layout = new QHBoxLayout();
layout->setSpacing(0);
layout->setContentsMargins(1, 1, 1, 1);
layout->setAlignment(Qt::AlignTop);
m_box = new QComboBox();
for (int mib : QTextCodec::availableMibs())
{
m_box->addItem(QTextCodec::codecForMib(mib)->name());
}
m_box->setEditable(false);
layout->addWidget(m_box);
setLayout(layout);
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
}
QString QtTextEncodingPicker::getText()
{
return m_box->currentText();
}
void QtTextEncodingPicker::setText(QString text)
{
m_box->setCurrentText(text);
}
@@ -1,23 +0,0 @@
#ifndef QT_TEXT_ENCODING_PICKER_H
#define QT_TEXT_ENCODING_PICKER_H
#include <QWidget>
class QComboBox;
class QtTextEncodingPicker
: public QWidget
{
Q_OBJECT
public:
QtTextEncodingPicker(QWidget *parent);
QString getText();
void setText(QString text);
private:
QComboBox* m_box;
};
#endif // QT_TEXT_ENCODING_PICKER_H
+26 -7
View File
@@ -6,6 +6,7 @@
#include "utility/messaging/type/MessageScrollSpeedChange.h"
#include "Application.h"
#include "component/view/DialogView.h"
#include "qt/window/project_wizzard/QtProjectWizzardContentPaths.h"
#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h"
#include "qt/window/project_wizzard/QtProjectWizzardContentGroup.h"
@@ -22,6 +23,9 @@ QtPreferencesWindow::QtPreferencesWindow(QWidget* parent)
m_appSettings.setSourcetrailPort(appSettings->getSourcetrailPort());
m_appSettings.setPluginPort(appSettings->getPluginPort());
m_appSettings.setScreenAutoScaling(appSettings->getScreenAutoScaling());
m_appSettings.setScreenScaleFactor(appSettings->getScreenScaleFactor());
QtProjectWizzardContentGroup* summary = new QtProjectWizzardContentGroup(this);
summary->setIsForm(true);
@@ -62,24 +66,39 @@ void QtPreferencesWindow::handleNext()
saveContent();
bool appSettingsChanged = !(m_appSettings == *ApplicationSettings::getInstance().get());
Application* app = Application::getInstance().get();
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
if (m_appSettings.getScrollSpeed() != ApplicationSettings::getInstance()->getScrollSpeed())
bool needsRestart =
m_appSettings.getScreenAutoScaling() != appSettings->getScreenAutoScaling() ||
m_appSettings.getScreenScaleFactor() != appSettings->getScreenScaleFactor();
if (needsRestart)
{
MessageScrollSpeedChange(ApplicationSettings::getInstance()->getScrollSpeed()).dispatch();
app->getDialogView()->confirm(
"Please restart the application for all changes to take effect."
);
}
if (m_appSettings.getSourcetrailPort() != ApplicationSettings::getInstance()->getSourcetrailPort() ||
m_appSettings.getPluginPort() != ApplicationSettings::getInstance()->getPluginPort())
bool appSettingsChanged = !(m_appSettings == *appSettings);
if (m_appSettings.getScrollSpeed() != appSettings->getScrollSpeed())
{
MessageScrollSpeedChange(appSettings->getScrollSpeed()).dispatch();
}
if (m_appSettings.getSourcetrailPort() != appSettings->getSourcetrailPort() ||
m_appSettings.getPluginPort() != appSettings->getPluginPort())
{
MessagePluginPortChange().dispatch();
}
Application::getInstance()->loadSettings();
app->loadSettings();
if (appSettingsChanged)
{
Project* currentProject = Application::getInstance()->getCurrentProject().get();
Project* currentProject = app->getCurrentProject().get();
if (currentProject)
{
MessageLoadProject(currentProject->getProjectSettingsFilePath(), true).dispatch();
@@ -1,7 +1,12 @@
#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h"
#include "qt/element/QtFontPicker.h"
#include "qt/element/QtTextEncodingPicker.h"
#include <QCheckBox>
#include <QComboBox>
#include <QFontComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QTextCodec>
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FileSystem.h"
@@ -17,8 +22,11 @@ QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences(
: QtProjectWizzardContent(window)
, m_oldColorSchemeIndex(-1)
, m_newColorSchemeIndex(-1)
, m_screenAutoScaling(nullptr)
, m_screenScaleFactor(nullptr)
{
m_colorSchemePaths = FileSystem::getFilePathsFromDirectory(ResourcePaths::getColorSchemesPath(), std::vector<std::string>(1, ".xml"));
m_colorSchemePaths =
FileSystem::getFilePathsFromDirectory(ResourcePaths::getColorSchemesPath(), std::vector<std::string>(1, ".xml"));
}
QtProjectWizzardContentPreferences::~QtProjectWizzardContentPreferences()
@@ -37,10 +45,9 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
addTitle("USER INTERFACE", layout, row);
// font face
m_fontFace = new QtFontPicker(this);
m_fontFace->setObjectName("name");
m_fontFace->setAttribute(Qt::WA_MacShowFocusRect, 0);
m_fontFace = new QFontComboBox(this);
m_fontFace->setFontFilters(QFontComboBox::MonospacedFonts);
m_fontFace->setEditable(false);
addLabelAndWidget("Font Face", m_fontFace, layout, row);
row++;
@@ -51,12 +58,11 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
m_tabWidth = addComboBox("Tab Width", 1, 16, "", layout, row);
// text encoding
m_textEncoding = new QtTextEncodingPicker(this);
m_textEncoding->setObjectName("text encoding");
m_textEncoding->setAttribute(Qt::WA_MacShowFocusRect, 0);
addLabelAndWidget("Text Encoding", m_textEncoding, layout, row);
row++;
m_textEncoding = addComboBox("Text Encoding", "", layout, row);
for (int mib : QTextCodec::availableMibs())
{
m_textEncoding->addItem(QTextCodec::codecForMib(mib)->name());
}
// color scheme
m_colorSchemes = addComboBox("Color Scheme", "", layout, row);
@@ -64,7 +70,8 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
{
m_colorSchemes->insertItem(i, m_colorSchemePaths[i].withoutExtension().fileName().c_str());
}
connect(m_colorSchemes, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &QtProjectWizzardContentPreferences::colorSchemeChanged);
connect(m_colorSchemes, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, &QtProjectWizzardContentPreferences::colorSchemeChanged);
// animations
m_useAnimations = addCheckBox("Animations", "Enable animations",
@@ -74,22 +81,69 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
m_showBuiltinTypes = addCheckBox("Built-in Types", "Show built-in types in graph when referenced",
"<p>Enable display of referenced built-in types in the graph view.</p>", layout, row);
// logging
m_loggingEnabled = addCheckBox("Logging", "Enable console and file logging",
"<p>Show logs in the console and save this information in files.</p>", layout, row);
connect(m_loggingEnabled, &QCheckBox::clicked, this, &QtProjectWizzardContentPreferences::loggingEnabledChanged);
m_verboseIndexerLoggingEnabled = addCheckBox(
"Indexer Logging",
"Enable verbose indexer logging",
"<p>Enable additional logs of abstract syntax tree traversal during indexing. This information can help "
"tracking down crashes that occurr during indexing.</p>"
"<p><b>Warning</b>: This slows down indexing performance a lot.</p>",
layout, row
);
addGap(layout, row);
// Linux UI scale
if (utility::getOsType() == OS_LINUX)
{
// screen
addTitle("SCREEN", layout, row);
QLabel* hint = new QLabel("<changes need restart>");
hint->setStyleSheet("color: grey");
layout->addWidget(hint, row-1, QtProjectWizzardWindow::BACK_COL, Qt::AlignRight);
// auto scaling
m_screenAutoScalingInfoLabel = new QLabel("");
m_screenAutoScaling = addComboBoxWithWidgets(
"Auto Scaling to DPI",
"<p>Define if automatic scaling to screen DPI resolution is active. "
"This setting manipulates the environment flag QT_AUTO_SCREEN_SCALE_FACTOR of the Qt framework "
"(<a href=\"http://doc.qt.io/qt-5/highdpi.html\">http://doc.qt.io/qt-5/highdpi.html</a>). "
"Choose 'system' to stick to the setting of your current environment.</p>"
"<p>Changes to this setting require a restart of the application to take effect.</p>",
{ m_screenAutoScalingInfoLabel },
layout,
row
);
m_screenAutoScaling->addItem("system", -1);
m_screenAutoScaling->addItem("off", 0);
m_screenAutoScaling->addItem("on", 1);
connect(m_screenAutoScaling, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, &QtProjectWizzardContentPreferences::uiAutoScalingChanges);
// scale factor
m_screenScaleFactorInfoLabel = new QLabel("");
m_screenScaleFactor = addComboBoxWithWidgets(
"Scale Factor",
"<p>Define a screen scale factor for the user interface of the application. "
"This setting manipulates the environment flag QT_SCALE_FACTOR of the Qt framework "
"(<a href=\"http://doc.qt.io/qt-5/highdpi.html\">http://doc.qt.io/qt-5/highdpi.html</a>). "
"Choose 'system' to stick to the setting of your current environment.</p>"
"<p>Changes to this setting require a restart of the application to take effect.</p>",
{ m_screenScaleFactorInfoLabel },
layout,
row
);
m_screenScaleFactor->addItem("system", -1.0);
m_screenScaleFactor->addItem("25%", 0.25);
m_screenScaleFactor->addItem("50%", 0.5);
m_screenScaleFactor->addItem("75%", 0.75);
m_screenScaleFactor->addItem("100%", 1.0);
m_screenScaleFactor->addItem("125%", 1.25);
m_screenScaleFactor->addItem("150%", 1.5);
m_screenScaleFactor->addItem("175%", 1.75);
m_screenScaleFactor->addItem("200%", 2.0);
m_screenScaleFactor->addItem("250%", 2.5);
m_screenScaleFactor->addItem("300%", 3.0);
m_screenScaleFactor->addItem("400%", 4.0);
connect(m_screenScaleFactor, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, &QtProjectWizzardContentPreferences::uiScaleFactorChanges);
addGap(layout, row);
}
// Controls
addTitle("CONTROLS", layout, row);
@@ -112,6 +166,25 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
addGap(layout, row);
// output
addTitle("OUTPUT", layout, row);
// logging
m_loggingEnabled = addCheckBox("Logging", "Enable console and file logging",
"<p>Show logs in the console and save this information in files.</p>", layout, row);
connect(m_loggingEnabled, &QCheckBox::clicked, this, &QtProjectWizzardContentPreferences::loggingEnabledChanged);
m_verboseIndexerLoggingEnabled = addCheckBox(
"Indexer Logging",
"Enable verbose indexer logging",
"<p>Enable additional logs of abstract syntax tree traversal during indexing. This information can help "
"tracking down crashes that occurr during indexing.</p>"
"<p><b>Warning</b>: This slows down indexing performance a lot.</p>",
layout, row
);
addGap(layout, row);
// Network
addTitle("NETWORK", layout, row);
@@ -128,7 +201,8 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
"<p>Port number that Sourcetrail uses to listen for incoming messages from plugins.</p>", layout, row);
// Sourcetrail port
m_pluginPort = addLineEdit("Plugin Port", "<p>Port number that Sourcetrail uses to sends outgoing messages to plugins.</p>", layout, row);
m_pluginPort = addLineEdit("Plugin Port",
"<p>Port number that Sourcetrail uses to sends outgoing messages to plugins.</p>", layout, row);
addGap(layout, row);
@@ -136,38 +210,24 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
addTitle("INDEXING", layout, row);
// indexer threads
const int minThreadCount = 0;
const int maxThreadCount = 24;
m_threads = new QComboBox(this);
connect(m_threads, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &QtProjectWizzardContentPreferences::indexerThreadsChanges);
for (int i = minThreadCount; i <= maxThreadCount; i++)
{
m_threads->insertItem(i, QString::number(i));
}
m_threadsInfoLabel = new QLabel("");
utility::setWidgetRetainsSpaceWhenHidden(m_threadsInfoLabel);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addWidget(m_threads);
hlayout->addWidget(m_threadsInfoLabel);
QWidget* threadsWidget = new QWidget();
threadsWidget->setLayout(hlayout);
addLabelAndWidget("Indexer Threads", threadsWidget, layout, row, Qt::AlignLeft);
addHelpButton(
m_threads = addComboBoxWithWidgets(
"Indexer Threads",
0,
24,
"<p>Set the number of threads used to work on indexing your project in parallel.</p>"
"<p>When setting this value to 0 Sourcetrail tries to use the ideal thread count for your computer.</p>",
layout, row
{ m_threadsInfoLabel },
layout,
row
);
row++;
connect(m_threads, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, &QtProjectWizzardContentPreferences::indexerThreadsChanges);
// multi process indexing
m_multiProcessIndexing = addCheckBox("Multi Process<br />C/C++ Indexing", "Run C/C++ indexer threads in different process",
m_multiProcessIndexing = addCheckBox("Multi Process<br />C/C++ Indexing",
"Run C/C++ indexer threads in different process",
"<p>Enable C/C++ indexer threads to run in different process.</p>"
"<p>This prevents the application from crashing due to unforseen exceptions while indexing.</p>",
layout, row);
@@ -201,12 +261,13 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
break;
}
const std::string javaArchitectureString = utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_32 ? "32 Bit" : "64 Bit";
const std::string javaArchitectureString =
utility::getApplicationArchitectureType() == APPLICATION_ARCHITECTURE_X86_32 ? "32 Bit" : "64 Bit";
addLabelAndWidget(
("Java Path (" + javaArchitectureString + ")").c_str(),
m_javaPath,
layout,
m_javaPath,
layout,
row
);
@@ -247,7 +308,8 @@ void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row)
addHelpButton(
"JRE System Library",
"<p>Only required for indexing Java projects.</p>"
"<p>Add the jar files of your JRE System Library. These jars can be found inside your JRE install directory.</p>", layout, row);
"<p>Add the jar files of your JRE System Library. These jars can be found inside your JRE install directory.</p>",
layout, row);
m_jreSystemLibraryPaths = new QtDirectoryListBox(this, title);
@@ -296,12 +358,12 @@ void QtProjectWizzardContentPreferences::load()
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
m_fontFace->setText(QString::fromStdString(appSettings->getFontName()));
m_fontFace->setCurrentText(QString::fromStdString(appSettings->getFontName()));
m_fontSize->setCurrentIndex(appSettings->getFontSize() - appSettings->getFontSizeMin());
m_tabWidth->setCurrentIndex(appSettings->getCodeTabWidth() - 1);
m_textEncoding->setText(QString::fromStdString(appSettings->getTextEncoding()));
m_textEncoding->setCurrentText(QString::fromStdString(appSettings->getTextEncoding()));
FilePath colorSchemePath = appSettings->getColorSchemePath();
for (size_t i = 0; i < m_colorSchemePaths.size(); i++)
@@ -318,13 +380,25 @@ void QtProjectWizzardContentPreferences::load()
m_useAnimations->setChecked(appSettings->getUseAnimations());
m_showBuiltinTypes->setChecked(appSettings->getShowBuiltinTypesInGraph());
m_loggingEnabled->setChecked(appSettings->getLoggingEnabled());
m_verboseIndexerLoggingEnabled->setChecked(appSettings->getVerboseIndexerLoggingEnabled());
m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked());
if (m_screenAutoScaling)
{
m_screenAutoScaling->setCurrentIndex(m_screenAutoScaling->findData(appSettings->getScreenAutoScaling()));
uiAutoScalingChanges(m_screenAutoScaling->currentIndex());
}
if (m_screenScaleFactor)
{
m_screenScaleFactor->setCurrentIndex(m_screenScaleFactor->findData(appSettings->getScreenScaleFactor()));
uiScaleFactorChanges(m_screenScaleFactor->currentIndex());
}
m_scrollSpeed->setText(QString::number(appSettings->getScrollSpeed(), 'f', 1));
m_graphZooming->setChecked(appSettings->getControlsGraphZoomOnMouseWheel());
m_loggingEnabled->setChecked(appSettings->getLoggingEnabled());
m_verboseIndexerLoggingEnabled->setChecked(appSettings->getVerboseIndexerLoggingEnabled());
m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked());
m_automaticUpdateCheck->setChecked(appSettings->getAutomaticUpdateCheck());
m_sourcetrailPort->setText(QString::number(appSettings->getSourcetrailPort()));
@@ -353,12 +427,12 @@ void QtProjectWizzardContentPreferences::save()
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
appSettings->setFontName(m_fontFace->getText().toStdString());
appSettings->setFontName(m_fontFace->currentText().toStdString());
appSettings->setFontSize(m_fontSize->currentIndex() + appSettings->getFontSizeMin());
appSettings->setCodeTabWidth(m_tabWidth->currentIndex() + 1);
appSettings->setTextEncoding(m_textEncoding->getText().toStdString());
appSettings->setTextEncoding(m_textEncoding->currentText().toStdString());
appSettings->setColorSchemePath(m_colorSchemePaths[m_colorSchemes->currentIndex()]);
m_oldColorSchemeIndex = -1;
@@ -366,14 +440,24 @@ void QtProjectWizzardContentPreferences::save()
appSettings->setUseAnimations(m_useAnimations->isChecked());
appSettings->setShowBuiltinTypesInGraph(m_showBuiltinTypes->isChecked());
appSettings->setLoggingEnabled(m_loggingEnabled->isChecked());
appSettings->setVerboseIndexerLoggingEnabled(m_verboseIndexerLoggingEnabled->isChecked());
if (m_screenAutoScaling)
{
appSettings->setScreenAutoScaling(m_screenAutoScaling->currentData().toInt());
}
if (m_screenScaleFactor)
{
appSettings->setScreenScaleFactor(m_screenScaleFactor->currentData().toDouble());
}
float scrollSpeed = m_scrollSpeed->text().toFloat();
if (scrollSpeed) appSettings->setScrollSpeed(scrollSpeed);
appSettings->setControlsGraphZoomOnMouseWheel(m_graphZooming->isChecked());
appSettings->setLoggingEnabled(m_loggingEnabled->isChecked());
appSettings->setVerboseIndexerLoggingEnabled(m_verboseIndexerLoggingEnabled->isChecked());
appSettings->setAutomaticUpdateCheck(m_automaticUpdateCheck->isChecked());
int sourcetrailPort = m_sourcetrailPort->text().toInt();
@@ -425,7 +509,8 @@ void QtProjectWizzardContentPreferences::javaPathDetectionClicked()
void QtProjectWizzardContentPreferences::jreSystemLibraryPathsDetectionClicked()
{
std::vector<FilePath> paths = m_jreSystemLibraryPathsDetector->getPaths(m_jreSystemLibraryPathsDetectorBox->currentText().toStdString());
std::vector<FilePath> paths =
m_jreSystemLibraryPathsDetector->getPaths(m_jreSystemLibraryPathsDetectorBox->currentText().toStdString());
std::vector<FilePath> oldPaths = m_jreSystemLibraryPaths->getList();
m_jreSystemLibraryPaths->setList(utility::unique(utility::concat(oldPaths, paths)));
}
@@ -448,7 +533,8 @@ void QtProjectWizzardContentPreferences::indexerThreadsChanges(int index)
{
if (index == 0)
{
m_threadsInfoLabel->setText(("detected " + std::to_string(utility::getIdealThreadCount()) + " threads to be ideal.").c_str());
m_threadsInfoLabel->setText(
("detected " + std::to_string(utility::getIdealThreadCount()) + " threads to be ideal.").c_str());
m_threadsInfoLabel->show();
}
else
@@ -457,6 +543,50 @@ void QtProjectWizzardContentPreferences::indexerThreadsChanges(int index)
}
}
void QtProjectWizzardContentPreferences::uiAutoScalingChanges(int index)
{
if (index == 0)
{
QString autoScale(qgetenv("QT_AUTO_SCREEN_SCALE_FACTOR_SOURCETRAIL"));
if (autoScale == "1")
{
autoScale = "on";
}
else
{
autoScale = "off";
}
m_screenAutoScalingInfoLabel->setText("detected: '" + autoScale + "'");
m_screenAutoScalingInfoLabel->show();
}
else
{
m_screenAutoScalingInfoLabel->hide();
}
}
void QtProjectWizzardContentPreferences::uiScaleFactorChanges(int index)
{
if (index == 0)
{
QString scale = "100";
bool ok;
double scaleFactor = qgetenv("QT_SCALE_FACTOR_SOURCETRAIL").toDouble(&ok);
if (ok)
{
scale = QString::number(int(scaleFactor * 100));
}
m_screenScaleFactorInfoLabel->setText("detected: '" + scale + "%'");
m_screenScaleFactorInfoLabel->show();
}
else
{
m_screenScaleFactorInfoLabel->hide();
}
}
void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layout, int& row)
{
std::vector<std::string> detectorNames = m_javaPathDetector->getWorkingDetectorNames();
@@ -608,6 +738,35 @@ QComboBox* QtProjectWizzardContentPreferences::addComboBox(
return comboBox;
}
QComboBox* QtProjectWizzardContentPreferences::addComboBoxWithWidgets(
QString label, QString helpText, std::vector<QWidget*> widgets, QGridLayout* layout, int& row)
{
QComboBox* comboBox = new QComboBox(this);
QHBoxLayout* hlayout = new QHBoxLayout();
hlayout->setContentsMargins(0, 0, 0, 0);
hlayout->addWidget(comboBox);
for (QWidget* widget : widgets)
{
hlayout->addWidget(widget);
}
QWidget* container = new QWidget();
container->setLayout(hlayout);
addLabelAndWidget(label, container, layout, row, Qt::AlignLeft);
if (helpText.size())
{
addHelpButton(label, helpText, layout, row);
}
row++;
return comboBox;
}
QComboBox* QtProjectWizzardContentPreferences::addComboBox(
QString label, int min, int max, QString helpText, QGridLayout* layout, int& row)
{
@@ -624,6 +783,22 @@ QComboBox* QtProjectWizzardContentPreferences::addComboBox(
return comboBox;
}
QComboBox* QtProjectWizzardContentPreferences::addComboBoxWithWidgets(
QString label, int min, int max, QString helpText, std::vector<QWidget*> widgets, QGridLayout* layout, int& row)
{
QComboBox* comboBox = addComboBoxWithWidgets(label, helpText, widgets, layout, row);
if (min != max)
{
for (int i = min; i <= max; i++)
{
comboBox->insertItem(i, QString::number(i));
}
}
return comboBox;
}
QLineEdit* QtProjectWizzardContentPreferences::addLineEdit(QString label, QString helpText, QGridLayout* layout, int& row)
{
QLineEdit* lineEdit = new QLineEdit(this);
@@ -1,18 +1,17 @@
#ifndef QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H
#define QT_PROJECT_WIZZARD_CONTENT_PREFERENCES_H
#include <QCheckBox>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include "qt/element/QtLocationPicker.h"
#include "qt/element/QtDirectoryListBox.h"
#include "qt/window/project_wizzard/QtProjectWizzardContent.h"
#include "utility/path_detector/CombinedPathDetector.h"
class QtFontPicker;
class QtTextEncodingPicker;
class QCheckBox;
class QComboBox;
class QFontComboBox;
class QLabel;
class QLineEdit;
class QtProjectWizzardContentPreferences
: public QtProjectWizzardContent
@@ -37,6 +36,8 @@ private slots:
void mavenPathDetectionClicked();
void loggingEnabledChanged();
void indexerThreadsChanges(int index);
void uiAutoScalingChanges(int index);
void uiScaleFactorChanges(int index);
private:
void addJavaPathDetection(QGridLayout* layout, int& row);
@@ -50,13 +51,17 @@ private:
QCheckBox* addCheckBox(QString label, QString text, QString helpText, QGridLayout* layout, int& row);
QComboBox* addComboBox(QString label, QString helpText, QGridLayout* layout, int& row);
QComboBox* addComboBoxWithWidgets(
QString label, QString helpText, std::vector<QWidget*> widgets, QGridLayout* layout, int& row);
QComboBox* addComboBox(QString label, int min, int max, QString helpText, QGridLayout* layout, int& row);
QComboBox* addComboBoxWithWidgets(
QString label, int min, int max, QString helpText, std::vector<QWidget*> widgets, QGridLayout* layout, int& row);
QLineEdit* addLineEdit(QString label, QString helpText, QGridLayout* layout, int& row);
QtFontPicker* m_fontFace;
QFontComboBox* m_fontFace;
QComboBox* m_fontSize;
QComboBox* m_tabWidth;
QtTextEncodingPicker* m_textEncoding;
QComboBox* m_textEncoding;
QComboBox* m_colorSchemes;
std::vector<FilePath> m_colorSchemePaths;
@@ -66,12 +71,18 @@ private:
QCheckBox* m_useAnimations;
QCheckBox* m_showBuiltinTypes;
QCheckBox* m_loggingEnabled;
QCheckBox* m_verboseIndexerLoggingEnabled;
QComboBox* m_screenAutoScaling;
QLabel* m_screenAutoScalingInfoLabel;
QComboBox* m_screenScaleFactor;
QLabel* m_screenScaleFactorInfoLabel;
QLineEdit* m_scrollSpeed;
QCheckBox* m_graphZooming;
QCheckBox* m_loggingEnabled;
QCheckBox* m_verboseIndexerLoggingEnabled;
QCheckBox* m_automaticUpdateCheck;
QLineEdit* m_sourcetrailPort;