From da6e0b015a7815d06bd4bf8ba854433f0b8cd22e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage <emmanuel.lepage@savoirfairelinux.com> Date: Tue, 13 Dec 2011 14:47:01 -0500 Subject: [PATCH] [ #7874 ] Twice less lines, same result --- kde/src/SFLPhoneView.cpp | 4 +- kde/src/widgets/Dialpad.cpp | 128 ++++++++---------------------------- kde/src/widgets/Dialpad.h | 63 ++++++++---------- 3 files changed, 57 insertions(+), 138 deletions(-) diff --git a/kde/src/SFLPhoneView.cpp b/kde/src/SFLPhoneView.cpp index b421e23f0c..617c8fb774 100755 --- a/kde/src/SFLPhoneView.cpp +++ b/kde/src/SFLPhoneView.cpp @@ -717,9 +717,9 @@ void SFLPhoneView::record() ///Access the voice mail list void SFLPhoneView::mailBox() { - Account * account = SFLPhone::model()->getCurrentAccount(); + Account* account = SFLPhone::model()->getCurrentAccount(); QString mailBoxNumber = account->getAccountDetail(ACCOUNT_MAILBOX); - Call * call = SFLPhone::model()->addDialingCall(); + Call* call = SFLPhone::model()->addDialingCall(); call->appendText(mailBoxNumber); action(call, CALL_ACTION_ACCEPT); } diff --git a/kde/src/widgets/Dialpad.cpp b/kde/src/widgets/Dialpad.cpp index 54998f3fe6..8634b1dee1 100755 --- a/kde/src/widgets/Dialpad.cpp +++ b/kde/src/widgets/Dialpad.cpp @@ -17,122 +17,50 @@ * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ + **************************************************************************/ //Parent #include "Dialpad.h" //Qt -#include <QtCore/QDebug> #include <QtGui/QLabel> -#include <QtGui/QPushButton> #include <QtGui/QGridLayout> -///Constructor -Dialpad::Dialpad(QWidget *parent) - : QWidget(parent) -{ - gridLayout = new QGridLayout(this); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - - pushButton_0 = new QPushButton(this); - pushButton_1 = new QPushButton(this); - pushButton_2 = new QPushButton(this); - pushButton_3 = new QPushButton(this); - pushButton_4 = new QPushButton(this); - pushButton_5 = new QPushButton(this); - pushButton_6 = new QPushButton(this); - pushButton_7 = new QPushButton(this); - pushButton_8 = new QPushButton(this); - pushButton_9 = new QPushButton(this); - pushButton_diese = new QPushButton(this); - pushButton_etoile = new QPushButton(this); - - pushButton_0->setObjectName(QString::fromUtf8("pushButton_0")); - pushButton_1->setObjectName(QString::fromUtf8("pushButton_1")); - pushButton_2->setObjectName(QString::fromUtf8("pushButton_2")); - pushButton_3->setObjectName(QString::fromUtf8("pushButton_3")); - pushButton_4->setObjectName(QString::fromUtf8("pushButton_4")); - pushButton_5->setObjectName(QString::fromUtf8("pushButton_5")); - pushButton_6->setObjectName(QString::fromUtf8("pushButton_6")); - pushButton_7->setObjectName(QString::fromUtf8("pushButton_7")); - pushButton_8->setObjectName(QString::fromUtf8("pushButton_8")); - pushButton_9->setObjectName(QString::fromUtf8("pushButton_9")); - pushButton_diese->setObjectName(QString::fromUtf8("pushButton_diese")); - pushButton_etoile->setObjectName(QString::fromUtf8("pushButton_etoile")); - - gridLayout->addWidget(pushButton_1 , 0, 0 ); - gridLayout->addWidget(pushButton_2 , 0, 1 ); - gridLayout->addWidget(pushButton_3 , 0, 2 ); - gridLayout->addWidget(pushButton_4 , 1, 0 ); - gridLayout->addWidget(pushButton_5 , 1, 1 ); - gridLayout->addWidget(pushButton_6 , 1, 2 ); - gridLayout->addWidget(pushButton_7 , 2, 0 ); - gridLayout->addWidget(pushButton_8 , 2, 1 ); - gridLayout->addWidget(pushButton_9 , 2, 2 ); - gridLayout->addWidget(pushButton_etoile , 3, 0 ); - gridLayout->addWidget(pushButton_0 , 3, 1 ); - gridLayout->addWidget(pushButton_diese , 3, 2 ); - - fillButtons(); - - QMetaObject::connectSlotsByName(this); -} - -///Make the buttons -void Dialpad::fillButtons() -{ - QHBoxLayout * layout; - QLabel * number; - QLabel * text; - int spacing = 5 ; - int numberSize = 14 ; - int textSize = 8 ; - - QPushButton * buttons[12] = - {pushButton_1, pushButton_2, pushButton_3, - pushButton_4, pushButton_5, pushButton_6, - pushButton_7, pushButton_8, pushButton_9, - pushButton_etoile, pushButton_0, pushButton_diese}; - - QString numbers[12] = - {"1", "2", "3", - "4", "5", "6", - "7", "8", "9", +const char* Dialpad::m_pNumbers[] = + {"1", "2", "3", + "4", "5", "6", + "7", "8", "9", "*", "0", "#"}; - QString texts[12] = - { "" , "abc", "def" , +const char* Dialpad::m_pTexts[12] = + { "" , "abc", "def" , "ghi" , "jkl", "mno" , "pqrs", "tuv", "wxyz", "" , "" , "" }; - - for(int i = 0 ; i < 12 ; i++) { - layout = new QHBoxLayout(); - layout->setSpacing(spacing); - number = new QLabel(numbers[i]); - number->setFont(QFont("", numberSize)); + +///Constructor +Dialpad::Dialpad(QWidget *parent) + : QWidget(parent),gridLayout(new QGridLayout(this)),m_pButtons(new DialpadButton*[12]) +{ + for (uint i=0; i < 12;i++) { + m_pButtons[i] = new DialpadButton(this,m_pNumbers[i]); + gridLayout->addWidget(m_pButtons[i],i/3,i%3); + QHBoxLayout* layout = new QHBoxLayout(m_pButtons[i]); + layout->setSpacing(m_Spacing); + QLabel* number = new QLabel(m_pNumbers[i]); + number->setFont(QFont("", m_NumberSize)); layout->addWidget(number); number->setAlignment(Qt::AlignRight | Qt::AlignVCenter); - text = new QLabel(texts[i]); - text->setFont(QFont("", textSize)); + QLabel* text = new QLabel(m_pTexts[i]); + text->setFont(QFont("", m_TextSize)); layout->addWidget(text); - buttons[i]->setLayout(layout); - buttons[i]->setMinimumHeight(30); - buttons[i]->setText(""); + m_pButtons[i]->setMinimumHeight(30); + connect(m_pButtons[i],SIGNAL(typed(QString&)),this,SLOT(clicked(QString&))); } } -///Slots -void Dialpad::on_pushButton_1_clicked() { emit typed("1"); } -void Dialpad::on_pushButton_2_clicked() { emit typed("2"); } -void Dialpad::on_pushButton_3_clicked() { emit typed("3"); } -void Dialpad::on_pushButton_4_clicked() { emit typed("4"); } -void Dialpad::on_pushButton_5_clicked() { emit typed("5"); } -void Dialpad::on_pushButton_6_clicked() { emit typed("6"); } -void Dialpad::on_pushButton_7_clicked() { emit typed("7"); } -void Dialpad::on_pushButton_8_clicked() { emit typed("8"); } -void Dialpad::on_pushButton_9_clicked() { emit typed("9"); } -void Dialpad::on_pushButton_0_clicked() { emit typed("0"); } -void Dialpad::on_pushButton_diese_clicked() { emit typed("#"); } -void Dialpad::on_pushButton_etoile_clicked() { emit typed("*"); } +///Proxy to make the view more convinient to use +void Dialpad::clicked(QString& text) +{ + emit typed(text); +} \ No newline at end of file diff --git a/kde/src/widgets/Dialpad.h b/kde/src/widgets/Dialpad.h index 2555e5e936..fbccc35edf 100755 --- a/kde/src/widgets/Dialpad.h +++ b/kde/src/widgets/Dialpad.h @@ -22,11 +22,27 @@ #define DIALPAD_H #include <QWidget> +#include <QPushButton> //Qt -class QPushButton; class QGridLayout; +///@class DialpadButton the 12 button of the dialpad +class DialpadButton : public QPushButton +{ + Q_OBJECT +public: + DialpadButton(QWidget* parent, const QString& value): QPushButton(parent),m_Value(value) { + connect(this,SIGNAL(clicked()),this,SLOT(sltClicked())); + } +private slots: + void sltClicked() { emit typed(m_Value); } +private: + QString m_Value; +signals: + void typed(QString&); +}; + ///@class Dialpad A widget that representing a phone dialpad with associated numbers and letters class Dialpad : public QWidget @@ -35,48 +51,23 @@ Q_OBJECT private: //Attributes - QGridLayout* gridLayout; - QPushButton* pushButton_0; - QPushButton* pushButton_1; - QPushButton* pushButton_2; - QPushButton* pushButton_3; - QPushButton* pushButton_4; - QPushButton* pushButton_5; - QPushButton* pushButton_6; - QPushButton* pushButton_7; - QPushButton* pushButton_8; - QPushButton* pushButton_9; - QPushButton* pushButton_diese; - QPushButton* pushButton_etoile; + QGridLayout* gridLayout; + DialpadButton** m_pButtons; + static const char* m_pNumbers[]; + static const char* m_pTexts []; + static const int m_Spacing = 5 ; + static const int m_NumberSize = 14 ; + static const int m_TextSize = 8 ; + public: Dialpad(QWidget *parent = 0); -// ~Dialpad(); - -private: - void fillButtons(); - private slots: - void on_pushButton_1_clicked(); - void on_pushButton_2_clicked(); - void on_pushButton_3_clicked(); - void on_pushButton_4_clicked(); - void on_pushButton_5_clicked(); - void on_pushButton_6_clicked(); - void on_pushButton_7_clicked(); - void on_pushButton_8_clicked(); - void on_pushButton_9_clicked(); - void on_pushButton_0_clicked(); - void on_pushButton_diese_clicked(); - void on_pushButton_etoile_clicked(); + void clicked(QString& text); signals: - /** - * This signal is emitted when the user types a button of the dialpad. - * @param text the text of the button typed by the user. - */ void typed(QString text); }; -#endif +#endif \ No newline at end of file -- GitLab