diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-11-08 12:31:36 -0600 |
commit | d796c9dd933ab96ec83b9a634feedd5d32e1ba3f (patch) | |
tree | 6e3dcca4f77e20ec8966c666aac7c35bd4704053 /examples/addressbook | |
download | tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.tar.gz tqt3-d796c9dd933ab96ec83b9a634feedd5d32e1ba3f.zip |
Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731
Diffstat (limited to 'examples/addressbook')
-rw-r--r-- | examples/addressbook/addressbook.doc | 41 | ||||
-rw-r--r-- | examples/addressbook/addressbook.pro | 13 | ||||
-rw-r--r-- | examples/addressbook/centralwidget.cpp | 351 | ||||
-rw-r--r-- | examples/addressbook/centralwidget.h | 59 | ||||
-rw-r--r-- | examples/addressbook/fileopen.xpm | 22 | ||||
-rw-r--r-- | examples/addressbook/fileprint.xpm | 24 | ||||
-rw-r--r-- | examples/addressbook/filesave.xpm | 22 | ||||
-rw-r--r-- | examples/addressbook/main.cpp | 27 | ||||
-rw-r--r-- | examples/addressbook/mainwindow.cpp | 108 | ||||
-rw-r--r-- | examples/addressbook/mainwindow.h | 49 |
10 files changed, 716 insertions, 0 deletions
diff --git a/examples/addressbook/addressbook.doc b/examples/addressbook/addressbook.doc new file mode 100644 index 000000000..3abc3c9ca --- /dev/null +++ b/examples/addressbook/addressbook.doc @@ -0,0 +1,41 @@ +/* +*/ +/*! \page addressbook-example.html + + \ingroup examples + \title Simple Addressbook + + This examples shows how to write a very simple, but complete application + using an addressbook as the example. + + <hr> + + Header file of the mainwindow: + + \include addressbook/mainwindow.h + + <hr> + + Implementation of the mainwindow: + + \include addressbook/mainwindow.cpp + + <hr> + + Header file of the centralwidget: + + \include addressbook/centralwidget.h + + <hr> + + Implementation of the centralwidget: + + \include addressbook/centralwidget.cpp + + <hr> + + Main: + + \include addressbook/main.cpp +*/ + diff --git a/examples/addressbook/addressbook.pro b/examples/addressbook/addressbook.pro new file mode 100644 index 000000000..f15ad9a1c --- /dev/null +++ b/examples/addressbook/addressbook.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = addressbook + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = full-config + +HEADERS = centralwidget.h \ + mainwindow.h +SOURCES = centralwidget.cpp \ + main.cpp \ + mainwindow.cpp diff --git a/examples/addressbook/centralwidget.cpp b/examples/addressbook/centralwidget.cpp new file mode 100644 index 000000000..86edc9c52 --- /dev/null +++ b/examples/addressbook/centralwidget.cpp @@ -0,0 +1,351 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "centralwidget.h" + +#include <qtabwidget.h> +#include <qlistview.h> +#include <qlayout.h> +#include <qwidget.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qlineedit.h> +#include <qlabel.h> +#include <qcheckbox.h> +#include <qfile.h> +#include <qtextstream.h> + +ABCentralWidget::ABCentralWidget( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ + mainGrid = new TQGridLayout( this, 2, 1, 5, 5 ); + + setupTabWidget(); + setupListView(); + + mainGrid->setRowStretch( 0, 0 ); + mainGrid->setRowStretch( 1, 1 ); +} + +void ABCentralWidget::save( const TQString &filename ) +{ + if ( !listView->firstChild() ) + return; + + TQFile f( filename ); + if ( !f.open( IO_WriteOnly ) ) + return; + + TQTextStream t( &f ); + t.setEncoding(TQTextStream::UnicodeUTF8); + + TQListViewItemIterator it( listView ); + + for ( ; it.current(); ++it ) + for ( unsigned int i = 0; i < 4; i++ ) + t << it.current()->text( i ) << "\n"; + + f.close(); +} + +void ABCentralWidget::load( const TQString &filename ) +{ + listView->clear(); + + TQFile f( filename ); + if ( !f.open( IO_ReadOnly ) ) + return; + + TQTextStream t( &f ); + t.setEncoding(TQTextStream::UnicodeUTF8); + + while ( !t.atEnd() ) { + TQListViewItem *item = new TQListViewItem( listView ); + for ( unsigned int i = 0; i < 4; i++ ) + item->setText( i, t.readLine() ); + } + + f.close(); +} + +void ABCentralWidget::setupTabWidget() +{ + tabWidget = new TQTabWidget( this ); + + TQWidget *input = new TQWidget( tabWidget ); + TQGridLayout *grid1 = new TQGridLayout( input, 2, 5, 5, 5 ); + + TQLabel *liFirstName = new TQLabel( "First &Name", input ); + liFirstName->resize( liFirstName->sizeHint() ); + grid1->addWidget( liFirstName, 0, 0 ); + + TQLabel *liLastName = new TQLabel( "&Last Name", input ); + liLastName->resize( liLastName->sizeHint() ); + grid1->addWidget( liLastName, 0, 1 ); + + TQLabel *liAddress = new TQLabel( "Add&ress", input ); + liAddress->resize( liAddress->sizeHint() ); + grid1->addWidget( liAddress, 0, 2 ); + + TQLabel *liEMail = new TQLabel( "&E-Mail", input ); + liEMail->resize( liEMail->sizeHint() ); + grid1->addWidget( liEMail, 0, 3 ); + + add = new TQPushButton( "A&dd", input ); + add->resize( add->sizeHint() ); + grid1->addWidget( add, 0, 4 ); + connect( add, SIGNAL( clicked() ), this, SLOT( addEntry() ) ); + + iFirstName = new TQLineEdit( input ); + iFirstName->resize( iFirstName->sizeHint() ); + grid1->addWidget( iFirstName, 1, 0 ); + liFirstName->setBuddy( iFirstName ); + + iLastName = new TQLineEdit( input ); + iLastName->resize( iLastName->sizeHint() ); + grid1->addWidget( iLastName, 1, 1 ); + liLastName->setBuddy( iLastName ); + + iAddress = new TQLineEdit( input ); + iAddress->resize( iAddress->sizeHint() ); + grid1->addWidget( iAddress, 1, 2 ); + liAddress->setBuddy( iAddress ); + + iEMail = new TQLineEdit( input ); + iEMail->resize( iEMail->sizeHint() ); + grid1->addWidget( iEMail, 1, 3 ); + liEMail->setBuddy( iEMail ); + + change = new TQPushButton( "&Change", input ); + change->resize( change->sizeHint() ); + grid1->addWidget( change, 1, 4 ); + connect( change, SIGNAL( clicked() ), this, SLOT( changeEntry() ) ); + + tabWidget->addTab( input, "&Add/Change Entry" ); + + // -------------------------------------- + + TQWidget *search = new TQWidget( this ); + TQGridLayout *grid2 = new TQGridLayout( search, 2, 5, 5, 5 ); + + cFirstName = new TQCheckBox( "First &Name", search ); + cFirstName->resize( cFirstName->sizeHint() ); + grid2->addWidget( cFirstName, 0, 0 ); + connect( cFirstName, SIGNAL( clicked() ), this, SLOT( toggleFirstName() ) ); + + cLastName = new TQCheckBox( "&Last Name", search ); + cLastName->resize( cLastName->sizeHint() ); + grid2->addWidget( cLastName, 0, 1 ); + connect( cLastName, SIGNAL( clicked() ), this, SLOT( toggleLastName() ) ); + + cAddress = new TQCheckBox( "Add&ress", search ); + cAddress->resize( cAddress->sizeHint() ); + grid2->addWidget( cAddress, 0, 2 ); + connect( cAddress, SIGNAL( clicked() ), this, SLOT( toggleAddress() ) ); + + cEMail = new TQCheckBox( "&E-Mail", search ); + cEMail->resize( cEMail->sizeHint() ); + grid2->addWidget( cEMail, 0, 3 ); + connect( cEMail, SIGNAL( clicked() ), this, SLOT( toggleEMail() ) ); + + sFirstName = new TQLineEdit( search ); + sFirstName->resize( sFirstName->sizeHint() ); + grid2->addWidget( sFirstName, 1, 0 ); + + sLastName = new TQLineEdit( search ); + sLastName->resize( sLastName->sizeHint() ); + grid2->addWidget( sLastName, 1, 1 ); + + sAddress = new TQLineEdit( search ); + sAddress->resize( sAddress->sizeHint() ); + grid2->addWidget( sAddress, 1, 2 ); + + sEMail = new TQLineEdit( search ); + sEMail->resize( sEMail->sizeHint() ); + grid2->addWidget( sEMail, 1, 3 ); + + find = new TQPushButton( "F&ind", search ); + find->resize( find->sizeHint() ); + grid2->addWidget( find, 1, 4 ); + connect( find, SIGNAL( clicked() ), this, SLOT( findEntries() ) ); + + cFirstName->setChecked( TRUE ); + sFirstName->setEnabled( TRUE ); + sLastName->setEnabled( FALSE ); + sAddress->setEnabled( FALSE ); + sEMail->setEnabled( FALSE ); + + tabWidget->addTab( search, "&Search" ); + + mainGrid->addWidget( tabWidget, 0, 0 ); +} + +void ABCentralWidget::setupListView() +{ + listView = new TQListView( this ); + listView->addColumn( "First Name" ); + listView->addColumn( "Last Name" ); + listView->addColumn( "Address" ); + listView->addColumn( "E-Mail" ); + + listView->setSelectionMode( TQListView::Single ); + + connect( listView, SIGNAL( clicked( TQListViewItem* ) ), this, SLOT( itemSelected( TQListViewItem* ) ) ); + + mainGrid->addWidget( listView, 1, 0 ); + listView->setAllColumnsShowFocus( TRUE ); +} + +void ABCentralWidget::addEntry() +{ + if ( !iFirstName->text().isEmpty() || !iLastName->text().isEmpty() || + !iAddress->text().isEmpty() || !iEMail->text().isEmpty() ) { + TQListViewItem *item = new TQListViewItem( listView ); + item->setText( 0, iFirstName->text() ); + item->setText( 1, iLastName->text() ); + item->setText( 2, iAddress->text() ); + item->setText( 3, iEMail->text() ); + } + + iFirstName->setText( "" ); + iLastName->setText( "" ); + iAddress->setText( "" ); + iEMail->setText( "" ); +} + +void ABCentralWidget::changeEntry() +{ + TQListViewItem *item = listView->currentItem(); + + if ( item && + ( !iFirstName->text().isEmpty() || !iLastName->text().isEmpty() || + !iAddress->text().isEmpty() || !iEMail->text().isEmpty() ) ) { + item->setText( 0, iFirstName->text() ); + item->setText( 1, iLastName->text() ); + item->setText( 2, iAddress->text() ); + item->setText( 3, iEMail->text() ); + } +} + +void ABCentralWidget::selectionChanged() +{ + iFirstName->setText( "" ); + iLastName->setText( "" ); + iAddress->setText( "" ); + iEMail->setText( "" ); +} + +void ABCentralWidget::itemSelected( TQListViewItem *item ) +{ + if ( !item ) + return; + item->setSelected( TRUE ); + item->repaint(); + + iFirstName->setText( item->text( 0 ) ); + iLastName->setText( item->text( 1 ) ); + iAddress->setText( item->text( 2 ) ); + iEMail->setText( item->text( 3 ) ); +} + +void ABCentralWidget::toggleFirstName() +{ + sFirstName->setText( "" ); + + if ( cFirstName->isChecked() ) { + sFirstName->setEnabled( TRUE ); + sFirstName->setFocus(); + } + else + sFirstName->setEnabled( FALSE ); +} + +void ABCentralWidget::toggleLastName() +{ + sLastName->setText( "" ); + + if ( cLastName->isChecked() ) { + sLastName->setEnabled( TRUE ); + sLastName->setFocus(); + } + else + sLastName->setEnabled( FALSE ); +} + +void ABCentralWidget::toggleAddress() +{ + sAddress->setText( "" ); + + if ( cAddress->isChecked() ) { + sAddress->setEnabled( TRUE ); + sAddress->setFocus(); + } + else + sAddress->setEnabled( FALSE ); +} + +void ABCentralWidget::toggleEMail() +{ + sEMail->setText( "" ); + + if ( cEMail->isChecked() ) { + sEMail->setEnabled( TRUE ); + sEMail->setFocus(); + } + else + sEMail->setEnabled( FALSE ); +} + +void ABCentralWidget::findEntries() +{ + if ( !cFirstName->isChecked() && + !cLastName->isChecked() && + !cAddress->isChecked() && + !cEMail->isChecked() ) { + listView->clearSelection(); + return; + } + + TQListViewItemIterator it( listView ); + + for ( ; it.current(); ++it ) { + bool select = TRUE; + + if ( cFirstName->isChecked() ) { + if ( select && it.current()->text( 0 ).contains( sFirstName->text() ) ) + select = TRUE; + else + select = FALSE; + } + if ( cLastName->isChecked() ) { + if ( select && it.current()->text( 1 ).contains( sLastName->text() ) ) + select = TRUE; + else + select = FALSE; + } + if ( cAddress->isChecked() ) { + if ( select && it.current()->text( 2 ).contains( sAddress->text() ) ) + select = TRUE; + else + select = FALSE; + } + if ( cEMail->isChecked() ) { + if ( select && it.current()->text( 3 ).contains( sEMail->text() ) ) + select = TRUE; + else + select = FALSE; + } + + if ( select ) + it.current()->setSelected( TRUE ); + else + it.current()->setSelected( FALSE ); + it.current()->repaint(); + } +} diff --git a/examples/addressbook/centralwidget.h b/examples/addressbook/centralwidget.h new file mode 100644 index 000000000..66e44a332 --- /dev/null +++ b/examples/addressbook/centralwidget.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef AB_CENTRALWIDGET_H +#define AB_CENTRALWIDGET_H + +#include <qwidget.h> +#include <qstring.h> + +class TQTabWidget; +class TQListView; +class TQGridLayout; +class TQLineEdit; +class TQPushButton; +class TQListViewItem; +class TQCheckBox; + +class ABCentralWidget : public TQWidget +{ + Q_OBJECT + +public: + ABCentralWidget( TQWidget *parent, const char *name = 0 ); + + void save( const TQString &filename ); + void load( const TQString &filename ); + +protected slots: + void addEntry(); + void changeEntry(); + void itemSelected( TQListViewItem* ); + void selectionChanged(); + void toggleFirstName(); + void toggleLastName(); + void toggleAddress(); + void toggleEMail(); + void findEntries(); + +protected: + void setupTabWidget(); + void setupListView(); + + TQGridLayout *mainGrid; + TQTabWidget *tabWidget; + TQListView *listView; + TQPushButton *add, *change, *find; + TQLineEdit *iFirstName, *iLastName, *iAddress, *iEMail, + *sFirstName, *sLastName, *sAddress, *sEMail; + TQCheckBox *cFirstName, *cLastName, *cAddress, *cEMail; + +}; + +#endif diff --git a/examples/addressbook/fileopen.xpm b/examples/addressbook/fileopen.xpm new file mode 100644 index 000000000..880417eee --- /dev/null +++ b/examples/addressbook/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/examples/addressbook/fileprint.xpm b/examples/addressbook/fileprint.xpm new file mode 100644 index 000000000..6ada912fa --- /dev/null +++ b/examples/addressbook/fileprint.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static const char *fileprint[] = { +" 16 14 6 1", +". c #000000", +"# c #848284", +"a c #c6c3c6", +"b c #ffff00", +"c c #ffffff", +"d c None", +"ddddd.........dd", +"dddd.cccccccc.dd", +"dddd.c.....c.ddd", +"ddd.cccccccc.ddd", +"ddd.c.....c....d", +"dd.cccccccc.a.a.", +"d..........a.a..", +".aaaaaaaaaa.a.a.", +".............aa.", +".aaaaaa###aa.a.d", +".aaaaaabbbaa...d", +".............a.d", +"d.aaaaaaaaa.a.dd", +"dd...........ddd" +}; diff --git a/examples/addressbook/filesave.xpm b/examples/addressbook/filesave.xpm new file mode 100644 index 000000000..bd6870f47 --- /dev/null +++ b/examples/addressbook/filesave.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *filesave[] = { +" 14 14 4 1", +". c #040404", +"# c #808304", +"a c #bfc2bf", +"b c None", +"..............", +".#.aaaaaaaa.a.", +".#.aaaaaaaa...", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".#.aaaaaaaa.#.", +".##........##.", +".############.", +".##.........#.", +".##......aa.#.", +".##......aa.#.", +".##......aa.#.", +"b............." +}; diff --git a/examples/addressbook/main.cpp b/examples/addressbook/main.cpp new file mode 100644 index 000000000..33b69833e --- /dev/null +++ b/examples/addressbook/main.cpp @@ -0,0 +1,27 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include <qapplication.h> + +#include "mainwindow.h" + +int main( int argc, char ** argv ) +{ + TQApplication a( argc, argv ); + + ABMainWindow *mw = new ABMainWindow(); + mw->setCaption( "TQt Example - Addressbook" ); + a.setMainWidget( mw ); + mw->show(); + + a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( tquit() ) ); + int result = a.exec(); + delete mw; + return result; +} diff --git a/examples/addressbook/mainwindow.cpp b/examples/addressbook/mainwindow.cpp new file mode 100644 index 000000000..e6f705b57 --- /dev/null +++ b/examples/addressbook/mainwindow.cpp @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#include "mainwindow.h" +#include "centralwidget.h" + +#include <qtoolbar.h> +#include <qtoolbutton.h> +#include <qpopupmenu.h> +#include <qmenubar.h> +#include <qstatusbar.h> +#include <qapplication.h> +#include <qfiledialog.h> + +ABMainWindow::ABMainWindow() + : TQMainWindow( 0, "example addressbook application" ), + filename( TQString::null ) +{ + setupMenuBar(); + setupFileTools(); + setupStatusBar(); + setupCentralWidget(); +} + + +ABMainWindow::~ABMainWindow() +{ +} + +void ABMainWindow::setupMenuBar() +{ + TQPopupMenu *file = new TQPopupMenu( this ); + menuBar()->insertItem( "&File", file ); + + file->insertItem( "New", this, SLOT( fileNew() ), CTRL + Key_N ); + file->insertItem( TQPixmap( "fileopen.xpm" ), "Open", this, SLOT( fileOpen() ), CTRL + Key_O ); + file->insertSeparator(); + file->insertItem( TQPixmap( "filesave.xpm" ), "Save", this, SLOT( fileSave() ), CTRL + Key_S ); + file->insertItem( "Save As...", this, SLOT( fileSaveAs() ) ); + file->insertSeparator(); + file->insertItem( TQPixmap( "fileprint.xpm" ), "Print...", this, SLOT( filePrint() ), CTRL + Key_P ); + file->insertSeparator(); + file->insertItem( "Close", this, SLOT( closeWindow() ), CTRL + Key_W ); + file->insertItem( "Quit", qApp, SLOT( tquit() ), CTRL + Key_Q ); +} + +void ABMainWindow::setupFileTools() +{ + //fileTools = new TQToolBar( this, "file operations" ); +} + +void ABMainWindow::setupStatusBar() +{ + //statusBar()->message( "Ready", 2000 ); +} + +void ABMainWindow::setupCentralWidget() +{ + view = new ABCentralWidget( this ); + setCentralWidget( view ); +} + +void ABMainWindow::closeWindow() +{ + close(); +} + +void ABMainWindow::fileNew() +{ +} + +void ABMainWindow::fileOpen() +{ + TQString fn = TQFileDialog::getOpenFileName( TQString::null, TQString::null, this ); + if ( !fn.isEmpty() ) { + filename = fn; + view->load( filename ); + } +} + +void ABMainWindow::fileSave() +{ + if ( filename.isEmpty() ) { + fileSaveAs(); + return; + } + + view->save( filename ); +} + +void ABMainWindow::fileSaveAs() +{ + TQString fn = TQFileDialog::getSaveFileName( TQString::null, TQString::null, this ); + if ( !fn.isEmpty() ) { + filename = fn; + fileSave(); + } +} + +void ABMainWindow::filePrint() +{ +} diff --git a/examples/addressbook/mainwindow.h b/examples/addressbook/mainwindow.h new file mode 100644 index 000000000..e7ae62d8d --- /dev/null +++ b/examples/addressbook/mainwindow.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of an example program for TQt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef AB_MAINWINDOW_H +#define AB_MAINWINDOW_H + +#include <qmainwindow.h> +#include <qstring.h> + +class TQToolBar; +class TQPopupMenu; +class ABCentralWidget; + +class ABMainWindow: public TQMainWindow +{ + Q_OBJECT + +public: + ABMainWindow(); + ~ABMainWindow(); + +protected slots: + void fileNew(); + void fileOpen(); + void fileSave(); + void fileSaveAs(); + void filePrint(); + void closeWindow(); + +protected: + void setupMenuBar(); + void setupFileTools(); + void setupStatusBar(); + void setupCentralWidget(); + + TQToolBar *fileTools; + TQString filename; + ABCentralWidget *view; + +}; + + +#endif |