1
/***************************************************************************
2
rkpreviewbox - description
4
begin : Wed Jan 24 2007
5
copyright : (C) 2007 by Thomas Friedrichsmeier
6
email : tfry@users.sourceforge.net
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
17
#include "rkpreviewbox.h"
21
#include <qcheckbox.h>
26
#include "../rkglobals.h"
27
#include "../rbackend/rinterface.h"
28
#include "../misc/xmlhelper.h"
31
RKPreviewBox::RKPreviewBox (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) {
34
preview_active = false;
35
last_plot_done = true;
36
new_plot_pending = false;
39
XMLHelper *xml = XMLHelper::getStaticHelper ();
41
// create and add property
42
addChild ("state", state = new RKComponentPropertyBool (this, true, preview_active, "active", "inactive"));
43
connect (state, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (changedState (RKComponentPropertyBase *)));
46
QVBoxLayout *vbox = new QVBoxLayout (this, RKGlobals::spacingHint ());
47
toggle_preview_box = new QCheckBox (xml->getStringAttribute (element, "label", i18n ("Preview"), DL_INFO), this);
48
vbox->addWidget (toggle_preview_box);
49
toggle_preview_box->setChecked (preview_active);
50
connect (toggle_preview_box, SIGNAL (stateChanged (int)), this, SLOT (changedState (int)));
53
status_label = new QLabel (QString::null, this);
54
vbox->addWidget (status_label);
56
// find and connect to code property of the parent
58
RKComponentBase *cp = parentComponent ()->lookupComponent ("code", &dummy);
59
if (cp && dummy.isNull () && (cp->type () == PropertyCode)) {
60
code_property = static_cast<RKComponentPropertyCode *> (cp);
61
connect (code_property, SIGNAL (valueChanged (RKComponentPropertyBase *)), this, SLOT (changedCode (RKComponentPropertyBase *)));
63
RK_DO (qDebug ("Could not find code property in preview box (remainder: %s)", dummy.latin1()), PLUGIN, DL_WARNING);
68
update_timer = new QTimer (this);
69
connect (update_timer, SIGNAL (timeout ()), this, SLOT (tryPreviewNow ()));
74
RKPreviewBox::~RKPreviewBox () {
80
void RKPreviewBox::changedState (RKComponentPropertyBase *) {
85
toggle_preview_box->setChecked (state->boolValue ());
92
void RKPreviewBox::changedCode (RKComponentPropertyBase *) {
98
void RKPreviewBox::changedState (int) {
101
state->setBoolValue (toggle_preview_box->isChecked ());
104
void RKPreviewBox::tryPreview () {
107
if (isEnabled () && toggle_preview_box->isChecked ()) update_timer->start (10, true);
110
updateStatusLabel ();
113
void RKPreviewBox::tryPreviewNow () {
116
if (!code_property) return;
117
if (!parentComponent ()->isSatisfied ()) {
120
if (!parentComponent ()->isReady ()) {
125
if (!last_plot_done) { // if the last plot is not done, yet, wait before starting the next.
126
new_plot_pending = true;
127
updateStatusLabel ();
131
preview_active = true;
133
RKGlobals::rInterface ()->issueCommand (dummy.sprintf (".rk.startPreviewDevice (\"%p\")", this), RCommand::Plugin | RCommand::Sync);
134
RKGlobals::rInterface ()->issueCommand ("local({\n" + code_property->preview () + "})\n", RCommand::Plugin | RCommand::Sync, QString::null, this);
136
last_plot_done = false;
137
new_plot_pending = false;
139
updateStatusLabel ();
142
void RKPreviewBox::killPreview () {
145
if (!preview_active) return;
146
preview_active = false;
148
RKGlobals::rInterface ()->issueCommand (command.sprintf (".rk.killPreviewDevice (\"%p\")", this), RCommand::Plugin | RCommand::Sync);
150
last_plot_done = true;
151
new_plot_pending = false;
154
void RKPreviewBox::rCommandDone (RCommand *) {
157
last_plot_done = true;
158
if (new_plot_pending) tryPreview ();
160
updateStatusLabel ();
163
void RKPreviewBox::updateStatusLabel () {
166
if (!toggle_preview_box->isChecked ()) {
167
status_label->setText (i18n ("Preview disabled"));
169
if (parentComponent ()->isSatisfied () && parentComponent ()->isReady ()) {
170
if (last_plot_done && (!new_plot_pending)) {
171
status_label->setText (i18n ("Preview up to date"));
173
status_label->setText (i18n ("Preview updating"));
176
status_label->setText (i18n ("Preview not (yet) possible"));
181
#include "rkpreviewbox.moc"