colorlistitem.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2006-2007 Kevin Kofler
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program 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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include <q3listbox.h>
  18. #include <qpainter.h>
  19. #include <qstyle.h>
  20. class ColorListItem : public Q3ListBoxItem {
  21. public:
  22. ColorListItem(Q3ListBox *listbox, const QColor &color)
  23. : Q3ListBoxItem(listbox), m_color(color) {}
  24. virtual ~ColorListItem() {}
  25. QColor color() {return m_color;}
  26. void setColor(const QColor &color) {m_color=color; listBox()->update();}
  27. protected:
  28. virtual void paint(QPainter *painter) {
  29. // Find out whether we are painted onto our listbox.
  30. bool inListBox=listBox() && listBox()->viewport()==painter->device();
  31. QRect r(0,0,width(listBox()),height(listBox()));
  32. if (inListBox && isSelected())
  33. painter->eraseRect(r);
  34. painter->fillRect(2,2,width(listBox())-4,height(listBox())-4,m_color);
  35. if (inListBox && isCurrent())
  36. listBox()->style().drawPrimitive(QStyle::PE_FocusRect,painter,r,listBox()->colorGroup());
  37. }
  38. virtual int height(const Q3ListBox *) const {return 16;}
  39. virtual int width(const Q3ListBox *listBox) const {
  40. return listBox->contentsWidth();
  41. }
  42. private:
  43. QColor m_color;
  44. };