UBTeacherGuideWidgetsTools.h 4.83 KB
Newer Older
1 2 3
/*
 * 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
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * (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 UBTEACHERGUIDEWIDGETSTOOLS_H
#define UBTEACHERGUIDEWIDGETSTOOLS_H

#include <QObject>
#include <QTreeWidgetItem>
#include <QTextEdit>
#include <QLabel>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QLineEdit>
#include <QMimeData>
#include <QStackedWidget>
#include <QWebView>

#include "customWidgets/UBMediaWidget.h"

32 33 34
#define TG_USER_ROLE_MIME_TYPE (Qt::UserRole+50)


35 36 37 38 39 40 41
class QTreeWidget;
class QVBoxLayout;
class QComboBox;
class QTextEdit;
class QWidget;
class UBTGAdaptableText;
class QDomElement;
42
class UBMediaWidget;
43 44 45

typedef struct
{
46
    QString name;
47 48 49 50
    QMap<QString,QString> attributes;
}tUBGEElementNode;


51
class iUBTGSaveData
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
{
public:
    virtual tUBGEElementNode* saveData() = 0;
};


class UBAddItem : public QTreeWidgetItem
{
public:
    explicit UBAddItem(const QString &strings, int addSubItemWidgetType, QTreeWidget* parent = 0);
    ~UBAddItem();

signals:

public slots:
};

69
class UBTGActionWidget : public QWidget, public iUBTGSaveData
70 71
{
    Q_OBJECT
72

73
public:
74
    explicit UBTGActionWidget(QTreeWidgetItem* widget, QWidget* parent = 0,const char* name = "UBTGActionWidget");
75 76 77
    ~UBTGActionWidget();
    void update();
    tUBGEElementNode* saveData();
78
    void initializeWithDom(QDomElement element);
79

80 81 82 83
private:
    QVBoxLayout* mpLayout;
    QComboBox* mpOwner;
    UBTGAdaptableText* mpTask;
84

85 86 87 88 89 90 91 92 93 94 95 96
protected:
    QTreeWidgetItem* mpTreeWidgetItem;
};


class UBTGAdaptableText : public QTextEdit
{
    Q_OBJECT
public:
    explicit UBTGAdaptableText(QTreeWidgetItem* widget = 0, QWidget *parent = 0, const char* name = "UBTGAdaptableText");
    void showText(const QString & text);
    void bottomMargin(int newValue);
97 98
    void setPlaceHolderText(QString text);
    QString text();
99
    void setInitialText(const QString& text);
100 101 102

public slots:
    void onTextChanged();
103 104

protected:
105 106 107 108
    void keyPressEvent(QKeyEvent* e);
    void keyReleaseEvent(QKeyEvent* e);
    void showEvent(QShowEvent* e);

109 110 111
private:
    int mBottomMargin;
    QTreeWidgetItem* mpTreeWidgetItem;
112 113 114
    int mMinimumHeight;
    bool mHasPlaceHolder;
    QString mPlaceHolderText;
115
    bool mIsUpdatingSize;
116 117 118
};


119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
class UBDraggableWeb : public QWebView
{
    Q_OBJECT
public:
    explicit UBDraggableWeb(QString& relativePath, QWidget* parent = 0);

private:
    void mousePressEvent(QMouseEvent* event);
    void mouseMoveEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);

    QString mRelativePath;
    QPoint mDragStartPosition;
    bool mDragStarted;
};

135
class UBTGMediaWidget : public QStackedWidget , public iUBTGSaveData
136 137 138 139
{
    Q_OBJECT
public:
    UBTGMediaWidget(QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget");
140
    UBTGMediaWidget(QString mediaPath, QTreeWidgetItem* widget = 0, QWidget* parent = 0, const char* name = "UBTGMediaWidget");
141 142
    ~UBTGMediaWidget();
    tUBGEElementNode* saveData();
143
    void initializeWithDom(QDomElement element);
144
    void removeSource();
145

146 147 148 149
protected:
    void dragEnterEvent(QDragEnterEvent* event);
    void dropEvent(QDropEvent* event);
    void mousePressEvent(QMouseEvent* event);
150 151
    void hideEvent(QHideEvent* event);
    void showEvent(QShowEvent* event);
152

153 154
private:
    void parseMimeData(const QMimeData* pMimeData);
155
    void createWorkWidget();
156 157 158 159 160 161 162 163 164
    void updateSize();

    QTreeWidgetItem* mpTreeWidgetItem;
    QLabel* mpDropMeWidget;
    QWidget* mpWorkWidget;
    QVBoxLayout* mpLayout;
    UBTGAdaptableText* mpTitle;
    QLabel* mpMediaLabelWidget;
    UBMediaWidget* mpMediaWidget;
165
    UBDraggableWeb* mpWebView;
166
    QString mMediaPath;
167
    bool mIsPresentationMode;
168
    QString mMediaType;
169
    bool mIsInitializationMode;
170 171
};

172

173
class UBTGUrlWidget : public QWidget , public iUBTGSaveData
174 175 176 177 178 179
{
    Q_OBJECT
public:
    UBTGUrlWidget(QWidget* parent = 0, const char* name = "UBTGUrlWidget");
    ~UBTGUrlWidget();
    tUBGEElementNode* saveData();
180
    void initializeWithDom(QDomElement element);
181 182 183 184 185 186
private:
    QVBoxLayout* mpLayout;
    QLineEdit* mpTitle;
    QLineEdit* mpUrl;
};

187 188 189 190 191 192 193 194 195
class UBTGDraggableTreeItem : public QTreeWidget
{
    Q_OBJECT
public:
    UBTGDraggableTreeItem(QWidget* parent = 0, const char* name = "UBTGDraggableTreeItem");

private:
    QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
};
196 197

#endif // UBTEACHERGUIDEWIDGETSTOOLS_H