Remove the arrows in the image view widget and replace them with previews of the next/previous images. Add a fullsize image viewer, add a "Save as..." option.

This commit is contained in:
David Sansome 2010-10-08 21:09:01 +00:00
parent f09a115339
commit 565ec47e42
36 changed files with 357 additions and 47 deletions

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "اضغط هنا لإضافة بعض الموسيقى"
@ -1517,6 +1520,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1518,6 +1521,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -406,6 +406,9 @@ msgstr ""
"Clementine no pot carregar cap visualització de projectM. Asseguri's que té "
"instal·lat Clementine correctament."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Fes click aquí per afegir música"
@ -1547,6 +1550,9 @@ msgstr "Freqüència de mostreig"
msgid "Samplerate"
msgstr "Freqüència de mostreig"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Desa la llista de reproducció"

View File

@ -394,6 +394,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Zde klikněte pro řidání hudby"
@ -1522,6 +1525,9 @@ msgstr "Vzorkovací frekvence"
msgid "Samplerate"
msgstr "Vzorkovací frekvence"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Uložit playlist"

View File

@ -394,6 +394,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Klik her for at tilføje musik"
@ -1523,6 +1526,9 @@ msgstr "Samplingsrate"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -404,6 +404,9 @@ msgstr ""
"Clementine konnte keine projectM-Visualisierungen laden. Überprüfen Sie Ihre "
"Installation."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Klicken Sie hier um das zu ändern"
@ -1548,6 +1551,9 @@ msgstr "Abtastrate"
msgid "Samplerate"
msgstr "Abtastrate"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Wiedergabeliste speichern"

View File

@ -405,6 +405,9 @@ msgstr ""
"Ο Clementine δεν μπορεί να φορτώσει κάποιο projectM οπτικό εφέ. Βεβαιωθείτε "
"πως έχετε εγκαταστήσει τον Clementine σωστά."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Κλικ εδώ για να προσθέσετε μουσική"
@ -1551,6 +1554,9 @@ msgstr "Ρυθμός δειγματοληψίας"
msgid "Samplerate"
msgstr "Δειγματοληψία"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Αποθήκευση λίστας αναπαραγωγής"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Click here to add some music"
@ -1522,6 +1525,9 @@ msgstr "Sample rate"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Save playlist"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Click here to add some music"
@ -1519,6 +1522,9 @@ msgstr "Sample rate"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -406,6 +406,9 @@ msgstr ""
"Clementine no puede cargar ninguna visualización de projectM. Asegúrese que "
"tiene instalado Clementine adecuadamente."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Haz clic aquí para añadir música"
@ -1552,6 +1555,9 @@ msgstr "Tasa de muestreo"
msgid "Samplerate"
msgstr "Tasa de muestreo"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Guardar lista de reproducción"

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Napsauta tästä lisätäksesi musiikkia"
@ -1520,6 +1523,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Tallenna soittolista"

View File

@ -409,6 +409,9 @@ msgstr ""
"Clementine n'a pu charger les visualisations projectM. Vérifiez que "
"Clementine est installé correctement."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Cliquez ici pour créer votre bibliothèque musicale"
@ -1556,6 +1559,9 @@ msgstr "Échantillonnage"
msgid "Samplerate"
msgstr "Échantillonnage"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Enregistrer la liste de lecture"

View File

@ -397,6 +397,9 @@ msgstr ""
"Clementine non pode carregar ningunha visualización de projectM. Asegúrese "
"que ten instalado Clementine adecuadamente."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Clique aqui para adicionar música"
@ -1524,6 +1527,9 @@ msgstr "Taxa de mostra"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -402,6 +402,9 @@ msgstr ""
"A Clementine egy projectM megjelenítést sem tud betölteni. Ellenőrizze, hogy "
"megfelelően telepítette a Clementinet."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Zene felvételéhez kattintson ide"
@ -1545,6 +1548,9 @@ msgstr "Mintavételi sűrűség"
msgid "Samplerate"
msgstr "Mintavétel"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Lejátszási lista mentése"

View File

@ -409,6 +409,9 @@ msgstr ""
"Clementine non può caricare alcuna visualizzazione projectM. Controlla che "
"Clementine sia installato correttamente."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Fai clic qui per aggiungere della musica"
@ -1556,6 +1559,9 @@ msgstr "Campionamento"
msgid "Samplerate"
msgstr "Campionamento"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Salva la scaletta"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1519,6 +1522,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1518,6 +1521,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Klikk her for å legge til litt musikk"
@ -1521,6 +1524,9 @@ msgstr "Samplingsrate"
msgid "Samplerate"
msgstr "Samplingsrate"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -405,6 +405,9 @@ msgstr ""
"Clementine kon geen projectM visualisaties laden. Controleer of u "
"Clementine correct hebt geïnstalleerd."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Klik hier om muziek toe te voegen"
@ -1551,6 +1554,9 @@ msgstr "Samplerate"
msgid "Samplerate"
msgstr "Samplerate"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Afspeellijst opslaan"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1517,6 +1520,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -405,6 +405,9 @@ msgstr ""
"Clementine nie może wczytać wizualizacji. Sprawdź czy Clementine został "
"zainstalowany prawidłowo."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Kliknij aby dodać jakąś muzykę"
@ -1547,6 +1550,9 @@ msgstr "Próbkowanie"
msgid "Samplerate"
msgstr "Próbkowanie"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Zapisz listę odtwarzania"

View File

@ -405,6 +405,9 @@ msgstr ""
"O Clementine não conseguiu carregar as visualizações projectM. Verifique se "
"o Clementine foi bem instalado."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Clique aqui para adicionar músicas"
@ -1548,6 +1551,9 @@ msgstr "Taxa de amostragem"
msgid "Samplerate"
msgstr "Taxa de amostragem"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Gravar lista de reprodução"

View File

@ -402,6 +402,9 @@ msgstr ""
"O Clementine não carregou nehuma visualização projectM. Verifique se você "
"intalou o Clementine corretamente."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Clique aqui para adicionar algumas músicas"
@ -1536,6 +1539,9 @@ msgstr "Taxa de amostragem"
msgid "Samplerate"
msgstr "Taxa de amostragem"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Salvar lista de reprodução"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Clic aici pentru a adăuga muzică"
@ -1518,6 +1521,9 @@ msgstr "Rată de eșantionare"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -400,6 +400,9 @@ msgstr ""
"Clementine не может загрузить какою-либо визуализацию projectM. Проверьте, "
"что установили Clementine правильно."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Щелкните здесь, чтобы добавить музыку"
@ -1540,6 +1543,9 @@ msgstr "Частота"
msgid "Samplerate"
msgstr "Частота дискретизации"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Сохранить список воспроизведения"

View File

@ -402,6 +402,9 @@ msgstr ""
"Clementine nemôže načítať žiadnu projectM vizualizáciu. Skontrolujte, či "
"máte Clementine nainštalovaný správne."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Kliknite sem aby ste pridali nejakú hudbu"
@ -1541,6 +1544,9 @@ msgstr "Rýchlosť vzorkovania"
msgid "Samplerate"
msgstr "Rýchlosť vzorkovania"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Uložiť playlist"

View File

@ -401,6 +401,9 @@ msgstr ""
"Clementine ni mogel naložiti predočenj projectM. Preverite, če je Clementine "
"pravilno nameščen."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Kliknite sem za dodajanje glasbe"
@ -1541,6 +1544,9 @@ msgstr "Hitrost vzorčenja"
msgid "Samplerate"
msgstr "Hitrost vzorčenja"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Shrani seznam predvajanja"

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Кликни овде да додате неку музику"
@ -1523,6 +1526,9 @@ msgstr "узорковање"
msgid "Samplerate"
msgstr "Учестаност узорковања"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Сачувај листу нумера"

View File

@ -393,6 +393,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Klicka här för att lägga till musik"
@ -1527,6 +1530,9 @@ msgstr "Samplingsfrekvens"
msgid "Samplerate"
msgstr "Samplingsfrekvens"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Spara spellista"

View File

@ -401,6 +401,9 @@ msgstr ""
"Clementine projectM görsellerini yükleyemedi. Clementine programını düzgün "
"yüklediğinizi kontrol edin."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Parça eklemek için buraya tıklayın"
@ -1544,6 +1547,9 @@ msgstr "Örnekleme oranı"
msgid "Samplerate"
msgstr "Örneklemeoranı"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Çalma listesini kaydet"

View File

@ -383,6 +383,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1508,6 +1511,9 @@ msgstr ""
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr ""

View File

@ -401,6 +401,9 @@ msgstr ""
"Clementine не вдалось завантажити візуалізації projectM. Перевірте чи ви "
"правильно встановили Clementine."
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "Клацніть тут, щоб додати музику"
@ -1541,6 +1544,9 @@ msgstr "Частота вибірки"
msgid "Samplerate"
msgstr "Частота вибірки"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "Зберегти список відтворення"

View File

@ -392,6 +392,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr ""
@ -1517,6 +1520,9 @@ msgstr "采样率"
msgid "Samplerate"
msgstr ""
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "保存播放列表"

View File

@ -397,6 +397,9 @@ msgid ""
"installed Clementine properly."
msgstr ""
msgid "Clementine image viewer"
msgstr ""
msgid "Click here to add some music"
msgstr "點擊此處加入一些音樂"
@ -1523,6 +1526,9 @@ msgstr "取樣頻率"
msgid "Samplerate"
msgstr "取樣頻率"
msgid "Save image"
msgstr ""
msgid "Save playlist"
msgstr "儲存播放清單"

View File

@ -16,58 +16,65 @@
#include "prettyimageview.h"
#include "core/networkaccessmanager.h"
#include "ui/iconloader.h"
#include <QApplication>
#include <QFileDialog>
#include <QLabel>
#include <QMenu>
#include <QMouseEvent>
#include <QNetworkReply>
#include <QPainter>
#include <QScrollArea>
#include <QSettings>
#include <QStyle>
#include <QStyleOption>
#include <QTimeLine>
#include <QtDebug>
const int PrettyImageView::kArrowWidth = 35;
const int PrettyImageView::kEdgeWidth = 50;
const int PrettyImageView::kImageHeight = 160;
const int PrettyImageView::kTotalHeight = 200;
const int PrettyImageView::kBorderHeight = 10;
const int PrettyImageView::kBorderHeight = 5;
const int PrettyImageView::kEdgePadding = 5;
const int PrettyImageView::kBaseAnimationDuration = 500; // msec
const int PrettyImageView::kArrowAnimationDuration = 250; // msec
const char* PrettyImageView::kSettingsGroup = "PrettyImageView";
PrettyImageView::PrettyImageView(NetworkAccessManager* network, QWidget* parent)
: QWidget(parent),
network_(network),
next_image_request_id_(1),
current_index_(0),
base_timeline_(new QTimeLine(kBaseAnimationDuration, this)),
left_timeline_(new QTimeLine(kArrowAnimationDuration, this)),
right_timeline_(new QTimeLine(kArrowAnimationDuration, this))
right_timeline_(new QTimeLine(kArrowAnimationDuration, this)),
menu_(NULL)
{
setMouseTracking(true);
setMinimumHeight(kTotalHeight);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
connect(base_timeline_, SIGNAL(valueChanged(qreal)), SLOT(update()));
connect(left_timeline_, SIGNAL(valueChanged(qreal)), SLOT(update()));
connect(right_timeline_, SIGNAL(valueChanged(qreal)), SLOT(update()));
QSettings s;
s.beginGroup(kSettingsGroup);
last_save_dir_ = s.value("last_save_dir", QDir::homePath()).toString();
}
QRect PrettyImageView::left() const {
return QRect(0, 0, kArrowWidth, height());
return QRect(0, 0, kEdgeWidth, height());
}
QRect PrettyImageView::right() const {
return QRect(width() - kArrowWidth, 0, kArrowWidth, height());
return QRect(width() - kEdgeWidth, 0, kEdgeWidth, height());
}
QPolygon PrettyImageView::arrow(const QRect& rect, int direction) const {
QPoint point(direction > 0 ? rect.right() : rect.left(),
(rect.bottom() - rect.top()) / 2 + rect.top());
return QPolygon()
<< point
<< QPoint(point.x() - direction * kArrowWidth, point.y() - kArrowWidth)
<< QPoint(point.x() - direction * kArrowWidth, point.y() + kArrowWidth);
QRect PrettyImageView::middle() const {
return QRect(kEdgeWidth + kEdgePadding, kBorderHeight,
width() - (kEdgeWidth + kEdgePadding) * 2, kImageHeight - kBorderHeight);
}
void PrettyImageView::Clear() {
@ -112,37 +119,53 @@ void PrettyImageView::paintEvent(QPaintEvent*) {
p.setBrush(palette().color(QPalette::Highlight));
p.setPen(QPen(palette().color(QPalette::Text), 0.5));
// Draw left arrow
p.setOpacity(base_timeline_->currentValue() * (0.5 + left_timeline_->currentValue() * 0.5));
p.drawConvexPolygon(arrow(left(), -1));
const int next_index = current_index_ + 1;
const int prev_index = current_index_ - 1;
const int image_width = width() - kEdgeWidth * 2;
// Draw right arrow
p.setOpacity(base_timeline_->currentValue() * (0.5 + right_timeline_->currentValue() * 0.5));
p.drawConvexPolygon(arrow(right(), +1));
const qreal next_opacity = 0.5 + right_timeline_->currentValue() * 0.5;
const qreal prev_opacity = 0.5 + left_timeline_->currentValue() * 0.5;
// Draw the current image
if (current_index_ >= 0 && current_index_ < images_.count()) {
QRect rect(0, 0, width(), kImageHeight - kBorderHeight);
const QRect current_rect(kEdgeWidth + kEdgePadding, kBorderHeight,
image_width - kEdgePadding*2, kImageHeight - kBorderHeight);
const QRect next_rect(width() - kEdgeWidth, kBorderHeight,
image_width, kImageHeight - kBorderHeight);
const QRect prev_rect(-image_width + kEdgeWidth, kBorderHeight,
image_width, kImageHeight - kBorderHeight);
p.setOpacity(1.0);
DrawImage(&p, rect, images_[current_index_]);
}
// Draw the images
DrawImage(&p, current_rect, Qt::AlignHCenter, 1.0, current_index_);
DrawImage(&p, next_rect, Qt::AlignLeft, next_opacity, next_index);
DrawImage(&p, prev_rect, Qt::AlignRight, prev_opacity, prev_index);
}
void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, const Image& image) {
const int width = image.image_.isNull() ? rect.height() * 1.6 :
float(image.image_.width()) / image.image_.height() * rect.height();
void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, Qt::Alignment align,
qreal opacity, int image_index) {
if (image_index < 0 || image_index >= images_.count())
return;
const Image& image = images_[image_index];
// Center the image in the rectangle
QRect actual_rect(0, kBorderHeight, width, rect.height());
actual_rect.moveLeft((rect.width() - width) / 2);
QSize image_size = image.image_.isNull() ? QSize(100, 160) : image.image_.size();
// Scale the image rect to fit in the rectangle
image_size.scale(rect.size(), Qt::KeepAspectRatio);
// Center the image in the rectangle and move it to the bottom
QRect draw_rect(QPoint(0, 0), image_size);
if (align & Qt::AlignLeft)
draw_rect.moveBottomLeft(rect.bottomLeft());
else if (align & Qt::AlignRight)
draw_rect.moveBottomRight(rect.bottomRight());
else if (align & Qt::AlignHCenter)
draw_rect.moveBottomLeft(rect.bottomLeft() + QPoint((rect.width() - draw_rect.width()) / 2, 0));
// Draw the main image
DrawThumbnail(p, actual_rect, image);
p->setOpacity(opacity);
DrawThumbnail(p, draw_rect, image);
// Draw the reflection
// Figure out where to draw it
QRect reflection_rect(actual_rect);
QRect reflection_rect(draw_rect);
reflection_rect.moveTop(reflection_rect.bottom());
// Create the reflected pixmap
@ -153,7 +176,7 @@ void PrettyImageView::DrawImage(QPainter* p, const QRect& rect, const Image& ima
// Set up the transformation
QTransform transform;
transform.scale(1.0, -1.0);
transform.translate(0.0, -actual_rect.height());
transform.translate(0.0, -draw_rect.height());
reflection_painter.setTransform(transform);
QRect fade_rect(reflection.rect().bottomLeft() - QPoint(0, kTotalHeight - kImageHeight),
@ -192,20 +215,27 @@ void PrettyImageView::mouseReleaseEvent(QMouseEvent* e) {
current_index_ = qMax(0, current_index_ - 1);
else if (right().contains(e->pos()))
current_index_ = qMin(images_.count() - 1, current_index_ + 1);
else if (middle().contains(e->pos()))
ShowFullsize();
update();
}
void PrettyImageView::mouseMoveEvent(QMouseEvent* e) {
SetTimeLineActive(left_timeline_, left().contains(e->pos()));
SetTimeLineActive(right_timeline_, right().contains(e->pos()));
}
const bool in_left = left().contains(e->pos());
const bool in_right = right().contains(e->pos());
const bool in_middle = middle().contains(e->pos());
void PrettyImageView::enterEvent(QEvent*) {
SetTimeLineActive(base_timeline_, true);
SetTimeLineActive(left_timeline_, in_left);
SetTimeLineActive(right_timeline_, in_right);
setCursor((in_left || in_right || in_middle) ?
QCursor(Qt::PointingHandCursor) : QCursor());
}
void PrettyImageView::leaveEvent(QEvent*) {
SetTimeLineActive(base_timeline_, false);
SetTimeLineActive(left_timeline_, false);
SetTimeLineActive(right_timeline_, false);
}
void PrettyImageView::SetTimeLineActive(QTimeLine* timeline, bool active) {
@ -226,3 +256,69 @@ void PrettyImageView::Image::SetImage(const QImage& image) {
thumbnail_ = QPixmap::fromImage(image_.scaledToHeight(
kImageHeight, Qt::SmoothTransformation));
}
void PrettyImageView::contextMenuEvent(QContextMenuEvent* e) {
if (!middle().contains(e->pos()))
return;
if (current_index_ < 0 || current_index_ >= images_.count())
return;
if (!menu_) {
menu_ = new QMenu(this);
menu_->addAction(IconLoader::Load("zoom-in"), tr("Show fullsize..."),
this, SLOT(ShowFullsize()));
menu_->addAction(IconLoader::Load("document-save"), tr("Save image") + "...",
this, SLOT(SaveAs()));
}
menu_->popup(e->globalPos());
}
void PrettyImageView::ShowFullsize() {
if (current_index_ < 0 || current_index_ >= images_.count())
return;
const QImage& image = images_[current_index_].image_;
QScrollArea* window = new QScrollArea;
QLabel* label = new QLabel(window);
label->setPixmap(QPixmap::fromImage(image));
window->setWidget(label);
window->setAttribute(Qt::WA_DeleteOnClose, true);
window->setWindowTitle(tr("Clementine image viewer"));
window->resize(qMin(800, image.width() + 2), qMin(500, image.height() + 2));
window->show();
}
void PrettyImageView::SaveAs() {
if (current_index_ < 0 || current_index_ >= images_.count())
return;
const Image& image_data = images_[current_index_];
QString filename = QFileInfo(image_data.url_.path()).fileName();
QImage image = image_data.image_;
if (filename.isEmpty())
filename = "artwork.jpg";
QString path = last_save_dir_.isEmpty() ? QDir::homePath() : last_save_dir_;
QFileInfo path_info(path);
if (path_info.isDir()) {
path += "/" + filename;
} else {
path = path_info.path() + "/" + filename;
}
filename = QFileDialog::getSaveFileName(this, tr("Save image"), path);
if (filename.isEmpty())
return;
image.save(filename);
last_save_dir_ = filename;
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("last_save_dir", last_save_dir_);
}

View File

@ -23,6 +23,7 @@
class NetworkAccessManager;
class QMenu;
class QNetworkReply;
class QTimeLine;
@ -35,11 +36,14 @@ public:
static const int kTotalHeight;
static const int kImageHeight;
static const int kBorderHeight;
static const int kArrowWidth;
static const int kEdgeWidth;
static const int kEdgePadding;
static const int kBaseAnimationDuration;
static const int kArrowAnimationDuration;
static const char* kSettingsGroup;
public slots:
void Clear();
void AddImage(const QUrl& url);
@ -48,9 +52,13 @@ protected:
void paintEvent(QPaintEvent*);
void mouseMoveEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void enterEvent(QEvent*);
void contextMenuEvent(QContextMenuEvent*);
void leaveEvent(QEvent*);
private slots:
void ShowFullsize();
void SaveAs();
private:
struct Image {
Image(const QUrl& url) : loading_(false), url_(url) {}
@ -65,11 +73,11 @@ private:
QRect left() const;
QRect right() const;
QPolygon arrow(const QRect& rect, int direction) const;
QRect middle() const;
void SetTimeLineActive(QTimeLine* timeline, bool active);
void DrawImage(QPainter* p, const QRect& rect, const Image& image);
void DrawImage(QPainter* p, const QRect& rect, Qt::Alignment align, qreal opacity, int image_index);
void DrawThumbnail(QPainter* p, const QRect& rect, const Image& image);
private slots:
@ -84,9 +92,11 @@ private:
QList<Image> images_;
int current_index_;
QTimeLine* base_timeline_;
QTimeLine* left_timeline_;
QTimeLine* right_timeline_;
QMenu* menu_;
QString last_save_dir_;
};
#endif // PRETTYIMAGEVIEW_H