35
35
#include <klocale.h>
36
36
#include <knuminput.h>
40
#include "ui_rangemodifierdialogwidget.h"
41
45
RangeDialog::RangeDialog(ParseObject* parent)
42
: ParseObjectDialog(parent),
43
startInput(0), stopInput(0), toTheEndCheckBox(0)
46
: ParseObjectDialog(parent), ui(new Ui::RangeModifierDialogWidget())
45
const int minRange = 1;
46
const int maxRange = 999999;
48
startInput = new KIntNumInput(this);
49
startInput->setMinimum(minRange);
50
startInput->setMaximum(maxRange);
51
startInput->setLabel(i18nc("Beginning of the text range", "From:"));
53
stopInput = new KIntNumInput(this);
54
stopInput->setMinimum(minRange);
55
stopInput->setMaximum(maxRange);
56
stopInput->setLabel(i18nc("end of the text range", "To:"));
58
toTheEndCheckBox = new QCheckBox(i18nc("range is specified until the end of the string", "to the end"));
59
toTheEndCheckBox->setChecked(true);
48
QWidget* mainWidget = new QWidget(this);
49
ui->setupUi(mainWidget);
50
setSettingsWidget(mainWidget);
51
ui->startInput->setFocus();
60
53
slotToTheEndChecked(true);
62
// --------------------------------------------------------
64
QWidget* mainWidget = new QWidget(this);
65
QGridLayout* mainLayout = new QGridLayout(this);
66
mainLayout->addWidget(startInput, 0, 0);
67
mainLayout->addWidget(toTheEndCheckBox, 1, 0);
68
mainLayout->addWidget(stopInput, 2, 0);
69
mainLayout->setSpacing(KDialog::spacingHint());
70
mainLayout->setMargin(KDialog::spacingHint());
71
mainLayout->setRowStretch(3, 10);
72
mainWidget->setLayout(mainLayout);
74
setSettingsWidget(mainWidget);
76
// --------------------------------------------------------
78
startInput->setFocus();
80
connect(toTheEndCheckBox, SIGNAL(toggled(bool)),
55
connect(ui->toTheEndCheckBox, SIGNAL(toggled(bool)),
81
56
this, SLOT(slotToTheEndChecked(bool)));
84
59
RangeDialog::~RangeDialog()
88
64
void RangeDialog::slotToTheEndChecked(bool checked)
90
stopInput->setEnabled(!checked);
66
ui->stopInput->setEnabled(!checked);
93
69
// --------------------------------------------------------
96
72
: Modifier(i18n("Range..."), i18n("Add only a specific range of a renaming option"),
97
73
SmallIcon("measure"))
99
addToken("{|from| - |to|}", i18n("Extract a specific range (if omitted, '|to|' = end of string)"));
75
addToken("{||from|| - ||to||}", i18n("Extract a specific range (if omitted, '||to||' = end of string)"));
101
77
QRegExp reg("\\{(\\d+)(-((-1|\\d+))?)?\\}");
102
78
reg.setMinimal(true);
112
88
QPointer<RangeDialog> dlg = new RangeDialog(this);
113
89
if (dlg->exec() == KDialog::Accepted)
115
int start = dlg->startInput->value();
116
int stop = dlg->stopInput->value();
91
int start = dlg->ui->startInput->value();
92
int stop = dlg->ui->stopInput->value();
118
if (dlg->toTheEndCheckBox->isChecked())
94
if (dlg->ui->toTheEndCheckBox->isChecked())
120
96
result = QString("{%1-}").arg(QString::number(start));
124
100
result = QString("{%1-%2}").arg(QString::number(start))
125
.arg(QString::number(stop));
101
.arg(QString::number(stop));