Akonadi Contacts

smsdialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2010 Felix Mauch ([email protected])
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "smsdialog.h"
10 
11 #include <KLocalizedString>
12 #include <KTextEdit>
13 #include <kcontacts/phonenumber.h>
14 
15 #include <QDialogButtonBox>
16 #include <QLabel>
17 #include <QPushButton>
18 #include <QVBoxLayout>
19 
20 SmsDialog::SmsDialog(const KContacts::PhoneNumber &number)
21  : mNumber(number.number())
22 {
23  initUI();
24 }
25 
26 SmsDialog::~SmsDialog()
27 {
28 }
29 
30 QString SmsDialog::message() const
31 {
32  return mText;
33 }
34 
35 void SmsDialog::initUI()
36 {
37  setWindowTitle(i18nc("@title:window", "SMS text"));
38 
39  auto topLayout = new QVBoxLayout(this);
40 
41  auto label = new QLabel(i18n("Please insert SMS text for an SMS to the following number: %1", mNumber), this);
42  topLayout->addWidget(label);
43  label->setWordWrap(true);
44 
45  mSmsTextEdit = new KTextEdit(this);
46  mSmsTextEdit->setAcceptRichText(false);
47  label->setBuddy(mSmsTextEdit);
48  topLayout->addWidget(mSmsTextEdit);
49 
50  connect(mSmsTextEdit, &KTextEdit::textChanged, this, &SmsDialog::updateCounter);
51 
52  mLengthLabel = new QLabel(QStringLiteral("-"), this);
53  topLayout->addWidget(mLengthLabel);
54 
55  mSmsTextEdit->setFocus();
57  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
58  okButton->setDefault(true);
59  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
60  topLayout->addWidget(buttonBox);
61  connect(buttonBox, &QDialogButtonBox::accepted, this, &SmsDialog::accept);
62  connect(buttonBox, &QDialogButtonBox::rejected, this, &SmsDialog::reject);
63 
64  updateCounter();
65 }
66 
67 void SmsDialog::updateCounter()
68 {
69  mText = mSmsTextEdit->toPlainText();
70  unsigned int messageSize = 160;
71 
72  const int size = mText.length();
73  for (int i = 0; i < size; ++i) {
74  if (mText[i].row() > 0) {
75  messageSize = 70;
76  break;
77  }
78  }
79  const int numberSms = (size - (size % messageSize)) / messageSize + 1;
80  const int numberChars = messageSize * numberSms;
81 
82  mLengthLabel->setText(i18n("%1/%2 (%3 SMS)", size, numberChars, numberSms));
83 }
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
void setShortcut(const QKeySequence &key)
void textChanged()
QString i18n(const char *text, const TYPE &arg...)
void setDefault(bool)
Key_Return
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.