24#include <tqvgroupbox.h>
26#include <tqapplication.h>
30#include <tqbuttongroup.h>
31#include <tqradiobutton.h>
32#include <tqwhatsthis.h>
33#include <tqcheckbox.h>
41SelectionRange::SelectionRange(
const TQString &s)
44 TQValueVector<TQPair<uint, uint> > r;
45 TQStringList list = TQStringList::split(
',', s);
46 TQRegExp range(
"^([0-9]+)\\-([0-9]+)$");
47 TQRegExp one(
"^[0-9]+$");
48 for (TQStringList::iterator it = list.begin(); it!=list.end(); ++it) {
49 if ( one.exactMatch(*it) ) {
50 uint p = (*it).toUInt();
51 r.push_back( qMakePair(p, p) );
52 }
else if ( range.exactMatch(*it) ) {
53 uint p1 = range.cap(1).toUInt();
54 uint p2 = range.cap(2).toUInt();
55 if ( p1>p2 )
continue;
56 r.push_back( qMakePair(p1, p2) );
61 TQPair<uint, uint> tmp;
62 for (uint i=1; i<r.size(); i++)
63 if ( r[i].first<r[i-1].first )
67 for (uint i=0; i<r.size(); i++)
68 if ( i!=0 && r[i].first<=tmp.second )
69 tmp.second = kMax(tmp.second, r[i].second);
71 _ranges.push_back(r[i]);
73 kdDebug(30516) <<
"selection range: (" << tmp.first <<
","
74 << tmp.second <<
") " << endl;
78uint SelectionRange::nbPages()
const
81 for (uint i=0; i<_ranges.size(); i++)
82 nb += _ranges[i].second - _ranges[i].first + 1;
86SelectionRangeIterator::SelectionRangeIterator(
const SelectionRange &range)
87 : _ranges(range._ranges)
92int SelectionRangeIterator::toFirst()
94 if ( _ranges.size()==0 ) _current = -1;
97 _current = _ranges[0].first;
102int SelectionRangeIterator::next()
104 if ( _current==-1 )
return -1;
105 if ( _current==
int(_ranges[_index].second) ) {
107 _current = (_index==_ranges.size() ? -1
108 : int(_ranges[_index].first));
117Dialog::Dialog(uint nbPages,
bool isEncrypted, TQWidget *widget)
118 : KDialogBase(Plain, i18n(
"KWord's PDF Import Filter"), Ok|Cancel, Ok,
119 widget,
"pdf_import_dialog"), _nbPages(nbPages)
121 TQApplication::restoreOverrideCursor();
123 TQVBoxLayout *top =
new TQVBoxLayout(plainPage(), KDialogBase::marginHint(),
124 KDialogBase::spacingHint());
127 TQVGroupBox *gbox =
new TQVGroupBox(i18n(
"Page Selection"), plainPage());
128 gbox->setInsideSpacing(KDialogBase::spacingHint());
129 top->addWidget(gbox);
130 _group =
new TQButtonGroup;
131 _allButton =
new TQRadioButton(i18n(
"All (%1 pages)").arg(nbPages), gbox);
132 _allButton->setChecked(
true);
133 _group->insert(_allButton);
134 TQHBox *hbox =
new TQHBox(gbox);
135 _rangeButton =
new TQRadioButton(i18n(
"Range:"), hbox);
136 _group->insert(_rangeButton);
137 _range =
new KLineEdit(hbox);
139 connect(_range, TQ_SIGNAL(textChanged(
const TQString &)),
140 TQ_SLOT(rangeChanged(
const TQString &)));
143 _images =
new TQCheckBox(i18n(
"Import images"), plainPage());
144 _images->setChecked(
true);
145 top->addWidget(_images);
146 _smart =
new TQCheckBox(i18n(
"\"Smart\" mode"), plainPage());
147 _smart->setChecked(
true);
148 TQWhatsThis::add(_smart,
149 i18n(
"Removes returns and hyphens at end of line. "
150 "Also tries to compute the paragraph alignment. "
151 "Note that the layout of some pages can "
153 top->addWidget(_smart);
156 gbox =
new TQVGroupBox(i18n(
"Passwords"), plainPage());
157 top->addWidget(gbox);
158 TQGrid *grid =
new TQGrid(2, gbox);
159 grid->setSpacing(KDialogBase::spacingHint());
160 (void)
new TQLabel(i18n(
"Owner:"), grid);
161 _owner =
new KLineEdit(grid);
162 _owner->setEchoMode(TQLineEdit::Password);
163 (void)
new TQLabel(i18n(
"User:"), grid);
164 _user =
new KLineEdit(grid);
165 _user->setEchoMode(TQLineEdit::Password);
166 grid->setEnabled(isEncrypted);
172 TQApplication::setOverrideCursor(TQt::waitCursor);
175void Dialog::rangeChanged(
const TQString &)
177 _rangeButton->setChecked(
true);
180Options Dialog::options()
const
183 o.range = SelectionRange( (_allButton->isChecked() ?
184 TQString(
"1-%1").arg(_nbPages) : _range->text()) );
185 o.ownerPassword = _owner->text();
186 o.userPassword = _user->text();
187 o.importImages = _images->isChecked();
188 o.smart = _smart->isChecked();