From be1208adb2f6c6ce52f1b07afd412a02925c270a Mon Sep 17 00:00:00 2001 From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Wed, 5 May 2010 13:27:06 +0000 Subject: [PATCH] New SequenceViewer, fixed selection from first row and first column, added ticks git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2178 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gui/src/CMakeLists.txt | 6 ++ modules/gui/src/sequence/secstr_row.hh | 3 - .../gui/src/sequence/seq_selection_painter.cc | 8 ++ modules/gui/src/sequence/sequence_model.cc | 3 + modules/gui/src/sequence/sequence_row.hh | 2 - .../gui/src/sequence/sequence_table_view.cc | 20 +++-- .../gui/src/sequence/sequence_table_view.hh | 5 +- modules/gui/src/sequence/sequence_viewer.cc | 3 +- modules/gui/src/sequence/tick_painter.cc | 56 +++++++++++++ modules/gui/src/sequence/tick_painter.hh | 43 ++++++++++ modules/gui/src/sequence/title_row.cc | 79 +++++++++++++++++++ modules/gui/src/sequence/title_row.hh | 45 +++++++++++ modules/gui/src/sequence/view_object.cc | 10 +++ modules/gui/src/sequence/view_object.hh | 1 + 14 files changed, 269 insertions(+), 15 deletions(-) create mode 100644 modules/gui/src/sequence/tick_painter.cc create mode 100644 modules/gui/src/sequence/tick_painter.hh create mode 100644 modules/gui/src/sequence/title_row.cc create mode 100644 modules/gui/src/sequence/title_row.hh diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index f646e95be..41e0c9901 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -32,6 +32,8 @@ sequence_model.hh sequence_row.hh sequence_table_view.hh sequence_viewer.hh +tick_painter.hh +title_row.hh view_object.hh ) @@ -218,6 +220,8 @@ sequence/sequence_model.cc sequence/sequence_row.cc sequence/sequence_table_view.cc sequence/sequence_viewer.cc +sequence/tick_painter.cc +sequence/title_row.cc sequence/view_object.cc gosty_app.cc change_process_name.cc @@ -346,6 +350,8 @@ sequence/sequence_model.hh sequence/sequence_row.hh sequence/sequence_table_view.hh sequence/sequence_viewer.hh +sequence/tick_painter.hh +sequence/title_row.hh sequence/view_object.hh plot_viewer/plot_axis_base.hh plot_viewer/plot_data_graphics_item_base.hh diff --git a/modules/gui/src/sequence/secstr_row.hh b/modules/gui/src/sequence/secstr_row.hh index 761bb9ac2..f52766032 100644 --- a/modules/gui/src/sequence/secstr_row.hh +++ b/modules/gui/src/sequence/secstr_row.hh @@ -51,9 +51,6 @@ private: mol::ChainView chain_; QVarLengthArray<mol::SecStructure> secstr_; }; - -typedef QList<BaseRow*> BaseRowList; - }} #endif diff --git a/modules/gui/src/sequence/seq_selection_painter.cc b/modules/gui/src/sequence/seq_selection_painter.cc index e0d5675c9..e9b0c4d5c 100644 --- a/modules/gui/src/sequence/seq_selection_painter.cc +++ b/modules/gui/src/sequence/seq_selection_painter.cc @@ -34,6 +34,14 @@ SeqSelectionPainter::SeqSelectionPainter(QObject* parent) void SeqSelectionPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){ painter->save(); + if ((index.column()-1)%10 > 4){ + painter->fillRect(option.rect, QColor(240,240,240)); + + } + if((index.column())%10 == 0){ + painter->setPen(QPen(QColor(135,135,135))); + painter->drawLine(option.rect.topRight(),option.rect.bottomRight()); + } if (option.state & QStyle::State_HasFocus){ painter->fillRect(option.rect, QColor(240,240,0,60)); } diff --git a/modules/gui/src/sequence/sequence_model.cc b/modules/gui/src/sequence/sequence_model.cc index ef91c46c0..75d05f4aa 100644 --- a/modules/gui/src/sequence/sequence_model.cc +++ b/modules/gui/src/sequence/sequence_model.cc @@ -33,6 +33,9 @@ namespace ost { namespace gui { SequenceModel::SequenceModel(QObject *parent) : QAbstractTableModel(parent), max_columns(0) { + this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()); + objects_.append(new ViewObject(this)); + this->endInsertRows(); } void SequenceModel::InsertSequence(QString& name, seq::SequenceHandle& seq){ diff --git a/modules/gui/src/sequence/sequence_row.hh b/modules/gui/src/sequence/sequence_row.hh index 589207796..f7727d5e2 100644 --- a/modules/gui/src/sequence/sequence_row.hh +++ b/modules/gui/src/sequence/sequence_row.hh @@ -60,8 +60,6 @@ private: seq::SequenceHandle sequence_; }; -typedef QList<BaseRow*> BaseRowList; - }} #endif diff --git a/modules/gui/src/sequence/sequence_table_view.cc b/modules/gui/src/sequence/sequence_table_view.cc index 80018d8db..8559eb00d 100644 --- a/modules/gui/src/sequence/sequence_table_view.cc +++ b/modules/gui/src/sequence/sequence_table_view.cc @@ -83,7 +83,7 @@ void SequenceTableView::InitStaticColumn() static_column_->horizontalHeader()->hide(); //this->viewport()->stackUnder(static_column_); - + static_column_->setSelectionBehavior(SelectRows); static_column_->setSelectionModel(this->selectionModel()); for(int col=1; col<this->model()->columnCount(); col++){ static_column_->setColumnHidden(col, true); @@ -95,7 +95,7 @@ void SequenceTableView::InitStaticColumn() static_column_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); static_column_->show(); static_column_->setStyleSheet("QTableView { border: 0px;" - "background-color: #ff0000;" + "background-color: #EDEDED;" "selection-background-color: #EEEEEE}" "QTableView::item{ border: none;" "padding: 0px; border-width: 0px; margin: 0px;}"); @@ -118,6 +118,7 @@ void SequenceTableView::InitStaticRow() static_row_->horizontalHeader()->hide(); static_row_->verticalHeader()->hide(); + static_row_->setSelectionBehavior(SelectColumns); static_row_->setSelectionModel(this->selectionModel()); for(int row=1; row<this->model()->rowCount(); row++){ static_row_->setRowHidden(row, true); @@ -129,7 +130,7 @@ void SequenceTableView::InitStaticRow() static_row_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); static_row_->show(); static_row_->setStyleSheet("QTableView { border: 0px;" - "background-color: #00ff00;" + "background-color: #EDEDED;" "selection-background-color: #EEEEEE}" "QTableView::item{ border: none;" "padding: 0px; border-width: 0px; margin: 0px;}"); @@ -137,6 +138,8 @@ void SequenceTableView::InitStaticRow() static_row_->setHorizontalScrollMode(ScrollPerPixel); + static_row_->setItemDelegate(delegate_); + connect(static_row_->horizontalScrollBar(), SIGNAL(valueChanged(int)), this->horizontalScrollBar(), SLOT(setValue(int))); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), static_row_->horizontalScrollBar(), SLOT(setValue(int))); @@ -166,7 +169,7 @@ void SequenceTableView::InitStaticField(){ static_field_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); static_field_->show(); static_field_->setStyleSheet("QTableView { border: 0px;" - "background-color: #0000ff;" + "background-color: #E0E0E0;" "selection-background-color: #EEEEEE}" "QTableView::item{ border: none;" "padding: 0px; border-width: 0px; margin: 0px;}"); @@ -271,7 +274,6 @@ void SequenceTableView::columnCountChanged(const QModelIndex& index, int old_cou static_field_->setColumnHidden(col,true); this->setItemDelegateForColumn(col, delegate_); } - this->setItemDelegateForRow(0, new QItemDelegate(this)); } } @@ -310,14 +312,18 @@ void SequenceTableView::resizeRowsToContents(){ this->updateStaticField(); } -QTableView* SequenceTableView::GetFirstRow(){ +QTableView* SequenceTableView::GetStaticRow(){ return static_row_; } -QTableView* SequenceTableView::GetFirstColumn(){ +QTableView* SequenceTableView::GetStaticColumn(){ return static_column_; } +QTableView* SequenceTableView::GetStaticField(){ + return static_field_; +} + void SequenceTableView::mouseDoubleClickEvent(QMouseEvent *event) { QModelIndex index = indexAt(event->pos()); diff --git a/modules/gui/src/sequence/sequence_table_view.hh b/modules/gui/src/sequence/sequence_table_view.hh index f56248c03..3d55cd861 100644 --- a/modules/gui/src/sequence/sequence_table_view.hh +++ b/modules/gui/src/sequence/sequence_table_view.hh @@ -36,8 +36,9 @@ class DLLEXPORT_OST_GUI SequenceTableView : public QTableView { Q_OBJECT public: SequenceTableView(QAbstractItemModel * model); - QTableView* GetFirstRow(); - QTableView* GetFirstColumn(); + QTableView* GetStaticRow(); + QTableView* GetStaticColumn(); + QTableView* GetStaticField(); ~SequenceTableView(); public slots: diff --git a/modules/gui/src/sequence/sequence_viewer.cc b/modules/gui/src/sequence/sequence_viewer.cc index 13dc41e65..391bfa443 100644 --- a/modules/gui/src/sequence/sequence_viewer.cc +++ b/modules/gui/src/sequence/sequence_viewer.cc @@ -62,7 +62,8 @@ SequenceViewerV2::SequenceViewerV2(QWidget* parent): Widget(NULL,parent) seq_table_view_->setSelectionMode(QAbstractItemView::ExtendedSelection); connect(seq_table_view_->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(SelectionModelChanged(const QItemSelection&, const QItemSelection&))); connect(seq_table_view_,SIGNAL(doubleClicked(const QModelIndex&)),model_,SLOT(DoubleClicked(const QModelIndex&))); - connect(seq_table_view_->GetFirstColumn(),SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(DoubleClicked(const QModelIndex&))); + connect(seq_table_view_->GetStaticColumn(),SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(DoubleClicked(const QModelIndex&))); + connect(seq_table_view_->GetStaticRow(),SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(DoubleClicked(const QModelIndex&))); } void SequenceViewerV2::NodeAdded(const gfx::GfxNodeP& n) diff --git a/modules/gui/src/sequence/tick_painter.cc b/modules/gui/src/sequence/tick_painter.cc new file mode 100644 index 000000000..770a34577 --- /dev/null +++ b/modules/gui/src/sequence/tick_painter.cc @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// 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 "tick_painter.hh" + +namespace ost { namespace gui { + +TickPainter::TickPainter(QObject* parent) + : Painter(parent) +{} + +void TickPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){ + painter->save(); + painter->setPen(QPen(Qt::red)); + QVariant value = index.data(Qt::DisplayRole); + if (value.isValid()){ + if(index.column()%10==0 || index.column()%10==1){ + QRect rect = option.rect; + QString text = value.toString(); + if(index.column()%10==0){ + rect.setRight(rect.right()+rect.width()); + } + else{ + rect.setLeft(rect.left()-rect.width()); + } + painter->setFont(index.data(Qt::FontRole).value<QFont>()); + painter->drawText(rect, Qt::AlignLeft|Qt::AlignBottom, text); + } + } + painter->restore(); +} + +}} diff --git a/modules/gui/src/sequence/tick_painter.hh b/modules/gui/src/sequence/tick_painter.hh new file mode 100644 index 000000000..3f5b104c2 --- /dev/null +++ b/modules/gui/src/sequence/tick_painter.hh @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// 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_TICK_PAINTER +#define OST_SEQUENCE_VIEWER_TICK_PAINTER + +/* + Author: Stefan Scheuber + */ + +#include <QObject> + +#include "painter.hh" + +namespace ost { namespace gui { + +class TickPainter : public Painter +{ + Q_OBJECT +public: + TickPainter(QObject* parent = 0); + void Paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index); +}; + +}} + +#endif diff --git a/modules/gui/src/sequence/title_row.cc b/modules/gui/src/sequence/title_row.cc new file mode 100644 index 000000000..d10dceeed --- /dev/null +++ b/modules/gui/src/sequence/title_row.cc @@ -0,0 +1,79 @@ +//------------------------------------------------------------------------------ +// 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 "sequence_model.hh" +#include "title_row.hh" + +namespace ost { namespace gui { + +TitleRow::TitleRow(QObject* parent) : BaseRow(QFont("Courier",10),parent) +{ } + +QVariant TitleRow::GetData(int column, int role) const +{ + column -= 1; + if(column<0){ + return QVariant(); + } + else if(role==Qt::DisplayRole && column%10==9){ + return QVariant(QString::number(column+1)); + } + else if(role==Qt::DisplayRole && column%10==0){ + return QVariant(QString::number(column)); + } + else if (role==Qt::FontRole){ + return QVariant(QFont("Verdana",8)); + } + else if (role==Qt::TextAlignmentRole){ + return QVariant(Qt::AlignHCenter|Qt::AlignBottom); + } + else if (role==Qt::SizeHintRole){ + QSize size = this->GetCellSize(); + size.setHeight(10); + return QVariant(size); + } + return BaseRow::GetData(column, role); +} + +Qt::ItemFlags TitleRow::Flags(int column) const +{ + if(column>=0){ + return Qt::ItemIsSelectable|Qt::ItemIsEnabled; + } + return BaseRow::Flags(column); +} + +void TitleRow::DoubleClicked(int column) +{ + if(this->parent()){ + SequenceModel* model = qobject_cast<SequenceModel*>(this->parent()->parent()); + int rows = model->rowCount()-1; + QItemSelection add = QItemSelection(model->index(1,column),model->index(rows,column)); + model->SelectionChanged(add,QItemSelection()); + } +} + +}} diff --git a/modules/gui/src/sequence/title_row.hh b/modules/gui/src/sequence/title_row.hh new file mode 100644 index 000000000..f3ad8796f --- /dev/null +++ b/modules/gui/src/sequence/title_row.hh @@ -0,0 +1,45 @@ +//------------------------------------------------------------------------------ +// 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_TITLE_ROW +#define OST_SEQUENCE_VIEWER_TITLE_ROW + +/* + Author: Stefan Scheuber + */ + +#include <QObject> + +#include "base_row.hh" + +namespace ost { namespace gui { + +class TitleRow : public BaseRow +{ + Q_OBJECT + +public: + TitleRow(QObject* parent); + + virtual QVariant GetData(int column, int role) const; + virtual Qt::ItemFlags Flags(int column) const; + virtual void DoubleClicked(int column); +}; +}} + +#endif diff --git a/modules/gui/src/sequence/view_object.cc b/modules/gui/src/sequence/view_object.cc index a69f29a90..c30dabe50 100644 --- a/modules/gui/src/sequence/view_object.cc +++ b/modules/gui/src/sequence/view_object.cc @@ -29,11 +29,13 @@ #include "sequence_row.hh" #include "secstr_row.hh" +#include "title_row.hh" #include "painter.hh" #include "seq_secstr_painter.hh" #include "seq_selection_painter.hh" #include "seq_text_painter.hh" +#include "tick_painter.hh" #include "view_object.hh" @@ -73,6 +75,14 @@ ViewObject::ViewObject(gfx::EntityP& entity, QObject* parent): QObject(parent), } } +ViewObject::ViewObject(QObject* parent): QObject(parent) +{ + TitleRow* new_row = new TitleRow(this); + Painter* p = new TickPainter(this); + new_row->InsertPainter(p); + rows_.append(new_row); +} + void ViewObject::InsertRow(int pos, BaseRow* row) { if(pos >= 0 && pos <= rows_.size()){ diff --git a/modules/gui/src/sequence/view_object.hh b/modules/gui/src/sequence/view_object.hh index 311b4ff83..f623ab16c 100644 --- a/modules/gui/src/sequence/view_object.hh +++ b/modules/gui/src/sequence/view_object.hh @@ -52,6 +52,7 @@ public: ViewObject(seq::SequenceHandle& sequence, const QString& name, QObject* parent = 0); ViewObject(mol::ChainView& chain, const QString& name, QObject* parent = 0); ViewObject(gfx::EntityP& entity, QObject* parent = 0); + ViewObject(QObject* parent = 0); void InsertRow(int pos, BaseRow* row); void RemoveRow(BaseRow* row); -- GitLab