diff --git a/.gitmodules b/.gitmodules index 3f0480529c..dd7e078495 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,7 +25,8 @@ url = https://bitbucket.org/codeimproved/qslog.git [submodule "installer/nxt-tools"] path = installer/nxt-tools - url = https://github.com/trikset/nxt-tools + url = https://github.com/trikset/nxt-tools.git + branch = main [submodule "trik-checkapp"] path = thirdparty/checkapp/checkapp url = https://github.com/trikset/trik-checkapp diff --git a/installer/nxt-tools b/installer/nxt-tools index dff80a065f..6c4d5f1150 160000 --- a/installer/nxt-tools +++ b/installer/nxt-tools @@ -1 +1 @@ -Subproject commit dff80a065f57f4df70b44c69df54dfa2433e9009 +Subproject commit 6c4d5f1150d8beb5004ce3b606c6134bf0fc262d diff --git a/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-linux-gnu.sh b/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-linux-gnu.sh index 19c9baa80d..83eed3b18b 100755 --- a/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-linux-gnu.sh +++ b/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-linux-gnu.sh @@ -6,4 +6,4 @@ cd "$(dirname "$0")" source "$INSTALLER_ROOT"/utils/common_utils.sh mkdir "$PWD"/../data/bin cd "$PWD"/../data/bin -rsync -a "$INSTALLER_ROOT"/nxt-tools/linux/nxt-tools ./ +rsync -a "$INSTALLER_ROOT"/nxt-tools ./ diff --git a/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-win32.sh b/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-win32.sh index 57a1ec8ca3..6a1907ba25 100644 --- a/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-win32.sh +++ b/installer/packages/trik-studio/ru.qreal.root.nxt.tools/meta/prebuild-win32.sh @@ -7,6 +7,6 @@ source "$INSTALLER_ROOT"/utils/common_utils.sh cd "$PWD"/../data -rsync -aR "$INSTALLER_ROOT"/nxt-tools/win/./nxt-tools . +rsync -aR "$INSTALLER_ROOT"/./nxt-tools . dos2unix nxt-tools/compile.sh rm -rf bin diff --git a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp index 4c531e909d..cdf8929164 100644 --- a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp +++ b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtFlashTool.cpp @@ -222,15 +222,25 @@ bool NxtFlashTool::uploadProgram(const QFileInfo &fileInfo) mCompileState = idle; mSource = fileInfo; -#ifdef Q_OS_WIN mCompileProcess.setWorkingDirectory(path()); - mCompileProcess.start("cmd", { "/c", path("compile.bat") - + " " + fileInfo.completeBaseName() - + " " + fileInfo.absolutePath() }); -#else - mCompileProcess.start("sh", { path("compile.sh") , fileInfo.absolutePath()}); -#endif + auto osType = PlatformInfo::osType(); + if (osType == "windows") { + auto line = path("compile.bat") + + " " + fileInfo.completeBaseName() + + " " + fileInfo.absolutePath() + + " " + path("gnuarm"); + mCompileProcess.start("cmd", { "/c", line}); + } + else if (osType == "linux") { + auto line = "./compile.sh . " + fileInfo.absolutePath() + + " GNUARM_ROOT="+SettingsManager::value("pathToArmNoneEabi").toString(); + mCompileProcess.start("/bin/bash", {"-c", line}); + } + else { + QLOG_INFO() << "Platform: " << osType << "not supported for upload program"; + return false; + } information(tr("Uploading program started. Please don't disconnect robot during the process")); return true; } @@ -291,6 +301,10 @@ void NxtFlashTool::readNxtCompileData() "If you sure in their validness contact developers")); } else { error(tr("Could not upload program. Make sure the robot is connected and ON")); + if (PlatformInfo::osType() == "linux") { + error(tr("If you are using GNU/Linux visit " + "https://help.trikset.com/nxt/run-upload-programs to get instructions")); + } } } diff --git a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp index e408cc20b2..a26178f16d 100644 --- a/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp +++ b/plugins/robots/generators/nxt/nxtOsekCGenerator/nxtOsekCGeneratorPlugin.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "nxtOsekCGeneratorPlugin.h" - #include #include #include @@ -22,6 +21,7 @@ #include #include +#include "QsLog.h" #include "nxtOsekCMasterGenerator.h" using namespace nxt::osekC; @@ -37,6 +37,12 @@ NxtOsekCGeneratorPlugin::NxtOsekCGeneratorPlugin() , mMasterGenerator(nullptr) , mCommunicator(utils::Singleton::instance()) { + const QString key = "pathToArmNoneEabi"; + const QString defaultPath = QDir(PlatformInfo::invariantSettingsPath("pathToNxtTools")).absolutePath() + +"/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi"; + if (qReal::SettingsManager::value(key).isNull()) { + qReal::SettingsManager::setValue(key, defaultPath); + } initActions(); initHotKeyActions(); } @@ -96,7 +102,6 @@ void NxtOsekCGeneratorPlugin::onCurrentDiagramChanged(const TabInfo &info) void NxtOsekCGeneratorPlugin::init(const kitBase::KitPluginConfigurator &configurator) { RobotsGeneratorPluginBase::init(configurator); - mFlashTool.reset(new NxtFlashTool(*mMainWindowInterface->errorReporter(), *mCommunicator)); connect(&*mFlashTool, &NxtFlashTool::uploadingComplete, this, &NxtOsekCGeneratorPlugin::onUploadingComplete); } @@ -223,21 +228,27 @@ void NxtOsekCGeneratorPlugin::uploadProgram() void NxtOsekCGeneratorPlugin::checkNxtTools() { const QDir dir(PlatformInfo::invariantSettingsPath("pathToNxtTools")); - if (!dir.exists()) { - mNxtToolsPresent = false; - } else { - QDir gnuarm(dir.absolutePath() + "/gnuarm/bin"); - QDir nexttool(dir.absolutePath() + "/nexttool"); - QDir nxtOSEK(dir.absolutePath() + "/nxtOSEK"); - -#ifdef Q_OS_WIN - QFile compile1(dir.absolutePath() + "/compile.bat"); - QFile compile2(dir.absolutePath() + "/compile.sh"); - mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists() - && compile1.exists() && compile2.exists(); -#else - QFile compile(dir.absolutePath() + "/compile.sh"); - mNxtToolsPresent = gnuarm.exists() && nexttool.exists() && nxtOSEK.exists() && compile.exists(); -#endif + auto compilePath = dir.absolutePath() + "/compile.sh"; + + auto nxtToolsPresent = dir.exists() + && QFileInfo::exists(dir.absolutePath() + "/gnuarm") + && QFileInfo::exists(dir.absolutePath() + "/nexttool") + && QFileInfo::exists(dir.absolutePath() + "/nxtOSEK") + && QFileInfo::exists(compilePath) && QFileInfo(compilePath).isFile(); + + if (!nxtToolsPresent) { + mNxtToolsPresent = false; + QLOG_ERROR() << "Missing" << dir.absolutePath() << "or mandatory subdirectory" << + dir.entryList(QDir::Filter::NoFilter, QDir::SortFlag::DirsFirst | QDir::SortFlag::Name); + return; + } + + auto osType = PlatformInfo::osType(); + if (osType == "linux") { + mNxtToolsPresent = true; + } + else if (osType == "windows") { + auto compileBatPath = dir.absolutePath() + "/compile.bat"; + mNxtToolsPresent = QFileInfo::exists(compileBatPath) && QFileInfo(compileBatPath).isFile(); } } diff --git a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.cpp b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.cpp index 9967bfb4ed..c82236561e 100644 --- a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.cpp +++ b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.cpp @@ -14,9 +14,11 @@ #include "nxtAdditionalPreferences.h" #include "ui_nxtAdditionalPreferences.h" - #include #include +#include "QsLog.h" +#include +#include using namespace nxt; using namespace qReal; @@ -28,6 +30,13 @@ NxtAdditionalPreferences::NxtAdditionalPreferences(const QString &realRobotName, { mUi->setupUi(this); mUi->robotImagePicker->configure("nxtRobot2DImage", tr("2D robot image:")); + if (PlatformInfo::osType() == "linux") { + mUi->compilerPicker->configure("pathToArmNoneEabi", tr("Path to arm-none-eabi:")); + setTextOnGeneratorLabel(); + } + else { + mUi->generatorSettingsGroupBox->setVisible(false); + } connect(mUi->manualComPortCheckbox, &QCheckBox::toggled , this, &NxtAdditionalPreferences::manualComPortCheckboxChecked); } @@ -37,11 +46,35 @@ NxtAdditionalPreferences::~NxtAdditionalPreferences() delete mUi; } +void NxtAdditionalPreferences::setColorOnGeneratorLabel(QColor color){ + QPalette palette = mUi->generatorLabel->palette(); + palette.setColor(mUi->generatorLabel->foregroundRole(), color); + mUi->generatorLabel->setPalette(palette); +} + +void NxtAdditionalPreferences::setTextOnGeneratorLabel(){ + if (!mUi->compilerPicker->isSavedDirExist()){ + mUi->generatorLabel->setText(tr("WARNING: Current directory doesn't exist. \nOpen " + "link" + " for instructions")); + mUi->generatorLabel->setTextFormat(Qt::RichText); + mUi->generatorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); + mUi->generatorLabel->setOpenExternalLinks(true); + setColorOnGeneratorLabel(QColor("red")); + } + else { + mUi->generatorLabel->setText("Current directory exist."); + setColorOnGeneratorLabel(QColor("black")); + } +} + void NxtAdditionalPreferences::save() { SettingsManager::setValue("NxtBluetoothPortName", selectedPortName()); SettingsManager::setValue("NxtManualComPortCheckboxChecked", mUi->manualComPortCheckbox->isChecked()); mUi->robotImagePicker->save(); + mUi->compilerPicker->save(); + setTextOnGeneratorLabel(); emit settingsChanged(); } @@ -49,6 +82,8 @@ void NxtAdditionalPreferences::restoreSettings() { ui::ComPortPicker::populate(*mUi->comPortComboBox, "NxtBluetoothPortName"); mUi->robotImagePicker->restore(); + mUi->compilerPicker->restore(); + setTextOnGeneratorLabel(); if (mUi->comPortComboBox->count() == 0) { mUi->comPortComboBox->hide(); @@ -72,7 +107,11 @@ void NxtAdditionalPreferences::restoreSettings() void NxtAdditionalPreferences::onRobotModelChanged(kitBase::robotModel::RobotModelInterface * const robotModel) { + QLOG_DEBUG() << robotModel->name(); mUi->bluetoothSettingsGroupBox->setVisible(robotModel->name() == mBluetoothRobotName); + if (PlatformInfo::osType() == "linux") { + mUi->generatorSettingsGroupBox->setVisible(robotModel->name() == "NxtOsekCGeneratorRobotModel"); + } } void NxtAdditionalPreferences::manualComPortCheckboxChecked(bool state) diff --git a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.h b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.h index 6c678beda0..1cf777d557 100644 --- a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.h +++ b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.h @@ -42,7 +42,8 @@ private slots: private: QString selectedPortName() const; - + void setColorOnGeneratorLabel(QColor color); + void setTextOnGeneratorLabel(); Ui::NxtAdditionalPreferences *mUi; const QString mBluetoothRobotName; }; diff --git a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.ui b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.ui index 956d6cda0b..ccc144e3d5 100644 --- a/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.ui +++ b/plugins/robots/interpreters/nxtKitInterpreter/src/nxtAdditionalPreferences.ui @@ -6,8 +6,8 @@ 0 0 - 414 - 164 + 401 + 284 @@ -27,22 +27,33 @@ 0 - - + - + - Bluetooth Settings + nxtOSEK Generator Settings - + - + - COM Port: + TextLabel + + + + + + + + + + Bluetooth Settings + + @@ -53,16 +64,6 @@ - - - - COM Port: - - - - - - @@ -73,6 +74,9 @@ + + + @@ -80,6 +84,20 @@ + + + + COM Port: + + + + + + + COM Port: + + + @@ -92,6 +110,12 @@
qrutils/widgets/imagePicker.h
1 + + qReal::ui::dirPicker + QWidget +
qrutils/widgets/dirPicker.h
+ 1 +
diff --git a/qrtranslations/fr/plugins/robots/nxtKitInterpreter_fr.ts b/qrtranslations/fr/plugins/robots/nxtKitInterpreter_fr.ts index 2068664b12..de402f6439 100644 --- a/qrtranslations/fr/plugins/robots/nxtKitInterpreter_fr.ts +++ b/qrtranslations/fr/plugins/robots/nxtKitInterpreter_fr.ts @@ -9,23 +9,33 @@ Configuration de NXT - + + nxtOSEK Generator Settings + + + + + TextLabel + + + + Bluetooth Settings Paramètres Bluetooth - - + + COM Port: Port série : - + No COM ports found. If you have a Bluetooth connection with active virtual COM port, please enter its name. Example: COM3 Aucu port série n'est détecté. Si vous avez une connexion Bluetooth avec un port série virtuel actif, tapez son nom. Par exemple : COM3 - + Specify COM port manually Spécifiez le port en série manuellement @@ -41,10 +51,21 @@ nxt::NxtAdditionalPreferences - + 2D robot image: + + + Path to arm-none-eabi: + + + + + WARNING: Current directory doesn't exist. +Open <a href="https://help.trikset.com/nxt/run-upload-programs">link</a> for instructions + + nxt::NxtKitInterpreterPlugin diff --git a/qrtranslations/fr/plugins/robots/nxtOsekCGenerator_fr.ts b/qrtranslations/fr/plugins/robots/nxtOsekCGenerator_fr.ts index 5283af4fe9..eb7c06fbcc 100644 --- a/qrtranslations/fr/plugins/robots/nxtOsekCGenerator_fr.ts +++ b/qrtranslations/fr/plugins/robots/nxtOsekCGenerator_fr.ts @@ -67,7 +67,7 @@ Le téléversement est deja lancé - + Uploading program started. Please don't disconnect robot during the process Le téléversement du programme est commencé. S'il vous plait, ne déconnectéz pas le robot jusqu'à ce que le processus se termine @@ -82,7 +82,7 @@ Échec de téléversement du programme. Assurez-vous que le robot soit connecté et qu'il ne soit pas éteint - + Error in reading from firmware file: %1 @@ -112,12 +112,12 @@ Téléversement réussi - + Compilation error occured. Please check your function blocks syntax. If you sure in their validness contact developers Une erreur de compilation s'est produite. Vérifiez le syntaxe à l'intérieur des blocs "fonction". S'ils sont valides, contactez les developpeurs - + Could not open %1 for reading. @@ -147,12 +147,17 @@ - + You need to have superuser privileges to flash NXT robot - + + If you are using GNU/Linux visit https://help.trikset.com/nxt/run-upload-programs to get instructions + + + + QReal requires superuser privileges to upload programs on NXT robot QReal necessite les droits de superutilisateur pour mettre à jour le programme du robot NXT @@ -165,8 +170,8 @@ Génération (NXT OSEK C) - - + + NXT tools package is not installed diff --git a/qrtranslations/fr/qrutils_fr.ts b/qrtranslations/fr/qrutils_fr.ts index d930d61d83..eacd8c6b85 100644 --- a/qrtranslations/fr/qrutils_fr.ts +++ b/qrtranslations/fr/qrutils_fr.ts @@ -507,6 +507,14 @@ + + qReal::ui::dirPicker + + + Browse... + + + utils::MetamodelGeneratorSupport diff --git a/qrtranslations/ru/plugins/robots/nxtKitInterpreter_ru.ts b/qrtranslations/ru/plugins/robots/nxtKitInterpreter_ru.ts index 0e26961090..ebd230c963 100644 --- a/qrtranslations/ru/plugins/robots/nxtKitInterpreter_ru.ts +++ b/qrtranslations/ru/plugins/robots/nxtKitInterpreter_ru.ts @@ -21,23 +21,33 @@ USB - + Bluetooth Settings Настройки Bluetooth - - + + COM Port: COM-Порт: - + No COM ports found. If you have a Bluetooth connection with active virtual COM port, please enter its name. Example: COM3 COM-порты не найдены. Если установлено Bluetooth-соединение с активным COM-портом, пожалуйста, укажите его имя. Пример: COM3 - + + nxtOSEK Generator Settings + Настройки генерации кода nxtOSEK + + + + TextLabel + + + + Specify COM port manually Указать COM-порт вручную @@ -60,10 +70,22 @@ nxt::NxtAdditionalPreferences - + 2D robot image: Картинка робота в 2D: + + + Path to arm-none-eabi: + Путь к кросс-компилятору + + + + WARNING: Current directory doesn't exist. +Open <a href="https://help.trikset.com/nxt/run-upload-programs">link</a> for instructions + ВНИМАНИЕ: Выбранная директория не существует. + Откройте <a href="https://help.trikset.com/nxt/run-upload-programs">ссылку</a> для дальнейших инструкций + nxt::NxtKitInterpreterPlugin diff --git a/qrtranslations/ru/plugins/robots/nxtOsekCGenerator_ru.ts b/qrtranslations/ru/plugins/robots/nxtOsekCGenerator_ru.ts index 0503e4fbfa..226b129c73 100644 --- a/qrtranslations/ru/plugins/robots/nxtOsekCGenerator_ru.ts +++ b/qrtranslations/ru/plugins/robots/nxtOsekCGenerator_ru.ts @@ -67,7 +67,7 @@ Программа уже загружается - + Uploading program started. Please don't disconnect robot during the process Начат процесс загрузки программы в робота. Пожалуйста, не отсоединяйте робота, пока процесс не будет завершен @@ -82,7 +82,7 @@ Не удалось загрузить программу в робота. Убедитесь, что робот включен и подсоединен к компьютеру - + Error in reading from firmware file: %1 Ошибка чтения из файла с прошивкой %1 @@ -112,12 +112,12 @@ Загрузка программы завершена успешно - + Compilation error occured. Please check your function blocks syntax. If you sure in their validness contact developers Произошла ошибка компиляции. Проверьте синтаксис выражений внутри блоков "Функция";. Если Вы уверены в их корректности, обратитесь к разработчикам - + Could not open %1 for reading. Не могу открыть файл %1 для чтения. @@ -147,12 +147,21 @@ Прошиваю робота... - + You need to have superuser privileges to flash NXT robot Загрузка программы не удалась. Возможно, стоит попробовать перезапустить среду с правами суперпользователя - + Could not upload program. Make sure the robot is connected and ON. + Не удалось загрузить программу. Убедитесь, что робот подключен и включен. + + + + If you are using GNU/Linux visit https://help.trikset.com/nxt/run-upload-programs to get instructions + Если вы пользователь ОС GNU/Linux, перейдите по ссылке https://help.trikset.com/nxt/run-upload-programs для получения инструкций. + + + QReal requires superuser privileges to upload programs on NXT robot Для загрузки программ в робота требуется запустить TRIKStudio с правами администратора @@ -169,8 +178,8 @@ Генерация (C) - - + + NXT tools package is not installed Пакет "Инструменты NXT" не установлен diff --git a/qrtranslations/ru/qrutils_ru.ts b/qrtranslations/ru/qrutils_ru.ts index 36fc8f0fe9..dae5e5a7ec 100644 --- a/qrtranslations/ru/qrutils_ru.ts +++ b/qrtranslations/ru/qrutils_ru.ts @@ -619,6 +619,14 @@ <строка>:<столбец> + + qReal::ui::dirPicker + + + Browse... + Обзор... + + utils::MetamodelGeneratorSupport diff --git a/qrutils/widgets/dirPicker.cpp b/qrutils/widgets/dirPicker.cpp new file mode 100644 index 0000000000..06382eb341 --- /dev/null +++ b/qrutils/widgets/dirPicker.cpp @@ -0,0 +1,70 @@ +/* Copyright 2017 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#include "dirPicker.h" +#include +#include +#include +#include +#include + +#include +#include + +using namespace qReal::ui; + + +dirPicker::dirPicker(QWidget *parent) + : QWidget(parent) +{ + mLabel = new QLabel(this); + mPathEditor = new QLineEdit(this); + QPushButton *button = new QPushButton(style()->standardIcon(QStyle::SP_DirIcon), tr("Browse..."), this); + QHBoxLayout *layout = new QHBoxLayout(this); + layout->addWidget(mLabel); + layout->addWidget(mPathEditor); + layout->addWidget(button); + connect(button, &QPushButton::clicked, this, &dirPicker::pick); +} + +void dirPicker::configure(const QString &settingsKey, const QString &title) +{ + mSettingsKey = settingsKey; + mLabel->setText(title); +} + +bool dirPicker::isSavedDirExist(){ + return QDir(SettingsManager::value(mSettingsKey).toString()).exists(); +} + +void dirPicker::save() const +{ + if (!mPathEditor->text().isEmpty() && !mSettingsKey.isEmpty()) { + SettingsManager::setValue(mSettingsKey, mPathEditor->text()); + } +} + +void dirPicker::restore() +{ + if (!mSettingsKey.isEmpty()) { + mPathEditor->setText(SettingsManager::value(mSettingsKey).toString()); + } +} + +void dirPicker::pick() +{ + QDir dirPath=QFileDialog::getExistingDirectory(this, "Get Any File"); + SettingsManager::setValue(mSettingsKey, dirPath.absolutePath()); + mPathEditor->setText(dirPath.absolutePath()); +} diff --git a/qrutils/widgets/dirPicker.h b/qrutils/widgets/dirPicker.h new file mode 100644 index 0000000000..e8a89d6e63 --- /dev/null +++ b/qrutils/widgets/dirPicker.h @@ -0,0 +1,57 @@ +/* Copyright 2017 CyberTech Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ + +#pragma once + +#include + +#include + +class QLabel; +class QLineEdit; + +namespace qReal { +namespace ui { + +/// Picks some image from disk, saves into settings. +class QRUTILS_EXPORT dirPicker : public QWidget +{ + Q_OBJECT + +public: + explicit dirPicker(QWidget *parent = nullptr); + + /// Sets parameters of the image picker. + void configure(const QString &settingsKey, const QString &title); + + /// Saves picked location into settings. + void save() const; + + /// Restores last picked value. + void restore(); + + bool isSavedDirExist(); + + +private slots: + void pick(); + +private: + QString mSettingsKey; + QLabel *mLabel; + QLineEdit *mPathEditor; +}; + +} +} diff --git a/qrutils/widgets/widgets.pri b/qrutils/widgets/widgets.pri index c98cbd474e..a7041c2f84 100644 --- a/qrutils/widgets/widgets.pri +++ b/qrutils/widgets/widgets.pri @@ -14,6 +14,7 @@ HEADERS += \ $$PWD/colorListEditor.h \ + $$PWD/dirPicker.h \ $$PWD/paintWidget.h \ $$PWD/painterInterface.h \ $$PWD/searchLineEdit.h \ @@ -26,6 +27,7 @@ HEADERS += \ SOURCES += \ $$PWD/colorListEditor.cpp \ + $$PWD/dirPicker.cpp \ $$PWD/paintWidget.cpp \ $$PWD/searchLineEdit.cpp \ $$PWD/consoleDock.cpp \