kaddressbook

stylepage.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
4  Tobias Koenig <tokoe@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqbuttongroup.h>
26 #include <tqlabel.h>
27 #include <tqlayout.h>
28 #include <tqpixmap.h>
29 #include <tqradiobutton.h>
30 
31 #include <kcombobox.h>
32 #include <kdialog.h>
33 #include <tdelocale.h>
34 
35 #include "stylepage.h"
36 
37 StylePage::StylePage( TDEABC::AddressBook *ab, TQWidget* parent, const char* name )
38  : TQWidget( parent, name ), mAddressBook( ab )
39 {
40  initGUI();
41 
42  initFieldCombo();
43 
44  mSortTypeCombo->insertItem( i18n( "Ascending" ) );
45  mSortTypeCombo->insertItem( i18n( "Descending" ) );
46 
47  connect( mStyleCombo, TQ_SIGNAL( activated( int ) ), TQ_SIGNAL( styleChanged( int ) ) );
48 }
49 
50 StylePage::~StylePage()
51 {
52 }
53 
54 void StylePage::setPreview( const TQPixmap &pixmap )
55 {
56  if ( pixmap.isNull() )
57  mPreview->setText( i18n( "(No preview available.)" ) );
58  else
59  mPreview->setPixmap( pixmap );
60 }
61 
62 void StylePage::addStyleName( const TQString &name )
63 {
64  mStyleCombo->insertItem( name );
65 }
66 
67 void StylePage::clearStyleNames()
68 {
69  mStyleCombo->clear();
70 }
71 
72 void StylePage::setSortField( TDEABC::Field *field )
73 {
74  mFieldCombo->setCurrentText( field->label() );
75 }
76 
77 void StylePage::setSortAscending( bool value )
78 {
79  if ( value )
80  mSortTypeCombo->setCurrentItem( 0 );
81  else
82  mSortTypeCombo->setCurrentItem( 1 );
83 }
84 
85 TDEABC::Field* StylePage::sortField()
86 {
87  if ( mFieldCombo->currentItem() == -1 )
88  return mFields[ 0 ];
89 
90  return mFields[ mFieldCombo->currentItem() ];
91 }
92 
93 bool StylePage::sortAscending()
94 {
95  return ( mSortTypeCombo->currentItem() == 0 );
96 }
97 
98 void StylePage::initFieldCombo()
99 {
100  if ( !mAddressBook )
101  return;
102 
103  mFieldCombo->clear();
104 
105  mFields = mAddressBook->fields( TDEABC::Field::All );
106  TDEABC::Field::List::ConstIterator it;
107  for ( it = mFields.begin(); it != mFields.end(); ++it )
108  mFieldCombo->insertItem( (*it)->label() );
109 }
110 
111 void StylePage::initGUI()
112 {
113  setCaption( i18n( "Choose Printing Style" ) );
114 
115  TQGridLayout *topLayout = new TQGridLayout( this, 2, 2, KDialog::marginHint(),
116  KDialog::spacingHint() );
117 
118  TQLabel *label = new TQLabel( i18n( "What should the print look like?\n"
119  "KAddressBook has several printing styles, designed for different purposes.\n"
120  "Choose the style that suits your needs below." ), this );
121  topLayout->addMultiCellWidget( label, 0, 0, 0, 1 );
122 
123  TQButtonGroup *group = new TQButtonGroup( i18n( "Sorting" ), this );
124  group->setColumnLayout( 0, TQt::Vertical );
125  TQGridLayout *sortLayout = new TQGridLayout( group->layout(), 2, 2,
126  KDialog::spacingHint() );
127  sortLayout->setAlignment( TQt::AlignTop );
128 
129  label = new TQLabel( i18n( "Criterion:" ), group );
130  sortLayout->addWidget( label, 0, 0 );
131 
132  mFieldCombo = new KComboBox( false, group );
133  sortLayout->addWidget( mFieldCombo, 0, 1 );
134 
135  label = new TQLabel( i18n( "Order:" ), group );
136  sortLayout->addWidget( label, 1, 0 );
137 
138  mSortTypeCombo = new KComboBox( false, group );
139  sortLayout->addWidget( mSortTypeCombo, 1, 1 );
140 
141  topLayout->addWidget( group, 1, 0 );
142 
143  group = new TQButtonGroup( i18n( "Print Style" ), this );
144  group->setColumnLayout( 0, TQt::Vertical );
145  TQVBoxLayout *styleLayout = new TQVBoxLayout( group->layout(),
146  KDialog::spacingHint() );
147 
148  mStyleCombo = new KComboBox( false, group );
149  styleLayout->addWidget( mStyleCombo );
150 
151  mPreview = new TQLabel( group );
152  TQFont font( mPreview->font() );
153  font.setPointSize( 20 );
154  mPreview->setFont( font );
155  mPreview->setScaledContents( true );
156  mPreview->setAlignment( int( TQLabel::WordBreak | TQLabel::AlignCenter ) );
157  styleLayout->addWidget( mPreview );
158 
159  topLayout->addWidget( group, 1, 1 );
160 }
161 
162 #include "stylepage.moc"