2
Copyright (C) 2010 Marco Mentasti <marcomentasti@gmail.com>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "textoutputwidget.h"
20
#include "connection.h"
24
#include <klocalizedstring.h>
26
#include <QFontDatabase>
28
#include <qtextedit.h>
29
#include <qdatetime.h>
31
TextOutputWidget::TextOutputWidget(QWidget *parent)
34
m_succesTextColor = QColor::fromRgb(3, 191, 3);
35
m_succesBackgroundColor = QColor::fromRgb(231, 247, 231);
37
m_errorTextColor = QColor::fromRgb(191, 3, 3);
38
m_errorBackgroundColor = QColor::fromRgb(247, 231, 231);
40
m_layout = new QHBoxLayout(this);
42
m_output = new QTextEdit();
43
m_output->setReadOnly(true);
45
QFont fixedFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
47
m_output->setCurrentFont(fixedFont);
49
KToolBar *toolbar = new KToolBar(this);
50
toolbar->setOrientation(Qt::Vertical);
51
toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
52
toolbar->setIconSize(QSize(16, 16));
54
/// TODO: disable actions if no results are displayed
56
QAction *action = new QAction( QIcon::fromTheme(QLatin1String("edit-clear")), i18nc("@action:intoolbar", "Clear"), this);
57
toolbar->addAction(action);
58
connect(action, SIGNAL(triggered()), m_output, SLOT(clear()));
60
m_layout->addWidget(toolbar);
61
m_layout->addWidget(m_output, 1);
62
m_layout->setContentsMargins(0, 0, 0, 0);
67
TextOutputWidget::~TextOutputWidget()
72
void TextOutputWidget::showErrorMessage(const QString &message)
74
QColor previousBackgroundColor = m_output->textBackgroundColor();
75
QColor previousColor = m_output->textColor();
77
m_output->setTextBackgroundColor(m_errorBackgroundColor);
78
m_output->setTextColor(m_errorTextColor);
80
writeMessage(message);
82
m_output->setTextBackgroundColor(previousBackgroundColor);
83
m_output->setTextColor(previousColor);
87
void TextOutputWidget::showSuccessMessage(const QString &message)
89
QColor previousBackgroundColor = m_output->textBackgroundColor();
90
QColor previousColor = m_output->textColor();
92
m_output->setTextBackgroundColor(m_succesBackgroundColor);
93
m_output->setTextColor(m_succesTextColor);
95
writeMessage(message);
97
m_output->setTextBackgroundColor(previousBackgroundColor);
98
m_output->setTextColor(previousColor);
101
void TextOutputWidget::writeMessage(const QString& msg)
103
m_output->append(QString::fromLatin1("%1: %2\n").arg(QDateTime::currentDateTime().toString(Qt::SystemLocaleDate)).arg(msg));