summaryrefslogtreecommitdiffstats
path: root/quanta/components/tableeditor/tableitem.cpp
blob: 96d7d37c93baca76d959f4656ef819380b4818f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***************************************************************************
                          tableitem.cpp -  description
                             -------------------
    begin                : Mon 15 Mar 2004
    copyright            : (C) 2004 by Michal Rudolf <mrudolf@kdewebdev.org>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qtextedit.h>
#include <qpainter.h>
#include "tableitem.h"

TableItem::TableItem(QTable* table, EditType et) : QTableItem(table, et)
{
  setReplaceable(false);
  m_halign = Qt::AlignLeft;
  m_valign = Qt::AlignVCenter;
}

TableItem::TableItem(QTable* table, EditType et, const QString& text) : QTableItem(table, et, text)
{
  setReplaceable(false);
  m_halign = Qt::AlignLeft;
  m_valign = Qt::AlignVCenter;
}

TableItem::TableItem (QTable* table, EditType et, const QString& text, const QPixmap& p) :
  QTableItem(table, et, text, p)
{
  setReplaceable(false);
  m_halign = Qt::AlignLeft;
  m_valign = Qt::AlignVCenter;
}

QWidget* TableItem::createEditor() const
{
  QTextEdit* Editor = new QTextEdit(table()->viewport());
  Editor->setTextFormat(QTextEdit::PlainText);
  Editor->setHScrollBarMode(QScrollView::AlwaysOff);
  Editor->setVScrollBarMode(QScrollView::AlwaysOff);
  Editor->setBold(m_header);
  Editor->setText(text());
  QObject::connect(Editor, SIGNAL(textChanged()), table(), SLOT(doValueChanged()));
  return Editor;
}

void TableItem::setContentFromEditor(QWidget *w)
{
  if (w->inherits( "QTextEdit" ))
    setText(((QTextEdit*)w)->text());
  else
    QTableItem::setContentFromEditor(w);
}

void TableItem::paint(QPainter* p, const QColorGroup& cg, const QRect& cr, bool selected)
{
   if (m_header) {
     QFont editFont = p->font();
     editFont.setBold(true);
     p->setFont(editFont);
   }
   QRect cr0(0, 0, cr.width(), cr.height());
   if (selected) {
     p->fillRect(cr0, cg.brush(QColorGroup::Highlight));
     p->setPen(cg.highlightedText());
   }
   else {
     p->fillRect(cr0, cg.brush(QColorGroup::Base));
     p->setPen(cg.text());
   }
   if (!pixmap().isNull()) {
     p->drawPixmap(4, 4, pixmap());
     p->drawText(6 + pixmap().width(), 4, cr0.width()-8, cr0.height()-8, m_halign | m_valign | WordBreak, text());
   }
   else
     p->drawText(4, 4, cr0.width()-8, cr0.height()-8, m_halign | m_valign | WordBreak, text());
}

QSize TableItem::sizeHint() const
{
   QSize size = QTableItem::sizeHint();
   size.setWidth(size.width()+8);
   size.setHeight(size.height()+8);
   return size;
}