UBFeaturesWidget.h 12.3 KB
Newer Older
Anna Udovichenko's avatar
Anna Udovichenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#ifndef UBFEATURESWIDGET_H
#define UBFEATURESWIDGET_H

#include <QWidget>
#include <QListView>
#include <QGraphicsView>
#include <QAbstractListModel>
#include <QPixmap>
#include <QVBoxLayout>
#include <QSlider>
#include <QUrl>
#include <QStyledItemDelegate>
#include <QLocale>
#include <QGraphicsLinearLayout>
#include <QStackedWidget>
16
#include <QDropEvent>
Anna Udovichenko's avatar
Anna Udovichenko committed
17 18

#include "UBDockPaletteWidget.h"
19
#include "core/UBSettings.h"
Anna Udovichenko's avatar
Anna Udovichenko committed
20
#include "board/UBFeaturesController.h"
21
#include "api/UBWidgetUniboardAPI.h"
22
#include "UBFeaturesActionBar.h"
Anna Udovichenko's avatar
Anna Udovichenko committed
23
#include "UBRubberBand.h"
24 25 26
#include <QtWebKit>
#include <QWebView>
#include <QWebSettings>
Anna Udovichenko's avatar
Anna Udovichenko committed
27 28 29 30

#define THUMBNAIL_WIDTH 400
#define ID_LISTVIEW 0
#define ID_PROPERTIES 1
31
#define ID_WEBVIEW 2
Anna Udovichenko's avatar
Anna Udovichenko committed
32 33 34 35 36 37 38 39 40 41 42 43

class UBListModel;

class UBFeaturesModel;
class UBFeaturesItemDelegate;
class UBFeaturesPathItemDelegate;
class UBFeaturesProxyModel;
class UBFeaturesSearchProxyModel;
class UBFeaturesPathProxyModel;
class UBFeaturesPathViewer;
class UBFeatureProperties;
class UBFeatureItemButton;
44
class UBFeaturesListView;
45
class UBFeaturesWebView;
46 47
class UBFeaturesNavigatorWidget;
class UBFeaturesMimeData;
48 49
class UBFeaturesCentralWidget;
class UBFeaturesNewFolderDialog;
50
class UBFeaturesProgressBar;
Anna Udovichenko's avatar
Anna Udovichenko committed
51 52 53 54 55 56 57 58 59 60 61 62 63

class UBFeaturesWidget : public UBDockPaletteWidget
{
    Q_OBJECT
public:
	UBFeaturesWidget(QWidget* parent=0, const char* name="UBFeaturesWidget");
    virtual ~UBFeaturesWidget();

	bool visibleInMode(eUBDockPaletteWidgetMode mode)
    {
        return mode == eUBDockPaletteWidget_BOARD
            || mode == eUBDockPaletteWidget_DESKTOP;
    }
64
    UBFeaturesController * getFeaturesController() const { return controller; }
65
    void importImage(const QImage &image, const QString &fileName = QString());
66 67 68 69

	static const int minThumbnailSize = 20;
	static const int maxThumbnailSize = 100;
	static const int defaultThumbnailSize = 40;
70

71 72 73
    static const char *objNamePathList;
    static const char *objNameFeatureList;

74 75 76 77
public:
    int scrollbarHorisontalPadding() const { return 10;}
    int scrollbarVerticalIndent() const { return 0;}

78 79 80
signals:
    void sendFileNameList(const QStringList lst);

Anna Udovichenko's avatar
Anna Udovichenko committed
81
private slots:
Ilia Ryabokon's avatar
Ilia Ryabokon committed
82
    void onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
83 84 85 86 87 88 89
    void currentSelected( const QModelIndex & );
    void searchStarted( const QString & );
    void createNewFolder();
    void deleteElements( const UBFeaturesMimeData * );
    void addToFavorite( const UBFeaturesMimeData  *);
    void removeFromFavorite( const UBFeaturesMimeData * );
    void onDisplayMetadata( QMap<QString,QString> );
90
    void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray);
91
    void addElementsToFavorite();
92
    void removeElementsFromFavorite();
93
    void deleteSelectedElements();
94
    void rescanModel();
95
    void lockIt(bool pLock);
96 97 98 99 100 101 102 103 104 105 106

private:
    void switchToListView();
    void switchToProperties();
    void switchToWebView();

private:
    UBFeaturesController *controller;
    UBFeaturesListView *pathListView;
    QVBoxLayout *layout;
    UBFeaturesActionBar *mActionBar;
Ilia Ryabokon's avatar
Ilia Ryabokon committed
107
    UBDownloadHttpFile* imageGatherer;
108
    UBFeaturesCentralWidget *centralWidget;
109 110 111 112 113 114 115 116 117 118 119 120 121 122
};


class UBFeaturesMimeData : public QMimeData
{
    Q_OBJECT

public:
    virtual QStringList formats() const;
    QList<UBFeature> features() const {return mFeatures;}
    void setFeatures(const QList<UBFeature> &fList) {mFeatures = fList;}

private:
    QList<UBFeature> mFeatures;
Anna Udovichenko's avatar
Anna Udovichenko committed
123 124
};

125

126 127 128
class UBFeaturesListView : public QListView
{
	Q_OBJECT
129

130
public:
131
    UBFeaturesListView( QWidget* parent=0, const char* name="UBFeaturesListView" );
Ivan Ilin's avatar
Ivan Ilin committed
132
    virtual ~UBFeaturesListView() {;}
133

134
protected:
135
    virtual void dragEnterEvent( QDragEnterEvent *event );
136
    virtual void dropEvent( QDropEvent *event );
137
    virtual void dragMoveEvent( QDragMoveEvent *event );
138 139 140

private slots:
    void thumbnailSizeChanged(int);
141

142 143
};

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

// class created to have the same style for slider and QListView itself
class UBFeaturesNavigatorWidget: public QWidget
{
    Q_OBJECT

public:
    UBFeaturesNavigatorWidget(QWidget *parent, const char* name = "");
    UBFeaturesListView *listView() {return mListView;}
    void setSliderPosition(int pValue);

private:
    UBFeaturesListView *mListView;
    QSlider *mListSlder;

};

161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
class UBFeaturesCentralWidget : public QWidget
{
  Q_OBJECT

public:
    enum StackElement{
        MainList = 0,
        FeaturePropertiesList,
        FeaturesWebView
    };

    enum AddWidget {
        NewFolderDialog = 0,
        ProgressBarWidget
    };

    enum AddWidgetState {
        NonModal = 0,
        Modal
    };

    UBFeaturesCentralWidget(QWidget *parent = 0);
    void setSliderPosition(int pValue) {mNavigator->setSliderPosition(pValue);}

    UBFeaturesListView *listView() {return mNavigator->listView();}
    void showElement(const UBFeature &feature, StackElement pView);
    void switchTo(StackElement pView);
    void setPropertiesPixmap(const QPixmap &pix);
    void setPropertiesThumbnail(const QPixmap &pix);
    StackElement currentView() const {return static_cast<StackElement>(mStackedWidget->currentIndex());}
    UBFeature getCurElementFromProperties();

    void setLockedExcludingAdditional(bool pLock);

    QStackedWidget *mStackedWidget;
        UBFeaturesNavigatorWidget *mNavigator;
        UBFeatureProperties *mFeatureProperties;
        UBFeaturesWebView *webView;

    QStackedWidget *mAdditionalDataContainer;

signals:
    void lockMainWidget(bool pLock);
    void createNewFolderSignal(QString pStr);
205
    void sendFileNameList(const QStringList lst);
206 207 208

//    progressbar widget related signals
    void maxFilesCountEvaluated(int pValue);
209 210 211 212 213 214
    void increaseStatusBarValue();
    void scanCategory(const QString &);
    void scanPath(const QString &);

public slots:
    void showAdditionalData(AddWidget pWidgetType, AddWidgetState pState = NonModal);
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234

private slots:
    void createNewFolderSlot(QString pStr);
    void hideAdditionalData();

    void scanStarted();
    void scanFinished();
};

class UBFeaturesNewFolderDialog : public QWidget
{
    Q_OBJECT

public:
    static const QString acceptText;
    static const QString cancelText;
    static const QString labelText;

    UBFeaturesNewFolderDialog(QWidget *parent = 0);
    void setRegexp(const QRegExp pRegExp);
235
    bool validString(const QString &pStr);
236 237 238 239 240 241 242 243

signals:
    void createNewFolder(QString str);
    void closeDialog();

private slots:
    void accept();
    void reject();
244 245 246
    void setFileNameList(const QStringList &pLst);
    void reactOnTextChanged(const QString &pStr);

247 248 249
private:
    QLineEdit *mLineEdit;
    QRegExpValidator *mValidator;
250 251
    QStringList mFileNameList;
    QPushButton *acceptButton;
252 253

};
254

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
class UBFeaturesProgressInfo: public QWidget {
    Q_OBJECT

public:
    UBFeaturesProgressInfo(QWidget *parent = 0);

private slots:
    void setCommmonInfoText(const QString &str);
    void setDetailedInfoText(const QString &str);
    void setProgressMin(int pValue);
    void setProgressMax(int pValue);
    void increaseProgressValue();
    void sendFeature(UBFeature pFeature);


private:
    QProgressBar *mProgressBar;
    QLabel *mCommonInfoLabel;
    QLabel *mDetailedInfoLabel;
};

276 277 278 279 280
class UBFeaturesWebView : public QWidget
{
    Q_OBJECT
public:
    UBFeaturesWebView(QWidget* parent = 0, const char* name = "UBFeaturesWebView");
281
    virtual ~UBFeaturesWebView();
282 283 284 285 286

    void showElement(const UBFeature &elem);

private slots:
    void onLoadFinished(bool ok);
Claudio Valerio's avatar
Claudio Valerio committed
287
    void javaScriptWindowObjectCleared();
288 289 290 291 292 293 294

private:
    QWebView* mpView;
    QWebSettings* mpWebSettings;
    QVBoxLayout* mpLayout;
    UBWidgetUniboardAPI* mpSankoreAPI;
};
Anna Udovichenko's avatar
Anna Udovichenko committed
295 296 297 298 299 300 301 302 303

class UBFeatureProperties : public QWidget
{
    Q_OBJECT
public:
    UBFeatureProperties(QWidget* parent=0, const char* name="UBFeatureProperties");
    ~UBFeatureProperties();

    void showElement(const UBFeature &elem);
304
    UBFeature getCurrentElement() const;
305 306
    void setOrigPixmap(const QPixmap &pix);
    void setThumbnail(const QPixmap &pix);
307

Anna Udovichenko's avatar
Anna Udovichenko committed
308
protected:
309 310
    void resizeEvent(QResizeEvent *event);
    void showEvent(QShowEvent *event);
Anna Udovichenko's avatar
Anna Udovichenko committed
311 312 313

private slots:
    void onAddToPage();
314
    void onAddToLib();
315
    void onSetAsBackground();
Anna Udovichenko's avatar
Anna Udovichenko committed
316 317 318
    //void onBack();

private:
319
	void populateMetadata();
320
    void adaptSize();
321

Anna Udovichenko's avatar
Anna Udovichenko committed
322 323
    QVBoxLayout* mpLayout;
    QHBoxLayout* mpButtonLayout;
324 325 326
    UBFeatureItemButton *mpAddPageButton;
    UBFeatureItemButton *mpAddToLibButton;
    UBFeatureItemButton *mpSetAsBackgroundButton;
Anna Udovichenko's avatar
Anna Udovichenko committed
327
    QLabel* mpObjInfoLabel;
328
    QTreeWidget* mpObjInfos;
Anna Udovichenko's avatar
Anna Udovichenko committed
329 330 331 332
    QLabel* mpThumbnail;
    QPixmap* mpOrigPixmap;
    int maxThumbHeight;
    UBFeature *mpElement;
333
    QTreeWidgetItem* mpItem;
Anna Udovichenko's avatar
Anna Udovichenko committed
334 335 336 337 338 339 340 341 342 343 344 345
};

class UBFeatureItemButton : public QPushButton
{
public:
    UBFeatureItemButton(QWidget* parent=0, const char* name="UBFeatureItemButton");
    ~UBFeatureItemButton();
};

class UBFeaturesModel : public QAbstractListModel
{
	Q_OBJECT
346 347 348 349

signals:
    void dataRestructured();

Anna Udovichenko's avatar
Anna Udovichenko committed
350
public:
351
    UBFeaturesModel(QList<UBFeature> *pFeaturesList, QObject *parent = 0) : QAbstractListModel(parent), featuresList(pFeaturesList) {;}
Ivan Ilin's avatar
Ivan Ilin committed
352
    virtual ~UBFeaturesModel(){;}
Anna Udovichenko's avatar
Anna Udovichenko committed
353

354
	void deleteFavoriteItem( const QString &path );
355
    void deleteItem( const QString &path );
356
    void deleteItem(const UBFeature &feature);
357

Anna Udovichenko's avatar
Anna Udovichenko committed
358 359 360 361 362 363 364 365
	QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
	QMimeData *mimeData( const QModelIndexList &indexes ) const;
	QStringList mimeTypes() const;
	int rowCount( const QModelIndex &parent ) const;
	Qt::ItemFlags flags( const QModelIndex &index ) const;
    bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent);
	bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
	bool removeRow(int row, const QModelIndex &parent = QModelIndex());
366 367
    //bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
    //bool insertRow(int row, const QModelIndex &parent = QModelIndex());
368 369

    void moveData(const UBFeature &source, const UBFeature &destination, Qt::DropAction action, bool deleteManualy = false);
Ivan Ilin's avatar
Ivan Ilin committed
370
    Qt::DropActions supportedDropActions() const { return Qt::MoveAction | Qt::CopyAction; }
371
//    void setFeaturesList(QList <UBFeature> *flist ) { featuresList = flist; }
Anna Udovichenko's avatar
Anna Udovichenko committed
372

373 374 375
public slots:
    void addItem( const UBFeature &item );

Anna Udovichenko's avatar
Anna Udovichenko committed
376
private:
377
	QList <UBFeature> *featuresList;
Anna Udovichenko's avatar
Anna Udovichenko committed
378 379 380 381 382 383
};

class UBFeaturesProxyModel : public QSortFilterProxyModel
{
	Q_OBJECT
public:
Ivan Ilin's avatar
Ivan Ilin committed
384 385
    UBFeaturesProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;}
    virtual ~UBFeaturesProxyModel() {}
Anna Udovichenko's avatar
Anna Udovichenko committed
386 387 388 389 390 391 392 393
protected:
	virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const;
};

class UBFeaturesSearchProxyModel : public QSortFilterProxyModel
{
	Q_OBJECT
public:
394
    UBFeaturesSearchProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent), mFilterPrefix() {;}
Ivan Ilin's avatar
Ivan Ilin committed
395
    virtual ~UBFeaturesSearchProxyModel() {}
396
    void setFilterPrefix(const QString &newPrefix) {mFilterPrefix = newPrefix;}
Anna Udovichenko's avatar
Anna Udovichenko committed
397 398
protected:
	virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const;
399 400
private:
    QString mFilterPrefix;
Anna Udovichenko's avatar
Anna Udovichenko committed
401 402 403 404 405 406
};

class UBFeaturesPathProxyModel : public QSortFilterProxyModel
{
	Q_OBJECT
public:
Ivan Ilin's avatar
Ivan Ilin committed
407 408 409
    UBFeaturesPathProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;}
    virtual ~UBFeaturesPathProxyModel() {}
    void setPath( const QString &p ) { path = p; }
Anna Udovichenko's avatar
Anna Udovichenko committed
410 411 412 413 414 415 416 417 418 419
protected:
	virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const;
private:
	QString path;
};

class UBFeaturesItemDelegate : public QStyledItemDelegate
{
	Q_OBJECT
public:
420
    UBFeaturesItemDelegate(QObject *parent = 0, const QListView *lw = 0) : QStyledItemDelegate(parent) { listView = lw; }
Ivan Ilin's avatar
Ivan Ilin committed
421
    ~UBFeaturesItemDelegate() {}
Anna Udovichenko's avatar
Anna Udovichenko committed
422 423 424 425 426 427 428 429 430 431 432 433
	//UBFeaturesItemDelegate(const QListView *lw = 0) { listView = lw; };
	//void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    //QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
	virtual QString	displayText ( const QVariant & value, const QLocale & locale ) const;
private:
	const QListView *listView;
};

class UBFeaturesPathItemDelegate : public QStyledItemDelegate
{
	Q_OBJECT
public:
434
    UBFeaturesPathItemDelegate(QObject *parent = 0);
Anna Udovichenko's avatar
Anna Udovichenko committed
435 436 437 438 439 440 441
	~UBFeaturesPathItemDelegate();
	virtual QString	displayText ( const QVariant & value, const QLocale & locale ) const;
	void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
	QPixmap *arrowPixmap;
};

442

Ivan Ilin's avatar
Ivan Ilin committed
443
#endif // UBFEATURESWIDGET_H