QPlatformDialogHelper: change ButtonRole flags to ensure 32-bit size
[qt:qtbase.git] / src / gui / kernel / qplatformdialoghelper.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qplatformdialoghelper.h"
43
44 #include <QtCore/QVariant>
45 #include <QtCore/QSharedData>
46 #include <QtCore/QSettings>
47 #include <QtCore/QHash>
48 #include <QtCore/QUrl>
49 #include <QtGui/QColor>
50
51 #include <algorithm>
52
53 QT_BEGIN_NAMESPACE
54
55 /*!
56     \class QPlatformDialogHelper
57     \since 5.0
58     \internal
59     \ingroup qpa
60
61     \brief The QPlatformDialogHelper class allows for platform-specific customization of dialogs.
62
63 */
64
65 static const int buttonRoleLayouts[2][5][14] =
66 {
67     // Qt::Horizontal
68     {
69         // WinLayout
70         { QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::AcceptRole,
71           QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::NoRole,
72           QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::ApplyRole,
73           QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
74
75         // MacLayout
76         { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole,
77           QPlatformDialogHelper::Stretch, QPlatformDialogHelper::DestructiveRole | QPlatformDialogHelper::Reverse,
78           QPlatformDialogHelper::AlternateRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::RejectRole | QPlatformDialogHelper::Reverse,
79           QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse,
80           QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
81
82         // KdeLayout
83         { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::YesRole,
84           QPlatformDialogHelper::NoRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole,
85           QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::EOL },
86
87         // GnomeLayout
88         { QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ActionRole,
89           QPlatformDialogHelper::ApplyRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::DestructiveRole | QPlatformDialogHelper::Reverse,
90           QPlatformDialogHelper::AlternateRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::RejectRole | QPlatformDialogHelper::Reverse,
91           QPlatformDialogHelper::AcceptRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::NoRole | QPlatformDialogHelper::Reverse,
92           QPlatformDialogHelper::YesRole | QPlatformDialogHelper::Reverse, QPlatformDialogHelper::EOL },
93
94         // MacModelessLayout
95         { QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch,
96           QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
97           QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
98     },
99
100     // Qt::Vertical
101     {
102         // WinLayout
103         { QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole,
104           QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole,
105           QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
106
107         // MacLayout
108         { QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole,
109           QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole,
110           QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
111
112         // KdeLayout
113         { QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole,
114           QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::Stretch, QPlatformDialogHelper::ResetRole,
115           QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::RejectRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL },
116
117         // GnomeLayout
118         { QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole, QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole,
119           QPlatformDialogHelper::AlternateRole, QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::Stretch,
120           QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL },
121
122         // MacModelessLayout
123         { QPlatformDialogHelper::ActionRole, QPlatformDialogHelper::ApplyRole, QPlatformDialogHelper::ResetRole, QPlatformDialogHelper::Stretch,
124           QPlatformDialogHelper::HelpRole, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL,
125           QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL, QPlatformDialogHelper::EOL }
126     }
127 };
128
129 QPlatformDialogHelper::QPlatformDialogHelper()
130 {
131 }
132
133 QPlatformDialogHelper::~QPlatformDialogHelper()
134 {
135 }
136
137 QVariant QPlatformDialogHelper::styleHint(StyleHint hint) const
138 {
139     return QPlatformDialogHelper::defaultStyleHint(hint);
140 }
141
142 QVariant  QPlatformDialogHelper::defaultStyleHint(QPlatformDialogHelper::StyleHint hint)
143 {
144     Q_UNUSED(hint);
145     return QVariant();
146 }
147
148 // Font dialog
149
150 class QFontDialogOptionsPrivate : public QSharedData
151 {
152 public:
153     QFontDialogOptionsPrivate() : options(0) {}
154
155     QFontDialogOptions::FontDialogOptions options;
156     QString windowTitle;
157 };
158
159 QFontDialogOptions::QFontDialogOptions() : d(new QFontDialogOptionsPrivate)
160 {
161 }
162
163 QFontDialogOptions::QFontDialogOptions(const QFontDialogOptions &rhs) : d(rhs.d)
164 {
165 }
166
167 QFontDialogOptions &QFontDialogOptions::operator=(const QFontDialogOptions &rhs)
168 {
169     if (this != &rhs)
170         d = rhs.d;
171     return *this;
172 }
173
174 QFontDialogOptions::~QFontDialogOptions()
175 {
176 }
177
178 QString QFontDialogOptions::windowTitle() const
179 {
180     return d->windowTitle;
181 }
182
183 void QFontDialogOptions::setWindowTitle(const QString &title)
184 {
185     d->windowTitle = title;
186 }
187
188 void QFontDialogOptions::setOption(QFontDialogOptions::FontDialogOption option, bool on)
189 {
190     if (!(d->options & option) != !on)
191         setOptions(d->options ^ option);
192 }
193
194 bool QFontDialogOptions::testOption(QFontDialogOptions::FontDialogOption option) const
195 {
196     return d->options & option;
197 }
198
199 void QFontDialogOptions::setOptions(FontDialogOptions options)
200 {
201     if (options != d->options)
202         d->options = options;
203 }
204
205 QFontDialogOptions::FontDialogOptions QFontDialogOptions::options() const
206 {
207     return d->options;
208 }
209
210 /*!
211     \class QPlatformFontDialogHelper
212     \since 5.0
213     \internal
214     \ingroup qpa
215
216     \brief The QPlatformFontDialogHelper class allows for platform-specific customization of font dialogs.
217
218 */
219 const QSharedPointer<QFontDialogOptions> &QPlatformFontDialogHelper::options() const
220 {
221     return m_options;
222 }
223
224 void QPlatformFontDialogHelper::setOptions(const QSharedPointer<QFontDialogOptions> &options)
225 {
226     m_options = options;
227 }
228
229 // Color dialog
230
231 class QColorDialogStaticData
232 {
233 public:
234     enum { CustomColorCount = 16, StandardColorCount = 6 * 8 };
235
236     QColorDialogStaticData();
237     inline void readSettings();
238     inline void writeSettings() const;
239
240     QRgb customRgb[CustomColorCount];
241     QRgb standardRgb[StandardColorCount];
242     bool customSet;
243 };
244
245 QColorDialogStaticData::QColorDialogStaticData() : customSet(false)
246 {
247     int i = 0;
248     for (int g = 0; g < 4; ++g)
249         for (int r = 0;  r < 4; ++r)
250             for (int b = 0; b < 3; ++b)
251                 standardRgb[i++] = qRgb(r * 255 / 3, g * 255 / 3, b * 255 / 2);
252     std::fill(customRgb, customRgb + CustomColorCount, 0xffffffff);
253     readSettings();
254 }
255
256 void QColorDialogStaticData::readSettings()
257 {
258 #ifndef QT_NO_SETTINGS
259     const QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
260     for (int i = 0; i < int(CustomColorCount); ++i) {
261         const QVariant v = settings.value(QStringLiteral("Qt/customColors/") + QString::number(i));
262         if (v.isValid())
263             customRgb[i] = v.toUInt();
264     }
265 #endif
266 }
267
268 void QColorDialogStaticData::writeSettings() const
269 {
270 #ifndef QT_NO_SETTINGS
271     if (!customSet) {
272         QSettings settings(QSettings::UserScope, QStringLiteral("QtProject"));
273         for (int i = 0; i < int(CustomColorCount); ++i)
274             settings.setValue(QStringLiteral("Qt/customColors/") + QString::number(i), customRgb[i]);
275     }
276 #endif
277 }
278
279 Q_GLOBAL_STATIC(QColorDialogStaticData, qColorDialogStaticData)
280
281 class QColorDialogOptionsPrivate : public QSharedData
282 {
283 public:
284     QColorDialogOptionsPrivate() : options(0) {}
285     // Write out settings around destruction of dialogs
286     ~QColorDialogOptionsPrivate() { qColorDialogStaticData()->writeSettings(); }
287
288     QColorDialogOptions::ColorDialogOptions options;
289     QString windowTitle;
290 };
291
292 QColorDialogOptions::QColorDialogOptions() : d(new QColorDialogOptionsPrivate)
293 {
294 }
295
296 QColorDialogOptions::QColorDialogOptions(const QColorDialogOptions &rhs) : d(rhs.d)
297 {
298 }
299
300 QColorDialogOptions &QColorDialogOptions::operator=(const QColorDialogOptions &rhs)
301 {
302     if (this != &rhs)
303         d = rhs.d;
304     return *this;
305 }
306
307 QColorDialogOptions::~QColorDialogOptions()
308 {
309 }
310
311 QString QColorDialogOptions::windowTitle() const
312 {
313     return d->windowTitle;
314 }
315
316 void QColorDialogOptions::setWindowTitle(const QString &title)
317 {
318     d->windowTitle = title;
319 }
320
321 void QColorDialogOptions::setOption(QColorDialogOptions::ColorDialogOption option, bool on)
322 {
323     if (!(d->options & option) != !on)
324         setOptions(d->options ^ option);
325 }
326
327 bool QColorDialogOptions::testOption(QColorDialogOptions::ColorDialogOption option) const
328 {
329     return d->options & option;
330 }
331
332 void QColorDialogOptions::setOptions(ColorDialogOptions options)
333 {
334     if (options != d->options)
335         d->options = options;
336 }
337
338 QColorDialogOptions::ColorDialogOptions QColorDialogOptions::options() const
339 {
340     return d->options;
341 }
342
343 int QColorDialogOptions::customColorCount()
344 {
345     return QColorDialogStaticData::CustomColorCount;
346 }
347
348 QRgb QColorDialogOptions::customColor(int index)
349 {
350     if (uint(index) >= uint(QColorDialogStaticData::CustomColorCount))
351         return qRgb(255, 255, 255);
352     return qColorDialogStaticData()->customRgb[index];
353 }
354
355 QRgb *QColorDialogOptions::customColors()
356 {
357     return qColorDialogStaticData()->customRgb;
358 }
359
360 void QColorDialogOptions::setCustomColor(int index, QRgb color)
361 {
362     if (uint(index) >= uint(QColorDialogStaticData::CustomColorCount))
363         return;
364     qColorDialogStaticData()->customSet = true;
365     qColorDialogStaticData()->customRgb[index] = color;
366 }
367
368 QRgb *QColorDialogOptions::standardColors()
369 {
370     return qColorDialogStaticData()->standardRgb;
371 }
372
373 QRgb QColorDialogOptions::standardColor(int index)
374 {
375     if (uint(index) >= uint(QColorDialogStaticData::StandardColorCount))
376         return qRgb(255, 255, 255);
377     return qColorDialogStaticData()->standardRgb[index];
378 }
379
380 void QColorDialogOptions::setStandardColor(int index, QRgb color)
381 {
382     if (uint(index) >= uint(QColorDialogStaticData::StandardColorCount))
383         return;
384     qColorDialogStaticData()->standardRgb[index] = color;
385 }
386
387 /*!
388     \class QPlatformColorDialogHelper
389     \since 5.0
390     \internal
391     \ingroup qpa
392
393     \brief The QPlatformColorDialogHelper class allows for platform-specific customization of color dialogs.
394
395 */
396 const QSharedPointer<QColorDialogOptions> &QPlatformColorDialogHelper::options() const
397 {
398     return m_options;
399 }
400
401 void QPlatformColorDialogHelper::setOptions(const QSharedPointer<QColorDialogOptions> &options)
402 {
403     m_options = options;
404 }
405
406 // File dialog
407
408 class QFileDialogOptionsPrivate : public QSharedData
409 {
410 public:
411     QFileDialogOptionsPrivate() : options(0),
412         viewMode(QFileDialogOptions::Detail),
413         fileMode(QFileDialogOptions::AnyFile),
414         acceptMode(QFileDialogOptions::AcceptOpen),
415         filters(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs)
416     {}
417
418     QFileDialogOptions::FileDialogOptions options;
419     QString windowTitle;
420
421     QFileDialogOptions::ViewMode viewMode;
422     QFileDialogOptions::FileMode fileMode;
423     QFileDialogOptions::AcceptMode acceptMode;
424     QString labels[QFileDialogOptions::DialogLabelCount];
425     QDir::Filters filters;
426     QList<QUrl> sidebarUrls;
427     QStringList nameFilters;
428     QStringList mimeTypeFilters;
429     QString defaultSuffix;
430     QStringList history;
431     QUrl initialDirectory;
432     QString initiallySelectedNameFilter;
433     QList<QUrl> initiallySelectedFiles;
434 };
435
436 QFileDialogOptions::QFileDialogOptions() : d(new QFileDialogOptionsPrivate)
437 {
438 }
439
440 QFileDialogOptions::QFileDialogOptions(const QFileDialogOptions &rhs) : d(rhs.d)
441 {
442 }
443
444 QFileDialogOptions &QFileDialogOptions::operator=(const QFileDialogOptions &rhs)
445 {
446     if (this != &rhs)
447         d = rhs.d;
448     return *this;
449 }
450
451 QFileDialogOptions::~QFileDialogOptions()
452 {
453 }
454
455 QString QFileDialogOptions::windowTitle() const
456 {
457     return d->windowTitle;
458 }
459
460 void QFileDialogOptions::setWindowTitle(const QString &title)
461 {
462     d->windowTitle = title;
463 }
464
465 void QFileDialogOptions::setOption(QFileDialogOptions::FileDialogOption option, bool on)
466 {
467     if (!(d->options & option) != !on)
468         setOptions(d->options ^ option);
469 }
470
471 bool QFileDialogOptions::testOption(QFileDialogOptions::FileDialogOption option) const
472 {
473     return d->options & option;
474 }
475
476 void QFileDialogOptions::setOptions(FileDialogOptions options)
477 {
478     if (options != d->options)
479         d->options = options;
480 }
481
482 QFileDialogOptions::FileDialogOptions QFileDialogOptions::options() const
483 {
484     return d->options;
485 }
486
487 QDir::Filters QFileDialogOptions::filter() const
488 {
489     return d->filters;
490 }
491
492 void QFileDialogOptions::setFilter(QDir::Filters filters)
493 {
494     d->filters  = filters;
495 }
496
497 void QFileDialogOptions::setViewMode(QFileDialogOptions::ViewMode mode)
498 {
499     d->viewMode = mode;
500 }
501
502 QFileDialogOptions::ViewMode QFileDialogOptions::viewMode() const
503 {
504     return d->viewMode;
505 }
506
507 void QFileDialogOptions::setFileMode(QFileDialogOptions::FileMode mode)
508 {
509     d->fileMode = mode;
510 }
511
512 QFileDialogOptions::FileMode QFileDialogOptions::fileMode() const
513 {
514     return d->fileMode;
515 }
516
517 void QFileDialogOptions::setAcceptMode(QFileDialogOptions::AcceptMode mode)
518 {
519     d->acceptMode = mode;
520 }
521
522 QFileDialogOptions::AcceptMode QFileDialogOptions::acceptMode() const
523 {
524     return d->acceptMode;
525 }
526
527 void QFileDialogOptions::setSidebarUrls(const QList<QUrl> &urls)
528 {
529     d->sidebarUrls = urls;
530 }
531
532 QList<QUrl> QFileDialogOptions::sidebarUrls() const
533 {
534     return d->sidebarUrls;
535 }
536
537 void QFileDialogOptions::setNameFilters(const QStringList &filters)
538 {
539     d->nameFilters = filters;
540 }
541
542 QStringList QFileDialogOptions::nameFilters() const
543 {
544     return d->nameFilters;
545 }
546
547 void QFileDialogOptions::setMimeTypeFilters(const QStringList &filters)
548 {
549     d->mimeTypeFilters = filters;
550 }
551
552 QStringList QFileDialogOptions::mimeTypeFilters() const
553 {
554     return d->mimeTypeFilters;
555 }
556
557 void QFileDialogOptions::setDefaultSuffix(const QString &suffix)
558 {
559     d->defaultSuffix = suffix;
560     if (d->defaultSuffix.size() > 1 && d->defaultSuffix.startsWith(QLatin1Char('.')))
561         d->defaultSuffix.remove(0, 1); // Silently change ".txt" -> "txt".
562 }
563
564 QString QFileDialogOptions::defaultSuffix() const
565 {
566     return d->defaultSuffix;
567 }
568
569 void QFileDialogOptions::setHistory(const QStringList &paths)
570 {
571     d->history = paths;
572 }
573
574 QStringList QFileDialogOptions::history() const
575 {
576     return d->history;
577 }
578
579 void QFileDialogOptions::setLabelText(QFileDialogOptions::DialogLabel label, const QString &text)
580 {
581     if (label >= 0 && label < DialogLabelCount)
582         d->labels[label] = text;
583 }
584
585 QString QFileDialogOptions::labelText(QFileDialogOptions::DialogLabel label) const
586 {
587     return (label >= 0 && label < DialogLabelCount) ? d->labels[label] : QString();
588 }
589
590 bool QFileDialogOptions::isLabelExplicitlySet(DialogLabel label)
591 {
592     return label >= 0 && label < DialogLabelCount && !d->labels[label].isEmpty();
593 }
594
595 QUrl QFileDialogOptions::initialDirectory() const
596 {
597     return d->initialDirectory;
598 }
599
600 void QFileDialogOptions::setInitialDirectory(const QUrl &directory)
601 {
602     d->initialDirectory = directory;
603 }
604
605 QString QFileDialogOptions::initiallySelectedNameFilter() const
606 {
607     return d->initiallySelectedNameFilter;
608 }
609
610 void QFileDialogOptions::setInitiallySelectedNameFilter(const QString &filter)
611 {
612     d->initiallySelectedNameFilter = filter;
613 }
614
615 QList<QUrl> QFileDialogOptions::initiallySelectedFiles() const
616 {
617     return d->initiallySelectedFiles;
618 }
619
620 void QFileDialogOptions::setInitiallySelectedFiles(const QList<QUrl> &files)
621 {
622     d->initiallySelectedFiles = files;
623 }
624
625 bool QPlatformFileDialogHelper::isSupportedUrl(const QUrl &url) const
626 {
627     return url.isLocalFile();
628 }
629
630 /*!
631     \class QPlatformFileDialogHelper
632     \since 5.0
633     \internal
634     \ingroup qpa
635
636     \brief The QPlatformFileDialogHelper class allows for platform-specific customization of file dialogs.
637
638 */
639 const QSharedPointer<QFileDialogOptions> &QPlatformFileDialogHelper::options() const
640 {
641     return m_options;
642 }
643
644 void QPlatformFileDialogHelper::setOptions(const QSharedPointer<QFileDialogOptions> &options)
645 {
646     m_options = options;
647 }
648
649 const char *QPlatformFileDialogHelper::filterRegExp =
650 "^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
651
652 // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
653 QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter)
654 {
655     QRegExp regexp(QString::fromLatin1(filterRegExp));
656     QString f = filter;
657     int i = regexp.indexIn(f);
658     if (i >= 0)
659         f = regexp.cap(2);
660     return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
661 }
662
663 // Message dialog
664
665 class QMessageDialogOptionsPrivate : public QSharedData
666 {
667 public:
668     QMessageDialogOptionsPrivate() :
669         icon(QMessageDialogOptions::NoIcon),
670         buttons(QPlatformDialogHelper::Ok)
671     {}
672
673     QString windowTitle;
674     QMessageDialogOptions::Icon icon;
675     QString text;
676     QString informativeText;
677     QString detailedText;
678     QPlatformDialogHelper::StandardButtons buttons;
679 };
680
681 QMessageDialogOptions::QMessageDialogOptions() : d(new QMessageDialogOptionsPrivate)
682 {
683 }
684
685 QMessageDialogOptions::QMessageDialogOptions(const QMessageDialogOptions &rhs) : d(rhs.d)
686 {
687 }
688
689 QMessageDialogOptions &QMessageDialogOptions::operator=(const QMessageDialogOptions &rhs)
690 {
691     if (this != &rhs)
692         d = rhs.d;
693     return *this;
694 }
695
696 QMessageDialogOptions::~QMessageDialogOptions()
697 {
698 }
699
700 QString QMessageDialogOptions::windowTitle() const
701 {
702     return d->windowTitle;
703 }
704
705 void QMessageDialogOptions::setWindowTitle(const QString &title)
706 {
707     d->windowTitle = title;
708 }
709
710 QMessageDialogOptions::Icon QMessageDialogOptions::icon() const
711 {
712     return d->icon;
713 }
714
715 void QMessageDialogOptions::setIcon(Icon icon)
716 {
717     d->icon = icon;
718 }
719
720 QString QMessageDialogOptions::text() const
721 {
722     return d->text;
723 }
724
725 void QMessageDialogOptions::setText(const QString &text)
726 {
727     d->text = text;
728 }
729
730 QString QMessageDialogOptions::informativeText() const
731 {
732     return d->informativeText;
733 }
734
735 void QMessageDialogOptions::setInformativeText(const QString &informativeText)
736 {
737     d->informativeText = informativeText;
738 }
739
740 QString QMessageDialogOptions::detailedText() const
741 {
742     return d->detailedText;
743 }
744
745 void QMessageDialogOptions::setDetailedText(const QString &detailedText)
746 {
747     d->detailedText = detailedText;
748 }
749
750 void QMessageDialogOptions::setStandardButtons(QPlatformDialogHelper::StandardButtons buttons)
751 {
752     d->buttons = buttons;
753 }
754
755 QPlatformDialogHelper::StandardButtons QMessageDialogOptions::standardButtons() const
756 {
757     return d->buttons;
758 }
759
760 QPlatformDialogHelper::ButtonRole QPlatformDialogHelper::buttonRole(QPlatformDialogHelper::StandardButton button)
761 {
762     switch (button) {
763     case Ok:
764     case Save:
765     case Open:
766     case SaveAll:
767     case Retry:
768     case Ignore:
769         return AcceptRole;
770
771     case Cancel:
772     case Close:
773     case Abort:
774         return RejectRole;
775
776     case Discard:
777         return DestructiveRole;
778
779     case Help:
780         return HelpRole;
781
782     case Apply:
783         return ApplyRole;
784
785     case Yes:
786     case YesToAll:
787         return YesRole;
788
789     case No:
790     case NoToAll:
791         return NoRole;
792
793     case RestoreDefaults:
794     case Reset:
795         return ResetRole;
796
797     default:
798         break;
799     }
800     return InvalidRole;
801 }
802
803 const int *QPlatformDialogHelper::buttonLayout(Qt::Orientation orientation, ButtonLayout policy)
804 {
805     if (policy == UnknownLayout) {
806 #if defined (Q_OS_OSX)
807         policy = MacLayout;
808 #elif defined (Q_OS_LINUX) || defined (Q_OS_UNIX)
809         policy = KdeLayout;
810 #else
811         policy = WinLayout;
812 #endif
813     }
814     return buttonRoleLayouts[orientation == Qt::Vertical][policy];
815 }
816
817 /*!
818     \class QPlatformMessageDialogHelper
819     \since 5.0
820     \internal
821     \ingroup qpa
822
823     \brief The QPlatformMessageDialogHelper class allows for platform-specific customization of Message dialogs.
824
825 */
826 const QSharedPointer<QMessageDialogOptions> &QPlatformMessageDialogHelper::options() const
827 {
828     return m_options;
829 }
830
831 void QPlatformMessageDialogHelper::setOptions(const QSharedPointer<QMessageDialogOptions> &options)
832 {
833     m_options = options;
834 }
835
836 QT_END_NAMESPACE