mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-23 22:01:05 -05:00
fixed layout of compact view to use a constant apsect ratio with cropping
This commit is contained in:
parent
d3cb789fcd
commit
5c240c6abb
@ -43,6 +43,8 @@
|
|||||||
|
|
||||||
#define LINK_IMAGE ":/images/thumb-link.png"
|
#define LINK_IMAGE ":/images/thumb-link.png"
|
||||||
|
|
||||||
|
// #ifdef DEBUG_BOARDPOSTDISPLAYWIDGET 1
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
|
|
||||||
const char *BoardPostDisplayWidget_compact::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2.png";
|
const char *BoardPostDisplayWidget_compact::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2.png";
|
||||||
@ -119,7 +121,9 @@ void BoardPostDisplayWidgetBase::setReadStatus(bool isNew, bool isUnread)
|
|||||||
|
|
||||||
void BoardPostDisplayWidget_compact::doExpand(bool e)
|
void BoardPostDisplayWidget_compact::doExpand(bool e)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_BOARDPOSTDISPLAYWIDGET
|
||||||
std::cerr << "Expanding" << std::endl;
|
std::cerr << "Expanding" << std::endl;
|
||||||
|
#endif
|
||||||
if(e)
|
if(e)
|
||||||
ui->frame_notes->show();
|
ui->frame_notes->show();
|
||||||
else
|
else
|
||||||
@ -335,6 +339,7 @@ void BoardPostDisplayWidget_compact::setup()
|
|||||||
// show/hide things based on the view type
|
// show/hide things based on the view type
|
||||||
|
|
||||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||||
|
ui->pictureLabel->setEnableZoom(false);
|
||||||
|
|
||||||
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
|
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
|
||||||
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
|
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
|
||||||
@ -350,10 +355,15 @@ void BoardPostDisplayWidget_compact::setup()
|
|||||||
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
||||||
// Wiping data - as its been passed to thumbnail.
|
// Wiping data - as its been passed to thumbnail.
|
||||||
|
|
||||||
int desired_height = QFontMetricsF(font()).height() * 5;
|
#ifdef DEBUG_BOARDPOSTDISPLAYWIDGET
|
||||||
|
std::cerr << "Got pixmap of size " << pixmap.width() << " x " << pixmap.height() << std::endl;
|
||||||
|
std::cerr << "Saving to pix.png" << std::endl;
|
||||||
|
pixmap.save("pix.png","PNG");
|
||||||
|
#endif
|
||||||
|
|
||||||
QPixmap scaledpixmap = pixmap.scaledToHeight(desired_height, Qt::SmoothTransformation);
|
int desired_height = QFontMetricsF(font()).height() * 5;
|
||||||
ui->pictureLabel->setPixmap(scaledpixmap);
|
ui->pictureLabel->setFixedSize(16/9.0*desired_height,desired_height);
|
||||||
|
ui->pictureLabel->setPicture(pixmap);
|
||||||
}
|
}
|
||||||
else if (mPost.mImage.mData == NULL)
|
else if (mPost.mImage.mData == NULL)
|
||||||
ui->pictureLabel->hide();
|
ui->pictureLabel->hide();
|
||||||
@ -465,13 +475,12 @@ void BoardPostDisplayWidget_card::setup()
|
|||||||
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
|
||||||
// Wiping data - as its been passed to thumbnail.
|
// Wiping data - as its been passed to thumbnail.
|
||||||
|
|
||||||
|
|
||||||
QPixmap scaledpixmap;
|
QPixmap scaledpixmap;
|
||||||
if(pixmap.width() > 800){
|
if(pixmap.width() > 800){
|
||||||
QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation);
|
QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation);
|
||||||
pictureLabel()->setPixmap(scaledpixmap);
|
ui->pictureLabel->setPixmap(scaledpixmap);
|
||||||
}else{
|
}else{
|
||||||
pictureLabel()->setPixmap(pixmap);
|
ui->pictureLabel->setPixmap(pixmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mPost.mImage.mData == NULL)
|
else if (mPost.mImage.mData == NULL)
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="ClickableLabel" name="pictureLabel">
|
<widget class="ZoomableLabel" name="pictureLabel">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -311,55 +311,6 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="newLabel">
|
|
||||||
<property name="text">
|
|
||||||
<string>New</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QToolButton" name="readButton">
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>24</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="focusPolicy">
|
|
||||||
<enum>Qt::NoFocus</enum>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Toggle Message Read Status</string>
|
|
||||||
</property>
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../images.qrc">
|
|
||||||
<normaloff>:/images/message-state-unread.png</normaloff>:/images/message-state-unread.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="checkable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="autoRaise">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="commentButton">
|
<widget class="QToolButton" name="commentButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -414,6 +365,55 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="readButton">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>24</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Toggle Message Read Status</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../images.qrc">
|
||||||
|
<normaloff>:/images/message-state-unread.png</normaloff>:/images/message-state-unread.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="newLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>New</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@ -489,9 +489,9 @@
|
|||||||
<header>gui/common/StyledLabel.h</header>
|
<header>gui/common/StyledLabel.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ClickableLabel</class>
|
<class>ZoomableLabel</class>
|
||||||
<extends>QLabel</extends>
|
<extends>QLabel</extends>
|
||||||
<header>util/ClickableLabel.h</header>
|
<header>gui/gxschannels/GxsChannelPostThumbnail.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -99,6 +99,8 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
|||||||
BoardPostDisplayWidget_compact w(post,displayFlags(post.mMeta.mMsgId),nullptr);
|
BoardPostDisplayWidget_compact w(post,displayFlags(post.mMeta.mMsgId),nullptr);
|
||||||
|
|
||||||
w.setFixedSize(option.rect.size());
|
w.setFixedSize(option.rect.size());
|
||||||
|
|
||||||
|
w.updateGeometry();
|
||||||
w.adjustSize();
|
w.adjustSize();
|
||||||
w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
||||||
}
|
}
|
||||||
@ -107,6 +109,7 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
|||||||
BoardPostDisplayWidget_card w(post,displayFlags(post.mMeta.mMsgId),nullptr);
|
BoardPostDisplayWidget_card w(post,displayFlags(post.mMeta.mMsgId),nullptr);
|
||||||
|
|
||||||
w.setFixedSize(option.rect.size());
|
w.setFixedSize(option.rect.size());
|
||||||
|
w.updateGeometry();
|
||||||
w.adjustSize();
|
w.adjustSize();
|
||||||
w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
||||||
}
|
}
|
||||||
@ -198,6 +201,8 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
|
|||||||
|
|
||||||
w->setFixedSize(option.rect.size());
|
w->setFixedSize(option.rect.size());
|
||||||
w->adjustSize();
|
w->adjustSize();
|
||||||
|
w->updateGeometry();
|
||||||
|
w->adjustSize();
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,16 @@
|
|||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "gui/common/FilesDefs.h"
|
#include "gui/common/FilesDefs.h"
|
||||||
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
||||||
|
|
||||||
|
// #define DEBUG_GXSCHANNELPOSTTHUMBNAIL 1
|
||||||
|
|
||||||
const float ChannelPostThumbnailView::DEFAULT_SIZE_IN_FONT_HEIGHT = 5.0;
|
const float ChannelPostThumbnailView::DEFAULT_SIZE_IN_FONT_HEIGHT = 5.0;
|
||||||
const float ChannelPostThumbnailView::FONT_SCALE_FACTOR = 1.5;
|
const float ChannelPostThumbnailView::FONT_SCALE_FACTOR = 1.5;
|
||||||
|
|
||||||
@ -50,7 +54,9 @@ void ChannelPostThumbnailView::setText(const QString& s)
|
|||||||
{
|
{
|
||||||
if(mPostTitle == NULL)
|
if(mPostTitle == NULL)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_GXSCHANNELPOSTTHUMBNAIL
|
||||||
std::cerr << "(EE) calling setText on a ChannelPostThumbnailView without SHOW_TEXT flag!"<< std::endl;
|
std::cerr << "(EE) calling setText on a ChannelPostThumbnailView without SHOW_TEXT flag!"<< std::endl;
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,6 +252,8 @@ void ZoomableLabel::mousePressEvent(QMouseEvent *me)
|
|||||||
mMoving = true;
|
mMoving = true;
|
||||||
mLastX = me->x();
|
mLastX = me->x();
|
||||||
mLastY = me->y();
|
mLastY = me->y();
|
||||||
|
|
||||||
|
emit clicked();
|
||||||
}
|
}
|
||||||
void ZoomableLabel::mouseReleaseEvent(QMouseEvent *)
|
void ZoomableLabel::mouseReleaseEvent(QMouseEvent *)
|
||||||
{
|
{
|
||||||
@ -292,7 +300,11 @@ QPixmap ZoomableLabel::extractCroppedScaledPicture() const
|
|||||||
|
|
||||||
void ZoomableLabel::setPicture(const QPixmap& pix)
|
void ZoomableLabel::setPicture(const QPixmap& pix)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_GXSCHANNELPOSTTHUMBNAIL
|
||||||
|
std::cerr << "Setting new picture of size " << pix.width() << " x " << pix.height() << std::endl;
|
||||||
|
#endif
|
||||||
mFullImage = pix;
|
mFullImage = pix;
|
||||||
|
setScaledContents(true);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
updateView();
|
updateView();
|
||||||
@ -312,7 +324,15 @@ void ZoomableLabel::updateView()
|
|||||||
// - the original center is preferred
|
// - the original center is preferred
|
||||||
// - if the crop overlaps the image border, the center is moved.
|
// - if the crop overlaps the image border, the center is moved.
|
||||||
|
|
||||||
QRect rect(mCenterX - 0.5 * width()*mZoomFactor, mCenterY - 0.5 * height()*mZoomFactor, width()*mZoomFactor, height()*mZoomFactor);
|
QRect rect(mCenterX - 0.5 * width()*mZoomFactor, mCenterY - 0.5 * height()*mZoomFactor, floor(width()*mZoomFactor), floor(height()*mZoomFactor));
|
||||||
|
|
||||||
|
#ifdef DEBUG_GXSCHANNELPOSTTHUMBNAIL
|
||||||
|
std::cerr << "Updating view: mCenterX=" << mCenterX << ", mCenterY=" << mCenterY << ", mZoomFactor=" << mZoomFactor << std::endl;
|
||||||
|
std::cerr << " Image size: " << mFullImage.width() << " x " << mFullImage.height() << ", window size: " << width() << " x " << height() << std::endl;
|
||||||
|
std::cerr << " cropped image: " << rect.left() << "," << rect.top() << "+" << rect.width() << "+" << rect.height() << std::endl;
|
||||||
|
std::cerr << " saving crop to pix2.png" << std::endl;
|
||||||
|
mFullImage.copy(rect).save("pix2.png","PNG");
|
||||||
|
#endif
|
||||||
QLabel::setPixmap(mFullImage.copy(rect));
|
QLabel::setPixmap(mFullImage.copy(rect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
class ZoomableLabel: public QLabel
|
class ZoomableLabel: public QLabel
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZoomableLabel(QWidget *parent): QLabel(parent),mZoomFactor(1.0),mCenterX(0.0),mCenterY(0.0),mZoomEnabled(true) {}
|
ZoomableLabel(QWidget *parent): QLabel(parent),mZoomFactor(1.0),mCenterX(0.0),mCenterY(0.0),mZoomEnabled(true) {}
|
||||||
|
|
||||||
@ -48,6 +50,9 @@ public:
|
|||||||
|
|
||||||
const QPixmap& originalImage() const { return mFullImage ; }
|
const QPixmap& originalImage() const { return mFullImage ; }
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void clicked();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *ev) override;
|
void mousePressEvent(QMouseEvent *ev) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *ev) override;
|
void mouseReleaseEvent(QMouseEvent *ev) override;
|
||||||
@ -57,9 +62,9 @@ protected:
|
|||||||
|
|
||||||
QPixmap mFullImage;
|
QPixmap mFullImage;
|
||||||
|
|
||||||
|
float mZoomFactor;
|
||||||
float mCenterX;
|
float mCenterX;
|
||||||
float mCenterY;
|
float mCenterY;
|
||||||
float mZoomFactor;
|
|
||||||
int mLastX,mLastY;
|
int mLastX,mLastY;
|
||||||
bool mMoving;
|
bool mMoving;
|
||||||
bool mZoomEnabled;
|
bool mZoomEnabled;
|
||||||
|
@ -37,7 +37,7 @@ signals:
|
|||||||
void clicked();
|
void clicked();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
void enterEvent(QEvent * /* ev */ ) override { if(mUseStyleSheet) setStyleSheet("QLabel { border: 2px solid #039bd5; }");}
|
void enterEvent(QEvent * /* ev */ ) override { if(mUseStyleSheet) setStyleSheet("QLabel { border: 2px solid #039bd5; }");}
|
||||||
void leaveEvent(QEvent * /* ev */ ) override { if(mUseStyleSheet) setStyleSheet("QLabel { border: 2px solid #CCCCCC; border-radius: 3px; }");}
|
void leaveEvent(QEvent * /* ev */ ) override { if(mUseStyleSheet) setStyleSheet("QLabel { border: 2px solid #CCCCCC; border-radius: 3px; }");}
|
||||||
|
Loading…
Reference in New Issue
Block a user