• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kaddressbook

  • sources
  • kde-4.12
  • kdepim
  • kaddressbook
  • printing
stylepage.cpp
Go to the documentation of this file.
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 along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  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 Qt, and distribute the resulting executable,
22  without including the source code for Qt in the source distribution.
23 */
24 
25 #include "stylepage.h"
26 
27 #include <QGridLayout>
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QPixmap>
31 #include <QVBoxLayout>
32 
33 #include <KComboBox>
34 #include <KDialog>
35 #include <KLocale>
36 
37 // helper method to sort contact fields by field label
38 static bool contactFieldsNameLesser( const ContactFields::Field &field,
39  const ContactFields::Field &otherField )
40 {
41  return ( QString::localeAwareCompare( ContactFields::label( field ),
42  ContactFields::label( otherField ) ) < 0 );
43 }
44 
45 StylePage::StylePage( QWidget *parent, const char *name )
46  : QWidget( parent )
47 {
48  setObjectName( QLatin1String(name) );
49  initGUI();
50 
51  initFieldCombo();
52 
53  mSortTypeCombo->addItem( i18nc( "@item:inlistbox Ascending sort order", "Ascending" ) );
54  mSortTypeCombo->addItem( i18nc( "@item:inlistbox Descending sort order", "Descending" ) );
55 
56  connect( mStyleCombo, SIGNAL(activated(int)), SIGNAL(styleChanged(int)) );
57 }
58 
59 StylePage::~StylePage()
60 {
61 }
62 
63 void StylePage::setPreview( const QPixmap &pixmap )
64 {
65  if ( pixmap.isNull() ) {
66  mPreview->setText( i18nc( "@label", "(No preview available.)" ) );
67  } else {
68  mPreview->setPixmap( pixmap );
69  }
70 }
71 
72 void StylePage::addStyleName( const QString &name )
73 {
74  mStyleCombo->addItem( name );
75 }
76 
77 void StylePage::clearStyleNames()
78 {
79  mStyleCombo->clear();
80 }
81 
82 void StylePage::setSortField( ContactFields::Field field )
83 {
84  mFieldCombo->setCurrentIndex( mFields.indexOf( field ) );
85 }
86 
87 void StylePage::setSortOrder( Qt::SortOrder sortOrder )
88 {
89  if ( sortOrder == Qt::AscendingOrder ) {
90  mSortTypeCombo->setCurrentIndex( 0 );
91  } else {
92  mSortTypeCombo->setCurrentIndex( 1 );
93  }
94 }
95 
96 ContactFields::Field StylePage::sortField() const
97 {
98  if ( mFieldCombo->currentIndex() == -1 ) {
99  return ContactFields::GivenName;
100  }
101 
102  return mFields[ mFieldCombo->currentIndex() ];
103 }
104 
105 Qt::SortOrder StylePage::sortOrder() const
106 {
107  return ( mSortTypeCombo->currentIndex() == 0 ? Qt::AscendingOrder : Qt::DescendingOrder );
108 }
109 
110 void StylePage::initFieldCombo()
111 {
112  mFieldCombo->clear();
113 
114  mFields = ContactFields::allFields();
115  mFields.remove( 0 ); // remove ContactFields::Undefined
116 
117  qSort( mFields.begin(), mFields.end(), contactFieldsNameLesser );
118 
119  ContactFields::Fields::ConstIterator it;
120  ContactFields::Fields::ConstIterator end(mFields.constEnd());
121  for ( it = mFields.constBegin(); it != end; ++it ) {
122  mFieldCombo->addItem( ContactFields::label( *it ) );
123  }
124 }
125 
126 void StylePage::initGUI()
127 {
128  setWindowTitle( i18nc( "@title:window", "Choose Printing Style" ) );
129 
130  QGridLayout *topLayout = new QGridLayout( this );
131  topLayout->setSpacing( KDialog::spacingHint() );
132  topLayout->setMargin( KDialog::marginHint() );
133 
134  QLabel *label =
135  new QLabel(
136  i18nc( "@label:textbox",
137  "What should the print look like?\n"
138  "KAddressBook has several printing styles, designed for different purposes.\n"
139  "Choose the style that suits your needs below." ), this );
140  topLayout->addWidget( label, 0, 0, 1, 2 );
141 
142  QGroupBox *group = new QGroupBox( i18nc( "@title:group", "Sorting" ), this );
143  QGridLayout *sortLayout = new QGridLayout();
144  group->setLayout( sortLayout );
145  sortLayout->setSpacing( KDialog::spacingHint() );
146  sortLayout->setMargin( KDialog::marginHint() );
147  sortLayout->setAlignment( Qt::AlignTop );
148 
149  label = new QLabel( i18nc( "@label:listbox", "Criterion:" ), group );
150  sortLayout->addWidget( label, 0, 0 );
151 
152  mFieldCombo = new KComboBox( false, group );
153  mFieldCombo->setToolTip(
154  i18nc( "@info:tooltip", "Select the primary sort field" ) );
155  mFieldCombo->setWhatsThis(
156  i18nc( "@info:whatsthis",
157  "From this list you can select the field on which your contacts are sorted "
158  "in the print output. Use the sorting order option to determine if the "
159  "sort will be in ascending or descending order." ) );
160  sortLayout->addWidget( mFieldCombo, 0, 1 );
161 
162  label = new QLabel( i18nc( "@label:listbox", "Order:" ), group );
163  sortLayout->addWidget( label, 1, 0 );
164 
165  mSortTypeCombo = new KComboBox( false, group );
166  mSortTypeCombo->setToolTip(
167  i18nc( "@info:tooltip", "Select the sorting order" ) );
168  mSortTypeCombo->setWhatsThis(
169  i18nc( "@info:whatsthis",
170  "Choose if you want to sort your contacts in ascending or descending order. "
171  "Use the sorting criterion option to specify on which contact field the sorting "
172  "will be performed." ) );
173  sortLayout->addWidget( mSortTypeCombo, 1, 1 );
174 
175  topLayout->addWidget( group, 1, 0 );
176 
177  group = new QGroupBox( i18nc( "@title:group", "Print Style" ), this );
178  QVBoxLayout *styleLayout = new QVBoxLayout();
179  group->setLayout( styleLayout );
180  styleLayout->setSpacing( KDialog::spacingHint() );
181  styleLayout->setMargin( KDialog::marginHint() );
182 
183  mStyleCombo = new KComboBox( false, group );
184  mStyleCombo->setToolTip(
185  i18nc( "@info:tooltip", "Select the print style" ) );
186  mStyleCombo->setWhatsThis(
187  i18nc( "@info:whatsthis",
188  "Choose your desired printing style. See the preview image to help you decide." ) );
189 
190  styleLayout->addWidget( mStyleCombo );
191 
192  mPreview = new QLabel( group );
193  QFont font( mPreview->font() );
194  font.setPointSize( 20 );
195  mPreview->setFont( font );
196  mPreview->setScaledContents( true );
197  mPreview->setAlignment( Qt::AlignCenter );
198  mPreview->setWordWrap( true );
199  styleLayout->addWidget( mPreview );
200 
201  topLayout->addWidget( group, 1, 1 );
202  topLayout->setRowStretch( 1, 1 );
203 }
204 
205 int StylePage::printingStyle() const
206 {
207  return mStyleCombo->currentIndex();
208 }
209 
210 void StylePage::setPrintingStyle( int index )
211 {
212  mStyleCombo->setCurrentIndex( index );
213 }
214 
215 #include "stylepage.moc"
StylePage::setPrintingStyle
void setPrintingStyle(int index)
Returns the sort order.
Definition: stylepage.cpp:210
StylePage::StylePage
StylePage(QWidget *parent=0, const char *name=0)
Definition: stylepage.cpp:45
StylePage::setPreview
void setPreview(const QPixmap &pixmap)
Set a preview image.
Definition: stylepage.cpp:63
StylePage::printingStyle
int printingStyle() const
Returns the sort order.
Definition: stylepage.cpp:205
StylePage::styleChanged
void styleChanged(int index)
This signal is emmited when the user selects a new style in the style combo box.
StylePage::~StylePage
~StylePage()
Definition: stylepage.cpp:59
stylepage.h
contactFieldsNameLesser
static bool contactFieldsNameLesser(const ContactFields::Field &field, const ContactFields::Field &otherField)
Definition: stylepage.cpp:38
ContactFields::label
static QString label(Field field)
Returns the i18n label for the field.
Definition: contactfields.cpp:25
StylePage::setSortOrder
void setSortOrder(Qt::SortOrder sortOrder)
Sets the sort order.
Definition: stylepage.cpp:87
StylePage::addStyleName
void addStyleName(const QString &name)
Add a style name.
Definition: stylepage.cpp:72
StylePage::setSortField
void setSortField(ContactFields::Field field)
Set the sort criterion field.
Definition: stylepage.cpp:82
StylePage::clearStyleNames
void clearStyleNames()
Clear the style name list.
Definition: stylepage.cpp:77
StylePage::sortField
ContactFields::Field sortField() const
Returns the sort criterion field.
Definition: stylepage.cpp:96
StylePage::sortOrder
Qt::SortOrder sortOrder() const
Returns the sort order.
Definition: stylepage.cpp:105
ContactFields::Field
Field
Describes the standard fields that are available for every contact.
Definition: contactfields.h:33
ContactFields::GivenName
Definition: contactfields.h:38
ContactFields::allFields
static Fields allFields()
Returns a list of all available fields.
Definition: contactfields.cpp:177
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal