~ubuntu-branches/ubuntu/saucy/rocs/saucy-proposed

« back to all changes in this revision

Viewing changes to App/Ui/ScriptOutputWidget.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg, Rohan Garg, Philip Muškovac
  • Date: 2013-06-21 02:04:20 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20130621020420-lzlui9y7qc6w3xog
Tags: 4:4.10.80-0ubuntu1
[ Rohan Garg ]
* New upstream release

[ Philip Muškovac ]
* Build-depend on libgrantlee-dev and libx11-dev
* Update rocs.install and not-installed 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of Rocs.
 
3
    Copyright 2012       Andreas Cord-Landwehr <cola@uni-paderborn.de>
 
4
 
 
5
    This program is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU General Public License as
 
7
    published by the Free Software Foundation; either version 2 of
 
8
    the License, or (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#include "ScriptOutputWidget.h"
 
20
#include "DocumentManager.h"
 
21
#include "EngineModules/Console/ConsoleModule.h"
 
22
#include <QWidget>
 
23
#include <QtScriptBackend.h>
 
24
#include <KDebug>
 
25
 
 
26
ScriptOutputWidget::ScriptOutputWidget(QWidget* parent)
 
27
    : QWidget(parent),
 
28
    _console(0)
 
29
{
 
30
    ui = new Ui::ScriptOutputWidget;
 
31
    ui->setupUi(this);
 
32
 
 
33
    // set icon
 
34
    ui->buttonEnableDebugOutput->setIcon(KIcon("tools-report-bug"));
 
35
    ui->buttonDisableClear->setIcon(KIcon("document-decrypt"));
 
36
    ui->buttonClear->setIcon(KIcon("edit-clear-list"));
 
37
 
 
38
    connect(ui->buttonEnableDebugOutput, SIGNAL(clicked(bool)), this, SLOT(showDebugOutput(bool)));
 
39
    connect(ui->buttonDisableClear, SIGNAL(clicked(bool)), this, SLOT(updateFixOutputButton()));
 
40
    connect(ui->buttonClear, SIGNAL(clicked(bool)), this, SLOT(clear()));
 
41
}
 
42
 
 
43
void ScriptOutputWidget::unsetConsoleInterface()
 
44
{
 
45
    if (_console) {
 
46
        _console->disconnect(this);
 
47
    }
 
48
    _console = 0;
 
49
}
 
50
 
 
51
void ScriptOutputWidget::setConsoleInterface(ConsoleModule* console)
 
52
{
 
53
    unsetConsoleInterface();
 
54
    _console = console;
 
55
 
 
56
    connect(console, SIGNAL(backlogChanged(ConsoleModule::MessageType,QString)),
 
57
            this, SLOT(appendOutput(ConsoleModule::MessageType,QString)));
 
58
}
 
59
 
 
60
ConsoleModule * ScriptOutputWidget::consoleInterface() const
 
61
{
 
62
    return _console;
 
63
}
 
64
 
 
65
void ScriptOutputWidget::updateFixOutputButton()
 
66
{
 
67
    if (ui->buttonDisableClear->isChecked() == true) {
 
68
        ui->buttonDisableClear->setIcon(KIcon("document-encrypt"));
 
69
    }
 
70
    else {
 
71
        ui->buttonDisableClear->setIcon(KIcon("document-decrypt"));
 
72
    }
 
73
}
 
74
 
 
75
void ScriptOutputWidget::clear()
 
76
{
 
77
    ui->dbgOutput->clear();
 
78
    ui->txtOutput->clear();
 
79
}
 
80
 
 
81
bool ScriptOutputWidget::isOutputClearEnabled() const
 
82
{
 
83
    return !ui->buttonDisableClear->isChecked();
 
84
}
 
85
 
 
86
void ScriptOutputWidget::appendOutput(ConsoleModule::MessageType type, const QString& message)
 
87
{
 
88
    switch(type)
 
89
    {
 
90
    case ConsoleModule::Log:
 
91
        ui->txtOutput->append(message);
 
92
        ui->dbgOutput->append("<i>" + message + "</i>");
 
93
        break;
 
94
    case ConsoleModule::Debug:
 
95
        ui->dbgOutput->append("<span style=\"color: green\">" + message + "</span>");
 
96
        break;
 
97
    case ConsoleModule::Error:
 
98
        ui->txtOutput->append("<b style=\"color: red\">" + message + "</b>");
 
99
        ui->dbgOutput->append("<b style=\"color: red\">" + message + "</b>");
 
100
        break;
 
101
    default:
 
102
        kWarning() << "Unknown message type, aborting printing.";
 
103
    }
 
104
}
 
105
 
 
106
void ScriptOutputWidget::showDebugOutput(bool show)
 
107
{
 
108
    if (show && !ui->buttonEnableDebugOutput->isChecked()) {
 
109
        ui->buttonEnableDebugOutput->toggle();
 
110
    }
 
111
    if (!show && ui->buttonEnableDebugOutput->isChecked()) {
 
112
        ui->buttonEnableDebugOutput->toggle();
 
113
    }
 
114
    if (show) {
 
115
        ui->output->setCurrentIndex(1);
 
116
    } else {
 
117
        ui->output->setCurrentIndex(0);
 
118
    }
 
119
}