mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-14 08:59:50 -05:00
Added to show the message length on Composer and Message Widget
This commit is contained in:
parent
cf05c86691
commit
39a89dd2a9
@ -22,6 +22,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QClipboard>
|
||||
#include <QLabel>
|
||||
#include <QTextCodec>
|
||||
#include <QPrintDialog>
|
||||
#include <QPrinter>
|
||||
@ -94,6 +95,8 @@
|
||||
#define STYLE_NORMAL "QLineEdit#%1 { border : none; }"
|
||||
#define STYLE_FAIL "QLineEdit#%1 { border : none; color : red; }"
|
||||
|
||||
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
|
||||
|
||||
class MessageItemDelegate : public QItemDelegate
|
||||
{
|
||||
public:
|
||||
@ -213,6 +216,8 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
|
||||
connect(ui.friendSelectionWidget, SIGNAL(doubleClicked(int,QString)), this, SLOT(addTo()));
|
||||
connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged()));
|
||||
|
||||
connect(ui.msgText, SIGNAL(textChanged()), this, SLOT(checkLength()));
|
||||
|
||||
/* hide the Tree +/- */
|
||||
ui.msgFileList -> setRootIsDecorated( false );
|
||||
|
||||
@ -352,6 +357,15 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
|
||||
/* set focus to subject */
|
||||
ui.titleEdit->setFocus();
|
||||
|
||||
infoLabel = new QLabel( "", this );
|
||||
statusBar()->addPermanentWidget(infoLabel);
|
||||
|
||||
lineLabel = new QLabel( "", this );
|
||||
statusBar()->addPermanentWidget(lineLabel);
|
||||
|
||||
lengthLabel = new QLabel( "", this );
|
||||
statusBar()->addPermanentWidget(lengthLabel);
|
||||
|
||||
// create tag menu
|
||||
TagsMenu *menu = new TagsMenu (tr("Tags"), this);
|
||||
connect(menu, SIGNAL(aboutToShow()), this, SLOT(tagAboutToShow()));
|
||||
@ -2853,3 +2867,28 @@ void MessageComposer::sendInvite(const RsGxsId &to, bool autoSend)
|
||||
/* window will destroy itself! */
|
||||
}
|
||||
|
||||
void MessageComposer::checkLength()
|
||||
{
|
||||
QString text;
|
||||
RsHtml::optimizeHtml(ui.msgText, text);
|
||||
std::wstring msg = text.toStdWString();
|
||||
int charlength = msg.length();
|
||||
int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length();
|
||||
|
||||
text = tr("Message Size: %1").arg(misc::friendlyUnit(charlength));
|
||||
lengthLabel->setText(text);
|
||||
|
||||
lineLabel->setText("|");
|
||||
|
||||
if(charRemains >= 0) {
|
||||
text = tr("It remains %1 characters after HTML conversion.").arg(charRemains);
|
||||
infoLabel->setStyleSheet("QStatusBar QLabel#infoLabel { }");
|
||||
}else{
|
||||
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
|
||||
infoLabel->setStyleSheet("QStatusBar QLabel#infoLabel {color: red; font: bold; }");
|
||||
}
|
||||
|
||||
//ui.actionSend->setEnabled(charRemains>=0);
|
||||
|
||||
infoLabel->setText(text);
|
||||
}
|
||||
|
@ -168,6 +168,8 @@ private slots:
|
||||
|
||||
static QString inviteMessage();
|
||||
|
||||
void checkLength();
|
||||
|
||||
private:
|
||||
static QString buildReplyHeader(const MessageInfo &msgInfo);
|
||||
|
||||
@ -257,6 +259,10 @@ private:
|
||||
RSTreeWidgetItemCompareRole *m_compareRole;
|
||||
QCompleter *m_completer;
|
||||
|
||||
QLabel *infoLabel;
|
||||
QLabel *lengthLabel;
|
||||
QLabel *lineLabel;
|
||||
|
||||
/** Qt Designer generated object */
|
||||
Ui::MessageComposer ui;
|
||||
|
||||
|
@ -509,6 +509,7 @@ void MessageWidget::fill(const std::string &msgId)
|
||||
ui.msgText->resetImagesStatus(false);
|
||||
|
||||
clearTagLabels();
|
||||
checkLength();
|
||||
|
||||
ui.inviteFrame->hide();
|
||||
ui.expandFilesButton->setChecked(false);
|
||||
@ -690,6 +691,7 @@ void MessageWidget::fill(const std::string &msgId)
|
||||
ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size)));
|
||||
|
||||
showTagLabels();
|
||||
checkLength();
|
||||
|
||||
currMsgFlags = msgInfo.msgflags;
|
||||
}
|
||||
@ -903,3 +905,15 @@ void MessageWidget::viewSource()
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void MessageWidget::checkLength()
|
||||
{
|
||||
QString text;
|
||||
RsHtml::optimizeHtml(ui.msgText, text);
|
||||
std::wstring msg = text.toStdWString();
|
||||
int charlength = msg.length();
|
||||
|
||||
text = tr("%1 (%2) ").arg(charlength).arg(misc::friendlyUnit(charlength));
|
||||
|
||||
ui.sizeLabel->setText(text);
|
||||
}
|
@ -86,6 +86,7 @@ private slots:
|
||||
void loadImagesAlways();
|
||||
void buttonStyle();
|
||||
void viewSource();
|
||||
void checkLength();
|
||||
|
||||
private:
|
||||
void clearTagLabels();
|
||||
|
@ -621,7 +621,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
@ -682,6 +682,27 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Message Size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="sizeLabel">
|
||||
<property name="text">
|
||||
<string>Size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="filesHSpacer">
|
||||
<property name="orientation">
|
||||
|
Loading…
Reference in New Issue
Block a user