Changeset 6116df for src/UIElements


Ignore:
Timestamp:
Jun 19, 2017, 8:24:17 AM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChangeBugEmailaddress, ChemicalSpaceEvaluator, EmpiricalPotential_contain_HomologyGraph_documentation, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_oldresults, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids_IntegrationTest, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps
Children:
be848d
Parents:
5776cb
git-author:
Frederik Heber <heber@…> (04/01/17 07:03:30)
git-committer:
Frederik Heber <frederik.heber@…> (06/19/17 08:24:17)
Message:

QtGeometryList now shows length or angle of stored vectors via tooltips.

Location:
src/UIElements/Views/Qt4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/UIElements/Views/Qt4/QtGeometryList.cpp

    r5776cb r6116df  
    4545
    4646#include <QAbstractItemView>
     47#include <QCoreApplication>
    4748
    4849using namespace std;
     
    5657{
    5758  setColumnCount(COLUMNCOUNT);
    58   setSelectionMode(QAbstractItemView::NoSelection);
     59  setSelectionMode(QAbstractItemView::SingleSelection);
     60  setSortingEnabled(true);
    5961
    6062  QStringList header;
     
    6264          header << COLUMNNAMES[i];
    6365        setHeaderLabels(header);
     66  sortByColumn(0);
     67
     68  setStyleSheet("QTreeView::item:hover{background-color:#999966;}");
    6469
    6570        refill(NULL);
     
    6873        GeometryRegistry::getInstance().signOn(this, GeometryRegistry::GeometryInserted);
    6974        GeometryRegistry::getInstance().signOn(this, GeometryRegistry::GeometryRemoved);
     75
     76        QCoreApplication::instance()->installEventFilter(this);
    7077}
    7178
     
    129136void QtGeometryList::subjectKilled(Observable *publisher) {
    130137}
     138
     139bool QtGeometryList::eventFilter(QObject* object, QEvent* event)
     140{
     141    if(event->type() == QEvent::MouseMove)
     142    {
     143         mouseMoveFunction(static_cast<QMouseEvent*>(event));
     144    }
     145    // Repeat for other mouse events
     146
     147   // returning true blocks event returning false doesnt so if you want to block all mouse events except what your handling then return true inside each of your ifs
     148   return false;
     149}
     150
     151void QtGeometryList::mouseMoveFunction(QMouseEvent * event)
     152{
     153  if (event->type() == QEvent::MouseMove) {
     154    QTreeWidgetItem* current = itemAt(event->pos());
     155    if (current == NULL)
     156      return;
     157    // reset all tooltips
     158    bool NoneSelected = true;
     159    for (int i=0;i<topLevelItemCount();i++){
     160      QTreeWidgetItem *item = topLevelItem(i);
     161      item->setToolTip(NAME, tr(""));
     162      item->setToolTip(VECTOR, tr(""));
     163      NoneSelected &= !item->isSelected();
     164    }
     165    const std::string name = current->text(NAME).toStdString();
     166    GeometryObject *v = GeometryRegistry::getInstance().getByName(name);
     167    const Vector currentVec = v->getVector();
     168    if ((NoneSelected) || (current->isSelected())) {
     169      // show norm
     170      std::string tooltiptext("Length:");
     171      tooltiptext += toString<double>(currentVec.Norm());
     172      tooltiptext += std::string(" Angström");
     173      current->setToolTip(NAME, trUtf8(tooltiptext.c_str()));
     174      current->setToolTip(VECTOR, trUtf8(tooltiptext.c_str()));
     175    } else {
     176      for (int i=0;i<topLevelItemCount();i++){
     177        QTreeWidgetItem *item = topLevelItem(i);
     178        if (item->isSelected()) {
     179          // show angle
     180          const std::string othername = item->text(NAME).toStdString();
     181          GeometryObject *otherv = GeometryRegistry::getInstance().getByName(othername);
     182          const Vector otherVec = otherv->getVector();
     183          std::string tooltiptext("Angle:");
     184          tooltiptext += toString<double>(currentVec.Angle(otherVec)*180/M_PI);
     185          tooltiptext += std::string(" deg");
     186          current->setToolTip(NAME, trUtf8(tooltiptext.c_str()));
     187          current->setToolTip(VECTOR, trUtf8(tooltiptext.c_str()));
     188          break;
     189        }
     190      }
     191    }
     192  }
     193}
  • src/UIElements/Views/Qt4/QtGeometryList.hpp

    r5776cb r6116df  
    1616
    1717#include <QtGui/QTreeWidget>
     18#include <QMouseEvent>
     19
    1820#include "CodePatterns/Observer/Observer.hpp"
    1921
     
    2729  QtGeometryList(QWidget * _parent=0);
    2830  virtual ~QtGeometryList();
     31
     32protected:
     33  bool eventFilter(QObject* object, QEvent* event);
     34  void mouseMoveFunction(QMouseEvent * event);
    2935
    3036protected:
Note: See TracChangeset for help on using the changeset viewer.