File indexing completed on 2024-04-21 15:12:05

0001 /************************************************************************
0002  *                                  *
0003  *  This file is part of Kooka, a scanning/OCR application using    *
0004  *  Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>.  *
0005  *                                  *
0006  *  Copyright (C) 2008-2016 Jonathan Marten <jjm@keelhaul.me.uk>    *
0007  *                                  *
0008  *  Kooka is free software; you can redistribute it and/or modify it    *
0009  *  under the terms of the GNU Library General Public License as    *
0010  *  published by the Free Software Foundation and appearing in the  *
0011  *  file COPYING included in the packaging of this file;  either    *
0012  *  version 2 of the License, or (at your option) any later version.    *
0013  *                                  *
0014  *  As a special exception, permission is given to link this program    *
0015  *  with any version of the KADMOS OCR/ICR engine (a product of     *
0016  *  reRecognition GmbH, Kreuzlingen), and distribute the resulting  *
0017  *  executable without including the source code for KADMOS in the  *
0018  *  source distribution.                        *
0019  *                                  *
0020  *  This program is distributed in the hope that it will be useful, *
0021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of  *
0022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *
0023  *  GNU General Public License for more details.            *
0024  *                                  *
0025  *  You should have received a copy of the GNU General Public       *
0026  *  License along with this program;  see the file COPYING.  If     *
0027  *  not, see <http://www.gnu.org/licenses/>.                *
0028  *                                  *
0029  ************************************************************************/
0030 
0031 #include "newscanpresetdialog.h"
0032 
0033 #include <qlabel.h>
0034 #include <qlineedit.h>
0035 #include <qlayout.h>
0036 
0037 #include <klocalizedstring.h>
0038 
0039 
0040 NewScanPresetDialog::NewScanPresetDialog(const QString &name, const QString &desc, bool renaming, QWidget *pnt)
0041     : DialogBase(pnt)
0042 {
0043     setObjectName("NewScanPresetDialog");
0044 
0045     setButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
0046 
0047     QWidget *vb = new QWidget(this);
0048     QVBoxLayout *vbVBoxLayout = new QVBoxLayout(vb);
0049 
0050     QLabel *l;
0051     if (renaming)
0052     {
0053         setWindowTitle(i18n("Edit Scan Preset"));
0054         l = new QLabel(i18n("Change the name and/or description of the scan preset."), vb);
0055     }
0056     else
0057     {
0058         setWindowTitle(i18n("Save Scan Preset"));
0059         l = new QLabel(i18n("Enter a name and description for the new scan preset."), vb);
0060     }
0061     vbVBoxLayout->addWidget(l);
0062 
0063     l = new QLabel("", vb);
0064     vbVBoxLayout->addWidget(l);
0065 
0066     l = new QLabel(i18n("Preset name:"), vb);
0067     vbVBoxLayout->addWidget(l);
0068     mNameEdit = new QLineEdit(name, vb);
0069     vbVBoxLayout->addWidget(mNameEdit);
0070     connect(mNameEdit, &QLineEdit::textChanged, this, &NewScanPresetDialog::slotTextChanged);
0071     l->setBuddy(mNameEdit);
0072 
0073     l = new QLabel(i18n("Description:"), vb);
0074     vbVBoxLayout->addWidget(l);
0075     mDescEdit = new QLineEdit(desc, vb);
0076     vbVBoxLayout->addWidget(mDescEdit);
0077     connect(mDescEdit, &QLineEdit::textChanged, this, &NewScanPresetDialog::slotTextChanged);
0078     l->setBuddy(mDescEdit);
0079 
0080     setMainWidget(vb);
0081     slotTextChanged();
0082     mNameEdit->setFocus();
0083 }
0084 
0085 void NewScanPresetDialog::slotTextChanged()
0086 {
0087     setButtonEnabled(QDialogButtonBox::Ok, !mNameEdit->text().trimmed().isEmpty() &&
0088                                            !mDescEdit->text().trimmed().isEmpty());
0089 }
0090 
0091 QString NewScanPresetDialog::getName() const
0092 {
0093     return (mNameEdit->text());
0094 }
0095 
0096 QString NewScanPresetDialog::getDescription() const
0097 {
0098     return (mDescEdit->text());
0099 }