diff --git a/modules/gui/src/sequence/sequence_delegate.cc b/modules/gui/src/sequence/sequence_delegate.cc new file mode 100644 index 0000000000000000000000000000000000000000..6e5a7a5cb64b6b6cb39ed7cf29d2e22c28b545e1 --- /dev/null +++ b/modules/gui/src/sequence/sequence_delegate.cc @@ -0,0 +1,78 @@ +//------------------------------------------------------------------------------ +// 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(); +} +}} diff --git a/modules/gui/src/sequence/sequence_delegate.hh b/modules/gui/src/sequence/sequence_delegate.hh new file mode 100644 index 0000000000000000000000000000000000000000..da820e5cd5c05e80c65ffcfdda00c337635ca258 --- /dev/null +++ b/modules/gui/src/sequence/sequence_delegate.hh @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// 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 diff --git a/modules/gui/src/sequence/sequence_viewer.cc b/modules/gui/src/sequence/sequence_viewer.cc index 8812786725cd09eff91966a11f47753055af96d3..db2aca7eb8b386f8261e9c71e5ac915cd4f1a4a0 100644 --- a/modules/gui/src/sequence/sequence_viewer.cc +++ b/modules/gui/src/sequence/sequence_viewer.cc @@ -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(); } }