Fork me on GitHub
2.15.20
FGx
A cross-platform launcher for FlightGear
fileviewerwidget.cpp
Go to the documentation of this file.
1 
2 #include <QtDebug>
3 #include <QVBoxLayout>
4 #include <QHBoxLayout>
5 #include <QToolButton>
6 
7 
8 #include <QFileInfo>
9 #include <QFile>
10 
11 #include "fileviewerwidget.h"
12 
14  QWidget(parent)
15 {
16 
17  QVBoxLayout *mainLayout = new QVBoxLayout();
18  mainLayout->setContentsMargins(0,0,0,0);
19  mainLayout->setSpacing(0);
20  this->setLayout(mainLayout);
21 
22  //= Top layout has label adn close
23  QHBoxLayout *topLayout = new QHBoxLayout();
24  topLayout->setContentsMargins(0,0,0,0);
25  topLayout->setSpacing(0);
26  mainLayout->addLayout(topLayout);
27 
28  lblFileName = new QLabel();
29  lblFileName->setStyleSheet("background-color: black; color: #dddddd; font-family: monospace; font-size: 14pt;");
30  topLayout->addWidget(lblFileName);
31 
32  QToolButton *buttClose = new QToolButton();
33  buttClose->setText(tr("Close"));
34  buttClose->setIcon(QIcon(":/icon/close"));
35  buttClose->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
36  topLayout->addWidget(buttClose);
37  connect(buttClose, SIGNAL(clicked()),
38  this, SLOT(close())
39  );
40 
41  txtEdit = new QTextEdit();
42  mainLayout->addWidget(txtEdit);
43 
44 
45 }
46 
47 /*! @brief Loads file and sets labels
48  *
49  * @todo no error trapping, autodetect required
50  */
51 void FileViewerWidget::setFile(QString file_path){
52 
53  QFileInfo finfo(file_path);
54 
55  this->setWindowTitle(file_path);
56 
57  this->lblFileName->setText(finfo.fileName());
58 
59  QFile file( file_path );
60  if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
61  //qDebug() << "TODO Open error cachce file=";
62  return;
63  }
64  QString contents = QString(file.readAll()).toUtf8();
65  //qDebug() << contents;
66  this->txtEdit->setPlainText(contents);
67 
68 }
69 
70 void FileViewerWidget::moveEvent(QMoveEvent *ev){
71  Q_UNUSED(ev);
72  //TODO save window size
73  //this->mainObject->settings->saveWindow(this);
74 }
QTextEdit * txtEdit
FileViewerWidget(QWidget *parent=0)
void setFile(QString file_name)
Loads file and sets labels.
void moveEvent(QMoveEvent *ev)