From 392e89f3ec5f716905ed4ec80282c6d06827a073 Mon Sep 17 00:00:00 2001
From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Mon, 3 May 2010 10:53:09 +0000
Subject: [PATCH] New SequenceViewer -Added Background Color for TableItems

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2162 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/gui/src/CMakeLists.txt                |  3 ++
 .../gui/src/sequence/seq_selection_painter.cc | 49 +++++++++++++++++++
 .../gui/src/sequence/seq_selection_painter.hh | 43 ++++++++++++++++
 modules/gui/src/sequence/view_object.cc       |  7 ++-
 4 files changed, 100 insertions(+), 2 deletions(-)
 create mode 100644 modules/gui/src/sequence/seq_selection_painter.cc
 create mode 100644 modules/gui/src/sequence/seq_selection_painter.hh

diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt
index 83cc8752a..01ed36015 100644
--- a/modules/gui/src/CMakeLists.txt
+++ b/modules/gui/src/CMakeLists.txt
@@ -23,6 +23,7 @@ sequence_search_bar.hh
 set(OST_GUI_SEQUENCE_VIEW_HEADERS
 painter.hh
 row.hh
+seq_selection_painter.hh
 seq_text_painter.hh
 sequence_delegate.hh
 sequence_model.hh
@@ -205,6 +206,7 @@ sequence_viewer/sequence_viewer.cc
 sequence_viewer/sequence_scene.cc
 sequence_viewer/sequence_search_bar.cc
 sequence/row.cc
+sequence/seq_selection_painter.cc
 sequence/seq_text_painter.cc
 sequence/sequence_delegate.cc
 sequence/sequence_model.cc
@@ -329,6 +331,7 @@ sequence_viewer/sequence_scene.hh
 sequence_viewer/sequence_search_bar.hh
 sequence/painter.hh
 sequence/row.hh
+sequence/seq_selection_painter.hh
 sequence/seq_text_painter.hh
 sequence/sequence_delegate.hh
 sequence/sequence_model.hh
diff --git a/modules/gui/src/sequence/seq_selection_painter.cc b/modules/gui/src/sequence/seq_selection_painter.cc
new file mode 100644
index 000000000..e0d5675c9
--- /dev/null
+++ b/modules/gui/src/sequence/seq_selection_painter.cc
@@ -0,0 +1,49 @@
+//------------------------------------------------------------------------------
+// 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 "seq_selection_painter.hh"
+
+namespace ost { namespace gui {
+
+SeqSelectionPainter::SeqSelectionPainter(QObject* parent)
+    : Painter(parent)
+{}
+
+void SeqSelectionPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){
+  painter->save();
+  if (option.state & QStyle::State_HasFocus){
+    painter->fillRect(option.rect, QColor(240,240,0,60));
+  }
+  if (option.state & QStyle::State_MouseOver){
+    painter->fillRect(option.rect, QColor(240,240,240,128));
+  }
+  if (option.state & QStyle::State_Selected){
+    painter->fillRect(option.rect, QColor(0,240,0,128));
+  }
+  painter->restore();
+}
+
+}}
diff --git a/modules/gui/src/sequence/seq_selection_painter.hh b/modules/gui/src/sequence/seq_selection_painter.hh
new file mode 100644
index 000000000..416f423c0
--- /dev/null
+++ b/modules/gui/src/sequence/seq_selection_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_SEQ_SELECTION_PAINTER
+#define OST_SEQUENCE_VIEWER_SEQ_SELECTION_PAINTER
+
+/*
+  Author: Stefan Scheuber
+ */
+
+#include <QObject>
+
+#include "painter.hh"
+
+namespace ost { namespace gui {
+
+class SeqSelectionPainter : public Painter
+{
+  Q_OBJECT
+public:
+  SeqSelectionPainter(QObject* parent = 0);
+  void Paint(QPainter *painter, const QStyleOptionViewItem &option,
+      const QModelIndex &index);
+};
+
+}}
+
+#endif
diff --git a/modules/gui/src/sequence/view_object.cc b/modules/gui/src/sequence/view_object.cc
index c3bd14e0c..43d6601e0 100644
--- a/modules/gui/src/sequence/view_object.cc
+++ b/modules/gui/src/sequence/view_object.cc
@@ -26,6 +26,7 @@
 
 #include "painter.hh"
 #include "seq_text_painter.hh"
+#include "seq_selection_painter.hh"
 
 #include "view_object.hh"
 
@@ -91,8 +92,10 @@ int ViewObject::GetRowCount()
 void ViewObject::AddSequence(seq::SequenceHandle& sequence)
 {
   Row* new_row = new Row(this);
-  Painter* p = new SeqTextPainter(this);
-  new_row->InsertPainter(p,0);
+  Painter* p = new SeqSelectionPainter(this);
+  new_row->InsertPainter(p);
+  p = new SeqTextPainter(this);
+  new_row->InsertPainter(p);
   QPair<Row*, seq::SequenceHandle> pair(new_row,sequence);
   rows_.append(pair);
 }
-- 
GitLab