From e38d2351b83fa65c66ccde443777647ef5cb6cff Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 1 Mar 2010 19:17:32 +0000 Subject: Added KDE3 version of Tellico git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/gui/listboxtext.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/gui/listboxtext.cpp (limited to 'src/gui/listboxtext.cpp') diff --git a/src/gui/listboxtext.cpp b/src/gui/listboxtext.cpp new file mode 100644 index 0000000..8ec6fa2 --- /dev/null +++ b/src/gui/listboxtext.cpp @@ -0,0 +1,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 + +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()); +} -- cgit v1.2.1