removed unused classes

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 1fd290d617
commit 0eb128ec04
  1. 1
      Sankore_3.1.pro
  2. 10
      src/board/UBBoardView.cpp
  3. 65
      src/customWidgets/UBActionableWidget.cpp
  4. 45
      src/customWidgets/UBActionableWidget.h
  5. 39
      src/customWidgets/UBDraggableLabel.cpp
  6. 23
      src/customWidgets/UBDraggableLabel.h
  7. 42
      src/customWidgets/UBDraggableMedia.cpp
  8. 19
      src/customWidgets/UBDraggableMedia.h
  9. 335
      src/customWidgets/UBMediaWidget.cpp
  10. 127
      src/customWidgets/UBMediaWidget.h
  11. 229
      src/customWidgets/UBWidgetList.cpp
  12. 69
      src/customWidgets/UBWidgetList.h
  13. 13
      src/customWidgets/customWidgets.pri

@ -52,7 +52,6 @@ include(src/tools/tools.pri)
include(src/desktop/desktop.pri)
include(src/web/web.pri)
include(src/transition/transition.pri)
include(src/customWidgets/customWidgets.pri)
include(src/interfaces/interfaces.pri)
DEPENDPATH += src/pdf-merger

@ -49,9 +49,6 @@
#include "document/UBDocumentProxy.h"
#include "customWidgets/UBDraggableLabel.h"
#include "customWidgets/UBDraggableMedia.h"
#include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsCache.h"
#include "tools/UBGraphicsTriangle.h"
@ -813,14 +810,11 @@ void UBBoardView::dropEvent (QDropEvent *event)
UBGraphicsWidgetItem* graphicsWidget = dynamic_cast<UBGraphicsWidgetItem*>(graphicsItemAtPos);
if (graphicsWidget && graphicsWidget->acceptDrops()) {
graphicsWidget->processDropEvent(event);
event->acceptProposedAction();
} else if (!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source())
|| dynamic_cast<QWebView*>(event->source()) || dynamic_cast<UBDraggableMediaPlayer *>(event->source())
|| dynamic_cast<UBDraggableLabel *>(event->source()) || dynamic_cast<UBDraggableMedia *>(event->source())) {
}
else if (!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source())){
mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction();
}

@ -1,65 +0,0 @@
#include <QPainter>
#include <QDebug>
#include "UBActionableWidget.h"
UBActionableWidget::UBActionableWidget(QWidget *parent, const char *name):QWidget(parent)
, mShowActions(false)
{
setObjectName(name);
mActions.clear();
mCloseButtons.setIcon(QIcon(QPixmap(":images/close.svg")));
mCloseButtons.setGeometry(0, 0, 2*ACTIONSIZE, ACTIONSIZE);
mCloseButtons.setVisible(false);
connect(&mCloseButtons, SIGNAL(clicked()), this, SLOT(onCloseClicked()));
}
UBActionableWidget::~UBActionableWidget()
{
}
void UBActionableWidget::addAction(eAction act)
{
if(!mActions.contains(act)){
mActions << act;
}
}
void UBActionableWidget::removeAction(eAction act)
{
if(mActions.contains(act)){
mActions.remove(mActions.indexOf(act));
}
}
void UBActionableWidget::removeAllActions()
{
mActions.clear();
}
void UBActionableWidget::setActionsVisible(bool bVisible)
{
if(!mActions.empty() && mActions.contains(eAction_Close)){
mCloseButtons.setVisible(bVisible);
}
}
void UBActionableWidget::onCloseClicked()
{
emit close(this);
}
void UBActionableWidget::setActionsParent(QWidget *parent)
{
if(mActions.contains(eAction_Close)){
mCloseButtons.setParent(parent);
}
}
void UBActionableWidget::unsetActionsParent()
{
if(mActions.contains(eAction_Close)){
mCloseButtons.setParent(this);
}
}

@ -1,45 +0,0 @@
#ifndef UBACTIONABLEWIDGET_H
#define UBACTIONABLEWIDGET_H
#include <QWidget>
#include <QPaintEvent>
#include <QToolButton>
#include <QPushButton>
#define ACTIONSIZE 16
typedef enum{
eAction_Close,
eAction_MoveUp,
eAction_MoveDown
}eAction;
class UBActionableWidget : public QWidget
{
Q_OBJECT
public:
UBActionableWidget(QWidget* parent=0, const char* name="UBActionableWidget");
~UBActionableWidget();
void addAction(eAction act);
void removeAction(eAction act);
void removeAllActions();
void setActionsVisible(bool bVisible);
signals:
void close(QWidget* w);
protected:
void setActionsParent(QWidget* parent);
void unsetActionsParent();
QVector<eAction> mActions;
QPushButton mCloseButtons;
private slots:
void onCloseClicked();
private:
bool mShowActions;
};
#endif // UBACTIONABLEWIDGET_H

@ -1,39 +0,0 @@
#include <QMimeData>
#include <QDrag>
#include <QUrl>
#include "UBDraggableLabel.h"
UBDraggableLabel::UBDraggableLabel(QWidget *parent) :
QLabel(parent)
{
}
UBDraggableLabel::~UBDraggableLabel()
{
//NOOP
}
void UBDraggableLabel::loadImage(QString imagePath)
{
mSourcePath = imagePath;
QPixmap pix = QPixmap(mSourcePath);
setPixmap(pix);
setScaledContents(true);
}
void UBDraggableLabel::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
urls << QUrl::fromLocalFile(mSourcePath);
mimeData->setUrls(urls);
mimeData->setText(mSourcePath);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->start();
}

@ -1,23 +0,0 @@
#ifndef UBDRAGGABLELABEL_H
#define UBDRAGGABLELABEL_H
#include <QLabel>
class UBDraggableLabel : public QLabel
{
Q_OBJECT
public:
UBDraggableLabel(QWidget *parent = 0);
~UBDraggableLabel();
void loadImage(QString imagePath);
signals:
public slots:
protected:
QString mSourcePath;
void mousePressEvent(QMouseEvent *event);
};
#endif // UBDRAGGABLELABEL_H

@ -1,42 +0,0 @@
#include <QApplication>
#include <QUrl>
#include "UBDraggableMedia.h"
UBDraggableMedia::UBDraggableMedia(eMediaType type, QWidget *parent, const char *name):UBMediaWidget(type, parent, name)
{
removeAllActions();
}
UBDraggableMedia::~UBDraggableMedia()
{
}
void UBDraggableMedia::mousePressEvent(QMouseEvent* ev)
{
if(Qt::LeftButton == ev->button()){
mDragStartPos = ev->pos();
}
}
void UBDraggableMedia::mouseMoveEvent(QMouseEvent* ev)
{
if(!(ev->buttons() & Qt::LeftButton)){
return;
}
if((ev->pos() - mDragStartPos).manhattanLength() < QApplication::startDragDistance()){
return;
}
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QList<QUrl> urls;
urls << QUrl(mFilePath);
mimeData->setText(mFilePath);
mimeData->setUrls(urls);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction | Qt::MoveAction);
}

@ -1,19 +0,0 @@
#ifndef UBDRAGGABLEMEDIA_H
#define UBDRAGGABLEMEDIA_H
#include "UBMediaWidget.h"
class UBDraggableMedia : public UBMediaWidget
{
public:
UBDraggableMedia(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBDraggableMedia");
~UBDraggableMedia();
protected:
void mousePressEvent(QMouseEvent* ev);
void mouseMoveEvent(QMouseEvent* ev);
private:
QPoint mDragStartPos;
};
#endif // UBDRAGGABLEMEDIA_H

@ -1,335 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "core/UBApplication.h"
#include "globals/UBGlobals.h"
#include "UBMediaWidget.h"
/**
* \brief Constructor
* @param type as the media type
* @param parent as the parent widget
* @param name as the object name
*/
UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name):UBActionableWidget(parent, name)
, mpMediaObject(NULL)
, mpVideoWidget(NULL)
, mpAudioOutput(NULL)
, mpPlayStopButton(NULL)
, mpPauseButton(NULL)
, mpSlider(NULL)
, mAutoUpdate(false)
, mGeneratingThumbnail(false)
, mBorder(5)
, mpMediaContainer(NULL)
, mpCover(NULL)
{
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet());
addAction(eAction_Close);
mType = type;
setLayout(&mLayout);
mpPlayStopButton = new UBMediaButton(this);
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg"));
mpPauseButton = new UBMediaButton(this);
mpPauseButton->setPixmap(QPixmap(":images/pause.svg"));
mpPauseButton->setEnabled(false);
mpSlider = new QSlider(this);
mpSlider->setOrientation(Qt::Horizontal);
mpSlider->setMinimum(0);
mpSlider->setMaximum(0);
mSeekerLayout.addWidget(mpPlayStopButton, 0);
mSeekerLayout.addWidget(mpPauseButton, 0);
mSeekerLayout.addWidget(mpSlider, 1);
mSeekerLayout.setContentsMargins(0, 0, 0, 0);
connect(mpPlayStopButton, SIGNAL(clicked()), this, SLOT(onPlayStopClicked()));
connect(mpPauseButton, SIGNAL(clicked()), this, SLOT(onPauseClicked()));
connect(mpSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int)));
}
/**
* \brief Destructor
*/
UBMediaWidget::~UBMediaWidget()
{
unsetActionsParent();
DELETEPTR(mpSlider);
DELETEPTR(mpPauseButton);
DELETEPTR(mpPlayStopButton);
DELETEPTR(mpAudioOutput);
DELETEPTR(mpVideoWidget);
DELETEPTR(mpMediaObject);
DELETEPTR(mpCover);
}
/**
* \brief Set the media file
* @param filePath as the media file path
*/
void UBMediaWidget::setFile(const QString &filePath)
{
Q_ASSERT("" != filePath);
mFilePath = filePath;
mpMediaObject = new Phonon::MediaObject(this);
mpMediaObject->setTickInterval(TICK_INTERVAL);
connect(mpMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State)));
connect(mpMediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(onTotalTimeChanged(qint64)));
connect(mpMediaObject, SIGNAL(tick(qint64)), this, SLOT(onTick(qint64)));
mpMediaObject->setCurrentSource(Phonon::MediaSource(filePath));
createMediaPlayer();
}
/**
* \brief Get the media type
* @returns the media type
*/
eMediaType UBMediaWidget::mediaType()
{
return mType;
}
void UBMediaWidget::showEvent(QShowEvent* event)
{
if(!mpVideoWidget){
mpVideoWidget = new Phonon::VideoWidget(this);
mMediaLayout.addStretch(1);
mMediaLayout.addWidget(mpVideoWidget, 0);
mMediaLayout.addStretch(1);
Phonon::createPath(mpMediaObject, mpVideoWidget);
adaptSizeToVideo();
mpMediaObject->play();
mpMediaObject->stop();
}
QWidget::showEvent(event);
}
/**
* \brief Create the media player
*/
void UBMediaWidget::createMediaPlayer()
{
mpMediaContainer = new QWidget(this);
mpMediaContainer->setObjectName("UBMediaVideoContainer");
mpMediaContainer->setLayout(&mMediaLayout);
if(eMediaType_Video == mType){
mMediaLayout.setContentsMargins(10, 10, 25, 10);
if(isVisible()){
mpVideoWidget = new Phonon::VideoWidget(this);
mMediaLayout.addStretch(1);
mMediaLayout.addWidget(mpVideoWidget, 0);
mMediaLayout.addStretch(1);
Phonon::createPath(mpMediaObject, mpVideoWidget);
adaptSizeToVideo();
}
mpAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
Phonon::createPath(mpMediaObject, mpAudioOutput);
}else if(eMediaType_Audio == mType){
mMediaLayout.setContentsMargins(10, 10, 10, 10);
mpCover = new QLabel(mpMediaContainer);
mpMediaContainer->setStyleSheet(QString("background: none;"));
setAudioCover(":images/libpalette/soundIcon.svg");
mpCover->setScaledContents(true);
mMediaLayout.addStretch(1);
mMediaLayout.addWidget(mpCover, 0);
mMediaLayout.addStretch(1);
mpAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
Phonon::createPath(mpMediaObject, mpAudioOutput);
}
mLayout.addWidget(mpMediaContainer, 1);
mLayout.addLayout(&mSeekerLayout, 0);
setActionsParent(mpMediaContainer);
}
/**
* \brief Adapt the widget size to the video in order to keep the good aspect ratio
*/
void UBMediaWidget::adaptSizeToVideo()
{
if(NULL != mpMediaContainer){
int origW = mpMediaContainer->width();
int origH = mpMediaContainer->height();
int newW = width();
float scaleFactor = (float)origW/(float)newW;
int newH = origH/scaleFactor;
resize(newW, height() + newH);
}
}
/**
* \brief Handle the media state change notification
* @param newState as the new state
* @param oldState as the old state
*/
void UBMediaWidget::onStateChanged(Phonon::State newState, Phonon::State oldState)
{
if(!mGeneratingThumbnail){
if(Phonon::LoadingState == oldState && Phonon::StoppedState == newState){
if(eMediaType_Video == mType){
// We do that here to generate the thumbnail of the video
mGeneratingThumbnail = true;
mpMediaObject->play();
mpMediaObject->pause();
mGeneratingThumbnail = false;
}
}else if(Phonon::PlayingState == oldState && Phonon::PausedState == newState){
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg"));
mpPauseButton->setEnabled(false);
}else if((Phonon::PausedState == oldState && Phonon::PlayingState == newState) ||
(Phonon::StoppedState == oldState && Phonon::PlayingState == newState)){
mpPlayStopButton->setPixmap(QPixmap(":images/stop.svg"));
mpPauseButton->setEnabled(true);
}else if(Phonon::PlayingState == oldState && Phonon::StoppedState == newState){
mpPlayStopButton->setPixmap(QPixmap(":images/play.svg"));
mpPauseButton->setEnabled(false);
mpSlider->setValue(0);
}
}
}
/**
* \brief Handles the total time change notification
* @param total as the new total time
*/
void UBMediaWidget::onTotalTimeChanged(qint64 total)
{
mpSlider->setMaximum(total);
}
/**
* \brief Handles the tick notification
* @param currentTime as the current time
*/
void UBMediaWidget::onTick(qint64 currentTime)
{
mAutoUpdate = true;
mpSlider->setValue((int)currentTime);
mAutoUpdate = false;
}
/**
* \brief Handles the seeker value change notification
* @param value as the new seeker value
*/
void UBMediaWidget::onSliderChanged(int value)
{
if(!mAutoUpdate){
mpMediaObject->seek(value);
}
}
/**
* \brief Toggle Play-Stop
*/
void UBMediaWidget::onPlayStopClicked()
{
switch(mpMediaObject->state()){
case Phonon::PlayingState:
mpMediaObject->stop();
break;
case Phonon::StoppedState:
case Phonon::PausedState:
mpMediaObject->play();
break;
default:
break;
}
}
/**
* \brief Pause the media
*/
void UBMediaWidget::onPauseClicked()
{
mpMediaObject->pause();
}
/**
* Get the border
* @returns the actual border
*/
int UBMediaWidget::border()
{
return mBorder;
}
/**
* \brief Handles the resize event
* @param ev as the resize event
*/
void UBMediaWidget::resizeEvent(QResizeEvent* ev)
{
Q_UNUSED(ev);
}
/**
* \brief Set the audio cover
* @param coverPath as the cover image file path
*/
void UBMediaWidget::setAudioCover(const QString &coverPath)
{
if(NULL != mpCover){
mpCover->setPixmap(QPixmap(coverPath));
}
}
// -----------------------------------------------------------------------------------------------------------
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the object name
*/
UBMediaButton::UBMediaButton(QWidget *parent, const char *name):QLabel(parent)
, mPressed(false)
{
setObjectName(name);
resize(UBMEDIABUTTON_SIZE, UBMEDIABUTTON_SIZE);
setStyleSheet(QString("padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;"));
}
/**
* \brief Destructor
*/
UBMediaButton::~UBMediaButton()
{
}
/**
* \brief Handles the mouse press notification
* @param ev as the mouse press event
*/
void UBMediaButton::mousePressEvent(QMouseEvent* ev)
{
Q_UNUSED(ev);
mPressed = true;
}
/**
* \brief Handles the mouse release notification
* @param ev as the mouse release event
*/
void UBMediaButton::mouseReleaseEvent(QMouseEvent* ev)
{
Q_UNUSED(ev);
if(mPressed){
mPressed = false;
emit clicked();
}
}

@ -1,127 +0,0 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UBMEDIAWIDGET_H
#define UBMEDIAWIDGET_H
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QMouseEvent>
#include <phonon/MediaObject>
#include <phonon/VideoWidget>
#include <phonon/AudioOutput>
#include "interfaces/IResizeable.h"
#include "UBActionableWidget.h"
#define UBMEDIABUTTON_SIZE 32
#define TICK_INTERVAL 1000
/**
* \brief The media type
*/
typedef enum{
eMediaType_Video,
eMediaType_Audio
}eMediaType;
class UBMediaButton : public QLabel
{
Q_OBJECT
public:
UBMediaButton(QWidget* parent=0, const char* name="UBMediaButton");
~UBMediaButton();
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent* ev);
void mouseReleaseEvent(QMouseEvent* ev);
private:
/** And indicator of the press event in progress */
bool mPressed;
};
class UBMediaWidget : public UBActionableWidget
{
Q_OBJECT
public:
UBMediaWidget(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBMediaWidget");
~UBMediaWidget();
void setFile(const QString& filePath);
eMediaType mediaType();
int border();
void setAudioCover(const QString& coverPath);
void setUrl(const QString& url){mUrl = url;}
QString url(){return mUrl;}
protected:
void resizeEvent(QResizeEvent* ev);
void showEvent(QShowEvent* event);
/** The current media file path */
QString mFilePath;
private slots:
void onPlayStopClicked();
void onPauseClicked();
void onStateChanged(Phonon::State newState, Phonon::State oldState);
void onTotalTimeChanged(qint64 total);
void onTick(qint64 currentTime);
void onSliderChanged(int value);
private:
void createMediaPlayer();
void adaptSizeToVideo();
/** The current media type */
eMediaType mType;
/** The media object */
Phonon::MediaObject* mpMediaObject;
/** The video renderer */
Phonon::VideoWidget* mpVideoWidget;
/** The audio renderer */
Phonon::AudioOutput* mpAudioOutput;
/** The principal layout of this widget */
QVBoxLayout mLayout;
/** The seeker layout */
QHBoxLayout mSeekerLayout;
/** The play-stop button */
UBMediaButton* mpPlayStopButton;
/** The pause button */
UBMediaButton* mpPauseButton;
/** The seeker slider */
QSlider* mpSlider;
/** An indicator of the seeker auto update in progress */
bool mAutoUpdate;
/** An indicator of the thumbnail generation in progress */
bool mGeneratingThumbnail;
/** The border */
int mBorder;
/** A widget that will contain the media */
QWidget* mpMediaContainer;
/** The media layout */
QHBoxLayout mMediaLayout;
/** The audio cover */
QLabel* mpCover;
/** The media url */
QString mUrl;
};
#endif // UBMEDIAWIDGET_H

@ -1,229 +0,0 @@
#include <QDebug>
#include <QScrollBar>
#include <QApplication>
#include <QPainter>
#include "globals/UBGlobals.h"
#include "UBWidgetList.h"
UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation, const char* name):QScrollArea(parent)
, mCanRemove(true)
, mpLayout(NULL)
, mpContainer(NULL)
, mMargin(10)
, mListElementsSpacing(10)
, mpEmptyLabel(NULL)
, mpCurrentWidget(NULL)
{
setObjectName(name);
mOrientation = orientation;
mpContainer = new QWidget(this);
mpEmptyLabel = new QLabel(this);
mpEmptyLabel->setObjectName("emptyString");
mpEmptyLabel->setWordWrap(true);
mpEmptyLabel->setAlignment(Qt::AlignCenter);
if(eWidgetListOrientation_Vertical == orientation){
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mpLayout = new QVBoxLayout(mpContainer);
}
else{
setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mpLayout = new QHBoxLayout(mpContainer);
}
mpLayout->setContentsMargins(margin(), margin(), margin(), margin());
mpContainer->setLayout(mpLayout);
setWidget(mpContainer);
}
UBWidgetList::~UBWidgetList()
{
DELETEPTR(mpEmptyLabel);
DELETEPTR(mpLayout);
DELETEPTR(mpContainer);
}
void UBWidgetList::addWidget(QWidget *widget)
{
if(NULL != mpLayout && NULL != widget){
widget->setParent(mpContainer);
mpEmptyLabel->setVisible(false);
mWidgetInfo[widget] = widget->size();
updateView(size());
mpLayout->addWidget(widget);
// This call is used only to refresh the size of the widgets
updateSizes();
}
}
void UBWidgetList::removeWidget(QWidget *widget)
{
if(NULL != mpLayout && NULL != widget){
mpLayout->removeWidget(widget);
mWidgetInfo.remove(widget);
widget->setVisible(false);
updateView(size());
if(0 == mpLayout->count()){
mpEmptyLabel->setVisible(true);
}
if(mpCurrentWidget == widget){
mpCurrentWidget = NULL;
}
}
}
int UBWidgetList::scaleWidgets(QSize pSize)
{
// to remove the first spacing that shouldn't be there.
int result = -mListElementsSpacing;
foreach(QWidget* eachWidget, mWidgetInfo.keys()){
qreal scaleFactor = 0;
int newWidgetWidth = pSize.width();
int newWidgetHeight = pSize.height();
if(eWidgetListOrientation_Vertical == mOrientation){
scaleFactor = (float)mWidgetInfo[eachWidget].width() / (float)pSize.width();
newWidgetHeight = mWidgetInfo[eachWidget].height()/scaleFactor;
result += newWidgetHeight;
eachWidget->setMinimumHeight(newWidgetHeight- 1);
eachWidget->setMaximumHeight(newWidgetHeight);
}
else{
scaleFactor = (float)mWidgetInfo[eachWidget].height() / (float)pSize.height();
newWidgetWidth = mWidgetInfo[eachWidget].width()/scaleFactor;
result += newWidgetWidth;
eachWidget->setMinimumWidth(newWidgetWidth - 1);
eachWidget->setMaximumWidth(newWidgetWidth);
}
//Adding a vertical/horizontal space between each element of the list
result += mListElementsSpacing;
}
return result;
}
void UBWidgetList::scaleContainer(QSize pSize, int updateValue)
{
if(eWidgetListOrientation_Vertical == mOrientation)
mpContainer->resize(pSize.width(), updateValue);
else
mpContainer->resize(updateValue, pSize.height());
}
void UBWidgetList::updateView(QSize pSize)
{
// Widgets on list are resized automatically to fit the mpcontainer.
// so if you want to keep the aspect ratio you have to calculate
// the sum of the new widget height and give it to the mpContainer.
// The container resize will trig the widgets resize and the good
// height permits to respect the aspect ratio.
int updatedValue = scaleWidgets(pSize);
scaleContainer(pSize,updatedValue);
}
void UBWidgetList::resizeEvent(QResizeEvent *ev)
{
Q_UNUSED(ev);
mpEmptyLabel->setGeometry((width() - mpEmptyLabel->width()) / 2,
(height() - mpEmptyLabel->height()) /2,
mpEmptyLabel->width(),
mpEmptyLabel->height());
updateView(size());
updateSizes();
}
void UBWidgetList::mousePressEvent(QMouseEvent *ev)
{
Q_UNUSED(ev);
if(mCanRemove){
QWidget* pWAt = widgetAt(ev->pos());
if(NULL != mpCurrentWidget){
if(pWAt != mpCurrentWidget){
mpCurrentWidget->setActionsVisible(false);
update();
}
}
mpCurrentWidget = dynamic_cast<UBActionableWidget*>(pWAt);
if(NULL != mpCurrentWidget){
mpCurrentWidget->setActionsVisible(true);
update();
}
}
update();
}
QWidget* UBWidgetList::widgetAt(QPoint p)
{
QWidget* pW = NULL;
pW = childAt(p);
if(NULL != pW){
do{
if( "UBTeacherStudentAction" == pW->objectName() ||
"UBUrlWidget" == pW->objectName() ||
"UBTBMediaPicture" == pW->objectName() ||
"UBMediaWidget" == pW->objectName()){
return pW;
}else{
pW = pW->parentWidget();
}
}while(NULL != pW && this != pW);
}
return pW;
}
void UBWidgetList::updateSizes()
{
// Resize all the widgets
foreach(QWidget* eachWidget, mWidgetInfo.keys()){
if(NULL != eachWidget){
QSize originalSize = mWidgetInfo[eachWidget];
int currentWidth = mpContainer->width();
int currentHeight = mpContainer->height();
if(eWidgetListOrientation_Vertical == mOrientation){
if(verticalScrollBar()->isVisible()){
currentWidth -= verticalScrollBar()->width();
eachWidget->setStyleSheet(QString("margin-right:%0;").arg(verticalScrollBar()->width()));
}
float scaleFactor = (float)currentWidth/(float)originalSize.width();
currentHeight = originalSize.height()*scaleFactor;
}else{
if(horizontalScrollBar()->isVisible()){
currentHeight -= horizontalScrollBar()->height();
eachWidget->setStyleSheet(QString("padding-bottom:%0;").arg(horizontalScrollBar()->height()));
}
float scaleFactor = (float)currentHeight/(float)originalSize.height();
currentWidth = originalSize.width()*scaleFactor;
}
eachWidget->resize(currentWidth, currentHeight);
}
}
}
void UBWidgetList::setMargin(int margin)
{
mMargin = margin;
}
int UBWidgetList::margin()
{
return mMargin;
}
void UBWidgetList::setEmptyText(const QString &text)
{
if(NULL != mpEmptyLabel){
mpEmptyLabel->setText(text);
}
}
bool UBWidgetList::empty()
{
return mWidgetInfo.empty();
}

@ -1,69 +0,0 @@
#ifndef UBWIDGETLIST_H
#define UBWIDGETLIST_H
#include <QWidget>
#include <QScrollArea>
#include <QBoxLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QResizeEvent>
#include <QVector>
#include <QLabel>
#include "interfaces/IResizeable.h"
#include "customWidgets/UBActionableWidget.h"
typedef enum{
eWidgetListOrientation_Vertical,
eWidgetListOrientation_Horizontal
}eWidgetListOrientation;
class UBWidgetList : public QScrollArea
{
Q_OBJECT
typedef struct
{
QSize size;
bool isResizable;
} sWidgetProperties;
public:
UBWidgetList(QWidget* parent=0, eWidgetListOrientation orientation = eWidgetListOrientation_Vertical, const char* name = "UBWidgetList");
~UBWidgetList();
void addWidget(QWidget* widget);
void removeWidget(QWidget* widget);
void setMargin(int margin);
void setEmptyText(const QString& text);
int margin();
bool empty();
void setListElementSpacing(int margin) { mListElementsSpacing = margin; }
int listElementsSpacing() {return mListElementsSpacing; }
signals:
void closeWidget(QWidget* w);
protected:
bool mCanRemove;
void resizeEvent(QResizeEvent* ev);
void mousePressEvent(QMouseEvent* ev);
private:
QWidget* widgetAt(QPoint p);
int scaleWidgets(QSize pSize);
void scaleContainer(QSize pSize, int updateValue);
void updateView(QSize pSize);
void updateSizes();
QBoxLayout* mpLayout;
QWidget* mpContainer;
eWidgetListOrientation mOrientation;
int mMargin;
int mListElementsSpacing;
QMap<QWidget*, QSize> mWidgetInfo;
QLabel* mpEmptyLabel;
UBActionableWidget* mpCurrentWidget;
};
#endif // UBWIDGETLIST_H

@ -1,13 +0,0 @@
HEADERS += src/customWidgets/UBWidgetList.h \
src/customWidgets/UBDraggableLabel.h \
src/customWidgets/UBMediaWidget.h \
src/globals/UBGlobals.h \
src/customWidgets/UBDraggableMedia.h \
src/customWidgets/UBActionableWidget.h
SOURCES += src/customWidgets/UBWidgetList.cpp \
src/customWidgets/UBDraggableLabel.cpp \
src/customWidgets/UBMediaWidget.cpp \
src/customWidgets/UBDraggableMedia.cpp \
src/customWidgets/UBActionableWidget.cpp
Loading…
Cancel
Save