Merge pull request #2089 from defnax/Postbutton-fix

Fixing the Post buttons to get disabled when the limit has been exceeded
This commit is contained in:
csoler 2020-11-01 22:07:14 +01:00 committed by GitHub
commit c8939bf8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 85 additions and 43 deletions

View File

@ -56,8 +56,9 @@ PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGrou
connect(ui->submitButton, SIGNAL(clicked()), this, SLOT(createPost()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->addPicButton, SIGNAL(clicked() ), this , SLOT(addPicture()));
connect(ui->RichTextEditWidget, SIGNAL(textSizeOk(bool)),ui->submitButton, SLOT(setEnabled(bool)));
ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/postedlinks.png"));
ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/postedlinks.png"));
ui->headerFrame->setHeaderText(tr("Create a new Post"));
setAttribute ( Qt::WA_DeleteOnClose, true );

View File

@ -26,6 +26,8 @@
#include <QMessageBox>
#include <iostream>
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
GxsCreateCommentDialog::GxsCreateCommentDialog(RsGxsCommentService *service, const RsGxsGrpMsgIdPair &parentId, const RsGxsMessageId& threadId, const RsGxsId& default_author,QWidget *parent) :
QDialog(parent),
ui(new Ui::GxsCreateCommentDialog), mCommentService(service), mParentId(parentId), mThreadId(threadId)
@ -33,9 +35,10 @@ GxsCreateCommentDialog::GxsCreateCommentDialog(RsGxsCommentService *service, co
ui->setupUi(this);
connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createComment()));
connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->commentTextEdit, SIGNAL(textChanged()), this, SLOT(checkLength()));
/* fill in the available OwnIds for signing */
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, default_author);
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, default_author);
}
void GxsCreateCommentDialog::loadComment(const QString &msgText, const QString &msgAuthor, const RsGxsId &msgAuthorId)
@ -105,3 +108,19 @@ GxsCreateCommentDialog::~GxsCreateCommentDialog()
{
delete ui;
}
void GxsCreateCommentDialog::checkLength(){
QString text;
RsHtml::optimizeHtml(ui->commentTextEdit, text);
std::wstring msg = text.toStdWString();
int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length();
if(charRemains >= 0) {
text = tr("It remains %1 characters after HTML conversion.").arg(charRemains);
ui->infoLabel->setStyleSheet("QLabel#infoLabel { }");
}else{
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
ui->infoLabel->setStyleSheet("QLabel#infoLabel {color: red; font: bold; }");
}
ui->postButton->setEnabled(charRemains>=0);
ui->infoLabel->setText(text);
}

View File

@ -43,6 +43,7 @@ public:
private slots:
void createComment();
void checkLength();
private:
Ui::GxsCreateCommentDialog *ui;

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>324</height>
<width>505</width>
<height>367</height>
</rect>
</property>
<property name="windowTitle">
@ -32,7 +32,7 @@
<item row="0" column="0">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -142,17 +142,20 @@ p, li { white-space: pre-wrap; }
<property name="topMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="GxsIdLabel" name="replaytolabel">
<property name="styleSheet">
<string notr="true"/>
<item row="5" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="text">
<string/>
<property name="sizeHint" stdset="0">
<size>
<width>276</width>
<height>20</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<item row="2" column="0" colspan="3">
<widget class="MimeTextEdit" name="commentTextEdit">
<property name="styleSheet">
<string notr="true"/>
@ -162,7 +165,21 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<item row="5" column="2">
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout" name="signedHLayout">
<item>
<widget class="QLabel" name="signedLabel">
@ -186,30 +203,26 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</item>
<item row="3" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>276</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QPushButton" name="postButton">
<property name="text">
<string>Post</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="cancelButton">
<item row="0" column="0" colspan="3">
<widget class="GxsIdLabel" name="replaytolabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>Cancel</string>
<string/>
</property>
</widget>
</item>

View File

@ -58,10 +58,12 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/channel.png"));
if(!existing_post.isNull())
if(!existing_post.isNull()){
headerFrame->setHeaderText(tr("Edit Channel Post"));
else
postButton->setText(tr("Update"));
}else{
headerFrame->setHeaderText(tr("New Channel Post"));
}
setAttribute ( Qt::WA_DeleteOnClose, true );
@ -79,6 +81,7 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
connect(stackedWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool)));
connect(aspectRatio_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(changeAspectRatio(int)));
connect(RichTextEditWidget, SIGNAL(textSizeOk(bool)),postButton, SLOT(setEnabled(bool)));
channelpostButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/comment.png"));
attachmentsButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/attachements.png"));

View File

@ -187,7 +187,8 @@ ShareManager QPushButton#addButton:hover {
padding: 4px;
}
CreateGxsForumMsg QPushButton#postButton:disabled, PostedCreatePostDialog QPushButton#postButton:disabled {
CreateGxsForumMsg QPushButton#postButton:disabled, PostedCreatePostDialog QPushButton#submitButton:disabled,
CreateGxsChannelMsg QPushButton#postButton:disabled, GxsCreateCommentDialog QPushButton#postButton:disabled {
font: bold;
font-size: 15px;
color: white;

View File

@ -2109,7 +2109,8 @@ GxsCreateCommentDialog QPushButton#postButton:hover, , GxsGroupDialog QPushButto
padding: 2px;
}
CreateGxsForumMsg QPushButton#postButton:disabled {
CreateGxsForumMsg QPushButton#postButton:disabled, PostedCreatePostDialog QPushButton#submitButton:disabled,
CreateGxsChannelMsg QPushButton#postButton:disabled, GxsCreateCommentDialog QPushButton#postButton:disabled {
font: bold;
font-size: 15px;
color: white;

View File

@ -1262,7 +1262,8 @@ ShareManager QPushButton#closeButton {
padding: 2px;
}
CreateGxsForumMsg QPushButton#postButton:disabled {
CreateGxsForumMsg QPushButton#postButton:disabled, PostedCreatePostDialog QPushButton#submitButton:disabled,
CreateGxsChannelMsg QPushButton#postButton:disabled, GxsCreateCommentDialog QPushButton#postButton:disabled {
font: bold;
font-size: 15px;
color: white;

View File

@ -602,15 +602,15 @@ void RichTextEdit::checkLength(){
if(charRemains >= 0) {
text = tr("It remains %1 characters after HTML conversion.").arg(charRemains);
f_info->setStyleSheet("QLabel#f_info { }");
emit textSizeOk(true);
}else{
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
f_info->setStyleSheet("QLabel#f_info {color: red; font: bold; }");
f_info->setStyleSheet("QLabel#f_info {color: red; font: bold; }");
emit textSizeOk(false);
}
//buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0);
f_info->setText(text);
}
void RichTextEdit::setPlaceHolderTextPosted() {
f_textedit->setPlaceholderText(tr("Text (optional)"));
}

View File

@ -38,10 +38,12 @@ class RichTextEdit : public QWidget, protected Ui::RichTextEdit {
QTextCursor textCursor() const { return f_textedit->textCursor(); }
void setTextCursor(const QTextCursor& cursor) { f_textedit->setTextCursor(cursor); }
signals:
void textSizeOk(bool);
public slots:
void setText(const QString &text);
void setPlaceHolderTextPosted();
void setPlaceHolderTextPosted();
protected slots:
void setPlainText(const QString &text) { f_textedit->setPlainText(text); }