fixed the size problem in boards UI

This commit is contained in:
csoler 2020-08-11 16:00:49 +02:00
parent 6f1e1f8523
commit ddd4ac8087
3 changed files with 424 additions and 449 deletions

View File

@ -51,6 +51,12 @@ BoardPostDisplayWidget::BoardPostDisplayWidget(const RsPostedPost& post,DisplayM
{
ui->setupUi(this);
setup();
ui->verticalLayout->addStretch();
ui->verticalLayout->setAlignment(Qt::AlignTop);
ui->topLayout->setAlignment(Qt::AlignTop);
ui->arrowsLayout->addStretch();
ui->arrowsLayout->setAlignment(Qt::AlignTop);
}
void BoardPostDisplayWidget::setCommentsSize(int comNb)

View File

@ -7,11 +7,11 @@
<x>0</x>
<y>0</y>
<width>758</width>
<height>195</height>
<height>190</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -22,18 +22,41 @@
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="topLayout">
<item>
<layout class="QVBoxLayout" name="arrowsLayout">
<item>
@ -113,28 +136,11 @@
<property name="text">
<string>PictureLabel_compact</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
@ -452,6 +458,9 @@
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdLabel</class>

View File

@ -87,36 +87,15 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
BoardPostDisplayWidget w(post,mDisplayMode);
//w.setMaximumWidth(mCellWidthPix);
//w.setMinimumWidth(mCellWidthPix);
w.adjustSize();
w.setFixedSize(cellSize(w.size()));
w.setFixedSize(option.rect.size());
QPixmap pixmap(option.rect.size());
#ifdef SUSPENDED_CODE
if((option.state & QStyle::State_Selected) && post.mMeta.mPublishTs > 0) // check if post is selected and is not empty (end of last row)
pixmap.fill(QRgb(0xff308dc7)); // I dont know how to grab the backgroud color for selected objects automatically.
else
#endif
pixmap.fill(QRgb(0x00f0f0f0)); // choose a fully transparent background
#ifdef TESTING
{
QPainter W(&pixmap);
QLinearGradient m_gradient(0,0,pixmap.width(),0);
m_gradient.setColorAt(0.0, QRgb(0xff390e90));
m_gradient.setColorAt(1.0, QRgb(0xff09feff));
W.fillRect(pixmap.rect(), m_gradient);
w.render(&W,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
}
#endif
w.render(&pixmap,QPoint(0,0),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
std::cerr << "PostedPostDelegate::paint(): w.size() = " << w.size() << std::endl;
#ifdef TODO
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus))
{
@ -126,25 +105,17 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
}
#endif
// debug
if(index.row()==0 && index.column()==0)
{
QFile file("yourFile.png");
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG");
std::cerr << "Saved pxmap to png" << std::endl;
}
// // debug
// if(index.row()==0 && index.column()==0)
// {
// QFile file("yourFile.png");
// file.open(QIODevice::WriteOnly);
// pixmap.save(&file, "PNG");
// std::cerr << "Saved pxmap to png" << std::endl;
// }
//std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl;
painter->save();
// Is this necessary?
//
// painter->setRenderHint( QPainter::Antialiasing,true);
// painter->setRenderHint( QPainter::TextAntialiasing,true);
// painter->setRenderHint( QPainter::SmoothPixmapTransform,true);
// painter->setRenderHint( QPainter::HighQualityAntialiasing,true);
painter->drawPixmap(option.rect.topLeft(), pixmap /*,.scaled(option.rect.width(),option.rect.width()*w.height()/(float)w.width(),Qt::KeepAspectRatio,Qt::SmoothTransformation)*/);
painter->restore();
}
@ -159,20 +130,10 @@ QSize PostedPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QMo
// This is the only place where we actually set the size of cells
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
BoardPostDisplayWidget w(post,mDisplayMode);
//w.setMinimumWidth(mCellWidthPix);
//w.setMaximumWidth(mCellWidthPix);
w.adjustSize();
QSize ss = cellSize(w.size());
std::cerr << "PostedPostDelegate::sizeHint(): w =" << w.width() << " x " << w.height() << " new size = " << ss.width() << " x " << ss.height() ;
w.setFixedSize(ss);
std::cerr << " Final size:" << w.size() << std::endl;
return w.size();
}
@ -184,12 +145,9 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
{
QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent);
//w->setMinimumWidth(mCellWidthPix);
//w->setMaximumWidth(mCellWidthPix);
w->adjustSize();
w->setFixedSize(cellSize(w->size()));
w->setFixedSize(option.rect.size());
std::cerr << "PostedPostDelegate::createEditor(): size = " << w->size() << std::endl;
return w;
}
else
@ -281,11 +239,13 @@ void PostedListWidgetWithModel::switchDisplayMode()
{
whileBlocking(ui->cardViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT);
ui->postsTree->setUniformRowHeights(true);
}
else
{
whileBlocking(ui->classicViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW);
ui->postsTree->setUniformRowHeights(false);
}
mPostedPostsModel->deepUpdate();