From 453debb2a35578675d5a36ff7c5103c48bc622b1 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 4 Jan 2012 17:04:58 +0100 Subject: [PATCH] changed to have a correct the wrong resize behaviour --- src/customWidgets/UBWidgetList.cpp | 15 +++++++--- src/gui/UBTeacherBarWidget.cpp | 44 +++++++++++++++++++++++++----- src/gui/UBTeacherBarWidget.h | 5 +++- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/customWidgets/UBWidgetList.cpp b/src/customWidgets/UBWidgetList.cpp index 87a9538d..fa3ce3ed 100644 --- a/src/customWidgets/UBWidgetList.cpp +++ b/src/customWidgets/UBWidgetList.cpp @@ -76,16 +76,23 @@ void UBWidgetList::updateSize(bool widgetAdded, QWidget *widget) int newWidgetHeight; if(eWidgetListOrientation_Vertical == mOrientation){ - scaleFactor = (float)widget->width() / (float)mpContainer->width(); + scaleFactor = (float)mpContainer->width() / (float)widget->width(); }else{ - scaleFactor = (float)widget->height() / (float)mpContainer->height(); + scaleFactor = (float)mpContainer->height() / (float)widget->height(); } - newWidgetWidth = widget->width()*scaleFactor; - newWidgetHeight = widget->height()*scaleFactor; + 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; + widget->resize(newWidgetWidth, newWidgetHeight); + qDebug() << "widget new value " << newWidgetWidth << "x" << newWidgetHeight; + // Now we have to update the container if(eWidgetListOrientation_Vertical == mOrientation){ if(widgetAdded){ diff --git a/src/gui/UBTeacherBarWidget.cpp b/src/gui/UBTeacherBarWidget.cpp index 3b403e2c..20229a03 100644 --- a/src/gui/UBTeacherBarWidget.cpp +++ b/src/gui/UBTeacherBarWidget.cpp @@ -322,12 +322,16 @@ QTextEdit* UBTeacherStudentAction::student() } -UBTeacherBarDropMediaZone::UBTeacherBarDropMediaZone(QWidget *parent, const char *name):UBWidgetList(parent) +UBTeacherBarDropMediaZone::UBTeacherBarDropMediaZone(QWidget *parent, const char *name):QWidget(parent) { setObjectName(name); setAcceptDrops(true); - setEmptyText(tr("Drag media here ...")); + + mWidget.setEmptyText(tr("Drag media here ...")); + mLayout.addWidget(&mWidget); + setLayout(&mLayout); + } UBTeacherBarDropMediaZone::~UBTeacherBarDropMediaZone() @@ -348,20 +352,46 @@ void UBTeacherBarDropMediaZone::dragLeaveEvent(QDragLeaveEvent *pEvent) void UBTeacherBarDropMediaZone::dropEvent(QDropEvent *pEvent) { - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(pEvent->mimeData()->urls().at(0).toLocalFile()); + QPixmap pixFromDropEvent; + QString mimeType; + QString resourcePath; + if(pEvent->mimeData()->hasText()){ + qDebug() << "pEvent->mimeData()->hasText()" << pEvent->mimeData()->text(); + resourcePath = pEvent->mimeData()->text(); + } + else if(pEvent->mimeData()->hasUrls()){ + qDebug() << "pEvent->mimeData()->hasUrls()" << pEvent->mimeData()->urls().at(0); + resourcePath = pEvent->mimeData()->urls().at(0).toLocalFile(); + } + else if(pEvent->mimeData()->hasImage()){ + qDebug() << "pEvent->mimeData()->hasImage()"; + pixFromDropEvent.loadFromData(pEvent->mimeData()->imageData().toByteArray()); + if(!pixFromDropEvent.isNull()) + mimeType = "image"; + } + + if (mimeType.isEmpty() && resourcePath.isEmpty()){ + pEvent->acceptProposedAction(); + return; + } + + mimeType = mimeType.isEmpty() ? UBFileSystemUtils::mimeTypeFromFileName(resourcePath) : mimeType; if(mimeType.contains("image")){ - QPixmap pix = QPixmap(pEvent->mimeData()->urls().at(0).toLocalFile()); + qDebug() << pixFromDropEvent.size(); + QPixmap pix = pixFromDropEvent.height() ? pixFromDropEvent : QPixmap(resourcePath); QLabel* label = new QLabel(); label->setPixmap(pix); + //label->resize(size()); label->setScaledContents(true); - addWidget(label); + mWidget.addWidget(label); mWidgetList << label; } else if(mimeType.contains("video") || mimeType.contains("audio")){ UBMediaPlayer* mediaPlayer = new UBMediaPlayer(); - mediaPlayer->setFile(pEvent->mimeData()->urls().at(0).toLocalFile()); + mediaPlayer->setFile(resourcePath); + //mediaPlayer->resize(size()); mediaPlayer->playPause(); - addWidget(mediaPlayer); + mWidget.addWidget(mediaPlayer); mWidgetList << mediaPlayer; } else{ diff --git a/src/gui/UBTeacherBarWidget.h b/src/gui/UBTeacherBarWidget.h index 9ac35434..63f7e262 100644 --- a/src/gui/UBTeacherBarWidget.h +++ b/src/gui/UBTeacherBarWidget.h @@ -47,7 +47,7 @@ private: }; -class UBTeacherBarDropMediaZone : public UBWidgetList +class UBTeacherBarDropMediaZone : public QWidget { Q_OBJECT @@ -57,6 +57,9 @@ public: private: QListmWidgetList; + UBWidgetList mWidget; + QVBoxLayout mLayout; + protected: void dragEnterEvent(QDragEnterEvent* pEvent);