diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-07-02 06:40:27 +0000 |
commit | 2595a15ebeb6fc46b7cb241d01ec0c2460ec2111 (patch) | |
tree | 18a8f0f4ac5a86dacfa74c3537551ec39bc85e75 /src/imagefactory.cpp | |
parent | 1d90725a4001fab9d3922b2cbcceeee5e2d1686f (diff) | |
download | tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.tar.gz tellico-2595a15ebeb6fc46b7cb241d01ec0c2460ec2111.zip |
TQt4 port tellico
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1239054 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/imagefactory.cpp')
-rw-r--r-- | src/imagefactory.cpp | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/src/imagefactory.cpp b/src/imagefactory.cpp index 00a980a..fe9fc6e 100644 --- a/src/imagefactory.cpp +++ b/src/imagefactory.cpp @@ -24,8 +24,8 @@ #include <kapplication.h> #include <kimageeffect.h> -#include <qfile.h> -#include <qdir.h> +#include <tqfile.h> +#include <tqdir.h> #define RELEASE_IMAGES @@ -34,18 +34,18 @@ using Tellico::ImageFactory; bool ImageFactory::s_needInit = true; const Tellico::Data::Image ImageFactory::s_null; -QDict<Tellico::Data::Image> ImageFactory::s_imageDict; +TQDict<Tellico::Data::Image> ImageFactory::s_imageDict; // since most images get turned into pixmaps quickly, use 10 megs // for images and 10 megs for pixmaps -QCache<Tellico::Data::Image> ImageFactory::s_imageCache(10 * 1024 * 1024); -QCache<QPixmap> ImageFactory::s_pixmapCache(10 * 1024 * 1024); +TQCache<Tellico::Data::Image> ImageFactory::s_imageCache(10 * 1024 * 1024); +TQCache<TQPixmap> ImageFactory::s_pixmapCache(10 * 1024 * 1024); // this image info map is just for big images that don't fit // in the cache, so that don't have to be continually reloaded to get info -QMap<QString, Tellico::Data::ImageInfo> ImageFactory::s_imageInfoMap; +TQMap<TQString, Tellico::Data::ImageInfo> ImageFactory::s_imageInfoMap; Tellico::StringSet ImageFactory::s_imagesInTmpDir; Tellico::StringSet ImageFactory::s_imagesToRelease; KTempDir* ImageFactory::s_tmpDir = 0; -QString ImageFactory::s_localDir; +TQString ImageFactory::s_localDir; void ImageFactory::init() { if(!s_needInit) { @@ -58,7 +58,7 @@ void ImageFactory::init() { s_needInit = false; } -QString ImageFactory::tempDir() { +TQString ImageFactory::tempDir() { if(!s_tmpDir) { s_tmpDir = new KTempDir(); s_tmpDir->setAutoDelete(true); @@ -66,19 +66,19 @@ QString ImageFactory::tempDir() { return s_tmpDir->name(); } -QString ImageFactory::dataDir() { - static const QString dataDir = Tellico::saveLocation(QString::fromLatin1("data/")); +TQString ImageFactory::dataDir() { + static const TQString dataDir = Tellico::saveLocation(TQString::tqfromLatin1("data/")); return dataDir; } -QString ImageFactory::localDir() { +TQString ImageFactory::localDir() { if(s_localDir.isEmpty()) { return dataDir(); } return s_localDir; } -QString ImageFactory::addImage(const KURL& url_, bool quiet_, const KURL& refer_, bool link_) { +TQString ImageFactory::addImage(const KURL& url_, bool quiet_, const KURL& refer_, bool link_) { return addImageImpl(url_, quiet_, refer_, link_).id(); } @@ -120,15 +120,15 @@ const Tellico::Data::Image& ImageFactory::addImageImpl(const KURL& url_, bool qu return *img; } -QString ImageFactory::addImage(const QImage& image_, const QString& format_) { +TQString ImageFactory::addImage(const TQImage& image_, const TQString& format_) { return addImageImpl(image_, format_).id(); } -QString ImageFactory::addImage(const QPixmap& pix_, const QString& format_) { +TQString ImageFactory::addImage(const TQPixmap& pix_, const TQString& format_) { return addImageImpl(pix_.convertToImage(), format_).id(); } -const Tellico::Data::Image& ImageFactory::addImageImpl(const QImage& image_, const QString& format_) { +const Tellico::Data::Image& ImageFactory::addImageImpl(const TQImage& image_, const TQString& format_) { Data::Image* img = new Data::Image(image_, format_); if(hasImage(img->id())) { const Data::Image& img2 = imageById(img->id()); @@ -146,37 +146,37 @@ const Tellico::Data::Image& ImageFactory::addImageImpl(const QImage& image_, con return *img; } -QString ImageFactory::addImage(const QByteArray& data_, const QString& format_, const QString& id_) { +TQString ImageFactory::addImage(const TQByteArray& data_, const TQString& format_, const TQString& id_) { return addImageImpl(data_, format_, id_).id(); } -const Tellico::Data::Image& ImageFactory::addImageImpl(const QByteArray& data_, const QString& format_, - const QString& id_) { +const Tellico::Data::Image& ImageFactory::addImageImpl(const TQByteArray& data_, const TQString& format_, + const TQString& id_) { if(id_.isEmpty()) { return s_null; } // do not call imageById(), it causes infinite looping with Document::loadImage() - Data::Image* img = s_imageCache.find(id_); + Data::Image* img = s_imageCache.tqfind(id_); if(img) { - myLog() << "ImageFactory::addImageImpl(QByteArray) - already exists in cache: " << id_ << endl; + myLog() << "ImageFactory::addImageImpl(TQByteArray) - already exists in cache: " << id_ << endl; return *img; } - img = s_imageDict.find(id_); + img = s_imageDict.tqfind(id_); if(img) { - myLog() << "ImageFactory::addImageImpl(QByteArray) - already exists in dict: " << id_ << endl; + myLog() << "ImageFactory::addImageImpl(TQByteArray) - already exists in dict: " << id_ << endl; return *img; } img = new Data::Image(data_, format_, id_); if(img->isNull()) { - myDebug() << "ImageFactory::addImageImpl(QByteArray) - NULL IMAGE!!!!!" << endl; + myDebug() << "ImageFactory::addImageImpl(TQByteArray) - NULL IMAGE!!!!!" << endl; delete img; return s_null; } -// myLog() << "ImageFactory::addImageImpl(QByteArray) - " << data_.size() +// myLog() << "ImageFactory::addImageImpl(TQByteArray) - " << data_.size() // << " bytes, format = " << format_ // << ", id = "<< img->id() << endl; @@ -185,7 +185,7 @@ const Tellico::Data::Image& ImageFactory::addImageImpl(const QByteArray& data_, return *img; } -const Tellico::Data::Image& ImageFactory::addCachedImageImpl(const QString& id_, CacheDir dir_) { +const Tellico::Data::Image& ImageFactory::addCachedImageImpl(const TQString& id_, CacheDir dir_) { // myLog() << "ImageFactory::addCachedImageImpl() - dir = " << (dir_ == DataDir ? "DataDir" : "TmpDir" ) // << "; id = " << id_ << endl; KURL u; @@ -197,7 +197,7 @@ const Tellico::Data::Image& ImageFactory::addCachedImageImpl(const QString& id_, u.setPath(tempDir() + id_); } - QString newID = addImage(u, true); + TQString newID = addImage(u, true); if(newID.isEmpty()) { myLog() << "ImageFactory::addCachedImageImpl() - null image loaded" << endl; return s_null; @@ -237,7 +237,7 @@ const Tellico::Data::Image& ImageFactory::addCachedImageImpl(const QString& id_, return *img; } -bool ImageFactory::writeImage(const QString& id_, const KURL& targetDir_, bool force_) { +bool ImageFactory::writeImage(const TQString& id_, const KURL& targetDir_, bool force_) { // myLog() << "ImageFactory::writeImage() - target = " << targetDir_.url() << id_ << endl; if(targetDir_.isEmpty()) { myDebug() << "ImageFactory::writeImage() - empty target dir!" << endl; @@ -261,25 +261,25 @@ bool ImageFactory::writeImage(const QString& id_, const KURL& targetDir_, bool f return FileHandler::writeDataURL(target, img.byteArray(), force_); } -bool ImageFactory::writeCachedImage(const QString& id_, CacheDir dir_, bool force_ /*=false*/) { +bool ImageFactory::writeCachedImage(const TQString& id_, CacheDir dir_, bool force_ /*=false*/) { if(id_.isEmpty()) { return false; } // myLog() << "ImageFactory::writeCachedImage() - dir = " << (dir_ == DataDir ? "DataDir" : "TmpDir" ) // << "; id = " << id_ << endl; - QString path = ( dir_ == DataDir ? dataDir() : dir_ == TempDir ? tempDir() : localDir() ); + TQString path = ( dir_ == DataDir ? dataDir() : dir_ == TempDir ? tempDir() : localDir() ); // images in the temp directory are erased every session, so we can track // whether they've already been written with a simple string set. // images in the data directory are persistent, so we have to check the // actual file existence - bool exists = ( dir_ == TempDir ? s_imagesInTmpDir.has(id_) : QFile::exists(path + id_)); + bool exists = ( dir_ == TempDir ? s_imagesInTmpDir.has(id_) : TQFile::exists(path + id_)); if(!force_ && exists) { // myDebug() << "...writeCachedImage() - exists = true: " << id_ << endl; } else if(!force_ && !exists && dir_ == LocalDir) { - QDir dir(localDir()); + TQDir dir(localDir()); if(!dir.exists()) { myDebug() << "ImageFactory::writeCachedImage() - creating " << s_localDir << endl; dir.mkdir(localDir()); @@ -314,7 +314,7 @@ bool ImageFactory::writeCachedImage(const QString& id_, CacheDir dir_, bool forc return success; } -const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { +const Tellico::Data::Image& ImageFactory::imageById(const TQString& id_) { if(id_.isEmpty()) { myDebug() << "ImageFactory::imageById() - empty id" << endl; return s_null; @@ -328,13 +328,13 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { // first check the cache, used for images that are in the data file, or are only temporary // then the dict, used for images downloaded, but not yet saved anywhere - Data::Image* img = s_imageCache.find(id_); + Data::Image* img = s_imageCache.tqfind(id_); if(img) { // myLog() << "...imageById() - found in cache" << endl; return *img; } - img = s_imageDict.find(id_); + img = s_imageDict.tqfind(id_); if(img) { // myLog() << "...imageById() - found in dict" << endl; return *img; @@ -345,7 +345,7 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { // also, the image info cache might not have it so check if the // id is a valid absolute url // yeah, it's probably slow - if((s_imageInfoMap.contains(id_) && s_imageInfoMap[id_].linkOnly) || !KURL::isRelativeURL(id_)) { + if((s_imageInfoMap.tqcontains(id_) && s_imageInfoMap[id_].linkOnly) || !KURL::isRelativeURL(id_)) { KURL u = id_; if(u.isValid()) { return addImageImpl(u, false, KURL(), true); @@ -369,9 +369,9 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { // try to do a delayed loading of the image if(Data::Document::self()->loadImage(id_)) { // loadImage() could insert in either the cache or the dict! - img = s_imageCache.find(id_); + img = s_imageCache.tqfind(id_); if(!img) { - img = s_imageDict.find(id_); + img = s_imageDict.tqfind(id_); } if(img) { // myLog() << "...imageById() - found in doc" << endl; @@ -388,7 +388,7 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { // don't check Config::writeImagesInFile(), someday we might have problems // and the image will exist in the data dir, but the app thinks everything should // be in the zip file instead - bool exists = QFile::exists(dataDir() + id_); + bool exists = TQFile::exists(dataDir() + id_); if(exists) { // if we're loading from the application data dir, but images are being saved in the // data file instead, then consider the document to be modified since it needs @@ -408,7 +408,7 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { if(localDir() == dataDir()) { return s_null; } - exists = QFile::exists(localDir() + id_); + exists = TQFile::exists(localDir() + id_); if(exists) { // if we're loading from the application data dir, but images are being saved in the // data file instead, then consider the document to be modified since it needs @@ -428,8 +428,8 @@ const Tellico::Data::Image& ImageFactory::imageById(const QString& id_) { return s_null; } -Tellico::Data::ImageInfo ImageFactory::imageInfo(const QString& id_) { - if(s_imageInfoMap.contains(id_)) { +Tellico::Data::ImageInfo ImageFactory::imageInfo(const TQString& id_) { + if(s_imageInfoMap.tqcontains(id_)) { return s_imageInfoMap[id_]; } @@ -444,31 +444,31 @@ void ImageFactory::cacheImageInfo(const Data::ImageInfo& info) { s_imageInfoMap.insert(info.id, info); } -bool ImageFactory::validImage(const QString& id_) { +bool ImageFactory::validImage(const TQString& id_) { // don't try s_imageInfoMap[id_] cause it inserts an empty image info - return s_imageInfoMap.contains(id_) || hasImage(id_) || !imageById(id_).isNull(); + return s_imageInfoMap.tqcontains(id_) || hasImage(id_) || !imageById(id_).isNull(); } -QPixmap ImageFactory::pixmap(const QString& id_, int width_, int height_) { +TQPixmap ImageFactory::pixmap(const TQString& id_, int width_, int height_) { if(id_.isEmpty()) { - return QPixmap(); + return TQPixmap(); } - const QString key = id_ + '|' + QString::number(width_) + '|' + QString::number(height_); - QPixmap* pix = s_pixmapCache.find(key); + const TQString key = id_ + '|' + TQString::number(width_) + '|' + TQString::number(height_); + TQPixmap* pix = s_pixmapCache.tqfind(key); if(pix) { return *pix; } const Data::Image& img = imageById(id_); if(img.isNull()) { - return QPixmap(); + return TQPixmap(); } if(width_ > 0 && height_ > 0) { - pix = new QPixmap(img.convertToPixmap(width_, height_)); + pix = new TQPixmap(img.convertToPixmap(width_, height_)); } else { - pix = new QPixmap(img.convertToPixmap()); + pix = new TQPixmap(img.convertToPixmap()); } // pixmap size is w x h x d, divided by 8 bits @@ -476,7 +476,7 @@ QPixmap ImageFactory::pixmap(const QString& id_, int width_, int height_) { kdWarning() << "ImageFactory::pixmap() - can't save in cache: " << id_ << endl; kdWarning() << "### Current pixmap size is " << (pix->width()*pix->height()*pix->depth()/8) << endl; kdWarning() << "### Max pixmap cache size is " << s_pixmapCache.maxCost() << endl; - QPixmap pix2(*pix); + TQPixmap pix2(*pix); delete pix; return pix2; } @@ -500,35 +500,35 @@ void ImageFactory::clean(bool deleteTempDirectory_) { void ImageFactory::createStyleImages(const StyleOptions& opt_) { const int collType = Kernel::self()->collectionType(); - const QColor& baseColor = opt_.baseColor.isValid() + const TQColor& baseColor = opt_.baseColor.isValid() ? opt_.baseColor : Config::templateBaseColor(collType); - const QColor& highColor = opt_.highlightedBaseColor.isValid() + const TQColor& highColor = opt_.highlightedBaseColor.isValid() ? opt_.highlightedBaseColor : Config::templateHighlightedBaseColor(collType); - const QColor& bgc1 = Tellico::blendColors(baseColor, highColor, 30); - const QColor& bgc2 = Tellico::blendColors(baseColor, highColor, 50); + const TQColor& bgc1 = Tellico::blendColors(baseColor, highColor, 30); + const TQColor& bgc2 = Tellico::blendColors(baseColor, highColor, 50); - const QString bgname = QString::fromLatin1("gradient_bg.png"); - QImage bgImage = KImageEffect::gradient(QSize(400, 1), bgc1, baseColor, + const TQString bgname = TQString::tqfromLatin1("gradient_bg.png"); + TQImage bgImage = KImageEffect::gradient(TQSize(400, 1), bgc1, baseColor, KImageEffect::PipeCrossGradient); bgImage = KImageEffect::rotate(bgImage, KImageEffect::Rotate90); - const QString hdrname = QString::fromLatin1("gradient_header.png"); - QImage hdrImage = KImageEffect::unbalancedGradient(QSize(1, 10), highColor, bgc2, + const TQString hdrname = TQString::tqfromLatin1("gradient_header.png"); + TQImage hdrImage = KImageEffect::unbalancedGradient(TQSize(1, 10), highColor, bgc2, KImageEffect::VerticalGradient, 100, -100); if(opt_.imgDir.isEmpty()) { // write the style images both to the tmp dir and the data dir // doesn't really hurt and lets the user switch back and forth ImageFactory::removeImage(bgname, true /*delete */); - ImageFactory::addImageImpl(Data::Image::byteArray(bgImage, "PNG"), QString::fromLatin1("PNG"), bgname); + ImageFactory::addImageImpl(Data::Image::byteArray(bgImage, "PNG"), TQString::tqfromLatin1("PNG"), bgname); ImageFactory::writeCachedImage(bgname, DataDir, true /*force*/); ImageFactory::writeCachedImage(bgname, TempDir, true /*force*/); ImageFactory::removeImage(hdrname, true /*delete */); - ImageFactory::addImageImpl(Data::Image::byteArray(hdrImage, "PNG"), QString::fromLatin1("PNG"), hdrname); + ImageFactory::addImageImpl(Data::Image::byteArray(hdrImage, "PNG"), TQString::tqfromLatin1("PNG"), hdrname); ImageFactory::writeCachedImage(hdrname, DataDir, true /*force*/); ImageFactory::writeCachedImage(hdrname, TempDir, true /*force*/); } else { @@ -537,7 +537,7 @@ void ImageFactory::createStyleImages(const StyleOptions& opt_) { } } -void ImageFactory::removeImage(const QString& id_, bool deleteImage_) { +void ImageFactory::removeImage(const TQString& id_, bool deleteImage_) { //be careful using this s_imageDict.remove(id_); s_imageCache.remove(id_); @@ -545,23 +545,23 @@ void ImageFactory::removeImage(const QString& id_, bool deleteImage_) { if(deleteImage_) { // remove from both data dir and temp dir - QFile::remove(dataDir() + id_); - QFile::remove(tempDir() + id_); + TQFile::remove(dataDir() + id_); + TQFile::remove(tempDir() + id_); } } Tellico::StringSet ImageFactory::imagesNotInCache() { StringSet set; - for(QDictIterator<Tellico::Data::Image> it(s_imageDict); it.current(); ++it) { - if(s_imageCache.find(it.currentKey()) == 0) { + for(TQDictIterator<Tellico::Data::Image> it(s_imageDict); it.current(); ++it) { + if(s_imageCache.tqfind(it.currentKey()) == 0) { set.add(it.currentKey()); } } return set; } -bool ImageFactory::hasImage(const QString& id_) { - return s_imageCache.find(id_, false) || s_imageDict.find(id_); +bool ImageFactory::hasImage(const TQString& id_) { + return s_imageCache.tqfind(id_, false) || s_imageDict.tqfind(id_); } // the purpose here is to remove images from the dict if they're is on the disk somewhere, @@ -573,17 +573,17 @@ void ImageFactory::releaseImages() { return; } - const QStringList images = s_imagesToRelease.toList(); - for(QStringList::ConstIterator it = images.begin(); it != images.end(); ++it) { + const TQStringList images = s_imagesToRelease.toList(); + for(TQStringList::ConstIterator it = images.begin(); it != images.end(); ++it) { s_imagesToRelease.remove(*it); - if(!s_imageDict.find(*it)) { + if(!s_imageDict.tqfind(*it)) { continue; } // myLog() << "ImageFactory::releaseImage() - id = " << *it << endl; - if(QFile::exists(dataDir() + *it)) { + if(TQFile::exists(dataDir() + *it)) { // myDebug() << "...exists in dataDir() - removing from dict" << endl; s_imageDict.remove(*it); - } else if(QFile::exists(tempDir() + *it)) { + } else if(TQFile::exists(tempDir() + *it)) { // myDebug() << "...exists in tempDir() - removing from dict" << endl; s_imageDict.remove(*it); } @@ -601,8 +601,8 @@ void ImageFactory::setLocalDirectory(const KURL& url_) { } else { s_localDir = url_.directory(false); // could have already been set once - if(!url_.fileName().contains(QString::fromLatin1("_files"))) { - s_localDir += url_.fileName().section('.', 0, 0) + QString::fromLatin1("_files/"); + if(!url_.fileName().tqcontains(TQString::tqfromLatin1("_files"))) { + s_localDir += url_.fileName().section('.', 0, 0) + TQString::tqfromLatin1("_files/"); } myLog() << "ImageFactory::setLocalDirectory() - local dir = " << s_localDir << endl; } |