Advertisement
Guest User

More work with chatedit

a guest
Jul 17th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.71 KB | None | 0 0
  1. diff --git a/src/chateditproxy.cpp b/src/chateditproxy.cpp
  2. index f81e0704..5e7787ce 100644
  3. --- a/src/chateditproxy.cpp
  4. +++ b/src/chateditproxy.cpp
  5. @@ -25,7 +25,6 @@
  6.  #include <QVBoxLayout>
  7.  
  8.  static const QLatin1String expandingLineEdit("options.ui.chat.use-expanding-line-edit");
  9. -static const QLatin1String audioMessage("options.media.audio-message");
  10.  
  11.  ChatEditProxy::ChatEditProxy(QWidget *parent) :
  12.      QWidget(parent), lineEditEnabled_(false), textEdit_(nullptr), layout_(nullptr)
  13. @@ -34,16 +33,8 @@ ChatEditProxy::ChatEditProxy(QWidget *parent) :
  14.      layout_->setMargin(0);
  15.      layout_->setSpacing(0);
  16.  
  17. -    connect(PsiOptions::instance(), &PsiOptions::optionChanged, this, [this](const QString &option) {
  18. -        if (option == expandingLineEdit)
  19. -            optionsChanged();
  20. -        if (option == audioMessage)
  21. -            addRrecordButton();
  22. -    });
  23. -    optionsChanged();
  24. -
  25. -    if (!textEdit_)
  26. -        updateLayout();
  27. +    connect(PsiOptions::instance(), &PsiOptions::optionChanged, this, &ChatEditProxy::optionsChanged);
  28. +    optionsChanged(expandingLineEdit);
  29.  }
  30.  
  31.  /**
  32. @@ -97,26 +88,16 @@ void ChatEditProxy::updateLayout()
  33.      delete textEdit_;
  34.      textEdit_ = newEdit;
  35.      layout_->addWidget(textEdit_);
  36. -    // Add sound record button if allowed and not exists
  37. -    addRrecordButton();
  38.      emit textEditCreated(textEdit_);
  39.  }
  40.  
  41.  /**
  42.   * Update ChatEdit widget according to current options.
  43.   */
  44. -void ChatEditProxy::optionsChanged()
  45. -{
  46. -    lineEditEnabled_ = PsiOptions::instance()->getOption(expandingLineEdit).toBool();
  47. -    updateLayout();
  48. -}
  49. -
  50. -void ChatEditProxy::addRrecordButton()
  51. +void ChatEditProxy::optionsChanged(const QString &option)
  52.  {
  53. -    bool isEnabled = PsiOptions::instance()->getOption(audioMessage).toBool();
  54. -    if (!textEdit_->hasSoundRecButton() && isEnabled) {
  55. -        textEdit_->addSoundRecButton();
  56. -    } else if (textEdit_->hasSoundRecButton() && !isEnabled) {
  57. -        textEdit_->removeSoundRecButton();
  58. +    if (option == expandingLineEdit) {
  59. +        lineEditEnabled_ = PsiOptions::instance()->getOption(expandingLineEdit).toBool();
  60. +        updateLayout();
  61.      }
  62.  }
  63. diff --git a/src/chateditproxy.h b/src/chateditproxy.h
  64. index 291191a9..ab631d62 100644
  65. --- a/src/chateditproxy.h
  66. +++ b/src/chateditproxy.h
  67. @@ -35,7 +35,7 @@ public:
  68.       * Returns encapsulated QTextEdit widget.
  69.       */
  70.      ChatEdit *chatEdit() const { return textEdit_; }
  71. -    void      optionsChanged();
  72. +    void      optionsChanged(const QString &option);
  73.  
  74.  signals:
  75.      /**
  76. @@ -54,7 +54,6 @@ private:
  77.      virtual ChatEdit *createTextEdit();
  78.      void              moveData(QTextEdit *newTextEdit, QTextEdit *oldTextEdit) const;
  79.      void              updateLayout();
  80. -    void              addRrecordButton();
  81.  
  82.      bool      lineEditEnabled_;
  83.      ChatEdit *textEdit_;
  84. diff --git a/src/groupchatdlg.cpp b/src/groupchatdlg.cpp
  85. index 6a9c0303..63ae98c8 100644
  86. --- a/src/groupchatdlg.cpp
  87. +++ b/src/groupchatdlg.cpp
  88. @@ -916,7 +916,7 @@ GCMainDlg::GCMainDlg(PsiAccount *pa, const Jid &j, TabManager *tabManager) : Tab
  89.          } else if (name == QString::fromLatin1("gchat_configure")) {
  90.              connect(action, SIGNAL(triggered()), SLOT(configureRoom()));
  91.          } else if (name == QString::fromLatin1("gchat_html_text")) {
  92. -            connect(action, SIGNAL(triggered()), d->mle(), SLOT(doHTMLTextMenu()));
  93. +            connect(action, &QAction::triggered, d->mle(), &ChatEdit::doHTMLTextMenu);
  94.          } else if (name == QString::fromLatin1("gchat_icon")) {
  95.              connect(account()->psi()->iconSelectPopup(), SIGNAL(textSelected(QString)), d, SLOT(addEmoticon(QString)));
  96.              action->setMenu(pa->psi()->iconSelectPopup());
  97. @@ -2288,7 +2288,6 @@ void GCMainDlg::setLooks()
  98.          d->mle()->setCssString(css);
  99.      }
  100.      ui_.vsplitter->optionsChanged();
  101. -    ui_.mle->optionsChanged();
  102.  
  103.      // update the fonts
  104.      QFont f;
  105. diff --git a/src/msgmle.cpp b/src/msgmle.cpp
  106. index 0e251dae..ef7f8cb5 100644
  107. --- a/src/msgmle.cpp
  108. +++ b/src/msgmle.cpp
  109. @@ -1,4 +1,4 @@
  110. -/*
  111. +/*
  112.   * msgmle.cpp - subclass of PsiTextView to handle various hotkeys
  113.   * Copyright (C) 2001-2003  Justin Karneges, Michail Pishchagin
  114.   *
  115. @@ -51,6 +51,9 @@
  116.  static const int TIMEOUT        = 30000; // 30 secs maximum time interval
  117.  static const int SECOND         = 1000;
  118.  static const int maxOverlayTime = TIMEOUT / SECOND;
  119. +static const QLatin1String capOption("options.ui.chat.auto-capitalize");
  120. +static const QLatin1String audioMessage("options.media.audio-message");
  121. +static const QLatin1String spellOption("options.ui.spell-check.enabled");
  122.  
  123.  //----------------------------------------------------------------------------
  124.  // CapitalLettersController
  125. @@ -61,7 +64,7 @@ class CapitalLettersController : public QObject {
  126.  public:
  127.      explicit CapitalLettersController(QTextEdit *parent) : QObject(), te_(parent), enabled_(true)
  128.      {
  129. -        connect(te_->document(), SIGNAL(contentsChange(int, int, int)), SLOT(textChanged(int, int, int)));
  130. +        connect(te_->document(), &QTextDocument::contentsChange, this, &CapitalLettersController::textChanged);
  131.      }
  132.  
  133.      ~CapitalLettersController() override = default;
  134. @@ -101,9 +104,8 @@ public slots:
  135.              } else if (charsAdded > 1) { // Insert a piece of text
  136.                  return;
  137.              } else {
  138. -                QString txt = te_->toPlainText();
  139.                  QRegExp capitalizeAfter("(?:^[^.][.]+\\s+)|(?:\\s*[^.]{2,}[.]+\\s+)|(?:[!?]\\s+)");
  140. -                int     index = txt.lastIndexOf(capitalizeAfter);
  141. +                int     index = te_->toPlainText().lastIndexOf(capitalizeAfter);
  142.                  if (index != -1 && index == pos - capitalizeAfter.matchedLength()) {
  143.                      capitalizeNext_ = true;
  144.                  }
  145. @@ -173,11 +175,13 @@ ChatEdit::ChatEdit(QWidget *parent) :
  146.  
  147.      previous_position_ = 0;
  148.      setCheckSpelling(checkSpellingGloballyEnabled());
  149. -    connect(PsiOptions::instance(), SIGNAL(optionChanged(const QString &)), SLOT(optionsChanged()));
  150. +    connect(PsiOptions::instance(), &PsiOptions::optionChanged, this, &ChatEdit::optionsChanged);
  151.      typedMsgsIndex = 0;
  152.      initActions();
  153.      setShortcuts();
  154. -    optionsChanged();
  155. +    optionsChanged(spellOption);
  156. +    optionsChanged(capOption);
  157. +    optionsChanged(audioMessage);
  158.  }
  159.  
  160.  ChatEdit::~ChatEdit()
  161. @@ -193,30 +197,30 @@ void ChatEdit::initActions()
  162.  {
  163.      act_showMessagePrev = new QAction(this);
  164.      addAction(act_showMessagePrev);
  165. -    connect(act_showMessagePrev, SIGNAL(triggered()), SLOT(showHistoryMessagePrev()));
  166. +    connect(act_showMessagePrev, &QAction::triggered, this, &ChatEdit::showHistoryMessagePrev);
  167.  
  168.      act_showMessageNext = new QAction(this);
  169.      addAction(act_showMessageNext);
  170. -    connect(act_showMessageNext, SIGNAL(triggered()), SLOT(showHistoryMessageNext()));
  171. +    connect(act_showMessageNext, &QAction::triggered, this, &ChatEdit::showHistoryMessageNext);
  172.  
  173.      act_showMessageFirst = new QAction(this);
  174.      addAction(act_showMessageFirst);
  175. -    connect(act_showMessageFirst, SIGNAL(triggered()), SLOT(showHistoryMessageFirst()));
  176. +    connect(act_showMessageFirst, &QAction::triggered, this, &ChatEdit::showHistoryMessageFirst);
  177.  
  178.      act_showMessageLast = new QAction(this);
  179.      addAction(act_showMessageLast);
  180. -    connect(act_showMessageLast, SIGNAL(triggered()), SLOT(showHistoryMessageLast()));
  181. +    connect(act_showMessageLast, &QAction::triggered, this, &ChatEdit::showHistoryMessageLast);
  182.  
  183.      act_changeCase = new QAction(this);
  184.      addAction(act_changeCase);
  185. -    connect(act_changeCase, SIGNAL(triggered()), capitalizer_, SLOT(changeCase()));
  186. +    connect(act_changeCase, &QAction::triggered, capitalizer_, &CapitalLettersController::changeCase);
  187.  
  188.      QClipboard *clipboard = QApplication::clipboard();
  189.      actPasteAsQuote_      = new QAction(tr("Paste as Quotation"), this);
  190.      actPasteAsQuote_->setEnabled(clipboard->mimeData()->hasText());
  191.      addAction(actPasteAsQuote_);
  192. -    connect(actPasteAsQuote_, SIGNAL(triggered()), SLOT(pasteAsQuote()));
  193. -    connect(clipboard, SIGNAL(dataChanged()), SLOT(changeActPasteAsQuoteState()));
  194. +    connect(actPasteAsQuote_, &QAction::triggered, this, &ChatEdit::pasteAsQuote);
  195. +    connect(clipboard, &QClipboard::dataChanged, this, &ChatEdit::changeActPasteAsQuoteState);
  196.  }
  197.  
  198.  void ChatEdit::setShortcuts()
  199. @@ -247,12 +251,12 @@ QMenu *ChatEdit::createStandardContextMenu(const QPoint &position)
  200.  
  201.  bool ChatEdit::checkSpellingGloballyEnabled()
  202.  {
  203. -    return (SpellChecker::instance()->available()
  204. -            && PsiOptions::instance()->getOption("options.ui.spell-check.enabled").toBool());
  205. +    return (SpellChecker::instance()->available() && PsiOptions::instance()->getOption(spellOption).toBool());
  206.  }
  207.  
  208.  void ChatEdit::setCheckSpelling(bool b)
  209.  {
  210. +    document()->blockSignals(true);
  211.      check_spelling_ = b;
  212.      if (check_spelling_) {
  213.          if (!spellhighlighter_)
  214. @@ -260,6 +264,7 @@ void ChatEdit::setCheckSpelling(bool b)
  215.      } else {
  216.          spellhighlighter_.reset();
  217.      }
  218. +    document()->blockSignals(false);
  219.  }
  220.  
  221.  bool ChatEdit::focusNextPrevChild(bool next) { return QWidget::focusNextPrevChild(next); }
  222. @@ -333,13 +338,13 @@ void ChatEdit::contextMenuEvent(QContextMenuEvent *e)
  223.                  if (!suggestions.isEmpty()) {
  224.                      for (const QString &suggestion : suggestions) {
  225.                          QAction *act_suggestion = spell_menu.addAction(suggestion);
  226. -                        connect(act_suggestion, SIGNAL(triggered()), SLOT(applySuggestion()));
  227. +                        connect(act_suggestion, &QAction::triggered, this, &ChatEdit::applySuggestion);
  228.                      }
  229.                      spell_menu.addSeparator();
  230.                  }
  231.                  if (SpellChecker::instance()->writable()) {
  232.                      QAction *act_add = spell_menu.addAction(tr("Add to dictionary"));
  233. -                    connect(act_add, SIGNAL(triggered()), SLOT(addToDictionary()));
  234. +                    connect(act_add, &QAction::triggered, this, &ChatEdit::addToDictionary);
  235.                  }
  236.                  spell_menu.exec(QCursor::pos());
  237.                  e->accept();
  238. @@ -405,10 +410,20 @@ void ChatEdit::addToDictionary()
  239.      setTextCursor(tc);
  240.  }
  241.  
  242. -void ChatEdit::optionsChanged()
  243. +void ChatEdit::optionsChanged(const QString &option)
  244.  {
  245. -    setCheckSpelling(checkSpellingGloballyEnabled());
  246. -    capitalizer_->setEnabled(PsiOptions::instance()->getOption("options.ui.chat.auto-capitalize").toBool());
  247. +    if (option == spellOption)
  248. +        setCheckSpelling(checkSpellingGloballyEnabled());
  249. +    if (option == capOption)
  250. +        capitalizer_->setEnabled(PsiOptions::instance()->getOption(capOption).toBool());
  251. +    if (option == audioMessage) {
  252. +        bool isEnabled = PsiOptions::instance()->getOption(audioMessage).toBool();
  253. +        if (!recButton_ && isEnabled) {
  254. +            addSoundRecButton();
  255. +        } else if (recButton_ && !isEnabled) {
  256. +            removeSoundRecButton();
  257. +        }
  258. +    }
  259.  }
  260.  
  261.  void ChatEdit::showHistoryMessageNext()
  262. @@ -703,11 +718,13 @@ void ChatEdit::addSoundRecButton()
  263.  void ChatEdit::removeSoundRecButton()
  264.  {
  265.      disconnect(recButton_.get());
  266. -    layout_.reset();
  267.      recButton_.reset();
  268.      overlay_.reset();
  269. +    layout_.reset();
  270.      disconnect(recorder_.get());
  271.      recorder_.reset();
  272. +    disconnect(document(), &QTextDocument::contentsChanged, this, &ChatEdit::setRigthMargin);
  273. +    setRigthMargin();
  274.  }
  275.  
  276.  void ChatEdit::setOverlayText(int value) { overlay_->setText(tr("Recording (%1 sec left)").arg(value)); }
  277. @@ -743,9 +760,11 @@ void ChatEdit::setRigthMargin()
  278.      // Set margin for text to avoid text placing under record button
  279.      const float      margin = recButtonHeigth() * 1.5;
  280.      QTextFrameFormat frmt   = document()->rootFrame()->frameFormat();
  281. -    if (frmt.rightMargin() < margin) {
  282. +    if (frmt.rightMargin() < margin || margin == 0) {
  283. +        document()->blockSignals(true);
  284.          frmt.setRightMargin(margin);
  285.          document()->rootFrame()->setFrameFormat(frmt);
  286. +        document()->blockSignals(false);
  287.      }
  288.  }
  289.  
  290. @@ -760,7 +779,7 @@ LineEdit::LineEdit(QWidget *parent) : ChatEdit(parent)
  291.  
  292.      setMinimumHeight(0);
  293.  
  294. -    connect(this, &QTextEdit::textChanged, this, &LineEdit::recalculateSize);
  295. +    connect(document(), &QTextDocument::contentsChanged, this, &LineEdit::recalculateSize);
  296.  }
  297.  
  298.  LineEdit::~LineEdit() { }
  299. @@ -789,13 +808,13 @@ QSize LineEdit::sizeHint() const
  300.  void LineEdit::resizeEvent(QResizeEvent *e)
  301.  {
  302.      ChatEdit::resizeEvent(e);
  303. -    QTimer::singleShot(0, this, SLOT(updateScrollBar()));
  304. +    QTimer::singleShot(0, this, &LineEdit::updateScrollBar);
  305.  }
  306.  
  307.  void LineEdit::recalculateSize()
  308.  {
  309.      updateGeometry();
  310. -    QTimer::singleShot(0, this, SLOT(updateScrollBar()));
  311. +    QTimer::singleShot(0, this, &LineEdit::updateScrollBar);
  312.  }
  313.  
  314.  void LineEdit::updateScrollBar()
  315. diff --git a/src/msgmle.h b/src/msgmle.h
  316. index 88e1c7d6..2d4e1cae 100644
  317. --- a/src/msgmle.h
  318. +++ b/src/msgmle.h
  319. @@ -83,7 +83,7 @@ public slots:
  320.  protected slots:
  321.      void applySuggestion();
  322.      void addToDictionary();
  323. -    void optionsChanged();
  324. +    void optionsChanged(const QString &option);
  325.      void showHistoryMessageNext();
  326.      void showHistoryMessagePrev();
  327.      void showHistoryMessageFirst();
  328. diff --git a/src/psichatdlg.cpp b/src/psichatdlg.cpp
  329. index 0dfe0f52..f2ae063f 100644
  330. --- a/src/psichatdlg.cpp
  331. +++ b/src/psichatdlg.cpp
  332. @@ -379,7 +379,6 @@ void PsiChatDlg::setLooks()
  333.          chatEdit()->setCssString(css);
  334.      }
  335.      ui_.splitter->optionsChanged();
  336. -    ui_.mle->optionsChanged();
  337.  
  338.      int s = PsiIconset::instance()->system().iconSize();
  339.      ui_.lb_status->setFixedSize(s, s);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement