| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/qt/ui/help.ui.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraView - visualization and exploration of geographical databases
    00003 using TerraLib.
    00004 Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
    00005 This file is part of TerraView. TerraView is free software; you can redistribute it
    00006 and/or modify it under the terms of the GNU General Public License as published by
    00007 the Free Software Foundation; either version 2 of the License, or
    00008 (at your option) any later version.
    00009
    00010 You should have received a copy of the GNU General Public License
    00011 along with TerraView.
    00012 The authors reassure the license terms regarding the warranties.
    00013 They specifically disclaim any warranties, including, but not limited to,
    00014 the implied warranties of merchantability and fitness for a particular purpose.
    00015 The software provided hereunder is on an "as is" basis, and the authors have no
    00016 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00017 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00018 indirect, special, incidental, or consequential damages arising out of the use of
    00019 this program and its documentation.
    00020 *************************************************************************************/
    00021
    00022 #include <qdir.h>
    00023 #include <TeWaitCursor.h>
    00024 #include <qprinter.h>
    00025 #include <qpainter.h>
    00026 #include <qpaintdevicemetrics.h>
    00027 #include <qsimplerichtext.h>
    00028 #include <qmessagebox.h>
    00029 #include <qapplication.h>
    00030 #include <qtextcodec.h>
    00031
    00032 void Help::init( QString helpFile )
    00033 {
    00034            std::string                      strLocale;
    00035            std::string                      strPath;
    00036
    00037            erro_ = false;
    00038            QDir dir;
    00039
    00040            strLocale=QTextCodec::locale();
    00041            if(strLocale.find("br") != std::string::npos)                                strPath="pt_br";
    00042            else if(strLocale.find("pt") != std::string::npos)                strPath="pt_br";
    00043            else if(strLocale.find("es") != std::string::npos)                strPath="es";
    00044            else if(strLocale.find("en") != std::string::npos)                strPath="en_us";
    00045
    00046            QString absFile = qApp->applicationDirPath() + "/doc/" + strPath.c_str() + "/";
    00047            absFile += helpFile;
    00048            std::string path = absFile.latin1();
    00049            QFileInfo info(absFile);
    00050            bool exist = info.exists();
    00051            bool isReadable = info.isReadable();
    00052            if(exist==false || isReadable==false)
    00053            {
    00054                       if(dir.cdUp())
    00055                       {
    00056                                  if(dir.cdUp())
    00057                                  {
    00058                                             absFile = dir.absPath() + "/doc/" + strPath.c_str() + "/";
    00059                                             absFile += helpFile;
    00060                                             std::string path = absFile.latin1();
    00061                                             QFileInfo info(absFile);
    00062                                             exist = info.exists();
    00063                                             isReadable = info.isReadable();
    00064                                             if(exist==false || isReadable==false)
    00065                                                        erro_ = true;;
    00066                                  }
    00067                                  else
    00068                                             erro_ = true;;
    00069                       }
    00070                       else
    00071                                  erro_ = true;;
    00072            }
    00073
    00074            if(erro_)
    00075            {
    00076                       QMessageBox::information(this, this->caption(), tr("The help of this interface is not available yet!"));
    00077                       return;
    00078            }
    00079
    00080     connect(homePushButton, SIGNAL(clicked()), textBrowser, SLOT(home()));
    00081     connect(backwardPushButton, SIGNAL(clicked()), this, SLOT(backward()));
    00082     connect(forwardPushButton, SIGNAL(clicked()), this, SLOT(forward()));
    00083     connect(textBrowser, SIGNAL(linkClicked(const QString&)), this, SLOT(linkClicked(const QString&)));
    00084     connect(textBrowser, SIGNAL(anchorClicked(const QString&, const QString&)), this, SLOT(anchorClicked(const QString&, const QString&)));
    00085
    00086            textBrowser->setSource(absFile);
    00087            erro_ = false;
    00088 }
    00089
    00090
    00091 void Help::reject()
    00092 {
    00093            hide();
    00094 }
    00095
    00096
    00097 void Help::printPushButton_clicked()
    00098 {
    00099     QPrinter printer( QPrinter::HighResolution );
    00100     printer.setFullPage(true);
    00101     printer.setOptionEnabled(QPrinter::PrintSelection, false);
    00102     printer.setOptionEnabled(QPrinter::PrintPageRange, false);
    00103
    00104     if ( printer.setup( this ) )
    00105            {
    00106         QPainter p( &printer );
    00107         if( !p.isActive() ) // starting printing failed
    00108             return;
    00109         QPaintDeviceMetrics metrics(p.device());
    00110         int dpiy = metrics.logicalDpiY();
    00111         int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
    00112         QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
    00113         QSimpleRichText richText( textBrowser->text(),
    00114                                   textBrowser->font(),
    00115                                   textBrowser->context(),
    00116                                   textBrowser->styleSheet(),
    00117                                   textBrowser->mimeSourceFactory(),
    00118                                   body.height() );
    00119         richText.setWidth( &p, body.width() );
    00120         QRect view( body );
    00121
    00122                       int page = 1;
    00123                       do
    00124                       {
    00125                                  richText.draw( &p, body.left(), body.top(), view, colorGroup() );
    00126                                  view.moveBy( 0, body.height() );
    00127                                  p.translate( 0 , -body.height() );
    00128                                  p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
    00129                                                                   view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
    00130                                  if ( view.top()  >= richText.height() )
    00131                                             break;
    00132                                  printer.newPage();
    00133                                  page++;
    00134                       } while (TRUE);
    00135            }
    00136 }
    00137
    00138
    00139 void Help::fontSizeComboBox_activated( const QString& /* size */ )
    00140 {
    00141 //         QFont font = textBrowser->font();
    00142 //         font.setPointSize(size.toInt());
    00143 //         font.setBold(boldCheckBox->isChecked());
    00144 //         textBrowser->setFont(font);
    00145 //         textBrowser->update();
    00146 }
    00147
    00148
    00149 void Help::boldCheckBox_clicked()
    00150 {
    00151 //         fontSizeComboBox_activated(fontSizeComboBox->currentText());
    00152 }
    00153
    00154
    00155 void Help::backward()
    00156 {
    00157            if(paragVec_.size() == 0)
    00158            {
    00159                       textBrowser->home();
    00160                       return;
    00161            }
    00162
    00163            textBrowser->backward();
    00164
    00165            int para = paragVec_[paragVec_.size()-1];
    00166            paragVec_.pop_back();
    00167            int index = indexVec_[indexVec_.size()-1];
    00168            indexVec_.pop_back();
    00169
    00170            textBrowser->setCursorPosition(para, index);
    00171            textBrowser->ensureCursorVisible();
    00172 }
    00173
    00174
    00175 void Help::forward()
    00176 {
    00177            int para, index;
    00178
    00179            textBrowser->getCursorPosition(&para, &index);
    00180
    00181            paragVec_.push_back(para);
    00182            indexVec_.push_back(index);
    00183
    00184            textBrowser->forward();
    00185 }
    00186
    00187
    00188 void Help::linkClicked(const QString & /* link */ )
    00189 {
    00190            int para, index;
    00191
    00192            textBrowser->getCursorPosition(&para, &index);
    00193
    00194            paragVec_.push_back(para);
    00195            indexVec_.push_back(index);
    00196 }
    00197
    00198
    00199 void Help::anchorClicked(const QString & /* link */, const QString & /* anchor */ )
    00200 {
    00201 }
    00202
    00203
    00204 void Help::scrollToAnchor( const QString &name)
    00205 {
    00206            textBrowser->scrollToAnchor(name);
    00207 }

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines