File indexing completed on 2024-04-28 04:20:14
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #ifndef KP_DOCUMENT_SAVE_OPTIONS_H 0030 #define KP_DOCUMENT_SAVE_OPTIONS_H 0031 0032 0033 class QImage; 0034 class QString; 0035 0036 class KConfigGroup; 0037 0038 0039 class kpDocumentSaveOptions 0040 { 0041 public: 0042 kpDocumentSaveOptions (); 0043 kpDocumentSaveOptions (const kpDocumentSaveOptions &rhs); 0044 kpDocumentSaveOptions (const QString &mimeType, int colorDepth, bool dither, int quality); 0045 virtual ~kpDocumentSaveOptions (); 0046 0047 bool operator== (const kpDocumentSaveOptions &rhs) const; 0048 bool operator!= (const kpDocumentSaveOptions &rhs) const; 0049 0050 kpDocumentSaveOptions &operator= (const kpDocumentSaveOptions &rhs); 0051 0052 0053 void printDebug (const QString &prefix) const; 0054 0055 0056 QString mimeType () const; 0057 void setMimeType (const QString &mimeType); 0058 0059 static QString invalidMimeType (); 0060 static bool mimeTypeIsInvalid (const QString &mimeType); 0061 bool mimeTypeIsInvalid () const; 0062 0063 0064 int colorDepth () const; 0065 void setColorDepth (int depth); 0066 0067 static int invalidColorDepth (); 0068 static bool colorDepthIsInvalid (int colorDepth); 0069 bool colorDepthIsInvalid () const; 0070 0071 0072 bool dither () const; 0073 void setDither (bool dither); 0074 0075 static int initialDither (); 0076 0077 0078 int quality () const; 0079 void setQuality (int quality); 0080 0081 static int invalidQuality (); 0082 static bool qualityIsInvalid (int quality); 0083 bool qualityIsInvalid () const; 0084 0085 0086 // (All assume that <config>'s group has been set) 0087 // (None of them call KConfigBase::reparseConfig() nor KConfigBase::sync()) 0088 0089 static QString defaultMimeType (const KConfigGroup &config); 0090 static void saveDefaultMimeType (KConfigGroup &config, const QString &mimeType); 0091 0092 static int defaultColorDepth (const KConfigGroup &config); 0093 static void saveDefaultColorDepth (KConfigGroup &config, int colorDepth); 0094 0095 static int defaultDither (const KConfigGroup &config); 0096 static void saveDefaultDither (KConfigGroup &config, bool dither); 0097 0098 static int defaultQuality (const KConfigGroup &config); 0099 static void saveDefaultQuality (KConfigGroup &config, int quality); 0100 0101 0102 static kpDocumentSaveOptions defaultDocumentSaveOptions (const KConfigGroup &config); 0103 // (returns true if it encountered a difference (and saved it to <config>)) 0104 static bool saveDefaultDifferences (KConfigGroup &config, 0105 const kpDocumentSaveOptions &oldDocInfo, 0106 const kpDocumentSaveOptions &newDocInfo); 0107 0108 0109 public: 0110 // (purely for informational purposes - not enforced by this class) 0111 static int mimeTypeMaximumColorDepth (const QString &mimeType); 0112 int mimeTypeMaximumColorDepth () const; 0113 0114 0115 static bool mimeTypeHasConfigurableColorDepth (const QString &mimeType); 0116 bool mimeTypeHasConfigurableColorDepth () const; 0117 0118 static bool mimeTypeHasConfigurableQuality (const QString &mimeType); 0119 bool mimeTypeHasConfigurableQuality () const; 0120 0121 0122 // TODO: checking for mask loss due to format e.g. BMP 0123 enum LossyType 0124 { 0125 LossLess = 0, 0126 0127 // mimeTypeMaximumColorDepth() < <pixmap>.depth() 0128 MimeTypeMaximumColorDepthLow = 1, 0129 // i.e. colorDepth() < <pixmap>.depth() || 0130 // colorDepth() < 32 && <pixmap>.mask() 0131 ColorDepthLow = 2, 0132 // i.e. mimeTypeHasConfigurableQuality() 0133 Quality = 4 0134 }; 0135 0136 // Returns whether saving <image> with these options will result in 0137 // loss of information. Returned value is the bitwise OR of 0138 // LossType enum possiblities. 0139 int isLossyForSaving (const QImage &image) const; 0140 0141 0142 private: 0143 // There is no need to maintain binary compatibility at this stage. 0144 // The d-pointer is just so that you can experiment without recompiling 0145 // the kitchen sink. 0146 class kpDocumentSaveOptionsPrivate *d; 0147 }; 0148 0149 0150 #endif // KP_DOCUMENT_SAVE_OPTIONS_H