kaddressbook

printstyle.cpp
1 /*
2  This file is part of KAddressBook.
3  Copyright (c) 1996-2002 Mirko Boehm <mirko@kde.org>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19  As a special exception, permission is given to link this program
20  with any edition of TQt, and distribute the resulting executable,
21  without including the source code for TQt in the source distribution.
22 */
23 
24 #include <kstandarddirs.h>
25 #include <kdebug.h>
26 
27 #include <tqwidget.h>
28 
29 #include "printstyle.h"
30 #include "printingwizard.h"
31 
32 using namespace KABPrinting;
33 
34 
35 PrintStyle::PrintStyle( PrintingWizard* parent, const char* name )
36  : TQObject( parent, name ), mWizard( parent ), mSortField( 0 )
37 {
38 }
39 
40 PrintStyle::~PrintStyle()
41 {
42 }
43 
44 const TQPixmap& PrintStyle::preview()
45 {
46  return mPreview;
47 }
48 
49 void PrintStyle::setPreview( const TQPixmap& image )
50 {
51  mPreview = image;
52 }
53 
54 bool PrintStyle::setPreview( const TQString& fileName )
55 {
56  TQPixmap preview;
57  TQString path = locate( "appdata", "printing/" + fileName );
58  if ( path.isEmpty() ) {
59  kdDebug(5720) << "PrintStyle::setPreview: preview not locatable." << endl;
60  return false;
61  } else {
62  if ( preview.load( path ) ) {
63  setPreview( preview );
64  return true;
65  } else {
66  kdDebug(5720) << "PrintStyle::setPreview: preview at '" << path << "' cannot be loaded." << endl;
67  return false;
68  }
69  }
70 }
71 
73 {
74  return mWizard;
75 }
76 
77 void PrintStyle::addPage( TQWidget *page, const TQString &title )
78 {
79  if ( mPageList.find( page ) == -1 ) { // not yet in the list
80  mPageList.append( page );
81  mPageTitles.append( title );
82  }
83 }
84 
86 {
87  TQWidget *wdg = 0;
88  int i = 0;
89  for ( wdg = mPageList.first(); wdg; wdg = mPageList.next(), ++i ) {
90  mWizard->addPage( wdg, mPageTitles[ i ] );
91  if ( i == 0 )
92  mWizard->setAppropriate( wdg, true );
93  }
94 
95  if ( wdg )
96  mWizard->setFinishEnabled( wdg, true );
97 }
98 
100 {
101  for ( TQWidget *wdg = mPageList.first(); wdg; wdg = mPageList.next() )
102  mWizard->removePage( wdg );
103 }
104 
105 void PrintStyle::setPreferredSortOptions( TDEABC::Field *field, bool ascending )
106 {
107  mSortField = field;
108  mSortType = ascending;
109 }
110 
112 {
113  return mSortField;
114 }
115 
117 {
118  return mSortType;
119 }
120 
121 PrintStyleFactory::PrintStyleFactory( PrintingWizard* parent, const char* name )
122  : mParent( parent ), mName( name )
123 {
124 }
125 
126 PrintStyleFactory::~PrintStyleFactory()
127 {
128 }
129 
130 #include "printstyle.moc"