tweaks for qt 4.7
[fapman] / logview.cpp
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager is free software: you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation, either version 3 of the License, or
7         (at your option) any later version.
8
9         Faster Application Manager is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #include <QtGui>
21
22 #ifdef Q_WS_MAEMO_5
23 #include <QtMaemo5>
24 #endif
25
26 #include "logview.h"
27 #include "ui_logview.h"
28 #include "aaptinterface.h"
29
30 LogView::LogView(QByteArray text, QWidget *parent) :
31     QDialog(parent),
32     ui(new Ui::LogView)
33 {
34     ui->setupUi(this);
35
36         QFont f = ui->plainTextEdit->font();
37         f.setPointSize( f.pointSize()-2 );
38
39         ui->plainTextEdit->setFont(f);
40
41         QString t = text;
42         QStringList lines = t.split('\n');
43
44         if( lines.count()>100 )
45                 ui->label->setText("Showing last 100 lines");
46
47         while( lines.count()>100 )
48                 lines.removeFirst();
49         lines << "" << "" << "" << "" << "";
50
51         ui->plainTextEdit->setPlainText("");
52         ui->plainTextEdit->appendPlainText(lines.join("\n"));
53 }
54
55 LogView::~LogView()
56 {
57     delete ui;
58 }
59
60 int LogView::exec()
61 {
62         /*
63 #ifdef Q_WS_MAEMO_5             // workaround for buggy Qt autorotation
64         QRect r = dynamic_cast<QWidget*>(this->parent())->rect();
65         if(r.width() < r.height())
66                 this->setAttribute(Qt::WA_Maemo5PortraitOrientation);
67 #endif
68         */
69
70         show();
71
72         //ui->plainTextEdit->setMinimumHeight( ui->plainTextEdit->contentsRect().height() );
73         //ui->scrollAreaWidgetContents->setMinimumHeight( ui->scrollAreaWidgetContents->contentsRect().height() );
74         //ui->plainTextEdit->setMinimumHeight( 800 );
75         //ui->plainTextEdit->adjustSize();
76         //ui->scrollAreaWidgetContents->adjustSize();
77
78         // taken from a Qt example, should auto-resize the textedit
79         QTextDocument *doc = ui->plainTextEdit->document();
80         QSize s = doc->size().toSize();
81         if (ui->plainTextEdit)
82                 s.setHeight((s.height() + 1) * ui->plainTextEdit->fontMetrics().lineSpacing());
83         const QRect fr = ui->plainTextEdit->frameRect();
84         const QRect cr = ui->plainTextEdit->contentsRect();
85         ui->plainTextEdit->setMinimumHeight(qMax(70, s.height() + (fr.height() - cr.height() - 1)));
86
87         int e = QDialog::exec();
88
89         /*
90 #ifdef Q_WS_MAEMO_5             // workaround for buggy Qt autorotation
91         this->setAttribute(Qt::WA_Maemo5AutoOrientation);
92 #endif
93         */
94
95         return e;
96 }
97
98 void LogView::changeEvent(QEvent *e)
99 {
100     QDialog::changeEvent(e);
101     switch (e->type()) {
102     case QEvent::LanguageChange:
103         ui->retranslateUi(this);
104         break;
105     default:
106         break;
107     }
108 }
109
110 void LogView::on_btnClear_clicked()
111 {
112         QFile logfile(KLogFile);
113         logfile.remove();
114
115         accept();
116 }
117
118 void LogView::on_btnCopy_clicked()
119 {
120         ui->plainTextEdit->selectAll();
121         ui->plainTextEdit->copy();
122
123         QMaemo5InformationBox::information ( this, "Copied" );
124 }