#include "qt/window/project_wizzard/QtProjectWizzardContentPreferences.h" #include "settings/ApplicationSettings.h" #include "utility/file/FileSystem.h" #include "utility/messaging/type/MessageSwitchColorScheme.h" #include "utility/ResourcePaths.h" #include "utility/utilityPathDetection.h" QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences( std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) , m_oldColorSchemeIndex(-1) { std::vector colorSchemePaths = FileSystem::getFileNamesFromDirectory(ResourcePaths::getColorSchemesPath(), std::vector(1, ".xml")); for (const std::string& colorScheme : colorSchemePaths) { m_colorSchemePaths.push_back(FilePath(colorScheme)); } } QtProjectWizzardContentPreferences::~QtProjectWizzardContentPreferences() { if (m_oldColorSchemeIndex != -1) { colorSchemeChanged(m_oldColorSchemeIndex); } } void QtProjectWizzardContentPreferences::populate(QGridLayout* layout, int& row) { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); // ui addTitle("USER INTERFACE", layout, row); // font face m_fontFace = new QtFontPicker(this); m_fontFace->setObjectName("name"); m_fontFace->setAttribute(Qt::WA_MacShowFocusRect, 0); addLabelAndWidget("Font face", m_fontFace, layout, row); row++; // font size m_fontSize = addComboBox("Font size", appSettings->getFontSizeMin(), appSettings->getFontSizeMax(), "", layout, row); // tab width m_tabWidth = addComboBox("Tab width", 1, 16, "", layout, row); // color scheme m_colorSchemes = addComboBox("Color scheme", 0, 0, "", layout, row); for (size_t i = 0; i < m_colorSchemePaths.size(); i++) { m_colorSchemes->insertItem(i, m_colorSchemePaths[i].withoutExtension().fileName().c_str()); } connect(m_colorSchemes, SIGNAL(activated(int)), this, SLOT(colorSchemeChanged(int))); // animations m_useAnimations = addCheckBox("Animations", "Enable animations", "Enable/disable animations throughout the user interface.", layout, row); // logging m_loggingEnabled = addCheckBox("Logging", "Enable console and file logging", "Save log files and show log information in the console.", layout, row); connect(m_loggingEnabled, SIGNAL(clicked()), this, SLOT(loggingEnabledChanged())); m_verboseIndexerLoggingEnabled = addCheckBox("Indexer Logging", "Enable verbose indexer logging", "Logs information of abstract syntax tree traversal during indexing. This information can help us " "reproduce crashes in indexing.\n\nThis slows down indexing performance a lot.", layout, row); addGap(layout, row); // Controls addTitle("CONTROLS", layout, row); // scroll speed m_scrollSpeed = addLineEdit("Scroll Speed", "Multiplier for scroll speed. Set to a value between 0 and 1 to scroll " "slower, or set to larger than 1 to scroll faster.", layout, row); // graph zooming m_graphZooming = addCheckBox("Graph Zoom", "Zoom on mouse wheel", "Switch graph zooming to mouse wheel only, instead of SHIFT + mouse wheel.", layout, row); addGap(layout, row); // indexing addTitle("INDEXING", layout, row); // indexer threads m_threads = addComboBox("Indexer threads", 1, 24, "Number of parallel threads used to index your projects.", layout, row); addGap(layout, row); // Plugins addTitle("PLUGIN", layout, row); // Coati port m_coatiPort = addLineEdit("Coati Port", "Port number that Coati uses to listen for incoming messages from plugins.", layout, row); // Coati port m_pluginPort = addLineEdit("Plugin Port", "Port number that Coati sends outgoing messages to.", layout, row); addGap(layout, row); // Java addTitle("JAVA", layout, row); // jvm library path m_javaPath = new QtLocationPicker(this); #ifdef _WIN32 QString filter = "JVM Library (jvm.dll)"; #elif __APPLE__ QString filter = "JVM Library (libjvm.dylib)"; #else QString filter = "JVM Library (libjvm.so)"; #endif m_javaPath->setFileFilter(filter); if (QSysInfo::windowsVersion() != QSysInfo::WV_None) { m_javaPath->setPlaceholderText("/bin/client/jvm.dll"); } else if (QSysInfo::macVersion() != QSysInfo::MV_None) { m_javaPath->setPlaceholderText("Contents/Home/jre/lib/server/libjvm.dylib"); } else { m_javaPath->setPlaceholderText("/bin//server/libjvm.so"); } addLabelAndWidget("Java Path", m_javaPath, layout, row); addHelpButton( "Location of your Java 8 runtime dynamic library (for information on how to set these take a look at " "" "Finding Java Runtime Library Location or use the auto detection below)" , layout, row ); row++; m_javaPathDetector = utility::getJavaRuntimePathDetector(); addJavaPathDetection(layout, row); // jvm max memory m_jvmMaximumMemory = addLineEdit("JVM Maximum Memory", "Specify the maximum amount of memory that should be " "allocated by the indexer's JVM. A value of -1 ignores this setting.", layout, row); layout->setRowMinimumHeight(row - 1, 30); addGap(layout, row); // C/C++ addTitle("C/C++", layout, row); } void QtProjectWizzardContentPreferences::load() { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); m_fontFace->setText(QString::fromStdString(appSettings->getFontName())); m_fontSize->setCurrentIndex(appSettings->getFontSize() - appSettings->getFontSizeMin()); m_tabWidth->setCurrentIndex(appSettings->getCodeTabWidth() - 1); FilePath colorSchemePath = appSettings->getColorSchemePath(); for (size_t i = 0; i < m_colorSchemePaths.size(); i++) { if (colorSchemePath == m_colorSchemePaths[i]) { m_colorSchemes->setCurrentIndex(i); m_oldColorSchemeIndex = i; break; } } m_useAnimations->setChecked(appSettings->getUseAnimations()); m_loggingEnabled->setChecked(appSettings->getLoggingEnabled()); m_verboseIndexerLoggingEnabled->setChecked(appSettings->getVerboseIndexerLoggingEnabled()); m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked()); m_scrollSpeed->setText(QString::number(appSettings->getScrollSpeed(), 'f', 1)); m_graphZooming->setChecked(appSettings->getControlsGraphZoomOnMouseWheel()); m_coatiPort->setText(QString::number(appSettings->getCoatiPort())); m_pluginPort->setText(QString::number(appSettings->getPluginPort())); m_threads->setCurrentIndex(appSettings->getIndexerThreadCount() - 1); if (m_javaPath) { m_javaPath->setText(QString::fromStdString(appSettings->getJavaPath())); } m_jvmMaximumMemory->setText(QString::number(appSettings->getJavaMaximumMemory())); } void QtProjectWizzardContentPreferences::save() { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); appSettings->setFontName(m_fontFace->getText().toStdString()); appSettings->setFontSize(m_fontSize->currentIndex() + appSettings->getFontSizeMin()); appSettings->setCodeTabWidth(m_tabWidth->currentIndex() + 1); appSettings->setColorSchemePath(m_colorSchemePaths[m_colorSchemes->currentIndex()]); m_oldColorSchemeIndex = -1; appSettings->setUseAnimations(m_useAnimations->isChecked()); appSettings->setLoggingEnabled(m_loggingEnabled->isChecked()); appSettings->setVerboseIndexerLoggingEnabled(m_verboseIndexerLoggingEnabled->isChecked()); float scrollSpeed = m_scrollSpeed->text().toFloat(); if (scrollSpeed) appSettings->setScrollSpeed(scrollSpeed); appSettings->setControlsGraphZoomOnMouseWheel(m_graphZooming->isChecked()); int coatiPort = m_coatiPort->text().toInt(); if (coatiPort) appSettings->setCoatiPort(coatiPort); int pluginPort = m_pluginPort->text().toInt(); if (pluginPort) appSettings->setPluginPort(pluginPort); appSettings->setIndexerThreadCount(m_threads->currentIndex() + 1); if (m_javaPath) { appSettings->setJavaPath(m_javaPath->getText().toStdString()); } int jvmMaximumMemory = m_jvmMaximumMemory->text().toInt(); if (jvmMaximumMemory) appSettings->setJavaMaximumMemory(jvmMaximumMemory); } bool QtProjectWizzardContentPreferences::check() { return true; } void QtProjectWizzardContentPreferences::colorSchemeChanged(int index) { MessageSwitchColorScheme(m_colorSchemePaths[index]).dispatch(); } void QtProjectWizzardContentPreferences::javaPathDetectionClicked() { std::vector paths = m_javaPathDetector->getPaths(m_javaPathDetectorBox->currentText().toStdString()); if (!paths.empty()) { m_javaPath->setText(paths.front().str().c_str()); } } void QtProjectWizzardContentPreferences::loggingEnabledChanged() { m_verboseIndexerLoggingEnabled->setEnabled(m_loggingEnabled->isChecked()); } void QtProjectWizzardContentPreferences::addJavaPathDetection(QGridLayout* layout, int& row) { std::vector detectorNames = m_javaPathDetector->getWorkingDetectorNames(); if (detectorNames.empty()) { return; } QLabel* label = new QLabel("Auto detection from:"); m_javaPathDetectorBox = new QComboBox(); for (const std::string& detectorName: detectorNames) { m_javaPathDetectorBox->addItem(detectorName.c_str()); } QPushButton* button = new QPushButton("detect"); button->setObjectName("windowButton"); connect(button, SIGNAL(clicked()), this, SLOT(javaPathDetectionClicked())); QHBoxLayout* hlayout = new QHBoxLayout(); hlayout->setContentsMargins(0, 0, 0, 0); hlayout->addWidget(label); hlayout->addWidget(m_javaPathDetectorBox); hlayout->addWidget(button); QWidget* detectionWidget = new QWidget(); detectionWidget->setLayout(hlayout); layout->addWidget(detectionWidget, row, QtProjectWizzardWindow::BACK_COL, Qt::AlignLeft | Qt::AlignTop); row++; } void QtProjectWizzardContentPreferences::addTitle(QString title, QGridLayout* layout, int& row) { layout->addWidget(createFormTitle(title), row++, QtProjectWizzardWindow::FRONT_COL, Qt::AlignLeft); } void QtProjectWizzardContentPreferences::addLabelAndWidget( QString label, QWidget* widget, QGridLayout* layout, int& row, Qt::Alignment widgetAlignment) { layout->addWidget(createFormLabel(label), row, QtProjectWizzardWindow::FRONT_COL, Qt::AlignRight); layout->addWidget(widget, row, QtProjectWizzardWindow::BACK_COL, widgetAlignment); } void QtProjectWizzardContentPreferences::addGap(QGridLayout* layout, int& row) { layout->setRowMinimumHeight(row++, 20); } QCheckBox* QtProjectWizzardContentPreferences::addCheckBox( QString label, QString text, QString help, QGridLayout* layout, int& row) { QCheckBox* checkBox = new QCheckBox(text, this); addLabelAndWidget(label, checkBox, layout, row, Qt::AlignLeft); if (help.size()) { addHelpButton(help, layout, row); } row++; return checkBox; } QComboBox* QtProjectWizzardContentPreferences::addComboBox( QString label, int min, int max, QString help, QGridLayout* layout, int& row) { QComboBox* comboBox = new QComboBox(this); addLabelAndWidget(label, comboBox, layout, row, Qt::AlignLeft); if (min != max) { for (int i = min; i <= max; i++) { comboBox->insertItem(i, QString::number(i)); } } if (help.size()) { addHelpButton(help, layout, row); } row++; return comboBox; } QLineEdit* QtProjectWizzardContentPreferences::addLineEdit(QString label, QString help, QGridLayout* layout, int& row) { QLineEdit* lineEdit = new QLineEdit(this); lineEdit->setObjectName("name"); lineEdit->setAttribute(Qt::WA_MacShowFocusRect, 0); addLabelAndWidget(label, lineEdit, layout, row); if (help.size()) { addHelpButton(help, layout, row); } row++; return lineEdit; }