File indexing completed on 2024-05-26 05:56:50

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2010, 2014 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "bytesperlinedialog.hpp"
0010 
0011 // KF
0012 #include <KLocalizedString>
0013 // Qt
0014 #include <QFormLayout>
0015 #include <QVBoxLayout>
0016 #include <QSpinBox>
0017 #include <QDialogButtonBox>
0018 // Std
0019 #include <limits>
0020 
0021 namespace Kasten {
0022 
0023 BytesPerLineDialog::BytesPerLineDialog(QWidget* parent)
0024     : QDialog(parent)
0025 {
0026     setAttribute(Qt::WA_DeleteOnClose, true);
0027 
0028     auto* pageLayout = new QFormLayout();
0029 
0030     mBytesPerLineEdit = new QSpinBox(this);
0031     mBytesPerLineEdit->setRange(1, std::numeric_limits<int>::max());
0032     const QString bytesPerLineLabel =
0033         i18nc("@label:spinbox number of bytes which are shown per line",
0034               "Bytes per Line:");
0035     pageLayout->addRow(bytesPerLineLabel, mBytesPerLineEdit);
0036 
0037     auto* dialogButtonBox = new QDialogButtonBox;
0038     dialogButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0039     connect(dialogButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0040     connect(dialogButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0041 
0042     auto* layout = new QVBoxLayout;
0043 
0044     layout->addLayout(pageLayout);
0045     layout->addWidget(dialogButtonBox);
0046     setLayout(layout);
0047 
0048     const QString caption =
0049         i18nc("@title:window", "Bytes per Line");
0050     setWindowTitle(caption);
0051 
0052     connect(this, &QDialog::finished, this, &BytesPerLineDialog::onFinished);
0053 }
0054 
0055 BytesPerLineDialog::~BytesPerLineDialog() = default;
0056 
0057 int BytesPerLineDialog::bytesPerLine()      const { return mBytesPerLineEdit->value(); }
0058 
0059 void BytesPerLineDialog::setBytesPerLine(int bytesPerLine)
0060 {
0061     mBytesPerLineEdit->setValue(bytesPerLine);
0062 }
0063 
0064 void BytesPerLineDialog::onFinished(int result)
0065 {
0066     if (result != QDialog::Accepted) {
0067         return;
0068     }
0069 
0070     Q_EMIT bytesPerLineAccepted(bytesPerLine());
0071 }
0072 
0073 }
0074 
0075 #include "moc_bytesperlinedialog.cpp"