diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 48bf020a3f17fbe8e2cd995e0eba580ef624987c..b8c52717944cf7a72b1a39ad2f54f7921b6cabdc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,12 +78,11 @@ set(QTLIBS ${Qt5Xml_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Svg_LIBRARIES}) # we need this to be able to include headers produced by uic in our code # (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) -INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) SET(XTPCPP_SRCS ./gui/mainwindow.cpp ./gui/peptide_detail_view/peptidewindow.cpp + ./gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp ./gui/peptide_list_view/peptidelistwindow.cpp ./gui/peptide_list_view/peptidetablemodel.cpp ./gui/peptide_list_view/peptidetableproxymodel.cpp @@ -107,6 +106,7 @@ SET(XTPCPP_MOC_HDRS ./gui/mainwindow.h ./gui/peptide_detail_view/peptidewindow.h + ./gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h ./gui/peptide_list_view/peptidelistwindow.h ./gui/peptide_list_view/peptidetablemodel.h ./gui/peptide_list_view/peptidetableproxymodel.h @@ -128,7 +128,8 @@ MESSAGE("XTPCPP_SRCS: ${XTPCPP_SRCS}") ADD_EXECUTABLE(xtpcpp main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${XTPCPP_MOC_SRCS} ${xtpcpp_RCC_SRCS}) -target_include_directories (xtpcpp PUBLIC ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTSVG_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR}) +target_include_directories (xtpcpp PUBLIC ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTSVG_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} +${CMAKE_CURRENT_BINARY_DIR}/gui/peptide_detail_view/spectrum_widget ${CMAKE_CURRENT_SOURCE_DIR}/gui/peptide_detail_view/spectrum_widget) SET_TARGET_PROPERTIES(xtpcpp PROPERTIES OUTPUT_NAME xtpcpp CLEAN_DIRECT_OUTPUT 1 diff --git a/src/gui/peptide_detail_view/peptide_detail_view.ui b/src/gui/peptide_detail_view/peptide_detail_view.ui index 9e7cad20f52da6518638a4b5b800cb1529fd6b59..14c4e4d61a32924cf0613c672c2039761a259abd 100644 --- a/src/gui/peptide_detail_view/peptide_detail_view.ui +++ b/src/gui/peptide_detail_view/peptide_detail_view.ui @@ -125,23 +125,29 @@ </layout> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"/> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + + <widget class="QSpectrumWidget" name="spectrumWidget" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_8"/> + </item> + </layout> + </item> + </layout> </item> </layout> </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> diff --git a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edb9a03b458ecc735ab604d1a7de3d6c3bc30c94 --- /dev/null +++ b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp @@ -0,0 +1,143 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* PAPPSOms-tools 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ +#include "overlaywidget.h" +#include <QDebug> + + + +void LoadingOverlay::paintLoadingMessage(QPainter &painter) { + + if (_is_loading) { + //p.fillRect(rect(), QColor(100, 100, 100, 128)); + painter.setPen(QColor(200, 200, 255, 255)); + painter.setFont(QFont("arial,helvetica", 48)); + painter.drawText(rect(), "Loading...", Qt::AlignHCenter | Qt::AlignVCenter); + } +} +void LoadingOverlay::displayLoadingMessage() { + _is_loading= true; +} +void LoadingOverlay::hideLoadingMessage() { + _is_loading= false; +} +void LoadingOverlay::paintEvent(QPaintEvent *) { + QPainter painter; + + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + paintLoadingMessage(painter); + paintUserSelectedZone(painter); + painter.end(); +} +void LoadingOverlay::mousePressEvent(QMouseEvent * event) { + + qDebug() << " LoadingOverlay::mousePressEvent"; + + _pressed = true; + _first_point.first = event->x(); + _first_point.second = event->y(); + _current_mouse_mz = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(event->x()); + + _second_point.first = 0; + emit mzChanged(_current_mouse_mz); + update(); +} + + +void LoadingOverlay::mouseReleaseEvent(QMouseEvent * event) { + + qDebug() << " LoadingOverlay::mouseReleaseEvent"; + _pressed = false; + // _press_mz = _spectrum_painter.getMzFromLocalPosX(event->x()); + //_second_point.first = event->x(); + //_second_point.second = event->y(); + if (_second_point.first > 0) { + mz min = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(_first_point.first); + mz max = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(_second_point.first); + if (max < min) { + swap(min,max); + } + pappso_double max_intensity = _p_spectrum_widget->getSpectrumPainter().getIntensityFromLocalPosY(_second_point.second); + _p_spectrum_widget->getSpectrumPainter().setMinMz(min); + _p_spectrum_widget->getSpectrumPainter().setMaxMz(max); + _p_spectrum_widget->getSpectrumPainter().setMaxIntensity(max_intensity); + } + else { + _p_spectrum_widget->getSpectrumPainter().setMaxMz(0); + } + _second_point.first = 0; + update(); + +} +void LoadingOverlay::mouseMoveEvent(QMouseEvent * event) { + qDebug() << "LoadingOverlay::mouseMoveEvent" << event->x(); + mz new_mz = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(event->x()); + + if (_pressed) { + int min = _p_spectrum_widget->getSpectrumPainter().getMarginLeft(); + _second_point.first = event->x(); + if (_second_point.first < min) { + _second_point.first = min; + } + int max = this->size().width(); + if (_second_point.first > max) { + _second_point.first = max; + } + _second_point.second = event->y(); + + if (_second_point.second < 0) { + _second_point.second = 0; + } + + max = _p_spectrum_widget->getSpectrumPainter().getLocalPosYFromIntensity(0); + if (_second_point.second > max) { + _second_point.second = max; + } + + _first_point.second = _p_spectrum_widget->getSpectrumPainter().getLocalPosYFromIntensity(0); + } + // if (_current_mouse_mz != new_mz) { + _current_mouse_mz = new_mz; + qDebug() << "LoadingOverlay::mouseMoveEvent emit mzChanged(_current_mouse_mz)" ; + emit mzChanged(_current_mouse_mz); + + // if (_press_mz > 0) { + update(); + + // } + // } +} + + +void LoadingOverlay::paintUserSelectedZone(QPainter & painter) { + if (_second_point.first > 0) { + painter.setPen(QColor("red")); + QRect rect(_first_point.first, _first_point.second, _second_point.first-_first_point.first, _second_point.second-_first_point.second); + painter.drawRect(rect); + + // show the classname of the widget + QBrush translucentBrush(QColor(255,246,240, 100)); + painter.fillRect(rect, translucentBrush); + } + +} diff --git a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h new file mode 100644 index 0000000000000000000000000000000000000000..0b264f154f57b26a41cea8286f0acce7207b6611 --- /dev/null +++ b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h @@ -0,0 +1,103 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* PAPPSOms-tools 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#ifndef OVERLAYWIDGET_H +#define OVERLAYWIDGET_H +#include <QApplication> +#include <QMainWindow> +#include <QResizeEvent> +#include <QPainter> + +#include "qspectrumwidget.h" + +class OverlayWidget : public QWidget +{ +public: + explicit OverlayWidget(QWidget * parent = 0) : QWidget(parent) { + if (parent) { + parent->installEventFilter(this); + raise(); + } + } +protected: + //! Catches resize and child events from the parent widget + bool eventFilter(QObject * obj, QEvent * ev) { + if (obj == parent()) { + if (ev->type() == QEvent::Resize) { + QResizeEvent * rev = static_cast<QResizeEvent*>(ev); + resize(rev->size()); + } + else if (ev->type() == QEvent::ChildAdded) { + raise(); + } + } + return QWidget::eventFilter(obj, ev); + } + //! Tracks parent widget changes + bool event(QEvent* ev) { + if (ev->type() == QEvent::ParentAboutToChange) { + if (parent()) parent()->removeEventFilter(this); + } + else if (ev->type() == QEvent::ParentChange) { + if (parent()) { + parent()->installEventFilter(this); + raise(); + } + } + return QWidget::event(ev); + } +}; + +class LoadingOverlay : public OverlayWidget +{ + Q_OBJECT +public: + LoadingOverlay(QSpectrumWidget * parent) : OverlayWidget(parent) { + // setAttribute(Qt::WA_TranslucentBackground); + _p_spectrum_widget =parent; + setMouseTracking(true); + } + void displayLoadingMessage(); + void hideLoadingMessage(); +protected: + void paintEvent(QPaintEvent *) override; + void mouseReleaseEvent(QMouseEvent * event) override; + void mousePressEvent(QMouseEvent * event) override; + void mouseMoveEvent(QMouseEvent * event) override; +signals: + void mzChanged(double mz); +private : + void paintLoadingMessage(QPainter & painter); + void paintUserSelectedZone(QPainter & painter); +private: + bool _pressed = false; + QSpectrumWidget * _p_spectrum_widget; + mz _current_mouse_mz; + bool _is_loading=false; + + std::pair<int, int> _first_point; + std::pair<int, int> _second_point; + +}; + +#endif // OVERLAYWIDGET_H diff --git a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92219efef566f69440c4d6fad003106e4400fc89 --- /dev/null +++ b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp @@ -0,0 +1,105 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* PAPPSOms-tools 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#include "qspectrumwidget.h" +#include <QStyleOption> +#include <pappsomspp/peptide/peptidefragmentionlistbase.h> +#include <pappsomspp/peptide/peptidestrparser.h> + +#include "../../utils/readspectrum.h" + + +QSpectrumWidget::QSpectrumWidget(QWidget *parent) + : QWidget(parent) +{ + qDebug() << "QSpectrumWidget::QSpectrumWidget begin"; + //_ion_list = PeptideFragmentIonListBase::getCIDionList(); + + //_peptide_sp = PeptideStrParser::parseString("AIADGSLLDLLR"); + + //_spectrum_sp = readSpectrum("../../pappsomspp/test/data/peaklist_15046.mgf", 0, _zmax).makeSpectrumSp(); + + unsigned int zmax=3; + + _spectrum_painter.setPeptideSp(Peptide("A").makePeptideSp()); + // _spectrum_painter.setSpectrumSp(Spectrum().makeSpectrumSp()); + + _spectrum_painter.setParentIonCharge(zmax); + _spectrum_painter.setIonList(PeptideFragmentIonListBase::getCIDionList()); + //_spectrum_painter.setPrecision(_p_precision); + + + setMouseTracking(true); + + //SvgSpectrum svgspectrum(_peptide_sp, _spectrum_sp, _zmax, _precision, _ion_list); + + _spectrum_painter.setMarginLeft(60); + _spectrum_painter.setMarginTop(15); + _spectrum_painter.setMarginBottom(20); + _spectrum_painter.setFontPointSize(10); + + qDebug() << "QSpectrumWidget::QSpectrumWidget end"; + +} +QSpectrumWidget::~QSpectrumWidget() +{ + +} + +void QSpectrumWidget::setPrecision(pappso::PrecisionP p_precision) { + qDebug() << "QSpectrumWidget::setPrecision"; + _spectrum_painter.setPrecision(p_precision); + update(); +} + +void QSpectrumWidget::setPeptideSp(pappso::PeptideSp & peptide_sp) { + _spectrum_painter.setPeptideSp(peptide_sp); + update(); +} +void QSpectrumWidget::setQualifiedSpectrum(pappso::QualifiedSpectrum spectrum) { + + _spectrum_painter.setQualifiedSpectrum(spectrum); + update(); + +} + +void QSpectrumWidget::paintEvent(QPaintEvent * /* event */) +{ + QPainter painter; + painter.begin(this); + painter.setRenderHint(QPainter::Antialiasing); + paint(painter); + painter.end(); +} + +void QSpectrumWidget::paint(QPainter &painter) +{ + //painter.drawLine(QLine(0, 35, 200, 35)); + _spectrum_painter.paint(painter, this->size().width(), this->size().height()); +} + +void QSpectrumWidget::setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList) { + _spectrum_painter.setIsotopeMassList(isotopeMassList); + update(); +} + diff --git a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h new file mode 100644 index 0000000000000000000000000000000000000000..bd0ac82e5686b45f38b1b4f7e3cd13d57101e1c5 --- /dev/null +++ b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h @@ -0,0 +1,69 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* PAPPSOms-tools 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 General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#ifndef QSPECTRUMWIDGET_H +#define QSPECTRUMWIDGET_H + +#include <QWidget> +#include <QPainter> +#include <QMouseEvent> +#include <pappsomspp/spectrum/qualifiedspectrum.h> +#include <pappsomspp/peptide/peptide.h> +#include <pappsomspp/peptide/peptidefragmention.h> +#include "../../utils/spectrumpainter.h" + +using namespace pappso; + +class QSpectrumWidget: public QWidget +{ + Q_OBJECT +public: + QSpectrumWidget(QWidget *parent = 0); + ~QSpectrumWidget(); + + void paint(QPainter &painter); + + pappso_double getCanvasWidth() const {return _spectrum_painter.getCanvasWidth();}; + void setPeptideSp(pappso::PeptideSp & peptide_sp); + void setPrecision(pappso::PrecisionP p_precision); + void setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList); + + SpectrumPainter & getSpectrumPainter() {return _spectrum_painter;}; + + +public slots: + void setQualifiedSpectrum(pappso::QualifiedSpectrum spectrum); + + // void setColor(const QColor &color); + // void setShape(Shape shape); +signals: + void mzChanged(double mz); + +protected: + void paintEvent(QPaintEvent *event) override; + +private : + SpectrumPainter _spectrum_painter; +}; + +#endif // QSPECTRUMWIDGET_H