a95f64c9b41d7f0f4f78795f373f2b9b594996dd
[qcpufreq] / src / helpwindow.cpp
1 #include "helpwindow.h"
2 #include "ui_helpwindow.h"
3
4 #include <QFile>
5 #include <QLocale>
6 #include <QTextStream>
7 #include <QMessageBox>
8 #include <QPalette>
9 #include <QBrush>
10 #include <QColor>
11
12 HelpWindow::HelpWindow(QWidget *parent) :
13     QWidget(parent),
14     ui(new Ui::HelpWindow)
15 {
16     //this is a stacked window on Maemo 5
17     #if defined(Q_WS_MAEMO_5)
18         //setAttribute(Qt::WA_Maemo5StackedWindow);
19     #endif
20     ui->setupUi(this);
21
22     setHelpText();
23
24     //format color of help text according to system color scheme
25     QPalette palette;
26     QBrush brush = palette.windowText();
27     QColor color = brush.color();
28     ui->textBrowser->setStyleSheet( "QTextEdit {background: transparent; color: " + color.name() + ";}" );
29 }
30
31
32 HelpWindow::~HelpWindow()
33 {
34     delete ui;
35 }
36
37
38 /**
39   * Assigns the help text to the QTextEdit
40   */
41 void HelpWindow::setHelpText()
42 {
43     //get the current locale name for lacalized help messages
44     QString locale = QLocale::system().name();
45     QStringList tmp = locale.split("_");
46     locale = tmp.first();
47
48     //open help text
49     QFile help( ":/txt/help_" + locale );
50
51     //open the file
52     if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
53         //try to open the file in english language instead
54         help.setFileName(":/txt/help_en");
55         if ( !help.exists() || !help.open( QIODevice::ReadOnly ) ) {
56             QMessageBox::critical(this, tr("QCPUFreq"), tr("Cannot open help file!"));
57             return;
58         }
59     }
60
61     //read the file
62     QTextStream in( &help );
63     QString txt;
64     do {
65         txt += in.readLine();
66         txt += "\n";
67     } while ( !in.atEnd() );
68
69     ui->textBrowser->setText( txt );
70 }