fixed ratio and added space between list elements

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent 8b333c21b9
commit 5e8a461474
  1. 7
      src/customWidgets/UBWidgetList.cpp
  2. 3
      src/customWidgets/UBWidgetList.h

@ -5,6 +5,7 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation,
, mpLayout(NULL) , mpLayout(NULL)
, mpContainer(NULL) , mpContainer(NULL)
, mMargin(5) , mMargin(5)
, mListElementsSpacing(10)
, mpEmptyLabel(NULL) , mpEmptyLabel(NULL)
{ {
setObjectName(name); setObjectName(name);
@ -75,7 +76,8 @@ void UBWidgetList::removeWidget(QWidget *widget)
int UBWidgetList::scaleWidgets(QSize pSize) int UBWidgetList::scaleWidgets(QSize pSize)
{ {
int result = 0; // to remove the first spacing that shouldn't be there.
int result = -mListElementsSpacing;
int count = 0; int count = 0;
foreach(QWidget* eachWidget, mWidgetInfo.keys()){ foreach(QWidget* eachWidget, mWidgetInfo.keys()){
qreal scaleFactor = 0; qreal scaleFactor = 0;
@ -85,6 +87,7 @@ int UBWidgetList::scaleWidgets(QSize pSize)
scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width(); scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width();
newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor; newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor;
result += newWidgetHeight; result += newWidgetHeight;
eachWidget->setMinimumHeight(newWidgetHeight);
} }
else{ else{
scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height(); scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height();
@ -99,6 +102,8 @@ int UBWidgetList::scaleWidgets(QSize pSize)
qDebug() << __PRETTY_FUNCTION__ << "scale factor " << scaleFactor; qDebug() << __PRETTY_FUNCTION__ << "scale factor " << scaleFactor;
qDebug() << __PRETTY_FUNCTION__ << "new height " << result; qDebug() << __PRETTY_FUNCTION__ << "new height " << result;
#endif #endif
//Adding a vertical/horizontal space between each element of the list
result += mListElementsSpacing;
} }
return result; return result;
} }

@ -29,6 +29,8 @@ public:
void setEmptyText(const QString& text); void setEmptyText(const QString& text);
int margin(); int margin();
bool empty(); bool empty();
void setListElementSpacing(int margin) { mListElementsSpacing = margin; }
int listElementsSpacing() {return mListElementsSpacing; }
protected: protected:
void resizeEvent(QResizeEvent* ev); void resizeEvent(QResizeEvent* ev);
@ -41,6 +43,7 @@ private:
QWidget* mpContainer; QWidget* mpContainer;
eWidgetListOrientation mOrientation; eWidgetListOrientation mOrientation;
int mMargin; int mMargin;
int mListElementsSpacing;
QMap<QWidget*,QSize> mWidgetInfo; QMap<QWidget*,QSize> mWidgetInfo;
QLabel* mpEmptyLabel; QLabel* mpEmptyLabel;
}; };

Loading…
Cancel
Save