You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. *
  3. * This file is part of QMapControl,
  4. * an open-source cross-platform map widget
  5. *
  6. * Copyright (C) 2007 - 2008 Kai Winter
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * Contact e-mail: kaiwinter@gmx.de
  22. * Program URL : http://qmapcontrol.sourceforge.net/
  23. *
  24. */
  25. #ifndef IMAGEMANAGER_H
  26. #define IMAGEMANAGER_H
  27. #include "qmapcontrol_global.h"
  28. #include <QtCore/QObject>
  29. #include <QtGui/QPixmapCache>
  30. #include <QtCore/QDebug>
  31. #include <QtCore/QMutex>
  32. #include <QtCore/QFile>
  33. #include <QtCore/QDateTime>
  34. #include <QtCore/QBuffer>
  35. #include <QtCore/QDir>
  36. #include <QtNetwork/QNetworkDiskCache>
  37. #include "mapcontrol.h"
  38. class MapNetwork;
  39. class MapControl;
  40. class ImageManager{
  41. public:
  42. explicit ImageManager( MapControl *ptr );
  43. virtual ~ImageManager();
  44. //! returns a QPixmap of the asked image
  45. /*!
  46. * If this component doesn�t have the image a network query gets started to load it.
  47. * @param host the host of the image
  48. * @param path the path to the image
  49. * @return the pixmap of the asked image
  50. */
  51. QPixmap getImage(const QString& host, const QString& path);
  52. QPixmap prefetchImage(const QString& host, const QString& path);
  53. void receivedImage(const QPixmap pixmap, const QString& url);
  54. void fetchFailed(const QString &url);
  55. /*!
  56. * This method is called by MapNetwork, after all images in its queue were loaded.
  57. * The ImageManager emits a signal, which is used in MapControl to remove the zoom image.
  58. * The zoom image should be removed on Tile Images with transparency.
  59. * Else the zoom image stay visible behind the newly loaded tiles.
  60. */
  61. void loadingQueueEmpty();
  62. /*!
  63. * Aborts all current loading threads.
  64. * This is useful when changing the zoom-factor, though newly needed images loads faster
  65. */
  66. void abortLoading();
  67. //! sets the proxy for HTTP connections
  68. /*!
  69. * This method sets the proxy for HTTP connections.
  70. * This is not provided by the current Qtopia version!
  71. * @param host the proxy�s hostname or ip
  72. * @param port the proxy�s port
  73. * @param username the proxy�s username
  74. * @param password the proxy�s password
  75. */
  76. void setProxy(QString host, int port, const QString username = QString(), const QString password = QString());
  77. //! sets the cache directory for persistently saving map tiles
  78. /*!
  79. *
  80. * @param path the path where map tiles should be stored
  81. * @param qDiskSizeMB the about of disk space to use for caching. Default is 250MB
  82. */
  83. void setCacheDir(const QDir& path, const int qDiskSizeMB = 250);
  84. /*!
  85. * @return Number of images pending in the load queue
  86. */
  87. int loadQueueSize() const;
  88. private:
  89. //Q_DISABLE_COPY( ImageManager )
  90. MapControl *m_pMapControl;
  91. QPixmap emptyPixmap;
  92. QPixmap loadingPixmap;
  93. MapNetwork* net;
  94. QNetworkDiskCache* diskCache;
  95. QVector<QString> prefetch;
  96. QHash<QString,QDateTime> failedFetches;
  97. public:
  98. void imageReceived();
  99. void loadingFinished();
  100. };
  101. #endif