#ifndef BUTTONVIEWITEM_H#define BUTTONVIEWITEM_H#include <qlistview.h>#include <qlist.h>class QPushButton;/** @author vladimir */class ButtonViewItem : public QListViewItem{public: ButtonViewItem(QListViewItem *parent = 0, const char *name = 0); ButtonViewItem(QListView *parent = 0, const char *name = 0); ~ButtonViewItem(); void setButtonText(const int& col, const QString& text); void insertButton(const unsigned int& col, const QString& text = ""); void setButtonPixmap(const int& col, const QPixmap& pixmap);private: QList<QPushButton> *pbListButton; void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ); void hideButtos(); void setOpen(bool flag);};#endif
#include "butviewitem.h"#include <qpushbutton.h>#include <qheader.h>ButtonViewItem::ButtonViewItem(QListViewItem *parent, const char *name) : QListViewItem(parent, name){ pbListButton = new QList<QPushButton>(); pbListButton->setAutoDelete(true); for (int i = 0; i < listView()->columns(); i++) pbListButton->append(NULL);}ButtonViewItem::ButtonViewItem(QListView *parent, const char *name) : QListViewItem(parent, name){ pbListButton = new QList<QPushButton>(); pbListButton->setAutoDelete(true); for (int i = 0; i < parent->columns(); i++) pbListButton->append(NULL);}ButtonViewItem::~ButtonViewItem(){ if (pbListButton) delete pbListButton;}void ButtonViewItem::paintCell ( QPainter * , const QColorGroup & , int column, int width, int ){ int w_st = listView()->header()->sectionPos(column) + 2; QRect rect = listView()->itemRect(this); int delta = listView()->header()->height(); int h_st = rect.y() + delta + 2; if (pbListButton->at(column)) { pbListButton->at(column)->setGeometry(w_st, h_st, width - 1, height() - 1); pbListButton->at(column)->show(); }}void ButtonViewItem::setButtonText(const int& col, const QString& text){ if (pbListButton->at(col)) pbListButton->at(col)->setText(text);}void ButtonViewItem::insertButton(const unsigned int& col, const QString& text){ if (!pbListButton->at(col) || pbListButton->count() >= col) { pbListButton->replace(col, new QPushButton(listView(), "button_item")); pbListButton->at(col)->hide(); setButtonText(col, text); }}void ButtonViewItem::setButtonPixmap(const int& col, const QPixmap& pixmap){ if (pbListButton->at(col)) pbListButton->at(col)->setPixmap(pixmap);}void ButtonViewItem::setOpen(bool flag){ if (!flag) { QListViewItemIterator iter( firstChild()); while (iter.current()) { ((ButtonViewItem*)iter.current())->hideButtos(); iter++; } } QListViewItem::setOpen(flag);}void ButtonViewItem::hideButtos(){ for (uint i = 0; i < pbListButton->count(); i++) if (pbListButton->at(i)) pbListButton->at(i)->hide();}