Add image handling to PulseAddDialog and PulseMessage

This commit is contained in:
drbob 2020-05-18 17:35:08 +10:00
parent 3312faf3ea
commit fbf56fcf03
5 changed files with 319 additions and 15 deletions

View File

@ -19,6 +19,7 @@
*******************************************************************************/ *******************************************************************************/
#include <iostream> #include <iostream>
#include <QtGui>
#include "PulseDetails.h" #include "PulseDetails.h"
@ -37,6 +38,8 @@ PulseAddDialog::PulseAddDialog(QWidget *parent)
connect(ui.pushButton_ClearDisplayAs, SIGNAL( clicked( void ) ), this, SLOT( clearDisplayAs( void ) ) ); connect(ui.pushButton_ClearDisplayAs, SIGNAL( clicked( void ) ), this, SLOT( clearDisplayAs( void ) ) );
connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelPulse( void ) ) ); connect(ui.pushButton_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelPulse( void ) ) );
connect(ui.textEdit_Pulse, SIGNAL( textChanged( void ) ), this, SLOT( pulseTextChanged( void ) ) ); connect(ui.textEdit_Pulse, SIGNAL( textChanged( void ) ), this, SLOT( pulseTextChanged( void ) ) );
setAcceptDrops(true);
} }
void PulseAddDialog::setGroup(RsWireGroup &group) void PulseAddDialog::setGroup(RsWireGroup &group)
@ -84,7 +87,7 @@ void PulseAddDialog::cleanup()
} }
// then finally // then finally
delete layout; delete layout;
mIsReply = false; mIsReply = false;
} }
ui.frame_reply->setVisible(false); ui.frame_reply->setVisible(false);
ui.comboBox_sentiment->setCurrentIndex(0); ui.comboBox_sentiment->setCurrentIndex(0);
@ -98,6 +101,23 @@ void PulseAddDialog::cleanup()
ui.pushButton_Post->setText("Post Pulse to Wire"); ui.pushButton_Post->setText("Post Pulse to Wire");
ui.frame_input->setVisible(true); ui.frame_input->setVisible(true);
ui.widget_sentiment->setVisible(true); ui.widget_sentiment->setVisible(true);
// cleanup images.
mImage1.clear();
ui.label_image1->clear();
ui.label_image1->setText("Drag and Drop Image");
mImage2.clear();
ui.label_image2->clear();
ui.label_image2->setText("Drag and Drop Image");
mImage3.clear();
ui.label_image3->clear();
ui.label_image3->setText("Drag and Drop Image");
mImage4.clear();
ui.label_image4->clear();
ui.label_image4->setText("Drag and Drop Image");
} }
void PulseAddDialog::pulseTextChanged() void PulseAddDialog::pulseTextChanged()
@ -221,6 +241,10 @@ void PulseAddDialog::postOriginalPulse()
pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT; pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString(); pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
// set images here too. // set images here too.
pPulse->mImage1 = mImage1;
pPulse->mImage2 = mImage2;
pPulse->mImage3 = mImage3;
pPulse->mImage4 = mImage4;
// this should be in async thread, so doesn't block UI thread. // this should be in async thread, so doesn't block UI thread.
if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse)) if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
@ -265,7 +289,11 @@ void PulseAddDialog::postReplyPulse()
pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex()); pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString(); pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
// set images too. // set images here too.
pPulse->mImage1 = mImage1;
pPulse->mImage2 = mImage2;
pPulse->mImage3 = mImage3;
pPulse->mImage4 = mImage4;
// this should be in async thread, so doesn't block UI thread. // this should be in async thread, so doesn't block UI thread.
if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId, if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
@ -288,5 +316,131 @@ void PulseAddDialog::clearDialog()
ui.textEdit_Pulse->setPlainText(""); ui.textEdit_Pulse->setPlainText("");
} }
//---------------------------------------------------------------------
// Drag and Drop Images.
void PulseAddDialog::dragEnterEvent(QDragEnterEvent *event)
{
std::cerr << "PulseAddDialog::dragEnterEvent()";
std::cerr << std::endl;
if (event->mimeData()->hasUrls())
{
std::cerr << "PulseAddDialog::dragEnterEvent() Accepting";
std::cerr << std::endl;
event->accept();
}
else
{
std::cerr << "PulseAddDialog::dragEnterEvent() Ignoring";
std::cerr << std::endl;
event->ignore();
}
}
void PulseAddDialog::dragLeaveEvent(QDragLeaveEvent *event)
{
std::cerr << "PulseAddDialog::dragLeaveEvent()";
std::cerr << std::endl;
event->ignore();
}
void PulseAddDialog::dragMoveEvent(QDragMoveEvent *event)
{
std::cerr << "PulseAddDialog::dragMoveEvent()";
std::cerr << std::endl;
event->accept();
}
void PulseAddDialog::dropEvent(QDropEvent *event)
{
std::cerr << "PulseAddDialog::dropEvent()";
std::cerr << std::endl;
if (event->mimeData()->hasUrls())
{
std::cerr << "PulseAddDialog::dropEvent() Urls:" << std::endl;
QList<QUrl> urls = event->mimeData()->urls();
QList<QUrl>::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;
addImage(localpath);
}
event->setDropAction(Qt::CopyAction);
event->accept();
}
else
{
std::cerr << "PulseAddDialog::dropEvent Ignoring";
std::cerr << std::endl;
event->ignore();
}
}
void PulseAddDialog::addImage(const QString &path)
{
std::cerr << "PulseAddDialog::addImage() loading image from: " << path.toStdString();
std::cerr << std::endl;
QPixmap qtn = QPixmap(path);
if (qtn.isNull()) {
std::cerr << "PulseAddDialog::addImage() Invalid Image";
std::cerr << std::endl;
return;
}
QPixmap image;
if ((qtn.width() <= 512) && (qtn.height() <= 512)) {
image = qtn;
} else {
image = qtn.scaled(512, 512, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
// scaled down for display, allow wide images.
QPixmap icon = qtn.scaled(256, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPG");
if (mImage1.empty()) {
std::cerr << "PulseAddDialog::addImage() Installing in Image1";
std::cerr << std::endl;
ui.label_image1->setPixmap(icon);
mImage1.copy((uint8_t *) ba.data(), ba.size());
std::cerr << "PulseAddDialog::addImage() Installing in Image1 Size: " << mImage1.mSize;
std::cerr << std::endl;
}
else if (mImage2.empty()) {
ui.label_image2->setPixmap(icon);
mImage2.copy((uint8_t *) ba.data(), ba.size());
std::cerr << "PulseAddDialog::addImage() Installing in Image2 Size: " << mImage2.mSize;
std::cerr << std::endl;
}
else if (mImage3.empty()) {
ui.label_image3->setPixmap(icon);
mImage3.copy((uint8_t *) ba.data(), ba.size());
std::cerr << "PulseAddDialog::addImage() Installing in Image3 Size: " << mImage3.mSize;
std::cerr << std::endl;
}
else if (mImage4.empty()) {
ui.label_image4->setPixmap(icon);
mImage4.copy((uint8_t *) ba.data(), ba.size());
std::cerr << "PulseAddDialog::addImage() Installing in Image4 Size: " << mImage4.mSize;
std::cerr << std::endl;
}
else {
std::cerr << "PulseAddDialog::addImage() Images all full";
std::cerr << std::endl;
}
}

View File

@ -25,6 +25,14 @@
#include <retroshare/rswire.h> #include <retroshare/rswire.h>
QT_BEGIN_NAMESPACE
class QDragEnterEvent;
class QDropEvent;
class QMouseEvent;
QT_END_NAMESPACE
class PulseAddDialog : public QWidget class PulseAddDialog : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -56,6 +64,12 @@ private:
uint32_t toPulseSentiment(int index); uint32_t toPulseSentiment(int index);
protected: protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void addImage(const QString &path);
RsWireGroup mGroup; // replyWith. RsWireGroup mGroup; // replyWith.
@ -64,6 +78,12 @@ protected:
RsWirePulse mReplyToPulse; RsWirePulse mReplyToPulse;
uint32_t mReplyType; uint32_t mReplyType;
// images
RsGxsImage mImage1;
RsGxsImage mImage2;
RsGxsImage mImage3;
RsGxsImage mImage4;
Ui::PulseAddDialog ui; Ui::PulseAddDialog ui;
}; };

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>720</width> <width>720</width>
<height>586</height> <height>633</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -161,6 +161,88 @@
<item> <item>
<widget class="QTextEdit" name="textEdit_Pulse"/> <widget class="QTextEdit" name="textEdit_Pulse"/>
</item> </item>
<item>
<widget class="QFrame" name="frame_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_image1">
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
</size>
</property>
<property name="text">
<string>Drag and Drop Image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_image2">
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
</size>
</property>
<property name="text">
<string>Drag and Drop Image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_image3">
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
</size>
</property>
<property name="text">
<string>Drag and Drop Image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_image4">
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
</size>
</property>
<property name="text">
<string>Drag and Drop Image</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QFrame" name="frame_URL"> <widget class="QFrame" name="frame_URL">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">

View File

@ -37,30 +37,66 @@ void PulseMessage::setup(RsWirePulseSPtr pulse)
setMessage(QString::fromStdString(pulse->mPulseText)); setMessage(QString::fromStdString(pulse->mPulseText));
// setup images. // setup images.
int width = 256;
int height = 128;
bool imagesShown = false;
if (pulse->mImage2.empty()) {
// allow wider space for image 1.
width = 512;
}
if (!pulse->mImage1.empty()) { if (!pulse->mImage1.empty()) {
// install image. // install image.
QPixmap qtn;
qtn.loadFromData(pulse->mImage1.mData, pulse->mImage1.mSize);
label_image1->setPixmap(qtn.scaled(width, height,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
imagesShown = true;
} else { } else {
// leave this visible for a bit. label_image1->setVisible(false);
// label_image1->setVisible(false);
} }
if (!pulse->mImage2.empty()) { if (!pulse->mImage2.empty()) {
// install image. // install image.
QPixmap qtn;
qtn.loadFromData(pulse->mImage2.mData, pulse->mImage2.mSize);
label_image2->setPixmap(qtn.scaled(width, height,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
imagesShown = true;
} else { } else {
label_image2->setVisible(false); label_image2->setVisible(false);
} }
width = 256;
if (pulse->mImage4.empty()) {
// allow wider space for image 3.
width = 512;
}
if (!pulse->mImage3.empty()) { if (!pulse->mImage3.empty()) {
// install image. // install image.
QPixmap qtn;
qtn.loadFromData(pulse->mImage3.mData, pulse->mImage3.mSize);
label_image3->setPixmap(qtn.scaled(width, height,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
imagesShown = true;
} else { } else {
label_image3->setVisible(false); label_image3->setVisible(false);
} }
if (!pulse->mImage4.empty()) { if (!pulse->mImage4.empty()) {
// install image. // install image.
QPixmap qtn;
qtn.loadFromData(pulse->mImage4.mData, pulse->mImage4.mSize);
label_image4->setPixmap(qtn.scaled(width, height,
Qt::KeepAspectRatio, Qt::SmoothTransformation));
imagesShown = true;
} else { } else {
label_image4->setVisible(false); label_image4->setVisible(false);
} }
frame_expand->setVisible(imagesShown);
} }
void PulseMessage::setMessage(QString msg) void PulseMessage::setMessage(QString msg)

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>553</width> <width>570</width>
<height>281</height> <height>376</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -30,52 +30,64 @@
<widget class="QLabel" name="label_image1"> <widget class="QLabel" name="label_image1">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>128</width>
<height>80</height> <height>128</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Image</string> <string>Image</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="label_image2"> <widget class="QLabel" name="label_image2">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>128</width>
<height>80</height> <height>128</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Image</string> <string>Image</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_image3"> <widget class="QLabel" name="label_image3">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>128</width>
<height>80</height> <height>128</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Image</string> <string>Image</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_image4"> <widget class="QLabel" name="label_image4">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>80</width> <width>128</width>
<height>80</height> <height>128</height>
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Image</string> <string>Image</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>