Skip to content
Snippets Groups Projects
Commit 5b4ab416 authored by stefan's avatar stefan
Browse files

use delegate to draw text

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2159 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent a0753d95
No related branches found
No related tags found
No related merge requests found
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
/*
Author: Stefan Scheuber
*/
#include <QtGui>
#include <iostream>
#include "sequence_delegate.hh"
namespace ost { namespace gui {
SequenceDelegate::SequenceDelegate(SequenceTableView* view, QObject *parent)
: QItemDelegate(parent), view_(view)
{
}
/*
QWidget *SequenceDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
{
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(0);
editor->setMaximum(100);
return editor;
}
*/
void SequenceDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
painter->save();
painter->setPen(QPen(Qt::NoPen));
if(option.state & QStyle::State_Selected){
painter->setBrush(option.palette.highlight());
}
else{
painter->setBrush(QBrush(Qt::white));
}
painter->drawRect(option.rect);
painter->setPen(QPen(Qt::lightGray));
if(index.column()%2){
painter->drawLine(option.rect.topLeft(),option.rect.bottomRight());
}
else{
painter->drawLine(option.rect.bottomLeft(),option.rect.topRight());
}
painter->setPen(QPen(Qt::black));
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid()){
QString text = value.toString();
painter->setFont(QFont("Courier",10));
painter->drawText(option.rect, Qt::AlignLeft|Qt::AlignVCenter, text);
}
painter->restore();
}
}}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef OST_SEQUENCE_VIEWER_SEQUENCE_DELEGATE
#define OST_SEQUENCE_VIEWER_SEQUENCE_DELEGATE
/*
Author: Stefan Scheuber
*/
#include <QItemDelegate>
#include <QModelIndex>
#include <QObject>
#include <QSize>
#include <QSpinBox>
#include "sequence_table_view.hh"
namespace ost { namespace gui {
class SequenceDelegate : public QItemDelegate
{
Q_OBJECT
public:
SequenceDelegate(SequenceTableView* view, QObject *parent = 0);
/* QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;*/
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
SequenceTableView* view_;
};
}}
#endif
......@@ -68,6 +68,8 @@ SequenceViewerV2::SequenceViewerV2(QWidget* parent): Widget(NULL,parent)
);
seq_table_view_->horizontalHeader()->setMinimumSectionSize(8);
seq_table_view_->horizontalHeader()->setDefaultSectionSize(10);
seq_table_view_->verticalHeader()->setMinimumSectionSize(8);
seq_table_view_->verticalHeader()->setDefaultSectionSize(10);
}
void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n)
......@@ -98,6 +100,7 @@ void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n)
seq.AttachView(v_one_chain);
QStandardItem* item = new QStandardItem(name.c_str());
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(seq_table_view_->model());
SequenceDelegate* del = new SequenceDelegate(seq_table_view_,this);
if(model){
int row = model->rowCount();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("") );
......@@ -108,13 +111,15 @@ void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n)
item->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
item->setFont(QFont("Courier",10));
QFontMetrics m = QFontMetrics(QFont("Courier",10));
item->setSizeHint(QSize(m.width(QString(seq.GetOneLetterCode(i)))+6,item->sizeHint().height()));
item->setSizeHint(QSize(m.width(QString(seq.GetOneLetterCode(i)))+2,m.height()+2));
model->setItem(row, i+1, item);
model->setHeaderData(i+1, Qt::Horizontal, QObject::tr("") );
seq_table_view_->setItemDelegateForColumn(i+1,del);
}
}
}
seq_table_view_->resizeColumnsToContents();
seq_table_view_->resizeRowsToContents();
}
}
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment