added the ability to delete an image in the media container of the teacherbar

preferencesAboutTextFull
shibakaneki 13 years ago
parent 45184923f3
commit 3bfc3ceb0d
  1. 70
      src/customWidgets/UBActionableWidget.cpp
  2. 35
      src/customWidgets/UBActionableWidget.h
  3. 5
      src/customWidgets/UBMediaWidget.cpp
  4. 3
      src/customWidgets/UBMediaWidget.h
  5. 41
      src/customWidgets/UBWidgetList.cpp
  6. 7
      src/customWidgets/UBWidgetList.h
  7. 6
      src/customWidgets/customWidgets.pri
  8. 70
      src/gui/UBTBPageEditWidget.cpp
  9. 22
      src/gui/UBTBPageEditWidget.h

@ -0,0 +1,70 @@
#include <QPainter>
#include <QDebug>
#include "UBActionableWidget.h"
UBActionableWidget::UBActionableWidget(QWidget *parent, const char *name):QWidget(parent)
, mShowActions(false)
{
setObjectName(name);
mActions.clear();
}
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)
{
mShowActions = bVisible;
}
bool UBActionableWidget::shouldClose(QPoint p)
{
qDebug() << "Should close: " << p.x() << "," << p.y();
bool close = false;
if(mShowActions &&
p.x() >= 0 &&
p.x() <= ACTIONSIZE &&
p.y() >= 0 &&
p.y() <= ACTIONSIZE){
close = true;
}
return close;
}
void UBActionableWidget::paintEvent(QPaintEvent* ev)
{
if(mShowActions){
QPainter p(this);
if(mActions.contains(eAction_Close)){
p.drawPixmap(0, 0, 16, 16, QPixmap(":images/close.svg"));
}else if(mActions.contains(eAction_MoveUp)){
// Implement me later
}else if(mActions.contains(eAction_MoveDown)){
// Implement me later
}
}
}

@ -0,0 +1,35 @@
#ifndef UBACTIONABLEWIDGET_H
#define UBACTIONABLEWIDGET_H
#include <QWidget>
#include <QPaintEvent>
#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);
bool shouldClose(QPoint p);
protected:
void paintEvent(QPaintEvent* ev);
QVector<eAction> mActions;
private:
bool mShowActions;
};
#endif // UBACTIONABLEWIDGET_H

@ -22,7 +22,7 @@
* @param parent as the parent widget
* @param name as the object name
*/
UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name):QWidget(parent)
UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name):UBActionableWidget(parent, name)
, mpMediaObject(NULL)
, mpVideoWidget(NULL)
, mpAudioOutput(NULL)
@ -35,11 +35,10 @@ UBMediaWidget::UBMediaWidget(eMediaType type, QWidget *parent, const char *name)
, mpMediaContainer(NULL)
, mpCover(NULL)
{
setObjectName(name);
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet());
addAction(eAction_Close);
mType = type;
setLayout(&mLayout);

@ -27,6 +27,7 @@
#include <phonon/AudioOutput>
#include "interfaces/IResizeable.h"
#include "UBActionableWidget.h"
#define UBMEDIABUTTON_SIZE 32
#define TICK_INTERVAL 1000
@ -58,7 +59,7 @@ private:
bool mPressed;
};
class UBMediaWidget : public QWidget
class UBMediaWidget : public UBActionableWidget
{
Q_OBJECT
public:

@ -1,5 +1,7 @@
#include <QDebug>
#include <QScrollBar>
#include <QApplication>
#include <QPainter>
#include "UBGlobals.h"
#include "UBWidgetList.h"
@ -135,8 +137,47 @@ void UBWidgetList::resizeEvent(QResizeEvent *ev)
void UBWidgetList::mousePressEvent(QMouseEvent *ev)
{
if(mCanRemove){
QWidget* pWAt = widgetAt(ev->pos());
if(NULL != mpCurrentWidget){
if(pWAt == mpCurrentWidget){
QPoint p;
p.setX(ev->x());
p.setY(ev->y());
if(mpCurrentWidget->shouldClose(p)){
emit closeWidget(mpCurrentWidget);
return;
}
}else{
mpCurrentWidget->setActionsVisible(false);
}
}
mpCurrentWidget = dynamic_cast<UBActionableWidget*>(pWAt);
if(NULL != mpCurrentWidget){
mpCurrentWidget->setActionsVisible(true);
}
}
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()

@ -11,6 +11,7 @@
#include <QLabel>
#include "interfaces/IResizeable.h"
#include "customWidgets/UBActionableWidget.h"
typedef enum{
eWidgetListOrientation_Vertical,
@ -40,6 +41,9 @@ public:
void setListElementSpacing(int margin) { mListElementsSpacing = margin; }
int listElementsSpacing() {return mListElementsSpacing; }
signals:
void closeWidget(QWidget* w);
protected:
bool mCanRemove;
@ -47,6 +51,7 @@ protected:
void mousePressEvent(QMouseEvent* ev);
private:
QWidget* widgetAt(QPoint p);
int scaleWidgets(QSize pSize);
void scaleContainer(QSize pSize, int updateValue);
void updateView(QSize pSize);
@ -58,7 +63,7 @@ private:
int mListElementsSpacing;
QMap<QWidget*, QSize> mWidgetInfo;
QLabel* mpEmptyLabel;
QWidget* mpCurrentWidget;
UBActionableWidget* mpCurrentWidget;
};
#endif // UBWIDGETLIST_H

@ -3,9 +3,11 @@ HEADERS += src/customWidgets/UBWidgetList.h \
src/customWidgets/UBDraggableLabel.h \
src/customWidgets/UBMediaWidget.h \
src/customWidgets/UBGlobals.h \
src/customWidgets/UBDraggableMedia.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/UBDraggableMedia.cpp \
src/customWidgets/UBActionableWidget.cpp

@ -100,6 +100,9 @@ UBTBPageEditWidget::UBTBPageEditWidget(UBTeacherBarDataMgr *pDataMgr, QWidget *p
connect(mpDocumentEditbutton, SIGNAL(clicked()), this, SLOT(onDocumentEditClicked()));
connect(mpPagePreviewButton, SIGNAL(clicked()), this, SLOT(onPagePreviewClicked()));
connect(mpMediaContainer, SIGNAL(mediaDropped(QString)), this, SLOT(onMediaDropped(QString)));
connect(mpActions, SIGNAL(closeWidget(QWidget*)), this, SLOT(onCloseWidget(QWidget*)));
connect(mpLinks, SIGNAL(closeWidget(QWidget*)), this, SLOT(onCloseWidget(QWidget*)));
connect(mpMediaContainer, SIGNAL(closeWidget(QWidget*)), this, SLOT(onCloseWidget(QWidget*)));
}
UBTBPageEditWidget::~UBTBPageEditWidget()
@ -271,15 +274,36 @@ void UBTBPageEditWidget::clearFields()
mClearingFields = false;
}
void UBTBPageEditWidget::onCloseWidget(QWidget *w)
{
if(NULL != w){
if("UBTeacherStudentAction" == w->objectName()){
UBTeacherStudentAction* pW = dynamic_cast<UBTeacherStudentAction*>(w);
mpActions->removeWidget(pW);
mActions.remove(mActions.indexOf(pW));
DELETEPTR(w);
}else if("UBUrlWidget" == w->objectName()){
UBUrlWidget* pW = dynamic_cast<UBUrlWidget*>(w);
mpLinks->removeWidget(pW);
mUrls.remove(mUrls.indexOf(pW));
DELETEPTR(w);
}else if("UBTBMediaPicture" == w->objectName() || "UBMediaWidget" == w->objectName()){
mpMediaContainer->removeWidget(w);
mMedias.remove(mMedias.indexOf(w));
DELETEPTR(w);
}
}
}
// ---------------------------------------------------------------------------------------------
UBUrlWidget::UBUrlWidget(QWidget *parent, const char *name):QWidget(parent)
UBUrlWidget::UBUrlWidget(QWidget *parent, const char *name):UBActionableWidget(parent, name)
, mpLayout(NULL)
, mpUrlLabel(NULL)
, mpUrl(NULL)
{
setObjectName(name);
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet());
addAction(eAction_Close);
mpLayout = new QVBoxLayout(this);
setLayout(mpLayout);
@ -435,12 +459,13 @@ QWidget* UBTBMediaContainer::generateMediaWidget(const QString& url)
QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(url);
if(mimeType.contains("image")){
QPixmap pix = QPixmap(url);
QLabel* label = new QLabel();
pix.scaledToWidth(label->width());
label->resize(pix.width(), pix.height());
label->setPixmap(pix);
label->setScaledContents(true);
pW = label;
UBPictureWidget* pic = new UBPictureWidget();
pix.scaledToWidth(pic->label()->width());
pic->label()->resize(pix.width(), pix.height());
pic->label()->setPixmap(pix);
pic->label()->setScaledContents(true);
pic->setObjectName("UBTBMediaPicture");
pW = pic;
}
else if(mimeType.contains("video") || mimeType.contains("audio")){
UBMediaWidget* mediaPlayer = new UBMediaWidget(mimeType.contains("audio")?eMediaType_Audio:eMediaType_Video);
@ -455,16 +480,15 @@ QWidget* UBTBMediaContainer::generateMediaWidget(const QString& url)
return pW;
}
UBTeacherStudentAction::UBTeacherStudentAction(QWidget *parent, const char *name):QWidget(parent)
UBTeacherStudentAction::UBTeacherStudentAction(QWidget *parent, const char *name):UBActionableWidget(parent, name)
, mpText(NULL)
, mpLayout(NULL)
, mpComboLayout(NULL)
, mpCombo(NULL)
{
setObjectName(name);
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet());
addAction(eAction_Close);
// Create the GUI
mpLayout = new QHBoxLayout(this);
@ -532,3 +556,27 @@ void UBTeacherStudentAction::setText(const QString& text)
}
}
// -------------------------------------------------------------
UBPictureWidget::UBPictureWidget(QWidget *parent, const char *name):UBActionableWidget(parent, name)
, mpLayout(NULL)
, mpLabel(NULL)
{
addAction(eAction_Close);
mpLayout = new QVBoxLayout(this);
setLayout(mpLayout);
mpLayout->setContentsMargins(10, 0, 10, 0);
mpLabel = new QLabel(this);
mpLayout->addWidget(mpLabel);
mpLabel->setGeometry( 10, 10, width()-2*10, height());
}
UBPictureWidget::~UBPictureWidget()
{
DELETEPTR(mpLabel);
DELETEPTR(mpLayout);
}
void UBPictureWidget::resizeEvent(QResizeEvent *ev)
{
mpLabel->setGeometry( 10, 10, width()-2*10, height());
}

@ -11,10 +11,11 @@
#include "core/UBPersistenceManager.h"
#include "customWidgets/UBWidgetList.h"
#include "customWidgets/UBActionableWidget.h"
#include "interfaces/IDropable.h"
#include "UBTeacherBarDataMgr.h"
class UBTeacherStudentAction : public QWidget
class UBTeacherStudentAction : public UBActionableWidget
{
Q_OBJECT
@ -33,7 +34,7 @@ private:
QComboBox* mpCombo;
};
class UBUrlWidget : public QWidget
class UBUrlWidget : public UBActionableWidget
{
public:
UBUrlWidget(QWidget* parent=0, const char* name="UBUrlWidget");
@ -56,6 +57,22 @@ private:
QLineEdit* mpTitle;
};
class UBPictureWidget : public UBActionableWidget
{
public:
UBPictureWidget(QWidget* parent=0, const char* name="UBPictureWidget");
~UBPictureWidget();
QLabel* label(){return mpLabel;}
protected:
void resizeEvent(QResizeEvent* ev);
private:
QVBoxLayout* mpLayout;
QLabel* mpLabel;
};
class UBTBMediaContainer : public UBWidgetList
, public IDropable
{
@ -104,6 +121,7 @@ private slots:
void onMediaDropped(const QString& url);
void onDocumentEditClicked();
void onPagePreviewClicked();
void onCloseWidget(QWidget* w);
private:
QVBoxLayout mLayout;

Loading…
Cancel
Save