AlbumShaper  1.0a3
contents.cpp
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 //Systemwide includes
12 #include <qfile.h>
13 #include <qstringlist.h>
14 //Added by qt3to4:
15 #include <Q3TextStream>
16 #include <Q3Frame>
17 
18 //Projectwide includes
19 #include "contents.h"
20 #include "../../config.h"
21 
22 #define LINK_COLOR "#0a92dd"
23 #define CURR_COLOR "#0e3980"
24 
25 //==============================================
26 Contents::Contents( Q3TextStream::Encoding type,
27  QString saveCharSet, Q3MimeSourceFactory* loadingMimeSource,
28  QWidget* parent, const char* name ) : Q3TextBrowser(parent,name)
29 {
30  this->type = type;
31  this->saveCharSet = saveCharSet;
32  this->setMimeSourceFactory( loadingMimeSource );
33 
34  //generate HTML
36  generateHTML(type, saveCharSet);
37  //--
38  //set browser and load contents
39  setHScrollBarMode( Q3ScrollView::AlwaysOff );
40  setVScrollBarMode( Q3ScrollView::AlwaysOff );
41  setFrameStyle( Q3Frame::NoFrame );
42  setSource( filename() );
43 
44  //------
45  //determine optimal size
46  int minH = heightForWidth( 1000 );
47  int w;
48  for(w=1; w<1000; w++)
49  {
50  if(heightForWidth(w) == minH ) break;
51  }
52 
53  optimalSize = QSize( w, heightForWidth(w) );
54  //------
55  //handle anchor clicks
56  connect( this, SIGNAL(anchorClicked(const QString&, const QString&)),
57  this, SLOT(handleAnchorClick(const QString&, const QString&)) );
58  //------
59 }
60 //==============================================
62 {
63  return optimalSize;
64 }
65 //==============================================
66 void Contents::handleAnchorClick(const QString &name, const QString&)
67 {
68  HELP_PAGE nextPage = INVALID;
69 
70  //only handle clicking on anchors with actual names
71  if( name.isNull() ) return;
72  else if(name.compare("WHATS_NEW") == 0)
73  nextPage = WHATS_NEW;
74  else if(name.compare("IMPORTING_AND_ORGANIZING") == 0)
75  nextPage = IMPORTING_AND_ORGANIZING;
76  else if(name.compare("ANNOTATING_ALBUMS") == 0)
77  nextPage = ANNOTATING_ALBUMS;
78  else if(name.compare("FRAMING") == 0)
79  nextPage = FRAMING;
80  else if(name.compare("ENHANCING") == 0)
81  nextPage = ENHANCING;
82  else if(name.compare("PRO_TOOLS") == 0)
83  nextPage = PRO_TOOLS;
84  else if(name.compare("MANIPULATING") == 0)
85  nextPage = MANIPULATING;
86  else if(name.compare("SAVING_AND_LOADING") == 0)
87  nextPage = SAVING_AND_LOADING;
88  else if(name.compare("KEYBOARD_SHORTCUTS") == 0)
89  nextPage = KEYBOARD_SHORTCUTS;
90 
91  if(nextPage != INVALID)
92  {
93  currentPage = nextPage;
95  reload();
96  emit setPage( currentPage );
97  }
98 }
99 //==============================================
101 {
102  return QString("%1/helpContents.html").arg(TEMP_DIR);
103 }
104 //==============================================
105 void Contents::generateHTML(Q3TextStream::Encoding type, QString charSet)
106 {
107  //create/open html file
108  QFile file( filename() );
109  if(file.open(QIODevice::WriteOnly))
110  {
111  //-----
112  Q3TextStream stream;
113  stream.setEncoding( type );
114  stream.setDevice( &file );
115  //-----
116  stream << "<html><head>\n";
117  stream << "<meta http-equiv='Content-Type' content='text/html; charset=" << charSet << "'>\n";
118  stream << "</head><body>\n";
119  stream << "<center><table><tr><td>\n";
120  stream << "<font face='Arial, sans-serif' size='+1'><b>\n";
121  //-----
122  printLink( stream, QString(tr("What's New")), WHATS_NEW, "WHATS_NEW" );
123  //-----
124  stream << "<p>" << tr("Tutorials:") << "\n";
125  //------
126  stream << "<font size='+0'><ul>\n";
127 
128  stream << "<li>\n";
129  printLink( stream, QString(tr("Import & Organize")),
130  IMPORTING_AND_ORGANIZING, "IMPORTING_AND_ORGANIZING" );
131  //------
132  stream << "<li>\n";
133  printLink( stream, QString(tr("Annotating Albums")),
134  ANNOTATING_ALBUMS, "ANNOTATING_ALBUMS" );
135  //------
136  stream << "<li>" << tr("Editing Photos:") << "\n";
137 
138  stream << "<ol>\n";
139  stream << "<li>\n";
140  printLink( stream, QString(tr("Framing")),
141  FRAMING, "FRAMING" );
142 
143  stream << "<li>\n";
144  printLink( stream, QString(tr("Fix it Fast")),
145  ENHANCING, "ENHANCING" );
146 
147  stream << "<li>\n";
148  printLink( stream, QString(tr("Pro Tools")),
149  PRO_TOOLS, "PRO_TOOLS" );
150 
151  stream << "<li>\n";
152  printLink( stream, QString(tr("Manipulations")),
153  MANIPULATING, "MANIPULATING" );
154  stream << "</ol>\n";
155  //------
156  stream << "<li>\n";
157  printLink( stream, QString(tr("Saving & Loading")),
158  SAVING_AND_LOADING, "SAVING_AND_LOADING" );
159  //------
160  stream << "</ul></font>\n";
161  //------
162  printLink( stream, QString(tr("Keyboard Shortcuts")), KEYBOARD_SHORTCUTS, "KEYBOARD_SHORTCUTS" );
163  //------
164  stream << "</b></font>\n";
165  stream << "</td></tr></table></center>\n";
166  stream << "</body></html>\n";
167  file.close();
168  }
169 }
170 //==============================================
171 void Contents::printLink( Q3TextStream& stream, QString text, HELP_PAGE anchor, QString anchorString )
172 {
173  if( currentPage != anchor )
174  {
175  stream << "<font color='" << LINK_COLOR << "'>";
176  stream << "<a name='" << anchorString << "'>";
177  }
178  else
179  {
180  stream << "<font color='" << CURR_COLOR << "'>";
181  }
182 
183  stream << text << "\n";
184 
185  if( currentPage != anchor )
186  {
187  stream << "</a>";
188  }
189  stream << "</font>\n";
190 }
191 //==============================================
QString TEMP_DIR
Definition: config.cpp:23
#define CURR_COLOR
Definition: contents.cpp:23
#define LINK_COLOR
Definition: contents.cpp:22
Q3TextStream::Encoding type
Definition: contents.h:58
QString saveCharSet
Definition: contents.h:59
void setPage(HELP_PAGE page)
void printLink(Q3TextStream &stream, QString text, HELP_PAGE anchor, QString anchorString)
Definition: contents.cpp:171
QSize optimalSize
Definition: contents.h:52
HELP_PAGE
Contents window widget.
Definition: contents.h:24
QSize minimumSizeHint() const
Definition: contents.cpp:61
void generateHTML(Q3TextStream::Encoding type, QString charSet)
Definition: contents.cpp:105
void handleAnchorClick(const QString &name, const QString &link)
Definition: contents.cpp:66
HELP_PAGE currentPage
Definition: contents.h:56
QString filename()
Definition: contents.cpp:100
Contents(Q3TextStream::Encoding type, QString saveCharSet, Q3MimeSourceFactory *loadingMimeSource, QWidget *parent=0, const char *name=0)
Definition: contents.cpp:26