source: trunk/examples/tutorials/addressbook-fr/part5/addressbook.cpp@ 168

Last change on this file since 168 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43#include "addressbook.h"
44
45AddressBook::AddressBook(QWidget *parent)
46 : QWidget(parent)
47{
48 QLabel *nameLabel = new QLabel(tr("Name:"));
49 nameLine = new QLineEdit;
50 nameLine->setReadOnly(true);
51
52 QLabel *addressLabel = new QLabel(tr("Address:"));
53 addressText = new QTextEdit;
54 addressText->setReadOnly(true);
55
56 addButton = new QPushButton(tr("&Add"));
57
58 editButton = new QPushButton(tr("&Edit"));
59 editButton->setEnabled(false);
60 removeButton = new QPushButton(tr("&Remove"));
61 removeButton->setEnabled(false);
62//! [instantiating findButton]
63 findButton = new QPushButton(tr("&Find"));
64 findButton->setEnabled(false);
65//! [instantiating findButton]
66 submitButton = new QPushButton(tr("&Submit"));
67 submitButton->hide();
68 cancelButton = new QPushButton(tr("&Cancel"));
69 cancelButton->hide();
70
71 nextButton = new QPushButton(tr("&Next"));
72 nextButton->setEnabled(false);
73 previousButton = new QPushButton(tr("&Previous"));
74 previousButton->setEnabled(false);
75
76//! [instantiating FindDialog]
77 dialog = new FindDialog;
78//! [instantiating FindDialog]
79
80 connect(addButton, SIGNAL(clicked()), this, SLOT(addContact()));
81 connect(submitButton, SIGNAL(clicked()), this, SLOT(submitContact()));
82 connect(editButton, SIGNAL(clicked()), this, SLOT(editContact()));
83 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
84 connect(removeButton, SIGNAL(clicked()), this, SLOT(removeContact()));
85//! [signals and slots for find]
86 connect(findButton, SIGNAL(clicked()), this, SLOT(findContact()));
87//! [signals and slots for find]
88 connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));
89 connect(previousButton, SIGNAL(clicked()), this, SLOT(previous()));
90
91 QVBoxLayout *buttonLayout1 = new QVBoxLayout;
92 buttonLayout1->addWidget(addButton);
93 buttonLayout1->addWidget(editButton);
94 buttonLayout1->addWidget(removeButton);
95//! [adding findButton to layout]
96 buttonLayout1->addWidget(findButton);
97//! [adding findButton to layout]
98 buttonLayout1->addWidget(submitButton);
99 buttonLayout1->addWidget(cancelButton);
100 buttonLayout1->addStretch();
101
102 QHBoxLayout *buttonLayout2 = new QHBoxLayout;
103 buttonLayout2->addWidget(previousButton);
104 buttonLayout2->addWidget(nextButton);
105
106 QGridLayout *mainLayout = new QGridLayout;
107 mainLayout->addWidget(nameLabel, 0, 0);
108 mainLayout->addWidget(nameLine, 0, 1);
109 mainLayout->addWidget(addressLabel, 1, 0, Qt::AlignTop);
110 mainLayout->addWidget(addressText, 1, 1);
111 mainLayout->addLayout(buttonLayout1, 1, 2);
112 mainLayout->addLayout(buttonLayout2, 2, 1);
113
114 setLayout(mainLayout);
115 setWindowTitle(tr("Simple Address Book"));
116}
117
118void AddressBook::addContact()
119{
120 oldName = nameLine->text();
121 oldAddress = addressText->toPlainText();
122
123 nameLine->clear();
124 addressText->clear();
125
126 updateInterface(AddingMode);