/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2013 Frederik Heber. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder 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 2 of the License, or * (at your option) any later version. * * MoleCuilder 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 MoleCuilder. If not, see . */ /* * QtTimeLine.cpp * * Created on: Jul 11, 2013 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif // make sure Qt includes come before MemDebug #include "QtTimeLine.hpp" #include "CodePatterns/MemDebug.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/Log.hpp" #include "Actions/WorldAction/SetWorldTimeAction.hpp" #include "Atom/atom.hpp" #include "Atom/AtomObserver.hpp" QtTimeLine::QtTimeLine(QWidget * _parent) : QSlider (Qt::Horizontal, _parent), Observer("QtTimeLine") { // set initial values QSlider::setMinimum(0); QSlider::setMaximum(0); QSlider::setValue(0); QSlider::setTickInterval(1); QSlider::setSingleStep(1); QSlider::setTracking(true); // sign on to observable AtomObserver::getInstance().signOn(this, AtomObservable::TrajectoryChanged); enlisted = true; // connect to QSlider's valueChanged() signal bool result = connect(this,SIGNAL(valueChanged(int)),this,SLOT(StepUpdate(int))); if (!result) ELOG(0, "Could not connect to QSlider::valueChanged."); } QtTimeLine::~QtTimeLine() { if (enlisted) AtomObserver::getInstance().signOff(this, AtomObservable::TrajectoryChanged); } void QtTimeLine::subjectKilled(Observable *publisher) { enlisted = false; } void QtTimeLine::update(Observable *publisher) { ELOG(0, "We are not enlisted for general updates."); } void QtTimeLine::recieveNotification(Observable *publisher, Notification_ptr notification) { // calculate max trajectory (need dynamic_cast due to virtual base) const atom *_atom = dynamic_cast(publisher); const int MaxTrajectory = _atom->getTrajectorySize()-1; if (MaxTrajectory > QSlider::maximum()) QSlider::setMaximum(MaxTrajectory); } void QtTimeLine::StepUpdate(int position) { MoleCuilder::WorldSetWorldTime(position); }