Rev 4430 | Rev 4631 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4430 | cbradney | 1 | /* |
2 | For general Scribus (>=1.3.2) copyright and licensing information please refer |
||
3 | to the COPYING file provided with the program. Following this notice may exist |
||
4 | a copyright and/or license notice that predates the release of Scribus 1.3.2 |
||
5 | for which a new license (GPL+exception) is in place. |
||
6 | */ |
||
3 | paul | 7 | /*************************************************************************** |
8 | customfdialog.cpp - description |
||
9 | ------------------- |
||
10 | begin : Fri Nov 30 2001 |
||
11 | copyright : (C) 2001 by Franz Schmid |
||
12 | email : Franz.Schmid@altmuehlnet.de |
||
13 | ***************************************************************************/ |
||
14 | |||
15 | /*************************************************************************** |
||
16 | * * |
||
17 | * This program is free software; you can redistribute it and/or modify * |
||
18 | * it under the terms of the GNU General Public License as published by * |
||
19 | * the Free Software Foundation; either version 2 of the License, or * |
||
20 | * (at your option) any later version. * |
||
21 | * * |
||
22 | ***************************************************************************/ |
||
23 | |||
24 | #include "customfdialog.h" |
||
25 | #include "customfdialog.moc" |
||
26 | #include <qpixmap.h> |
||
27 | #include <qpainter.h> |
||
28 | #include <qfileinfo.h> |
||
29 | #include <qdir.h> |
||
30 | #include <qdom.h> |
||
15 | Franz | 31 | #include <qtextcodec.h> |
3543 | avox | 32 | #include "sccombobox.h" |
1555 | fschmid | 33 | #include "scribusstructs.h" |
2004 | fschmid | 34 | #include "scimage.h" |
2534 | craig | 35 | #include <util.h> |
36 | |||
3 | paul | 37 | extern QString DocDir; |
38 | |||
39 | ImIconProvider::ImIconProvider(QWidget *pa) : QFileIconProvider(pa) |
||
40 | { |
||
161 | Franz | 41 | fmts.clear(); |
1820 | fschmid | 42 | QString tmp[] = {"eps", "gif", "png", "jpg", "jpeg", "xpm", "tif", "tiff", "bmp", "pbm", "pgm", "ppm", "xbm", "xpm", "psd"}; |
167 | Franz | 43 | size_t array = sizeof(tmp) / sizeof(*tmp); |
44 | for (uint a = 0; a < array; ++a) |
||
45 | fmts += tmp[a]; |
||
161 | Franz | 46 | imagepm = loadIcon("image.png"); |
47 | pspm = loadIcon("postscript.png"); |
||
48 | txtpm = loadIcon("txt.png"); |
||
49 | docpm = loadIcon("doc.png"); |
||
50 | pdfpm = loadIcon("pdf.png"); |
||
867 | fschmid | 51 | oosxdpm = loadIcon("ooo_draw.png"); |
52 | oosxwpm = loadIcon("ooo_writer.png"); |
||
53 | vectorpm = loadIcon("vectorgfx.png"); |
||
3 | paul | 54 | } |
55 | |||
56 | const QPixmap * ImIconProvider::pixmap(const QFileInfo &fi) |
||
57 | { |
||
58 | QString ext = fi.extension(false).lower(); |
||
59 | if (fmts.contains(ext)) |
||
60 | return &imagepm; |
||
61 | else |
||
161 | Franz | 62 | { |
867 | fschmid | 63 | ext = fi.extension(true).lower(); |
64 | if (ext.endsWith("ps")) |
||
3 | paul | 65 | return &pspm; |
867 | fschmid | 66 | if (ext.endsWith("txt")) |
3 | paul | 67 | return &txtpm; |
867 | fschmid | 68 | if (ext.endsWith("scd") || ext.endsWith("scd.gz")) |
3 | paul | 69 | return &docpm; |
867 | fschmid | 70 | if (ext.endsWith("sla") || ext.endsWith("sla.gz")) |
3 | paul | 71 | return &docpm; |
867 | fschmid | 72 | if (ext.endsWith("pdf")) |
3 | paul | 73 | return &pdfpm; |
867 | fschmid | 74 | if (ext.endsWith("sxd")) |
75 | return &oosxdpm; |
||
76 | if (ext.endsWith("sxw")) |
||
77 | return &oosxwpm; |
||
78 | if (ext.endsWith("svg") || ext.endsWith("svgz")) |
||
79 | return &vectorpm; |
||
3 | paul | 80 | return QFileIconProvider::pixmap(fi); |
161 | Franz | 81 | } |
3 | paul | 82 | } |
83 | |||
84 | FDialogPreview::FDialogPreview(QWidget *pa) : QLabel(pa) |
||
85 | { |
||
86 | setAlignment(AlignLeft | AlignTop); |
||
87 | setMinimumSize( QSize( 100, 100 ) ); |
||
867 | fschmid | 88 | setMaximumSize( QSize( 300, 300 ) ); |
3 | paul | 89 | setScaledContents( false ); |
90 | setEraseColor( white ); |
||
91 | setFrameShape( QLabel::WinPanel ); |
||
92 | setFrameShadow( QLabel::Sunken ); |
||
311 | Franz | 93 | updtPix(); |
3 | paul | 94 | } |
95 | |||
311 | Franz | 96 | void FDialogPreview::updtPix() |
97 | { |
||
98 | QPixmap pm; |
||
99 | QRect inside = contentsRect(); |
||
100 | pm = QPixmap(inside.width(), inside.height()); |
||
101 | pm.fill(white); |
||
102 | setPixmap(pm); |
||
103 | } |
||
104 | |||
3 | paul | 105 | void FDialogPreview::GenPreview(QString name) |
106 | { |
||
107 | QPixmap pm; |
||
108 | QString Buffer = ""; |
||
109 | QFileInfo fi = QFileInfo(name); |
||
110 | if (fi.isDir()) |
||
111 | return; |
||
311 | Franz | 112 | updtPix(); |
113 | int w = pixmap()->width(); |
||
114 | int h = pixmap()->height(); |
||
1505 | fschmid | 115 | bool mode = false; |
1915 | fschmid | 116 | QString ext = fi.extension(false).lower(); |
117 | QStringList formats; |
||
118 | formats = QStringList::fromStrList(QImageIO::inputFormats()); |
||
119 | formats.append("jpg"); |
||
120 | #ifdef HAVE_TIFF |
||
121 | formats.append("tif"); |
||
122 | formats.append("tiff"); |
||
123 | #endif |
||
124 | formats.append("psd"); |
||
125 | formats.append("eps"); |
||
126 | formats.append("pdf"); |
||
127 | formats.append("ps"); |
||
128 | QString allFormats = formats.join( " " ); |
||
129 | formats.clear(); |
||
130 | allFormats = allFormats.lower(); |
||
131 | formats = QStringList::split( " ", allFormats ); |
||
132 | if (formats.contains(ext)) |
||
161 | Franz | 133 | { |
2004 | fschmid | 134 | ScImage im; |
3685 | fschmid | 135 | if (im.LoadPicture(name, "", 0, false, false, 4, 72, &mode)) |
161 | Franz | 136 | { |
3703 | fschmid | 137 | int ix,iy; |
138 | if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull())) |
||
139 | { |
||
3706 | fschmid | 140 | ix = im.imgInfo.exifInfo.width; |
141 | iy = im.imgInfo.exifInfo.height; |
||
3703 | fschmid | 142 | } |
143 | else |
||
144 | { |
||
145 | ix = im.width(); |
||
146 | iy = im.height(); |
||
147 | } |
||
2004 | fschmid | 148 | int xres = im.imgInfo.xres; |
149 | int yres = im.imgInfo.yres; |
||
1915 | fschmid | 150 | QString tmp = ""; |
151 | QString tmp2 = ""; |
||
2004 | fschmid | 152 | QImage im2; |
3703 | fschmid | 153 | if ((ix > w-5) || (iy > h-44)) |
1798 | fschmid | 154 | { |
1915 | fschmid | 155 | double sx = im.width() / static_cast<double>(w-5); |
156 | double sy = im.height() / static_cast<double>(h-44); |
||
157 | im2 = sy < sx ? im.smoothScale(qRound(im.width() / sx), qRound(im.height() / sx)) : |
||
3703 | fschmid | 158 | im.smoothScale(qRound(im.width() / sy), qRound(im.height() / sy)); |
1798 | fschmid | 159 | } |
2004 | fschmid | 160 | else |
161 | im2 = im.copy(); |
||
1915 | fschmid | 162 | QPainter p; |
163 | pixmap()->fill(white); |
||
164 | p.begin(pixmap()); |
||
2004 | fschmid | 165 | p.drawImage(0, 0, im2); |
1915 | fschmid | 166 | p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy)); |
167 | p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI")); |
||
168 | QString cSpace; |
||
169 | if ((ext == "pdf") || (ext == "eps") || (ext == "ps")) |
||
170 | cSpace = tr("Unknown"); |
||
171 | else |
||
172 | { |
||
2004 | fschmid | 173 | switch (im.imgInfo.colorspace) |
1915 | fschmid | 174 | { |
175 | case 0: |
||
176 | cSpace = tr("RGB"); |
||
177 | break; |
||
178 | case 1: |
||
179 | cSpace = tr("CMYK"); |
||
180 | break; |
||
181 | case 2: |
||
182 | cSpace = tr("Grayscale"); |
||
183 | break; |
||
184 | } |
||
185 | } |
||
186 | p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace); |
||
187 | p.end(); |
||
188 | repaint(); |
||
1798 | fschmid | 189 | } |
161 | Franz | 190 | } |
3 | paul | 191 | else |
161 | Franz | 192 | { |
193 | if (loadText(name, &Buffer)) |
||
3 | paul | 194 | { |
161 | Franz | 195 | if (Buffer.startsWith("<SCRIBUS")) |
3 | paul | 196 | { |
197 | QDomDocument docu("scridoc"); |
||
198 | if(!docu.setContent(Buffer)) |
||
199 | return; |
||
200 | QDomElement elem=docu.documentElement(); |
||
1915 | fschmid | 201 | if ((elem.tagName() != "SCRIBUS") && (elem.tagName() != "SCRIBUSUTF8") && (elem.tagName() != "SCRIBUSUTF8NEW")) |
3 | paul | 202 | return; |
203 | QDomNode DOC=elem.firstChild(); |
||
204 | QDomElement dc=DOC.toElement(); |
||
205 | QString Tit = tr("Title:")+" "; |
||
206 | QString ti2 = dc.attribute("TITLE"); |
||
2877 | cbradney | 207 | if (ti2.isEmpty()) |
3 | paul | 208 | ti2= tr("No Title"); |
209 | Tit += ti2+"\n"; |
||
210 | QString Aut = tr("Author:")+" "; |
||
211 | QString au2 = dc.attribute("AUTHOR"); |
||
2877 | cbradney | 212 | if (au2.isEmpty()) |
3 | paul | 213 | au2 = tr("Unknown"); |
214 | Aut += au2; |
||
340 | Franz | 215 | setText( tr("Scribus Document")+"\n\n"+Tit+Aut); |
161 | Franz | 216 | } |
1915 | fschmid | 217 | else if ((ext == "txt") || (ext == "html") || (ext == "xml")) |
3 | paul | 218 | setText(Buffer.left(200)); |
219 | } |
||
161 | Franz | 220 | } |
4182 | subik | 221 | } |
3 | paul | 222 | |
223 | void FDialogPreview::previewUrl( const QUrl &url ) |
||
224 | { |
||
225 | if (url.isLocalFile()) |
||
226 | GenPreview(url.path()); |
||
227 | } |
||
228 | |||
4182 | subik | 229 | CustomFDialog::CustomFDialog(QWidget *parent, QString wDir, QString caption, |
230 | QString filter, bool preview, |
||
231 | bool existing, bool compress, |
||
232 | bool codec, bool dirOnly) |
||
233 | : QFileDialog(QString::null, filter, parent, 0, true) |
||
3 | paul | 234 | { |
83 | Franz | 235 | setIcon(loadIcon("AppIcon.png")); |
4182 | subik | 236 | setCaption(caption); |
415 | Franz | 237 | cDir = QDir(wDir); |
3 | paul | 238 | setDir(cDir); |
239 | setIconProvider(new ImIconProvider(this)); |
||
311 | Franz | 240 | FDialogPreview *pw; |
310 | Franz | 241 | if (dirOnly) |
161 | Franz | 242 | { |
3 | paul | 243 | Layout = new QFrame(this); |
244 | Layout1 = new QHBoxLayout(Layout); |
||
310 | Franz | 245 | Layout1->setSpacing( 0 ); |
3 | paul | 246 | Layout1->setMargin( 0 ); |
2397 | cbradney | 247 | SaveZip = new QCheckBox( tr( "&Compress File" ), Layout, "test"); |
310 | Franz | 248 | Layout1->addWidget(SaveZip, Qt::AlignLeft); |
3 | paul | 249 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
310 | Franz | 250 | Layout1->addItem( spacer ); |
251 | addWidgets(0, Layout, 0); |
||
252 | LayoutC = new QFrame(this); |
||
253 | Layout1C = new QHBoxLayout(LayoutC); |
||
254 | Layout1C->setSpacing( 0 ); |
||
255 | Layout1C->setMargin( 0 ); |
||
2397 | cbradney | 256 | WFonts = new QCheckBox( tr( "&Include Fonts" ), LayoutC, "test"); |
310 | Franz | 257 | Layout1C->addWidget(WFonts, Qt::AlignLeft); |
258 | QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
259 | Layout1C->addItem( spacer2 ); |
||
260 | addWidgets(0, LayoutC, 0); |
||
261 | setMode(QFileDialog::DirectoryOnly); |
||
161 | Franz | 262 | } |
3 | paul | 263 | else |
161 | Franz | 264 | { |
310 | Franz | 265 | setContentsPreviewEnabled( true ); |
311 | Franz | 266 | pw = new FDialogPreview( this ); |
310 | Franz | 267 | setContentsPreview( pw, pw ); |
4182 | subik | 268 | if (compress) |
161 | Franz | 269 | { |
310 | Franz | 270 | Layout = new QFrame(this); |
271 | Layout1 = new QHBoxLayout(Layout); |
||
272 | Layout1->setSpacing( 6 ); |
||
273 | Layout1->setMargin( 0 ); |
||
2397 | cbradney | 274 | SaveZip = new QCheckBox( tr( "&Compress File" ), Layout, "test"); |
310 | Franz | 275 | Layout1->addWidget(SaveZip); |
276 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
277 | Layout1->addItem( spacer ); |
||
278 | } |
||
4182 | subik | 279 | if (existing) |
310 | Franz | 280 | setMode(QFileDialog::ExistingFile); |
281 | else |
||
282 | { |
||
283 | setMode(QFileDialog::AnyFile); |
||
4182 | subik | 284 | if (compress) |
310 | Franz | 285 | addWidgets(0, Layout, 0); |
286 | } |
||
4182 | subik | 287 | if (codec) |
310 | Franz | 288 | { |
289 | LayoutC = new QFrame(this); |
||
290 | Layout1C = new QHBoxLayout(LayoutC); |
||
291 | Layout1C->setSpacing( 0 ); |
||
292 | Layout1C->setMargin( 4 ); |
||
293 | TxCodeT = new QLabel(this); |
||
294 | TxCodeT->setText( tr("Encoding:")); |
||
3543 | avox | 295 | TxCodeM = new ScComboBox(true, LayoutC, "Cod"); |
310 | Franz | 296 | TxCodeM->setEditable(false); |
4182 | subik | 297 | QString tmp_txc[] = {"ISO 8859-1", "ISO 8859-2", "ISO 8859-3", |
298 | "ISO 8859-4", "ISO 8859-5", "ISO 8859-6", |
||
299 | "ISO 8859-7", "ISO 8859-8", "ISO 8859-9", |
||
300 | "ISO 8859-10", "ISO 8859-13", "ISO 8859-14", |
||
301 | "ISO 8859-15", "utf8", "KOI8-R", "KOI8-U", |
||
302 | "CP1250", "CP1251", "CP1252", "CP1253", |
||
303 | "CP1254", "CP1255", "CP1256", "CP1257", |
||
304 | "Apple Roman"}; |
||
310 | Franz | 305 | size_t array = sizeof(tmp_txc) / sizeof(*tmp_txc); |
306 | for (uint a = 0; a < array; ++a) |
||
307 | TxCodeM->insertItem(tmp_txc[a]); |
||
308 | QString localEn = QTextCodec::codecForLocale()->name(); |
||
309 | bool hasIt = false; |
||
310 | for (int cc = 0; cc < TxCodeM->count(); ++cc) |
||
15 | Franz | 311 | { |
310 | Franz | 312 | if (TxCodeM->text(cc) == localEn) |
313 | { |
||
314 | TxCodeM->setCurrentItem(cc); |
||
315 | hasIt = true; |
||
316 | break; |
||
317 | } |
||
15 | Franz | 318 | } |
310 | Franz | 319 | if (!hasIt) |
320 | { |
||
321 | TxCodeM->insertItem(localEn); |
||
322 | TxCodeM->setCurrentItem(TxCodeM->count()-1); |
||
323 | } |
||
324 | TxCodeM->setMinimumSize(QSize(200, 0)); |
||
325 | Layout1C->addWidget(TxCodeM); |
||
326 | QSpacerItem* spacer2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); |
||
327 | Layout1C->addItem( spacer2 ); |
||
328 | addWidgets(TxCodeT, LayoutC, 0); |
||
161 | Franz | 329 | } |
4182 | subik | 330 | setPreviewMode(preview ? QFileDialog::Contents : QFileDialog::NoPreview ); |
310 | Franz | 331 | setViewMode( QFileDialog::List ); |
4182 | subik | 332 | if (compress) |
333 | connect(SaveZip, SIGNAL(clicked()), this, SLOT(handleCompress())); |
||
161 | Franz | 334 | } |
3 | paul | 335 | HomeB = new QToolButton(this); |
336 | HomeB->setIconSet(loadIcon("gohome.png")); |
||
4499 | cbradney | 337 | HomeB->setAutoRaise(true); |
112 | Franz | 338 | HomeB->setTextLabel( tr("Moves to your Document Directory.\nThis can be set in the Preferences.")); |
3 | paul | 339 | connect(HomeB, SIGNAL(clicked()), this, SLOT(slotHome())); |
340 | addToolButton(HomeB); |
||
4182 | subik | 341 | // default init |
342 | extZip = "gz"; |
||
3 | paul | 343 | } |
344 | |||
345 | CustomFDialog::~CustomFDialog() |
||
346 | { |
||
347 | setIconProvider(0); |
||
348 | cDir.setCurrent(dir()->path()); |
||
349 | } |
||
350 | |||
351 | void CustomFDialog::slotHome() |
||
352 | { |
||
353 | setDir(QDir(DocDir)); |
||
354 | } |
||
355 | |||
4182 | subik | 356 | void CustomFDialog::handleCompress() |
3 | paul | 357 | { |
4182 | subik | 358 | QFileInfo tmp; |
359 | tmp.setFile(selectedFile()); |
||
360 | QString e(tmp.extension()); |
||
361 | |||
3 | paul | 362 | if (SaveZip->isChecked()) |
161 | Franz | 363 | { |
4182 | subik | 364 | if (e != extZip) |
365 | tmp.setFile(tmp.baseName() + "." + extZip); |
||
161 | Franz | 366 | } |
3 | paul | 367 | else |
161 | Franz | 368 | { |
4182 | subik | 369 | if (e != ext) |
370 | tmp.setFile(tmp.baseName() + "." + ext); |
||
161 | Franz | 371 | } |
4182 | subik | 372 | setSelection(tmp.fileName()); |
3 | paul | 373 | } |
4182 | subik | 374 | |
375 | void CustomFDialog::setExtension(QString e) |
||
376 | { |
||
377 | ext = e; |
||
378 | } |
||
379 | |||
380 | QString CustomFDialog::extension() |
||
381 | { |
||
382 | return ext; |
||
383 | } |
||
384 | |||
385 | void CustomFDialog::setZipExtension(QString e) |
||
386 | { |
||
387 | extZip = e; |
||
388 | } |
||
389 | |||
390 | QString CustomFDialog::zipExtension() |
||
391 | { |
||
392 | return extZip; |
||
393 | } |