"Fossies" - the Fresh Open Source Software Archive

Member "highlight-3.57-x64/src/gui-qt/showtextfile.cpp" (12 May 2020, 2637 Bytes) of package /windows/www/highlight-3.57-x64.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "showtextfile.cpp": 3.53_vs_3.54.

    1 
    2 /***************************************************************************
    3                                showtestfile.cpp
    4                              -------------------
    5     begin                : Mo 16.03.2009
    6     copyright            : (C) 2009-2017 by Andre Simon
    7     email                : a.simon@mailbox.org
    8  ***************************************************************************/
    9 
   10 /*
   11 This file is part of Highlight.
   12 
   13 Highlight is free software: you can redistribute it and/or modify
   14 it under the terms of the GNU General Public License as published by
   15 the Free Software Foundation, either version 3 of the License, or
   16 (at your option) any later version.
   17 
   18 Highlight is distributed in the hope that it will be useful,
   19 but WITHOUT ANY WARRANTY; without even the implied warranty of
   20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   21 GNU General Public License for more details.
   22 
   23 You should have received a copy of the GNU General Public License
   24 along with Highlight.  If not, see <http://www.gnu.org/licenses/>.
   25 */
   26 
   27 #include "showtextfile.h"
   28 #include "ui_showtextfile.h"
   29 #include <QTextStream>
   30 #include <QFile>
   31 #include <QDir>
   32 
   33 ShowTextFile::ShowTextFile(QWidget *parent) :
   34     QDialog(parent),
   35     m_ui(new Ui::ShowTextFile)
   36 {
   37     m_ui->setupUi(this);
   38 }
   39 
   40 ShowTextFile::~ShowTextFile()
   41 {
   42     delete m_ui;
   43 }
   44 
   45 void ShowTextFile::changeEvent(QEvent *e)
   46 {
   47     switch (e->type()) {
   48     case QEvent::LanguageChange:
   49         m_ui->retranslateUi(this);
   50         break;
   51     default:
   52         break;
   53     }
   54 }
   55 
   56 bool ShowTextFile::setFileName(const QString& fileName)
   57 {
   58 #ifdef Q_OS_OSX
   59     QFile file( QString("%1/../Resources/%2").arg(QCoreApplication::applicationDirPath()).arg( fileName ));
   60 #else
   61     #ifndef DOC_DIR
   62     QFile file( QString("%1/%2").arg(QDir::currentPath()).arg( fileName ));
   63     #else
   64     QFile file( QString("%1/%2").arg(DOC_DIR).arg(fileName ));
   65     #endif
   66 #endif
   67     if ( file.open( QIODevice::ReadOnly) ) {
   68         QTextStream stream( &file );
   69         //m_ui->textBrowser->setText( stream.readAll() );
   70         
   71         QString line;
   72         do {
   73             line = stream.readLine();
   74             if (! (line.startsWith(":") || line.startsWith("//")) )
   75                 m_ui->textBrowser->append( line );
   76         } while (!line.isNull());
   77         
   78         m_ui->lbTitle->setText(fileName);
   79         m_ui->textBrowser->moveCursor(QTextCursor::Start);
   80     }
   81     return file.exists();
   82 }
   83 
   84 void ShowTextFile::setText(const QString& content, const QString& title)
   85 {
   86    m_ui->textBrowser->setText( content );
   87    m_ui->lbTitle->setText(title);
   88 }
   89 
   90 
   91 void ShowTextFile::on_pushButton_clicked()
   92 {
   93     this->close();
   94 }