~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to addons/katesql/textoutputwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2010  Marco Mentasti  <marcomentasti@gmail.com>
 
3
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
#include "textoutputwidget.h"
 
20
#include "connection.h"
 
21
 
 
22
#include <ktoolbar.h>
 
23
#include <QAction>
 
24
#include <klocalizedstring.h>
 
25
 
 
26
#include <QFontDatabase>
 
27
#include <qlayout.h>
 
28
#include <qtextedit.h>
 
29
#include <qdatetime.h>
 
30
 
 
31
TextOutputWidget::TextOutputWidget(QWidget *parent)
 
32
: QWidget(parent)
 
33
{
 
34
  m_succesTextColor = QColor::fromRgb(3, 191, 3);
 
35
  m_succesBackgroundColor = QColor::fromRgb(231, 247, 231);
 
36
 
 
37
  m_errorTextColor = QColor::fromRgb(191, 3, 3);
 
38
  m_errorBackgroundColor = QColor::fromRgb(247, 231, 231);
 
39
 
 
40
  m_layout = new QHBoxLayout(this);
 
41
 
 
42
  m_output = new QTextEdit();
 
43
  m_output->setReadOnly(true);
 
44
 
 
45
  QFont fixedFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
 
46
 
 
47
  m_output->setCurrentFont(fixedFont);
 
48
 
 
49
  KToolBar *toolbar = new KToolBar(this);
 
50
  toolbar->setOrientation(Qt::Vertical);
 
51
  toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
 
52
  toolbar->setIconSize(QSize(16, 16));
 
53
 
 
54
  /// TODO: disable actions if no results are displayed
 
55
 
 
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()));
 
59
 
 
60
  m_layout->addWidget(toolbar);
 
61
  m_layout->addWidget(m_output, 1);
 
62
  m_layout->setContentsMargins(0, 0, 0, 0);
 
63
 
 
64
  setLayout(m_layout);
 
65
}
 
66
 
 
67
TextOutputWidget::~TextOutputWidget()
 
68
{
 
69
}
 
70
 
 
71
 
 
72
void TextOutputWidget::showErrorMessage(const QString &message)
 
73
{
 
74
  QColor previousBackgroundColor = m_output->textBackgroundColor();
 
75
  QColor previousColor = m_output->textColor();
 
76
 
 
77
  m_output->setTextBackgroundColor(m_errorBackgroundColor);
 
78
  m_output->setTextColor(m_errorTextColor);
 
79
 
 
80
  writeMessage(message);
 
81
 
 
82
  m_output->setTextBackgroundColor(previousBackgroundColor);
 
83
  m_output->setTextColor(previousColor);
 
84
}
 
85
 
 
86
 
 
87
void TextOutputWidget::showSuccessMessage(const QString &message)
 
88
{
 
89
  QColor previousBackgroundColor = m_output->textBackgroundColor();
 
90
  QColor previousColor = m_output->textColor();
 
91
 
 
92
  m_output->setTextBackgroundColor(m_succesBackgroundColor);
 
93
  m_output->setTextColor(m_succesTextColor);
 
94
 
 
95
  writeMessage(message);
 
96
 
 
97
  m_output->setTextBackgroundColor(previousBackgroundColor);
 
98
  m_output->setTextColor(previousColor);
 
99
}
 
100
 
 
101
void TextOutputWidget::writeMessage(const QString& msg)
 
102
{
 
103
  m_output->append(QString::fromLatin1("%1: %2\n").arg(QDateTime::currentDateTime().toString(Qt::SystemLocaleDate)).arg(msg));
 
104
 
 
105
  raise();
 
106
}