diff options
author | Arno <am@disconnect.de> | 2012-04-28 15:34:01 +0200 |
---|---|---|
committer | Arno <am@disconnect.de> | 2012-04-28 15:34:01 +0200 |
commit | 3c0e81b3a2cb8d000a57f9ef7de0846aca25b56a (patch) | |
tree | 13e3372925d3eb98094ac8f07149142b906ecfc6 | |
parent | 3f2df0541a862d8e6a799b9502e6b3f7a0c5f884 (diff) | |
download | SheMov-3c0e81b3a2cb8d000a57f9ef7de0846aca25b56a.tar.gz SheMov-3c0e81b3a2cb8d000a57f9ef7de0846aca25b56a.tar.bz2 SheMov-3c0e81b3a2cb8d000a57f9ef7de0846aca25b56a.zip |
Get rid of PictureViewer
Remove last remnants of PictureViewer (without the 2).
-rw-r--r-- | pictureviewer.cpp | 219 | ||||
-rw-r--r-- | pictureviewer.h | 58 | ||||
-rw-r--r-- | shemov.cpp | 1 | ||||
-rw-r--r-- | shemov.pro | 2 |
4 files changed, 0 insertions, 280 deletions
diff --git a/pictureviewer.cpp b/pictureviewer.cpp deleted file mode 100644 index 0014b60..0000000 --- a/pictureviewer.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - 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. -*/ - -#include <QGraphicsScene> -#include <QGraphicsPixmapItem> -#include <QFileInfo> -#include <QLinearGradient> -#include <QDesktopWidget> -#include <QApplication> -#include <QDir> -#include <QWheelEvent> -#include <QSettings> - -#include <algorithm> - -#include "pictureviewer.h" -#include "helper.h" - -PictureViewer::PictureViewer(QWidget *parent) : QGraphicsView(parent), mCurrentPic(0), mInfoItem(0) { - mScene = new QGraphicsScene(this); - setScene(mScene); -} - -void PictureViewer::showPic(const QString &path, bool enableDirEntries){ - QFileInfo fi(path); - if(!fi.exists() || fi.isDir()){ - return; - } - - QPixmap img(path); - if(img.isNull()){ - return; - } - - if(mCurrentPic){ - mScene->removeItem(mCurrentPic); - mScene->removeItem(mInfoItem); - delete mCurrentPic; - delete mInfoItem; - mCurrentPic = 0; - mInfoItem = 0; - } - - if(enableDirEntries){ - setDir(path); - }else{ - mDirEntries = QFileInfoList(); - mCurrentEntry = mDirEntries.constEnd(); - } - if(!isVisible()){ - show(); - } - - QSize maxSize; - QDesktopWidget *desktopWidget = QApplication::desktop(); - QSize desktopSize = desktopWidget->availableGeometry().size(); - if((img.height() > desktopSize.height()) || (img.width() > desktopSize.height())){ - maxSize = desktopSize; - }else{ - maxSize = img.size(); - } - - if(img.width() > maxSize.width() || img.height() > maxSize.height()){ - img = img.scaled(maxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); - } - - if(mResize){ - resize(img.size() + QSize(20, 20)); - } - setSceneRect(viewport()->rect()); - setGradient(img.toImage()); - QGraphicsPixmapItem *item = new QGraphicsPixmapItem(img); - mCurrentPic = item; - item->setPos(center(img)); - mScene->addItem(item); - - PictureviewerInfoItem *infoItem = new PictureviewerInfoItem(fi.fileName()); - QRectF infoItemRect = infoItem->boundingRect(); - int infoWidth = infoItemRect.size().width(); - int viewportWidth = viewport()->size().width(); - int center = (viewportWidth - infoWidth) / 2; - mInfoItem = infoItem; - QPoint infoPoint = QPoint(center, 10); - infoItem->setPos(infoPoint); - mScene->addItem(infoItem); - - setWindowTitle(fi.fileName()); -} - -void PictureViewer::next(){ - if(mCurrentEntry == mDirEntries.constEnd()){ - return; - } - QString nextPath; - while(mCurrentEntry != mDirEntries.constEnd()){ - ++mCurrentEntry; - if(mCurrentEntry == mDirEntries.constEnd()){ - break; - } - QFileInfo fi = *mCurrentEntry; - if(isPic(fi.absoluteFilePath())){ - nextPath = fi.absoluteFilePath(); - break; - } - } - if(!nextPath.isEmpty()){ - showPic(nextPath); - } -} - -void PictureViewer::previous(){ - if(mCurrentEntry == mDirEntries.constBegin()){ - return; - } - QString nextPath; - while(mCurrentEntry != mDirEntries.constBegin()){ - --mCurrentEntry; - QFileInfo fi = *mCurrentEntry; - if(isPic(fi.absoluteFilePath())){ - nextPath = fi.absoluteFilePath(); - break; - } - } - if(!nextPath.isEmpty()){ - showPic(nextPath); - } -} - -void PictureViewer::readSettings(){ - QSettings s; - mResize = s.value("ui/resizepicviewer").toBool(); -} - -void PictureViewer::wheelEvent(QWheelEvent *event){ - int steps = event->delta() / 8 / 15; - if(steps < 0){ - next(); - }else{ - previous(); - } -} - -void PictureViewer::setGradient(const QImage &img){ - QColor c1(img.pixel(2, 2)); - QColor c2(img.pixel(img.width() - 2, img.height() - 2)); - QLinearGradient g(QPointF(0, 0), sceneRect().bottomRight()); - g.setColorAt(0, c1); - g.setColorAt(1, c2); - setBackgroundBrush(QBrush(g)); -} - -void PictureViewer::setDir(const QString &path){ - QFileInfo fi(path); - QString dir = fi.absolutePath(); - if(dir == mCurrentDir || !fi.exists()){ - return; - } - mCurrentDir = dir; - QDir currentDir = QDir(mCurrentDir); - mDirEntries = currentDir.entryInfoList(QDir::Files, QDir::Name); - std::sort(mDirEntries.begin(), mDirEntries.end(), Helper::SortFileInfoList()); - mCurrentEntry = std::find_if(mDirEntries.constBegin(), mDirEntries.constEnd(), std::bind2nd(Helper::FileInfoListContains(), fi.fileName())); -} - -bool PictureViewer::isPic(const QString &path){ - QFileInfo fi(path); - if(!fi.exists() || !fi.isFile()){ - return false; - } - QString mime = Helper::mimeType(path); - if(mime.toLower().startsWith("image")){ - return true; - } - return false; -} - -QPointF PictureViewer::center(const QPixmap &pic){ - QSize viewportSize = viewport()->size(); - float x = (viewportSize.width() - pic.width()) / 2; - float y = (viewportSize.height() - pic.height()) / 2; - return QPointF(x, y); -} - -PictureviewerInfoItem::PictureviewerInfoItem(const QString &fileName, QGraphicsItem *parent) : QGraphicsItem(parent), mFileName(fileName){ - setZValue(1); -} - -QRectF PictureviewerInfoItem::boundingRect() const { - QSize size = qApp->fontMetrics().size(Qt::TextSingleLine, mFileName); - size += QSize(2, 2); - QRectF retval; - retval.setWidth(size.width()); - retval.setHeight(size.height()); - return retval; -} - -void PictureviewerInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){ - Q_UNUSED(option); - Q_UNUSED(widget); - painter->save(); - painter->setRenderHint(QPainter::Antialiasing, false); - painter->setRenderHint(QPainter::TextAntialiasing, true); - QRectF boundRect = boundingRect(); - QColor backgroundColor(Qt::white); - backgroundColor.setAlpha(70); - QBrush brush(backgroundColor); - painter->setPen(QPen(Qt::NoPen)); - painter->setBrush(brush); - painter->drawRect(boundRect); - QPen pen(Qt:: black); - painter->setPen(pen); - QPoint start(1, qApp->fontMetrics().ascent() + 1); - painter->drawText(start, mFileName); - painter->restore(); -} diff --git a/pictureviewer.h b/pictureviewer.h deleted file mode 100644 index adfa537..0000000 --- a/pictureviewer.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - 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. -*/ - -#ifndef PICTUREVIEWER_H -#define PICTUREVIEWER_H - -#include <QGraphicsView> -#include <QFileInfoList> -#include <QGraphicsItem> - -class QGraphicsScene; -class QGraphicsPixmapItem; -class QWheelEvent; -class PictureviewerInfoItem; - -class PictureViewer : public QGraphicsView { - Q_OBJECT - public: - PictureViewer(QWidget *parent = 0); - - public slots: - void showPic(const QString &path, bool enableDirEntries = true); - void next(); - void previous(); - void readSettings(); - - protected: - void wheelEvent(QWheelEvent *event); - - private: - void setGradient(const QImage &img); - void setDir(const QString &path); - bool isPic(const QString &path); - QPointF center(const QPixmap &pic); - QGraphicsScene *mScene; - QGraphicsPixmapItem *mCurrentPic; - PictureviewerInfoItem *mInfoItem; - QString mCurrentDir; - QFileInfoList mDirEntries; - QFileInfoList::const_iterator mCurrentEntry; - bool mResize; -}; - -class PictureviewerInfoItem : public QGraphicsItem { - public: - PictureviewerInfoItem(const QString &fileName, QGraphicsItem *parent = 0); - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - - private: - const QString mFileName; -}; - -#endif @@ -41,7 +41,6 @@ #include "configurationdialog.h" #include "statisticsdialog.h" #include "filesystemfileproxy.h" -#include "pictureviewer.h" #include "archivetreeview.h" #include "smglobals.h" #include "seriestreewidget.h" @@ -16,7 +16,6 @@ SOURCES = main.cpp \ configurationdialog.cpp \ statisticsdialog.cpp \ programconfigurator.cpp \ - pictureviewer.cpp \ smtreeitem.cpp \ smtreemodel.cpp \ smglobals.cpp \ @@ -52,7 +51,6 @@ HEADERS = \ configurationdialog.h \ statisticsdialog.h \ programconfigurator.h \ - pictureviewer.h \ smtreeitem.h \ smtreemodel.h \ smglobals.h \ |