blob: 8ec6fa2c71f9d29bf42218df3c97cd945c00ae66 (
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
|
/***************************************************************************
copyright : (C) 2005-2006 by Robby Stephenson
email : $EMAIL
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
#include "listboxtext.h"
#include "../tellico_utils.h"
#include <qpainter.h>
using Tellico::GUI::ListBoxText;
ListBoxText::ListBoxText(QListBox* listbox_, const QString& text_)
: QListBoxText(listbox_, text_), m_colored(false) {
}
ListBoxText::ListBoxText(QListBox* listbox_, const QString& text_, QListBoxItem* after_)
: QListBoxText(listbox_, text_, after_), m_colored(false) {
}
int ListBoxText::width(const QListBox* listbox_) const {
if(m_colored) {
QFont font = listbox_->font();
font.setBold(true);
font.setItalic(true);
QFontMetrics fm(font);
return fm.width(text()) + 6;
} else {
return QListBoxText::width(listbox_);
}
}
// I don't want the height to change when colored
// so all the items are at the same level for multi-column boxes
int ListBoxText::height(const QListBox* listbox_) const {
return QListBoxText::height(listbox_);
}
void ListBoxText::setColored(bool colored_) {
if(m_colored != colored_) {
m_colored = colored_;
listBox()->triggerUpdate(false);
}
}
void ListBoxText::setText(const QString& text_) {
QListBoxText::setText(text_);
listBox()->triggerUpdate(true);
}
// mostly copied from QListBoxText::paint() in Qt 3.1.1
void ListBoxText::paint(QPainter* painter_) {
if(m_colored) {
QFont font = painter_->font();
font.setBold(true);
font.setItalic(true);
painter_->setFont(font);
if(!isSelected()) {
painter_->setPen(Tellico::contrastColor);
}
}
int itemHeight = height(listBox());
QFontMetrics fm = painter_->fontMetrics();
int yPos = ((itemHeight - fm.height()) / 2) + fm.ascent();
painter_->drawText(3, yPos, text());
}
|