Added to show the message length on Composer and Message Widget

This commit is contained in:
defnax 2021-01-10 19:20:17 +01:00
parent cf05c86691
commit 39a89dd2a9
5 changed files with 82 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QClipboard> #include <QClipboard>
#include <QLabel>
#include <QTextCodec> #include <QTextCodec>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinter> #include <QPrinter>
@ -94,6 +95,8 @@
#define STYLE_NORMAL "QLineEdit#%1 { border : none; }" #define STYLE_NORMAL "QLineEdit#%1 { border : none; }"
#define STYLE_FAIL "QLineEdit#%1 { border : none; color : red; }" #define STYLE_FAIL "QLineEdit#%1 { border : none; color : red; }"
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
class MessageItemDelegate : public QItemDelegate class MessageItemDelegate : public QItemDelegate
{ {
public: 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(doubleClicked(int,QString)), this, SLOT(addTo()));
connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged())); connect(ui.friendSelectionWidget, SIGNAL(itemSelectionChanged()), this, SLOT(friendSelectionChanged()));
connect(ui.msgText, SIGNAL(textChanged()), this, SLOT(checkLength()));
/* hide the Tree +/- */ /* hide the Tree +/- */
ui.msgFileList -> setRootIsDecorated( false ); ui.msgFileList -> setRootIsDecorated( false );
@ -352,6 +357,15 @@ MessageComposer::MessageComposer(QWidget *parent, Qt::WindowFlags flags)
/* set focus to subject */ /* set focus to subject */
ui.titleEdit->setFocus(); 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 // create tag menu
TagsMenu *menu = new TagsMenu (tr("Tags"), this); TagsMenu *menu = new TagsMenu (tr("Tags"), this);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(tagAboutToShow())); connect(menu, SIGNAL(aboutToShow()), this, SLOT(tagAboutToShow()));
@ -2853,3 +2867,28 @@ void MessageComposer::sendInvite(const RsGxsId &to, bool autoSend)
/* window will destroy itself! */ /* 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);
}

View File

@ -168,6 +168,8 @@ private slots:
static QString inviteMessage(); static QString inviteMessage();
void checkLength();
private: private:
static QString buildReplyHeader(const MessageInfo &msgInfo); static QString buildReplyHeader(const MessageInfo &msgInfo);
@ -257,6 +259,10 @@ private:
RSTreeWidgetItemCompareRole *m_compareRole; RSTreeWidgetItemCompareRole *m_compareRole;
QCompleter *m_completer; QCompleter *m_completer;
QLabel *infoLabel;
QLabel *lengthLabel;
QLabel *lineLabel;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::MessageComposer ui; Ui::MessageComposer ui;

View File

@ -509,6 +509,7 @@ void MessageWidget::fill(const std::string &msgId)
ui.msgText->resetImagesStatus(false); ui.msgText->resetImagesStatus(false);
clearTagLabels(); clearTagLabels();
checkLength();
ui.inviteFrame->hide(); ui.inviteFrame->hide();
ui.expandFilesButton->setChecked(false); ui.expandFilesButton->setChecked(false);
@ -690,6 +691,7 @@ void MessageWidget::fill(const std::string &msgId)
ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size))); ui.filesSize->setText(QString(misc::friendlyUnit(msgInfo.size)));
showTagLabels(); showTagLabels();
checkLength();
currMsgFlags = msgInfo.msgflags; currMsgFlags = msgInfo.msgflags;
} }
@ -903,3 +905,15 @@ void MessageWidget::viewSource()
delete dialog; 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);
}

View File

@ -86,6 +86,7 @@ private slots:
void loadImagesAlways(); void loadImagesAlways();
void buttonStyle(); void buttonStyle();
void viewSource(); void viewSource();
void checkLength();
private: private:
void clearTagLabels(); void clearTagLabels();

View File

@ -621,7 +621,7 @@
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <property name="rightMargin">
<number>0</number> <number>3</number>
</property> </property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
@ -682,6 +682,27 @@
</item> </item>
</layout> </layout>
</item> </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> <item>
<spacer name="filesHSpacer"> <spacer name="filesHSpacer">
<property name="orientation"> <property name="orientation">