Skip to content
Snippets Groups Projects
Commit da6e0b01 authored by Emmanuel Lepage's avatar Emmanuel Lepage
Browse files

[ #7874 ] Twice less lines, same result

parent 8a87398c
No related branches found
No related tags found
No related merge requests found
...@@ -17,122 +17,50 @@ ...@@ -17,122 +17,50 @@
* along with this program; if not, write to the * * along with this program; if not, write to the *
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ **************************************************************************/
//Parent //Parent
#include "Dialpad.h" #include "Dialpad.h"
//Qt //Qt
#include <QtCore/QDebug>
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QPushButton>
#include <QtGui/QGridLayout> #include <QtGui/QGridLayout>
///Constructor const char* Dialpad::m_pNumbers[] =
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", {"1", "2", "3",
"4", "5", "6", "4", "5", "6",
"7", "8", "9", "7", "8", "9",
"*", "0", "#"}; "*", "0", "#"};
QString texts[12] = const char* Dialpad::m_pTexts[12] =
{ "" , "abc", "def" , { "" , "abc", "def" ,
"ghi" , "jkl", "mno" , "ghi" , "jkl", "mno" ,
"pqrs", "tuv", "wxyz", "pqrs", "tuv", "wxyz",
"" , "" , "" }; "" , "" , "" };
for(int i = 0 ; i < 12 ; i++) { ///Constructor
layout = new QHBoxLayout(); Dialpad::Dialpad(QWidget *parent)
layout->setSpacing(spacing); : QWidget(parent),gridLayout(new QGridLayout(this)),m_pButtons(new DialpadButton*[12])
number = new QLabel(numbers[i]); {
number->setFont(QFont("", numberSize)); 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); layout->addWidget(number);
number->setAlignment(Qt::AlignRight | Qt::AlignVCenter); number->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
text = new QLabel(texts[i]); QLabel* text = new QLabel(m_pTexts[i]);
text->setFont(QFont("", textSize)); text->setFont(QFont("", m_TextSize));
layout->addWidget(text); layout->addWidget(text);
buttons[i]->setLayout(layout); m_pButtons[i]->setMinimumHeight(30);
buttons[i]->setMinimumHeight(30); connect(m_pButtons[i],SIGNAL(typed(QString&)),this,SLOT(clicked(QString&)));
buttons[i]->setText("");
} }
} }
///Slots ///Proxy to make the view more convinient to use
void Dialpad::on_pushButton_1_clicked() { emit typed("1"); } void Dialpad::clicked(QString& text)
void Dialpad::on_pushButton_2_clicked() { emit typed("2"); } {
void Dialpad::on_pushButton_3_clicked() { emit typed("3"); } emit typed(text);
void Dialpad::on_pushButton_4_clicked() { emit typed("4"); } }
void Dialpad::on_pushButton_5_clicked() { emit typed("5"); } \ No newline at end of file
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("*"); }
...@@ -22,11 +22,27 @@ ...@@ -22,11 +22,27 @@
#define DIALPAD_H #define DIALPAD_H
#include <QWidget> #include <QWidget>
#include <QPushButton>
//Qt //Qt
class QPushButton;
class QGridLayout; 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 A widget that representing a phone dialpad with associated numbers and letters
class Dialpad : public QWidget class Dialpad : public QWidget
...@@ -36,46 +52,21 @@ Q_OBJECT ...@@ -36,46 +52,21 @@ Q_OBJECT
private: private:
//Attributes //Attributes
QGridLayout* gridLayout; QGridLayout* gridLayout;
QPushButton* pushButton_0; DialpadButton** m_pButtons;
QPushButton* pushButton_1;
QPushButton* pushButton_2; static const char* m_pNumbers[];
QPushButton* pushButton_3; static const char* m_pTexts [];
QPushButton* pushButton_4; static const int m_Spacing = 5 ;
QPushButton* pushButton_5; static const int m_NumberSize = 14 ;
QPushButton* pushButton_6; static const int m_TextSize = 8 ;
QPushButton* pushButton_7;
QPushButton* pushButton_8;
QPushButton* pushButton_9;
QPushButton* pushButton_diese;
QPushButton* pushButton_etoile;
public: public:
Dialpad(QWidget *parent = 0); Dialpad(QWidget *parent = 0);
// ~Dialpad();
private:
void fillButtons();
private slots: private slots:
void on_pushButton_1_clicked(); void clicked(QString& text);
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();
signals: 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); void typed(QString text);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment