PDF4QT/Pdf4QtViewerPlugins/DimensionsPlugin/settingsdialog.cpp

66 lines
2.2 KiB
C++
Raw Normal View History

2020-11-21 16:56:10 +01:00
// Copyright (C) 2020 Jakub Melka
//
2020-12-20 19:03:58 +01:00
// This file is part of Pdf4Qt.
2020-11-21 16:56:10 +01:00
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is free software: you can redistribute it and/or modify
2020-11-21 16:56:10 +01:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is distributed in the hope that it will be useful,
2020-11-21 16:56:10 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
2020-12-20 19:03:58 +01:00
// along with Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
2020-11-21 16:56:10 +01:00
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "pdfwidgetutils.h"
SettingsDialog::SettingsDialog(QWidget* parent, DimensionUnit& lengthUnit, DimensionUnit& areaUnit, DimensionUnit& angleUnit) :
QDialog(parent),
ui(new Ui::SettingsDialog),
m_lengthUnit(lengthUnit),
m_areaUnit(areaUnit),
m_angleUnit(angleUnit)
{
ui->setupUi(this);
m_lengthUnits = DimensionUnit::getLengthUnits();
m_areaUnits = DimensionUnit::getAreaUnits();
m_angleUnits = DimensionUnit::getAngleUnits();
initComboBox(m_lengthUnits, m_lengthUnit, ui->lengthsComboBox);
initComboBox(m_areaUnits, m_areaUnit, ui->areasComboBox);
initComboBox(m_angleUnits, m_angleUnit, ui->anglesComboBox);
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(320, 160)));
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::initComboBox(const DimensionUnits& units, const DimensionUnit& currentUnit, QComboBox* comboBox)
{
for (const DimensionUnit& unit : units)
{
comboBox->addItem(unit.symbol, unit.symbol);
}
comboBox->setCurrentIndex(comboBox->findText(currentUnit.symbol));
}
void SettingsDialog::accept()
{
m_lengthUnit = m_lengthUnits[ui->lengthsComboBox->currentIndex()];
m_areaUnit = m_areaUnits[ui->areasComboBox->currentIndex()];
m_angleUnit = m_angleUnits[ui->anglesComboBox->currentIndex()];
QDialog::accept();
}