From bac4c4caac970f231c7e4a6f6efafdc7a25b4431 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 5 Jan 2012 10:59:23 +0100 Subject: [PATCH] first draft for fixing resize problem --- src/customWidgets/UBWidgetList.cpp | 41 ++++++++++++++++-------------- src/gui/UBTeacherBarWidget.cpp | 17 ++++++++----- src/gui/UBTeacherBarWidget.h | 2 +- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/customWidgets/UBWidgetList.cpp b/src/customWidgets/UBWidgetList.cpp index fa3ce3ed..667d8908 100644 --- a/src/customWidgets/UBWidgetList.cpp +++ b/src/customWidgets/UBWidgetList.cpp @@ -50,9 +50,9 @@ void UBWidgetList::addWidget(QWidget *widget) { if(NULL != mpLayout){ mpEmptyLabel->setVisible(false); + mWidgets << widget; updateSize(true, widget); mpLayout->addWidget(widget); - mWidgets << widget; } } @@ -76,34 +76,31 @@ void UBWidgetList::updateSize(bool widgetAdded, QWidget *widget) int newWidgetHeight; if(eWidgetListOrientation_Vertical == mOrientation){ - scaleFactor = (float)mpContainer->width() / (float)widget->width(); + scaleFactor = (float)widget->width() / (float)mpContainer->width(); }else{ - scaleFactor = (float)mpContainer->height() / (float)widget->height(); + scaleFactor = (float)widget->height() / (float)mpContainer->height(); } - newWidgetWidth = (int)((float)widget->width()*scaleFactor); - newWidgetHeight = (int)((float)widget->height()*scaleFactor); - - qDebug() << "container size " << mpContainer->size(); - qDebug() << "widget size " << widget->size(); - qDebug() << "scale factor " << scaleFactor; - + newWidgetWidth = widget->width()/scaleFactor; + newWidgetHeight = widget->height()/scaleFactor; widget->resize(newWidgetWidth, newWidgetHeight); - qDebug() << "widget new value " << newWidgetWidth << "x" << newWidgetHeight; // Now we have to update the container if(eWidgetListOrientation_Vertical == mOrientation){ if(widgetAdded){ mpContainer->resize(mpContainer->width(), mpContainer->height() + newWidgetHeight); - }else{ + } + else{ mpContainer->resize(mpContainer->width(), mpContainer->height() - newWidgetHeight); } - }else{ + } + else{ if(widgetAdded){ mpContainer->resize(mpContainer->width() + newWidgetWidth, mpContainer->height()); - }else{ + } + else{ mpContainer->resize(mpContainer->width() - newWidgetWidth, mpContainer->height()); } } @@ -119,12 +116,17 @@ void UBWidgetList::resizeEvent(QResizeEvent *ev) float scale; if(eWidgetListOrientation_Vertical == mOrientation){ scale = (float)ev->size().width() / (float)ev->oldSize().width(); - updateAllWidgetsize(scale); - mpContainer->resize(width() - 2, mpContainer->height()*scale); - }else{ + if(scale != 0 && scale < 10){ + updateAllWidgetsize(scale); + mpContainer->resize(width() - 2, mpContainer->height()*scale); + } + } + else{ scale = (float)ev->size().height() / (float)ev->oldSize().height(); - updateAllWidgetsize(scale); - mpContainer->resize(mpContainer->width()*scale, height() - 2); + if(scale != 0 && scale < 10){ + updateAllWidgetsize(scale); + mpContainer->resize(mpContainer->width()*scale, height() - 2); + } } } } @@ -154,3 +156,4 @@ void UBWidgetList::setEmptyText(const QString &text) } // TODO : - add onHover 'delete' button + diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 3a682e8a..d65e41fe 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -112,7 +112,7 @@ UBTeacherBarWidget::UBTeacherBarWidget(QWidget *parent, const char *name):UBDock // Media mpMediaLabel = new QLabel(tr("Media"), this); mpLayout->addWidget(mpMediaLabel, 0); - mpDropMediaZone = new UBTeacherBarDropMediaZone(); + mpDropMediaZone = new UBTeacherBarDropMediaZone(this); mpLayout->addWidget(mpDropMediaZone, 1); // Links @@ -369,9 +369,9 @@ UBTeacherBarDropMediaZone::UBTeacherBarDropMediaZone(QWidget *parent, const char { setObjectName(name); setAcceptDrops(true); - - mWidget.setEmptyText(tr("Drag media here ...")); - mLayout.addWidget(&mWidget); + mWidget = new UBWidgetList(parent); + mWidget->setEmptyText(tr("Drag media here ...")); + mLayout.addWidget(mWidget); setLayout(&mLayout); } @@ -379,6 +379,10 @@ UBTeacherBarDropMediaZone::UBTeacherBarDropMediaZone(QWidget *parent, const char UBTeacherBarDropMediaZone::~UBTeacherBarDropMediaZone() { qDeleteAll(mWidgetList); + if(mWidget){ + delete mWidget; + mWidget = NULL; + } } @@ -423,9 +427,8 @@ void UBTeacherBarDropMediaZone::dropEvent(QDropEvent *pEvent) QPixmap pix = pixFromDropEvent.height() ? pixFromDropEvent : QPixmap(resourcePath); QLabel* label = new QLabel(); label->setPixmap(pix); - //label->resize(size()); label->setScaledContents(true); - mWidget.addWidget(label); + mWidget->addWidget(label); mWidgetList << label; } else if(mimeType.contains("video") || mimeType.contains("audio")){ @@ -433,7 +436,7 @@ void UBTeacherBarDropMediaZone::dropEvent(QDropEvent *pEvent) mediaPlayer->setFile(resourcePath); //mediaPlayer->resize(size()); mediaPlayer->playPause(); - mWidget.addWidget(mediaPlayer); + mWidget->addWidget(mediaPlayer); mWidgetList << mediaPlayer; } else{ diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index 29933d9d..644b496a 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -48,7 +48,7 @@ public: private: QListmWidgetList; - UBWidgetList mWidget; + UBWidgetList* mWidget; QVBoxLayout mLayout;