Fix #816595 (Long titles do not wrap in cover browser)

This commit is contained in:
Kovid Goyal 2011-07-27 13:33:43 -06:00
parent 2144e84dd2
commit 889799dab6
2 changed files with 35 additions and 14 deletions

View File

@ -29,12 +29,14 @@ if pictureflow is not None:
pictureflow.FlowImages.__init__(self) pictureflow.FlowImages.__init__(self)
self.images = [] self.images = []
self.captions = [] self.captions = []
self.subtitles = []
for f in os.listdir(dirpath): for f in os.listdir(dirpath):
f = os.path.join(dirpath, f) f = os.path.join(dirpath, f)
img = QImage(f) img = QImage(f)
if not img.isNull(): if not img.isNull():
self.images.append(img) self.images.append(img)
self.captions.append(os.path.basename(f)) self.captions.append(os.path.basename(f))
self.subtitles.append('%d bytes'%os.stat(f).st_size)
def count(self): def count(self):
return len(self.images) return len(self.images)
@ -45,6 +47,9 @@ if pictureflow is not None:
def caption(self, index): def caption(self, index):
return self.captions[index] return self.captions[index]
def subtitle(self, index):
return self.subtitles[index]
def currentChanged(self, index): def currentChanged(self, index):
print 'current changed:', index print 'current changed:', index

View File

@ -99,6 +99,8 @@ typedef unsigned short QRgb565;
#define PFREAL_ONE (1 << PFREAL_SHIFT) #define PFREAL_ONE (1 << PFREAL_SHIFT)
#define PFREAL_HALF (PFREAL_ONE >> 1) #define PFREAL_HALF (PFREAL_ONE >> 1)
#define TEXT_FLAGS (Qt::TextWordWrap|Qt::TextWrapAnywhere|Qt::TextHideMnemonic|Qt::AlignCenter)
inline PFreal fmul(PFreal a, PFreal b) inline PFreal fmul(PFreal a, PFreal b)
{ {
return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT; return ((long long)(a))*((long long)(b)) >> PFREAL_SHIFT;
@ -401,6 +403,7 @@ private:
QImage* surface(int slideIndex); QImage* surface(int slideIndex);
void triggerRender(); void triggerRender();
void resetSlides(); void resetSlides();
void render_text(QPainter*, int);
}; };
PictureFlowPrivate::PictureFlowPrivate(PictureFlow* w, int queueLength_) PictureFlowPrivate::PictureFlowPrivate(PictureFlow* w, int queueLength_)
@ -663,6 +666,30 @@ void PictureFlowPrivate::triggerRender()
triggerTimer.start(); triggerTimer.start();
} }
void PictureFlowPrivate::render_text(QPainter *painter, int index) {
QRect brect, brect2;
int buffer_width, buffer_height;
QString caption, subtitle;
caption = slideImages->caption(index);
subtitle = slideImages->subtitle(index);
buffer_width = buffer.width(); buffer_height = buffer.height();
brect = painter->boundingRect(QRect(0, 0, buffer_width, fontSize), TEXT_FLAGS, caption);
brect2 = painter->boundingRect(QRect(0, 0, buffer_width, fontSize), TEXT_FLAGS, subtitle);
// So that if there is no subtitle, the caption is not flush with the bottom
if (brect2.height() < fontSize) brect2.setHeight(fontSize);
brect.moveTop(buffer_height - (brect.height() + brect2.height()));
//printf("top: %d, height: %d\n", brect.top(), brect.height());
//
painter->drawText(brect, TEXT_FLAGS, caption);
brect2.moveTop(buffer_height - brect2.height());
painter->drawText(brect2, TEXT_FLAGS, slideImages->subtitle(index));
}
// Render the slides. Updates only the offscreen buffer. // Render the slides. Updates only the offscreen buffer.
void PictureFlowPrivate::render() void PictureFlowPrivate::render()
{ {
@ -708,10 +735,7 @@ void PictureFlowPrivate::render()
//painter.setPen(QColor(255,255,255,127)); //painter.setPen(QColor(255,255,255,127));
if (centerIndex < slideCount() && centerIndex > -1) { if (centerIndex < slideCount() && centerIndex > -1) {
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2-fontSize*4), render_text(&painter, centerIndex);
Qt::AlignCenter, slideImages->caption(centerIndex));
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2-fontSize*2),
Qt::AlignCenter, slideImages->subtitle(centerIndex));
} }
painter.end(); painter.end();
@ -764,20 +788,12 @@ void PictureFlowPrivate::render()
painter.setPen(QColor(255,255,255, (255-fade) )); painter.setPen(QColor(255,255,255, (255-fade) ));
if (leftTextIndex < sc && leftTextIndex > -1) { if (leftTextIndex < sc && leftTextIndex > -1) {
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*4), render_text(&painter, leftTextIndex);
Qt::AlignCenter, slideImages->caption(leftTextIndex));
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*2),
Qt::AlignCenter, slideImages->subtitle(leftTextIndex));
} }
painter.setPen(QColor(255,255,255, fade)); painter.setPen(QColor(255,255,255, fade));
if (leftTextIndex+1 < sc && leftTextIndex > -2) { if (leftTextIndex+1 < sc && leftTextIndex > -2) {
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*4), render_text(&painter, leftTextIndex+1);
Qt::AlignCenter, slideImages->caption(leftTextIndex+1));
painter.drawText( QRect(0,0, buffer.width(), buffer.height()*2 - fontSize*2),
Qt::AlignCenter, slideImages->subtitle(leftTextIndex+1));
} }
painter.end(); painter.end();