diff options
author | Arno <am@disconnect.de> | 2010-12-12 11:36:42 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-12-12 11:36:42 +0100 |
commit | ce8ea0df0dd34e516bfad507c4dfb3735ecdf82b (patch) | |
tree | 83491df938f694d394890077b8cea1dc2b748837 | |
parent | f2a3027188423719fcde96dd5975646b7122e268 (diff) | |
download | SheMov-ce8ea0df0dd34e516bfad507c4dfb3735ecdf82b.tar.gz SheMov-ce8ea0df0dd34e516bfad507c4dfb3735ecdf82b.tar.bz2 SheMov-ce8ea0df0dd34e516bfad507c4dfb3735ecdf82b.zip |
Hover fix
When hovering over movies in local mode both the ToolTip and the hover
image was shown. Fixed by only showing the ToolTip when the movie is not
available, eg. archive mode. In any other case incorporate the ToolTip
info into the hover image.
-rw-r--r-- | filestreemodel.cpp | 2 | ||||
-rw-r--r-- | filestreewidget.cpp | 62 | ||||
-rw-r--r-- | filestreewidget.h | 1 | ||||
-rw-r--r-- | hoverwindow.cpp | 14 | ||||
-rw-r--r-- | hoverwindow.h | 2 |
5 files changed, 72 insertions, 9 deletions
diff --git a/filestreemodel.cpp b/filestreemodel.cpp index 5bb0741..8fd9e31 100644 --- a/filestreemodel.cpp +++ b/filestreemodel.cpp @@ -157,7 +157,7 @@ QVariant FilesTreeModel::data(const QModelIndex &index, int role) const{ return item->data(index.column()); } if(role == Qt::ToolTipRole){ - if(mMode != Normal){ + if((mMode == Archived) && (item->data(FileType) == Movie)){ int seriesPartId = item->data(SeriesPartId).toInt(); int seriesId = mSeriesModel->seriesIdByPartId(seriesPartId); if(seriesId != -1){ diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 9076091..bc60541 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -23,6 +23,13 @@ #include <QSettings> #include <QHeaderView> #include <QInputDialog> +#include <QPainter> +#include <QTextDocument> +#include <QImage> +#include <QHash> +#include <QBrush> +#include <QColor> +#include <QPen> #include "filestreewidget.h" #include "smglobals.h" @@ -32,6 +39,7 @@ #include "pictureviewer.h" #include "filepropertiesdialog.h" #include "hoverwindow.h" +#include "seriestreemodel.h" FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSize(0){ //the view @@ -397,22 +405,74 @@ bool FilesTreeView::exitHover(bool exitVal){ void FilesTreeView::doHover(const QModelIndex &idx){ QPixmap pm; + bool scale = true; mCurHover = idx; if(idx.data(FilesTreeModel::FileTypeRole).toInt() == FilesTreeModel::Movie){ pm = Helper::grabFrame(idx.data(FilesTreeModel::FullPathRole).toString()); if(pm.isNull()){ return; } + scale = false; + FilesTreeModel *filesModel = qobject_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); + if(filesModel->mode() == FilesTreeModel::Local){ + pm = annotateHover(pm, idx); + scale = false; + } }else{ if(!pm.load(idx.data(FilesTreeModel::FullPathRole).toString())){ return; } } - mHoverWin->setPixmap(pm); + mHoverWin->setPixmap(pm, scale); mHoverWin->setPos(); mHoverWin->setVisible(true); } +const QPixmap FilesTreeView::annotateHover(const QPixmap &hoverImage, const QModelIndex &idx) const{ + SeriesTreeModel *seriesModel = qobject_cast<SeriesTreeModel*>(SmGlobals::instance()->model("SeriesModel")); + int seriesId = seriesModel->seriesIdByPartId(idx.data(FilesTreeModel::SeriesPartIdRole).toInt()); + if(seriesId == -1){ + return hoverImage; + } + QModelIndex seriesIdx = seriesModel->findValue(seriesId, QModelIndex(), SeriesTreeModel::SeriesId); + if(!seriesIdx.isValid()){ + return hoverImage; + } + FilesTreeModel *filesModel = qobject_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); + QHash<QString, QString> files = filesModel->filesBySeriesPartId(idx.data(FilesTreeModel::SeriesPartIdRole).toInt()); + QModelIndex seriesPartIdx = seriesModel->findValue(idx.data(FilesTreeModel::SeriesPartIdRole), seriesIdx, SeriesTreeModel::SeriesPartId); + QString data = QString(tr("<p style=\"text-decoration: underline; font-weight: bold\">%1 %2</p>")).arg(seriesPartIdx.data(SeriesTreeModel::NameRole).toString()).arg(QString::number(seriesPartIdx.data(SeriesTreeModel::SeriesPartRole).toInt())); + data.append(QString(tr("<p style=\"margin-bottom: 0px; padding-bottom: 0px\">Files:</p>"))); + data.append(tr("<ul style=\"margin-top: 0px\">")); + QHash<QString, QString>::const_iterator it = files.constBegin(); + while(it != files.constEnd()){ + data.append(QString("<li style=\"margin-left: -10px\">%1</li>").arg(it.key())); + ++it; + } + data.append(tr("</ul>")); + QTextDocument doc; + doc.setHtml(data); + doc.setTextWidth(hoverImage.width()); + QSize picSize(hoverImage.width(), hoverImage.height() + doc.size().height()); + QImage retImg(picSize, QImage::Format_ARGB32_Premultiplied); + retImg.fill(0); + QPainter p(&retImg); + p.drawPixmap(0, 0, hoverImage); + p.setRenderHint(QPainter::Antialiasing, false); + p.setRenderHint(QPainter::TextAntialiasing, true); + QColor bgColor(Qt::white); + bgColor.setAlpha(70); + QBrush brush(bgColor); + p.setPen(QPen(Qt::NoPen)); + p.setBrush(brush); + QRect bgRect(0, hoverImage.height(), hoverImage.width(), doc.size().height()); + p.drawRect(bgRect); + p.setPen(QPen(Qt::black)); + p.translate(0, hoverImage.height()); + doc.drawContents(&p); + return QPixmap::fromImage(retImg); +} + FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {} // left + right are from the sourceModel() !!!! diff --git a/filestreewidget.h b/filestreewidget.h index 7353a52..23c9ef8 100644 --- a/filestreewidget.h +++ b/filestreewidget.h @@ -76,6 +76,7 @@ class FilesTreeView : public QTreeView { private: bool exitHover(bool exitVal = true); void doHover(const QModelIndex &idx); + const QPixmap annotateHover(const QPixmap &hoverImage, const QModelIndex &idx) const; QModelIndex mCurHover; HoverWindow *mHoverWin; bool mHoverPics; diff --git a/hoverwindow.cpp b/hoverwindow.cpp index 6ca6bce..9e09728 100644 --- a/hoverwindow.cpp +++ b/hoverwindow.cpp @@ -47,14 +47,16 @@ void HoverWindow::setContent(const QString &parent, const QStringList &children) mLabel->setText(curText); } -void HoverWindow::setPixmap(const QPixmap &pm){ +void HoverWindow::setPixmap(const QPixmap &pm, bool scale){ mAlignCenter = true; QPixmap curPm = pm; - if(curPm.height() > 500){ - curPm = curPm.scaledToHeight(500); - } - if(curPm.width() > 300){ - curPm = curPm.scaledToWidth(300); + if(scale){ + if(curPm.height() > 500){ + curPm = curPm.scaledToHeight(500); + } + if(curPm.width() > 300){ + curPm = curPm.scaledToWidth(300); + } } mLabel->setPixmap(curPm); setMaximumSize(curPm.width() + 10, curPm.height() + 10); diff --git a/hoverwindow.h b/hoverwindow.h index ee061dd..af2f084 100644 --- a/hoverwindow.h +++ b/hoverwindow.h @@ -21,7 +21,7 @@ class HoverWindow : public QWidget { public: explicit HoverWindow(QWidget *parent = 0, Qt::WindowFlags f = Qt::Tool | Qt::FramelessWindowHint); void setContent(const QString &parent, const QStringList &children); - void setPixmap(const QPixmap &pm); + void setPixmap(const QPixmap &pm, bool scale = true); void setData(const QList<QVariant> &data); int pixmapHeight() const; void setPos(); |