mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-23 13:51:12 -05:00
Add image handling to PulseAddDialog and PulseMessage
This commit is contained in:
parent
3312faf3ea
commit
fbf56fcf03
@ -19,6 +19,7 @@
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
#include <QtGui>
|
||||
|
||||
#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_Cancel, SIGNAL( clicked( void ) ), this, SLOT( cancelPulse( void ) ) );
|
||||
connect(ui.textEdit_Pulse, SIGNAL( textChanged( void ) ), this, SLOT( pulseTextChanged( void ) ) );
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void PulseAddDialog::setGroup(RsWireGroup &group)
|
||||
@ -84,7 +87,7 @@ void PulseAddDialog::cleanup()
|
||||
}
|
||||
// then finally
|
||||
delete layout;
|
||||
mIsReply = false;
|
||||
mIsReply = false;
|
||||
}
|
||||
ui.frame_reply->setVisible(false);
|
||||
ui.comboBox_sentiment->setCurrentIndex(0);
|
||||
@ -98,6 +101,23 @@ void PulseAddDialog::cleanup()
|
||||
ui.pushButton_Post->setText("Post Pulse to Wire");
|
||||
ui.frame_input->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()
|
||||
@ -221,6 +241,10 @@ void PulseAddDialog::postOriginalPulse()
|
||||
pPulse->mSentiment = WIRE_PULSE_SENTIMENT_NO_SENTIMENT;
|
||||
pPulse->mPulseText = ui.textEdit_Pulse->toPlainText().toStdString();
|
||||
// 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.
|
||||
if (!rsWire->createOriginalPulse(mGroup.mMeta.mGroupId, pPulse))
|
||||
@ -265,7 +289,11 @@ void PulseAddDialog::postReplyPulse()
|
||||
|
||||
pPulse->mSentiment = toPulseSentiment(ui.comboBox_sentiment->currentIndex());
|
||||
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.
|
||||
if (!rsWire->createReplyPulse(mReplyToPulse.mMeta.mGroupId,
|
||||
@ -288,5 +316,131 @@ void PulseAddDialog::clearDialog()
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,14 @@
|
||||
|
||||
#include <retroshare/rswire.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
class QMouseEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
class PulseAddDialog : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -56,6 +64,12 @@ private:
|
||||
uint32_t toPulseSentiment(int index);
|
||||
|
||||
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.
|
||||
|
||||
@ -64,6 +78,12 @@ protected:
|
||||
RsWirePulse mReplyToPulse;
|
||||
uint32_t mReplyType;
|
||||
|
||||
// images
|
||||
RsGxsImage mImage1;
|
||||
RsGxsImage mImage2;
|
||||
RsGxsImage mImage3;
|
||||
RsGxsImage mImage4;
|
||||
|
||||
Ui::PulseAddDialog ui;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>720</width>
|
||||
<height>586</height>
|
||||
<height>633</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -161,6 +161,88 @@
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit_Pulse"/>
|
||||
</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>
|
||||
<widget class="QFrame" name="frame_URL">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
|
@ -37,30 +37,66 @@ void PulseMessage::setup(RsWirePulseSPtr pulse)
|
||||
setMessage(QString::fromStdString(pulse->mPulseText));
|
||||
|
||||
// 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()) {
|
||||
// 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 {
|
||||
// leave this visible for a bit.
|
||||
// label_image1->setVisible(false);
|
||||
label_image1->setVisible(false);
|
||||
}
|
||||
|
||||
if (!pulse->mImage2.empty()) {
|
||||
// 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 {
|
||||
label_image2->setVisible(false);
|
||||
}
|
||||
|
||||
width = 256;
|
||||
if (pulse->mImage4.empty()) {
|
||||
// allow wider space for image 3.
|
||||
width = 512;
|
||||
}
|
||||
|
||||
if (!pulse->mImage3.empty()) {
|
||||
// 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 {
|
||||
label_image3->setVisible(false);
|
||||
}
|
||||
|
||||
if (!pulse->mImage4.empty()) {
|
||||
// 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 {
|
||||
label_image4->setVisible(false);
|
||||
}
|
||||
|
||||
frame_expand->setVisible(imagesShown);
|
||||
}
|
||||
|
||||
void PulseMessage::setMessage(QString msg)
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>553</width>
|
||||
<height>281</height>
|
||||
<width>570</width>
|
||||
<height>376</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -30,52 +30,64 @@
|
||||
<widget class="QLabel" name="label_image1">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>80</height>
|
||||
<width>128</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>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>
|
||||
<width>128</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>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>
|
||||
<width>128</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>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>
|
||||
<width>128</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Image</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user