From 2511b5d13571a3ef8fe95705d6f6d2d95c9823f5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 12 Jun 2010 15:35:37 -0600 Subject: [PATCH] Cover Browser: Scale text size with height of cover browser. Only show a reflection of half the cover. Also Fix #5808 (Cover browser in 0.7.2 now has reduced quality images.) --- src/calibre/gui2/cover_flow.py | 1 - src/calibre/gui2/pictureflow/pictureflow.cpp | 36 ++++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/cover_flow.py b/src/calibre/gui2/cover_flow.py index f06d912a5d..6a9709cd8b 100644 --- a/src/calibre/gui2/cover_flow.py +++ b/src/calibre/gui2/cover_flow.py @@ -83,7 +83,6 @@ if pictureflow is not None: self.setFocusPolicy(Qt.WheelFocus) self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) - self.setZoomFactor(150) def sizeHint(self): return self.minimumSize() diff --git a/src/calibre/gui2/pictureflow/pictureflow.cpp b/src/calibre/gui2/pictureflow/pictureflow.cpp index 60985a1a12..58b6cd32e0 100644 --- a/src/calibre/gui2/pictureflow/pictureflow.cpp +++ b/src/calibre/gui2/pictureflow/pictureflow.cpp @@ -85,7 +85,9 @@ typedef long PFreal; typedef unsigned short QRgb565; -#define FONT_SIZE 18 +#define REFLECTION_FACTOR 1.5 + +#define MAX(x, y) ((x > y) ? x : y) #define RGB565_RED_MASK 0xF800 #define RGB565_GREEN_MASK 0x07E0 @@ -124,6 +126,7 @@ inline PFreal floatToFixed(float val) return (PFreal)(val*PFREAL_ONE); } +// sinTable {{{ #define IANGLE_MAX 1024 #define IANGLE_MASK 1023 @@ -293,6 +296,7 @@ int main(int, char**) return 0; } #endif +// }}} inline PFreal fsin(int iangle) { @@ -315,6 +319,8 @@ struct SlideInfo PFreal cy; }; +// PicturePlowPrivate {{{ + class PictureFlowPrivate { public: @@ -369,6 +375,7 @@ private: int slideWidth; int slideHeight; + int fontSize; int zoom; int queueLength; @@ -406,6 +413,7 @@ PictureFlowPrivate::PictureFlowPrivate(PictureFlow* w, int queueLength_) slideWidth = 200; slideHeight = 200; + fontSize = 10; zoom = 100; centerIndex = 0; @@ -542,8 +550,11 @@ void PictureFlowPrivate::showSlide(int index) void PictureFlowPrivate::resize(int w, int h) { - slideHeight = int(float(h)/2.); + if (w < 10) w = 10; + if (h < 10) h = 10; + slideHeight = int(float(h)/REFLECTION_FACTOR); slideWidth = int(float(slideHeight) * 2/3.); + fontSize = MAX(int(h/20.), 12); recalc(w, h); resetSlides(); triggerRender(); @@ -592,8 +603,8 @@ static QImage prepareSurface(QImage img, int w, int h) img = img.scaled(w, h, Qt::IgnoreAspectRatio, mode); // slightly larger, to accomodate for the reflection - int hs = h * 2; - int hofs = h / 3; + int hs = int(h * REFLECTION_FACTOR); + int hofs = 0; // offscreen buffer: black is sweet QImage result(hs, w, QImage::Format_RGB16); @@ -715,13 +726,13 @@ void PictureFlowPrivate::render() QFont font = QFont(); font.setBold(true); - font.setPointSize(FONT_SIZE); + font.setPixelSize(fontSize); painter.setFont(font); painter.setPen(Qt::white); //painter.setPen(QColor(255,255,255,127)); if (centerIndex < slideCount() && centerIndex > -1) - painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2-FONT_SIZE*3), + painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2-fontSize*3), Qt::AlignCenter, slideImages->caption(centerIndex)); painter.end(); @@ -766,7 +777,7 @@ void PictureFlowPrivate::render() QFont font = QFont(); font.setBold(true); - font.setPointSize(FONT_SIZE); + font.setPixelSize(fontSize); painter.setFont(font); int leftTextIndex = (step>0) ? centerIndex : centerIndex-1; @@ -774,12 +785,12 @@ void PictureFlowPrivate::render() painter.setPen(QColor(255,255,255, (255-fade) )); if (leftTextIndex < sc && leftTextIndex > -1) - painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - FONT_SIZE*3), + painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*3), Qt::AlignCenter, slideImages->caption(leftTextIndex)); painter.setPen(QColor(255,255,255, fade)); if (leftTextIndex+1 < sc && leftTextIndex > -2) - painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - FONT_SIZE*3), + painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*3), Qt::AlignCenter, slideImages->caption(leftTextIndex+1)); @@ -893,7 +904,7 @@ int col1, int col2) int center = (sh*BILINEAR_STRETCH_VER/2); int dy = dist*BILINEAR_STRETCH_VER / h; #else - int center = (sh/2); + int center = sh/2; int dy = dist / h; #endif int p1 = center*PFREAL_ONE - dy/2; @@ -1110,8 +1121,9 @@ void PictureFlowPrivate::clearSurfaceCache() surfaceCache.clear(); } -// ----------------------------------------- +// }}} +// PictureFlow {{{ PictureFlow::PictureFlow(QWidget* parent, int queueLength): QWidget(parent) { d = new PictureFlowPrivate(this, queueLength); @@ -1387,3 +1399,5 @@ void PictureFlow::emitcurrentChanged(int index) { emit currentChanged(index); } int FlowImages::count() { return 0; } QImage FlowImages::image(int index) { index=0; return QImage(); } QString FlowImages::caption(int index) {index=0; return QString(); } + +// }}}