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); ui->setupUi(this);
setup(); 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) void BoardPostDisplayWidget::setCommentsSize(int comNb)

View File

@ -7,11 +7,11 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>758</width> <width>758</width>
<height>195</height> <height>190</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -22,18 +22,41 @@
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"/> <string notr="true"/>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <property name="spacing">
<layout class="QHBoxLayout" name="horizontalLayout_6"> <number>0</number>
<item> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <property name="leftMargin">
<property name="sizeConstraint"> <number>0</number>
<enum>QLayout::SetMinimumSize</enum> </property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property> </property>
<item> <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> <item>
<layout class="QVBoxLayout" name="arrowsLayout"> <layout class="QVBoxLayout" name="arrowsLayout">
<item> <item>
@ -113,28 +136,11 @@
<property name="text"> <property name="text">
<string>PictureLabel_compact</string> <string>PictureLabel_compact</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget> </widget>
</item> </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> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint"> <property name="sizeConstraint">
@ -452,6 +458,9 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
</layout>
</widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>GxsIdLabel</class> <class>GxsIdLabel</class>

View File

@ -87,36 +87,15 @@ void PostedPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
BoardPostDisplayWidget w(post,mDisplayMode); BoardPostDisplayWidget w(post,mDisplayMode);
//w.setMaximumWidth(mCellWidthPix);
//w.setMinimumWidth(mCellWidthPix);
w.adjustSize(); w.adjustSize();
w.setFixedSize(option.rect.size());
w.setFixedSize(cellSize(w.size()));
QPixmap pixmap(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 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 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 #ifdef TODO
if(IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) 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 #endif
// debug // // debug
if(index.row()==0 && index.column()==0) // if(index.row()==0 && index.column()==0)
{ // {
QFile file("yourFile.png"); // QFile file("yourFile.png");
file.open(QIODevice::WriteOnly); // file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG"); // pixmap.save(&file, "PNG");
std::cerr << "Saved pxmap to png" << std::endl; // 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; //std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl;
painter->save(); 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->drawPixmap(option.rect.topLeft(), pixmap /*,.scaled(option.rect.width(),option.rect.width()*w.height()/(float)w.width(),Qt::KeepAspectRatio,Qt::SmoothTransformation)*/);
painter->restore(); 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 // This is the only place where we actually set the size of cells
RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ; RsPostedPost post = index.data(Qt::UserRole).value<RsPostedPost>() ;
BoardPostDisplayWidget w(post,mDisplayMode); BoardPostDisplayWidget w(post,mDisplayMode);
//w.setMinimumWidth(mCellWidthPix);
//w.setMaximumWidth(mCellWidthPix);
w.adjustSize(); 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(); return w.size();
} }
@ -184,12 +145,9 @@ QWidget *PostedPostDelegate::createEditor(QWidget *parent, const QStyleOptionVie
{ {
QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent); QWidget *w = new BoardPostDisplayWidget(post,mDisplayMode,parent);
//w->setMinimumWidth(mCellWidthPix);
//w->setMaximumWidth(mCellWidthPix);
w->adjustSize(); w->adjustSize();
w->setFixedSize(cellSize(w->size())); w->setFixedSize(option.rect.size());
std::cerr << "PostedPostDelegate::createEditor(): size = " << w->size() << std::endl;
return w; return w;
} }
else else
@ -281,11 +239,13 @@ void PostedListWidgetWithModel::switchDisplayMode()
{ {
whileBlocking(ui->cardViewButton)->setChecked(false); whileBlocking(ui->cardViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_COMPACT);
ui->postsTree->setUniformRowHeights(true);
} }
else else
{ {
whileBlocking(ui->classicViewButton)->setChecked(false); whileBlocking(ui->classicViewButton)->setChecked(false);
mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW); mPostedPostsDelegate->setDisplayMode(BoardPostDisplayWidget::DISPLAY_MODE_CARD_VIEW);
ui->postsTree->setUniformRowHeights(false);
} }
mPostedPostsModel->deepUpdate(); mPostedPostsModel->deepUpdate();