From ce8ea0df0dd34e516bfad507c4dfb3735ecdf82b Mon Sep 17 00:00:00 2001 From: Arno Date: Sun, 12 Dec 2010 11:36:42 +0100 Subject: 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. --- filestreemodel.cpp | 2 +- filestreewidget.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++- filestreewidget.h | 1 + hoverwindow.cpp | 14 ++++++------ 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 #include #include +#include +#include +#include +#include +#include +#include +#include #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(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(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(SmGlobals::instance()->model("FilesModel")); + QHash files = filesModel->filesBySeriesPartId(idx.data(FilesTreeModel::SeriesPartIdRole).toInt()); + QModelIndex seriesPartIdx = seriesModel->findValue(idx.data(FilesTreeModel::SeriesPartIdRole), seriesIdx, SeriesTreeModel::SeriesPartId); + QString data = QString(tr("

%1 %2

")).arg(seriesPartIdx.data(SeriesTreeModel::NameRole).toString()).arg(QString::number(seriesPartIdx.data(SeriesTreeModel::SeriesPartRole).toInt())); + data.append(QString(tr("

Files:

"))); + data.append(tr("
    ")); + QHash::const_iterator it = files.constBegin(); + while(it != files.constEnd()){ + data.append(QString("
  • %1
  • ").arg(it.key())); + ++it; + } + data.append(tr("
")); + 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 &data); int pixmapHeight() const; void setPos(); -- cgit v1.2.3-70-g09d2