diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 78765845..abf5729f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,196 +1,197 @@ project(gwenviewlib) # Extract version of libjpeg so that we can use the appropriate dir # See bug #227313 file(READ "${JPEG_INCLUDE_DIR}/jpeglib.h" jpeglib_h_content) string(REGEX MATCH "#define +JPEG_LIB_VERSION +([0-9]+)" "\\1" jpeglib_version "${jpeglib_h_content}") set(jpeglib_version ${CMAKE_MATCH_1}) if ("${jpeglib_version}" STREQUAL "") # libjpeg-turbo keeps JPEG_LIB_VERSION in jconfig.h, not jpeglib.h :/ file(READ "${JPEG_INCLUDE_DIR}/jconfig.h" jconfig_h_content) string(REGEX MATCH "#define +JPEG_LIB_VERSION +([0-9]+)" "\\1" jpeglib_version "${jconfig_h_content}") set(jpeglib_version ${CMAKE_MATCH_1}) endif ("${jpeglib_version}" STREQUAL "") if ("${jpeglib_version}" LESS 80) set(GV_JPEG_DIR libjpeg-62) endif ("${jpeglib_version}" LESS 80) if ("${jpeglib_version}" EQUAL 80) set(GV_JPEG_DIR libjpeg-80) endif ("${jpeglib_version}" EQUAL 80) if ("${GV_JPEG_DIR}" STREQUAL "") message(FATAL_ERROR "Unknown libjpeg version: ${jpeglib_version}") endif ("${GV_JPEG_DIR}" STREQUAL "") message(STATUS "libjpeg version: ${jpeglib_version}") add_definitions(-Dlibjpeg_EXPORTS) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/${GV_JPEG_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR} ${SOPRANO_INCLUDE_DIR} ${EXIV2_INCLUDE_DIR} ${JPEG_INCLUDE_DIR} ) # For config-gwenview.h include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ) set(gwenviewlib_SRCS crop/cropwidget.cpp crop/cropimageoperation.cpp crop/croptool.cpp document/abstractdocumentimpl.cpp document/documentjob.cpp document/animateddocumentloadedimpl.cpp document/document.cpp document/documentfactory.cpp document/documentloadedimpl.cpp document/emptydocumentimpl.cpp document/jpegdocumentloadedimpl.cpp document/loadingdocumentimpl.cpp document/loadingjob.cpp document/savejob.cpp document/svgdocumentloadedimpl.cpp document/videodocumentloadedimpl.cpp documentview/abstractdocumentviewadapter.cpp + documentview/abstractimageview.cpp documentview/documentview.cpp documentview/documentviewcontroller.cpp documentview/documentviewsynchronizer.cpp documentview/messageviewadapter.cpp documentview/imageviewadapter.cpp documentview/svgviewadapter.cpp documentview/videoviewadapter.cpp abstractimageoperation.cpp abstractimageviewtool.cpp documentview/documentviewcontainer.cpp binder.cpp eventwatcher.cpp splittercollapser.cpp historymodel.cpp archiveutils.cpp datewidget.cpp exiv2imageloader.cpp flowlayout.cpp fullscreenbar.cpp fullscreentheme.cpp graphicswidgetfloater.cpp hudwidget.cpp imageformats/imageformats.cpp imageformats/jpegplugin.cpp imageformats/jpeghandler.cpp imagemetainfomodel.cpp imagescaler.cpp imageutils.cpp imageview.cpp invisiblebuttongroup.cpp iodevicejpegsourcemanager.cpp jpegcontent.cpp semanticinfo/sorteddirmodel.cpp memoryutils.cpp messagebubble.cpp mimetypeutils.cpp paintutils.cpp placetreemodel.cpp preferredimagemetainfomodel.cpp print/printhelper.cpp print/printoptionspage.cpp slidecontainer.cpp slideshow.cpp scrolltool.cpp statusbartoolbutton.cpp redeyereduction/redeyereductionimageoperation.cpp redeyereduction/redeyereductiontool.cpp resize/resizeimageoperation.cpp resize/resizeimagedialog.cpp thumbnailloadjob.cpp thumbnailview/abstractthumbnailviewhelper.cpp thumbnailview/abstractdocumentinfoprovider.cpp thumbnailview/contextbarbutton.cpp thumbnailview/itemeditor.cpp thumbnailview/previewitemdelegate.cpp thumbnailview/thumbnailbarview.cpp thumbnailview/thumbnailslider.cpp thumbnailview/thumbnailview.cpp thumbnailview/tooltipwidget.cpp timeutils.cpp transformimageoperation.cpp urlutils.cpp widgetfloater.cpp zoomslider.cpp zoomwidget.cpp ${GV_JPEG_DIR}/transupp.c ) if (NOT GWENVIEW_SEMANTICINFO_BACKEND_NONE) set(gwenviewlib_SRCS ${gwenviewlib_SRCS} semanticinfo/abstractsemanticinfobackend.cpp semanticinfo/semanticinfodirmodel.cpp semanticinfo/tagitemdelegate.cpp semanticinfo/tagmodel.cpp semanticinfo/tagwidget.cpp ) endif (NOT GWENVIEW_SEMANTICINFO_BACKEND_NONE) if (GWENVIEW_SEMANTICINFO_BACKEND_FAKE) set(gwenviewlib_SRCS ${gwenviewlib_SRCS} semanticinfo/fakesemanticinfobackend.cpp ) endif (GWENVIEW_SEMANTICINFO_BACKEND_FAKE) if (GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK) set(gwenviewlib_SRCS ${gwenviewlib_SRCS} semanticinfo/nepomuksemanticinfobackend.cpp ) endif (GWENVIEW_SEMANTICINFO_BACKEND_NEPOMUK) set_source_files_properties( exiv2imageloader.cpp PROPERTIES COMPILE_FLAGS "${KDE4_ENABLE_EXCEPTIONS}" ) kde4_add_ui_files(gwenviewlib_SRCS crop/cropwidget.ui documentview/messageview.ui print/printoptionspage.ui redeyereduction/redeyereductionhud.ui resize/resizeimagewidget.ui ) kde4_add_kcfg_files(gwenviewlib_SRCS gwenviewconfig.kcfgc ) kde4_add_library(gwenviewlib SHARED ${gwenviewlib_SRCS}) set_target_properties(gwenviewlib PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) if(WIN32) set_target_properties( gwenviewlib PROPERTIES COMPILE_FLAGS -DJPEG_STATIC ) endif(WIN32) target_link_libraries(gwenviewlib ${KDE4_KFILE_LIBS} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBS} ${JPEG_LIBRARY} ${EXIV2_LIBRARIES} ${QT_QTOPENGL_LIBRARY} ) if( WIN32 ) target_link_libraries( gwenviewlib ${EXPAT_LIBRARIES} ) endif( WIN32 ) if (NOT GWENVIEW_SEMANTICINFO_BACKEND_NONE) target_link_libraries(gwenviewlib ${NEPOMUK_LIBRARIES} ${SOPRANO_LIBRARIES} ) endif (NOT GWENVIEW_SEMANTICINFO_BACKEND_NONE) install(TARGETS gwenviewlib ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/lib/documentview/abstractimageview.cpp b/lib/documentview/abstractimageview.cpp new file mode 100644 index 00000000..42b8f30f --- /dev/null +++ b/lib/documentview/abstractimageview.cpp @@ -0,0 +1,62 @@ +// vim: set tabstop=4 shiftwidth=4 noexpandtab: +/* +Gwenview: an image viewer +Copyright 2011 Aurélien Gâteau + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. + +*/ +// Self +#include "abstractimageview.moc" + +// Local + +// KDE + +// Qt +#include + +namespace Gwenview { + +struct AbstractImageViewPrivate { +}; + +AbstractImageView::AbstractImageView(QGraphicsItem* parent) +: QGraphicsWidget(parent) +, mZoom(1) +, d(new AbstractImageViewPrivate) { +} + +AbstractImageView::~AbstractImageView() { + delete d; +} + +void AbstractImageView::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { + painter->drawPixmap( + (size().width() - mCachePix.width()) / 2, + (size().height() - mCachePix.height()) / 2, + mCachePix); +} + +qreal AbstractImageView::zoom() const { + return mZoom; +} + +void AbstractImageView::setZoom(qreal zoom, const QPointF& /*center*/) { + mZoom = zoom; + updateCache(); +} + +} // namespace diff --git a/lib/documentview/abstractimageview.h b/lib/documentview/abstractimageview.h new file mode 100644 index 00000000..fd2b13f9 --- /dev/null +++ b/lib/documentview/abstractimageview.h @@ -0,0 +1,63 @@ +// vim: set tabstop=4 shiftwidth=4 noexpandtab: +/* +Gwenview: an image viewer +Copyright 2011 Aurélien Gâteau + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. + +*/ +#ifndef ABSTRACTIMAGEVIEW_H +#define ABSTRACTIMAGEVIEW_H + +// Local + +// KDE + +// Qt +#include + +namespace Gwenview { + + +class AbstractImageViewPrivate; +/** + * + */ +class AbstractImageView : public QGraphicsWidget { + Q_OBJECT +public: + AbstractImageView(QGraphicsItem* parent = 0); + ~AbstractImageView(); + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/); + + qreal zoom() const; + + void setZoom(qreal zoom, const QPointF& /*center*/); + +protected: + virtual void updateCache() = 0; + qreal mZoom; + QPixmap mCachePix; + +private: + AbstractImageViewPrivate* const d; +}; + + + +} // namespace + +#endif /* ABSTRACTIMAGEVIEW_H */ diff --git a/lib/documentview/svgviewadapter.cpp b/lib/documentview/svgviewadapter.cpp index e1b3440e..66dd5e82 100644 --- a/lib/documentview/svgviewadapter.cpp +++ b/lib/documentview/svgviewadapter.cpp @@ -1,190 +1,168 @@ // vim: set tabstop=4 shiftwidth=4 noexpandtab: /* Gwenview: an image viewer Copyright 2008 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ // Self #include "svgviewadapter.moc" // Qt #include #include #include #include #include // KDE #include // Local #include "document/documentfactory.h" namespace Gwenview { -AbstractImageView::AbstractImageView(QGraphicsItem* parent) -: QGraphicsWidget(parent) -, mZoom(1) -{ -} - -void AbstractImageView::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) { - painter->drawPixmap( - (size().width() - mCachePix.width()) / 2, - (size().height() - mCachePix.height()) / 2, - mCachePix); -} - -qreal AbstractImageView::zoom() const { - return mZoom; -} - -void AbstractImageView::setZoom(qreal zoom, const QPointF& /*center*/) { - mZoom = zoom; - updateCache(); -} - /// SvgImageView //// SvgImageView::SvgImageView(QGraphicsItem* parent) : AbstractImageView(parent) , mRenderer(new QSvgRenderer(this)) {} void SvgImageView::loadFromDocument(Document::Ptr doc) { mRenderer->load(doc->rawData()); updateCache(); } QSize SvgImageView::defaultSize() const { return mRenderer->defaultSize(); } void SvgImageView::updateCache() { mCachePix = QPixmap(defaultSize() * mZoom); mCachePix.fill(Qt::transparent); QPainter painter(&mCachePix); mRenderer->render(&painter, QRectF(mCachePix.rect())); update(); } //// SvgViewAdapter //// struct SvgViewAdapterPrivate { Document::Ptr mDocument; SvgImageView* mView; bool mZoomToFit; }; SvgViewAdapter::SvgViewAdapter() : d(new SvgViewAdapterPrivate) { d->mZoomToFit = true; d->mView = new SvgImageView; setWidget(d->mView); } SvgViewAdapter::~SvgViewAdapter() { delete d; } QCursor SvgViewAdapter::cursor() const { return widget()->cursor(); } void SvgViewAdapter::setCursor(const QCursor& cursor) { widget()->setCursor(cursor); } void SvgViewAdapter::setDocument(Document::Ptr doc) { d->mDocument = doc; connect(d->mDocument.data(), SIGNAL(loaded(KUrl)), SLOT(loadFromDocument())); loadFromDocument(); } void SvgViewAdapter::loadFromDocument() { d->mView->loadFromDocument(d->mDocument); if (d->mZoomToFit) { setZoom(computeZoomToFit()); } } Document::Ptr SvgViewAdapter::document() const { return d->mDocument; } void SvgViewAdapter::setZoomToFit(bool on) { if (d->mZoomToFit == on) { return; } d->mZoomToFit = on; if (d->mZoomToFit) { setZoom(computeZoomToFit()); } zoomToFitChanged(on); } bool SvgViewAdapter::zoomToFit() const { return d->mZoomToFit; } qreal SvgViewAdapter::zoom() const { return d->mView->zoom(); } void SvgViewAdapter::setZoom(qreal zoom, const QPointF& center) { d->mView->setZoom(zoom, center); emit zoomChanged(zoom); } qreal SvgViewAdapter::computeZoomToFit() const { return qMin(computeZoomToFitWidth(), computeZoomToFitHeight()); } qreal SvgViewAdapter::computeZoomToFitWidth() const { qreal width = d->mView->defaultSize().width(); return width != 0 ? (d->mView->size().width() / width) : 1; } qreal SvgViewAdapter::computeZoomToFitHeight() const { qreal height = d->mView->defaultSize().height(); return height != 0 ? (d->mView->size().height() / height) : 1; } bool SvgViewAdapter::eventFilter(QObject*, QEvent* event) { if (event->type() == QEvent::Resize) { if (d->mZoomToFit) { setZoom(computeZoomToFit()); } } return false; } } // namespace diff --git a/lib/documentview/svgviewadapter.h b/lib/documentview/svgviewadapter.h index 24358667..b57d2841 100644 --- a/lib/documentview/svgviewadapter.h +++ b/lib/documentview/svgviewadapter.h @@ -1,113 +1,98 @@ // vim: set tabstop=4 shiftwidth=4 noexpandtab: /* Gwenview: an image viewer Copyright 2008 Aurélien Gâteau This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. */ #ifndef SVGVIEWADAPTER_H #define SVGVIEWADAPTER_H #include // Qt #include // KDE // Local +#include #include class QSvgRenderer; namespace Gwenview { -class AbstractImageView : public QGraphicsWidget { -public: - AbstractImageView(QGraphicsItem* parent = 0); - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/); - - qreal zoom() const; - - void setZoom(qreal zoom, const QPointF& /*center*/); - -protected: - virtual void updateCache() = 0; - qreal mZoom; - QPixmap mCachePix; -}; - class SvgImageView : public AbstractImageView { public: SvgImageView(QGraphicsItem* parent = 0); void loadFromDocument(Document::Ptr doc); QSize defaultSize() const; protected: void updateCache(); private: QSvgRenderer* mRenderer; }; struct SvgViewAdapterPrivate; class GWENVIEWLIB_EXPORT SvgViewAdapter : public AbstractDocumentViewAdapter { Q_OBJECT public: SvgViewAdapter(); ~SvgViewAdapter(); virtual QCursor cursor() const; virtual void setCursor(const QCursor&); virtual void setDocument(Document::Ptr); virtual Document::Ptr document() const; virtual MimeTypeUtils::Kind kind() const { return MimeTypeUtils::KIND_SVG_IMAGE; } virtual bool canZoom() const { return true; } virtual void setZoomToFit(bool); virtual bool zoomToFit() const; virtual qreal zoom() const; virtual void setZoom(qreal /*zoom*/, const QPointF& /*center*/ = QPointF(-1, -1)); virtual qreal computeZoomToFit() const; virtual qreal computeZoomToFitWidth() const; virtual qreal computeZoomToFitHeight() const; protected: virtual bool eventFilter(QObject*, QEvent*); private Q_SLOTS: void loadFromDocument(); private: SvgViewAdapterPrivate* const d; }; } // namespace #endif /* SVGVIEWADAPTER_H */