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 <KContacts/PhoneNumber>
12 #include <KLocalizedString>
13 #include <KTextEdit>
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() = default;
27 
29 {
30  return mText;
31 }
32 
33 void SmsDialog::initUI()
34 {
35  setWindowTitle(i18nc("@title:window", "SMS text"));
36 
37  auto topLayout = new QVBoxLayout(this);
38 
39  auto label = new QLabel(i18n("Please insert SMS text for an SMS to the following number: %1", mNumber), this);
40  topLayout->addWidget(label);
41  label->setWordWrap(true);
42 
43  mSmsTextEdit = new KTextEdit(this);
44  mSmsTextEdit->setAcceptRichText(false);
45  label->setBuddy(mSmsTextEdit);
46  topLayout->addWidget(mSmsTextEdit);
47 
48  connect(mSmsTextEdit, &KTextEdit::textChanged, this, &SmsDialog::updateCounter);
49 
50  mLengthLabel = new QLabel(QStringLiteral("-"), this);
51  topLayout->addWidget(mLengthLabel);
52 
53  mSmsTextEdit->setFocus();
55  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
56  okButton->setDefault(true);
57  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
58  topLayout->addWidget(buttonBox);
59  connect(buttonBox, &QDialogButtonBox::accepted, this, &SmsDialog::accept);
60  connect(buttonBox, &QDialogButtonBox::rejected, this, &SmsDialog::reject);
61 
62  updateCounter();
63 }
64 
65 void SmsDialog::updateCounter()
66 {
67  mText = mSmsTextEdit->toPlainText();
68  unsigned int messageSize = 160;
69 
70  const int size = mText.length();
71  for (int i = 0; i < size; ++i) {
72  if (mText[i].row() > 0) {
73  messageSize = 70;
74  break;
75  }
76  }
77  const int numberSms = (size - (size % messageSize)) / messageSize + 1;
78  const int numberChars = messageSize * numberSms;
79 
80  mLengthLabel->setText(i18n("%1/%2 (%3 SMS)", size, numberChars, numberSms));
81 }
void setShortcut(const QKeySequence &key)
QString i18n(const char *text, const TYPE &arg...)
Key_Return
QString label(StandardShortcut id)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
void textChanged()
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.