diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 802e69ed1..a4ce2c722 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -1,4 +1,6 @@ -CONFIG += qt gui uic qrc resources uitools idle bitdht # framecatcher# blogs +CONFIG += qt gui uic qrc resources uitools idle bitdht +CONFIG += photoshare wikipoos + QT += network xml script TEMPLATE = app @@ -843,3 +845,45 @@ minimal { util/stringutil.h \ lang/languagesupport.h } + + + +photoshare { + + HEADERS += gui/PhotoShare/PhotoItem.h \ + gui/PhotoShare/PhotoDialog.h \ + gui/PhotoShare/PhotoAddDialog.h \ + gui/PhotoShare/PhotoDetailsDialog.h \ + gui/PhotoShare/PhotoDrop.h \ + + FORMS += gui/PhotoShare/PhotoItem.ui \ + gui/PhotoShare/PhotoDialog.ui \ + gui/PhotoShare/PhotoAddDialog.ui \ + gui/PhotoShare/PhotoDetailsDialog.ui \ + + SOURCES += gui/PhotoShare/PhotoItem.cpp \ + gui/PhotoShare/PhotoDialog.cpp \ + gui/PhotoShare/PhotoAddDialog.cpp \ + gui/PhotoShare/PhotoDetailsDialog.cpp \ + gui/PhotoShare/PhotoDrop.cpp \ + +} + + +wikipoos { + + HEADERS += gui/WikiPoos/WikiDialog.h \ + gui/WikiPoos/WikiAddDialog.h \ + gui/WikiPoos/WikiEditDialog.h \ + + FORMS += gui/WikiPoos/WikiDialog.ui \ + gui/WikiPoos/WikiAddDialog.ui \ + gui/WikiPoos/WikiEditDialog.ui \ + + SOURCES += gui/WikiPoos/WikiDialog.cpp \ + gui/WikiPoos/WikiAddDialog.cpp \ + gui/WikiPoos/WikiEditDialog.cpp \ + +} + + diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 7e1cb1482..2925539f4 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -57,6 +57,10 @@ #include "chat/PopupChatDialog.h" #include "RetroShareLink.h" + // New Cache Classes - +#include "gui/PhotoShare/PhotoDialog.h" +#include "gui/WikiPoos/WikiDialog.h" + #ifdef UNFINISHED #include "unfinished/ApplicationWindow.h" #endif @@ -316,6 +320,17 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) } #endif + // New Cache Classes - + MainPage *photoPage = NULL; + ui.stackPages->add(photoPage = new PhotoDialog(ui.stackPages), + createPageAction(QIcon(IMG_HELP), tr("PhotoShare"), grp)); + + // New Cache Classes - + MainPage *wikiPage = NULL; + ui.stackPages->add(wikiPage = new WikiDialog(ui.stackPages), + createPageAction(QIcon(IMG_HELP), tr("WikiPoos"), grp)); + + /* Create the toolbar */ ui.toolBar->addActions(grp->actions()); diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.cpp b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.cpp new file mode 100644 index 000000000..26302cf2b --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.cpp @@ -0,0 +1,162 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "gui/PhotoShare/PhotoAddDialog.h" +#include "gui/PhotoShare/PhotoDetailsDialog.h" +#include "gui/PhotoShare/PhotoDrop.h" + +#include + +/** Constructor */ +PhotoAddDialog::PhotoAddDialog(QWidget *parent) +: QWidget(parent) +{ + ui.setupUi(this); + + connect(ui.scrollAreaWidgetContents, SIGNAL( buttonStatus( uint32_t ) ), this, SLOT( updateMoveButtons( uint32_t ) ) ); + connect(ui.pushButton_ShiftLeft, SIGNAL( clicked( void ) ), ui.scrollAreaWidgetContents, SLOT( moveLeft( void ) ) ); + connect(ui.pushButton_ShiftRight, SIGNAL( clicked( void ) ), ui.scrollAreaWidgetContents, SLOT( moveRight( void ) ) ); + connect(ui.pushButton_EditPhotoDetails, SIGNAL( clicked( void ) ), this, SLOT( showPhotoDetails( void ) ) ); + + connect(ui.pushButton_Publish, SIGNAL( clicked( void ) ), this, SLOT( publishAlbum( void ) ) ); + + mPhotoDetails = NULL; + +} + + +void PhotoAddDialog::updateMoveButtons(uint32_t status) +{ + std::cerr << "PhotoAddDialog::updateMoveButtons(" << status << ")"; + std::cerr << std::endl; + + switch(status) + { + case PHOTO_SHIFT_NO_BUTTONS: + ui.pushButton_ShiftLeft->setEnabled(false); + ui.pushButton_ShiftRight->setEnabled(false); + break; + case PHOTO_SHIFT_LEFT_ONLY: + ui.pushButton_ShiftLeft->setEnabled(true); + ui.pushButton_ShiftRight->setEnabled(false); + break; + case PHOTO_SHIFT_RIGHT_ONLY: + ui.pushButton_ShiftLeft->setEnabled(false); + ui.pushButton_ShiftRight->setEnabled(true); + break; + case PHOTO_SHIFT_BOTH: + ui.pushButton_ShiftLeft->setEnabled(true); + ui.pushButton_ShiftRight->setEnabled(true); + break; + } +} + + +void PhotoAddDialog::showPhotoDetails() +{ + std::cerr << "PhotoAddDialog::showPhotoDetails()"; + std::cerr << std::endl; + + if (!mPhotoDetails) + { + mPhotoDetails = new PhotoDetailsDialog(NULL); + } + + PhotoItem *item = ui.scrollAreaWidgetContents->getSelectedPhotoItem(); + + mPhotoDetails->setPhotoItem(item); + mPhotoDetails->show(); +} + + + + +void PhotoAddDialog::publishAlbum() +{ + std::cerr << "PhotoAddDialog::publishAlbum()"; + std::cerr << std::endl; + + /* we need to iterate through each photoItem, and extract the details */ + + + RsPhotoAlbum album; + RsPhotoThumbnail albumThumb; + + album.mShareOptions.mShareType = 0; + album.mShareOptions.mShareGroupId = "unknown"; + album.mShareOptions.mPublishKey = "unknown"; + album.mShareOptions.mCommentMode = 0; + album.mShareOptions.mResizeMode = 0; + + album.mTitle = ui.lineEdit_Title->text().toStdString(); + album.mCategory = "Unknown"; + album.mCaption = ui.lineEdit_Caption->text().toStdString(); + album.mWhere = ui.lineEdit_Where->text().toStdString(); + album.mWhen = ui.lineEdit_When->text().toStdString(); + + if (rsPhoto->submitAlbumDetails(album, albumThumb)) + { + /* now have path and album id */ + int photoCount = ui.scrollAreaWidgetContents->getPhotoCount(); + + for(int i = 0; i < photoCount; i++) + { + RsPhotoPhoto photo; + RsPhotoThumbnail thumbnail; + PhotoItem *item = ui.scrollAreaWidgetContents->getPhotoIdx(i); + photo = item->mDetails; + item->getPhotoThumbnail(thumbnail); + + photo.mAlbumId = album.mAlbumId; + photo.mOrder = i; + + /* scale photo if needed */ + if (album.mShareOptions.mResizeMode) + { + /* */ + + } + /* save image to album path */ + photo.path = "unknown"; + + rsPhoto->submitPhoto(photo, thumbnail); + } + } + + clearDialog(); + + hide(); +} + + +void PhotoAddDialog::clearDialog() +{ + ui.lineEdit_Title->setText(QString("title")); + ui.lineEdit_Caption->setText(QString("Caption")); + ui.lineEdit_Where->setText(QString("Where")); + ui.lineEdit_When->setText(QString("When")); + + ui.scrollAreaWidgetContents->clearPhotos(); +} + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.h b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.h new file mode 100644 index 000000000..36a8055de --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.h @@ -0,0 +1,53 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_PHOTO_ADD_DIALOG_H +#define MRK_PHOTO_ADD_DIALOG_H + +#include "ui_PhotoAddDialog.h" + +class PhotoDetailsDialog; + +class PhotoAddDialog : public QWidget +{ + Q_OBJECT + +public: + PhotoAddDialog(QWidget *parent = 0); + +private slots: + void showPhotoDetails(); + void updateMoveButtons(uint32_t status); + + void publishAlbum(); + void clearDialog(); + +protected: + + PhotoDetailsDialog *mPhotoDetails; + Ui::PhotoAddDialog ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.ui b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.ui new file mode 100644 index 000000000..eff5b7584 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoAddDialog.ui @@ -0,0 +1,466 @@ + + + PhotoAddDialog + + + + 0 + 0 + 852 + 383 + + + + + + + + + + Qt::Vertical + + + + + + + + 1 + 0 + + + + Share Options + + + + + + + 0 + 0 + + + + + Public + + + + + All Friends + + + + + Restricted + + + + + + + + + 0 + 0 + + + + + N/A + + + + + University Friends + + + + + Family + + + + + This List Contains + + + + + All your Groups + + + + + + + + + 0 + 0 + + + + + Resize Images (< 1Mb) + + + + + Resize Images (< 10Mb) + + + + + Send Original Images + + + + + + + + + 0 + 0 + + + + + No Comments Allowed + + + + + Authenticated Comments + + + + + Any Comments Allowed + + + + + + + + + 0 + 0 + + + + + Publish with XXX Key + + + + + + + + + + + + 0 + 1 + + + + Album Thumbnail + + + + + + Album Thumbnail......... +Drag and Drop an Image +from the Picture List +to make it the Album +Image +1 +2 + + + + + + + + + + + 10 + 1 + + + + Basic Details + + + + + + + 0 + 0 + + + + + + + + Category: + + + + + + + + Travel + + + + + Holiday + + + + + Friends + + + + + Family + + + + + Work + + + + + Random + + + + + + + + Caption + + + + + + + + 0 + 0 + + + + + + + + Where: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + Album Title: + + + + + + + When + + + + + + + + + + Delete Album + + + + + + + Qt::Horizontal + + + + 78 + 20 + + + + + + + + Edit Album Details + + + + + + + + + + + HELP: Drag & Drop to insert, and re-order pictures. Click on a picture to edit details below. + + + + + + + + 0 + 10 + + + + true + + + Qt::ScrollBarAsNeeded + + + true + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + 0 + 0 + 822 + 76 + + + + QWidget#scrollAreaWidgetContents{border: none;} + + + + + + + + + + + + + + + Edit Photo Details + + + + + + + Qt::Horizontal + + + + 68 + 17 + + + + + + + + << + + + + + + + >> + + + + + + + Qt::Horizontal + + + + 68 + 17 + + + + + + + + Publish Album + + + + + + + + + + PhotoDrop + QWidget +
gui/PhotoShare/PhotoDrop.h
+ 1 +
+
+ + + + +
diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.cpp b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.cpp new file mode 100644 index 000000000..42ae09461 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.cpp @@ -0,0 +1,127 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "gui/PhotoShare/PhotoDetailsDialog.h" +#include "gui/PhotoShare/PhotoItem.h" + +/** Constructor */ +PhotoDetailsDialog::PhotoDetailsDialog(QWidget *parent) +: QWidget(parent) +{ + ui.setupUi(this); + connect( ui.pushButton_Update, SIGNAL( clicked() ), this, SLOT( updateDetails () ) ); + +} + + +void PhotoDetailsDialog::setPhotoItem(PhotoItem *item) +{ + if (mPhotoItem == item) + { + return; + } + + mPhotoItem = item; + + /* update fields from the edit fields */ + refreshDetails(); +} + + +void PhotoDetailsDialog::refreshDetails() +{ + + if(!mPhotoItem) + { + blankDetails(); + } + + ui.label_Headline->setText(QString("Photo Description")); + + //ui.comboBox_Category= mPhotoItem->mDetails.mCaption; + + ui.lineEdit_Caption->setText(QString::fromStdString(mPhotoItem->mDetails.mCaption)); + ui.textEdit_Description->setText(QString::fromStdString(mPhotoItem->mDetails.mDescription)); + ui.lineEdit_Photographer->setText(QString::fromStdString(mPhotoItem->mDetails.mPhotographer)); + ui.lineEdit_Where->setText(QString::fromStdString(mPhotoItem->mDetails.mWhere)); + ui.lineEdit_When->setText(QString::fromStdString(mPhotoItem->mDetails.mWhen)); + ui.lineEdit_Other->setText(QString::fromStdString(mPhotoItem->mDetails.mOther)); + ui.lineEdit_Title->setText(QString::fromStdString(mPhotoItem->mDetails.mTitle)); + ui.lineEdit_HashTags->setText(QString::fromStdString(mPhotoItem->mDetails.mHashTags)); + + const QPixmap *qtn = mPhotoItem->getPixmap(); + QPixmap cpy(*qtn); + ui.label_Photo->setPixmap(cpy); +} + +void PhotoDetailsDialog::blankDetails() +{ + ui.label_Headline->setText(QString("Nothing")); + + //ui.comboBox_Category= mPhotoItem->mDetails.mCaption; + + ui.lineEdit_Caption->setText(QString("N/A")); + ui.textEdit_Description->setText(QString("N/A")); + ui.lineEdit_Photographer->setText(QString("N/A")); + ui.lineEdit_Where->setText(QString("N/A")); + ui.lineEdit_When->setText(QString("N/A")); + ui.lineEdit_Other->setText(QString("N/A")); + ui.lineEdit_Title->setText(QString("N/A")); + ui.lineEdit_HashTags->setText(QString("N/A")); + + //QPixmap qtn = mPhotoItem->getPixmap(); + //ui.label_Photo->setPixmap(qtn); +} + + +void PhotoDetailsDialog::updateDetails() +{ + saveDetails(); + + hide(); +} + +void PhotoDetailsDialog::saveDetails() +{ + + if(!mPhotoItem) + { + return; + } + + //mPhotoItem->mDetails.mCaption = ui.comboBox_Category; + + mPhotoItem->mDetails.mCaption = ui.lineEdit_Caption->text().toStdString(); + mPhotoItem->mDetails.mDescription = ui.textEdit_Description->toPlainText().toStdString(); + mPhotoItem->mDetails.mPhotographer = ui.lineEdit_Photographer->text().toStdString(); + mPhotoItem->mDetails.mWhere = ui.lineEdit_Where->text().toStdString(); + mPhotoItem->mDetails.mWhen = ui.lineEdit_When->text().toStdString(); + mPhotoItem->mDetails.mOther = ui.lineEdit_Other->text().toStdString(); + mPhotoItem->mDetails.mTitle = ui.lineEdit_Title->text().toStdString(); + mPhotoItem->mDetails.mHashTags = ui.lineEdit_HashTags->text().toStdString(); + + //QPixmap qtn = mPhotoItem->getPixmap(); + //ui.label_Photo->setPixmap(qtn); +} + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.h b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.h new file mode 100644 index 000000000..0e3c2746d --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.h @@ -0,0 +1,56 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_PHOTO_DETAILS_DIALOG_H +#define MRK_PHOTO_DETAILS_DIALOG_H + +#include "ui_PhotoDetailsDialog.h" + +class PhotoItem; + +class PhotoDetailsDialog : public QWidget +{ + Q_OBJECT + +public: + PhotoDetailsDialog(QWidget *parent = 0); + +void setPhotoItem(PhotoItem *item); + +private: +void saveDetails(); +void refreshDetails(); + +private slots: +void updateDetails(); +void blankDetails(); + +private: + PhotoItem *mPhotoItem; + + Ui::PhotoDetailsDialog ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.ui b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.ui new file mode 100644 index 000000000..45bc80d3f --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDetailsDialog.ui @@ -0,0 +1,221 @@ + + + PhotoDetailsDialog + + + + 0 + 0 + 683 + 415 + + + + + + + + + + + + + + + 18 + 75 + true + + + + Album Description + + + + + + + Album Name: + + + + + + + + + + Category: + + + + + + + + Travel + + + + + Holiday + + + + + Friends + + + + + Family + + + + + Work + + + + + Random + + + + + + + + + + Thumbnail +Here +Dummy +Text +1 +2 +3 +................................... + + + + + + + + + + + Caption: + + + + + + + + + + Photographer: + + + + + + + + + + Description + + + + + + + + + + Where: + + + + + + + + + + When + + + + + + + + + + Other 1: + + + + + + + + + + HashTags: + + + + + + + + + + Qt::Vertical + + + + 20 + 18 + + + + + + + + + + + + Qt::Horizontal + + + + 598 + 20 + + + + + + + + Update Details + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDialog.cpp b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.cpp new file mode 100644 index 000000000..f3e9741c4 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.cpp @@ -0,0 +1,461 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include "PhotoDialog.h" + +#include +#include + +#include +#include + +#include + +/****** + * #define PHOTO_DEBUG 1 + *****/ + + +/**************************************************************** + * New Photo Display Widget. + * + * This has two 'lists'. + * Top list shows Albums. + * Lower list is photos from the selected Album. + * + * Notes: + * Each Item will be an AlbumItem, which contains a thumbnail & random details. + * We will limit Items to < 100. With a 'Filter to see more message. + * + * Thumbnails will come from Service. + * Option to Share albums / pictures onward (if permissions allow). + * Option to Download the albums to a specified directory. (is this required if sharing an album?) + * + * Will introduce a FullScreen SlideShow later... first get basics happening. + */ + + + + +/** Constructor */ +PhotoDialog::PhotoDialog(QWidget *parent) +: MainPage(parent) +{ + ui.setupUi(this); + + mAddDialog = NULL; + mAlbumSelected = NULL; + mPhotoSelected = NULL; + + connect( ui.toolButton_NewAlbum, SIGNAL(clicked()), this, SLOT(OpenOrShowPhotoAddDialog())); + + QTimer *timer = new QTimer(this); + timer->connect(timer, SIGNAL(timeout()), this, SLOT(checkUpdate())); + timer->start(1000); + + +} + + +void PhotoDialog::notifySelection(PhotoItem *item, int ptype) +{ + std::cerr << "PhotoDialog::notifySelection() from : " << ptype << " " << item; + std::cerr << std::endl; + + switch(ptype) + { + default: + case PHOTO_ITEM_TYPE_ALBUM: + notifyAlbumSelection(item); + break; + case PHOTO_ITEM_TYPE_PHOTO: + notifyPhotoSelection(item); + break; + } +} + +void PhotoDialog::notifyAlbumSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyAlbumSelection() from : " << item; + std::cerr << std::endl; + + if (mAlbumSelected) + { + std::cerr << "PhotoDialog::notifyAlbumSelection() unselecting old one : " << mAlbumSelected; + std::cerr << std::endl; + + mAlbumSelected->setSelected(false); + } + + mAlbumSelected = item; + insertPhotosForSelectedAlbum(); +} + + +void PhotoDialog::notifyPhotoSelection(PhotoItem *item) +{ + std::cerr << "PhotoDialog::notifyPhotoSelection() from : " << item; + std::cerr << std::endl; + + if (mPhotoSelected) + { + std::cerr << "PhotoDialog::notifyPhotoSelection() unselecting old one : " << mPhotoSelected; + std::cerr << std::endl; + + mPhotoSelected->setSelected(false); + } + + mPhotoSelected = item; +} + + +void PhotoDialog::checkUpdate() +{ + /* update */ + if (!rsPhoto) + return; + + if (rsPhoto->updated()) + { + insertAlbums(); + } + + return; +} + + +/*************** New Photo Dialog ***************/ + +void PhotoDialog::OpenOrShowPhotoAddDialog() +{ + if (mAddDialog) + { + mAddDialog->show(); + } + else + { + mAddDialog = new PhotoAddDialog(NULL); + mAddDialog->show(); + } +} + + +bool PhotoDialog::matchesAlbumFilter(const RsPhotoAlbum &album) +{ + + return true; +} + +double PhotoDialog::AlbumScore(const RsPhotoAlbum &album) +{ + return 1; +} + + +bool PhotoDialog::matchesPhotoFilter(const RsPhotoPhoto &photo) +{ + + return true; +} + +double PhotoDialog::PhotoScore(const RsPhotoPhoto &photo) +{ + return 1; +} + + +bool PhotoDialog::FilterNSortAlbums(const std::list &albumIds, std::list &filteredAlbumIds, int count) +{ + std::multimap sortedAlbums; + std::multimap::iterator sit; + std::list::const_iterator it; + + for(it = albumIds.begin(); it != albumIds.end(); it++) + { + RsPhotoAlbum album; + rsPhoto->getAlbum(*it, album); + + if (matchesAlbumFilter(album)) + { + double score = AlbumScore(album); + + sortedAlbums.insert(std::make_pair(score, *it)); + } + } + + int i; + for (sit = sortedAlbums.begin(), i = 0; (sit != sortedAlbums.end()) && (i < count); sit++, i++) + { + filteredAlbumIds.push_back(sit->second); + } + + return true; +} + + +bool PhotoDialog::FilterNSortPhotos(const std::list &photoIds, std::list &filteredPhotoIds, int count) +{ + std::multimap sortedPhotos; + std::multimap::iterator sit; + std::list::const_iterator it; + + int i = 0; + for(it = photoIds.begin(); it != photoIds.end(); it++, i++) + { + RsPhotoPhoto photo; + rsPhoto->getPhoto(*it, photo); + + if (matchesPhotoFilter(photo)) + { + double score = i; //PhotoScore(album); + sortedPhotos.insert(std::make_pair(score, *it)); + } + } + + for (sit = sortedPhotos.begin(), i = 0; (sit != sortedPhotos.end()) && (i < count); sit++, i++) + { + filteredPhotoIds.push_back(sit->second); + } + return true; +} + + + +void PhotoDialog::insertAlbums() +{ + /* clear it all */ + clearAlbums(); + //ui.albumLayout->clear(); + + /* create a list of albums */ + + + std::list albumIds; + std::list filteredAlbumIds; + std::list::iterator it; + + rsPhoto->getAlbumList(albumIds); + + /* Filter Albums */ /* Sort Albums */ +#define MAX_ALBUMS 50 + + int count = MAX_ALBUMS; + FilterNSortAlbums(albumIds, filteredAlbumIds, count); + + for(it = filteredAlbumIds.begin(); it != filteredAlbumIds.end(); it++) + { + addAlbum(*it); + } + + insertPhotosForAlbum(filteredAlbumIds); +} + +void PhotoDialog::insertPhotosForSelectedAlbum() +{ + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum()"; + std::cerr << std::endl; + + clearPhotos(); + + std::list albumIds; + if (mAlbumSelected) + { + albumIds.push_back(mAlbumSelected->mDetails.mAlbumId); + + std::cerr << "PhotoDialog::insertPhotosForSelectedAlbum() AlbumId: " << mAlbumSelected->mDetails.mAlbumId; + std::cerr << std::endl; + } + + insertPhotosForAlbum(albumIds); +} + + +void PhotoDialog::addAlbum(const std::string &id) +{ + + RsPhotoAlbum album; + rsPhoto->getAlbum(id, album); + + + RsPhotoThumbnail thumbnail; + rsPhoto->getAlbumThumbnail(id, thumbnail); + + std::cerr << " PhotoDialog::addAlbum() AlbumId: " << album.mAlbumId << std::endl; + + PhotoItem *item = new PhotoItem(this, album, thumbnail); + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + alayout->addWidget(item); +} + +void PhotoDialog::clearAlbums() +{ + std::cerr << "PhotoDialog::clearAlbums()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearAlbums() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearAlbums() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearAlbums() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + mAlbumSelected = NULL; + +} + +void PhotoDialog::clearPhotos() +{ + std::cerr << "PhotoDialog::clearPhotos()" << std::endl; + + std::list photoItems; + std::list::iterator pit; + + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + int count = alayout->count(); + for(int i = 0; i < count; i++) + { + QLayoutItem *litem = alayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDialog::clearPhotos() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + std::cerr << "PhotoDialog::clearPhotos() item: " << item; + std::cerr << std::endl; + + photoItems.push_back(item); + } + else + { + std::cerr << "PhotoDialog::clearPhotos() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + alayout->removeWidget(item); + delete item; + } + + mPhotoSelected = NULL; + + +} + + +void PhotoDialog::insertPhotosForAlbum(const std::list &albumIds) +{ + /* clear it all */ + clearPhotos(); + //ui.photoLayout->clear(); + + /* create a list of albums */ + + std::list ids; + std::list photoIds; + std::list filteredPhotoIds; + std::list::const_iterator it; + + for(it = albumIds.begin(); it != albumIds.end(); it++) + { + rsPhoto->getPhotoList(*it, photoIds); + } + + /* Filter Albums */ /* Sort Albums */ +#define MAX_PHOTOS 50 + + int count = MAX_PHOTOS; + + FilterNSortPhotos(photoIds, filteredPhotoIds, MAX_PHOTOS); + + for(it = filteredPhotoIds.begin(); it != filteredPhotoIds.end(); it++) + { + addPhoto(*it); + } +} + + +void PhotoDialog::addPhoto(const std::string &id) +{ + + RsPhotoPhoto photo; + rsPhoto->getPhoto(id,photo); + + RsPhotoThumbnail thumbnail; + rsPhoto->getPhotoThumbnail(id, thumbnail); + + std::cerr << "PhotoDialog::addPhoto() AlbumId: " << photo.mAlbumId; + std::cerr << " PhotoId: " << photo.mId; + std::cerr << std::endl; + + PhotoItem *item = new PhotoItem(this, photo, thumbnail); + QLayout *alayout = ui.scrollAreaWidgetContents_2->layout(); + alayout->addWidget(item); + +} + + +void PhotoDialog::deletePhotoItem(PhotoItem *item, uint32_t type) +{ + + + return; +} + + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDialog.h b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.h new file mode 100644 index 000000000..bf2cc3708 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.h @@ -0,0 +1,93 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_PHOTO_DIALOG_H +#define MRK_PHOTO_DIALOG_H + +#include "gui/mainpage.h" +#include "ui_PhotoDialog.h" + +#include + +#include + +#include "gui/PhotoShare/PhotoItem.h" +#include "gui/PhotoShare/PhotoAddDialog.h" + +class PhotoDialog : public MainPage, public PhotoHolder +{ + Q_OBJECT + +public: + PhotoDialog(QWidget *parent = 0); + +virtual void deletePhotoItem(PhotoItem *, uint32_t type); +virtual void notifySelection(PhotoItem *item, int ptype); + + void notifyAlbumSelection(PhotoItem *item); + void notifyPhotoSelection(PhotoItem *item); + +private slots: + + void checkUpdate(); + void OpenOrShowPhotoAddDialog(); + +private: + + + + /* TODO: These functions must be filled in for proper filtering to work + * and tied to the GUI input + */ + + bool matchesAlbumFilter(const RsPhotoAlbum &album); + double AlbumScore(const RsPhotoAlbum &album); + bool matchesPhotoFilter(const RsPhotoPhoto &photo); + double PhotoScore(const RsPhotoPhoto &photo); + + /* Grunt work of setting up the GUI */ + + bool FilterNSortAlbums(const std::list &albumIds, std::list &filteredAlbumIds, int count); + bool FilterNSortPhotos(const std::list &photoIds, std::list &filteredPhotoIds, int count); + void insertAlbums(); + void insertPhotosForAlbum(const std::list &albumIds); + void insertPhotosForSelectedAlbum(); + + void addAlbum(const std::string &id); + void addPhoto(const std::string &id); + + void clearAlbums(); + void clearPhotos(); + + PhotoAddDialog *mAddDialog; + + PhotoItem *mAlbumSelected; + PhotoItem *mPhotoSelected; + + /* UI - from Designer */ + Ui::PhotoDialog ui; + +}; + +#endif + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDialog.ui b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.ui new file mode 100644 index 000000000..385336ad0 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDialog.ui @@ -0,0 +1,239 @@ + + + PhotoDialog + + + + 0 + 0 + 774 + 608 + + + + + + + + + + + + Filter + + + + + + + + + + Source + + + + + Category + + + + + Rating + + + + + + + + + + + [ - ] + + + + + + + [ + ] + + + + + + + + + + + + Source + + + + + Category + + + + + Rating + + + + + + + + + + + [ - ] + + + + + + + [ + ] + + + + + + + + + + + Qt::Vertical + + + + true + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + 0 + 0 + 746 + 227 + + + + QWidget#scrollAreaWidgetContents{border: none;} + + + + + + + + + + + + + Qt::Horizontal + + + + 139 + 20 + + + + + + + + + + true + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + 0 + 0 + 746 + 227 + + + + QWidget#scrollAreaWidgetContents{border: none;} + + + + + + Qt::Horizontal + + + + 426 + 20 + + + + + + + + + + + + + + + Remove Picture + + + + + + + Slide Show + + + + + + + Edit Album + + + + + + + Edit Picture Details + + + + + + + New Album + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDialog_v1.ui b/retroshare-gui/src/gui/PhotoShare/PhotoDialog_v1.ui new file mode 100644 index 000000000..3e44e7d1f --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDialog_v1.ui @@ -0,0 +1,273 @@ + + + PhotoDialog + + + + 0 + 0 + 774 + 608 + + + + + + + + + + + + Filter + + + + + + + + + + Source + + + + + Category + + + + + Rating + + + + + + + + + + + [ - ] + + + + + + + [ + ] + + + + + + + + + + + + Source + + + + + Category + + + + + Rating + + + + + + + + + + + [ - ] + + + + + + + [ + ] + + + + + + + + + + + Qt::Vertical + + + + true + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + 0 + 0 + 746 + 227 + + + + QWidget#scrollAreaWidgetContents{border: none;} + + + + + + + + + Album 1 + + + + + + + Album 2 + + + + + + + Album 3 + + + + + + + Album 4 + + + + + + + Qt::Horizontal + + + + 139 + 20 + + + + + + + + + + true + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + + + 0 + 0 + 746 + 227 + + + + QWidget#scrollAreaWidgetContents{border: none;} + + + + + + + + + PICTURE 1 + + + + + + + Qt::Horizontal + + + + 426 + 20 + + + + + + + + + + + + + + + Remove Picture + + + + + + + Slide Show + + + + + + + Edit Album + + + + + + + Edit Picture Details + + + + + + + New Album + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDrop.cpp b/retroshare-gui/src/gui/PhotoShare/PhotoDrop.cpp new file mode 100644 index 000000000..01ecf0c49 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDrop.cpp @@ -0,0 +1,641 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#include + +#include "PhotoDrop.h" + +#include + +// Helper Class +class gridIndex +{ + public: + gridIndex() + :row(0), column(0) { return; } + + gridIndex(int in_row, int in_column) + :row(in_row), column(in_column) { return; } + + bool operator<(const gridIndex &other) const + { + if (row == other.row) + { + return (column < other.column); + } + return (row < other.row); + } + + int row, column; +}; + + + + + +PhotoDrop::PhotoDrop(QWidget *parent) + : QWidget(parent) +{ + setAcceptDrops(true); + mSelected = NULL; + checkMoveButtons(); + reorderPhotos(); +} + +void PhotoDrop::notifySelection(PhotoItem *item, int ptype) +{ + std::cerr << "PhotoDrop::notifySelection() from : " << ptype << " " << item; + std::cerr << std::endl; + + if (mSelected) + { + std::cerr << "PhotoDrop::notifySelection() unselecting old one : " << mSelected; + std::cerr << std::endl; + + mSelected->setSelected(false); + } + + mSelected = item; + checkMoveButtons(); +} + + +void PhotoDrop::clear() +{ +} + + +PhotoItem *PhotoDrop::getSelectedPhotoItem() +{ + return mSelected; +} + + +void PhotoDrop::deletePhotoItem(PhotoItem *, uint32_t type) +{ + return; +} + + +void PhotoDrop::resizeEvent ( QResizeEvent * event ) +{ + /* calculate the preferred number of columns for the PhotoItems */ + reorderPhotos(); +} + +int PhotoDrop::getPhotoCount() +{ + std::cerr << "PhotoDrop::getPhotoCount()"; + std::cerr << std::endl; + + /* grab the first PhotoItem - and get it size */ + const QObjectList &items = children(); + QObjectList::const_iterator qit; + int count = 0; + for(qit = items.begin(); qit != items.end(); qit++) + { + PhotoItem *item = dynamic_cast(*qit); + if (item) + { + std::cerr << "PhotoDrop::getPhotoCount() item: " << item; + std::cerr << std::endl; + + count++; + } + else + { + std::cerr << "PhotoDrop::getPhotoCount() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + return count; +} + + + +PhotoItem *PhotoDrop::getPhotoIdx(int idx) +{ + std::cerr << "PhotoDrop::getPhotoIdx(" << idx << ")"; + std::cerr << std::endl; + + /* grab the first PhotoItem - and get it size */ + const QObjectList &items = children(); + QObjectList::const_iterator qit; + + int count = 0; + for(qit = items.begin(); qit != items.end(); qit++) + { + PhotoItem *item = dynamic_cast(*qit); + if (item) + { + std::cerr << "PhotoDrop::getPhotoIdx() item: " << item; + std::cerr << std::endl; + if (count == idx) + { + return item; + } + + count++; + } + else + { + std::cerr << "PhotoDrop::getPhotoIdx() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + return NULL; +} + + + +void PhotoDrop::reorderPhotos() +{ + std::cerr << "PhotoDrop::reorderPhotos()"; + std::cerr << std::endl; + + /* now move the qwidgets around */ + QLayout *alayout = layout(); + QGridLayout *glayout = dynamic_cast(alayout); + if (!glayout) + { + std::cerr << "PhotoDrop::reorderPhotos() not GridLayout... not much we can do!"; + std::cerr << std::endl; + return; + } + + /* grab the first PhotoItem - and get it size */ + std::map photoItems; + std::map::iterator pit; + + int count = glayout->count(); + int i = 0; + for(i = 0; i < count; i++) + { + QLayoutItem *litem = glayout->itemAt(i); + if (!litem) + { + std::cerr << "PhotoDrop::reorderPhotos() missing litem"; + std::cerr << std::endl; + continue; + } + + PhotoItem *item = dynamic_cast(litem->widget()); + if (item) + { + + int selectedRow; + int selectedColumn; + int rowSpan; + int colSpan; + glayout->getItemPosition(i, &selectedRow, &selectedColumn, &rowSpan, &colSpan); + + std::cerr << "PhotoDrop::reorderPhotos() item: " << item; + std::cerr << " layoutIdx: " << i; + std::cerr << " item pos(" << selectedRow << ", " << selectedColumn; + std::cerr << ")" << std::endl; + + gridIndex idx(selectedRow, selectedColumn); + photoItems[idx] = item; + + } + else + { + std::cerr << "PhotoDrop::reorderPhotos() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + pit = photoItems.begin(); + if (pit == photoItems.end()) + { + std::cerr << "PhotoDrop::reorderPhotos() No PhotoItems."; + std::cerr << std::endl; + + mColumns = 1; + + // no PhotoItems here. + return; + } + + int minWidth = (pit->second)->minimumWidth(); + +#define EXPECTED_WIDTH (200) + if (minWidth < EXPECTED_WIDTH) + { + minWidth = EXPECTED_WIDTH; + } + int space = width(); + mColumns = space / minWidth; + + std::cerr << "PhotoDrop::reorderPhotos() minWidth: " << minWidth << " space: " << space; + std::cerr << " columns: " << mColumns; + std::cerr << std::endl; + + std::cerr << "PhotoDrop::reorderPhotos() Getting ordered Items from Layout"; + std::cerr << std::endl; + + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + glayout->removeWidget(pit->second); + } + + for(pit = photoItems.begin(), i = 0; pit != photoItems.end(); pit++, i++) + { + int row = i / mColumns; + int column = i % mColumns; + + std::cerr << "Inserting item: " << pit->second << " at (" << row << "," << column << ")"; + std::cerr << std::endl; + glayout->addWidget(pit->second, row, column, Qt::AlignCenter); + } +} + + +void PhotoDrop::moveLeft() +{ + std::cerr << "PhotoDrop::moveLeft()"; + std::cerr << std::endl; + + QLayout *alayout = layout(); + if (!alayout) + { + std::cerr << "PhotoDrop::moveLeft() No Layout"; + std::cerr << std::endl; + return; + } + + QGridLayout *glayout = dynamic_cast(alayout); + if (!glayout) + { + std::cerr << "PhotoDrop::moveLeft() not GridLayout... not much we can do!"; + std::cerr << std::endl; + return; + } + + int count = alayout->count(); + if ((!mSelected) || (count < 2)) + { + std::cerr << "PhotoDrop::moveLeft() Not enough items"; + std::cerr << std::endl; + return; + } + + int index = alayout->indexOf(mSelected); + int selectedRow; + int selectedColumn; + int rowSpan; + int colSpan; + glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan); + + if ((selectedRow == 0) && (selectedColumn == 0)) + { + std::cerr << "PhotoDrop::moveLeft() Selected is first item"; + std::cerr << std::endl; + return; + } + + int swapRow = selectedRow; + int swapColumn = selectedColumn - 1; + + if (swapColumn < 0) + { + swapRow--; + swapColumn = mColumns - 1; + } + + std::cerr << "PhotoDrop::moveLeft() Trying to swap (" << selectedRow << ","; + std::cerr << selectedColumn << ") <-> (" << swapRow; + std::cerr << "," << swapColumn << ")"; + std::cerr << std::endl; + + QLayoutItem *litem = glayout->itemAtPosition(swapRow, swapColumn); + if (!litem) + { + std::cerr << "PhotoDrop::moveLeft() No layout item to the right"; + std::cerr << std::endl; + return; + } + + QWidget *widget = litem->widget(); + if (!widget) + { + std::cerr << "PhotoDrop::moveLeft() No item to the left"; + std::cerr << std::endl; + return; + } + + /* grab both items, and switch */ + std::cerr << "PhotoDrop::moveLeft() could move index: " << index; + std::cerr << std::endl; + + glayout->removeWidget(widget); + glayout->removeWidget(mSelected); + + glayout->addWidget(widget, selectedRow, selectedColumn, Qt::AlignCenter); + glayout->addWidget(mSelected, swapRow, swapColumn, Qt::AlignCenter); + + checkMoveButtons(); +} + + +void PhotoDrop::moveRight() +{ + std::cerr << "PhotoDrop::moveRight()"; + std::cerr << std::endl; + + QLayout *alayout = layout(); + if (!alayout) + { + std::cerr << "PhotoDrop::moveRight() No Layout"; + std::cerr << std::endl; + return; + } + + QGridLayout *glayout = dynamic_cast(alayout); + if (!glayout) + { + std::cerr << "PhotoDrop::moveRight() not GridLayout... not much we can do!"; + std::cerr << std::endl; + return; + } + + int count = alayout->count(); + if ((!mSelected) || (count < 2)) + { + std::cerr << "PhotoDrop::moveRight() Not enough items"; + std::cerr << std::endl; + return; + } + + int index = alayout->indexOf(mSelected); + int selectedRow; + int selectedColumn; + int rowSpan; + int colSpan; + glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan); + + int maxRow = (count - 1) / mColumns; + int maxCol = (count - 1) % mColumns; + if ((selectedRow == maxRow) && (selectedColumn == maxCol)) + { + std::cerr << "PhotoDrop::moveRight() Selected is last item"; + std::cerr << std::endl; + return; + } + + int swapRow = selectedRow; + int swapColumn = selectedColumn + 1; + + if (swapColumn == mColumns) + { + swapRow++; + swapColumn = 0; + } + + std::cerr << "PhotoDrop::moveRight() Trying to swap (" << selectedRow << ","; + std::cerr << selectedColumn << ") <-> (" << swapRow; + std::cerr << "," << swapColumn << ")"; + std::cerr << std::endl; + + QLayoutItem *litem = glayout->itemAtPosition(swapRow, swapColumn); + if (!litem) + { + std::cerr << "PhotoDrop::moveRight() No layout item to the right"; + std::cerr << std::endl; + return; + } + + QWidget *widget = litem->widget(); + + if (!widget) + { + std::cerr << "PhotoDrop::moveRight() No item to the right"; + std::cerr << std::endl; + return; + } + + /* grab both items, and switch */ + std::cerr << "PhotoDrop::moveRight() could move index: " << index; + std::cerr << std::endl; + + glayout->removeWidget(widget); + glayout->removeWidget(mSelected); + + glayout->addWidget(widget, selectedRow, selectedColumn, Qt::AlignCenter); + glayout->addWidget(mSelected, swapRow, swapColumn, Qt::AlignCenter); + + checkMoveButtons(); +} + + +void PhotoDrop::checkMoveButtons() +{ + std::cerr << "PhotoDrop::checkMoveButtons()"; + std::cerr << std::endl; + /* locate mSelected in the set */ + QLayout *alayout = layout(); + if (!alayout) + { + std::cerr << "PhotoDrop::checkMoveButtons() No Layout"; + std::cerr << std::endl; + return; + } + + int count = alayout->count(); + if ((!mSelected) || (count < 2)) + { + buttonStatus(PHOTO_SHIFT_NO_BUTTONS); + return; + } + + QGridLayout *glayout = dynamic_cast(alayout); + if (!glayout) + { + std::cerr << "PhotoDrop::checkMoveButtons() not GridLayout... not much we can do!"; + std::cerr << std::endl; + buttonStatus(PHOTO_SHIFT_NO_BUTTONS); + return; + } + + int index = alayout->indexOf(mSelected); + int selectedRow; + int selectedColumn; + int rowSpan; + int colSpan; + glayout->getItemPosition(index, &selectedRow, &selectedColumn, &rowSpan, &colSpan); + + int maxRow = (count - 1) / mColumns; + int maxCol = (count - 1) % mColumns; + if ((selectedRow == 0) && (selectedColumn == 0)) + { + buttonStatus(PHOTO_SHIFT_RIGHT_ONLY); + } + else if ((selectedRow == maxRow) && (selectedColumn == maxCol)) + { + buttonStatus(PHOTO_SHIFT_LEFT_ONLY); + } + else + { + buttonStatus(PHOTO_SHIFT_BOTH); + } +} + + +void PhotoDrop::clearPhotos() +{ + std::cerr << "PhotoDrop::clearPhotos()"; + std::cerr << std::endl; + + /* grab the first PhotoItem - and get it size */ + const QObjectList &items = children(); + QObjectList::const_iterator qit; + std::list photoItems; + std::list::iterator pit; + + for(qit = items.begin(); qit != items.end(); qit++) + { + PhotoItem *item = dynamic_cast(*qit); + if (item) + { + photoItems.push_back(item); + std::cerr << "PhotoDrop::clearPhotos() item: " << item; + std::cerr << std::endl; + } + else + { + std::cerr << "PhotoDrop::clearPhotos() Found Child, which is not a PhotoItem???"; + std::cerr << std::endl; + } + } + + QLayout *alayout = layout(); + QGridLayout *glayout = dynamic_cast(alayout); + if (!glayout) + { + std::cerr << "PhotoDrop::clearPhotos() not GridLayout... not much we can do!"; + std::cerr << std::endl; + return; + } + + for(pit = photoItems.begin(); pit != photoItems.end(); pit++) + { + PhotoItem *item = *pit; + glayout->removeWidget(item); + delete item; + } + + mSelected = NULL; +} + + + + +void PhotoDrop::dragEnterEvent(QDragEnterEvent *event) +{ + // Only Accept DragEntetEvents from the Disk / URLs. + // TODO: check that the data is suitable - and a photo + + std::cerr << "PhotoDrop::dragEnterEvent()"; + std::cerr << std::endl; + + //if (event->mimeData()->hasFormat("image/x-photo-item")) + if (event->mimeData()->hasUrls()) + { + event->accept(); + } + else + { + event->ignore(); + } +} + +void PhotoDrop::dragLeaveEvent(QDragLeaveEvent *event) +{ + // We can drag an existing Image to the "Album Spot" (or elsewhere). + // But we cannot drag anything else out. + + std::cerr << "PhotoDrop::dragLeaveEvent()"; + std::cerr << std::endl; + + event->ignore(); +} + +void PhotoDrop::dragMoveEvent(QDragMoveEvent *event) +{ + + std::cerr << "PhotoDrop::dragMoveEvent()"; + std::cerr << std::endl; + + //event->accept(); + event->ignore(); +} + +void PhotoDrop::dropEvent(QDropEvent *event) +{ + std::cerr << "PhotoDrop::dropEvent()"; + std::cerr << std::endl; + + + if (event->mimeData()->hasUrls()) + { + std::cerr << "PhotoDrop::dropEvent() Urls:" << std::endl; + + QList urls = event->mimeData()->urls(); + QList::iterator uit; + for (uit = urls.begin(); uit != urls.end(); ++uit) + { + QString localpath = uit->toLocalFile(); + std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl; + std::cerr << "or As Local File: " << localpath.toStdString() << std::endl; + + PhotoItem *item = new PhotoItem(this, localpath.toStdString()); + + //mPhotos.push_back(item); + layout()->addWidget(item); + } + event->setDropAction(Qt::CopyAction); + event->accept(); + } + else + { + event->ignore(); + } + + checkMoveButtons(); +} + +void PhotoDrop::mousePressEvent(QMouseEvent *event) +{ + /* see if this is in the space of one of our children */ + QPoint pos = event->pos(); + + std::cerr << "PhotoDrop::mousePressEvent(" << pos.x() << ", " << pos.y() << ")"; + std::cerr << std::endl; + + QWidget::mousePressEvent(event); +} + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoDrop.h b/retroshare-gui/src/gui/PhotoShare/PhotoDrop.h new file mode 100644 index 000000000..55f07ac60 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoDrop.h @@ -0,0 +1,87 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_PHOTO_DROP_H +#define MRK_PHOTO_DROP_H + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QDragEnterEvent; +class QDropEvent; +class QMouseEvent; +QT_END_NAMESPACE + +#include "gui/PhotoShare/PhotoItem.h" + +#define PHOTO_SHIFT_NO_BUTTONS 0 +#define PHOTO_SHIFT_LEFT_ONLY 1 +#define PHOTO_SHIFT_RIGHT_ONLY 2 +#define PHOTO_SHIFT_BOTH 3 + + +class PhotoDrop : public QWidget, public PhotoHolder +{ + Q_OBJECT + +public: + PhotoDrop(QWidget *parent = 0); + void clear(); + +virtual void deletePhotoItem(PhotoItem *, uint32_t type); +virtual void notifySelection(PhotoItem *item, int ptype); + +PhotoItem *getSelectedPhotoItem(); +int getPhotoCount(); +PhotoItem *getPhotoIdx(int idx); + +public slots: + void moveLeft(); + void moveRight(); + void checkMoveButtons(); + void clearPhotos(); + +signals: + void buttonStatus(uint32_t status); + +protected: + + void resizeEvent(QResizeEvent *event); + void mousePressEvent(QMouseEvent *event); + + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + +private: + void reorderPhotos(); + + PhotoItem *mSelected; + int mColumns; +}; + +#endif diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoItem.cpp b/retroshare-gui/src/gui/PhotoShare/PhotoItem.cpp new file mode 100644 index 000000000..7d0e41920 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoItem.cpp @@ -0,0 +1,239 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + +#include +#include +#include +#include + +#include "PhotoItem.h" + +#include + +#include +#include + +/**** + * #define DEBUG_ITEM 1 + ****/ + +/** Constructor */ +PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail) +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_ALBUM) +{ + setupUi(this); + + setAttribute ( Qt::WA_DeleteOnClose, true ); + + mDetails = *( (RsPhotoPhoto *) &(album)); + updateAlbumText(album); + updateImage(thumbnail); + + setSelected(false); +} + + +PhotoItem::PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail) +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_PHOTO) +{ + setupUi(this); + + setAttribute ( Qt::WA_DeleteOnClose, true ); + + mDetails = *( (RsPhotoPhoto *) &(photo)); + + updatePhotoText(photo); + updateImage(thumbnail); + + setSelected(false); +} + + +PhotoItem::PhotoItem(PhotoHolder *parent, std::string path) // for new photos. +:QWidget(NULL), mParent(parent), mType(PHOTO_ITEM_TYPE_NEW) +{ + setupUi(this); + + setAttribute ( Qt::WA_DeleteOnClose, true ); + + QString dummyString("dummytext"); + titleLabel->setText(QString("NEW PHOTO")); + + fromBoldLabel->setText(QString("From:")); + fromLabel->setText(QString("Ourselves")); + + statusBoldLabel->setText(QString("Status:")); + statusLabel->setText(QString("new photo")); + + dateBoldLabel->setText(QString("Date:")); + dateLabel->setText(QString("now")); + + int width = 120; + int height = 120; + + //QPixmap qtn = QPixmap(QString::fromStdString(path)).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QPixmap qtn = QPixmap(QString::fromStdString(path)).scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation); + imgLabel->setPixmap(qtn); + setSelected(false); +} + +void PhotoItem::updateAlbumText(const RsPhotoAlbum &album) +{ + QString dummyString("dummytext"); + titleLabel->setText(QString("TITLE")); + + fromBoldLabel->setText(QString("From:")); + fromLabel->setText(QString("Unknown")); + + statusBoldLabel->setText(QString("Status:")); + statusLabel->setText(QString("new photo")); + + dateBoldLabel->setText(QString("Date:")); + dateLabel->setText(QString("now")); + + //QDateTime qtime; + //qtime.setTime_t(msg.ts); + //QString timestamp = qtime.toString("dd.MMMM yyyy hh:mm"); + //timestamplabel->setText(timestamp); + + dateBoldLabel->setText(dummyString); + dateLabel->setText(dummyString); + +} + +void PhotoItem::updatePhotoText(const RsPhotoPhoto &photo) +{ + QString dummyString("dummytext"); + titleLabel->setText(QString("TITLE")); + + fromBoldLabel->setText(QString("From:")); + fromLabel->setText(QString("Unknown")); + + statusBoldLabel->setText(QString("Status:")); + statusLabel->setText(QString("new photo")); + + dateBoldLabel->setText(QString("Date:")); + dateLabel->setText(QString("now")); +} + + +void PhotoItem::updateImage(const RsPhotoThumbnail &thumbnail) +{ + if (thumbnail.data != NULL) + { + QPixmap qtn; + qtn.loadFromData(thumbnail.data, thumbnail.size, thumbnail.type.c_str()); + imgLabel->setPixmap(qtn); + } +} + +bool PhotoItem::getPhotoThumbnail(RsPhotoThumbnail &nail) +{ + const QPixmap *tmppix = imgLabel->pixmap(); + + QByteArray ba; + QBuffer buffer(&ba); + + if(!tmppix->isNull()) + { + // send chan image + + buffer.open(QIODevice::WriteOnly); + tmppix->save(&buffer, "PNG"); // writes image into ba in PNG format + + RsPhotoThumbnail tmpnail; + tmpnail.data = (uint8_t *) ba.data(); + tmpnail.size = ba.size(); + + nail.copyFrom(tmpnail); + + return true; + } + + nail.data = NULL; + nail.size = 0; + return false; +} + + +void PhotoItem::removeItem() +{ +#ifdef DEBUG_ITEM + std::cerr << "PhotoItem::removeItem()"; + std::cerr << std::endl; +#endif + hide(); + if (mParent) + { + mParent->deletePhotoItem(this, mType); + } +} + + +void PhotoItem::setSelected(bool on) +{ + mSelected = on; + if (mSelected) + { + mParent->notifySelection(this, mType); + frame->setStyleSheet("QFrame#frame{border: 2px solid #55CC55;\nbackground: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #55EE55, stop: 1 #CCCCCC);\nborder-radius: 10px}"); + } + else + { + frame->setStyleSheet("QFrame#frame{border: 2px solid #CCCCCC;\nbackground: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #EEEEEE, stop: 1 #CCCCCC);\nborder-radius: 10px}"); + } + update(); +} + +bool PhotoItem::isSelected() +{ + return mSelected; +} + + +void PhotoItem::mousePressEvent(QMouseEvent *event) +{ + /* We can be very cunning here? + * grab out position. + * flag ourselves as selected. + * then pass the mousePressEvent up for handling by the parent + */ + + QPoint pos = event->pos(); + + std::cerr << "PhotoItem::mousePressEvent(" << pos.x() << ", " << pos.y() << ")"; + std::cerr << std::endl; + + setSelected(true); + + QWidget::mousePressEvent(event); +} + + +const QPixmap *PhotoItem::getPixmap() +{ + return imgLabel->pixmap(); +} + + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoItem.h b/retroshare-gui/src/gui/PhotoShare/PhotoItem.h new file mode 100644 index 000000000..0f71233cd --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoItem.h @@ -0,0 +1,86 @@ +/* + * Retroshare Photo Plugin. + * + * Copyright 2012-2012 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2.1 as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + +#ifndef MRK_PHOTO_PHOTO_ITEM_H +#define MRK_PHOTO_PHOTO_ITEM_H + +#include "ui_PhotoItem.h" + +#include + +class PhotoItem; + +class PhotoHolder +{ + public: +virtual void deletePhotoItem(PhotoItem *, uint32_t ptype) = 0; +virtual void notifySelection(PhotoItem *item, int ptype) = 0; +}; + + +#define PHOTO_ITEM_TYPE_ALBUM 0x0001 +#define PHOTO_ITEM_TYPE_PHOTO 0x0002 +#define PHOTO_ITEM_TYPE_NEW 0x0003 + +class PhotoItem : public QWidget, private Ui::PhotoItem +{ + Q_OBJECT + +public: + PhotoItem(PhotoHolder *parent, const RsPhotoAlbum &album, const RsPhotoThumbnail &thumbnail); + PhotoItem(PhotoHolder *parent, const RsPhotoPhoto &photo, const RsPhotoThumbnail &thumbnail); + PhotoItem(PhotoHolder *parent, std::string url); // for new photos. + + bool getPhotoThumbnail(RsPhotoThumbnail &nail); + + void removeItem(); + + void setSelected(bool on); + bool isSelected(); + + const QPixmap *getPixmap(); + + // details are public - so that can be easily edited. + RsPhotoPhoto mDetails; + +//private slots: + + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + void updateAlbumText(const RsPhotoAlbum &album); + void updatePhotoText(const RsPhotoPhoto &photo); + void updateImage(const RsPhotoThumbnail &thumbnail); + + PhotoHolder *mParent; + uint32_t mType; + + + bool mSelected; +}; + + +#endif + diff --git a/retroshare-gui/src/gui/PhotoShare/PhotoItem.ui b/retroshare-gui/src/gui/PhotoShare/PhotoItem.ui new file mode 100644 index 000000000..8b7e990d9 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/PhotoItem.ui @@ -0,0 +1,247 @@ + + + PhotoItem + + + + 0 + 0 + 166 + 216 + + + + + 9 + + + + + + + + 6 + + + + + + 0 + 0 + + + + QFrame#frame{border: 2px solid #CCCCCC; +background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 #EEEEEE, stop: 1 #CCCCCC); +border-radius: 10px} + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + + + + 150 + 150 + + + + + 150 + 150 + + + + QLabel#label{border: 2px solid black; +background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, + stop: 0 #EEEEEE, stop: 1 #CCCCCC); +border-radius: 10px} + + + + + + :/images/konversation.png + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + Album: + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + From + + + + + + + + 0 + 0 + + + + + 9 + + + + Signed by + + + true + + + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + Status + + + + + + + + 0 + 0 + + + + + 9 + + + + You eyes only + + + true + + + + + + + + + + + + 0 + 0 + + + + + 9 + 75 + true + + + + Date + + + + + + + + 0 + 0 + + + + + 9 + + + + You eyes only + + + true + + + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/PhotoShare/Photo_images.qrc b/retroshare-gui/src/gui/PhotoShare/Photo_images.qrc new file mode 100644 index 000000000..3ab091103 --- /dev/null +++ b/retroshare-gui/src/gui/PhotoShare/Photo_images.qrc @@ -0,0 +1,5 @@ + + + images/dummy.png + +