-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,044 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
RedPandaIDE/settingsdialog/environmentdatasizewidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Roy Qu ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#include "environmentdatasizewidget.h" | ||
#include "ui_environmentdatasizewidget.h" | ||
#include "../settings.h" | ||
#include "../iconsmanager.h" | ||
#include "../systemconsts.h" | ||
#include "../compiler/executablerunner.h" | ||
#include "utils.h" | ||
#include "utils/escape.h" | ||
#include "utils/font.h" | ||
|
||
#include <QFileDialog> | ||
#include <QMessageBox> | ||
|
||
EnvironmentDataSizeWidget::EnvironmentDataSizeWidget(const QString& name, const QString& group, QWidget *parent) : | ||
SettingsWidget(name,group,parent), | ||
ui(new Ui::EnvironmentDataSizeWidget) | ||
{ | ||
ui->setupUi(this); | ||
updateScalePreview(pSettings->environment().dataSizeDialect()); | ||
} | ||
|
||
EnvironmentDataSizeWidget::~EnvironmentDataSizeWidget() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void EnvironmentDataSizeWidget::updateScalePreview(DataSizeDialect dialect) | ||
{ | ||
QLocale locale = QLocale::system(); | ||
QLocale::DataSizeFormats qtDialect = Settings::Environment::qtDataSizeDialect(dialect); | ||
QString previewText; | ||
auto append = [&] (QString display1, qint64 size1, QString display2, qint64 size2) { | ||
previewText += display1; | ||
previewText += " B = "; | ||
previewText += locale.formattedDataSize(size1, 2, qtDialect); | ||
previewText += ", "; | ||
previewText += display2; | ||
previewText += " B = "; | ||
previewText += locale.formattedDataSize(size2, 2, qtDialect); | ||
previewText += "\n"; | ||
}; | ||
append("10³", 1'000, "2¹⁰", 1LL << 10); | ||
append("10⁶", 1'000'000, "2²⁰", 1LL << 20); | ||
append("10⁹", 1'000'000'000, "2³⁰", 1LL << 30); | ||
append("10¹²", 1'000'000'000'000, "2⁴⁰", 1LL << 40); | ||
append("10¹⁵", 1'000'000'000'000'000, "2⁵⁰", 1LL << 50); | ||
append("10¹⁸", 1'000'000'000'000'000'000, "2⁶⁰", 1LL << 60); | ||
ui->tbScalePreview->setText(previewText); | ||
} | ||
|
||
void EnvironmentDataSizeWidget::doLoad() | ||
{ | ||
switch (pSettings->environment().dataSizeDialect()) { | ||
case DataSizeDialect::SiDecimal: | ||
ui->rbSiDecimal->setChecked(true); | ||
break; | ||
case DataSizeDialect::IecBinary: | ||
ui->rbIecBinary->setChecked(true); | ||
break; | ||
case DataSizeDialect::JedecBinary: | ||
ui->rbJedecBinary->setChecked(true); | ||
break; | ||
} | ||
} | ||
|
||
void EnvironmentDataSizeWidget::doSave() | ||
{ | ||
if (ui->rbSiDecimal->isChecked()) | ||
pSettings->environment().setDataSizeDialect(DataSizeDialect::SiDecimal); | ||
else if (ui->rbIecBinary->isChecked()) | ||
pSettings->environment().setDataSizeDialect(DataSizeDialect::IecBinary); | ||
else if (ui->rbJedecBinary->isChecked()) | ||
pSettings->environment().setDataSizeDialect(DataSizeDialect::JedecBinary); | ||
pSettings->environment().save(); | ||
} | ||
|
||
void EnvironmentDataSizeWidget::updateIcons(const QSize &) | ||
{ | ||
} | ||
|
||
void EnvironmentDataSizeWidget::on_rbSiDecimal_clicked() | ||
{ | ||
updateScalePreview(DataSizeDialect::SiDecimal); | ||
} | ||
|
||
void EnvironmentDataSizeWidget::on_rbIecBinary_clicked() | ||
{ | ||
updateScalePreview(DataSizeDialect::IecBinary); | ||
} | ||
|
||
void EnvironmentDataSizeWidget::on_rbJedecBinary_clicked() | ||
{ | ||
updateScalePreview(DataSizeDialect::JedecBinary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Roy Qu ([email protected]) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef ENVIRONMENTDATASIZEWIDGET_H | ||
#define ENVIRONMENTDATASIZEWIDGET_H | ||
|
||
#include "settings.h" | ||
#include "settingswidget.h" | ||
#include "utils.h" | ||
|
||
namespace Ui { | ||
class EnvironmentDataSizeWidget; | ||
} | ||
|
||
class EnvironmentDataSizeWidget : public SettingsWidget | ||
{ | ||
Q_OBJECT | ||
|
||
using DataSizeDialect = Settings::Environment::DataSizeDialect; | ||
|
||
public: | ||
explicit EnvironmentDataSizeWidget(const QString& name, const QString& group, QWidget *parent = nullptr); | ||
~EnvironmentDataSizeWidget(); | ||
|
||
private: | ||
void updateScalePreview(DataSizeDialect dialect); | ||
|
||
private: | ||
Ui::EnvironmentDataSizeWidget *ui; | ||
|
||
private slots: | ||
void on_rbSiDecimal_clicked(); | ||
void on_rbIecBinary_clicked(); | ||
void on_rbJedecBinary_clicked(); | ||
|
||
// SettingsWidget interface | ||
protected: | ||
void doLoad() override; | ||
void doSave() override; | ||
void updateIcons(const QSize &size) override; | ||
}; | ||
|
||
#endif // ENVIRONMENTDATASIZEWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>EnvironmentDataSizeWidget</class> | ||
<widget class="QWidget" name="EnvironmentDataSizeWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QGroupBox" name="grpDataSize"> | ||
<layout class="QGridLayout" name="gridLayout_2"> | ||
<item row="2" column="0"> | ||
<widget class="QRadioButton" name="rbIecBinary"> | ||
<property name="text"> | ||
<string>IEC binary</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="0"> | ||
<widget class="QRadioButton" name="rbJedecBinary"> | ||
<property name="text"> | ||
<string>JEDEC binary extrapolated</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="4" column="0"> | ||
<widget class="QTextBrowser" name="tbScalePreview"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<widget class="QRadioButton" name="rbSiDecimal"> | ||
<property name="text"> | ||
<string>SI decimal</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="verticalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Vertical</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>20</width> | ||
<height>40</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
</layout> | ||
</widget> | ||
<tabstops> | ||
<tabstop>grpDataSize</tabstop> | ||
</tabstops> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.