filters
dialog.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "dialog.h"
00021 #include "dialog.moc"
00022
00023 #include <qhbox.h>
00024 #include <qvgroupbox.h>
00025 #include <qregexp.h>
00026 #include <qapplication.h>
00027 #include <qgrid.h>
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 #include <qbuttongroup.h>
00031 #include <qradiobutton.h>
00032 #include <qwhatsthis.h>
00033 #include <qcheckbox.h>
00034
00035 #include <klocale.h>
00036 #include <kdebug.h>
00037 #include <klineedit.h>
00038
00039
00040
00041 SelectionRange::SelectionRange(const QString &s)
00042 {
00043
00044 QValueVector<QPair<uint, uint> > r;
00045 QStringList list = QStringList::split(',', s);
00046 QRegExp range("^([0-9]+)\\-([0-9]+)$");
00047 QRegExp one("^[0-9]+$");
00048 for (QStringList::iterator it = list.begin(); it!=list.end(); ++it) {
00049 if ( one.exactMatch(*it) ) {
00050 uint p = (*it).toUInt();
00051 r.push_back( qMakePair(p, p) );
00052 } else if ( range.exactMatch(*it) ) {
00053 uint p1 = range.cap(1).toUInt();
00054 uint p2 = range.cap(2).toUInt();
00055 if ( p1>p2 ) continue;
00056 r.push_back( qMakePair(p1, p2) );
00057 }
00058 }
00059
00060
00061 QPair<uint, uint> tmp;
00062 for (uint i=1; i<r.size(); i++)
00063 if ( r[i].first<r[i-1].first )
00064 qSwap(r[i-1], r[i]);
00065
00066
00067 for (uint i=0; i<r.size(); i++)
00068 if ( i!=0 && r[i].first<=tmp.second )
00069 tmp.second = kMax(tmp.second, r[i].second);
00070 else {
00071 _ranges.push_back(r[i]);
00072 tmp = r[i];
00073 kdDebug(30516) << "selection range: (" << tmp.first << ","
00074 << tmp.second << ") " << endl;
00075 }
00076 }
00077
00078 uint SelectionRange::nbPages() const
00079 {
00080 uint nb = 0;
00081 for (uint i=0; i<_ranges.size(); i++)
00082 nb += _ranges[i].second - _ranges[i].first + 1;
00083 return nb;
00084 }
00085
00086 SelectionRangeIterator::SelectionRangeIterator(const SelectionRange &range)
00087 : _ranges(range._ranges)
00088 {
00089 toFirst();
00090 }
00091
00092 int SelectionRangeIterator::toFirst()
00093 {
00094 if ( _ranges.size()==0 ) _current = -1;
00095 else {
00096 _index = 0;
00097 _current = _ranges[0].first;
00098 }
00099 return _current;
00100 }
00101
00102 int SelectionRangeIterator::next()
00103 {
00104 if ( _current==-1 ) return -1;
00105 if ( _current==int(_ranges[_index].second) ) {
00106 _index++;
00107 _current = (_index==_ranges.size() ? -1
00108 : int(_ranges[_index].first));
00109 } else _current++;
00110 return _current;
00111 }
00112
00113
00114 namespace PDFImport
00115 {
00116
00117 Dialog::Dialog(uint nbPages, bool isEncrypted, QWidget *widget)
00118 : KDialogBase(Plain, i18n("KWord's PDF Import Filter"), Ok|Cancel, Ok,
00119 widget, "pdf_import_dialog"), _nbPages(nbPages)
00120 {
00121 QApplication::restoreOverrideCursor();
00122
00123 QVBoxLayout *top = new QVBoxLayout(plainPage(), KDialogBase::marginHint(),
00124 KDialogBase::spacingHint());
00125
00126
00127 QVGroupBox *gbox = new QVGroupBox(i18n("Page Selection"), plainPage());
00128 gbox->setInsideSpacing(KDialogBase::spacingHint());
00129 top->addWidget(gbox);
00130 _group = new QButtonGroup;
00131 _allButton = new QRadioButton(i18n("All (%1 pages)").arg(nbPages), gbox);
00132 _allButton->setChecked(true);
00133 _group->insert(_allButton);
00134 QHBox *hbox = new QHBox(gbox);
00135 _rangeButton = new QRadioButton(i18n("Range:"), hbox);
00136 _group->insert(_rangeButton);
00137 _range = new KLineEdit(hbox);
00138 _range->setFocus();
00139 connect(_range, SIGNAL(textChanged(const QString &)),
00140 SLOT(rangeChanged(const QString &)));
00141
00142
00143 _images = new QCheckBox(i18n("Import images"), plainPage());
00144 _images->setChecked(true);
00145 top->addWidget(_images);
00146 _smart = new QCheckBox(i18n("\"Smart\" mode"), plainPage());
00147 _smart->setChecked(true);
00148 QWhatsThis::add(_smart,
00149 i18n("Removes returns and hyphens at end of line. "
00150 "Also tries to compute the paragraph alignment. "
00151 "Note that the layout of some pages can "
00152 "get messed up."));
00153 top->addWidget(_smart);
00154
00155
00156 gbox = new QVGroupBox(i18n("Passwords"), plainPage());
00157 top->addWidget(gbox);
00158 QGrid *grid = new QGrid(2, gbox);
00159 grid->setSpacing(KDialogBase::spacingHint());
00160 (void)new QLabel(i18n("Owner:"), grid);
00161 _owner = new KLineEdit(grid);
00162 _owner->setEchoMode(QLineEdit::Password);
00163 (void)new QLabel(i18n("User:"), grid);
00164 _user = new KLineEdit(grid);
00165 _user->setEchoMode(QLineEdit::Password);
00166 grid->setEnabled(isEncrypted);
00167 }
00168
00169 Dialog::~Dialog()
00170 {
00171 delete _group;
00172 QApplication::setOverrideCursor(Qt::waitCursor);
00173 }
00174
00175 void Dialog::rangeChanged(const QString &)
00176 {
00177 _rangeButton->setChecked(true);
00178 }
00179
00180 Options Dialog::options() const
00181 {
00182 Options o;
00183 o.range = SelectionRange( (_allButton->isChecked() ?
00184 QString("1-%1").arg(_nbPages) : _range->text()) );
00185 o.ownerPassword = _owner->text();
00186 o.userPassword = _user->text();
00187 o.importImages = _images->isChecked();
00188 o.smart = _smart->isChecked();
00189 return o;
00190 }
00191
00192 }
|