#include <QFileDialog>
#include <QMessageBox>
#include <QMouseEvent>
+#include <QWheelEvent>
#include <QRubberBand>
#include <QRect>
#include <QString>
SequenceBrowser::SequenceBrowser(QWidget *parent)
: QGLWidget(parent),
rubberBand(0),
- popupMenu(new QMenu(this)),
- copySelectedSequenceAsFastaAction(new QAction(tr("&Copy as Fasta"), this)),
- copySelectedSequenceAsStringAction(new QAction(tr("&Copy Sequence"), this))
+ popupMenu(0),
+ copySelectedSequenceAsFastaAction(0),
+ copySelectedSequenceAsStringAction(0),
+ editSequencePropertiesAction(0),
+ clearSelectionAction(0)
{
+ popupMenu = new QMenu(this);
+ copySelectedSequenceAsFastaAction = new QAction(tr("&Copy as Fasta"), this);
connect(copySelectedSequenceAsFastaAction, SIGNAL(triggered()),
this, SLOT(copySelectedSequenceAsFasta()));
popupMenu->addAction(copySelectedSequenceAsFastaAction);
+
+ copySelectedSequenceAsStringAction = new QAction(tr("&Copy Sequence"), this);
copySelectedSequenceAsStringAction->setShortcut(Qt::CTRL | Qt::Key_C);
connect(copySelectedSequenceAsStringAction, SIGNAL(triggered()),
this, SLOT(copySelectedSequenceAsString()));
popupMenu->addAction(copySelectedSequenceAsStringAction);
+
+ // connect edit properties action
+ editSequencePropertiesAction = new QAction(tr("Sequence &Properties"), this);
+ connect(editSequencePropertiesAction, SIGNAL(triggered()),
+ this, SLOT(editSequenceProperties()));
+
+ clearSelectionAction = new QAction(tr("Clear Selection"), this);
+ clearSelectionAction->setShortcut(Qt::Key_Escape);
+ connect(clearSelectionAction, SIGNAL(triggered()),
+ this, SLOT(clearSelection()));
+ this->addAction(clearSelectionAction);
+
}
SequenceBrowser::SequenceBrowser(const SequenceBrowser& sb, QWidget *parent)
GlSeqBrowser(sb),
rubberBand(sb.rubberBand),
popupMenu(sb.popupMenu),
- copySelectedSequenceAsFastaAction(sb.copySelectedSequenceAsFastaAction)
+ copySelectedSequenceAsFastaAction(sb.copySelectedSequenceAsFastaAction),
+ copySelectedSequenceAsStringAction(sb.copySelectedSequenceAsStringAction),
+ editSequencePropertiesAction(sb.editSequencePropertiesAction),
+ clearSelectionAction(sb.clearSelectionAction)
{
resize(sb.width(), sb.height());
setZoom(sb.zoom());
return copySelectedSequenceAsStringAction;
}
+QAction *SequenceBrowser::getEditSequencePropertiesAction()
+{
+ return editSequencePropertiesAction;
+}
+
QSize SequenceBrowser::sizeHint() const
{
- //return QSize((int)GlSeqBrowser::viewportHeight(), (int)GlSeqBrowser::viewportWidth());
- return QSize(600, 400);
+ return QSize(viewportPixelWidth(), viewportPixelHeight());
}
void SequenceBrowser::setViewportCenter(float x)
popupMenu->popup(point);
}
+void SequenceBrowser::editSequenceProperties()
+{
+ // if there's a previous window, disconnect its signal
+ if (properties) {
+ disconnect(properties.get(), SIGNAL(propertiesChanged()),
+ this, SLOT(updateGL()));
+ }
+ PropertiesWindowRef new_properties(new PropertiesWindow(track_container));
+ properties = new_properties;
+ connect(properties.get(), SIGNAL(propertiesChanged()),
+ this, SLOT(updateGL()));
+ properties->show();
+}
+
void SequenceBrowser::push_sequence(boost::shared_ptr<Sequence> s)
{
GlSeqBrowser::push_sequence(s);
selectedCanvasRegion = r;
}
}
+
+void SequenceBrowser::wheelEvent(QWheelEvent *e)
+{
+ e->accept();
+ double cur_zoom = GlSeqBrowser::zoom();
+
+ // Normalize so one 15 degree turn of the mouse wheel
+ // is equal to 1 step.
+ int num_degrees = e->delta() / 8;
+ int num_steps = num_degrees / 15;
+
+ // Positive
+ if (num_steps >= 0)
+ {
+ // Invert number of steps because code was written
+ // thinking that adding a positve num_steps was zooming
+ // in, but because it's bp/pixel, it's actually zooming out.
+ // To get mouse wheel to zoom in, when pushing the wheel
+ // forward, I can use the existing code, by making num_steps
+ // negative here.
+ num_steps = num_steps * (-1);
+
+ if (cur_zoom + num_steps >= 1.0)
+ {
+ emit mouseWheelZoom(cur_zoom + num_steps);
+ }
+ else if (cur_zoom > 1.0 && cur_zoom + num_steps < 1.0)
+ {
+ emit mouseWheelZoom(1.0);
+ }
+ else if (cur_zoom <= 0.1)
+ {
+ emit mouseWheelZoom(cur_zoom + ((double)num_steps*0.01));
+ }
+ else if (cur_zoom <= 1.0 && cur_zoom + ((double)num_steps*0.1) >= 0.1)
+ {
+ emit mouseWheelZoom(cur_zoom + ((double)num_steps*0.1));
+ }
+ else if (cur_zoom <= 1.0 && cur_zoom + ((double)num_steps*0.1) < 0.1)
+ {
+ emit mouseWheelZoom(0.1);
+ }
+
+ }
+ // Negative
+ else
+ {
+
+ // Invert number of steps because code was written
+ // thinking that adding a positve num_steps was zooming
+ // in, but because it's bp/pixel, it's actually zooming out.
+ // To get mouse wheel to zoom out, when pulling the wheel
+ // backwards, I can use the existing code, by making num_steps
+ // positive here.
+ num_steps = num_steps * (-1);
+
+ if (cur_zoom >= 1.0)
+ {
+ emit mouseWheelZoom(cur_zoom+num_steps);
+ }
+ else if (cur_zoom < 1.0 && cur_zoom >= 0.1)
+ {
+ emit mouseWheelZoom(cur_zoom + ((double)num_steps*0.1));
+ }
+ else if (cur_zoom < 0.1)
+ {
+ emit mouseWheelZoom(cur_zoom + ((double)num_steps*0.01));
+ }
+
+ }
+
+ //cout << "Mouse wheel delta: " << num_degrees << "; " << num_steps << "\n";
+}
+
+void SequenceBrowser::clearSelection()
+{
+ GlSeqBrowser::clearSelection();
+ if (rubberBand and rubberBand->isVisible()) {
+ rubberBand->hide();
+ }
+ updateGL();
+}