diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index b8443780cb107591dabc42a9673dd059a39bedd7..f646e95be392341a479c836cbfbe806a7fa2f5bd 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -21,13 +21,15 @@ sequence_search_bar.hh ) set(OST_GUI_SEQUENCE_VIEW_HEADERS -painter.hh base_row.hh +painter.hh +secstr_row.hh seq_secstr_painter.hh seq_selection_painter.hh seq_text_painter.hh sequence_delegate.hh sequence_model.hh +sequence_row.hh sequence_table_view.hh sequence_viewer.hh view_object.hh @@ -207,11 +209,13 @@ sequence_viewer/sequence_viewer.cc sequence_viewer/sequence_scene.cc sequence_viewer/sequence_search_bar.cc sequence/base_row.cc +sequence/secstr_row.cc sequence/seq_secstr_painter.cc sequence/seq_selection_painter.cc sequence/seq_text_painter.cc sequence/sequence_delegate.cc sequence/sequence_model.cc +sequence/sequence_row.cc sequence/sequence_table_view.cc sequence/sequence_viewer.cc sequence/view_object.cc @@ -331,13 +335,15 @@ sequence_viewer/sequence_viewer_base.hh sequence_viewer/sequence_viewer.hh sequence_viewer/sequence_scene.hh sequence_viewer/sequence_search_bar.hh -sequence/painter.hh sequence/base_row.hh +sequence/painter.hh +sequence/secstr_row.hh sequence/seq_secstr_painter.hh sequence/seq_selection_painter.hh sequence/seq_text_painter.hh sequence/sequence_delegate.hh sequence/sequence_model.hh +sequence/sequence_row.hh sequence/sequence_table_view.hh sequence/sequence_viewer.hh sequence/view_object.hh diff --git a/modules/gui/src/sequence/base_row.cc b/modules/gui/src/sequence/base_row.cc index 823b4f86ba239ab11b9606c3b8497b38bd93ad72..dab716f65d8d4b186068ef78f8c9df4b22603ff1 100644 --- a/modules/gui/src/sequence/base_row.cc +++ b/modules/gui/src/sequence/base_row.cc @@ -29,7 +29,24 @@ namespace ost { namespace gui { BaseRow::BaseRow(QObject *parent) : QObject(parent) -{ } +{ this->SetFont(font_); } + +BaseRow::BaseRow(QFont font, QObject *parent) : QObject(parent) +{ + this->SetFont(font); +} + +int BaseRow::GetColumnCount() const +{ + return -1; +} + +void BaseRow::Init() +{ + QFontMetrics metrics = QFontMetrics(font_); + default_font_size_=QSize(metrics.boundingRect('W').width(),metrics.boundingRect('|').height()); + default_cell_size_ = QSize(metrics.boundingRect('W').width()+2,metrics.boundingRect('|').height()*2); +} void BaseRow::InsertPainter(Painter* painter, int pos) { @@ -67,6 +84,29 @@ bool BaseRow::IsPainterPosValid(int pos) return false; } +const QFont& BaseRow::GetFont() const +{ + return font_; +} + +void BaseRow::SetFont(const QFont& font) +{ + font_ = font; + QFontMetrics metrics = QFontMetrics(font_); + default_font_size_=QSize(metrics.boundingRect('W').width(),metrics.boundingRect('|').height()); + default_cell_size_ = QSize(metrics.boundingRect('W').width()+2,metrics.boundingRect('|').height()*2); +} + +const QSize& BaseRow::GetFontSize() const +{ + return default_font_size_; +} + +const QSize& BaseRow::GetCellSize() const +{ + return default_cell_size_; +} + const PainterList& BaseRow::GetPainters() const { return painter_; diff --git a/modules/gui/src/sequence/base_row.hh b/modules/gui/src/sequence/base_row.hh index 9ed545fe00820dc5a84aa084198bd844bc34191b..5d749c5d29015744dbfc2936bab2f226edfe0908 100644 --- a/modules/gui/src/sequence/base_row.hh +++ b/modules/gui/src/sequence/base_row.hh @@ -16,8 +16,8 @@ // 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_ROW -#define OST_SEQUENCE_VIEWER_ROW +#ifndef OST_SEQUENCE_VIEWER_BASE_ROW +#define OST_SEQUENCE_VIEWER_BASE_ROW /* Author: Stefan Scheuber @@ -37,15 +37,24 @@ class BaseRow : public QObject public: BaseRow(QObject *parent = 0); + BaseRow(QFont font, QObject *parent = 0); + + void Init(); + + virtual int GetColumnCount() const; void InsertPainter(Painter* painter, int pos = -1); void RemovePainter(Painter* painter); - Painter* GetPainter(int pos); int GetPainterCount(); - const PainterList& GetPainters() const; + const QFont& GetFont() const; + void SetFont(const QFont& font); + const QSize& GetFontSize() const; + + virtual const QSize& GetCellSize() const; + virtual QVariant GetData(int column, int role) const; virtual bool SetData(int column, const QVariant& value, int role); virtual Qt::ItemFlags Flags(int column) const; @@ -54,6 +63,9 @@ public: private: bool IsPainterPosValid(int pos); PainterList painter_; + QFont font_; + QSize default_font_size_; + QSize default_cell_size_; }; typedef QList<BaseRow*> BaseRowList; diff --git a/modules/gui/src/sequence/secstr_row.cc b/modules/gui/src/sequence/secstr_row.cc new file mode 100644 index 0000000000000000000000000000000000000000..680533df1612adc21b41cc784b4d4b9297a24758 --- /dev/null +++ b/modules/gui/src/sequence/secstr_row.cc @@ -0,0 +1,132 @@ +//------------------------------------------------------------------------------ +// 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 <ost/mol/mol.hh> +#include <ost/mol/view_op.hh> + +#include <ost/gfx/entity.hh> + +#include "secstr_row.hh" + +namespace ost { namespace gui { + +SecStrRow::SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent) : SequenceRow(name,parent) +{ this->SetChain(chain); } + +void SecStrRow::SetSequence(seq::SequenceHandle& sequence) +{ + //Do nothing +} + +void SecStrRow::SetChain(mol::ChainView& chain) +{ + String seq_str; + seq_str.reserve(chain.GetResidueCount()); + for (mol::ResidueViewList::const_iterator r=chain.GetResidueList().begin(), + e2=chain.GetResidueList().end(); r!=e2; ++r) { + mol::ResidueView res=*r; + seq_str.append(1, res.GetOneLetterCode()); + } + if (!seq_str.empty()) { + seq::SequenceHandle sequence=seq::CreateSequence(this->GetName().toStdString(), seq_str); + mol::EntityView v_one_chain=chain.GetEntity().GetHandle().CreateEmptyView(); + v_one_chain.AddChain(chain, mol::ViewAddFlag::INCLUDE_ALL); + sequence.AttachView(v_one_chain); + + mol::alg::SecStructureSegments sec = mol::alg::ExtractSecStructureSegments(chain); + secstr_ = QVarLengthArray<mol::SecStructure>(chain.GetResidueCount()); + for (mol::alg::SecStructureSegments::iterator i=sec.begin(), + e=sec.end(); i!=e; ++i) { + mol::alg::SecStructureSegment s=*i; + for(int i = s.first; i <= s.last ;i++){ + secstr_[i] = s.ss_type; + } + } + this->chain_ = chain; + this->SetSequence(sequence); + } +} + +QVariant SecStrRow::GetData(int column, int role) const +{ + if(column > 0 && column < this->GetSequence().GetLength()){ + if (role==Qt::UserRole){ + QVariant variant; + variant.setValue(secstr_); + return variant; + } + if (role==Qt::UserRole+1){ + return QVariant(this->GetFontSize()); + } + } + return SequenceRow::GetData(column, role); +} + +void SecStrRow::DoubleClicked(int column) +{ + if(column>0){ + column-=1; + if(this->secstr_.size()>0 && column < this->secstr_.size()){ + mol::SecStructure& src_str = this->secstr_[column]; + QVarLengthArray<bool> src_type(3); + src_type[0] = src_str.IsHelical(); + src_type[1] = src_str.IsExtended(); + src_type[2] = src_str.IsCoil(); + int i = column; + QSet<int> cols_to_add; + mol::SecStructure& col_str = this->secstr_[i]; + while(i >= 0 && (col_str = this->secstr_[i])){ + if(src_type[0] == col_str.IsHelical() + && src_type[1] == col_str.IsExtended() + && src_type[2] == col_str.IsCoil()){ + cols_to_add.insert(i+1); + --i; + } + else{break;} + } + i = column + 1; + if(i < this->secstr_.size()){ + while(i < this->secstr_.size() && (col_str = this->secstr_[i])){ + if(src_type[0] == col_str.IsHelical() + && src_type[1] == col_str.IsExtended() + && src_type[2] == col_str.IsCoil()){ + cols_to_add.insert(i+1); + ++i; + } + else{ + break; + } + } + } + this->SetSelection(cols_to_add, QSet<int>()); + } + } + else{ + SequenceRow::DoubleClicked(column); + } +} + +}} diff --git a/modules/gui/src/sequence/secstr_row.hh b/modules/gui/src/sequence/secstr_row.hh new file mode 100644 index 0000000000000000000000000000000000000000..4e3286a77ce15390c8cc47c7c4308731924abd4d --- /dev/null +++ b/modules/gui/src/sequence/secstr_row.hh @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// 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_SECSTR_ROW +#define OST_SEQUENCE_VIEWER_SECSTR_ROW + +/* + Author: Stefan Scheuber + */ + +#include <QObject> +#include <QVarLengthArray> + +#include <ost/mol/chain_view.hh> +#include <ost/mol/alg/sec_structure_segments.hh> + +#include "sequence_row.hh" + +namespace ost { namespace gui { + +class SecStrRow : public SequenceRow +{ + Q_OBJECT + +public: + SecStrRow(const QString& name, mol::ChainView& chain, ViewObject* parent); + + virtual QVariant GetData(int column, int role) const; + virtual void DoubleClicked(int column); + + void SetSequence(seq::SequenceHandle& sequence); + void SetChain(mol::ChainView& chain); + +private: + mol::ChainView chain_; + QVarLengthArray<mol::SecStructure> secstr_; +}; + +typedef QList<BaseRow*> BaseRowList; + +}} + +Q_DECLARE_METATYPE(QVarLengthArray<ost::mol::SecStructure>) + +#endif diff --git a/modules/gui/src/sequence/sequence_row.cc b/modules/gui/src/sequence/sequence_row.cc new file mode 100644 index 0000000000000000000000000000000000000000..6be93018c3572bce633f614f1d7bc42de53f087b --- /dev/null +++ b/modules/gui/src/sequence/sequence_row.cc @@ -0,0 +1,149 @@ +//------------------------------------------------------------------------------ +// 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 <ost/mol/mol.hh> +#include <ost/mol/view_op.hh> + +#include <ost/gfx/entity.hh> + +#include "view_object.hh" +#include "sequence_row.hh" + +namespace ost { namespace gui { + +SequenceRow::SequenceRow(const QString& name, seq::SequenceHandle& sequence, ViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name), sequence_(sequence) +{ } + +SequenceRow::SequenceRow(const QString& name, ViewObject* parent) : BaseRow(QFont("Courier",11),parent), name_(name) +{ } + +int SequenceRow::GetColumnCount() const +{ + return sequence_.GetLength()+1; +} + +void SequenceRow::SetName(const QString& name) +{ + this->name_ = name; +} + +const QString& SequenceRow::GetName() +{ + return this->name_; +} + +void SequenceRow::SetSequence(seq::SequenceHandle& sequence) +{ + this->sequence_ = sequence; +} + +const seq::SequenceHandle& SequenceRow::GetSequence() const +{ + return this->sequence_; +} + +QVariant SequenceRow::GetData(int column, int role) const +{ + if(column<0 || column > sequence_.GetLength())return QVariant(); + + if(column == 0) { + if (role == Qt::DisplayRole){ + return QVariant(this->name_); + } + } + else if(column > 0) { + if (role==Qt::DisplayRole) { + return QVariant(QString(this->sequence_.GetOneLetterCode(column - 1))); + } + if (role==Qt::FontRole){ + return QVariant(this->GetFont()); + } + if (role==Qt::SizeHintRole){ + return QVariant(this->GetCellSize()); + } + } + return QVariant(); +} + +Qt::ItemFlags SequenceRow::Flags(int column) const +{ + if(column<0 || column > this->GetColumnCount())return Qt::NoItemFlags; + + if(column==0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + else if(column>0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return BaseRow::Flags(column); +} + +void SequenceRow::DoubleClicked(int column) +{ + QSet<int> all; + int seq_length = this->sequence_.GetLength(); + for(int i = 0; i < seq_length; i++){ + all.insert(i+1); + } + this->SetSelection(all,QSet<int>()); +} + +void SequenceRow::SetSelection(const QSet<int>& added, const QSet<int>& removed) +{ + ViewObject* view_object = qobject_cast<ViewObject*>(this->parent()); + if(view_object){ + if(gfx::EntityP entity = view_object->GetGfxObject()){ + mol::EntityView sel = entity->GetSelection(); + mol::EntityView view = this->sequence_.GetAttachedView().GetHandle().CreateEmptyView(); + + QSetIterator<int> i(removed); + while (i.hasNext()){ + int column = i.next()-1; + if(column >= 0 && column < this->sequence_.GetLength()){ + if (mol::ResidueView rv = this->sequence_.GetResidue(this->sequence_.GetResidueIndex(column))) { + view.AddResidue(rv, mol::ViewAddFlag::INCLUDE_ATOMS); + } + } + } + sel = mol::Difference(sel,view); + view = this->sequence_.GetAttachedView().GetHandle().CreateEmptyView(); + i = QSetIterator<int>(added); + while (i.hasNext()){ + int column = i.next()-1; + if(column >= 0 && column < this->sequence_.GetLength()){ + if (mol::ResidueView rv=this->sequence_.GetResidue(this->sequence_.GetResidueIndex(column))) { + view.AddResidue(rv, mol::ViewAddFlag::INCLUDE_ATOMS); + } + } + } + sel = mol::Union(sel,view); + sel.AddAllInclusiveBonds(); + entity->SetSelection(sel); + } + } +} + +}} diff --git a/modules/gui/src/sequence/sequence_row.hh b/modules/gui/src/sequence/sequence_row.hh new file mode 100644 index 0000000000000000000000000000000000000000..07c1c1a6e1cec30f56e369200d5aaf69877e67ae --- /dev/null +++ b/modules/gui/src/sequence/sequence_row.hh @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// 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_ROW +#define OST_SEQUENCE_VIEWER_SEQUENCE_ROW + +/* + Author: Stefan Scheuber + */ + +#include <QObject> + +#include <ost/seq/sequence_handle.hh> + +#include "base_row.hh" + +namespace ost { namespace gui { + +class ViewObject; + +class SequenceRow : public BaseRow +{ + Q_OBJECT + +public: + SequenceRow(const QString& name, seq::SequenceHandle& sequence, ViewObject* parent); + SequenceRow(const QString& name, ViewObject* parent); + + virtual int GetColumnCount() const; + + virtual QVariant GetData(int column, int role) const; + virtual Qt::ItemFlags Flags(int column) const; + virtual void DoubleClicked(int column); + + void SetName(const QString& name); + const QString& GetName(); + + virtual void SetSequence(seq::SequenceHandle& sequence); + const seq::SequenceHandle& GetSequence() const; + + void SetSelection(const QSet<int>& added, const QSet<int>& removed); + +private: + QString name_; + seq::SequenceHandle sequence_; +}; + +typedef QList<BaseRow*> BaseRowList; + +}} + +#endif